b2evolution PHP Cross Reference Blogging Systems

Source: /skins/forums/_item_comment_form.inc.php - 415 lines - 17456 bytes - Text - Print

Description: This is the template that displays the comment form for a post

   1  <?php
   2  /**

   3   * This is the template that displays the comment form for a post

   4   *

   5   * This file is not meant to be called directly.

   6   *

   7   * b2evolution - {@link http://b2evolution.net/}

   8   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   9   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

  10   *

  11   * @package evoskins

  12   */
  13  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  14  
  15  global $cookie_name, $cookie_email, $cookie_url;
  16  global $comment_allowed_tags;
  17  global $comment_cookies, $comment_allow_msgform;
  18  global $checked_attachments; // Set this var as global to use it in the method $Item->can_attach()

  19  global $PageCache;
  20  global $Blog, $dummy_fields;
  21  
  22  // Default params:

  23  $params = array_merge( array(
  24          'disp_comment_form'       =>    true,
  25          'form_title_start'     => '<h3>',
  26          'form_title_end'       => '</h3>',
  27          'form_title_text'      => T_('Leave a comment'),
  28          'form_comment_text'    => T_('Comment text'),
  29          'form_submit_text'     => T_('Send comment'),
  30          'form_params'          => array(), // Use to change a structre of form, i.e. fieldstart, fieldend and etc.
  31          'policy_text'          => '',
  32          'textarea_lines'       => 10,
  33          'default_text'         => '',
  34          'preview_block_start'  => '',
  35          'preview_start'        => '<div class="bComment" id="comment_preview">',
  36          'comment_template'     => '_item_comment.inc.php',    // The template used for displaying individual comments (including preview)
  37          'preview_end'          => '</div>',
  38          'preview_block_end'    => '',
  39          'before_comment_error' => '<p><em>',
  40          'comment_closed_text'  => '#',
  41          'after_comment_error'  => '</em></p>',
  42          'before_comment_form'  => '',
  43          'after_comment_form'   => '',
  44      ), $params );
  45  
  46  $comment_reply_ID = param( 'reply_ID', 'integer', 0 );
  47  
  48  $email_is_detected = false; // Used when comment contains an email strings

  49  
  50  // Consider comment attachments list empty

  51  $comment_attachments = '';
  52  
  53  /*

  54   * Comment form:

  55   */
  56  $section_title = $params['form_title_start'].$params['form_title_text'].$params['form_title_end'];
  57  if( $params['disp_comment_form'] && $Item->can_comment( $params['before_comment_error'], $params['after_comment_error'], '#', $params['comment_closed_text'], $section_title, $params ) )
  58  { // We want to display the comments form and the item can be commented on:
  59  
  60      echo $params['before_comment_form'];
  61  
  62      // INIT/PREVIEW:

  63      if( $Comment = $Session->get('core.preview_Comment') )
  64      {    // We have a comment to preview
  65          if( $Comment->item_ID == $Item->ID )
  66          { // display PREVIEW:
  67  
  68              // We do not want the current rendered page to be cached!!

  69              if( !empty( $PageCache ) )
  70              {
  71                  $PageCache->abort_collect();
  72              }
  73  
  74              if( $Comment->email_is_detected )
  75              {    // We set it to define a some styles below
  76                  $email_is_detected = true;
  77              }
  78  
  79              if( empty( $Comment->in_reply_to_cmt_ID ) )
  80              { // Display the comment preview here only if this comment is not a reply, otherwise it was already displayed
  81                  // ------------------ PREVIEW COMMENT INCLUDED HERE ------------------

  82                  skin_include( $params['comment_template'], array(
  83                          'Comment'              => & $Comment,
  84                          'comment_block_start'  => $Comment->email_is_detected ? '' : $params['preview_block_start'],
  85                          'comment_start'        => $Comment->email_is_detected ? $params['comment_error_start'] : $params['preview_start'],
  86                          'comment_end'          => $Comment->email_is_detected ? $params['comment_error_end'] : $params['preview_end'],
  87                          'comment_block_end'    => $Comment->email_is_detected ? '' : $params['preview_block_end'],
  88                      ) );
  89                  // Note: You can customize the default item feedback by copying the generic

  90                  // /skins/_item_comment.inc.php file into the current skin folder.

  91                  // ---------------------- END OF PREVIEW COMMENT ---------------------

  92              }
  93  
  94              // Form fields:

  95              $comment_content = $Comment->original_content;
  96              // comment_attachments contains all file IDs that have been attached

  97              $comment_attachments = $Comment->preview_attachments;
  98              // checked_attachments contains all attachment file IDs which checkbox was checked in

  99              $checked_attachments = $Comment->checked_attachments;
 100              // for visitors:

 101              $comment_author = $Comment->author;
 102              $comment_author_email = $Comment->author_email;
 103              $comment_author_url = $Comment->author_url;
 104  
 105              // Display error messages again after preview of comment

 106              global $Messages;
 107              $Messages->display();
 108          }
 109  
 110          // delete any preview comment from session data:

 111          $Session->delete( 'core.preview_Comment' );
 112      }
 113      else
 114      { // New comment:
 115          if( ( $Comment = get_comment_from_session() ) == NULL )
 116          { // there is no saved Comment in Session
 117              $Comment = new Comment();
 118              if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
 119              {    // This page is going into the cache, we don't want personal data cached!!!
 120                  // fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?

 121                  $comment_author = '';
 122                  $comment_author_email = '';
 123                  $comment_author_url = '';
 124              }
 125              else
 126              { // Try to get params from $_COOKIE through the param() function
 127                  $comment_author = param_cookie( $cookie_name, 'string', '' );
 128                  $comment_author_email = evo_strtolower( param_cookie( $cookie_email, 'string', '' ) );
 129                  $comment_author_url = param_cookie( $cookie_url, 'string', '' );
 130              }
 131              if( empty($comment_author_url) )
 132              {    // Even if we have a blank cookie, let's reset this to remind the bozos what it's for
 133                  $comment_author_url = 'http://';
 134              }
 135  
 136              $comment_content =  $params['default_text'];
 137          }
 138          else
 139          { // set saved Comment attributes from Session
 140              $comment_content = $Comment->content;
 141              $comment_author = $Comment->author;
 142              $comment_author_email = $Comment->author_email;
 143              $comment_author_url = $Comment->author_url;
 144              // comment_attachments contains all file IDs that have been attached

 145              $comment_attachments = $Comment->preview_attachments;
 146              // checked_attachments contains all attachment file IDs which checkbox was checked in

 147              $checked_attachments = $Comment->checked_attachments;
 148          }
 149  
 150          if( $params['comment_mode'] == 'quote' )
 151          {    // These params go from ajax form loading, Used to reply with quote
 152              set_param( 'mode', $params['comment_mode'] );
 153              set_param( 'qc', $params['comment_qc'] );
 154              set_param( 'qp', $params['comment_qp'] );
 155              set_param( $dummy_fields[ 'content' ], $params[ $dummy_fields[ 'content' ] ] );
 156          }
 157  
 158          $mode = param( 'mode', 'string' );
 159          if( $mode == 'quote' )
 160          { // Quote for comment/post
 161              $comment_content = param( $dummy_fields[ 'content' ], 'html' );
 162              $quoted_comment_ID = param( 'qc', 'integer', 0 );
 163              $quoted_post_ID = param( 'qp', 'integer', 0 );
 164              if( !empty( $quoted_comment_ID ) )
 165              {
 166                  $CommentCache = & get_CommentCache();
 167                  $quoted_Comment = & $CommentCache->get_by_ID( $quoted_comment_ID, false );
 168                  $quoted_Item = $quoted_Comment->get_Item();
 169                  if( $quoted_User = $quoted_Comment->get_author_User() )
 170                  { // User is registered
 171                      $quoted_login = $quoted_User->login;
 172                  }
 173                  else
 174                  { // Anonymous user
 175                      $quoted_login = $quoted_Comment->get_author_name();
 176                  }
 177                  $quoted_content = $quoted_Comment->get( 'content' );
 178                  $quoted_ID = 'c'.$quoted_Comment->ID;
 179              }
 180              else if( !empty( $quoted_post_ID ) )
 181              {
 182                  $ItemCache = & get_ItemCache();
 183                  $quoted_Item = & $ItemCache->get_by_ID( $quoted_post_ID, false );
 184                  $quoted_login = $quoted_Item->get_creator_login();
 185                  $quoted_content = $quoted_Item->get( 'content' );
 186                  $quoted_ID = 'p'.$quoted_Item->ID;
 187              }
 188  
 189              if( !empty( $quoted_Item ) )
 190              {    // Format content for editing, if we were not already in editing...
 191                  $comment_title = '';
 192                  $comment_content .= '[quote=@'.$quoted_login.'#'.$quoted_ID.']'.strip_tags($quoted_content).'[/quote]';
 193  
 194                  $Plugins_admin = & get_Plugins_admin();
 195                  $quoted_Item->load_Blog();
 196                  $plugins_params = array( 'object_type' => 'Comment', 'object_Blog' => & $quoted_Item->Blog );
 197                  $Plugins_admin->unfilter_contents( $comment_title /* by ref */, $comment_content /* by ref */, $quoted_Item->get_renderers_validated(), $plugins_params );
 198              }
 199          }
 200      }
 201  
 202      if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
 203      {    // This page is going into the cache, we don't want personal data cached!!!
 204          // fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?

 205      }
 206      else
 207      {
 208          // Get values that may have been passed through after a preview

 209          param( 'comment_cookies', 'integer', NULL );
 210          param( 'comment_allow_msgform', 'integer', NULL ); // checkbox

 211  
 212          if( is_null($comment_cookies) )
 213          { // "Remember me" checked, if remembered before:
 214              $comment_cookies = isset($_COOKIE[$cookie_name]) || isset($_COOKIE[$cookie_email]) || isset($_COOKIE[$cookie_url]);
 215          }
 216      }
 217  
 218      echo $params['form_title_start'];
 219      echo $params['form_title_text'];
 220      echo $params['form_title_end'];
 221  
 222  /*

 223      echo '<script type="text/javascript">

 224  /* <![CDATA[ *

 225  function validateCommentForm(form)

 226  {

 227      if( form.'.$dummy_fields['content'].'.value.replace(/^\s+|\s+$/g,"").length == 0 )

 228      {

 229          alert("'.TS_('Please do not send empty comments.').'");

 230          return false;

 231      }

 232  }

 233  /* ]]> *

 234  </script>';*/
 235  
 236      $Form = new Form( $samedomain_htsrv_url.'comment_post.php', 'bComment_form_id_'.$Item->ID, 'post', NULL, 'multipart/form-data' );
 237  
 238      $Form->switch_template_parts( $params['form_params'] );
 239  
 240      $Form->begin_form( 'bComment', '', array( 'target' => '_self'/*, 'onsubmit' => 'return validateCommentForm(this);'*/ ) );
 241  
 242      // TODO: dh> a plugin hook would be useful here to add something to the top of the Form.

 243      //           Actually, the best would be, if the $Form object could be changed by a plugin

 244      //           before display!

 245  
 246      $Form->add_crumb( 'comment' );
 247      $Form->hidden( 'comment_post_ID', $Item->ID );
 248      if( !empty( $comment_reply_ID ) )
 249      {
 250          $Form->hidden( 'reply_ID', $comment_reply_ID );
 251  
 252          // Link to scroll back up to replying comment

 253          echo '<a href="'.url_add_param( $Item->get_permanent_url(), 'reply_ID='.$comment_reply_ID.'&amp;redir=no' ).'#c'.$comment_reply_ID.'" class="comment_reply_current" rel="'.$comment_reply_ID.'">'.T_('You are currently replying to a specific comment').'</a>';
 254      }
 255      $Form->hidden( 'redirect_to',
 256              // Make sure we get back to the right page (on the right domain)

 257              // fp> TODO: check if we can use the permalink instead but we must check that application wide,

 258              // that is to say: check with the comments in a pop-up etc...

 259              // url_rel_to_same_host(regenerate_url( '', '', $Blog->get('blogurl'), '&' ), $htsrv_url)

 260              // fp> what we need is a regenerate_url that will work in permalinks

 261              // fp> below is a simpler approach:

 262              $Item->get_feedback_url( $disp == 'feedback-popup', '&' )
 263          );
 264  
 265      if( check_user_status( 'is_validated' ) )
 266      { // User is logged in and activated:
 267          $Form->info_field( T_('User'), '<strong>'.$current_User->get_identity_link( array( 'link_text' => 'login' ) ).'</strong>'
 268              .' '.get_user_profile_link( ' [', ']', T_('Edit profile') ) );
 269      }
 270      else
 271      { // User is not logged in or not activated:
 272          if( is_logged_in() && empty( $comment_author ) && empty( $comment_author_email ) )
 273          {
 274              $comment_author = $current_User->login;
 275              $comment_author_email = $current_User->email;
 276          }
 277          // Note: we use funky field names to defeat the most basic guestbook spam bots

 278          $Form->text( $dummy_fields[ 'name' ], $comment_author, 40, T_('Name'), '', 100, 'bComment' );
 279  
 280          $Form->text( $dummy_fields[ 'email' ], $comment_author_email, 40, T_('Email'), '<br />'.T_('Your email address will <strong>not</strong> be revealed on this site.'), 100, 'bComment' );
 281  
 282          $Item->load_Blog();
 283          if( $Item->Blog->get_setting( 'allow_anon_url' ) )
 284          {
 285              $Form->text( $dummy_fields[ 'url' ], $comment_author_url, 40, T_('Website'), '<br />'.T_('Your URL will be displayed.'), 100, 'bComment' );
 286          }
 287      }
 288  
 289      if( $Item->can_rate() )
 290      {    // Comment rating:
 291          echo $Form->begin_field( NULL, T_('Your vote'), true );
 292          $Comment->rating_input( array( 'item_ID' => $Item->ID ) );
 293          echo $Form->end_field();
 294      }
 295  
 296      if( !empty($params['policy_text']) )
 297      {    // We have a policy text to display
 298          $Form->info_field( '', $params['policy_text'] );
 299      }
 300  
 301      ob_start();
 302      echo '<div class="comment_toolbars">';
 303      // CALL PLUGINS NOW:

 304      $Plugins->trigger_event( 'DisplayCommentToolbar', array( 'Comment' => & $Comment, 'Item' => & $Item ) );
 305      echo '</div>';
 306      $plugins_toolbar = ob_get_clean();
 307  
 308      $Form->switch_template_parts( array(
 309              'inputstart' => '<td class="row2 left">'.$plugins_toolbar,
 310          ) );
 311      // Message field:

 312      $note = '';
 313      // $note = T_('Allowed XHTML tags').': '.htmlspecialchars(str_replace( '><',', ', $comment_allowed_tags));

 314      $Form->textarea( $dummy_fields[ 'content' ], htmlspecialchars_decode( $comment_content ), $params['textarea_lines'], $params['form_comment_text'], $note, 38, 'bComment' );
 315      $Form->switch_template_parts( $params['form_params'] );
 316  
 317      // Display renderers

 318      $comment_renderer_checkboxes = $Plugins->get_renderer_checkboxes( array( 'default' ), array( 'Blog' => & $Blog, 'setting_name' => 'coll_apply_comment_rendering' ) );
 319      if( !empty( $comment_renderer_checkboxes ) )
 320      {
 321          $Form->info( T_('Text Renderers'), $comment_renderer_checkboxes );
 322      }
 323  
 324      // set b2evoCanvas for plugins

 325      echo '<script type="text/javascript">var b2evoCanvas = document.getElementById( "'.$dummy_fields[ 'content' ].'" );</script>';
 326  
 327      // Attach files:

 328      if( !empty( $comment_attachments ) )
 329      {    // display already attached files checkboxes
 330          $FileCache = & get_FileCache();
 331          $attachments = explode( ',', $comment_attachments );
 332          $final_attachments = explode( ',', $checked_attachments );
 333          // create attachments checklist

 334          $list_options = array();
 335          foreach( $attachments as $attachment_ID )
 336          {
 337              $attachment_File = $FileCache->get_by_ID( $attachment_ID, false );
 338              if( $attachment_File )
 339              {
 340                  // checkbox should be checked only if the corresponding file id is in the final attachments array

 341                  $checked = in_array( $attachment_ID, $final_attachments );
 342                  $list_options[] = array( 'preview_attachment'.$attachment_ID, 1, '', $checked, false, $attachment_File->get( 'name' ) );
 343              }
 344          }
 345          if( !empty( $list_options ) )
 346          {    // display list
 347              $Form->checklist( $list_options, 'comment_attachments', T_( 'Attached files' ) );
 348          }
 349          // memorize all attachments ids

 350          $Form->hidden( 'preview_attachments', $comment_attachments );
 351      }
 352      if( $Item->can_attach() )
 353      {    // Display attach file input field
 354          $Form->input_field( array( 'label' => T_('Attach files'), 'note' => '<br />'.get_upload_restriction(), 'name' => 'uploadfile[]', 'type' => 'file', 'size' => '30' ) );
 355      }
 356  
 357      $comment_options = array();
 358  
 359      if( ! is_logged_in( false ) )
 360      { // User is not logged in:
 361          $comment_options[] = '<label><input type="checkbox" class="checkbox" name="comment_cookies" tabindex="7"'
 362                                                      .( $comment_cookies ? ' checked="checked"' : '' ).' value="1" /> '.T_('Remember me').'</label>'
 363                                                      .' <span class="note">('.T_('For my next comment on this site').')</span>';
 364          // TODO: If we got info from cookies, Add a link called "Forget me now!" (without posting a comment).

 365  
 366          $msgform_class_start = '';
 367          $msgform_class_end = '';
 368          if( $email_is_detected )
 369          {    // Set a class when comment contains a email
 370              $msgform_class_start = '<div class="comment_recommended_option">';
 371              $msgform_class_end = '</div>';
 372          }
 373  
 374          $comment_options[] = $msgform_class_start.
 375                                                      '<label><input type="checkbox" class="checkbox" name="comment_allow_msgform" tabindex="8"'
 376                                                      .( $comment_allow_msgform ? ' checked="checked"' : '' ).' value="1" /> '.T_('Allow message form').'</label>'
 377                                                      .' <span class="note">('.T_('Allow users to contact me through a message form -- Your email will <strong>not</strong> be revealed!').')</span>'.
 378                                                      $msgform_class_end;
 379          // TODO: If we have an email in a cookie, Add links called "Add a contact icon to all my previous comments" and "Remove contact icon from all my previous comments".

 380      }
 381  
 382      if( ! empty($comment_options) )
 383      {
 384          echo $Form->begin_field( NULL, T_('Options'), true );
 385          echo implode( '<br />', $comment_options );
 386          echo $Form->end_field();
 387      }
 388  
 389      $Plugins->trigger_event( 'DisplayCommentFormFieldset', array( 'Form' => & $Form, 'Item' => & $Item ) );
 390  
 391      $Form->begin_fieldset();
 392          echo '<div class="input">';
 393  
 394          $preview_text = ( $Item->can_attach() ) ? T_('Preview/Add file') : T_('Preview');
 395          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[preview]', 'class' => 'preview', 'value' => $preview_text, 'tabindex' => 9 ) );
 396          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[save]', 'class' => 'submit', 'value' => $params['form_submit_text'], 'tabindex' => 10 ) );
 397  
 398          $Plugins->trigger_event( 'DisplayCommentFormButton', array( 'Form' => & $Form, 'Item' => & $Item ) );
 399  
 400          echo '</div>';
 401      $Form->end_fieldset();
 402      ?>
 403  
 404      <div class="clear"></div>
 405  
 406      <?php
 407      $Form->end_form();
 408  
 409      echo $params['after_comment_form'];
 410  
 411      echo_comment_reply_js( $Item );
 412  }
 413  
 414  echo_comment_moderate_js();
 415  ?>

title

Description

title

Description

title

Description

title

title

Body