b2evolution PHP Cross Reference Blogging Systems

Source: /inc/skins/skins.ctrl.php - 261 lines - 7605 bytes - Text - Print

Description: This file implements the UI controller for skins management. b2evolution - {@link http://b2evolution.net/}

   1  <?php
   2  /**
   3   * This file implements the UI controller for skins management.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   *
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
   9   *
  10   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  11   *
  12   * {@internal Open Source relicensing agreement:
  13   * }}
  14   *
  15   * @package admin
  16   *
  17   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  18   * @author fplanque: Francois PLANQUE.
  19   *
  20   * @version $Id: skins.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  21   */
  22  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  23  
  24  // Memorize this as the last "tab" used in the Blog Settings:
  25  $UserSettings->set( 'pref_coll_settings_tab', 'manage_skins' );
  26  $UserSettings->dbupdate();
  27  
  28  load_funcs( 'skins/_skin.funcs.php' );
  29  
  30  // Check permission to display:
  31  $current_User->check_perm( 'options', 'view', true );
  32  
  33  
  34  param( 'action', 'string', 'list' );
  35  
  36  param( 'redirect_to', 'url', '?ctrl=skins' );
  37  
  38  if( param( 'skin_ID', 'integer', '', true) )
  39  {// Load file type:
  40      $SkinCache = & get_SkinCache();
  41      if( ($edited_Skin = & $SkinCache->get_by_ID( $skin_ID, false )) === false )
  42      {    // We could not find the skin to edit:
  43          unset( $edited_Skin );
  44          forget_param( 'skin_ID' );
  45          $Messages->head = T_('Cannot edit skin!');
  46          $Messages->add( T_('Requested skin is not installed any longer.'), 'error' );
  47          $action = 'nil';
  48      }
  49  }
  50  
  51  
  52  /**
  53   * Perform action:
  54   */
  55  switch( $action )
  56  {
  57      case 'create':
  58          param( 'skin_folder', 'string', true );
  59          // Check validity of requested skin name:
  60          if( preg_match( '~([^-A-Za-z0-9._]|\.\.)~', $skin_folder ) )
  61          {
  62              debug_die( 'The requested skin name is invalid.' );
  63          }
  64  
  65          // Check that this action request is not a CSRF hacked request:
  66          $Session->assert_received_crumb( 'skin' );
  67  
  68          // Check permission to edit:
  69          $current_User->check_perm( 'options', 'edit', true );
  70  
  71          // CREATE NEW SKIN:
  72          $edited_Skin = & skin_install( $skin_folder );
  73  
  74          $Messages->add( T_('Skin has been installed.'), 'success' );
  75  
  76          // We want to highlight the edited object on next list display:
  77          $Session->set( 'fadeout_array', array( 'skin_ID' => array($edited_Skin->ID) ) );
  78  
  79          // PREVENT RELOAD & Switch to list mode:
  80          header_redirect( $redirect_to );
  81          break;
  82  
  83  
  84      case 'update':
  85          // Update skin properties:
  86  
  87          // Check that this action request is not a CSRF hacked request:
  88          $Session->assert_received_crumb( 'skin' );
  89  
  90          // Check permission:
  91          $current_User->check_perm( 'options', 'edit', true );
  92  
  93          // Make sure we got an skin_ID:
  94          param( 'skin_ID', 'integer', true );
  95  
  96          // load data from request
  97          if( $edited_Skin->load_from_Request() )
  98          {    // We could load data from form without errors:
  99              // Update in DB:
 100              $edited_Skin->dbupdate();
 101              $Messages->add( T_('Skin properties updated.'), 'success' );
 102  
 103              // We want to highlight the edited object on next list display:
 104              $Session->set( 'fadeout_array', array( 'skin_ID' => array($edited_Skin->ID) ) );
 105  
 106              // Redirect so that a reload doesn't write to the DB twice:
 107              header_redirect( $redirect_to, 303 ); // Will EXIT
 108              // We have EXITed already at this point!!
 109          }
 110          break;
 111  
 112  
 113      case 'reload':
 114          // Reload containers:
 115  
 116          // Check that this action request is not a CSRF hacked request:
 117          $Session->assert_received_crumb( 'skin' );
 118  
 119           // Check permission:
 120          $current_User->check_perm( 'options', 'edit', true );
 121  
 122          // Make sure we got an skin_ID:
 123          param( 'skin_ID', 'integer', true );
 124  
 125          // Look for containers in skin file:
 126          $edited_Skin->discover_containers();
 127  
 128          // Save to DB:
 129          $edited_Skin->db_save_containers();
 130  
 131          // We want to highlight the edited object on next list display:
 132           $Session->set( 'fadeout_array', array( 'skin_ID' => array($edited_Skin->ID) ) );
 133  
 134          // Redirect so that a reload doesn't write to the DB twice:
 135          header_redirect( $redirect_to, 303 ); // Will EXIT
 136          // We have EXITed already at this point!!
 137          break;
 138  
 139  
 140      case 'delete':
 141          // Uninstall a skin:
 142  
 143          // Check that this action request is not a CSRF hacked request:
 144          $Session->assert_received_crumb( 'skin' );
 145  
 146          // Check permission:
 147          $current_User->check_perm( 'options', 'edit', true );
 148  
 149          // Make sure we got an skin_ID:
 150          param( 'skin_ID', 'integer', true );
 151  
 152          if( param( 'confirm', 'integer', 0 ) )
 153          { // confirmed, Delete from DB:
 154              $msg = sprintf( T_('Skin &laquo;%s&raquo; uninstalled.'), $edited_Skin->dget('name') );
 155              $edited_Skin->dbdelete( true );
 156              //unset( $edited_Skin );
 157              //forget_param( 'skin_ID' );
 158              $Messages->add( $msg, 'success' );
 159  
 160              // Redirect so that a reload doesn't write to the DB twice:
 161              header_redirect( $redirect_to, 303 ); // Will EXIT
 162              // We have EXITed already at this point!!
 163          }
 164          else
 165          {    // not confirmed, Check for restrictions:
 166              if( ! $edited_Skin->check_delete( sprintf( T_('Cannot uninstall skin &laquo;%s&raquo;'), $edited_Skin->dget('name') ) ) )
 167              {    // There are restrictions:
 168                  $action = 'edit';
 169              }
 170          }
 171  
 172          break;
 173  
 174  
 175      case 'reset':
 176          // Reset settings to default values:
 177  
 178          // Check that this action request is not a CSRF hacked request:
 179          $Session->assert_received_crumb( 'skin' );
 180  
 181           // Check permission:
 182          $current_User->check_perm( 'options', 'edit', true );
 183  
 184          // Make sure we got skin and blog IDs:
 185          param( 'skin_ID', 'integer', true );
 186          param( 'blog', 'integer', true );
 187  
 188          // At some point we may want to remove skin settings from all blogs
 189          $DB->query('DELETE FROM T_coll_settings
 190                                   WHERE cset_coll_ID = '.$DB->quote($blog).'
 191                                                AND cset_name REGEXP "^skin'.$skin_ID.'_"');
 192  
 193          $Messages->add( T_('Skin params have been reset to defaults.'), 'success' );
 194  
 195          // Redirect so that a reload doesn't write to the DB twice:
 196          header_redirect( '?ctrl=coll_settings&tab=skin&blog='.$blog, 303 ); // Will EXIT
 197          // We have EXITed already at this point!!
 198          break;
 199  }
 200  
 201  
 202  $AdminUI->set_path( 'blogs', 'skin', 'manage_skins' );
 203  
 204  
 205  /**
 206   * Display page header, menus & messages:
 207   */
 208  $AdminUI->set_coll_list_params( 'blog_properties', 'edit',
 209                                              array( 'ctrl' => 'skins' ),
 210                                              T_('All'), '?ctrl=collections&amp;blog=0' );
 211  
 212  
 213  $AdminUI->breadcrumbpath_init();
 214  $AdminUI->breadcrumbpath_add( T_('Settings'), '?ctrl=coll_settings&amp;blog=$blog$' );
 215  $AdminUI->breadcrumbpath_add( T_('Skin'), '?ctrl=coll_settings&amp;tab=skin&amp;blog=$blog$' );
 216  $AdminUI->breadcrumbpath_add( T_('Skin configuration'), '?ctrl=skins' );
 217  
 218  
 219  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 220  $AdminUI->disp_html_head();
 221  
 222  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 223  $AdminUI->disp_body_top();
 224  
 225  // Begin payload block:
 226  $AdminUI->disp_payload_begin();
 227  
 228  /**
 229   * Display Payload:
 230   */
 231  switch( $action )
 232  {
 233      case 'new':
 234          // Display VIEW:
 235          $AdminUI->disp_view( 'skins/views/_skin_list_available.view.php' );
 236          break;
 237  
 238      case 'delete':
 239          // We need to ask for confirmation:
 240          $edited_Skin->confirm_delete(
 241                  sprintf( T_('Uninstall skin &laquo;%s&raquo;?'),  $edited_Skin->dget( 'name' ) ),
 242                  'skin', $action, get_memorized( 'action' ) );
 243      case 'edit':
 244      case 'update':    // we return in this state after a validation error
 245          // Display VIEW:
 246          $AdminUI->disp_view( 'skins/views/_skin.form.php' );
 247          break;
 248  
 249      case 'list':
 250          // Display VIEW:
 251          $AdminUI->disp_view( 'skins/views/_skin_list.view.php' );
 252          break;
 253  }
 254  
 255  // End payload block:
 256  $AdminUI->disp_payload_end();
 257  
 258  // Display body bottom, debug info and close </html>:
 259  $AdminUI->disp_global_footer();
 260  
 261  ?>

title

Description

title

Description

title

Description

title

title

Body