[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/skins/ -> _msgform.php (source)

   1  <?php
   2  /**

   3   * This is the template that displays the message user form

   4   *

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

   6   * It is meant to be called by an include in the main.page.php template.

   7   * To display a feedback, you should call a stub AND pass the right parameters

   8   * For example: /blogs/index.php?disp=msgform&recipient_id=n

   9   * Note: don't code this URL by hand, use the template functions to generate it!

  10   *

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

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

  13   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

  14   *

  15   * @package evoskins

  16   *

  17   * @todo dh> A user/blog might want to accept only mails from logged in users (fp>yes!)

  18   * @todo dh> For logged in users the From name and address should be not editable/displayed

  19   *           (the same as when commenting). (fp>yes!!!)

  20   */
  21  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  22  
  23  global $cookie_name, $cookie_email;
  24  
  25  global $DB;
  26  
  27  // Parameters

  28  $redirect_to = param( 'redirect_to', 'string', '' ); // pass-through (hidden field)

  29  $recipient_id = param( 'recipient_id', 'integer', '' );
  30  $post_id = param( 'post_id', 'integer', '' );
  31  $comment_id = param( 'comment_id', 'integer', '' );
  32  $subject = param( 'subject', 'string', '' );
  33  
  34  
  35  // User's preferred name or the stored value in her cookie (from commenting):

  36  $email_author = '';
  37  if( is_logged_in() )
  38  {
  39      $email_author = $current_User->get_preferred_name();
  40  }
  41  if( ! strlen($email_author) && isset($_COOKIE[$cookie_name]) )
  42  {
  43      $email_author = trim($_COOKIE[$cookie_name]);
  44  }
  45  
  46  // User's email address or the stored value in her cookie (from commenting):

  47  $email_author_address = '';
  48  if( is_logged_in() )
  49  {
  50      $email_author_address = $current_User->email;
  51  }
  52  if( ! strlen($email_author_address) && isset($_COOKIE[$cookie_email]) )
  53  {
  54      $email_author_address = trim($_COOKIE[$cookie_email]);
  55  }
  56  
  57  $recipient_User = NULL;
  58  $Comment = NULL;
  59  
  60  
  61  // Get the name of the recipient and check if he wants to receive mails through the message form

  62  
  63  
  64  if( ! empty($recipient_id) )
  65  { // If the email is to a registered user get the email address from the users table
  66      $UserCache = & get_Cache( 'UserCache' );
  67      $recipient_User = & $UserCache->get_by_ID( $recipient_id );
  68  
  69      if( $recipient_User )
  70      {
  71          if( empty($recipient_User->allow_msgform) )
  72          { // should be prevented by UI
  73              echo '<p class="error">The user does not want to receive emails through the message form.</p>';
  74              return;
  75          }
  76          $recipient_name = $recipient_User->get('preferredname');
  77          $recipient_address = $recipient_User->get('email');
  78      }
  79  }
  80  elseif( ! empty($comment_id) )
  81  { // If the email is through a comment, get the email address from the comments table (or the linked member therein):
  82  
  83      // Load comment from DB:

  84      $row = $DB->get_row( '
  85          SELECT *
  86            FROM T_comments
  87           WHERE comment_ID = '.$comment_id, ARRAY_A );
  88  
  89      if( $row )
  90      {
  91          $Comment = & new Comment( $row );
  92  
  93          if( $comment_author_User = & $Comment->get_author_User() )
  94          { // Source comment is from a registered user:
  95              if( ! $comment_author_User->allow_msgform )
  96              {
  97                  echo '<p class="error">The user does not want to get contacted through the message form.</p>'; // should be prevented by UI

  98                  return;
  99              }
 100          }
 101          elseif( ! $Comment->allow_msgform )
 102          { // Source comment is from an anonymou suser:
 103              echo '<p class="error">This commentator does not want to get contacted through the message form.</p>'; // should be prevented by UI

 104              return;
 105          }
 106  
 107          $recipient_name = $Comment->get_author_name();
 108          $recipient_address = $Comment->get_author_email();
 109      }
 110  }
 111  
 112  if( empty($recipient_address) )
 113  {    // We should never have called this in the first place!
 114      // Could be that commenter did not provide an email, etc...

 115      echo 'No recipient specified!';
 116      return;
 117  }
 118  
 119  // Get the suggested subject for the email:

 120  if( empty($subject) )
 121  { // no subject provided by param:
 122      if( ! empty($comment_id) )
 123      {
 124          $row = $DB->get_row( '
 125              SELECT post_title
 126                FROM T_items__item, T_comments
 127               WHERE comment_ID = '.$DB->quote($comment_id).'
 128                 AND post_ID = comment_post_ID' );
 129  
 130          if( $row )
 131          {
 132              $subject = T_('Re:').' '.sprintf( /* TRANS: Used as mail subject; %s gets replaced by an item's title */ T_( 'Comment on %s' ), $row->post_title );
 133          }
 134      }
 135  
 136      if( empty($subject) && ! empty($post_id) )
 137      {
 138          $row = $DB->get_row( '
 139                  SELECT post_title
 140                    FROM T_items__item
 141                   WHERE post_ID = '.$post_id );
 142          if( $row )
 143          {
 144              $subject = T_('Re:').' '.$row->post_title;
 145          }
 146      }
 147  }
 148  ?>
 149  
 150  <!-- form to send email -->
 151  <?php
 152  
 153  $Form = new Form( $htsrv_url.'message_send.php' );
 154      $Form->begin_form( 'bComment' );
 155  
 156      if( !empty( $Blog ) )
 157      {
 158          $Form->hidden( 'blog', $Blog->ID );
 159      }
 160      $Form->hidden( 'recipient_id', $recipient_id );
 161      $Form->hidden( 'post_id', $post_id );
 162      $Form->hidden( 'comment_id', $comment_id );
 163      $Form->hidden( 'redirect_to', url_rel_to_same_host($redirect_to, $htsrv_url) );
 164  
 165      ?>
 166  
 167      <fieldset>
 168          <div class="label"><label><?php echo T_('To')?>:</label></div>
 169          <div class="info"><strong><?php echo $recipient_name;?></strong></div>
 170      </fieldset>
 171  
 172      <?php
 173      // Note: we use funky field name in order to defeat the most basic guestbook spam bots:

 174      $Form->text( 'd', $email_author, 40, T_('From'),  T_('Your name.'), 50, 'bComment' );
 175      $Form->text( 'f', $email_author_address, 40, T_('Email'), T_('Your email address. (Will <strong>not</strong> be displayed on this site.)'), 100, 'bComment' );
 176      $Form->text( 'g', $subject, 40, T_('Subject'), T_('Subject of email message.'), 255, 'bComment' );
 177      $Form->textarea( 'h', '', 15, T_('Message'), T_('Plain text only.'), 40, 'bComment' );
 178  
 179      $Plugins->trigger_event( 'DisplayMessageFormFieldset', array( 'Form' => & $Form,
 180          'recipient_ID' => & $recipient_id, 'item_ID' => $post_id, 'comment_ID' => $comment_id ) );
 181  
 182      $Form->begin_fieldset();
 183      ?>
 184          <div class="input">
 185              <?php
 186              $Form->button_input( array( 'name' => 'submit_message_'.$recipient_id, 'class' => 'submit', 'value' => T_('Send message') ) );
 187  
 188              $Plugins->trigger_event( 'DisplayMessageFormButton', array( 'Form' => & $Form,
 189                  'recipient_ID' => & $recipient_id, 'item_ID' => $post_id, 'comment_ID' => $comment_id ) );
 190              ?>
 191          </div>
 192          <?php
 193      $Form->end_fieldset();
 194      ?>
 195  
 196      <div class="clear"></div>
 197  
 198  <?php
 199  $Form->end_form();
 200  
 201  
 202  /*

 203   * $Log: _msgform.php,v $

 204   * Revision 1.39  2007/09/22 19:23:56  fplanque

 205   * various fixes & enhancements

 206   *

 207   * Revision 1.38  2007/09/17 18:03:52  blueyed

 208   * Fixed cases for no $Blog, e.g. with contact.php

 209   *

 210   * Revision 1.37  2007/09/08 14:50:02  fplanque

 211   * FIX

 212   *

 213   * Revision 1.36  2007/07/09 20:15:59  fplanque

 214   * doc

 215   *

 216   * Revision 1.35  2007/07/09 20:03:59  blueyed

 217   * - Prefer current User's name+email instead of the ones from comment remember-me cookies

 218   * - todos

 219   *

 220   * Revision 1.34  2007/06/30 01:25:15  fplanque

 221   * fixes

 222   *

 223   * Revision 1.33  2007/05/14 02:43:06  fplanque

 224   * Started renaming tables. There probably won't be a better time than 2.0.

 225   *

 226   * Revision 1.32  2007/04/26 00:11:04  fplanque

 227   * (c) 2007

 228   *

 229   * Revision 1.31  2007/03/18 01:39:55  fplanque

 230   * renamed _main.php to main.page.php to comply with 2.0 naming scheme.

 231   * (more to come)

 232   *

 233   * Revision 1.30  2006/10/15 21:30:46  blueyed

 234   * Use url_rel_to_same_host() for redirect_to params.

 235   *

 236   * Revision 1.29  2006/08/19 07:56:32  fplanque

 237   * Moved a lot of stuff out of the automatic instanciation in _main.inc

 238   *

 239   * Revision 1.28  2006/07/06 19:56:29  fplanque

 240   * no message

 241   *

 242   * Revision 1.27  2006/06/16 20:34:20  fplanque

 243   * basic spambot defeating

 244   *

 245   * Revision 1.26  2006/05/30 21:51:03  blueyed

 246   * Lazy-instantiate "expensive" properties of Comment and Item.

 247   *

 248   * Revision 1.25  2006/05/19 18:15:06  blueyed

 249   * Merged from v-1-8 branch

 250   *

 251   * Revision 1.24.2.1  2006/05/19 15:06:26  fplanque

 252   * dirty sync

 253   *

 254   * Revision 1.24  2006/05/06 21:52:50  blueyed

 255   * trans

 256   *

 257   * Revision 1.23  2006/05/04 14:28:15  blueyed

 258   * Fix/enhanced

 259   *

 260   * Revision 1.22  2006/04/20 16:31:30  fplanque

 261   * comment moderation (finished for 1.8)

 262   *

 263   * Revision 1.21  2006/04/11 21:22:26  fplanque

 264   * partial cleanup

 265   *

 266   */
 267  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics