liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file comments_inc.php

Documentation is available at comments_inc.php

  1. <?php
  2. /**
  3.  * comment_inc
  4.  *
  5.  * @author   spider <spider@steelsun.com>
  6.  * @version  $Revision$
  7.  * @package  liberty
  8.  * @subpackage functions
  9.  */
  10.  
  11. // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  12. // All Rights Reserved. See below for details and a complete list of authors.
  13. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  14.  
  15. // This file sets up the information needed to display
  16. // the comments preferences, post-comment box and the
  17. // list of comments. Finally it displays comments.tpl
  18. // using this information
  19.  
  20. // Setup URLS for the Comments next and prev buttons and use variables that
  21. // cannot be aliased by normal Bit variables.
  22. // Traverse each _REQUEST data adn put them in an array
  23.  
  24. // this script may only be included - so its better to die if called directly.
  25.  
  26.  
  27. /**
  28.  * Parameters that need to be set when calling this file
  29.  * @param numeric $commentsParentId    The content id of the object where a new comment will be attached                                  (required)
  30.  * @param array   $commentsParentIds   The list of content id of object the comments will be displayed - if not defined $commentsParentId (required if $commentsParentId is not set)
  31.  * @param string  $comments_return_url The URL the user should be sent to after posting the comment                                       (required)
  32. ***/
  33.  
  34.  
  35. /**
  36.  * required setup
  37.  */
  38. require_onceLIBERTY_PKG_PATH.'LibertyComment.php' );
  39.  
  40. global $commentsLib$gBitSmarty$gBitSystem$gBitThemes;
  41.  
  42. $postComment array();
  43. $formfeedback array'error' => array() );
  44. $gBitSmarty->assign_by_ref'formfeedback'$formfeedback );
  45.  
  46. // make sure that we don't feed ajax comments if we don't have javascript enabled
  47. if!$gBitThemes->isJavascriptEnabled() ) {
  48.     $gBitSystem->setConfig'comments_ajax''n' );
  49. }
  50.  
  51. if@BitBase::verifyId$_REQUEST['delete_comment_id')) {
  52.     $deleteComment new LibertyComment($_REQUEST['delete_comment_id']);
  53.     // make sure we're loaded up before we delete
  54.     $deleteComment->loadComment();
  55.     if$deleteComment->isValid(&& $gContent->hasUserPermission'p_liberty_admin_comments' )) {
  56.         // delete entire thread
  57.         $deleteComment->expunge();
  58.     }
  59. }
  60.  
  61. if@BitBase::verifyId$_REQUEST['post_comment_id'&& $gContent->hasUserPermission'p_liberty_post_comments' )) {
  62.     $post_comment_id $_REQUEST['post_comment_id'];
  63.     $editComment new LibertyComment$post_comment_id );
  64.     //if we are passed a comment id but not going to store it then turn off ajax
  65.     if!isset$_REQUEST['post_comment_submit'&& !isset$_REQUEST['post_comment_cancel')){
  66.         //even if ajax is on - we force it off in this case
  67.         $gBitSmarty->assign'comments_ajax'FALSE );
  68.     }
  69.  
  70.     if$editComment->mInfo['content_id'{
  71.         if$editComment->userCanUpdate$gContent )) {
  72.             $postComment['data'$editComment->mInfo['data'];
  73.             $postComment['title'$editComment->mInfo['title'];
  74.         else {
  75.             $formfeedback['error'"You do not have permission to edit this comment.";
  76.             $editComment NULL;
  77.             $post_comment_id NULL;
  78.         }
  79.     else {
  80.         $formfeedback['error'"Comment does not exist.";
  81.         $editComment NULL;
  82.         $post_comment_id NULL;
  83.     }
  84. else {
  85.     $post_comment_id NULL;
  86.     $editComment NULL;
  87. }
  88. $gBitSmarty->assign('post_comment_id'$post_comment_id);
  89.  
  90. // Store comment posts
  91. if!empty$_REQUEST['post_comment_submit'&& $gContent->hasUserPermission'p_liberty_post_comments' )) {
  92.  
  93.     // check for !anon_post before logging in (auto-fill can hork things up)
  94.     ifempty$_REQUEST['anon_post'&& !empty$_REQUEST['login_email'&& !empty$_REQUEST['login_password') ) {
  95.         $gBitUser->login$_REQUEST['login_email']$_REQUEST['login_password');
  96.         if!empty$gBitUser->mErrors['login') ) {
  97.             $formfeedback['error'][$gBitUser->mErrors['login'];
  98.         }
  99.     else {
  100.         if!empty($_REQUEST['comment_name')) {
  101.             $_REQUEST['anon_name'$_REQUEST['comment_name'];
  102.         }
  103.     }
  104.  
  105.     // this commentsParentId is some crazy ass business - lets prepare for the day when this can be removed
  106.     // there are references to it in LibertyComments::verifyComments as well
  107.     $_REQUEST['comments_parent_id'$commentsParentId;
  108.  
  109.     $storeComment new LibertyComment@BitBase::verifyId$editComment->mCommentId $editComment->mCommentId NULL );
  110.  
  111.     ifempty$formfeedback['error'&& $storeComment->storeComment$_REQUEST )) {
  112.         // store successful
  113.         $storeComment->loadComment();
  114.         ifempty$_REQUEST['post_comment_id'&& $gBitSystem->isPackageActive'switchboard' ) ) {
  115.             // A new comment, and we have switchboard to send notifications
  116.             global $gSwitchboardSystem;
  117.             // Draft the message:
  118.             $message['subject'tra'New comment on:' ).' '.$gContent->getTitle().' @ '.$gBitSystem->getConfig'site_title' );
  119.             $message['message'tra('A new message was posted to ').' '.$gContent->getTitle()."<br/>\n".$gContent->getDisplayUri()."<br/>\n"
  120.                     .'/----- '.tra('Here is the message')." -----/<br/>\n<br/>\n".'<h2>'.$storeComment->getTitle()."</h2>\n".tra('By').' '.$gBitUser->getDisplayName()."\n<p>".$storeComment->parseData().'</p>';
  121.             $gSwitchboardSystem->sendEvent('My Content''new comment'$gContent->mContentId$message );
  122.         }
  123.         $postComment NULL;
  124.     else {
  125.         // store fails handle errors and preview
  126.         $formfeedback['error']=array_merge$formfeedback['error']$storeComment->mErrors );
  127.         $postComment['data'!empty$_REQUEST['comment_data'$_REQUEST['comment_data''';
  128.         $postComment['title'!empty$_REQUEST['comment_title'$_REQUEST['comment_title''';
  129.         if!empty$_REQUEST['comment_name') ) {
  130.             $postComment['anon_name'$_REQUEST['comment_name'];
  131.         }
  132.  
  133.         $_REQUEST['post_comment_request'TRUE;
  134.         //this is critical and triggers other settings if store fails - do not remove without looking at what preview effects
  135.         $_REQUEST['post_comment_preview'TRUE;
  136.     }
  137. elseif(!empty($_REQUEST['post_comment_request']&& !$gContent->hasUserPermission'p_liberty_post_comments' )) {
  138.     $formfeedback['warning']="You don't have permission to post comments.";
  139. }
  140.  
  141. // $post_comment_request is a flag indicating whether or not to display the comment input form
  142. ifempty$_REQUEST['post_comment_request'&& !$gBitSystem->isFeatureActive'comments_auto_show_form' ) ) {
  143.     $post_comment_request NULL;
  144. elseif$gContent->hasUserPermission'p_liberty_post_comments' ) ) {
  145.     $post_comment_request TRUE;
  146.     // force off ajax attachments which does not work for comments attachments
  147.     if$gBitSystem->isFeatureActive'comments_allow_attachments' && $gBitSystem->getConfig'liberty_attachment_style'== 'ajax' ){
  148.         $gBitSystem->setConfig'liberty_attachment_style''standard' );
  149.     }
  150. }
  151.  
  152. // in anticipation of mainlining LCConfig package - enable comment format configuration
  153. // hack because comments does not have edit service -wjames5
  154. if$gBitSystem->isPackageActive'lcconfig' ) ){
  155.     $spoofHash array();
  156.     lcconfig_content_editnew LibertyComment()$spoofHash  );
  157. }
  158.  
  159. if!empty$_REQUEST['post_comment_request'&& $_REQUEST['post_comment_request'== 'y' && !$gContent->hasUserPermission'p_liberty_post_comments' ) ) {
  160.     $gBitSystem->fatalPermission'p_liberty_post_comments' );
  161. }
  162. $gBitSmarty->assign_by_ref('post_comment_request'$post_comment_request);
  163.  
  164. if!empty$_REQUEST['post_comment_cancel') ) {
  165.     $postComment NULL;
  166. }
  167.  
  168. // $post_comment_preview is a flag indicating that the user wants to preview their comment prior to saving it
  169. if!empty$_REQUEST['post_comment_preview')) {
  170.     ifisset$_REQUEST['no_js_preview'&& $_REQUEST['no_js_preview']=="y" {
  171.         $no_js_preview $_REQUEST['no_js_preview'];
  172.  
  173.         //even if ajax is on - we force it off in this case
  174.         $gBitSmarty->assign'comments_ajax'FALSE );
  175.     else {
  176.         $no_js_preview "n";
  177.     }
  178.  
  179.     $gBitSmarty->assign_by_ref'no_js_preview'$no_js_preview );
  180.  
  181.     $postComment['user_id'$gBitUser->mUserId;
  182.     $postComment['title'$_REQUEST['comment_title'];
  183.     if!empty$_REQUEST['comment_name')) {
  184.         $postComment['anon_name'$_REQUEST['comment_name'];
  185.     }
  186.     $postComment['data'$_REQUEST['comment_data'];
  187.     $postComment['format_guid'empty$_REQUEST['format_guid'])$gBitSystem->getConfig'default_format' $_REQUEST['format_guid'];
  188.     $postComment['parsed_data'LibertyComment::parseData$postComment );
  189.     $postComment['created'time();
  190.     $postComment['last_modified'time();
  191.     $gBitSmarty->assign('post_comment_preview'TRUE);
  192. }
  193.  
  194. // $post_comment_reply_id is the content_id which a post is replying to
  195. if@BitBase::verifyId$_REQUEST['post_comment_reply_id')) {
  196.     $post_comment_reply_id $_REQUEST['post_comment_reply_id'];
  197.     $tmpComment new LibertyCommentNULL$post_comment_reply_id );
  198.     if!empty$_REQUEST['quote')) {
  199.         $postComment['data'$tmpComment->getQuoted();
  200.     }
  201.     ifpreg_match'/^' tra'Re:' '/'$tmpComment->mInfo['title')) {
  202.         $comment_prefix '';
  203.     else {
  204.         $comment_prefix tra'Re:' " ";
  205.     }
  206.  
  207.     //this always overrides the title with "Re: Parent Title" -- not sure what it really should do so I put in this conditional for previews
  208.     if!isset$_REQUEST['comment_title')) {
  209.         $postComment['title'$comment_prefix.$tmpComment->mInfo['title'];
  210.     }
  211.  
  212.     $gBitSmarty->assign'post_comment_reply_id'$post_comment_reply_id );
  213. }
  214.  
  215. if$gContent->hasUserPermission'p_liberty_read_comments' )) {
  216.  
  217.     if!empty$_SESSION['liberty_comments_per_page')) {
  218.         $maxComments $_SESSION['liberty_comments_per_page'];
  219.     else {
  220.         $maxComments $gBitSystem->getConfig'comments_per_page'10 );
  221.     }
  222.  
  223.     if!empty$_REQUEST["comments_maxComments")) {
  224.         $maxComments $_REQUEST["comments_maxComments"];
  225.         $comments_at_top_of_page 'y';
  226.         $_SESSION['liberty_comments_per_page'$maxComments;
  227.     }
  228.  
  229.     if!empty$_SESSION['liberty_comments_ordering')) {
  230.         $comments_sort_mode $_SESSION['liberty_comments_ordering'];
  231.     else {
  232.         $comments_sort_mode $gBitSystem->getConfig'comments_default_ordering''commentDate_desc' );
  233.     }
  234.  
  235.     if!empty$_REQUEST["comments_sort_mode")) {
  236.         $comments_sort_mode $_REQUEST["comments_sort_mode"];
  237.         $comments_at_top_of_page 'y';
  238.         $_SESSION['liberty_comments_ordering'$comments_sort_mode;
  239.     }
  240.  
  241.     if!empty$_SESSION['liberty_comments_display_mode')) {
  242.         $comments_display_style $_SESSION['liberty_comments_display_mode'];
  243.     else {
  244.         $comments_display_style $gBitSystem->getConfig'comments_default_display_mode''threaded' );
  245.     }
  246.  
  247.     if!empty$_REQUEST["comments_style") ) {
  248.         $comments_display_style $_REQUEST["comments_style"];
  249.         $comments_at_top_of_page 'y';
  250.         $_SESSION['liberty_comments_display_mode'$comments_display_style;
  251.     }
  252.  
  253.     if!empty$_REQUEST['comment_page'|| !empty$_REQUEST['post_comment_request') ) {
  254.         $comments_at_top_of_page 'y';
  255.     }
  256.     $commentOffset !empty$_REQUEST['comment_page'($_REQUEST['comment_page'1$maxComments 0;
  257.  
  258.     ifempty$gComment )) {
  259.         $gComment new LibertyComment();
  260.     }
  261.  
  262.     $currentPage !empty$_REQUEST['comment_page'$_REQUEST['comment_page'1;
  263.     if$currentPage {
  264.         $currentPage 1;
  265.     }
  266.  
  267.     # logic to support displaying a single comment -- used when we need a URL pointing to a comment
  268.     if!empty$_REQUEST['view_comment_id')) {
  269.         $commentOffset $gComment->getNumComments_upto$_REQUEST['view_comment_id');
  270. #       echo "commentOffset =$commentOffset= maxComments=$maxComments=\n";
  271.         $comments_sort_mode 'commentDate_asc';
  272.         $comments_display_style 'flat';
  273.         $comments_at_top_of_page 'y';
  274.         $maxComments 1;
  275.         $currentPage ceil$commentOffset $maxComments );
  276.     else {
  277.         $commentOffset $currentPage $maxComments;
  278.     }
  279.  
  280.  
  281.     // $commentsParentId is the content_id which the comment tree is attached to
  282.     if!@BitBase::verifyId$commentsParentId ) ) {
  283.         $comments array();
  284.         $numComments 0;
  285.     else {
  286.         if@BitBase::verifyId$commentsParentIds ) ) {
  287.             $parents $commentsParentIds;
  288.         else {
  289.             $parents $commentsParentId;
  290.         }
  291.         // pass in a reference to the root object so that we can do proper permissions checks
  292.         if is_object$gContent )) {
  293.             $gComment->mRootObj $gContent;
  294.         }
  295.         $numComments $gComment->getNumComments$commentsParentId );
  296.         if ($commentOffset $numComments{
  297.             $commentOffset $numComments $maxComments;
  298.             $currentPage ceil$commentOffset+$maxComments );
  299.         }
  300.         $comments $gComment->getComments$parents$maxComments$commentOffset$comments_sort_mode$comments_display_style );
  301.     }
  302.  
  303.     if$comments_display_style == 'flat' {
  304.         $commentsTree $comments;
  305.     else {
  306.         $commentsTree array();
  307.         foreach$comments as $id => $node ){
  308.             if!empty$comments$node['parent_id'] ] )) {
  309.                 $comments$node['parent_id'] ]['children'][$id&$comments[$id];
  310.             }
  311.             if$node['parent_id'== $node['root_id'|| empty$comments$node['parent_id'] ] )) {
  312.                 $comments[$id]['level'0;
  313.                 $commentsTree[$id&$comments[$id];
  314.             }
  315.         }
  316.     }
  317.  
  318.     $gBitSmarty->assign_by_ref'comments'$commentsTree );
  319.     $gBitSmarty->assign'maxComments'$maxComments );
  320.  
  321.     $numCommentPages ceil$numComments $maxComments );
  322.     $comments_return_url $comments_return_url.!strpos$comments_return_url'?' '?' '' );
  323.  
  324.     // libertypagination smarty function setup
  325.     $commentsPgnHash array(
  326.             'numPages'      => $numCommentPages,
  327.             'pgnName'       => 'comment_page',
  328.             'page'          => $currentPage,
  329.             'comment_page'  => $currentPage,
  330.             'url'           => $comments_return_url,
  331.             'comments_page' => empty$comments_on_separate_page FALSE $comments_on_separate_page ),
  332.             'ianchor'       => 'editcomments',
  333.             );
  334.     $gBitSmarty->assign_by_ref'commentsPgnHash'$commentsPgnHash );
  335.     $gBitSmarty->assign_by_ref'postComment'$postComment );
  336.     $gBitSmarty->assign_by_ref'gComment'$gComment );
  337.  
  338.     $gBitSmarty->assign'currentTimestamp'time() );
  339.     $gBitSmarty->assign'comments_return_url'$comments_return_url );
  340.     $gBitSmarty->assign'comments_at_top_of_page'isset$comments_at_top_of_page && $gBitSystem->getConfig'comments_reorganise_page_layout''n' == 'y' $comments_at_top_of_page NULL );
  341.     $gBitSmarty->assign'comments_style'$comments_display_style );
  342.     $gBitSmarty->assign'comments_sort_mode'$comments_sort_mode );
  343.     $gBitSmarty->assign'textarea_id''commentpost' );
  344.     $gBitSmarty->assign'comments_count'$numComments );
  345.  
  346.     // @TODO get this shit out of here - boards and any other package ridding on comments should make use of services
  347.     if$gBitSystem->isPackageActive'boards' )) {
  348.         require_once(BOARDS_PKG_PATH.'BitBoardTopic.php');
  349.     }
  350.  
  351.     // @TODO get this shit out of here - boards and any other package ridding on comments should make use of services
  352.     // this clearly can go in an edit service, but need to be careful since comments currently does not call edit service - have to check what doing so might trigger.
  353.     if!empty$_REQUEST['post_comment_request')) {
  354.         if$gBitSystem->isPackageActive'boards' )
  355.                 && (
  356.                     BitBoardTopic::isLockedMsg@BitBase::verifyId$storeComment->mInfo['parent_id')
  357.                         ? $storeComment->mInfo['parent_id'!@BitBase::verifyId$_REQUEST['post_comment_reply_id')
  358.                             ? $commentsParentId $_REQUEST['post_comment_reply_id'))
  359.                    )
  360.           {
  361.             unset$_REQUEST['post_comment_request');
  362.             unset$_GET['post_comment_request');
  363.             unset$_POST['post_comment_request');
  364.             $formfeedback['warning']="The selected Topic is Locked posting is disabled";
  365.         }
  366.     }
  367.  
  368. }

Documentation generated on Wed, 29 Jul 2015 13:56:15 +0000 by phpDocumentor 1.5.0-lsces