b2evolution PHP Cross Reference Blogging Systems

Source: /inc/tools/tools.ctrl.php - 395 lines - 11466 bytes - Text - Print

Description: This file implements the UI controller for additional tools.

   1  <?php
   2  /**
   3   * This file implements the UI controller for additional tools.
   4   *
   5   * b2evolution - {@link http://b2evolution.net/}
   6   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   8   *
   9   * @package admin
  10   * @author blueyed: Daniel HAHLER
  11   *
  12   * @version $Id: tools.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  13   */
  14  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  15  
  16  
  17  load_funcs('plugins/_plugin.funcs.php');
  18  load_funcs('tools/model/_dbmaintenance.funcs.php');
  19  load_funcs('tools/model/_tool.funcs.php');
  20  
  21  // load item class
  22  load_class( 'items/model/_item.class.php', 'Item' );
  23  
  24  param( 'tab', 'string', '', true );
  25  param( 'tab3', 'string', 'tools', true );
  26  
  27  $tab_Plugin = NULL;
  28  $tab_plugin_ID = false;
  29  
  30  if( ! empty($tab) )
  31  {    // We have requested a tab which is handled by a plugin:
  32      if( preg_match( '~^plug_ID_(\d+)$~', $tab, $match ) )
  33      { // Instanciate the invoked plugin:
  34          $tab_plugin_ID = $match[1];
  35          $tab_Plugin = & $Plugins->get_by_ID( $match[1] );
  36          if( ! $tab_Plugin )
  37          { // Plugin does not exist
  38              $Messages->add( sprintf( T_( 'The plugin with ID %d could not get instantiated.' ), $tab_plugin_ID ), 'error' );
  39              $tab_plugin_ID = false;
  40              $tab_Plugin = false;
  41              $tab = '';
  42          }
  43          else
  44          {
  45              $Plugins->call_method_if_active( $tab_plugin_ID, 'AdminTabAction', $params = array() );
  46          }
  47      }
  48      else
  49      {
  50          $tab = '';
  51          $Messages->add( 'Invalid sub-menu!' ); // Should need no translation, prevented by GUI
  52      }
  53  }
  54  
  55  // Highlight the requested tab (if valid):
  56  $AdminUI->set_path( 'options', 'misc', !empty( $tab ) ? $tab : $tab3 );
  57  
  58  
  59  if( empty($tab) )
  60  {    // "Main tab" actions:
  61      if( param( 'action', 'string', '' ) )
  62      {
  63          // Check that this action request is not a CSRF hacked request:
  64          $Session->assert_received_crumb( 'tools' );
  65  
  66          // fp> TODO: have an option to only PRUNE files older than for example 30 days
  67          $current_User->check_perm('options', 'edit', true);
  68      }
  69  
  70      set_max_execution_time(0);
  71  
  72      $Plugins->trigger_event( 'AdminToolAction' );
  73  
  74      switch( $action )
  75      {
  76          case 'del_itemprecache':
  77              // Clear pre-renderered item cache (DB)
  78              dbm_delete_itemprecache();
  79              break;
  80  
  81          case 'del_commentprecache':
  82              // Clear pre-renderered comment cache (DB)
  83              $DB->query('DELETE FROM T_comments__prerendering WHERE 1=1');
  84  
  85              $Messages->add( sprintf( T_('Removed %d cached entries.'), $DB->rows_affected ), 'success' );
  86              break;
  87  
  88          case 'del_pagecache':
  89              // Delete the page cache /blogs/cache
  90              dbm_delete_pagecache();
  91              break;
  92  
  93          case 'del_filecache':
  94              // delete the thumbnail cahces .evocache
  95              dbm_delete_filecache();
  96              break;
  97  
  98          case 'repair_cache':
  99              // Repair cache
 100              dbm_repair_cache();
 101              break;
 102  
 103          case 'optimize_tables': // Optimize MyISAM & InnoDB tables
 104          case 'check_tables':    // Check ALL database tables
 105          case 'analyze_tables':  // Analize ALL database tables
 106              $template_action = $action;
 107              break;
 108  
 109          case 'find_broken_posts':
 110              // Find all broken posts that have no matching category
 111              dbm_find_broken_posts();
 112              break;
 113  
 114          case 'find_broken_slugs':
 115              // Find all broken slugs that have no matching target post
 116              dbm_find_broken_slugs();
 117              break;
 118  
 119          case 'delete_orphan_comment_uploads':
 120              // delete orphan comment upload, older than 24 hours
 121              dbm_delete_orphan_comment_uploads();
 122              break;
 123  
 124          case 'delete_orphan_files':
 125              // delete orphan File objects with no matching file on disk
 126          case 'delete_orphan_file_roots':
 127              // delete orphan file roots with no matching Blog or User entry in the database
 128              $template_action = $action;
 129              break;
 130  
 131          case 'prune_hits_sessions':
 132              // Prune old hits & sessions
 133              load_class( 'sessions/model/_hitlist.class.php', 'Hitlist' );
 134              Hitlist::dbprune(); // will prune once per day, according to Settings
 135              break;
 136  
 137          case 'create_sample_comments':
 138              $blog_ID = param( 'blog_ID', 'string', 0 );
 139              $num_comments = param( 'num_comments', 'string', 0 );
 140              $num_posts = param( 'num_posts', 'string', 0 );
 141  
 142              if( ! ( param_check_number( 'blog_ID', T_('Blog ID must be a number'), true ) &&
 143                  param_check_number( 'num_comments', T_('Comments per post must be a number'), true ) &&
 144                  param_check_number( 'num_posts', T_('"How many posts" field must be a number'), true ) ) )
 145              { // param errors
 146                  $action = 'show_create_comments';
 147                  break;
 148              }
 149  
 150              // check blog_ID
 151              $BlogCache = & get_BlogCache();
 152              $selected_Blog = $BlogCache->get_by_ID( $blog_ID, false, false );
 153              if( $selected_Blog == NULL )
 154              {
 155                  $Messages->add( T_( 'Blog ID must be a valid Blog ID!' ), 'error' );
 156                  $action = 'show_create_comments';
 157                  break;
 158              }
 159  
 160              // Execute a creating of comments inside template in order to see a process
 161              $template_action = 'create_sample_comments';
 162              break;
 163  
 164          case 'create_sample_posts':
 165              $blog_ID = param( 'blog_ID', 'string', 0 );
 166              $num_posts = param( 'num_posts', 'string', 0 );
 167  
 168              if( ! ( param_check_number( 'blog_ID', T_('Blog ID must be a number'), true ) &&
 169                  param_check_number( 'num_posts', T_('"How many posts" field must be a number'), true ) ) )
 170              { // param errors
 171                  $action = 'show_create_posts';
 172                  break;
 173              }
 174  
 175              // check blog_ID
 176              $BlogCache = & get_BlogCache();
 177              $selected_Blog = $BlogCache->get_by_ID( $blog_ID, false, false );
 178              if( $selected_Blog == NULL )
 179              {
 180                  $Messages->add( T_( 'Blog ID must be a valid Blog ID!' ), 'error' );
 181                  $action = 'show_create_posts';
 182                  break;
 183              }
 184  
 185              // Execute a creating of posts inside template in order to see a process
 186              $template_action = 'create_sample_posts';
 187              break;
 188  
 189          case 'create_sample_users':
 190              $num_users = param( 'num_users', 'string', 0 );
 191              $group_ID = param( 'group_ID', 'string', 0 );
 192  
 193              if( ! param_check_number( 'num_users', T_('"How many users" field must be a number'), true ) )
 194              { // param errors
 195                  $action = 'show_create_users';
 196                  break;
 197              }
 198  
 199              // Execute a creating of users inside template in order to see a process
 200              $template_action = 'create_sample_users';
 201              break;
 202  
 203          case 'recreate_itemslugs':
 204              // Recreate all item slugs (change title-[0-9] canonical slugs to a slug generated from current title). Old slugs will still work, but redirect to the new one.
 205              dbm_recreate_itemslugs();
 206              break;
 207  
 208          case 'recreate_autogenerated_excerpts':
 209              // Execute recreating of autogenerated excerpts inside template in order to see the process
 210              $template_action = $action;
 211              break;
 212  
 213          case 'del_obsolete_tags':
 214              $DB->query('
 215                  DELETE T_items__tag FROM T_items__tag
 216                    LEFT JOIN T_items__itemtag ON tag_ID = itag_tag_ID
 217                   WHERE itag_itm_ID IS NULL');
 218              $Messages->add( sprintf(T_('Removed %d obsolete tag entries.'), $DB->rows_affected), 'success' );
 219              break;
 220  
 221          case 'view_phpinfo':
 222              // Display PHP info and exit
 223              headers_content_mightcache('text/html');
 224              phpinfo();
 225              exit();
 226              break;
 227  
 228          case 'create_sample_hits':
 229  
 230              $days = param( 'days', 'integer', 0 );
 231              $min_interval = param( 'min_interval', 'integer', 0 );
 232              $max_interval = param( 'max_interval', 'integer', 0 );
 233  
 234              if( $days < 1 )
 235              {
 236                  param_error( 'days', 'Please enter how many days of stats to generate' );
 237                  $action = 'show_create_hits';
 238                  break;
 239              }
 240  
 241              if( ( $min_interval > $max_interval ) || ( $min_interval < 0 ) || ( $max_interval <= 0 ) )
 242              {
 243                  param_error( 'min_interval', 'Please enter correct interval values' );
 244                  param_error( 'max_interval', 'Please enter correct interval values' );
 245                  $action = 'show_create_hits';
 246                  break;
 247              }
 248  
 249              // Execute a creating of hits inside template in order to see a process
 250              $template_action = 'create_sample_hits';
 251              break;
 252  
 253          case 'create_sample_messages':
 254              $num_loops = param( 'num_loops', 'string', 0 );
 255              $num_messages = param( 'num_messages', 'string', 0 );
 256              $num_words = param( 'num_words', 'string', 0 );
 257              $max_users = param( 'max_users', 'string', 0 );
 258  
 259              if( ! ( param_check_number( 'num_loops', T_('"How many loops" field must be a number'), true ) &&
 260                  param_check_number( 'num_messages', T_('"How many messages in each conversation" field must be a number'), true ) &&
 261                  param_check_number( 'num_words', T_('"How many words in each message" field must be a number'), true ) &&
 262                  param_check_number( 'max_users', T_('"Max # of participants in a conversation" field must be a number'), true ) ) )
 263              { // param errors
 264                  $action = 'show_create_messages';
 265                  break;
 266              }
 267  
 268              // Execute a creating of messages inside template in order to see a process
 269              $template_action = 'create_sample_messages';
 270              break;
 271  
 272          case 'test_flush':
 273              // Execute a testing of flush inside template in order to see a process
 274              $template_action = 'test_flush';
 275              $template_title = T_('Log of test flush').get_manual_link( 'test-flush-tool' );
 276              break;
 277      }
 278  }
 279  $AdminUI->breadcrumbpath_init( false );  // fp> I'm playing with the idea of keeping the current blog in the path here...
 280  $AdminUI->breadcrumbpath_add( T_('System'), '?ctrl=system' );
 281  $AdminUI->breadcrumbpath_add( T_('Maintenance'), '?ctrl=tools' );
 282  switch( $tab3 )
 283  {
 284      case 'import':
 285          $AdminUI->breadcrumbpath_add( T_('Import'), '?ctrl=tools&amp;tab3=import' );
 286          break;
 287  
 288      case 'test':
 289          $AdminUI->breadcrumbpath_add( T_('Testing'), '?ctrl=tools&amp;tab3=import' );
 290          break;
 291  
 292      case 'tools':
 293      default:
 294          $AdminUI->breadcrumbpath_add( T_('Tools'), '?ctrl=tools' );
 295          break;
 296  }
 297  
 298  
 299  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 300  $AdminUI->disp_html_head();
 301  
 302  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 303  $AdminUI->disp_body_top();
 304  
 305  // Begin payload block:
 306  $AdminUI->disp_payload_begin();
 307  
 308  
 309  if( empty($tab) )
 310  {
 311      switch( $action )
 312      {
 313          case 'find_broken_posts':
 314              $AdminUI->disp_view( 'tools/views/_broken_posts.view.php' );
 315              break;
 316  
 317          case 'find_broken_slugs':
 318              $AdminUI->disp_view( 'tools/views/_broken_slugs.view.php' );
 319              break;
 320  
 321          case 'show_create_comments':
 322              $AdminUI->disp_view( 'tools/views/_create_comments.form.php' );
 323              break;
 324  
 325          case 'show_create_posts':
 326              $AdminUI->disp_view( 'tools/views/_create_posts.form.php' );
 327              break;
 328              break;
 329  
 330          case 'show_create_users':
 331              $AdminUI->disp_view( 'tools/views/_create_users.form.php' );
 332              break;
 333  
 334          case 'show_create_hits':
 335              $AdminUI->disp_view( 'tools/views/_create_test_hit.form.php' );
 336              break;
 337  
 338          case 'show_create_messages':
 339              // Get count users
 340              $SQL = new SQL();
 341              $SQL->SELECT( 'COUNT( user_ID )' );
 342              $SQL->FROM( 'T_users' );
 343              $users_count = $DB->get_var( $SQL->get() );
 344              $threads_count = $users_count * $users_count - $users_count + 1;
 345  
 346              $AdminUI->disp_view( 'tools/views/_create_messages.form.php' );
 347              break;
 348  
 349  
 350          default:
 351              switch( $tab3 )
 352              {
 353                  case 'import':
 354                      $AdminUI->disp_view( 'tools/views/_misc_import.view.php' );
 355                      break;
 356  
 357                  case 'test':
 358                      $AdminUI->disp_view( 'tools/views/_misc_test.view.php' );
 359                      break;
 360  
 361                  case 'tools':
 362                  default:
 363                      $AdminUI->disp_view( 'tools/views/_misc_tools.view.php' );
 364                      break;
 365              }
 366              break;
 367      }
 368  }
 369  elseif( $tab_Plugin )
 370  { // Plugin tab
 371  
 372      // Icons:
 373      ?>
 374  
 375      <div class="right_icons">
 376  
 377      <?php
 378      echo $tab_Plugin->get_edit_settings_link()
 379          .' '.$tab_Plugin->get_help_link('$help_url');
 380      ?>
 381  
 382      </div>
 383  
 384      <?php
 385      $Plugins->call_method_if_active( $tab_plugin_ID, 'AdminTabPayload', $params = array() );
 386  }
 387  
 388  
 389  // End payload block:
 390  $AdminUI->disp_payload_end();
 391  
 392  // Display body bottom, debug info and close </html>:
 393  $AdminUI->disp_global_footer();
 394  
 395  ?>

title

Description

title

Description

title

Description

title

title

Body