plugins/admin/Home.php
changeset 915 91f4da84966f
child 916 05c341ea7545
equal deleted inserted replaced
914:f808e55fb92a 915:91f4da84966f
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
       
     5  * Version 1.1.6 (Caoineag beta 1)
       
     6  * Copyright (C) 2006-2008 Dan Fuhry
       
     7  *
       
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
       
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
       
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
       
    13  */
       
    14 
       
    15 function page_Admin_Home()
       
    16 {
       
    17   global $db, $session, $paths, $template, $plugins; // Common objects
       
    18   global $lang;
       
    19   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
       
    20   {
       
    21     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
       
    22     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
       
    23     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
       
    24     return;
       
    25   }
       
    26   
       
    27   if ( $paths->getParam(0) == 'updates.xml' )
       
    28   {
       
    29     return acphome_process_updates();
       
    30   }
       
    31   
       
    32   // Welcome
       
    33   echo '<h2>' . $lang->get('acphome_heading_main') . '</h2>';
       
    34   echo '<p>' . $lang->get('acphome_welcome_line1') . '</p>';
       
    35   
       
    36   // Stats
       
    37   acphome_show_stats();
       
    38   
       
    39   //
       
    40   // Alerts
       
    41   //
       
    42   
       
    43   echo '<h3>' . $lang->get('acphome_heading_alerts') . '</h3>';
       
    44   
       
    45   // Demo mode
       
    46   if ( defined('ENANO_DEMO_MODE') )
       
    47   {
       
    48     echo '<div class="acphome-box info">';
       
    49       echo '<h3>' . $lang->get('acphome_msg_demo_title') . '</h3>
       
    50             <p>' . $lang->get('acphome_msg_demo_body', array('reset_url' => makeUrlNS('Special', 'DemoReset', false, true))) . '</p>';
       
    51     echo '</div>';
       
    52   }
       
    53   
       
    54   // Check for the installer scripts
       
    55   if( file_exists(ENANO_ROOT.'/install/install.php') && !defined('ENANO_DEMO_MODE') )
       
    56   {
       
    57     echo '<div class="acphome-box warning">
       
    58             <h3>' . $lang->get('acphome_msg_install_files_title') . '</h3>
       
    59             <p>' . $lang->get('acphome_msg_install_files_body') . '</p>
       
    60           </div>';
       
    61   }
       
    62   
       
    63   // Inactive users
       
    64   $q = $db->sql_query('SELECT time_id FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\';');
       
    65   if ( $q )
       
    66   {
       
    67     if ( $db->numrows() > 0 )
       
    68     {
       
    69       $n = $db->numrows();
       
    70       $um_flags = 'href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'UserManager\'); return false;"';
       
    71       if ( $n == 1 )
       
    72         $s = $lang->get('acphome_msg_inactive_users_one', array('um_flags' => $um_flags));
       
    73       else
       
    74         $s = $lang->get('acphome_msg_inactive_users_plural', array('um_flags' => $um_flags));
       
    75       echo '<div class="acphome-box notice">
       
    76               <h3>' . $lang->get('acphome_heading_inactive_users') . '</h3>
       
    77               ' . $s . '
       
    78             </div>';
       
    79     }
       
    80   }
       
    81   $db->free_result();
       
    82   
       
    83   // Update checker
       
    84   echo '<div class="acphome-box info">';
       
    85     echo '<h3>' . $lang->get('acphome_heading_updates') . '</h3>';
       
    86     echo '<p>' . $lang->get('acphome_msg_updates_info', array('updates_url' => 'http://ktulu.enanocms.org/meta/updates.xml')) . '</p>';
       
    87     echo '<div id="update_check_container"><input type="button" onclick="ajaxUpdateCheck(this.parentNode.id);" value="' . $lang->get('acphome_btn_check_updates') . '" /></div>';
       
    88   echo '</div>';
       
    89   
       
    90   // Docs
       
    91   echo '<div class="acphome-box info halfwidth">';
       
    92   echo '<h3>' . $lang->get('acphome_heading_docs') . '</h3>';
       
    93   echo '<p>' . $lang->get('acphome_msg_docs_info') . '</p>';
       
    94   echo '</div>';
       
    95   
       
    96   // Support
       
    97   echo '<div class="acphome-box info halfwidth">';
       
    98   echo '<h3>' . $lang->get('acphome_heading_support') . '</h3>';
       
    99   echo '<p>' . $lang->get('acphome_msg_support_info') . '</p>';
       
   100   echo '</div>';
       
   101   
       
   102   echo '<span class="menuclear"></span>';
       
   103   
       
   104   //
       
   105   // Stats
       
   106   //
       
   107   
       
   108   if(getConfig('log_hits') == '1')
       
   109   {
       
   110     require_once(ENANO_ROOT . '/includes/stats.php');
       
   111     $stats = stats_top_pages(10);
       
   112     //die('<pre>'.print_r($stats,true).'</pre>');
       
   113     $c = 0;
       
   114     $cls = 'row2';
       
   115     echo '<h3>' . $lang->get('acphome_heading_top_pages') . '</h3>
       
   116           <div class="tblholder">
       
   117             <table style="width: 100%;" border="0" cellspacing="1" cellpadding="4">
       
   118               <tr>
       
   119                 <th>' . $lang->get('acphome_th_toppages_page') . '</th>
       
   120                 <th>' . $lang->get('acphome_th_toppages_hits') . '</th>
       
   121               </tr>';
       
   122     foreach($stats as $data)
       
   123     {
       
   124       echo   '<tr>';
       
   125       $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
       
   126       echo     '<td class="'.$cls.'">
       
   127                   <a href="'.makeUrl($data['page_urlname']).'">'.$data['page_title'].'</a></td><td style="text-align: center;" class="'.$cls.'">'.$data['num_hits']
       
   128              . '</td>';
       
   129       echo   '</tr>';
       
   130     }
       
   131     echo '  </table>
       
   132           </div>';
       
   133   }
       
   134   
       
   135   // Any hooks?
       
   136   $code = $plugins->setHook('acp_home');
       
   137   foreach ( $code as $cmd )
       
   138   {
       
   139     eval($cmd);
       
   140   }
       
   141   
       
   142   //
       
   143   // Security log
       
   144   //
       
   145   
       
   146   echo '<h3>' . $lang->get('acphome_heading_seclog') . '</h3>';
       
   147   echo '<p>' . $lang->get('acphome_msg_seclog_info') . '</p>';
       
   148   $seclog = get_security_log(5);
       
   149   echo $seclog;
       
   150   
       
   151   echo '<p><a href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'SecurityLog\'); return false;">' . $lang->get('acphome_btn_seclog_full') . '</a></p>';
       
   152   
       
   153 }
       
   154 
       
   155 function acphome_process_updates()
       
   156 {
       
   157   require_once(ENANO_ROOT . '/includes/http.php');
       
   158   
       
   159   $req = new Request_HTTP('ktulu.enanocms.org', '/meta/updates.xml');
       
   160   $response = $req->get_response_body();
       
   161   header('Content-type: application/xml');
       
   162   if ( $req->response_code != HTTP_OK )
       
   163   {
       
   164     // Error in response
       
   165     echo '<enano><latest><error><![CDATA[
       
   166 Did not properly receive response from server. Response code: ' . $req->response_code . ' ' . $req->response_string . '
       
   167 ]]></error></latest></enano>';
       
   168   }
       
   169   else
       
   170   {
       
   171     // Retrieve first update
       
   172     $first_update = preg_match('/<release tag="([^"]+)" version="([^"]+)" (codename="([^"]+)" )?relnotes="([^"]+)" ?\/>/', $response, $match);
       
   173     if ( !$first_update )
       
   174     {
       
   175       echo '<enano><latest><error><![CDATA[
       
   176 Received invalid XML response.
       
   177 ]]></error></latest></enano>';
       
   178     }
       
   179     else
       
   180     {
       
   181       if ( version_compare(enano_version(true), $match[2], '<') )
       
   182       {
       
   183         $response = str_replace_once('</latest>', "  <haveupdates />\n  </latest>", $response);
       
   184       }
       
   185       echo $response;
       
   186     }
       
   187   }
       
   188   return true;
       
   189 }
       
   190 
       
   191 function acphome_show_stats()
       
   192 {
       
   193   global $db, $session, $paths, $template, $plugins; // Common objects
       
   194   global $lang;
       
   195   
       
   196   // Page count
       
   197   $q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "pages");
       
   198   if ( !$q )
       
   199     $db->_die();
       
   200   list($page_count) = $db->fetchrow_num();
       
   201   $db->free_result();
       
   202   
       
   203   // Edits per day
       
   204   $q = $db->sql_query('SELECT ( COUNT(*) - 1 ) AS edit_count, MIN(time_id) AS install_date FROM ' . table_prefix . 'logs WHERE ( log_type = \'page\' AND action = \'edit\' ) OR ( log_type = \'security\' AND action = \'install_enano\' );');
       
   205   if ( !$q )
       
   206     $db->_die();
       
   207   $edit_info = $db->fetchrow();
       
   208   $install_date =& $edit_info['install_date'];
       
   209   $db->free_result();
       
   210   
       
   211   $days_installed = round( (time() / 86400) - ($install_date / 86400) );
       
   212   
       
   213   // Comments
       
   214   $q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "comments");
       
   215   if ( !$q )
       
   216     $db->_die();
       
   217   list($comment_count) = $db->fetchrow_num();
       
   218   $db->free_result();
       
   219   
       
   220   // Users
       
   221   $q = $db->sql_query('SELECT ( COUNT(*) - 1 ) FROM ' . table_prefix . "users");
       
   222   if ( !$q )
       
   223     $db->_die();
       
   224   list($user_count) = $db->fetchrow_num();
       
   225   $db->free_result();
       
   226   
       
   227   // Cache size
       
   228   $cache_size = 0;
       
   229   if ( $dr = @opendir(ENANO_ROOT . '/cache/') )
       
   230   {
       
   231     while ( $dh = @readdir($dr) )
       
   232     {
       
   233       $file = ENANO_ROOT . "/cache/$dh";
       
   234       if ( @is_file($file) )
       
   235         $cache_size += filesize($file);
       
   236     }
       
   237     closedir($dr);
       
   238   }
       
   239   $cache_size = humanize_filesize($cache_size);
       
   240   
       
   241   // Files directory size
       
   242   $files_size = 0;
       
   243   if ( $dr = @opendir(ENANO_ROOT . '/files/') )
       
   244   {
       
   245     while ( $dh = @readdir($dr) )
       
   246     {
       
   247       $file = ENANO_ROOT . "/files/$dh";
       
   248       if ( @is_file($file) )
       
   249         $files_size += filesize($file);
       
   250     }
       
   251     closedir($dr);
       
   252   }
       
   253   $files_size = humanize_filesize($files_size);
       
   254   
       
   255   // Avatar directory size
       
   256   $avatar_size = 0;
       
   257   if ( $dr = @opendir(ENANO_ROOT . '/files/avatars/') )
       
   258   {
       
   259     while ( $dh = @readdir($dr) )
       
   260     {
       
   261       $file = ENANO_ROOT . "/files/avatars/$dh";
       
   262       if ( @is_file($file) )
       
   263         $avatar_size += filesize($file);
       
   264     }
       
   265     closedir($dr);
       
   266   }
       
   267   $avatar_size = humanize_filesize($avatar_size);
       
   268   
       
   269   // Database size
       
   270   $db_size = $lang->get('acphome_stat_dbsize_unsupported');
       
   271   if ( ENANO_DBLAYER == 'MYSQL' )
       
   272   {
       
   273     $q = $db->sql_query('SHOW TABLE STATUS;');
       
   274     if ( $q )
       
   275     {
       
   276       $db_size = 0;
       
   277       while ( $row = $db->fetchrow() )
       
   278       {
       
   279         if ( preg_match('/^' . table_prefix . '/', $row['Name']) )
       
   280         {
       
   281           $db_size += $row['Data_length'] + $row['Index_length'];
       
   282         }
       
   283       }
       
   284       $db_size = humanize_filesize($db_size);
       
   285     }
       
   286   }
       
   287   else if ( ENANO_DBLAYER == 'PGSQL' )
       
   288   {
       
   289     require(ENANO_ROOT . '/config.php');
       
   290     global $dbname, $dbuser, $dbpasswd;
       
   291     $dbuser = false;
       
   292     $dbpasswd = false;
       
   293     
       
   294     $q = $db->sql_query('SELECT pg_database_size(\'' . $db->escape($dbname) . '\');');
       
   295     if ( $q )
       
   296     {
       
   297       list($db_size) = $db->fetchrow_num();
       
   298       $db_size = humanize_filesize($db_size);
       
   299       $db->free_result();
       
   300     }
       
   301   }
       
   302   
       
   303   // Install date
       
   304   $install_date_human = MemberlistFormatter::format_date($install_date);
       
   305   
       
   306   // Last upgrade
       
   307   $q = $db->sql_query('SELECT time_id FROM ' . table_prefix . "logs WHERE log_type = 'security' AND action = 'upgrade_enano' ORDER BY time_id DESC LIMIT 1;");
       
   308   if ( !$q )
       
   309     $db->_die();
       
   310   
       
   311   if ( $db->numrows() < 1 )
       
   312   {
       
   313     $last_upgrade = $lang->get('acphome_stat_lastupdate_never');
       
   314   }
       
   315   else
       
   316   {
       
   317     list($last_upgrade) = $db->fetchrow_num();
       
   318     $last_upgrade = MemberlistFormatter::format_date($last_upgrade);
       
   319   }
       
   320   $db->free_result();
       
   321   
       
   322   ?>
       
   323   <div class="tblholder">
       
   324   <table border="0" cellspacing="1" cellpadding="4">
       
   325     <tr>
       
   326       <th colspan="4">
       
   327         <?php echo $lang->get('acphome_stat_header'); ?>
       
   328       </th>
       
   329     </tr>
       
   330     
       
   331     <tr>
       
   332       <td class="row2" style="width: 25%;">
       
   333         <?php echo $lang->get('acphome_stat_numpages'); ?>
       
   334       </td>
       
   335       <td class="row1" style="width: 25%;">
       
   336         <?php echo strval($page_count); ?>
       
   337       </td>
       
   338       <td class="row2" style="width: 25%;">
       
   339         <?php echo $lang->get('acphome_stat_edits'); ?>
       
   340       </td>
       
   341       <td class="row1" style="width: 25%;">
       
   342         <?php echo $lang->get('acphome_stat_edits_data', array('edit_count' => $edit_info['edit_count'], 'per_day' => number_format($edit_info['edit_count'] / $days_installed, 2))); ?>
       
   343       </td>
       
   344     </tr>
       
   345     
       
   346     <tr>
       
   347       <td class="row2" style="width: 25%;">
       
   348         <?php echo $lang->get('acphome_stat_comments'); ?>
       
   349       </td>
       
   350       <td class="row1" style="width: 25%;">
       
   351         <?php echo $lang->get('acphome_stat_comments_data', array('comment_count' => $comment_count, 'per_day' => number_format($comment_count / $days_installed, 2))); ?>
       
   352       </td>
       
   353       <td class="row2" style="width: 25%;">
       
   354         <?php echo $lang->get('acphome_stat_users'); ?>
       
   355       </td>
       
   356       <td class="row1" style="width: 25%;">
       
   357         <?php echo strval($user_count); ?>
       
   358       </td>
       
   359     </tr>
       
   360     
       
   361     <tr>
       
   362       <td class="row2" style="width: 25%;">
       
   363         <?php echo $lang->get('acphome_stat_filesize'); ?>
       
   364       </td>
       
   365       <td class="row1" style="width: 25%;">
       
   366         <?php echo $files_size; ?>
       
   367       </td>
       
   368       <td class="row2" style="width: 25%;">
       
   369         <?php echo $lang->get('acphome_stat_cachesize'); ?>
       
   370       </td>
       
   371       <td class="row1" style="width: 25%;">
       
   372         <?php echo $cache_size; ?>
       
   373       </td>
       
   374     </tr>
       
   375     
       
   376     <tr>
       
   377       <td class="row2" style="width: 25%;">
       
   378         <?php echo $lang->get('acphome_stat_avatarsize'); ?>
       
   379       </td>
       
   380       <td class="row1" style="width: 25%;">
       
   381         <?php echo $avatar_size; ?>
       
   382       </td>
       
   383       <td class="row2" style="width: 25%;">
       
   384         <?php echo $lang->get('acphome_stat_dbsize'); ?>
       
   385       </td>
       
   386       <td class="row1" style="width: 25%;">
       
   387         <?php echo $db_size; ?>
       
   388       </td>
       
   389     </tr>
       
   390     
       
   391     <tr>
       
   392       <td class="row2" style="width: 25%;">
       
   393         <?php echo $lang->get('acphome_stat_installdate'); ?>
       
   394       </td>
       
   395       <td class="row1" style="width: 25%;">
       
   396         <?php echo $install_date_human; ?>
       
   397       </td>
       
   398       <td class="row2" style="width: 25%;">
       
   399         <?php echo $lang->get('acphome_stat_lastupdate'); ?>
       
   400       </td>
       
   401       <td class="row1" style="width: 25%;">
       
   402         <?php echo $last_upgrade; ?>
       
   403       </td>
       
   404     </tr>
       
   405     
       
   406     <tr>
       
   407       <th colspan="4" class="subhead systemversion">
       
   408         <?php echo $lang->get('acphome_stat_enano_version', array(
       
   409             'version' => enano_version(true),
       
   410             'releasename' => enano_codename(),
       
   411             'aboutlink' => makeUrlNS('Special', 'About_Enano')
       
   412           )); ?>
       
   413       </th>
       
   414     </tr>
       
   415     
       
   416   </table>
       
   417   </div>
       
   418   <?php
       
   419 }