b2evolution PHP Cross Reference Blogging Systems

Source: /skins/touch/_item_comment_form.inc.php - 357 lines - 15079 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          'after_comment_error'  => '</em></p>',
  42          'before_comment_form'  => '',
  43          'after_comment_form'   => '',
  44      ), $params );
  45  
  46  echo '<div id="textinputwrap">';
  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'], '#', '#', $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 comment 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.p.value.replace(/^\s+|\s+$/g,"").length == 0 )

 180      {

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

 182          return false;

 183      }

 184  }/* ]]> *

 185  </script>';*/
 186  
 187      $Form = new Form( $samedomain_htsrv_url.'comment_post.php', 'bComment_form_id_'.$Item->ID, 'post', NULL, 'multipart/form-data' );
 188  
 189      $Form->switch_template_parts( $params['form_params'] );
 190  
 191      $Form->begin_form( 'bComment', '', array( 'target' => '_self', /*'onsubmit' => 'return validateCommentForm(this);'*/ ) );
 192  
 193      // TODO: dh> a plugin hook would be useful here to add something to the top of the Form.

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

 195      //           before display!

 196  
 197      $Form->add_crumb( 'comment' );
 198      $Form->hidden( 'comment_post_ID', $Item->ID );
 199      if( !empty( $comment_reply_ID ) )
 200      {
 201          $Form->hidden( 'reply_ID', $comment_reply_ID );
 202  
 203          // Link to scroll back up to replying comment

 204          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>';
 205      }
 206      $Form->hidden( 'redirect_to',
 207              // Make sure we get back to the right page (on the right domain)

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

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

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

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

 212              // fp> below is a simpler approach:

 213              $Item->get_feedback_url( $disp == 'feedback-popup', '&' )
 214          );
 215  
 216      if( check_user_status( 'is_validated' ) )
 217      { // User is logged in and activated:
 218          $Form->info_field( T_('User'), '<strong>'.$current_User->get_identity_link( array(
 219                  'link_text' => $params['author_link_text'] ) ).'</strong> '
 220                  .get_user_profile_link( ' [', ']', T_('Edit profile') ) );
 221      }
 222      else
 223      { // User is not logged in or not activated:
 224          if( is_logged_in() && empty( $comment_author ) && empty( $comment_author_email ) )
 225          {
 226              $comment_author = $current_User->login;
 227              $comment_author_email = $current_User->email;
 228          }
 229          // Note: we use funky field names to defeat the most basic guestbook spam bots

 230          $Form->text( $dummy_fields[ 'name' ], $comment_author, 40, T_('Name'), '', 100, 'bComment' );
 231  
 232          $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' );
 233  
 234          $Item->load_Blog();
 235          if( $Item->Blog->get_setting( 'allow_anon_url' ) )
 236          {
 237              $Form->text( $dummy_fields[ 'url' ], $comment_author_url, 40, T_('Website'), '<br />'.T_('Your URL will be displayed.'), 100, 'bComment' );
 238          }
 239      }
 240  
 241      if( $Item->can_rate() )
 242      {    // Comment rating:
 243          echo $Form->begin_field( NULL, T_('Your vote'), true );
 244          $Comment->rating_input( array( 'item_ID' => $Item->ID ) );
 245          echo $Form->end_field();
 246      }
 247  
 248      if( !empty($params['policy_text']) )
 249      {    // We have a policy text to display
 250          $Form->info_field( '', $params['policy_text'] );
 251      }
 252  
 253      echo '<div class="comment_toolbars">';
 254      // CALL PLUGINS NOW:

 255      $Plugins->trigger_event( 'DisplayCommentToolbar', array( 'Comment' => & $Comment, 'Item' => & $Item ) );
 256      echo '</div>';
 257  
 258      // Message field:

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

 261      $Form->textarea( $dummy_fields[ 'content' ], $comment_content, $params['textarea_lines'], $params['form_comment_text'], $note, 38, 'bComment' );
 262  
 263      // set b2evoCanvas for plugins

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

 267      if( !empty( $comment_attachments ) )
 268      {    // display already attached files checkboxes
 269          $FileCache = & get_FileCache();
 270          $attachments = explode( ',', $comment_attachments );
 271          $final_attachments = explode( ',', $checked_attachments );
 272          // create attachments checklist

 273          $list_options = array();
 274          foreach( $attachments as $attachment_ID )
 275          {
 276              $attachment_File = $FileCache->get_by_ID( $attachment_ID, false );
 277              if( $attachment_File )
 278              {
 279                  // checkbox should be checked only if the corresponding file id is in the final attachments array

 280                  $checked = in_array( $attachment_ID, $final_attachments );
 281                  $list_options[] = array( 'preview_attachment'.$attachment_ID, 1, '', $checked, false, $attachment_File->get( 'name' ) );
 282              }
 283          }
 284          if( !empty( $list_options ) )
 285          {    // display list
 286              $Form->checklist( $list_options, 'comment_attachments', T_( 'Attached files' ) );
 287          }
 288          // memorize all attachments ids

 289          $Form->hidden( 'preview_attachments', $comment_attachments );
 290      }
 291      if( $Item->can_attach() )
 292      {    // Display attach file input field
 293          $Form->input_field( array( 'label' => T_('Attach files'), 'note' => '<br />'.get_upload_restriction(), 'name' => 'uploadfile[]', 'type' => 'file', 'size' => '30' ) );
 294      }
 295  
 296      $comment_options = array();
 297  
 298      if( ! is_logged_in( false ) )
 299      { // User is not logged in:
 300          $comment_options[] = '<label><input type="checkbox" class="checkbox" name="comment_cookies" tabindex="7"'
 301                                                      .( $comment_cookies ? ' checked="checked"' : '' ).' value="1" /> '.T_('Remember me').'</label>'
 302                                                      .' <span class="note">('.T_('For my next comment on this site').')</span>';
 303          // TODO: If we got info from cookies, Add a link called "Forget me now!" (without posting a comment).

 304  
 305          $msgform_class_start = '';
 306          $msgform_class_end = '';
 307          if( $email_is_detected )
 308          {    // Set a class when comment contains a email
 309              $msgform_class_start = '<div class="comment_recommended_option">';
 310              $msgform_class_end = '</div>';
 311          }
 312  
 313          $comment_options[] = $msgform_class_start.
 314                                                      '<label><input type="checkbox" class="checkbox" name="comment_allow_msgform" tabindex="8"'
 315                                                      .( $comment_allow_msgform ? ' checked="checked"' : '' ).' value="1" /> '.T_('Allow message form').'</label>'
 316                                                      .' <span class="note">('.T_('Allow users to contact me through a message form -- Your email will <strong>not</strong> be revealed!').')</span>'.
 317                                                      $msgform_class_end;
 318          // 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".

 319      }
 320  
 321      // Display renderers

 322      $comment_renderer_checkboxes = $Plugins->get_renderer_checkboxes( array( 'default' ), array( 'Blog' => & $Blog, 'setting_name' => 'coll_apply_comment_rendering' ) );
 323      if( !empty( $comment_renderer_checkboxes ) )
 324      {
 325          $Form->begin_fieldset();
 326          echo '<div class="label">'.T_('Text Renderers').':</div>';
 327          echo '<div class="input">';
 328          echo $comment_renderer_checkboxes;
 329          echo '</div>';
 330          $Form->end_fieldset();
 331      }
 332  
 333      $Plugins->trigger_event( 'DisplayCommentFormFieldset', array( 'Form' => & $Form, 'Item' => & $Item ) );
 334  
 335      $Form->begin_fieldset();
 336          echo '<div class="input">';
 337  
 338          $preview_text = ( $Item->can_attach() ) ? T_('Preview/Add file') : T_('Preview');
 339          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[save]', 'class' => 'submit', 'value' => $params['form_submit_text'], 'tabindex' => 10 ) );
 340          $Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[preview]', 'class' => 'preview', 'value' => $preview_text, 'tabindex' => 9 ) );
 341  
 342          $Plugins->trigger_event( 'DisplayCommentFormButton', array( 'Form' => & $Form, 'Item' => & $Item ) );
 343  
 344          echo '</div>';
 345      $Form->end_fieldset();
 346      ?>
 347  
 348      <div class="clear"></div>
 349  
 350      <?php
 351      $Form->end_form();
 352  
 353      echo $params['after_comment_form'];
 354  
 355      echo_comment_reply_js( $Item );
 356  }
 357  ?>

title

Description

title

Description

title

Description

title

title

Body