PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/core/admin.class.php

http://xklog.googlecode.com/
PHP | 228 lines | 180 code | 30 blank | 18 comment | 54 complexity | 28806010235663b35eca55c15d46233d MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. !defined('IN_NOVA') && exit('Access Denied!');
  3. class Admin extends Application {
  4. public function __construct() {
  5. global $cache,$db;
  6. parent::__construct();
  7. // ?????
  8. //$cache_list = array( 'config', 'category', 'count', 'tag' );
  9. if( $cache->config == NULL ) {
  10. $content = $db->fetch_all( 'SELECT * FROM `' . DB_PREFIX . 'set' );
  11. $cache->set( 'config', $content[0], 0 );
  12. }
  13. if( $cache->tag == NULL ) {
  14. $content = array();
  15. $query = $db->query( 'SELECT * FROM `' . DB_PREFIX . 'tags` ORDER BY t_id Asc' );
  16. while ( $row = $db->fetch_array( $query ) ) {
  17. $content[$row['t_id']] = array( 't_name' => $row['t_name'], 't_num' => $row['t_num'], );
  18. }
  19. $cache->set( 'tag', $content, 0 );
  20. unset( $query, $row );
  21. }
  22. if( $cache->category == NULL ) {
  23. global $db;
  24. $content = array();
  25. $query = $db->query( 'SELECT cid,pid,name,alias,articlenum,description FROM `' . DB_PREFIX . 'category` ORDER BY num ASC,cid DESC' );
  26. while ( $row = $db->fetch_array( $query ) ){
  27. $content[$row['cid']] = $row;
  28. }
  29. $cache->set( 'category', $content, 0 );
  30. unset( $query, $row );
  31. }
  32. if( $cache->count == NULL ) {
  33. $content = array(
  34. 'article_num' => $db->result( 'SELECT count(id) FROM `' . DB_PREFIX . 'article` WHERE isdel=False' ),
  35. 'comment_num' => $db->result( 'SELECT count(cid) FROM `' . DB_PREFIX . 'comment` WHERE isdel=False AND articleid<>0' ),
  36. 'guestbook_num' => $db->result( 'SELECT count(cid) FROM `' . DB_PREFIX . 'comment` WHERE isdel=False AND articleid=0' ),
  37. 'user_num' => $db->result( 'SELECT count(u_id) FROM `' . DB_PREFIX . 'user` WHERE u_isdel=False' ),
  38. 'guestbook_num_censor' => $db->result( "SELECT count(cid) FROM `" . DB_PREFIX . "comment` WHERE isshow=0 and isdel=0 and articleid=0" ),
  39. 'comment_num_censor' => $db->result( "SELECT count(cid) FROM `" . DB_PREFIX . "comment` WHERE isshow=0 and isdel=0 and articleid<>0" ),
  40. 'file_num' => $db->result( "SELECT count(ul_id) FROM `" . DB_PREFIX . "upload`" ),
  41. );
  42. $cache->set( 'count', $content, 0 );
  43. }
  44. unset( $content );
  45. }
  46. public function start() {
  47. global $request,$cache,$user;
  48. if( $request->get( 'm' ) == NULL ) {
  49. $request->m = 'index';
  50. }
  51. if( !isset( $_SESSION['user_group'] ) ) {
  52. $_SESSION['user_group'] = 0;
  53. }
  54. // ??????
  55. $username = $request->get( APP_PREFIX . 'username', 'C' );
  56. $password = $request->get( APP_PREFIX . 'password', 'C' );
  57. if( $username !== NULL && $password !== NULL ){
  58. if( $user->login( $username, $password ) != 1 ) {
  59. echo $user->login( $username, $password );
  60. setcookie( APP_PREFIX . 'username', NULL );
  61. setcookie( APP_PREFIX . 'password', NULL );
  62. }
  63. }
  64. unset( $username, $password );
  65. if( !$user->is_super_admin() ) {
  66. $request->m = 'login';
  67. }
  68. // ?? ohash
  69. if( $cache->ohash == NULL ) {
  70. // ????????????? 20 ??
  71. $cache->set( 'ohash', get_random_string(8), 1200 );
  72. } else {
  73. $cache->set( 'ohash', $cache->ohash, 600 );
  74. }
  75. $module = $request->get( 'm' );
  76. if( method_exists( $this, $module ) ) {
  77. $this->$module();
  78. } else {
  79. $this->page( $module );
  80. }
  81. }
  82. // ??
  83. private function page( $name, $page_make = FALSE ) {
  84. global $theme,$request,$cache;
  85. //[DEBUG]
  86. global $log;
  87. //[/DEBUG]
  88. // ?? ohash
  89. if( ( $cache->ohash != $request->get( 'ohash' ) ) && $name != 'login' && $name != 'index' ) {
  90. // ohash ??????????????
  91. global $user;
  92. $user->logout();
  93. echo 'forbidden';
  94. return;
  95. }
  96. // ?????????
  97. $tmparray = array('/',"\0",'..');
  98. if( str_replace( $tmparray, '', $name ) != $name ) {
  99. $theme->err_404();
  100. return;
  101. }
  102. if( is_file( APP_ADMIN .'kernel/' . $name . '.class.php' ) ) {
  103. include( APP_ADMIN .'kernel/' . $name . '.class.php' );
  104. } else {
  105. $this->err_404();
  106. return;
  107. }
  108. //[DEBUG]
  109. $runtime = microtime( TRUE );
  110. //[/DEBUG]
  111. $name = ucwords( $name );
  112. $page = new $name();
  113. $page->start();
  114. //[DEBUG]
  115. $runtime = microtime( TRUE ) - $runtime;
  116. if( defined( 'APP_DEBUG' ) && APP_DEBUG === TRUE ) {
  117. $log->add( '???????' . $runtime * 1000 . 'ms?', E_USER_NOTICE );
  118. }
  119. //[/DEBUG]
  120. }
  121. //
  122. private function cache_refresh_all() {
  123. global $cache;
  124. $cache->refresh_all( TRUE );
  125. }
  126. // 404
  127. public function err_404() {
  128. @header( 'HTTP/1.1 404 Not Found' );
  129. @header( 'status: 404 Not Found' );
  130. ?>
  131. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  132. <html xmlns = "http://www.w3.org/1999/xhtml" lang = "zh-cn">
  133. <head>
  134. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  135. <title>Error 404 - Not Found</title>
  136. </head>
  137. <body>
  138. <h2>Error 404 - Not Found</h2>
  139. </body>
  140. </html>
  141. <?php
  142. }
  143. // ??
  144. static public function get_navigator( $article_num, $max_per_page, $current_page, $module, $params = '' ){
  145. if( $article_num < $max_per_page + 1 ) return;
  146. if( ( $article_num % $max_per_page ) == 0 ){
  147. $page_num = floor( $article_num / $max_per_page );
  148. }else{
  149. $page_num = floor( $article_num / $max_per_page ) + 1;
  150. }
  151. if( $current_page > $page_num ) return;
  152. if( $module == '' ) $module = 'index';
  153. $leader = '<div class="navigator"><span class="navigator_tip">Pages?' . $current_page . '/' . $page_num . '</span>';
  154. $i = 1;
  155. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">Ť</a>';
  156. if( $current_page != 1 ){
  157. $i = $current_page - 1;
  158. }
  159. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">‹</a>';
  160. if( $current_page > 5 ){
  161. $leader .= ' …… ';
  162. for( $i = $current_page - 4 ; $i < $current_page ; $i ++ ){
  163. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">' . $i . '</a>';
  164. }
  165. }else{
  166. for($i = 1 ; $i < $current_page ; $i ++ ){
  167. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">' . $i . '</a>';
  168. }
  169. }
  170. $leader .= '<span class="navigator_current">' . $current_page . '</span>';
  171. if( $page_num - $current_page > 4 ){
  172. for($i = $current_page + 1 ; $i < $current_page + 5 ; $i ++ ){
  173. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">' . $i . '</a>';
  174. }
  175. $leader .= ' …… ';
  176. }else{
  177. for( $i = $current_page + 1 ; $i < $page_num + 1 ; $i ++ ){
  178. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">' . $i . '</a>';
  179. }
  180. }
  181. if( $current_page > $page_num - 1 ){
  182. $i = $page_num;
  183. }else{
  184. $i = $current_page + 1;
  185. }
  186. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $i, $module, $params ) . '">›</a>';
  187. $leader .= '<a href="#" onclick="' . Admin::get_navigator_url( $page_num, $module, $params ) . '">ť</a></div>';
  188. return $leader;
  189. }
  190. static public function get_navigator_url( $i, $module , $params = '' ) {
  191. if( $params == '' ) {
  192. return "ajax_load('" . ADMIN_PATH . "','" . $module . "',null,'" . $i . "');return false;";
  193. } else {
  194. return "ajax_load('" . ADMIN_PATH . "','" . $module . "','" . $params . "','" . $i . "');return false;";
  195. }
  196. }
  197. }
  198. ?>