diff -r de56132c008d -r bdac73ed481e plugins/admin/Home.php --- a/plugins/admin/Home.php Sun Mar 28 21:49:26 2010 -0400 +++ b/plugins/admin/Home.php Sun Mar 28 23:10:46 2010 -0400 @@ -13,435 +13,435 @@ function page_Admin_Home() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) - { - $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); - echo '

' . $lang->get('adm_err_not_auth_title') . '

'; - echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; - return; - } - - if ( $paths->getParam(0) == 'updates.xml' ) - { - return acphome_process_updates(); - } - - // Welcome - echo '

' . $lang->get('acphome_heading_main') . '

'; - echo '

' . $lang->get('acphome_welcome_line1') . '

'; - - // Stats - acphome_show_stats(); - - // - // Alerts - // - - echo '

' . $lang->get('acphome_heading_alerts') . '

'; - - // Demo mode - if ( defined('ENANO_DEMO_MODE') ) - { - echo '
'; - echo '

' . $lang->get('acphome_msg_demo_title') . '

-

' . $lang->get('acphome_msg_demo_body', array('reset_url' => makeUrlNS('Special', 'DemoReset', false, true))) . '

'; - echo '
'; - } - - // Check for the installer scripts - if( file_exists(ENANO_ROOT.'/install/install.php') && !defined('ENANO_DEMO_MODE') ) - { - echo '
-

' . $lang->get('acphome_msg_install_files_title') . '

-

' . $lang->get('acphome_msg_install_files_body') . '

-
'; - } - - // Inactive users - $q = $db->sql_query('SELECT time_id FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\';'); - if ( $q ) - { - if ( $db->numrows() > 0 ) - { - $n = $db->numrows(); - $um_flags = 'href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'UserManager\'); return false;"'; - if ( $n == 1 ) - $s = $lang->get('acphome_msg_inactive_users_one', array('um_flags' => $um_flags)); - else - $s = $lang->get('acphome_msg_inactive_users_plural', array('um_flags' => $um_flags, 'num_users' => $n)); - echo '
-

' . $lang->get('acphome_heading_inactive_users') . '

- ' . $s . ' -
'; - } - } - $db->free_result(); - - acp_usermanager_lockouts(true); - - // Update checker - echo '
'; - echo '

' . $lang->get('acphome_heading_updates') . '

'; - echo '

' . $lang->get('acphome_msg_updates_info', array('updates_url' => 'http://ktulu.enanocms.org/meta/updates.xml')) . '

'; - echo '
'; - echo '
'; - - // Docs - echo '
'; - echo '

' . $lang->get('acphome_heading_docs') . '

'; - echo '

' . $lang->get('acphome_msg_docs_info') . '

'; - echo '
'; - - // Support - echo '
'; - echo '

' . $lang->get('acphome_heading_support') . '

'; - echo '

' . $lang->get('acphome_msg_support_info') . '

'; - echo '
'; - - echo ''; - - // - // Stats - // - - if(getConfig('log_hits') == '1') - { - require_once(ENANO_ROOT . '/includes/stats.php'); - $stats = stats_top_pages(10); - //die('
'.print_r($stats,true).'
'); - $c = 0; - $cls = 'row2'; - echo '

' . $lang->get('acphome_heading_top_pages') . '

-
- - - - - '; - foreach($stats as $data) - { - echo ''; - $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; - echo ''; - echo ''; - } - echo '
' . $lang->get('acphome_th_toppages_page') . '' . $lang->get('acphome_th_toppages_hits') . '
- '.$data['page_title'].''.$data['num_hits'] - . '
-
'; - } - - // Any hooks? - $code = $plugins->setHook('acp_home'); - foreach ( $code as $cmd ) - { - eval($cmd); - } - - // - // Security log - // - - echo '

' . $lang->get('acphome_heading_seclog') . '

'; - echo '

' . $lang->get('acphome_msg_seclog_info') . '

'; - $seclog = get_security_log(5); - echo $seclog; - - echo '

' . $lang->get('acphome_btn_seclog_full') . '

'; - + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); + echo '

' . $lang->get('adm_err_not_auth_title') . '

'; + echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; + return; + } + + if ( $paths->getParam(0) == 'updates.xml' ) + { + return acphome_process_updates(); + } + + // Welcome + echo '

' . $lang->get('acphome_heading_main') . '

'; + echo '

' . $lang->get('acphome_welcome_line1') . '

'; + + // Stats + acphome_show_stats(); + + // + // Alerts + // + + echo '

' . $lang->get('acphome_heading_alerts') . '

'; + + // Demo mode + if ( defined('ENANO_DEMO_MODE') ) + { + echo '
'; + echo '

' . $lang->get('acphome_msg_demo_title') . '

+

' . $lang->get('acphome_msg_demo_body', array('reset_url' => makeUrlNS('Special', 'DemoReset', false, true))) . '

'; + echo '
'; + } + + // Check for the installer scripts + if( file_exists(ENANO_ROOT.'/install/install.php') && !defined('ENANO_DEMO_MODE') ) + { + echo '
+

' . $lang->get('acphome_msg_install_files_title') . '

+

' . $lang->get('acphome_msg_install_files_body') . '

+
'; + } + + // Inactive users + $q = $db->sql_query('SELECT time_id FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\';'); + if ( $q ) + { + if ( $db->numrows() > 0 ) + { + $n = $db->numrows(); + $um_flags = 'href="#" onclick="ajaxPage(\''.$paths->nslist['Admin'].'UserManager\'); return false;"'; + if ( $n == 1 ) + $s = $lang->get('acphome_msg_inactive_users_one', array('um_flags' => $um_flags)); + else + $s = $lang->get('acphome_msg_inactive_users_plural', array('um_flags' => $um_flags, 'num_users' => $n)); + echo '
+

' . $lang->get('acphome_heading_inactive_users') . '

+ ' . $s . ' +
'; + } + } + $db->free_result(); + + acp_usermanager_lockouts(true); + + // Update checker + echo '
'; + echo '

' . $lang->get('acphome_heading_updates') . '

'; + echo '

' . $lang->get('acphome_msg_updates_info', array('updates_url' => 'http://ktulu.enanocms.org/meta/updates.xml')) . '

'; + echo '
'; + echo '
'; + + // Docs + echo '
'; + echo '

' . $lang->get('acphome_heading_docs') . '

'; + echo '

' . $lang->get('acphome_msg_docs_info') . '

'; + echo '
'; + + // Support + echo '
'; + echo '

' . $lang->get('acphome_heading_support') . '

'; + echo '

' . $lang->get('acphome_msg_support_info') . '

'; + echo '
'; + + echo ''; + + // + // Stats + // + + if(getConfig('log_hits') == '1') + { + require_once(ENANO_ROOT . '/includes/stats.php'); + $stats = stats_top_pages(10); + //die('
'.print_r($stats,true).'
'); + $c = 0; + $cls = 'row2'; + echo '

' . $lang->get('acphome_heading_top_pages') . '

+
+ + + + + '; + foreach($stats as $data) + { + echo ''; + $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; + echo ''; + echo ''; + } + echo '
' . $lang->get('acphome_th_toppages_page') . '' . $lang->get('acphome_th_toppages_hits') . '
+ '.$data['page_title'].''.$data['num_hits'] + . '
+
'; + } + + // Any hooks? + $code = $plugins->setHook('acp_home'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + + // + // Security log + // + + echo '

' . $lang->get('acphome_heading_seclog') . '

'; + echo '

' . $lang->get('acphome_msg_seclog_info') . '

'; + $seclog = get_security_log(5); + echo $seclog; + + echo '

' . $lang->get('acphome_btn_seclog_full') . '

'; + } function acphome_process_updates() { - require_once(ENANO_ROOT . '/includes/http.php'); - - try - { - $req = new Request_HTTP('ktulu.enanocms.org', '/meta/updates.xml'); - $response = $req->get_response_body(); - header('Content-type: application/xml'); - } - catch ( Exception $e ) - { - header('Content-type: application/xml'); - echo 'get_response_body(); + header('Content-type: application/xml'); + } + catch ( Exception $e ) + { + header('Content-type: application/xml'); + echo 'getMessage() . ' ]]>'; - return true; - } - if ( $req->response_code != HTTP_OK ) - { - // Error in response - echo 'response_code != HTTP_OK ) + { + // Error in response + echo 'response_code . ' ' . $req->response_string . ' ]]>'; - } - else - { - // Retrieve first update - $first_update = preg_match('//', $response, $match); - if ( !$first_update ) - { - echo '/', $response, $match); + if ( !$first_update ) + { + echo ''; - } - else - { - if ( version_compare(enano_version(true), $match[2], '<') ) - { - $response = str_replace_once('', " \n ", $response); - } - echo $response; - } - } - return true; + } + else + { + if ( version_compare(enano_version(true), $match[2], '<') ) + { + $response = str_replace_once('', " \n ", $response); + } + echo $response; + } + } + return true; } function acphome_show_stats() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - - // Page count - $q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "pages"); - if ( !$q ) - $db->_die(); - list($page_count) = $db->fetchrow_num(); - $db->free_result(); - - // Edits per day - $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\' );'); - if ( !$q ) - $db->_die(); - $edit_info = $db->fetchrow(); - $install_date =& $edit_info['install_date']; - $db->free_result(); - - $days_installed = round( (time() / 86400) - ($install_date / 86400) ); - if ( $days_installed < 1 ) - $days_installed = 1; - - // Comments - $q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "comments"); - if ( !$q ) - $db->_die(); - list($comment_count) = $db->fetchrow_num(); - $db->free_result(); - - // Users - $q = $db->sql_query('SELECT ( COUNT(*) - 1 ) FROM ' . table_prefix . "users"); - if ( !$q ) - $db->_die(); - list($user_count) = $db->fetchrow_num(); - $db->free_result(); - - // Cache size - $cache_size = 0; - if ( $dr = @opendir(ENANO_ROOT . '/cache/') ) - { - while ( $dh = @readdir($dr) ) - { - $file = ENANO_ROOT . "/cache/$dh"; - if ( @is_file($file) ) - $cache_size += filesize($file); - } - closedir($dr); - } - $cache_size = humanize_filesize($cache_size); - - // Files directory size - $files_size = 0; - if ( $dr = @opendir(ENANO_ROOT . '/files/') ) - { - while ( $dh = @readdir($dr) ) - { - $file = ENANO_ROOT . "/files/$dh"; - if ( @is_file($file) ) - $files_size += filesize($file); - } - closedir($dr); - } - $files_size = humanize_filesize($files_size); - - // Avatar directory size - $avatar_size = 0; - if ( $dr = @opendir(ENANO_ROOT . '/files/avatars/') ) - { - while ( $dh = @readdir($dr) ) - { - $file = ENANO_ROOT . "/files/avatars/$dh"; - if ( @is_file($file) ) - $avatar_size += filesize($file); - } - closedir($dr); - } - $avatar_size = humanize_filesize($avatar_size); - - // Database size - $db_size = $lang->get('acphome_stat_dbsize_unsupported'); - if ( ENANO_DBLAYER == 'MYSQL' ) - { - $q = $db->sql_query('SHOW TABLE STATUS;'); - if ( $q ) - { - $db_size = 0; - while ( $row = $db->fetchrow() ) - { - if ( preg_match('/^' . table_prefix . '/', $row['Name']) ) - { - $db_size += $row['Data_length'] + $row['Index_length']; - } - } - $db_size = humanize_filesize($db_size); - } - } - else if ( ENANO_DBLAYER == 'PGSQL' ) - { - require(ENANO_ROOT . '/config.php'); - global $dbname, $dbuser, $dbpasswd; - $dbuser = false; - $dbpasswd = false; - - $q = $db->sql_query('SELECT pg_database_size(\'' . $db->escape($dbname) . '\');'); - if ( $q ) - { - list($db_size) = $db->fetchrow_num(); - $db_size = humanize_filesize($db_size); - $db->free_result(); - } - } - - // Install date - $site_age = floor((time() - $install_date) / 86400); - $install_date_human = MemberlistFormatter::format_date($install_date); - if ( $site_age > 7 ) - { - $install_date_human .= ' ' . $lang->get('acphome_stat_installdate_ago', array( - 'days' => number_format($site_age) - )); - } - - // Last upgrade - $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;"); - if ( !$q ) - $db->_die(); - - if ( $db->numrows() < 1 ) - { - $last_upgrade = $lang->get('acphome_stat_lastupdate_never'); - } - else - { - list($last_upgrade) = $db->fetchrow_num(); - $ver_age = floor((time() - $last_upgrade) / 86400); - $last_upgrade = MemberlistFormatter::format_date($last_upgrade); - if ( $ver_age > 7 ) - { - $last_upgrade .= ' ' . $lang->get('acphome_stat_installdate_ago', array( - 'days' => number_format($ver_age) - )); - } - } - $db->free_result(); - - ?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- get('acphome_stat_header'); ?> -
- get('acphome_stat_numpages'); ?> - - - - get('acphome_stat_edits'); ?> - - get('acphome_stat_edits_data', array('edit_count' => $edit_info['edit_count'], 'per_day' => number_format($edit_info['edit_count'] / $days_installed, 2))); ?> -
- get('acphome_stat_comments'); ?> - - get('acphome_stat_comments_data', array('comment_count' => $comment_count, 'per_day' => number_format($comment_count / $days_installed, 2))); ?> - - get('acphome_stat_users'); ?> - - -
- get('acphome_stat_filesize'); ?> - - - - get('acphome_stat_cachesize'); ?> - - -
- get('acphome_stat_avatarsize'); ?> - - - - get('acphome_stat_dbsize'); ?> - - -
- get('acphome_stat_installdate'); ?> - - - - get('acphome_stat_lastupdate'); ?> - - -
- get('acphome_stat_enano_version', array( - 'version' => enano_version(true), - 'releasename' => enano_codename(), - 'aboutlink' => makeUrlNS('Special', 'About_Enano') - )); ?> -
-
- sql_query('SELECT COUNT(*) FROM ' . table_prefix . "pages"); + if ( !$q ) + $db->_die(); + list($page_count) = $db->fetchrow_num(); + $db->free_result(); + + // Edits per day + $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\' );'); + if ( !$q ) + $db->_die(); + $edit_info = $db->fetchrow(); + $install_date =& $edit_info['install_date']; + $db->free_result(); + + $days_installed = round( (time() / 86400) - ($install_date / 86400) ); + if ( $days_installed < 1 ) + $days_installed = 1; + + // Comments + $q = $db->sql_query('SELECT COUNT(*) FROM ' . table_prefix . "comments"); + if ( !$q ) + $db->_die(); + list($comment_count) = $db->fetchrow_num(); + $db->free_result(); + + // Users + $q = $db->sql_query('SELECT ( COUNT(*) - 1 ) FROM ' . table_prefix . "users"); + if ( !$q ) + $db->_die(); + list($user_count) = $db->fetchrow_num(); + $db->free_result(); + + // Cache size + $cache_size = 0; + if ( $dr = @opendir(ENANO_ROOT . '/cache/') ) + { + while ( $dh = @readdir($dr) ) + { + $file = ENANO_ROOT . "/cache/$dh"; + if ( @is_file($file) ) + $cache_size += filesize($file); + } + closedir($dr); + } + $cache_size = humanize_filesize($cache_size); + + // Files directory size + $files_size = 0; + if ( $dr = @opendir(ENANO_ROOT . '/files/') ) + { + while ( $dh = @readdir($dr) ) + { + $file = ENANO_ROOT . "/files/$dh"; + if ( @is_file($file) ) + $files_size += filesize($file); + } + closedir($dr); + } + $files_size = humanize_filesize($files_size); + + // Avatar directory size + $avatar_size = 0; + if ( $dr = @opendir(ENANO_ROOT . '/files/avatars/') ) + { + while ( $dh = @readdir($dr) ) + { + $file = ENANO_ROOT . "/files/avatars/$dh"; + if ( @is_file($file) ) + $avatar_size += filesize($file); + } + closedir($dr); + } + $avatar_size = humanize_filesize($avatar_size); + + // Database size + $db_size = $lang->get('acphome_stat_dbsize_unsupported'); + if ( ENANO_DBLAYER == 'MYSQL' ) + { + $q = $db->sql_query('SHOW TABLE STATUS;'); + if ( $q ) + { + $db_size = 0; + while ( $row = $db->fetchrow() ) + { + if ( preg_match('/^' . table_prefix . '/', $row['Name']) ) + { + $db_size += $row['Data_length'] + $row['Index_length']; + } + } + $db_size = humanize_filesize($db_size); + } + } + else if ( ENANO_DBLAYER == 'PGSQL' ) + { + require(ENANO_ROOT . '/config.php'); + global $dbname, $dbuser, $dbpasswd; + $dbuser = false; + $dbpasswd = false; + + $q = $db->sql_query('SELECT pg_database_size(\'' . $db->escape($dbname) . '\');'); + if ( $q ) + { + list($db_size) = $db->fetchrow_num(); + $db_size = humanize_filesize($db_size); + $db->free_result(); + } + } + + // Install date + $site_age = floor((time() - $install_date) / 86400); + $install_date_human = MemberlistFormatter::format_date($install_date); + if ( $site_age > 7 ) + { + $install_date_human .= ' ' . $lang->get('acphome_stat_installdate_ago', array( + 'days' => number_format($site_age) + )); + } + + // Last upgrade + $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;"); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() < 1 ) + { + $last_upgrade = $lang->get('acphome_stat_lastupdate_never'); + } + else + { + list($last_upgrade) = $db->fetchrow_num(); + $ver_age = floor((time() - $last_upgrade) / 86400); + $last_upgrade = MemberlistFormatter::format_date($last_upgrade); + if ( $ver_age > 7 ) + { + $last_upgrade .= ' ' . $lang->get('acphome_stat_installdate_ago', array( + 'days' => number_format($ver_age) + )); + } + } + $db->free_result(); + + ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ get('acphome_stat_header'); ?> +
+ get('acphome_stat_numpages'); ?> + + + + get('acphome_stat_edits'); ?> + + get('acphome_stat_edits_data', array('edit_count' => $edit_info['edit_count'], 'per_day' => number_format($edit_info['edit_count'] / $days_installed, 2))); ?> +
+ get('acphome_stat_comments'); ?> + + get('acphome_stat_comments_data', array('comment_count' => $comment_count, 'per_day' => number_format($comment_count / $days_installed, 2))); ?> + + get('acphome_stat_users'); ?> + + +
+ get('acphome_stat_filesize'); ?> + + + + get('acphome_stat_cachesize'); ?> + + +
+ get('acphome_stat_avatarsize'); ?> + + + + get('acphome_stat_dbsize'); ?> + + +
+ get('acphome_stat_installdate'); ?> + + + + get('acphome_stat_lastupdate'); ?> + + +
+ get('acphome_stat_enano_version', array( + 'version' => enano_version(true), + 'releasename' => enano_codename(), + 'aboutlink' => makeUrlNS('Special', 'About_Enano') + )); ?> +
+
+