b2evolution PHP Cross Reference Blogging Systems

Source: /skins/_item_feedback.inc.php - 372 lines - 13536 bytes - Text - Print

Description: This is the template that displays the feedback for a post (comments, trackback, pingback...)

   1  <?php
   2  /**
   3   * This is the template that displays the feedback for a post
   4   * (comments, trackback, pingback...)
   5   *
   6   * You may want to call this file multiple time in a row with different $c $tb $pb params.
   7   * This allow to seprate different kinds of feedbacks instead of displaying them mixed together
   8   *
   9   * This file is not meant to be called directly.
  10   * It is meant to be called by an include in the main.page.php template.
  11   * To display a feedback, you should call a stub AND pass the right parameters
  12   * For example: /blogs/index.php?p=1&more=1&c=1&tb=1&pb=1
  13   * Note: don't code this URL by hand, use the template functions to generate it!
  14   *
  15   * b2evolution - {@link http://b2evolution.net/}
  16   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  17   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
  18   *
  19   * @package evoskins
  20   */
  21  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  22  
  23  ?>
  24  <!-- ===================== START OF FEEDBACK ===================== -->
  25  <?php
  26  
  27  // Default params:
  28  $params = array_merge( array(
  29          'Item'                 => NULL,
  30          'disp_comments'        => true,
  31          'disp_comment_form'    => true,
  32          'disp_trackbacks'      => true,
  33          'disp_trackback_url'   => true,
  34          'disp_pingbacks'       => true,
  35          'disp_section_title'   => true,
  36          'disp_rating_summary'  => true,
  37          'before_section_title' => '<h3>',
  38          'after_section_title'  => '</h3>',
  39          'comments_title_text'  => '',
  40          'comment_list_start'   => "\n\n",
  41          'comment_list_end'     => "\n\n",
  42          'comment_start'        => '<div class="bComment">',
  43          'comment_end'          => '</div>',
  44          'preview_start'        => '<div class="bComment" id="comment_preview">',
  45          'preview_end'          => '</div>',
  46          'comment_error_start'  => '<div class="bComment" id="comment_error">',
  47          'comment_error_end'    => '</div>',
  48          'comment_template'     => '_item_comment.inc.php',    // The template used for displaying individual comments (including preview)
  49          'author_link_text'     => 'login', // avatar | only_avatar | login | nickname | firstname | lastname | fullname | preferredname
  50          'link_to'              => 'userurl>userpage',            // 'userpage' or 'userurl' or 'userurl>userpage' or 'userpage>userurl'
  51          'form_title_start'     => '<h3>',
  52          'form_title_end'       => '</h3>',
  53          'disp_notification'    => true,
  54          'notification_before'  => '<div class="comment_notification">',
  55          'notification_text'    => T_( 'This is your post. You are receiving notifications when anyone comments on your posts.' ),
  56          'notification_text2'   => T_( 'You will be notified by email when someone comments here.' ),
  57          'notification_text3'   => T_( 'Notify me by email when someone comments here.' ),
  58          'notification_after'   => '</div>',
  59          'feed_title'           => '#',
  60      ), $params );
  61  
  62  
  63  global $c, $tb, $pb, $redir;
  64  
  65  if( !empty( $params['Item'] ) && is_object( $params['Item'] ) )
  66  {    // Set Item object from params
  67      $Item = $params['Item'];
  68      // Unset params Item object because the params array should be json encodable and we must avoid recursions. We already have the Item for further use.
  69      unset( $params['Item'] );
  70  }
  71  
  72  // ----------------- MODULES "Before Comments" EVENT -----------------
  73  modules_call_method( 'before_comments', $params );
  74  // -------------------- END OF MODULES EVENT ---------------------
  75  
  76  // Check if user is allowed to see comments, display corresponding message if not allowed
  77  if( $Item->can_see_comments( true ) )
  78  { // user is allowed to see comments
  79      if( empty($c) )
  80      {    // Comments not requested
  81          $params['disp_comments'] = false;                    // DO NOT Display the comments if not requested
  82          $params['disp_comment_form'] = false;            // DO NOT Display the comments form if not requested
  83      }
  84  
  85      if( empty($tb) || !$Item->can_receive_pings() )
  86      {    // Trackback not requested or not allowed
  87          $params['disp_trackbacks'] = false;                // DO NOT Display the trackbacks if not requested
  88          $params['disp_trackback_url'] = false;        // DO NOT Display the trackback URL if not requested
  89      }
  90  
  91      if( empty($pb) )
  92      {    // Pingback not requested
  93          $params['disp_pingbacks'] = false;                // DO NOT Display the pingbacks if not requested
  94      }
  95  
  96      if( ! ($params['disp_comments'] || $params['disp_comment_form'] || $params['disp_trackbacks'] || $params['disp_trackback_url'] || $params['disp_pingbacks'] ) )
  97      {    // Nothing more to do....
  98          return false;
  99      }
 100  
 101      echo '<a id="feedbacks"></a>';
 102  
 103      $type_list = array();
 104      $disp_title = array();
 105      $rating_summary = '';
 106  
 107      if( $params['disp_comments'] )
 108      {    // We requested to display comments
 109          if( $Item->can_see_comments() )
 110          {    // User can see a comments
 111              $type_list[] = 'comment';
 112              if( !empty( $params['comments_title_text'] ) )
 113              {
 114                  $disp_title[] = $params['comments_title_text'];
 115              }
 116              else if( $title = $Item->get_feedback_title( 'comments' ) )
 117              {
 118                  $disp_title[] = $title;
 119              }
 120  
 121              if( $params['disp_rating_summary'] )
 122              {    // We requested to display rating summary
 123                  $rating_summary = $Item->get_rating_summary( $params );
 124              }
 125          }
 126          else
 127          {    // User cannot see comments
 128              $params['disp_comments'] = false;
 129          }
 130          echo '<a id="comments"></a>';
 131      }
 132  
 133      if( $params['disp_trackbacks'] )
 134      {
 135          $type_list[] = 'trackback';
 136          if( $title = $Item->get_feedback_title( 'trackbacks' ) )
 137          {
 138              $disp_title[] = $title;
 139          }
 140          echo '<a id="trackbacks"></a>';
 141      }
 142  
 143      if( $params['disp_pingbacks'] )
 144      {
 145          $type_list[] = 'pingback';
 146          if( $title = $Item->get_feedback_title( 'pingbacks' ) )
 147          {
 148              $disp_title[] = $title;
 149          }
 150          echo '<a id="pingbacks"></a>';
 151      }
 152  
 153      if( $params['disp_trackback_url'] )
 154      { // We want to display the trackback URL:
 155  
 156          echo $params['before_section_title'];
 157          echo T_('Trackback address for this post');
 158          echo $params['after_section_title'];
 159  
 160          /*
 161           * Trigger plugin event, which could display a captcha form, before generating a whitelisted URL:
 162           */
 163          if( ! $Plugins->trigger_event_first_true( 'DisplayTrackbackAddr', array('Item' => & $Item, 'template' => '<code>%url%</code>') ) )
 164          { // No plugin displayed a payload, so we just display the default:
 165              echo '<p class="trackback_url"><a href="'.$Item->get_trackback_url().'">'.T_('Trackback URL (right click and copy shortcut/link location)').'</a></p>';
 166          }
 167      }
 168  
 169  
 170      if( $params['disp_comments'] || $params['disp_trackbacks'] || $params['disp_pingbacks']  )
 171      {
 172          if( empty($disp_title) )
 173          {    // No title yet
 174              if( $title = $Item->get_feedback_title( 'feedbacks', '', T_('Feedback awaiting moderation'), T_('Feedback awaiting moderation'), array( 'review', 'draft' ), false ) )
 175              { // We have some feedback awaiting moderation: we'll want to show that in the title
 176                  $disp_title[] = $title;
 177              }
 178          }
 179  
 180          if( empty($disp_title) )
 181          {    // Still no title
 182              $disp_title[] = T_('No feedback yet');
 183          }
 184  
 185          if( $params['disp_section_title'] )
 186          {    // Display title
 187              echo $params['before_section_title'];
 188              echo implode( ', ', $disp_title);
 189              echo $params['after_section_title'];
 190          }
 191          echo $rating_summary;
 192  
 193          $comments_per_page = !$Blog->get_setting( 'threaded_comments' ) ? $Blog->get_setting( 'comments_per_page' ) : 1000;
 194          $CommentList = new CommentList2( $Blog, $comments_per_page, 'CommentCache', 'c_' );
 195  
 196          // Filter list:
 197          $CommentList->set_default_filters( array(
 198                  'types' => $type_list,
 199                  'statuses' => get_inskin_statuses(),
 200                  'post_ID' => $Item->ID,
 201                  'order' => $Blog->get_setting( 'comments_orderdir' ),
 202                  'threaded_comments' => $Blog->get_setting( 'threaded_comments' ),
 203              ) );
 204  
 205          $CommentList->load_from_Request();
 206  
 207          // Get ready for display (runs the query):
 208          $CommentList->display_init();
 209  
 210          // Set redir=no in order to open comment pages
 211          memorize_param( 'redir', 'string', '', 'no' );
 212  
 213          if( $Blog->get_setting( 'paged_comments' ) )
 214          { // Prev/Next page navigation
 215              $CommentList->page_links( array(
 216                      'page_url' => url_add_tail( $Item->get_permanent_url(), '#comments' ),
 217                  ) );
 218          }
 219  
 220  
 221          if( $Blog->get_setting( 'threaded_comments' ) )
 222          {    // Array to store the comment replies
 223              global $CommentReplies;
 224              $CommentReplies = array();
 225  
 226              if( $Comment = $Session->get('core.preview_Comment') )
 227              {    // Init PREVIEW comment
 228                  if( $Comment->item_ID == $Item->ID )
 229                  {
 230                      $CommentReplies[ $Comment->in_reply_to_cmt_ID ] = array( $Comment );
 231                  }
 232              }
 233          }
 234  
 235          echo $params['comment_list_start'];
 236          /**
 237           * @var Comment
 238           */
 239          while( $Comment = & $CommentList->get_next() )
 240          {    // Loop through comments:
 241  
 242              if( $Blog->get_setting( 'threaded_comments' ) && $Comment->in_reply_to_cmt_ID > 0 )
 243              {    // Store the replies in a special array
 244                  if( !isset( $CommentReplies[ $Comment->in_reply_to_cmt_ID ] ) )
 245                  {
 246                      $CommentReplies[ $Comment->in_reply_to_cmt_ID ] = array();
 247                  }
 248                  $CommentReplies[ $Comment->in_reply_to_cmt_ID ][] = $Comment;
 249                  continue; // Skip dispay a comment reply here in order to dispay it after parent comment by function display_comment_replies()
 250              }
 251  
 252              // ------------------ COMMENT INCLUDED HERE ------------------
 253              skin_include( $params['comment_template'], array(
 254                      'Comment'          => & $Comment,
 255                      'comment_start'    => $params['comment_start'],
 256                      'comment_end'      => $params['comment_end'],
 257                      'author_link_text' => $params['author_link_text'],
 258                      'link_to'          => $params['link_to'],        // 'userpage' or 'userurl' or 'userurl>userpage' or 'userpage>userurl'
 259                      'author_link_text' => $params['author_link_text'],
 260                  ) );
 261              // Note: You can customize the default item feedback by copying the generic
 262              // /skins/_item_comment.inc.php file into the current skin folder.
 263              // ---------------------- END OF COMMENT ---------------------
 264  
 265              if( $Blog->get_setting( 'threaded_comments' ) )
 266              {    // Display the comment replies
 267                  display_comment_replies( $Comment->ID, $params );
 268              }
 269          }    // End of comment list loop.
 270          echo $params['comment_list_end'];
 271  
 272  
 273          if( $Blog->get_setting( 'paged_comments' ) )
 274          { // Prev/Next page navigation
 275              $CommentList->page_links( array(
 276                      'page_url' => url_add_tail( $Item->get_permanent_url(), '#comments' ),
 277                  ) );
 278          }
 279  
 280          // Restore "redir" param
 281          forget_param('redir');
 282  
 283          // _______________________________________________________________
 284          // Display count of comments to be moderated:
 285          $Item->feedback_moderation( 'feedbacks', '<div class="moderation_msg"><p>', '</p></div>', '',
 286                  T_('This post has 1 feedback awaiting moderation... %s'),
 287                  T_('This post has %d feedbacks awaiting moderation... %s') );
 288          // _______________________________________________________________
 289      }
 290  }
 291  
 292  // ------------------ COMMENT FORM INCLUDED HERE ------------------
 293  if( $params['disp_comment_form'] )
 294  {
 295      if( $Blog->get_ajax_form_enabled() )
 296      {
 297          // The following params will be piped through the AJAX request...
 298          $json_params = array(
 299              'action' => 'get_comment_form',
 300              'p' => $Item->ID,
 301              'blog' => $Blog->ID,
 302              'disp' => $disp,
 303              'params' => $params );
 304          display_ajax_form( $json_params );
 305      }
 306      else
 307      {
 308          skin_include( '_item_comment_form.inc.php', $params );
 309      }
 310      // Note: You can customize the default item feedback by copying the generic
 311      // /skins/_item_comment_form.inc.php file into the current skin folder.
 312  }
 313  // ---------------------- END OF COMMENT FORM ---------------------
 314  
 315  // ----------- Register for item's comment notification -----------
 316  if( is_logged_in() && $Item->can_comment( NULL ) )
 317  {
 318      global $DB, $htsrv_url;
 319      global $UserSettings;
 320  
 321      $not_subscribed = true;
 322      $creator_User = $Item->get_creator_User();
 323  
 324      if( $Blog->get_setting( 'allow_subscriptions' ) )
 325      {
 326          $sql = 'SELECT count( sub_user_ID ) FROM T_subscriptions
 327                      WHERE sub_user_ID = '.$current_User->ID.' AND sub_coll_ID = '.$Blog->ID.' AND sub_comments <> 0';
 328          if( $DB->get_var( $sql ) > 0 )
 329          {
 330              echo '<p>'.T_( 'You are receiving notifications when anyone comments on any post.' );
 331              echo ' <a href="'.$Blog->get('subsurl').'">'.T_( 'Click here to manage your subscriptions.' ).'</a></p>';
 332              $not_subscribed = false;
 333          }
 334      }
 335  
 336      if( $params['disp_notification'] )
 337      {    // Display notification link
 338          echo $params['notification_before'];
 339  
 340          $notification_icon = get_icon( 'notification' );
 341  
 342          if( $not_subscribed && ( $creator_User->ID == $current_User->ID ) && ( $UserSettings->get( 'notify_published_comments', $current_User->ID ) != 0 ) )
 343          {
 344              echo '<p>'.$notification_icon.' <span>'.$params['notification_text'];
 345              echo ' <a href="'.$Blog->get('subsurl').'">'.T_( 'Click here to manage your subscriptions.' ).'</a></span></p>';
 346              $not_subscribed = false;
 347          }
 348          if( $not_subscribed && $Blog->get_setting( 'allow_item_subscriptions' ) )
 349          {
 350              if( get_user_isubscription( $current_User->ID, $Item->ID ) )
 351              {
 352                  echo '<p>'.$notification_icon.' <span>'.$params['notification_text2'];
 353                  echo ' <a href="'.$samedomain_htsrv_url.'action.php?mname=collections&action=isubs_update&p='.$Item->ID.'&amp;notify=0&amp;'.url_crumb( 'collections_isubs_update' ).'">'.T_( 'Click here to unsubscribe.' ).'</a></span></p>';
 354              }
 355              else
 356              {
 357                  echo '<p>'.$notification_icon.' <span><a href="'.$samedomain_htsrv_url.'action.php?mname=collections&action=isubs_update&p='.$Item->ID.'&amp;notify=1&amp;'.url_crumb( 'collections_isubs_update' ).'">'.$params['notification_text3'].'</a></span></p>';
 358              }
 359          }
 360  
 361          echo $params['notification_after'];
 362      }
 363  }
 364  
 365  
 366  if( $Item->can_see_comments( false ) && ( $params['disp_comments'] || $params['disp_trackbacks'] || $params['disp_pingbacks'] ) )
 367  {    // user is allowed to see comments
 368      // Display link for comments feed:
 369      $Item->feedback_feed_link( '_rss2', '<div class="feedback_feed_msg"><p>', '</p></div>', $params['feed_title'] );
 370  }
 371  
 372  ?>

title

Description

title

Description

title

Description

title

title

Body