b2evolution PHP Cross Reference Blogging Systems

Source: /inc/slugs/slugs.ctrl.php - 192 lines - 5274 bytes - Text - Print

Description: This file implements the slugs control. b2evolution - {@link http://b2evolution.net/} Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   1  <?php
   2  /**
   3   * This file implements the slugs control.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * @package admin
  11   *
  12   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  13   * @author evfy-asimo: Attila Simo.
  14   *
  15   * @version $Id: slugs.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  16   */
  17  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  18  
  19  load_class( 'slugs/model/_slug.class.php', 'Slug' );
  20  
  21  /**
  22   * @var User
  23   */
  24  global $current_User;
  25  
  26  // Check minimum permission:
  27  $current_User->check_perm( 'slugs', 'view', true );
  28  
  29  $AdminUI->set_path( 'options', 'slugs' );
  30  
  31  param_action( 'list' );
  32  
  33  param( 'slug_filter', 'string', '', true );
  34  param( 'slug_item_ID', 'string', '', true );
  35  // other slug object type IDs come here
  36  
  37  if( param( 'slug_ID', 'integer', '', true) )
  38  {// Load file type:
  39      $SlugCache = & get_SlugCache();
  40      if( ($edited_Slug = & $SlugCache->get_by_ID( $slug_ID, false )) === false )
  41      {    // We could not find the goal to edit:
  42          unset( $edited_Slug );
  43          forget_param( 'slug_ID' );
  44          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Slug') ), 'error' );
  45          $action = 'nil';
  46      }
  47  }
  48  
  49  switch( $action )
  50  {
  51      case 'list':
  52          break;
  53  
  54      case 'new':
  55          $edited_Slug = new Slug();
  56          break;
  57  
  58      case 'edit':
  59          // Slug edit form...:
  60          // Make sure we got a slug_ID:
  61          param( 'slug_ID', 'string', true );
  62           break;
  63   
  64      case 'create':
  65          // Create new slug...
  66          $edited_Slug = new Slug();
  67  
  68          // Check that this action request is not a CSRF hacked request:
  69          $Session->assert_received_crumb( 'slug' );
  70  
  71          // Check that current user has permission to create slugs:
  72          $current_User->check_perm( 'slugs', 'edit', true );
  73  
  74          // load data from request
  75          if( $edited_Slug->load_from_Request() )
  76          {    // We could load data from form without errors:
  77              // Insert in DB:
  78              $edited_Slug->dbinsert();
  79              $Messages->add( T_('New slug created.'), 'success' );
  80  
  81              // Redirect so that a reload doesn't write to the DB twice:
  82              header_redirect( '?ctrl=slugs', 303 ); // Will EXIT
  83              // We have EXITed already at this point!!
  84          }
  85          $action = 'new';
  86          break;
  87  
  88      case 'update':
  89          // Update slug...
  90          
  91          // Check that this action request is not a CSRF hacked request:
  92          $Session->assert_received_crumb( 'slug' );
  93  
  94          // Check that current user has permission to edit slugs:
  95          $current_User->check_perm( 'slugs', 'edit', true );
  96  
  97          // Make sure we got an slug_ID:
  98          param( 'slug_ID', 'integer', true );
  99  
 100          // load data from request
 101          if( $edited_Slug->load_from_Request() )
 102          {    // We could load data from form without errors:
 103              // Update slug in DB:
 104              $edited_Slug->dbupdate();
 105              $Messages->add( T_('Slug updated.'), 'success' );
 106  
 107              // Redirect so that a reload doesn't write to the DB twice:
 108              header_redirect( '?ctrl=slugs', 303 ); // Will EXIT
 109              // We have EXITed already at this point!!
 110          }
 111          $action = 'edit';
 112          break;
 113  
 114      case 'delete':
 115          // Delete slug:
 116  
 117          // Check that this action request is not a CSRF hacked request:
 118          $Session->assert_received_crumb( 'slug' );
 119  
 120          // Check that current user has permission to edit slugs:
 121          $current_User->check_perm( 'slugs', 'edit', true );
 122  
 123          // Make sure we got an slug_ID:
 124          param( 'slug_ID', 'integer', true );
 125  
 126          if( param( 'confirm', 'integer', 0 ) )
 127          { // confirmed, Delete from DB:
 128              $msg = sprintf( T_('Slug &laquo;%s&raquo; deleted.'), $edited_Slug->dget('title') );
 129              $edited_Slug->dbdelete( true );
 130              unset( $edited_Slug );
 131              forget_param( 'slug_ID' );
 132              $Messages->add( $msg, 'success' );
 133              // Redirect so that a reload doesn't write to the DB twice:
 134              header_redirect( regenerate_url( 'action', '', '', '&' ), 303 ); // Will EXIT
 135              // We have EXITed already at this point!!
 136          }
 137          else
 138          {    // not confirmed, Check for restrictions:
 139              if( ! $edited_Slug->check_delete( sprintf( T_('Cannot delete slug &laquo;%s&raquo;'), $edited_Slug->dget('title') ), array(), true ) )
 140              {    // There are restrictions:
 141                  $action = 'list';
 142              }
 143          }
 144          break;
 145  }
 146  
 147  
 148  $AdminUI->breadcrumbpath_init( false );
 149  $AdminUI->breadcrumbpath_add( T_('System'), '?ctrl=system' );
 150  $AdminUI->breadcrumbpath_add( T_('Slugs'), '?ctrl=slugs' );
 151  
 152  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 153  $AdminUI->disp_html_head();
 154  
 155  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 156  $AdminUI->disp_body_top();
 157  
 158  $AdminUI->disp_payload_begin();
 159  
 160  /**
 161   * Display payload:
 162   */
 163  switch( $action )
 164  {
 165      case 'nil':
 166          // Do nothing
 167          break;
 168  
 169      case 'new':
 170      case 'edit':
 171          // Display slug form
 172          $AdminUI->disp_view( 'slugs/views/_slug.form.php' );
 173          break;
 174  
 175      case 'delete':
 176          // We need to ask for confirmation:
 177          $edited_Slug->confirm_delete(
 178                  sprintf( T_('Delete slug &laquo;%s&raquo;?'), $edited_Slug->dget('title') ),
 179                  'slug', $action, get_memorized( 'action' ) );
 180          // NO BREAK
 181      case 'list':
 182          // list slugs:
 183          $AdminUI->disp_view( 'slugs/views/_slug_list.view.php' );
 184          break;
 185  }
 186  
 187  $AdminUI->disp_payload_end();
 188  
 189  // Display body bottom, debug info and close </html>:
 190  $AdminUI->disp_global_footer();
 191  
 192  ?>

title

Description

title

Description

title

Description

title

title

Body