[ 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/inc/comments/ -> _comments.ctrl.php (source)

   1  <?php
   2  /**

   3   * This file implements the UI controller for managing comments.

   4   *

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

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

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

   8   *

   9   * {@internal Open Source relicensing agreement:

  10   * }}

  11   *

  12   * @package admin

  13   *

  14   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  15   * @author fplanque: Francois PLANQUE.

  16   *

  17   * @package admin

  18   *

  19   * @version $Id: _comments.ctrl.php,v 1.3 2007/11/02 01:51:55 fplanque Exp $

  20   */
  21  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  22  
  23  /**

  24   * @var AdminUI

  25   */
  26  global $AdminUI;
  27  
  28  /**

  29   * @var UserSettings

  30   */
  31  global $UserSettings;
  32  
  33  param( 'action', 'string', 'list' );
  34  
  35  /*

  36   * Init the objects we want to work on.

  37   */
  38  switch( $action )
  39  {
  40      case 'edit':
  41      case 'update':
  42      case 'publish':
  43      case 'deprecate':
  44      case 'delete':
  45          param( 'comment_ID', 'integer', true );
  46          $edited_Comment = Comment_get_by_ID( $comment_ID );
  47  
  48          $edited_Comment_Item = & $edited_Comment->get_Item();
  49          set_working_blog( $edited_Comment_Item->blog_ID );
  50          $BlogCache = & get_Cache( 'BlogCache' );
  51          $Blog = & $BlogCache->get_by_ID( $blog );
  52  
  53          // Check permission:

  54          $current_User->check_perm( 'blog_comments', 'edit', true, $blog );
  55  
  56          // Where are we going to redirect to?

  57          param( 'redirect_to', 'string', url_add_param( $admin_url, 'ctrl=items&blog='.$blog.'&p='.$edited_Comment->item_ID, '&' ) );
  58          break;
  59  
  60      case 'list':
  61        // Check permission:

  62        $selected = autoselect_blog( 'blog_comments', 'edit' );
  63          if( ! $selected )
  64          { // No blog could be selected
  65              $Messages->add( T_('You have no permission to edit comments.' ), 'error' );
  66              $action = 'nil';
  67          }
  68          elseif( set_working_blog( $selected ) )    // set $blog & memorize in user prefs
  69          {    // Selected a new blog:
  70              $BlogCache = & get_Cache( 'BlogCache' );
  71              $Blog = & $BlogCache->get_by_ID( $blog );
  72          }
  73          break;
  74  
  75      default:
  76          debug_die( 'unhandled action 1' );
  77  }
  78  
  79  
  80  $AdminUI->set_path( 'items' );    // Sublevel may be attached below

  81  
  82  /**

  83   * Perform action:

  84   */
  85  switch( $action )
  86  {
  87       case 'nil':
  88          // Do nothing

  89          break;
  90  
  91  
  92      case 'edit':
  93          $AdminUI->title = $AdminUI->title_titlearea = T_('Editing comment').' #'.$edited_Comment->ID;
  94          break;
  95  
  96  
  97      case 'update':
  98          // fp> TODO: $edited_Comment->load_from_Request( true );

  99  
 100          if( ! $edited_Comment->get_author_User() )
 101          { // If this is not a member comment
 102              param( 'newcomment_author', 'string', true );
 103              param( 'newcomment_author_email', 'string' );
 104              param( 'newcomment_author_url', 'string' );
 105              $edited_Comment->set( 'author', $newcomment_author );
 106              $edited_Comment->set( 'author_email', $newcomment_author_email );
 107              $edited_Comment->set( 'author_url', $newcomment_author_url );
 108  
 109              // CHECK url

 110              if( $error = validate_url( $newcomment_author_url, $allowed_uri_scheme ) )
 111              {
 112                  $Messages->add( T_('Supplied URL is invalid: ').$error, 'error' );
 113              }
 114          }
 115          param( 'content', 'html' );
 116          param( 'post_autobr', 'integer', ($comments_use_autobr == 'always') ? 1 : 0 );
 117  
 118          // CHECK and FORMAT content

 119          $content = format_to_post( $content, $post_autobr, 0); // We are faking this NOT to be a comment

 120          $edited_Comment->set( 'content', $content );
 121  
 122          if( $current_User->check_perm( 'edit_timestamp' ))
 123          { // We use user date
 124              param_date( 'comment_issue_date', T_('Please enter a valid comment date.'), true );
 125              if( strlen(get_param('comment_issue_date')) )
 126              { // only set it, if a date was given:
 127                  param_time( 'comment_issue_time' );
 128                  $edited_Comment->set( 'date', form_date( get_param( 'comment_issue_date' ), get_param( 'comment_issue_time' ) ) ); // TODO: cleanup...

 129              }
 130          }
 131  
 132          param( 'comment_rating', 'integer', NULL );
 133          $edited_Comment->set_from_Request( 'rating' );
 134  
 135          param( 'comment_status', 'string', 'published' );
 136          $edited_Comment->set_from_Request( 'status', 'comment_status' );
 137  
 138          if( $Messages->count('error') )
 139          {    // There have been some validation errors:
 140              break;
 141          }
 142  
 143          // UPDATE DB:

 144          $edited_Comment->dbupdate();    // Commit update to the DB

 145  
 146          $Messages->add( T_('Comment has been updated.'), 'success' );
 147  
 148          header_redirect( $redirect_to );
 149          /* exited */

 150          break;
 151  
 152  
 153      case 'publish':
 154          $edited_Comment->set('status', 'published' );
 155  
 156          $edited_Comment->dbupdate();    // Commit update to the DB

 157  
 158          $Messages->add( T_('Comment has been published.'), 'success' );
 159  
 160          header_redirect( $redirect_to );
 161          /* exited */

 162          break;
 163  
 164  
 165      case 'deprecate':
 166          $edited_Comment->set('status', 'deprecated' );
 167  
 168          $edited_Comment->dbupdate();    // Commit update to the DB

 169  
 170          $Messages->add( T_('Comment has been deprecated.'), 'success' );
 171  
 172          header_redirect( $redirect_to );
 173          /* exited */

 174          break;
 175  
 176  
 177      case 'delete':
 178          // fp> TODO: non JS confirm

 179  
 180          // Delete from DB:

 181          $edited_Comment->dbdelete();
 182  
 183          $Messages->add( T_('Comment has been deleted.'), 'success' );
 184  
 185          header_redirect( $redirect_to );
 186          break;
 187  
 188  
 189      case 'list':
 190          /*

 191           * Latest comments:

 192           */
 193          $AdminUI->title = $AdminUI->title_titlearea = T_('Latest comments');
 194  
 195          param( 'show_statuses', 'array', array(), true );    // Array of cats to restrict to

 196  
 197          // Generate available blogs list:

 198          $blogListButtons = $AdminUI->get_html_collection_list( 'blog_comments', 'edit',
 199                          $pagenow.'?ctrl=comments&amp;blog=%d', NULL, '' );
 200  
 201          /*

 202           * Add sub menu entries:

 203           * We do this here instead of _header because we need to include all filter params into regenerate_url()

 204           */
 205          attach_browse_tabs();
 206  
 207          $AdminUI->append_path_level( 'comments' );
 208  
 209          /*

 210           * List of comments to display:

 211           */
 212          $CommentList = & new CommentList( $Blog, "'comment','trackback','pingback'", $show_statuses, '',    '',    'DESC',    '',    20 );
 213          break;
 214  
 215  
 216      default:
 217          debug_die( 'unhandled action 2' );
 218  }
 219  
 220  
 221  /*

 222   * Page navigation:

 223   */
 224  
 225  $AdminUI->set_path( 'items', 'comments' );
 226  
 227  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)

 228  $AdminUI->disp_html_head();
 229  
 230  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)

 231  $AdminUI->disp_body_top();
 232  
 233  /**

 234   * Display payload:

 235   */
 236  switch( $action )
 237  {
 238      case 'nil':
 239          // Do nothing

 240          break;
 241  
 242  
 243      case 'edit':
 244      case 'update':    // on error
 245          // Begin payload block:

 246          $AdminUI->disp_payload_begin();
 247  
 248          // Display VIEW:

 249          $AdminUI->disp_view( 'comments/views/_comment.form.php' );
 250  
 251  
 252          // End payload block:

 253          $AdminUI->disp_payload_end();
 254          break;
 255  
 256  
 257      case 'list':
 258      default:
 259          // Begin payload block:

 260          $AdminUI->disp_payload_begin();
 261  
 262          // Display VIEW:

 263          $AdminUI->disp_view( 'comments/views/_browse_comments.view.php' );
 264  
 265          // End payload block:

 266          $AdminUI->disp_payload_end();
 267          break;
 268  }
 269  
 270  // Display body bottom, debug info and close </html>:

 271  $AdminUI->disp_global_footer();
 272  
 273  
 274  /*

 275   * $Log: _comments.ctrl.php,v $

 276   * Revision 1.3  2007/11/02 01:51:55  fplanque

 277   * comment ratings

 278   *

 279   * Revision 1.2  2007/09/04 19:51:27  fplanque

 280   * in-context comment editing

 281   *

 282   * Revision 1.1  2007/06/25 10:59:39  fplanque

 283   * MODULES (refactored MVC)

 284   *

 285   * Revision 1.9  2007/05/13 18:49:54  fplanque

 286   * made autoselect_blog() more robust under PHP4

 287   *

 288   * Revision 1.8  2007/05/09 01:01:32  fplanque

 289   * permissions cleanup

 290   *

 291   * Revision 1.7  2007/04/26 00:11:09  fplanque

 292   * (c) 2007

 293   *

 294   * Revision 1.6  2007/03/07 02:37:52  fplanque

 295   * OMG I decided that pregenerating the menus was getting to much of a PITA!

 296   * It's a zillion problems with the permissions.

 297   * This will be simplified a lot. Enough of these crazy stuff.

 298   *

 299   * Revision 1.5  2006/12/26 00:55:58  fplanque

 300   * wording

 301   *

 302   * Revision 1.4  2006/12/18 03:20:41  fplanque

 303   * _header will always try to set $Blog.

 304   * controllers can use valid_blog_requested() to make sure we have one

 305   * controllers should call set_working_blog() to change $blog, so that it gets memorized in the user settings

 306   *

 307   * Revision 1.3  2006/12/17 23:42:38  fplanque

 308   * Removed special behavior of blog #1. Any blog can now aggregate any other combination of blogs.

 309   * Look into Advanced Settings for the aggregating blog.

 310   * There may be side effects and new bugs created by this. Please report them :]

 311   *

 312   * Revision 1.2  2006/12/12 02:47:47  fplanque

 313   * Completed comment controller

 314   *

 315   * Revision 1.1  2006/12/12 02:01:52  fplanque

 316   * basic comment controller

 317   *

 318   */
 319  ?>


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