Changeset 1132

Show
Ignore:
Timestamp:
05/31/07 11:10:18 (2 years ago)
Author:
icewing
Message:

Marcus Povey <marcus@dushka.co.uk>
* First version ajax comment submission code.

Files:

Legend:

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

    r1117 r1132  
    5959                } 
    6060                 
    61                 define('redirect_url',$redirect_url); 
     61                $xml = optional_param('returnformat',''); 
     62                if (!empty($xml)) 
     63                { 
     64                        // If we are returning xml for the ajax response then output message and die. 
     65                        $msg = implode("\n", $messages); 
     66                        header("Content-type: text/xml"); 
     67                        echo "<ajax>\n<message>$msg</message>\n</ajax>\n"; 
     68                        exit; 
     69                } 
     70                else { 
     71                        define('redirect_url',$redirect_url); 
     72                } 
    6273                } 
    6374                break; 
  • devel/mod/generic_comments/lib.php

    r1117 r1132  
    22 
    33function generic_comments_init() { 
    4         global $CFG, $db,$function; 
    5          
     4        global $CFG, $db,$function, $metatags; 
     5 
     6        $metatags .= "<script type=\"text/javascript\" src=\"{$CFG->wwwroot}mod/generic_comments/generic_comments.js\"><!-- generic_comments js --></script>"; 
     7 
    68        // create the generic_comments and generic watchlist table 
    79        $tables = $db->Metatables(); 
     
    1921    $function['permissions:check'][] = $CFG->dirroot . "mod/generic_comments/permissions_check.php"; 
    2022 
     23 
     24    // Add annotation support 
     25        display_set_display_annotation_function("file::file", "generic_comments_displayobjectannotations"); 
     26 
    2127} 
    2228 
    2329function generic_comments_pagesetup() { 
    2430// need to set up an admin option to allow comments to be editable 
     31 
     32} 
     33 
     34function generic_comments_displayobjectannotations($object, $object_type, $view) 
     35{ 
     36        $return = ""; 
     37 
     38        if ($object_type == "file::file") 
     39        { 
     40                $txt = __gettext('Click to add or view comments on this file.'); 
     41                $int = implode('',action('annotate',$object->ident,'file::file',NULL, 
     42                        array('comment_form_type'=>'inline', 'comment_sort'=>'DESC', 'comment_form_text'=>$txt))); 
     43 
     44                $return .= <<< END 
     45                        <script type="text/javascript"> 
     46                        <!-- 
     47                                $int 
     48                        --> 
     49                        </script> 
     50                        <noscript> 
     51END; 
     52                $return .= implode('',action('annotate',$object->ident,'file::file',NULL, 
     53                        array('comment_form_type'=>'summary', 'comment_sort'=>'DESC', 'comment_form_text'=>$txt))); 
     54 
     55                $return .= <<< END 
     56                        </noscript> 
     57END; 
     58        } 
     59 
     60        return $return; 
    2561} 
    2662 
     
    5288 
    5389        $item_details = ""; 
    54         if ($object_type=="file::file"
     90        if (($object_type=="file::file") || (($object_type=="file::folder"))
    5591                $item_details = display_run_displayobject('file', $object_id, $object_type); 
    56                  
    57         if ($item_details == "")  
    58                 $item_details .= "<p>" . __gettext("Unknown object type") . "</p>";      
    5992         
    6093        $run_result = <<< END 
     
    226259                } 
    227260                 
    228                 $body = "<p>$comment_count <a href=\"{$CFG->wwwroot}mod/generic_comments/comment_page.php?object_id=$object_id&object_type=$object_type$comment_sort\">$comment_form_text</a>";          
     261                $body = "<p>$comment_count <a href=\"{$CFG->wwwroot}mod/generic_comments/comment_page.php?object_id=$object_id&object_type=$object_type$comment_sort\">$comment_form_text</a>"; 
     262 
     263 
     264                 
     265         } elseif ($comment_form_type == 'inline') { 
     266                // Funky javascript inline editing 
     267 
     268                $count = count_records('comments','object_id',$object_id,'object_type',$object_type); 
     269                if (!isset($count) || $count == 0) { 
     270                        $comment_count = "0 ".__gettext("comments")."."; 
     271                } elseif ($count == 1) { 
     272                        $comment_count = "1 ".__gettext("comment")."."; 
     273                } else { 
     274                        $comment_count = $count." ".__gettext("comments")."."; 
     275                } 
     276                 
     277                if ($parameters && strtoupper($parameters['comment_sort']) == 'DESC') { 
     278                        $comment_sort = '&comment_sort=DESC'; 
     279                } 
     280                 
     281                $field = display_input_field(array("new_comment","","longtext")); 
     282                if (logged_on) { 
     283                        $userid = $_SESSION['userid']; 
     284                } else { 
     285                        $userid = -1; 
     286                }        
     287 
     288                /* There now follows a selection of nasty hacks. Yes yes, I know this is ugly, but it means that it falls back cleanly if no javascript is supported. TODO: There must be a better way, but i'm too tired just now to think of one.*/ 
     289                if (logged_on) { 
     290                        $comment_name = $_SESSION['name']; 
     291                } else { 
     292                        $comment_name = __gettext("Guest"); 
     293                } 
     294 
     295                $comment_name_enc = templates_draw(array( 
     296         
     297                                'context' => 'databox1', 
     298                                'name' => __gettext("Your name"), 
     299                                'column1' => "<input type=\"text\" name=\"postedname\" value=\"".htmlspecialchars($comment_name, ENT_COMPAT, 'utf-8')."\" />" 
     300         
     301                            ) 
     302                            ); 
     303                $postcomment = __gettext("Post comment..."); 
     304                $bodyfrm = <<< END 
     305                        <span style="cursor:hand; cursor:pointer" onclick="showhide('oid_$object_id')">$comment_count $comment_form_text</span> 
     306                        <div id="oid_$object_id" style="display:none"> 
     307                                <form id="comment_$object_id"> 
     308                                        $field  
     309                                        <input type="hidden" name="action" value="comment:add" /> 
     310                                        <input type="hidden" name="object_id" value="{$object_id}" /> 
     311                                        <input type="hidden" name="object_type" value="{$object_type}" /> 
     312                                        <input type="hidden" name="owner" value="{$userid}" /> 
     313                                        <input type="hidden" name="comment_form_type" value="integrated" /> 
     314                                        <input type="hidden" name="comment_sort" value="{$comment_sort}" /> 
     315                                        $comment_name_enc 
     316                                </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> 
     319                        </div> 
     320END; 
     321                $body = ""; 
     322                foreach (explode("\n",addslashes($bodyfrm)) as $line) 
     323                        $body .= "document.write(\"" . trim($line) . "\");"; 
     324 
    229325         } 
    230326    return $body;