b2evolution PHP Cross Reference Blogging Systems

Source: /skins/_item_comment_form.inc.php - 363 lines - 14984 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          'author_link_text'     => 'login',
  33          'textarea_lines'       => 10,
  34          'default_text'         => '',
  35          'preview_block_start'  => '',
  36          'preview_start'        => '<div class="bComment" id="comment_preview">',
  37          'comment_template'     => '_item_comment.inc.php',    // The template used for displaying individual comments (including preview)
  38          'preview_end'          => '</div>',
  39          'preview_block_end'    => '',
  40          'before_comment_error' => '<p><em>',
  41          'comment_closed_text'  => '#',
  42          'after_comment_error'  => '</em></p>',
  43          'before_comment_form'  => '',
  44          'after_comment_form'   => '',
  45          'form_comment_redirect_to' => $Item->get_feedback_url( $disp == 'feedback-popup', '&' ),
  46      ), $params );
  47  
  48  $comment_reply_ID = param( 'reply_ID', 'integer', 0 );
  49  
  50  $email_is_detected = false; // Used when comment contains an email strings
  51  
  52  // Consider comment attachments list empty
  53  $comment_attachments = '';
  54  
  55  /*
  56   * Comment form:
  57   */
  58  $section_title = $params['form_title_start'].$params['form_title_text'].$params['form_title_end'];
  59  if( $params['disp_comment_form'] && $Item->can_comment( $params['before_comment_error'], $params['after_comment_error'], '#', $params['comment_closed_text'], $section_title, $params ) )
  60  { // We want to display the comments form and the item can be commented on:
  61  
  62      echo $params['before_comment_form'];
  63  
  64      // INIT/PREVIEW:
  65      if( $Comment = $Session->get('core.preview_Comment') )
  66      {    // We have a comment to preview
  67          if( $Comment->item_ID == $Item->ID )
  68          { // display PREVIEW:
  69  
  70              // We do not want the current rendered page to be cached!!
  71              if( !empty( $PageCache ) )
  72              {
  73                  $PageCache->abort_collect();
  74              }
  75  
  76              if( $Comment->email_is_detected )
  77              {    // We set it to define a some styles below
  78                  $email_is_detected = true;
  79              }
  80  
  81              if( empty( $Comment->in_reply_to_cmt_ID ) )
  82              { // Display the comment preview here only if this comment is not a reply, otherwise it was already displayed
  83                  // ------------------ PREVIEW COMMENT INCLUDED HERE ------------------
  84                  skin_include( $params['comment_template'], array(
  85                          'Comment'              => & $Comment,
  86                          'comment_block_start'  => $Comment->email_is_detected ? '' : $params['preview_block_start'],
  87                          'comment_start'        => $Comment->email_is_detected ? $params['comment_error_start'] : $params['preview_start'],
  88                          'comment_end'          => $Comment->email_is_detected ? $params['comment_error_end'] : $params['preview_end'],
  89                          'comment_block_end'    => $Comment->email_is_detected ? '' : $params['preview_block_end'],
  90                          'author_link_text'     => $params['author_link_text'],
  91                      ) );
  92                  // Note: You can customize the default item feedback by copying the generic
  93                  // /skins/_item_comment.inc.php file into the current skin folder.
  94                  // ---------------------- END OF PREVIEW COMMENT ---------------------
  95              }
  96  
  97              // Form fields:
  98              $comment_content = $Comment->original_content;
  99              // comment_attachments contains all file IDs that have been attached
 100              $comment_attachments = $Comment->preview_attachments;
 101              // checked_attachments contains all attachment file IDs which checkbox was checked in
 102              $checked_attachments = $Comment->checked_attachments;
 103              // for visitors:
 104              $comment_author = $Comment->author;
 105              $comment_author_email = $Comment->author_email;
 106              $comment_author_url = $Comment->author_url;
 107  
 108              // Display error messages again after preview of comment
 109              global $Messages;
 110              $Messages->display();
 111          }
 112  
 113          // delete any preview comment from session data:
 114          $Session->delete( 'core.preview_Comment' );
 115      }
 116      else
 117      { // New comment:
 118          if( ( $Comment = get_comment_from_session() ) == NULL )
 119          { // there is no saved Comment in Session
 120              $Comment = new Comment();
 121              if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
 122              {    // This page is going into the cache, we don't want personal data cached!!!
 123                  // fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?
 124                  $comment_author = '';
 125                  $comment_author_email = '';
 126                  $comment_author_url = '';
 127              }
 128              else
 129              { // Get params from $_COOKIE
 130                  $comment_author = param_cookie( $cookie_name, 'string', '' );
 131                  $comment_author_email = evo_strtolower( param_cookie( $cookie_email, 'string', '' ) );
 132                  $comment_author_url = param_cookie( $cookie_url, 'string', '' );
 133              }
 134              if( empty($comment_author_url) )
 135              {    // Even if we have a blank cookie, let's reset this to remind the bozos what it's for
 136                  $comment_author_url = 'http://';
 137              }
 138  
 139              $comment_content =  $params['default_text'];
 140          }
 141          else
 142          { // set saved Comment attributes from Session
 143              $comment_content = $Comment->content;
 144              $comment_author = $Comment->author;
 145              $comment_author_email = $Comment->author_email;
 146              $comment_author_url = $Comment->author_url;
 147              // comment_attachments contains all file IDs that have been attached
 148              $comment_attachments = $Comment->preview_attachments;
 149              // checked_attachments contains all attachment file IDs which checkbox was checked in
 150              $checked_attachments = $Comment->checked_attachments;
 151          }
 152      }
 153  
 154      if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
 155      {    // This page is going into the cache, we don't want personal data cached!!!
 156          // fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?
 157      }
 158      else
 159      {
 160          // Get values that may have been passed through after a preview
 161          param( 'comment_cookies', 'integer', NULL );
 162          param( 'comment_allow_msgform', 'integer', NULL ); // checkbox
 163  
 164          if( is_null($comment_cookies) )
 165          { // "Remember me" checked, if remembered before:
 166              $comment_cookies = isset($_COOKIE[$cookie_name]) || isset($_COOKIE[$cookie_email]) || isset($_COOKIE[$cookie_url]);
 167          }
 168      }
 169  
 170      echo $params['form_title_start'];
 171      echo $params['form_title_text'];
 172      echo $params['form_title_end'];
 173  
 174  /*
 175      echo '<script type="text/javascript">
 176  /* <![CDATA[ *
 177  function validateCommentForm(form)
 178  {
 179      if( form.'.$dummy_fields['content'].'.value.replace(/^\s+|\s+$/g,"").length == 0 )
 180      {
 181          alert("'.TS_('Please do not send empty comments.').'");
 182          return false;
 183      }
 184  }
 185  /* ]]> *
 186  </script>';*/
 187  
 188      $Form = new Form( $samedomain_htsrv_url.'comment_post.php', 'bComment_form_id_'.$Item->ID, 'post', NULL, 'multipart/form-data' );
 189  
 190      $Form->switch_template_parts( $params['form_params'] );
 191  
 192      $Form->begin_form( 'bComment', '', array( 'target' => '_self'/*, 'onsubmit' => 'return validateCommentForm(this);'*/ ) );
 193  
 194      // TODO: dh> a plugin hook would be useful here to add something to the top of the Form.
 195      //           Actually, the best would be, if the $Form object could be changed by a plugin
 196      //           before display!
 197  
 198      $Form->add_crumb( 'comment' );
 199      $Form->hidden( 'comment_post_ID', $Item->ID );
 200      if( !empty( $comment_reply_ID ) )
 201      {
 202          $Form->hidden( 'reply_ID', $comment_reply_ID );
 203  
 204          // Link to scroll back up to replying comment
 205          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>';
 206      }
 207      $Form->hidden( 'redirect_to',
 208              // Make sure we get back to the right page (on the right domain)
 209              // fp> TODO: check if we can use the permalink instead but we must check that application wide,
 210              // that is to say: check with the comments in a pop-up etc...
 211              // url_rel_to_same_host(regenerate_url( '', '', $Blog->get('blogurl'), '&' ), $htsrv_url)
 212              // fp> what we need is a regenerate_url that will work in permalinks
 213              // fp> below is a simpler approach:
 214              $params['form_comment_redirect_to']
 215          );
 216  
 217      if( check_user_status( 'is_validated' ) )
 218      { // User is logged in and activated:
 219          $Form->info_field( T_('User'), '<strong>'.$current_User->get_identity_link( array(
 220                  'link_text' => $params['author_link_text'] ) ).'</strong> '
 221                  .get_user_profile_link( ' [', ']', T_('Edit profile') ) );
 222      }
 223      else
 224      { // User is not logged in or not activated:
 225          if( is_logged_in() && empty( $comment_author ) && empty( $comment_author_email ) )
 226          {
 227              $comment_author = $current_User->login;
 228              $comment_author_email = $current_User->email;
 229          }
 230          // Note: we use funky field names to defeat the most basic guestbook spam bots
 231          $Form->text( $dummy_fields[ 'name' ], $comment_author, 40, T_('Name'), '', 100, 'bComment' );
 232  
 233          $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' );
 234  
 235          $Item->load_Blog();
 236          if( $Item->Blog->get_setting( 'allow_anon_url' ) )
 237          {
 238              $Form->text( $dummy_fields[ 'url' ], $comment_author_url, 40, T_('Website'), '<br />'.T_('Your URL will be displayed.'), 100, 'bComment' );
 239          }
 240      }
 241  
 242      if( $Item->can_rate() )
 243      {    // Comment rating:
 244          echo $Form->begin_field( NULL, T_('Your vote'), true );
 245          $Comment->rating_input( array( 'item_ID' => $Item->ID ) );
 246          echo $Form->end_field();
 247      }
 248  
 249      if( !empty($params['policy_text']) )
 250      {    // We have a policy text to display
 251          $Form->info_field( '', $params['policy_text'] );
 252      }
 253  
 254      echo '<div class="comment_toolbars">';
 255      // CALL PLUGINS NOW:
 256      $Plugins->trigger_event( 'DisplayCommentToolbar', array( 'Comment' => & $Comment, 'Item' => & $Item ) );
 257      echo '</div>';
 258  
 259      // Message field:
 260      $note = '';
 261      // $note = T_('Allowed XHTML tags').': '.htmlspecialchars(str_replace( '><',', ', $comment_allowed_tags));
 262      $Form->textarea( $dummy_fields[ 'content' ], $comment_content, $params['textarea_lines'], $params['form_comment_text'], $note, 38, 'bComment' );
 263  
 264      // set b2evoCanvas for plugins
 265      echo '<script type="text/javascript">var b2evoCanvas = document.getElementById( "'.$dummy_fields[ 'content' ].'" );</script>';
 266  
 267      // Attach files:
 268      if( !empty( $comment_attachments ) )
 269      {    // display already attached files checkboxes
 270          $FileCache = & get_FileCache();
 271          $attachments = explode( ',', $comment_attachments );
 272          $final_attachments = explode( ',', $checked_attachments );
 273          // create attachments checklist
 274          $list_options = array();
 275          foreach( $attachments as $attachment_ID )
 276          {
 277              $attachment_File = $FileCache->get_by_ID( $attachment_ID, false );
 278              if( $attachment_File )
 279              {
 280                  // checkbox should be checked only if the corresponding file id is in the final attachments array
 281                  $checked = in_array( $attachment_ID, $final_attachments );
 282                  $list_options[] = array( 'preview_attachment'.$attachment_ID, 1, '', $checked, false, $attachment_File->get( 'name' ) );
 283              }
 284          }
 285          if( !empty( $list_options ) )
 286          {    // display list
 287              $Form->checklist( $list_options, 'comment_attachments', T_( 'Attached files' ) );
 288          }
 289          // memorize all attachments ids
 290          $Form->hidden( 'preview_attachments', $comment_attachments );
 291      }
 292      if( $Item->can_attach() )
 293      {    // Display attach file input field
 294          $Form->input_field( array( 'label' => T_('Attach files'), 'note' => '<br />'.get_upload_restriction(), 'name' => 'uploadfile[]', 'type' => 'file' ) );
 295      }
 296  
 297      $comment_options = array();
 298  
 299      if( ! is_logged_in( false ) )
 300      { // User is not logged in:
 301          $comment_options[] = '<label><input type="checkbox" class="checkbox" name="comment_cookies" tabindex="7"'
 302                                                      .( $comment_cookies ? ' checked="checked"' : '' ).' value="1" /> '.T_('Remember me').'</label>'
 303                                                      .' <span class="note">('.T_('For my next comment on this site').')</span>';
 304          // TODO: If we got info from cookies, Add a link called "Forget me now!" (without posting a comment).
 305  
 306          $msgform_class_start = '';
 307          $msgform_class_end = '';
 308          if( $email_is_detected )
 309          {    // Set a class when comment contains a email
 310              $msgform_class_start = '<div class="comment_recommended_option">';
 311              $msgform_class_end = '</div>';
 312          }
 313  
 314          $comment_options[] = $msgform_class_start.
 315                                                      '<label><input type="checkbox" class="checkbox" name="comment_allow_msgform" tabindex="8"'
 316                                                      .( $comment_allow_msgform ? ' checked="checked"' : '' ).' value="1" /> '.T_('Allow message form').'</label>'
 317                                                      .' <span class="note">('.T_('Allow users to contact me through a message form -- Your email will <strong>not</strong> be revealed!').')</span>'.
 318                                                      $msgform_class_end;
 319          // 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".
 320      }
 321  
 322      if( ! empty($comment_options) )
 323      {
 324          echo $Form->begin_field( NULL, T_('Options'), true );
 325          echo implode( '<br />', $comment_options );
 326          echo $Form->end_field();
 327      }
 328  
 329      // Display renderers
 330      $comment_renderer_checkboxes = $Plugins->get_renderer_checkboxes( array( 'default' ), array( 'Blog' => & $Blog, 'setting_name' => 'coll_apply_comment_rendering' ) );
 331      if( !empty( $comment_renderer_checkboxes ) )
 332      {
 333          $Form->begin_fieldset();
 334          echo '<div class="label">'.T_('Text Renderers').':</div>';
 335          echo '<div class="input">'.$comment_renderer_checkboxes.'</div>';
 336          $Form->end_fieldset();
 337      }
 338  
 339      $Plugins->trigger_event( 'DisplayCommentFormFieldset', array( 'Form' => & $Form, 'Item' => & $Item ) );
 340  
 341      $Form->begin_fieldset();
 342          echo '<div class="input">';
 343  
 344          $preview_text = ( $Item->can_attach() ) ? T_('Preview/Add file') : T_('Preview');
 345          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[save]', 'class' => 'submit', 'value' => $params['form_submit_text'], 'tabindex' => 10 ) );
 346          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[preview]', 'class' => 'preview', 'value' => $preview_text, 'tabindex' => 9 ) );
 347  
 348          $Plugins->trigger_event( 'DisplayCommentFormButton', array( 'Form' => & $Form, 'Item' => & $Item ) );
 349  
 350          echo '</div>';
 351      $Form->end_fieldset();
 352      ?>
 353  
 354      <div class="clear"></div>
 355  
 356      <?php
 357      $Form->end_form();
 358  
 359      echo $params['after_comment_form'];
 360  
 361      echo_comment_reply_js( $Item );
 362  }
 363  ?>

title

Description

title

Description

title

Description

title

title

Body