Changeset 1133

Show
Ignore:
Timestamp:
05/31/07 12:35:15 (2 years ago)
Author:
icewing
Message:

Marcus Povey <marcus@dushka.co.uk>
* Generic comments ajaxy stuff committed. Rather rough and ready + php
_needs_ some tidying.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/mod/generic_comments/comments_actions.php

    r1132 r1133  
    88                // Create a comment 
    99            case "comment:add": 
     10                $ok = false; 
    1011                $comment = new StdClass; 
    1112                $comment->object_id = optional_param('object_id',0,PARAM_INT); 
     
    3334                            $comment = plugin_hook("comment","publish",$comment); 
    3435                            $messages[] = __gettext("Your comment has been added."); // gettext variable 
     36                            $ok = true; 
    3537                             
    3638                            // If we're logged on and not the owner of this post, add post to our watchlist 
     
    6365                { 
    6466                        // If we are returning xml for the ajax response then output message and die. 
     67 
     68                        if ($ok!=true) {  
     69                                $ok = "<error>1</error>\n";  
     70                        } else {  
     71                                $messages[] = __gettext(" Click <a href=\"\">here</a> to refresh"); 
     72                                $ok = "<error>0</error>\n"; 
     73                        } 
     74                         
    6575                        $msg = implode("\n", $messages); 
    6676                        header("Content-type: text/xml"); 
    67                         echo "<ajax>\n<message>$msg</message>\n</ajax>\n"; 
     77                         
     78                        echo "<ajax>\n<message>$msg</message>\n$ok</ajax>\n"; 
    6879                        exit; 
    6980                } 
  • devel/mod/generic_comments/generic_comments.js

    r1132 r1133  
    11var http_Request = false; 
     2var success = false; 
     3var objectid = ""; 
    24 
    35function showhide(oid) 
     
    5153                        message = result.getElementsByTagName('message')[0]; 
    5254 
    53                         document.getElementById('ajaxmessages').innerHTML = message.textContent;  
    54 // todo find system-message 
     55                        error = result.getElementsByTagName('error')[0]; 
     56                        if (error.textContent == '0') { 
     57                                success = true; 
     58                        } 
     59 
     60                        if (success == true) 
     61                        { 
     62                                document.getElementById('ajaxmessages_' + objectid).innerHTML = '<a href="">' + message.textContent + '</a>';  
     63                        } 
     64                        else 
     65                        { 
     66                                document.getElementById('ajaxmessages_' + objectid).innerHTML = message.textContent;  
     67                        } 
    5568                } else { 
    5669                        alert('There was a problem with the request.'); 
     
    5972} 
    6073 
    61 function sendcomment(url, formid
     74function sendcomment(url, formid, oid
    6275{ 
    6376        var parameters; 
     77        objectid = oid; 
    6478 
    6579        http_Request = getAjaxObj(); 
     
    94108 
    95109        frm.new_comment.disabled=false; 
     110 
     111        if (success==true) {  
     112                frm.new_comment.value="";  
     113        } 
    96114} 
  • devel/mod/generic_comments/lib.php

    r1132 r1133  
    293293                } 
    294294 
     295                 
     296 
     297                $thispageurl = generic_comments_add_parameter_to_url(get_url($object_id, $object_type),'comment_sort',$sort_sequence); 
    295298                $comment_name_enc = templates_draw(array( 
    296299         
     
    302305                            ); 
    303306                $postcomment = __gettext("Post comment..."); 
     307 
     308                if ($comments = get_records_sql("SELECT * FROM {$CFG->prefix}comments WHERE object_id = $object_id AND object_type = '$object_type' ORDER BY posted $sort_sequence")) { 
     309                $numcomments = count($comments); 
     310                $pagelinks = ''; 
     311                if (!empty($perpage) && $numcomments > $perpage) { 
     312                    $comments = array_slice($comments, $offset, $perpage); 
     313                    $numpages = ceil($numcomments / $perpage); 
     314                    $pagelinks = __gettext("Page: "); 
     315                    for ($i = 1; $i <= $numpages; $i++) { 
     316                        $pagenum = $i - 1; 
     317                        if ($pagenum != $page) { 
     318                                if ($pagenum) { 
     319                                        $pageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$pagenum); 
     320                                } 
     321                            //$pageurl = $thispageurl . (($pagenum) ? '.' . $pagenum : ''); 
     322                            $pagelinks .= ' <a href="' . $pageurl . '">' . $i . '</a>' ; 
     323                        } else { 
     324                            $pagelinks .= ' ' . $i . ' '; 
     325                        } 
     326                         
     327                    } 
     328                    //$thispageurl .= '.' . $page; 
     329                    $thispageurl = generic_comments_add_parameter_to_url($thispageurl,'commentpage',$page); 
     330                     
     331                } 
     332                 
     333                foreach($comments as $comment) { 
     334                    $commentmenu = ""; 
     335                    if (isloggedin() && ($comment->owner == $_SESSION['userid'] || run("permissions:check",array("comment:delete",$_SESSION['userid'],$comment->object_id,$comment->object_type)))) { 
     336                        $returnConfirm = __gettext("Are you sure you want to permanently delete this comment?"); 
     337                        $Delete = __gettext("Delete"); 
     338                        $commentmenu = <<< END 
     339                        <a href="{$CFG->wwwroot}mod/generic_comments/action_redirection.php?action=comment:delete&amp;comment_form_type=$comment_form_type&amp;comment_delete={$comment->ident}" onclick="return confirm('$returnConfirm')">$Delete</a> 
     340END; 
     341                    } 
     342                    $comment->postedname = htmlspecialchars($comment->postedname, ENT_COMPAT, 'utf-8'); 
     343                     
     344                    // turn commentor name into a link if they're a registered user 
     345                    // add rel="nofollow" to comment links if they're not 
     346                    if ($comment->owner > 0) { 
     347                        $commentownerusername = user_info('username', $comment->owner); 
     348                        $comment->postedname = '<a href="' . url . $commentownerusername . '/">' . $comment->postedname . '</a>'; 
     349                        $comment->icon = '<a href="' . url . $commentownerusername . '/">' . user_icon_html($comment->owner,50) . "</a>"; 
     350                        $comment->body = run("weblogs:text:process", array($comment->body, false)); 
     351                    } else { 
     352                        $comment->icon = "<img src=\"" . $CFG->wwwroot . "_icons/data/default.png\" width=\"50\" height=\"50\" align=\"left\" alt=\"\" />"; 
     353                        $comment->body = run("weblogs:text:process", array($comment->body, true)); 
     354                    } 
     355                     
     356                    $commentsbody .= templates_draw(array( 
     357                                                          'context' => 'weblogcomment', 
     358                                                          'postedname' => $comment->postedname, 
     359                                                          'body' => '<a name="cmt' . $comment->ident . '" id="cmt' . $comment->ident . '"></a>' . $comment->body, 
     360                                                          'posted' => strftime("%A, %d %B %Y, %H:%M %Z",$comment->posted), 
     361                                                          'usericon' => $comment->icon, 
     362                                                          'permalink' => $thispageurl . "#cmt" . $comment->ident, 
     363                                                          'links' =>  $commentmenu 
     364                                                          ) 
     365                                                    ); 
     366                     
     367                } 
     368                $commentsbody = templates_draw(array( 
     369                                                     'context' => 'weblogcomments', 
     370                                                     'paging' => $pagelinks, 
     371                                                     'comments' => $commentsbody 
     372                                                     ) 
     373                                               ); 
     374        } 
     375 
    304376                $bodyfrm = <<< END 
    305377                        <span style="cursor:hand; cursor:pointer" onclick="showhide('oid_$object_id')">$comment_count $comment_form_text</span> 
     
    315387                                        $comment_name_enc 
    316388                                </form> 
    317                                 <div id="ajaxmessages"></div> 
    318                                 <span style="cursor:hand; cursor:pointer" onclick="sendcomment('{$CFG->wwwroot}mod/generic_comments/action_redirection.php','comment_$object_id')">$postcomment</span> 
     389                                <div id="ajaxmessages_$object_id"></div> 
     390                                <span style="cursor:hand; cursor:pointer" onclick="sendcomment('{$CFG->wwwroot}mod/generic_comments/action_redirection.php','comment_$object_id', $object_id)">$postcomment</span> 
     391 
     392                                $commentsbody 
    319393                        </div> 
    320394END;