PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/kernel/admin.class.php

http://xklog.googlecode.com/
PHP | 369 lines | 317 code | 14 blank | 38 comment | 51 complexity | bb54749cc0d5c013520f254c0723f0d0 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. !defined('IN_NOVA') && exit('Access Denied!');
  3. class Admin {
  4. public function __construct() {}
  5. public function __destruct() {}
  6. public function start() {
  7. global $db,$theme,$cache,$request;
  8. $id = $request->id;
  9. switch( $request->get( 'p' ) ) {
  10. case 'saveadd':
  11. // ??????
  12. $article_id = $this->article_add();
  13. //$article_type = $request->get( 'article_type', 'P' );
  14. if( $cache->config['arttype'] == '??' ){
  15. page_make( $article_id, $article_type );
  16. }
  17. $cache->refresh( 'count', TRUE );
  18. $cache->refresh( 'article_new', TRUE );
  19. $cache->refresh( 'article_list', TRUE );
  20. $theme->show_message( L('_ADD_ARTICLE_SUCCESS_'), $theme->get_blog_info('path') );
  21. break;
  22. case 'saveedit':
  23. // ??????
  24. $this->article_edit( $id );
  25. $article_type = $request->get('article_type','P');
  26. if( $cache->config['arttype'] == '??' ){
  27. page_make( $article_id, $article_type );
  28. }
  29. $cache->refresh( 'article_hot', TRUE );
  30. $cache->refresh( 'article_new', TRUE );
  31. $cache->refresh( 'article_list', TRUE );
  32. $theme->show_message( L('_EDIT_ARTICLE_SUCCESS_'), $theme->get_blog_info('path') );
  33. break;
  34. case 'top':
  35. // ??????
  36. $db->query( "UPDATE `" . DB_PREFIX . "article` SET istop = 1 WHERE id=$id" );
  37. // ????
  38. $cache->refresh( 'article_list', TRUE );
  39. $theme->show_message( '??????', $request->get_http_referer() );
  40. break;
  41. case 'topcancel':
  42. // ????????
  43. $db->query( "UPDATE `" . DB_PREFIX . "article` SET istop = 0 WHERE id=$id" );
  44. // ????
  45. $cache->refresh( 'article_list', TRUE );
  46. $theme->show_message( '????????', $request->get_http_referer() );
  47. break;
  48. case 'reflash':
  49. // ??????
  50. /*page_make_html( $id );
  51. $db->query( "UPDATE `" . DB_PREFIX . "article` SET `update`=0 WHERE id=$id" );*/
  52. $theme->show_message( '??????', $request->get_http_referer() );
  53. break;
  54. case 'del':
  55. // ??????
  56. $category = $db->result( "SELECT category FROM `" . DB_PREFIX . "article` WHERE id=$id AND isdel = 0" );
  57. if( $category == '' ) {
  58. $theme->show_message( '??????' );
  59. break;
  60. }
  61. // ??????
  62. $db->query( "UPDATE `" . DB_PREFIX . "category` SET articlenum = articlenum - 1 WHERE cid=$category" );
  63. // ????????
  64. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET isdel = 1 WHERE articleid=$id" );
  65. // ??????
  66. $tags = $db->result( "SELECT tag FROM `" . DB_PREFIX . "article` WHERE id=$id" );
  67. $tags = str_replace( '*}{*',',',$tags );
  68. $tags = str_replace( '*}','',$tags );
  69. $tags = str_replace( '{*','',$tags );
  70. $tags = split( ',' , $tags );
  71. foreach($tags as $tag){
  72. if( $tag != '' ){
  73. $db->query( "UPDATE `" . DB_PREFIX . "tags` SET t_num=t_num-1 WHERE t_id=$tag" );
  74. }
  75. }
  76. // ????
  77. $db->query( "UPDATE `" . DB_PREFIX . "article` SET isdel = 1 WHERE id=$id" );
  78. // ????
  79. $cache->article_new = NULL;
  80. $cache->article_hot = NULL;
  81. $cache->comment_new = NULL;
  82. $cache->category = NULL;
  83. $cache->count = NULL;
  84. $cache->tag = NULL;
  85. $theme->show_message( '??????' );
  86. break;
  87. case 'addreply':
  88. // ??????
  89. $reply = htmlspecialchars( $request->get('commentreply','P') );
  90. $reply = str_replace( array("\r\n", "\n", "\r"), '<br />', $reply );
  91. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET replyuser = '" . $_SESSION['user_name'] . "',reply = '$reply',replytime = " . PHP_TIME . " WHERE cid = $id" );
  92. $theme->show_message( '??????', $request->get_http_referer() );
  93. break;
  94. case 'delreply':
  95. // ??????
  96. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET replyuser = NULL WHERE cid = $id" );
  97. $theme->show_message( '??????' );
  98. break;
  99. case 'delcomment':
  100. // ??????
  101. $aid = $db->result( "SELECT articleid FROM `" . DB_PREFIX . "comment` WHERE cid=$id AND isdel = 0" );
  102. if( $aid == '' ) {
  103. $theme->show_message( '??????' );
  104. break;
  105. }
  106. $db->query( "UPDATE `" . DB_PREFIX . "article` SET comment=comment-1 WHERE id=$aid" );
  107. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET isdel=1 WHERE cid=$id" );
  108. $cache->article_hot = NULL;
  109. $cache->comment_new = NULL;
  110. $cache->guestbook_new = NULL;
  111. $cache->count = NULL;
  112. $theme->show_message( '??????' );
  113. break;
  114. case 'censor':
  115. // ??????
  116. $db->query( "UPDATE `" . DB_PREFIX . "comment` SET isshow = 1 WHERE cid = $id" );
  117. $cache->comment_new = NULL;
  118. $cache->guestbook_new = NULL;
  119. $theme->show_message( '??????', $request->get_http_referer() );
  120. break;
  121. case 'edit':
  122. // ???????
  123. include( APP_ROOT . 'editor/fckeditor.php' );
  124. $theme->theme['article'] = $db->fetch_one_array( 'SELECT * FROM `' . DB_PREFIX . 'article` WHERE id=' . $id );
  125. $theme->theme['article']['trackback'] = '';//$db->result( 'SELECT tb_url FROM `' . DB_PREFIX . 'trackback` WHERE tb_type = 0 AND tb_article_id=' . $id );
  126. // ????
  127. $theme->theme['article']['attachment'] = str_replace( '*}{*',',',$theme->theme['article']['attachment']);
  128. $theme->theme['article']['attachment'] = str_replace( '*}','',$theme->theme['article']['attachment']);
  129. $theme->theme['article']['attachment'] = str_replace( '{*','',$theme->theme['article']['attachment']);
  130. $temp = array();
  131. $temp = split( ',' , $theme->theme['article']['attachment'] );
  132. $theme->theme['article']['attachment'] = '';
  133. $blog_path = str_replace( ' ','%20',APP_PATH );
  134. foreach($temp as $row){
  135. if( !is_numeric( $row ) ) continue;
  136. $file_info = $db->fetch_one_array( "SELECT ul_filetype,ul_filepath FROM `" . DB_PREFIX . "upload` WHERE ul_id=$row" );
  137. if ( stristr( $file_info['ul_filetype'],'image' ) ) {
  138. $ubb = '<img src=' . $blog_path . $file_info['ul_filepath'] . ' />';
  139. $ubb2 = '<img src=' . $blog_path . 'include/attachment.php?id=' . $row . ' />';
  140. } else {
  141. $ubb = '<span class=download><a href=' . $blog_path . $file_info['ul_filepath'] . ' target=_blank>??????</a></span>';
  142. $ubb2 = '<span class=download><a href=' . $blog_path . 'include/attachment.php?id=' . $row . ' target=_blank>??????</a></span>';
  143. }
  144. $theme->theme['article']['attachment'] .= '<li><a href="javascript:;" onclick="to_editor(\''.$ubb2.'\')" title="??????">[?????]</a> <a href="#" onclick="to_editor(\''.$ubb.'\')" title="??????">[????]</a> ' . $file_info['ul_filepath'] . '</li>';
  145. }
  146. $theme->theme['article']['attachment'] = '<ol>' . $theme->theme['article']['attachment'] . '</ol>';
  147. // ????
  148. $theme->theme['article']['tag'] = str_replace( '*}{*',',',$theme->theme['article']['tag']);
  149. $theme->theme['article']['tag'] = str_replace( '*}','',$theme->theme['article']['tag']);
  150. $theme->theme['article']['tag'] = str_replace( '{*','',$theme->theme['article']['tag']);
  151. $temp = array();
  152. $temp = split( ',' , $theme->theme['article']['tag']);
  153. $theme->theme['article']['tag'] = '';
  154. foreach($temp as $row){
  155. if( isset( $cache->tag[$row]['t_name'] ) ){
  156. $theme->theme['article']['tag'] .= '{*' . $cache->tag[$row]['t_name'] . '*}';
  157. }
  158. }
  159. $theme->theme['article']['tag'] = str_replace( '*}{*',',',$theme->theme['article']['tag']);
  160. $theme->theme['article']['tag'] = str_replace( '*}','',$theme->theme['article']['tag']);
  161. $theme->theme['article']['tag'] = str_replace( '{*','',$theme->theme['article']['tag']);
  162. // ……
  163. $theme->theme['article']['p'] = 'saveedit';
  164. $theme->theme['article']['extra'] = array( 'id' => $id );
  165. $theme->load('admin');
  166. break;
  167. default:
  168. // ???????
  169. include( APP_ROOT . 'editor/fckeditor.php' );
  170. $theme->theme['article'] = array();
  171. $temp = array('title','content','summary','category','tag','trackback','address','keywords','description');
  172. foreach ( $temp as $value ) {
  173. $theme->theme['article'][$value] = '';
  174. }
  175. $theme->theme['article']['trackback'] = '???????';
  176. // ……
  177. $theme->theme['article']['p'] = 'saveadd';
  178. $theme->theme['article']['extra'] = '';
  179. $theme->load('admin');
  180. }
  181. }
  182. // ??????
  183. private function article_add(){
  184. global $cache,$db,$request;
  185. $title = $request->get('article_title','P');
  186. $keywords = $request->get('article_keywords','P');
  187. $description = $request->get('article_description','P');
  188. $content = $request->get('article_content','P');
  189. $summary = $request->get('article_summary','P');
  190. $address = $request->get('article_alias','P');
  191. $type = $request->get('article_type','P');
  192. if( trim( $title ) == '' || trim( $content ) == '' ){
  193. echo "<script language=javascript>alert( '???????????' );location.href = 'javascript:history.back()'</script>";
  194. return;
  195. }
  196. if( strlen( $content ) > $cache->config['artmaxlength'] ){
  197. echo "<script language=javascript>alert( '??????????? " . $cache->config['artmaxlength'] . " ???' );location.href = 'javascript:history.back()'</script>";
  198. return;
  199. }
  200. if( strlen( $summary ) > $cache->config['artmaxlength'] ){
  201. echo "<script language=javascript>alert( '??????????? " . $cache->config['artmaxlength'] . " ???' );location.href = 'javascript:history.back()'</script>";
  202. return;
  203. }
  204. // ???????????
  205. // ?????????????????????? is_numeric ???????????
  206. if( is_numeric( $address ) ) {
  207. echo "<script language=javascript>alert( '???????????????' );location.href = 'javascript:history.back()'</script>";
  208. return;
  209. }
  210. if( $db->result( "SELECT COUNT(id) FROM `" . DB_PREFIX . "article` WHERE address='$address'") ) {
  211. echo "<script language=javascript>alert( '????????????' );location.href = 'javascript:history.back()'</script>";
  212. return;
  213. }
  214. $file_path = APP_ROOT . '/article/' . $address . '.html';
  215. @file_put_contents( $file_path, ' ' );
  216. if( file_exists( $file_path ) ) {
  217. unlink( $file_path );
  218. }else{
  219. echo "<script language=javascript>alert( '???????????' );location.href = 'javascript:history.back()'</script>";
  220. return;
  221. }
  222. unset( $file_path );
  223. // ????
  224. $category = $request->get('article_category','P');
  225. $db->query( "UPDATE `" . DB_PREFIX . "category` SET articlenum = articlenum + 1 WHERE cid = '$category'");
  226. $cache->refresh( 'category', TRUE );
  227. $type = $request->get('article_type','P');
  228. $trackback = $request->get('article_trackback','P');
  229. // ????
  230. $temp = explode( ',' , $request->get('article_tag','P') );
  231. $temp = array_unique( $temp );
  232. $tag = '';
  233. $find = false;
  234. foreach( $temp as $itag ){
  235. if( $itag != '' ){
  236. foreach( $cache->tag as $tag_id => $tag_arr ){
  237. if( $tag_arr['t_name'] == $itag ){
  238. $db->query( "UPDATE `" . DB_PREFIX . "tags` SET t_num = t_num + 1 WHERE t_name = '$itag'");
  239. $tag .= '{*' . $tag_id . '*}';
  240. $find = true;
  241. break;
  242. }
  243. }
  244. if( $find == false ){
  245. $db->query( "INSERT INTO `" . DB_PREFIX . "tags` (`t_name`,`t_num`) VALUES ('$itag',1)" );
  246. $tag .= '{*' . $db->insert_id() . '*}';
  247. }else{
  248. $find = false;
  249. }
  250. }
  251. }
  252. $cache->refresh( 'tag', TRUE );
  253. if( !isset( $_SESSION['upfile'] ) ) $_SESSION['upfile'] = '';
  254. $db->query( "INSERT INTO `" . DB_PREFIX . "article` (`title`,`keywords`,`description`,`time`,`author`,`category`,`tag`,`summary`,`content`,`read`,`comment`,`address`,`type`,`attachment`) VALUES ('$title', '$keywords', '$description', '" . PHP_TIME . "', '" . $_SESSION['user_name'] . "', $category, '$tag', '$summary', '$content',0,0,'$address','$type','" . $_SESSION['upfile'] . "')" );
  255. unset($_SESSION['upfile']);
  256. return $db->insert_id();
  257. }
  258. // ??????
  259. private function article_edit( $article_id ){
  260. global $cache,$db,$request;
  261. $title = $request->get('article_title','P');
  262. $keywords = $request->get('article_keywords','P');
  263. $description = $request->get('article_description','P');
  264. $content = $request->get('article_content','P');
  265. $summary = $request->get('article_summary','P');
  266. $address = trim( $request->get('article_alias','P') );
  267. $type = $request->get('article_type','P');
  268. if( trim( $title ) == '' || trim( $content ) == '' ){
  269. echo "<script language=javascript>alert( '???????????' );location.href = 'javascript:history.back()'</script>";
  270. return;
  271. }
  272. if( strlen( $content ) > $cache->config['artmaxlength'] ){
  273. echo "<script language=javascript>alert( '??????????? " . $cache->config['artmaxlength'] . " ???' );location.href = 'javascript:history.back()'</script>";
  274. return;
  275. }
  276. if( strlen( $summary ) > $cache->config['artmaxlength'] ){
  277. echo "<script language=javascript>alert( '??????????? " . $cache->config['artmaxlength'] . " ???' );location.href = 'javascript:history.back()'</script>";
  278. return;
  279. }
  280. // ????????
  281. if( $db->result( "SELECT COUNT(id) FROM `" . DB_PREFIX . "article` WHERE id = $article_id" ) == 0 ){
  282. $theme->show_message( '?????????????' );
  283. return;
  284. }
  285. // ???????????
  286. if( is_numeric( $address ) ) {
  287. echo "<script language=javascript>alert( '???????????????' );location.href = 'javascript:history.back()'</script>";
  288. return;
  289. }
  290. if( $db->result( "SELECT COUNT(id) FROM `" . DB_PREFIX . "article` WHERE address='$address' AND id<>$article_id") ) {
  291. echo "<script language=javascript>alert( '??????????' );location.href = 'javascript:history.back()'</script>";
  292. return;
  293. }
  294. $file_path = APP_ROOT . '/article/' . $address . '.html';
  295. @file_put_contents( $file_path, ' ' );
  296. if( file_exists( $file_path ) ) {
  297. unlink( $file_path );
  298. }else{
  299. echo "<script language=javascript>alert( '???????????' );location.href = 'javascript:history.back()'</script>";
  300. return;
  301. }
  302. unset( $file_path );
  303. // ?????
  304. $category_old = $db->result( "SELECT category FROM `" . DB_PREFIX . "article` WHERE id = $article_id" );
  305. $db->query( "UPDATE `" . DB_PREFIX . "category` SET articlenum = articlenum - 1 WHERE cid = $category_old");
  306. // ?????
  307. $category = $request->get('article_category','P');
  308. $db->query( "UPDATE `" . DB_PREFIX . "category` SET articlenum = articlenum + 1 WHERE cid = $category");
  309. $cache->refresh( 'category', TRUE );
  310. $type = $request->get('article_type','P');
  311. $trackback = $request->get('article_trackback','P');
  312. // ?????
  313. $tags_old = $db->result( "SELECT tag FROM `" . DB_PREFIX . "article` WHERE id = $article_id" );
  314. $tags_old = str_replace( '*}{*',',',$tags_old);
  315. $tags_old = str_replace( '*}','',$tags_old);
  316. $tags_old = str_replace( '{*','',$tags_old);
  317. $tags_old = explode( ',' ,$tags_old );
  318. foreach( $tags_old as $i_tag ){
  319. if( $i_tag != '' ){
  320. $db->query( "UPDATE `" . DB_PREFIX . "tags` SET t_num = t_num - 1 WHERE t_id = $i_tag" );
  321. }
  322. }
  323. // ?????
  324. $temp = explode( ',' , $request->get('article_tag','P') );
  325. $temp = array_unique( $temp );
  326. $tag = '';
  327. $find = false;
  328. $tag_list = $db->fetch_all( 'SELECT * FROM `' . DB_PREFIX . 'tags` ORDER BY t_id Asc' );
  329. foreach( $temp as $itag ){
  330. if( $itag != '' ){
  331. foreach( $tag_list as $tag_arr ){
  332. if( $tag_arr['t_name'] == $itag ){
  333. $db->query( "UPDATE `" . DB_PREFIX . "tags` SET t_num = t_num + 1 WHERE t_name = '$itag'");
  334. $tag .= '{*' . $tag_arr['t_id'] . '*}';
  335. $find = true;
  336. break;
  337. }
  338. }
  339. if( $find == false ){
  340. $db->query( "INSERT INTO `" . DB_PREFIX . "tags` (`t_name`,`t_num`) VALUES ('$itag',1)" );
  341. $tag .= '{*' . $db->insert_id() . '*}';
  342. }else{
  343. $find = false;
  344. }
  345. }
  346. }
  347. $cache->refresh( 'tag', TRUE );
  348. if( !isset( $_SESSION['upfile'] ) ) $_SESSION['upfile'] = '';
  349. $upfile = $db->result( "SELECT attachment FROM `" . DB_PREFIX . "article` WHERE id = $article_id" );
  350. $upfile .= $_SESSION['upfile'];
  351. $db->query( "UPDATE `" . DB_PREFIX . "article` SET title = '$title' ,keywords= '$keywords',description = '$description', author = '" . $_SESSION['user_name'] . "',category = $category ,tag = '$tag',summary = '$summary',content = '$content',address = '$address',type='$type',attachment='$upfile' WHERE id = $article_id" );
  352. unset($_SESSION['upfile']);
  353. }
  354. }
  355. ?>