PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/core/theme.class.php

http://xklog.googlecode.com/
PHP | 708 lines | 619 code | 51 blank | 38 comment | 161 complexity | baf643c14dd0a553403afe5beeb9149e MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. !defined('IN_NOVA') && exit('Access Denied!');
  3. class Theme {
  4. public $theme;
  5. function __construct() {
  6. $this->theme['js_head'] = array();
  7. $this->theme['js_foot'] = array();
  8. $this->theme['css'] = array();
  9. }
  10. function __set( $name, $value ) {
  11. $this->theme[$name] = $value;
  12. }
  13. function __get( $name ) {
  14. //[DEBUG]
  15. global $log;
  16. //[/DEBUG]
  17. if( !isset( $this->theme[$name] ) ) {
  18. //[DEBUG]
  19. if( defined( 'APP_DEBUG' ) && APP_DEBUG === TRUE ) {
  20. $log->add( '[' . __FILE__ . '] [' . __LINE__ . '] ' . L( '_USE_ILLEGAL_INDEX_' ) . ' ' . $name, E_USER_NOTICE );
  21. }
  22. //[/DEBUG]
  23. return NULL;
  24. }
  25. return $this->theme[$name];
  26. }
  27. // ????
  28. public function load( $tpl, $ext = 'php' ) {
  29. global $db,$request,$cache;
  30. $style = $this->style;
  31. if( $style == NULL ) {
  32. $style = $cache->config['style'];
  33. }
  34. $tpl_file = APP_THEME . $style . '/' . $tpl . '.' . $ext;
  35. if ( file_exists( $tpl_file ) ) {
  36. include( $tpl_file );
  37. } else {
  38. $tpl_file = APP_THEME . 'template/' . $tpl . '.' . $ext;
  39. if( file_exists( $tpl_file ) ) {
  40. include( $tpl_file );
  41. }else{
  42. throw new NovaException( '???? ' . $tpl . '.' . $ext . ' ????', E_ERROR );
  43. }
  44. }
  45. }
  46. // ?????????
  47. static public function is_legal( $each_dir ) {
  48. if( !file_exists( APP_THEME . $each_dir . '/info.xml' ) ) return false;
  49. if( !file_exists( APP_THEME . $each_dir . '/index.php' ) ) return false;
  50. if( !file_exists( APP_THEME . $each_dir . '/page.php' ) ) return false;
  51. return true;
  52. }
  53. // ?? xml ????
  54. static public function parse_xml_info( $xml_file,$type ) {
  55. $fp = fopen($xml_file, 'rb');
  56. $content = fread($fp, filesize($xml_file));
  57. preg_match_all('/<name>(.+?)<\/name>/is',$content, $name);
  58. preg_match_all('/<author>(.*?)<\/author>/is',$content, $author);
  59. preg_match_all('/<version>(.*?)<\/version>/is',$content, $version);
  60. preg_match_all('/<pubdate>(.*?)<\/pubdate>/is',$content, $pubdate);
  61. preg_match_all('/<homepage>(.*?)<\/homepage>/is',$content, $homepage);
  62. preg_match_all('/<thumb>(.*?)<\/thumb>/is',$content, $thumb);
  63. preg_match_all('/<intro>(.*?)<\/intro>/is',$content, $intro);
  64. $info = array(
  65. 'name' => $name[1][0],
  66. 'author' => $author[1][0],
  67. 'version' => $version[1][0],
  68. 'pubdate' => $pubdate[1][0],
  69. 'homepage' => $homepage[1][0],
  70. 'thumb' => $thumb[1][0],
  71. 'intro' => $intro[1][0],
  72. );
  73. return $info;
  74. }
  75. // 404
  76. public function err_404() {
  77. @header( 'HTTP/1.1 404 Not Found' );
  78. @header( 'status: 404 Not Found' );
  79. $this->load('404');
  80. }
  81. // keyword ??
  82. public function get_keywords() {
  83. global $cache;
  84. if( isset( $this->theme['keywords'] ) && $this->theme['keywords'] != '' ) {
  85. return $this->theme['keywords'];
  86. }else{
  87. return $cache->config['keywords'];
  88. }
  89. }
  90. // description ??
  91. public function get_description() {
  92. global $cache;
  93. if( isset( $this->theme['description'] ) && $this->theme['description'] != '' ) {
  94. return $this->theme['description'];
  95. }else{
  96. return $cache->config['description'];
  97. }
  98. }
  99. // ????
  100. public function get_title() {
  101. global $cache;
  102. if ( isset( $this->theme['title'] ) ) {
  103. return $this->theme['title'] . ' Ť ' . $cache->config['blogname'];
  104. } else {
  105. return $cache->config['blogname'] . ' &raquo; ' . $cache->config['description'];
  106. }
  107. }
  108. // ????
  109. public function get_info( $index ) {
  110. global $cache;
  111. //[DEBUG]
  112. global $log;
  113. //[/DEBUG]
  114. switch( $index ) {
  115. case 'path':
  116. return APP_PATH;
  117. case 'theme_path':
  118. return THEME_PATH . $this->get_info( 'style' ) . '/';
  119. case 'style':
  120. if( $this->style == NULL ) {
  121. $this->style = $cache->config['style'];
  122. }
  123. return $this->style;
  124. case 'version':
  125. return XKLOG_VERSION;
  126. default:
  127. if ( array_key_exists( $index, $cache->config ) ) {
  128. return $cache->config[$index];
  129. } else {
  130. //[DEBUG]
  131. if( defined( 'APP_DEBUG' ) && APP_DEBUG === TRUE ) {
  132. $log->add( '[' . __FILE__ . '] [' . __LINE__ . '] ' . L( '_USE_ILLEGAL_INDEX_' ) . ' ' . $index, E_USER_NOTICE );
  133. }
  134. //[/DEBUG]
  135. return NULL;
  136. }
  137. }
  138. }
  139. //js
  140. public function get_js( $index ) {
  141. global $cache;
  142. $output = '';
  143. if( $index == 'head' ) {
  144. $output .= "<script language=\"javascript\" type=\"text/javascript\" src=\"" . THEME_PATH . "script/jquery.js\"></script>";
  145. $output .= "<script language=\"javascript\" type=\"text/javascript\" src=\"" . THEME_PATH . "script/common.js\"></script>";
  146. foreach( $this->theme['js_head'] as $js ) {
  147. $output .= "<script language=\"javascript\" type=\"text/javascript\" src=\"$js\"></script>";
  148. }
  149. $output .= "<script language=\"javascript\" type=\"text/javascript\">var BLOG_URL = '" . $cache->config['domain'] . "';var BLOG_PATH= '" . APP_PATH . "' ;</script>";
  150. } else {
  151. foreach( $this->theme['js_foot'] as $js ) {
  152. $output .= "<script language=\"javascript\" type=\"text/javascript\" src=\"$js\"></script>";
  153. }
  154. }
  155. return $output;
  156. }
  157. public function get_css() {
  158. $output = '';
  159. foreach( $this->theme['css'] as $css ) {
  160. $output .= "<link rel=\"stylesheet\" href=\"$css\" type=\"text/css\" media=\"screen\" />";
  161. }
  162. return $output;
  163. }
  164. //????
  165. public function get_run_info() {
  166. global $db,$_NOVA;
  167. $run_time = number_format( microtime( TRUE ) - $_NOVA['RUN_TIME']['NOVA_START'], 4 );
  168. if ( function_exists('ob_gzhandler') ) {
  169. $temp = 'Gzip enabled';
  170. } else {
  171. $temp = 'Gzip disabled';
  172. }
  173. return 'Processed in ' . $run_time * 1000 . ' ms, ' . $db->querynum . ' queries, ' . $temp;
  174. }
  175. // ????
  176. public function get_menu() {
  177. global $cache;
  178. $value = '';
  179. if( !isset( $this->theme['name'] ) ) $this->theme['name'] = '';
  180. foreach( $cache->menu as $ikey => $ivalue ) {
  181. if( $ivalue['type'] == 0 ){
  182. if( $this->theme['name'] == $ikey || ( $this->theme['name'] == '' && $ikey == 'index' ) ){
  183. $value .= '<li class="current_page"><a href="' . U( APP_PATH, $ivalue['address'], '' ) . '">' . $ivalue['title'] . '</a></li>';
  184. }else{
  185. $value .= '<li><a href="' . U( APP_PATH, $ivalue['address'], '' ) . '">' . $ivalue['title'] . '</a></li>';
  186. }
  187. }else{
  188. if( $this->theme['name'] == $ikey || ( $this->theme['name'] == '' && $ikey == 'index' ) ){
  189. $value .= '<li class="current_page"><a href="' . $ivalue['address'] . '" target="_blank">' . $ivalue['title'] . '</a></li>';
  190. }else{
  191. $value .= '<li><a href="' . $ivalue['address'] . '" target="_blank">' . $ivalue['title'] . '</a></li>';
  192. }
  193. }
  194. }
  195. return $value;
  196. }
  197. // ??????
  198. public function show_article_list( $id = 0, $type = 'index' ) {
  199. global $cache,$db;
  200. $offset = ( $this->current_page - 1 ) * $this->max_per_page;
  201. $temp = array();
  202. if ( $type == 'category' && array_key_exists( $id , $cache->category ) ) {
  203. $sql = "SELECT * FROM `" . DB_PREFIX . "article` WHERE isdel=0 AND category=$id ORDER BY istop DESC,id DESC LIMIT $offset, $this->max_per_page";
  204. $temp = $db->fetch_all( $sql );
  205. $article_num = $cache->category[$id]['articlenum'];
  206. } elseif( $type == 'tags' && array_key_exists( $id , $cache->tag ) ) {
  207. $sql = "SELECT * FROM `" . DB_PREFIX . "article` WHERE isdel=0 AND tag LIKE '%{*$id*}%' ORDER BY istop DESC,id DESC LIMIT $offset, $this->max_per_page";
  208. $temp = $db->fetch_all( $sql );
  209. $article_num = $cache->tag[$id]['t_num'];
  210. } else {
  211. if( $this->current_page == 1 ) {
  212. if( $cache->article_list == NULL ) {
  213. $temp = $db->fetch_all( "SELECT * FROM `" . DB_PREFIX . "article` WHERE isdel=0 ORDER BY istop DESC,id DESC LIMIT 0," . $this->max_per_page );
  214. foreach( $temp as $key => $value ) {
  215. if( $value['summary'] != '' ) {
  216. $value['content'] = $value['summary'];
  217. }
  218. $value['summary'] = '';
  219. $temp[$key] = $value;
  220. }
  221. $cache->set( 'article_list', $temp, 0 );
  222. } else {
  223. $temp = $cache->article_list;
  224. }
  225. } else {
  226. $sql = "SELECT * FROM `" . DB_PREFIX . "article` WHERE isdel=0 ORDER BY istop DESC,id DESC LIMIT $offset, $this->max_per_page";
  227. $temp = $db->fetch_all( $sql );
  228. }
  229. $article_num = $cache->count['article_num'];
  230. }
  231. foreach( $temp as $row => $value ){
  232. $this->theme['content'] = &$value;
  233. $this->load( 'article_index' );
  234. }
  235. }
  236. // ????
  237. public function show_article_detail( $id ){
  238. global $db;
  239. $sql = "SELECT * FROM `" . DB_PREFIX . "article` WHERE isdel = 0 AND id=$id";
  240. $article = $db->fetch_one_array( $sql );
  241. if( $article == '' ) {
  242. throw new NovaException( '?? id ???', E_ERROR );
  243. }
  244. $this->theme['content'] = &$article;
  245. $this->load('article_read');
  246. }
  247. // ????
  248. public function get_article_content( $key ) {
  249. global $cache;
  250. switch( $key ) {
  251. case 'summary':
  252. if( $this->theme['content']['summary'] != '' ) {
  253. return $this->theme['content']['summary'];
  254. } else {
  255. return $this->theme['content']['content'];
  256. }
  257. break;
  258. case 'title':
  259. if( $this->theme['content']['istop'] ) {
  260. $this->theme['content']['title'] = '[??] ' . $this->theme['content']['title'];
  261. }
  262. return $this->theme['content']['title'];
  263. break;
  264. case 'url':
  265. if( $this->theme['content']['address'] == '' ) $this->theme['content']['address'] = $this->theme['content']['id'];
  266. if( $cache->config['arttype'] == '??' ){
  267. $this->theme['content']['url'] = APP_PATH . 'index.php?m=article&p=' . $this->theme['content']['id'];
  268. }else{
  269. $this->theme['content']['url'] = APP_PATH . 'article/' . $cache->category[$this->theme['content']['category']]['alias'] . '/' . $this->theme['content']['address'] . '.html';
  270. }
  271. return $this->theme['content']['url'];
  272. case 'tag':
  273. if( $this->theme['content']['tag'] != '' ) {
  274. $tags = str_replace( '*}{*', ',', $this->theme['content']['tag'] );
  275. $tags = str_replace( '{*', '', $tags );
  276. $tags = str_replace( '*}', '', $tags );
  277. $temp = explode( ',' , $tags);
  278. $tags = '';
  279. foreach($temp as $row){
  280. $tags .= '<a href="' . U( APP_PATH, 'tags', urlencode( $cache->tag[$row]['t_name'] ) ) . '">' . $cache->tag[$row]['t_name'] . '</a>';
  281. }
  282. $tags = str_replace( '</a><a href=','</a> , <a href=', $tags );
  283. return $tags;
  284. } else {
  285. return '';
  286. }
  287. case 'category':
  288. return '<a href="' . U( APP_PATH, 'category', $cache->category[$this->theme['content']['category']]['alias'] ) . '" title="' . $cache->category[$this->theme['content']['category']]['description'] . '">' . $cache->category[$this->theme['content']['category']]['name'] . '</a>';
  289. default:
  290. if( isset( $this->theme['content'][$key] ) ) {
  291. return $this->theme['content'][$key];
  292. } else {
  293. return '';
  294. }
  295. }
  296. }
  297. public function get_article_path( $id, $type ) {
  298. global $cache;
  299. $output = '';
  300. switch( $type ) {
  301. case 'tags':
  302. // ?? -> ??? -> XXXX
  303. $output = '<div id="postpath"><a href="' . APP_PATH . '" title="' . $cache->config['blogname'] . '">' . L( '_HOME_PAGE_' ) . '</a> &gt; ';
  304. $output .= '<a href="' . U( APP_PATH, 'tags' ) . '">' . L( '_TAGS_CLOUD_' ) . '</a> &gt; ';
  305. $output .= $cache->tag[$id]['t_name'] . '</div>';
  306. break;
  307. case 'category':
  308. case 'article':
  309. // ?? -> ???? -> ???? -> ……
  310. $output = '<div id="postpath"><a href="' . APP_PATH . '" title="' . $cache->config['blogname'] . '">' . L( '_HOME_PAGE_' ) . '</a> &gt; ';
  311. $output .= $this->get_article_path_c( $cache->category[$id]['pid'] );
  312. break;
  313. }
  314. if( $type == 'article' ) {
  315. $output .= '<a href="' . U( APP_PATH, 'category', $cache->category[$id]['alias'] ) . '" title="' . $cache->category[$id]['description'] . '">' . $cache->category[$id]['name'] . '</a> &gt; ';
  316. $output .= $this->title . '</div>';
  317. } elseif( $type == 'category' ) {
  318. $output .= $cache->category[$id]['name'] . '</div>';
  319. }
  320. return $output;
  321. }
  322. private function get_article_path_c( $id ) {
  323. global $cache;
  324. if( $id == 0 ) {
  325. return '';
  326. }
  327. $output = '<a href="' . U( APP_PATH, 'category', $cache->category[$id]['alias'] ) . '" title="' . $cache->category[$id]['description'] . '">' . $cache->category[$id]['name'] . '</a> &gt; ';
  328. $output = $this->get_article_path_c( $cache->category[$id]['pid'] ) . $output;
  329. return $output;
  330. }
  331. public function get_announcement( $module ) {
  332. $output = '';
  333. if( $module == 'index' ) {
  334. global $cache;
  335. if( $cache->laodao === NULL ) {
  336. global $db;
  337. $cache->set( 'laodao', $db->result("SELECT ld_laodao FROM `" . DB_PREFIX . "laodao` ORDER BY ld_id DESC LIMIT 0,1"), 0 );
  338. }
  339. if( is_string( $cache->laodao ) && $cache->laodao != '' ) {
  340. $output = '<div id="announcement">' . str_replace( array("\r\n", "\n", "\r"),'<br />',htmlspecialchars( $cache->laodao ) ) . '</div>';
  341. }
  342. }
  343. return $output;
  344. }
  345. // ????
  346. public function get_style( $a_tag = '<li>', $b_tag = '</li>' ) {
  347. global $cache;
  348. $output = '';
  349. $cstyle = $this->style;
  350. if( $cstyle == NULL ) {
  351. $cstyle = $cache->config['style'];
  352. }
  353. foreach( $cache->style as $style ) {
  354. if( $style['directory'] == $cstyle ) {
  355. $output .= $a_tag . $style['name'] . $b_tag;
  356. }else{
  357. $output .= $a_tag . '<a href="' . U( APP_PATH, 'index', $style['directory'] ) . '">' . $style['name'] . '</a>' . $b_tag;
  358. }
  359. }
  360. return $output;
  361. }
  362. // ????
  363. public function get_category( $pid = 0, $showrss = TRUE, $str_len = 30 ) {
  364. global $cache;
  365. $output = '<ul>';
  366. foreach ( $cache->category as $row ) {
  367. if( $row['pid'] != $pid ) continue;
  368. if( $showrss == TRUE ) {
  369. $rssicon = ' [<a href="' . U( APP_PATH, 'rss', $row['cid'] ) . '">RSS</a>]';
  370. } else {
  371. $rssicon = '';
  372. }
  373. $output .= '<li><a href="' . U( APP_PATH ,'category', $row['alias'] ) . '" title="' . $row['description'] . '">' . cut_str( $row['name'],$str_len ) . '(' . $row['articlenum'] . ')</a>' . $rssicon . $this->get_category( $row['cid'] , $showrss, $str_len - 2 ) . '</li>';
  374. }
  375. if( $output == '<ul>' ) {
  376. $output = '';
  377. } else {
  378. $output .= '</ul>';
  379. }
  380. return $output;
  381. }
  382. // ????
  383. public function get_comment_new( $str_len = 30 ) {
  384. global $cache;
  385. $output = '';
  386. if( $cache->comment_new == NULL ) {
  387. global $db;
  388. $cache->set( 'comment_new', $db->fetch_all( 'SELECT C.cid,C.comment, C.articleid, A.type, A.address, A.category, A.title, C.author FROM `' . DB_PREFIX . 'comment` as C, `' . DB_PREFIX . 'article` as A WHERE C.articleid=A.id and C.isdel=0 and C.isshow=1 and A.isdel=0 ORDER BY C.cid DESC limit 0,12' ), 0 );
  389. }
  390. foreach ( $cache->comment_new as $row ) {
  391. if( $row['address'] == '' ) $row['address'] = $row['articleid'];
  392. if( $cache->config['arttype'] == '??' ){
  393. $output .= '<li><a href="' . APP_PATH . 'index.php?m=article&p=' . $row['articleid'] . '#comment-' . $row['cid'] . '" title="[' . $row['author'] . '] ??? [' . strip_tags( $row['title'] ) . ']">' . cut_str( str_replace( '<br />', ' ', $row['comment'] ), $str_len ) . '</a></li>';
  394. } else {
  395. $output .= '<li><a href="' . APP_PATH . 'article/' . $cache->category[$row['category']]['alias'] . '/' . $row['address'] . '.html#comment-' . $row['cid'] . '" title="[' . $row['author'] . '] ??? [' . strip_tags( $row['title'] ) . ']">' . cut_str( str_replace( '<br />', ' ', $row['comment'] ), $str_len ) . '</a></li>';
  396. }
  397. }
  398. echo $output;
  399. }
  400. // ????
  401. public function show_message( $msg, $url = '', $litime = 3000 ) {
  402. global $_ENV;
  403. if( is_array($msg) ){
  404. $temp = '<ol>';
  405. foreach($msg as $row => $value){
  406. $temp .= '<li>' . $value . '</li>';
  407. }
  408. $temp .= '</ol>';
  409. $msg = $temp;
  410. unset($temp);
  411. }
  412. if( $url == '' ){
  413. $_ENV['message'] = array(
  414. 'content' => $msg,
  415. 'goto' => '',
  416. );
  417. }else{
  418. $_ENV['message'] = array(
  419. 'content' => $msg . "<script>setTimeout(\"window.location.href='" . $url . "';\",{$litime});</script>",
  420. 'goto' => '<a href="' . $url . '">??????????????????</a>',
  421. );
  422. }
  423. $this->load( 'message' );
  424. }
  425. // ??????????
  426. public function get_article_li( $type = 'new', $str_len = 30 ) {
  427. global $cache,$db;
  428. $output = '';
  429. if( $type == 'new' ){
  430. $temp = $cache->article_new;
  431. if( $temp == NULL ) {
  432. $content = $db->fetch_all( 'SELECT id,title,type,address,category FROM `' . DB_PREFIX . 'article` WHERE isdel=0 AND `type`<3 ORDER BY id DESC limit 0,6' );
  433. $cache->set( 'article_new', $content, 0 );
  434. $temp = $content;
  435. unset( $content );
  436. }
  437. }elseif( $type == 'hot' ){
  438. $temp = $cache->article_hot;
  439. if( $temp == NULL ) {
  440. $content = $db->fetch_all( 'SELECT id,title,type,address,category FROM `' . DB_PREFIX . 'article` WHERE isdel=0 AND `type`<3 ORDER BY comment DESC,`read` DESC limit 0,6' );
  441. $cache->set( 'article_hot', $content, 0 );
  442. $temp = $content;
  443. unset( $content );
  444. }
  445. }else{
  446. $temp = $cache->article_rnd;
  447. if( $temp == NULL ) {
  448. $content = $db->fetch_all( 'SELECT id,title,type,address,category FROM `' . DB_PREFIX . 'article` WHERE isdel=0 AND `type`<3 ORDER BY rand() limit 0,6' );
  449. // ??????30?
  450. $cache->set( 'article_rnd', $content, 30 );
  451. $temp = $content;
  452. unset( $content );
  453. }
  454. }
  455. if( isset( $temp ) ) {
  456. foreach ( $temp as $row) {
  457. if( $row['address'] == '' ) $row['address'] = $row['id'];
  458. if( $cache->config['arttype'] == '??' ){
  459. $output .= '<li><a href="' . APP_PATH . 'index.php?m=article&p=' . $row['id'] . '" title="' . strip_tags( $row['title'] ) . '">'.cut_str( $row['title'],$str_len ).'</a></li>';
  460. } else {
  461. $output .= '<li><a href="' . APP_PATH . 'article/' . $cache->category[$row['category']]['alias'] . '/' . $row['address'] . '.html" title="' . strip_tags( $row['title'] ) . '">'.cut_str( $row['title'],$str_len ).'</a></li>';
  462. }
  463. }
  464. return $output;
  465. }
  466. }
  467. // ????
  468. public function get_link( $str_len = 30, $a_tag = '<li>', $b_tag = '</li>' ) {
  469. global $cache;
  470. $output = '';
  471. if( $cache->link == NULL ) {
  472. global $db;
  473. $cache->set( 'link', $db->fetch_all( 'SELECT title,description,address FROM `' . DB_PREFIX . 'link` WHERE isdel=0 ORDER BY lid Asc' ), 0 );
  474. }
  475. foreach ( $cache->link as $row) {
  476. $output .= $a_tag . '<a href="' . $row['address'] . '" title="' . $row['description'] . '" target="_blank">' . cut_str( $row['title'],$str_len ) . '</a>' . $b_tag;
  477. }
  478. return $output;
  479. }
  480. // ????
  481. public function get_count( $a_tag = '<li>', $b_tag = '</li>' ) {
  482. global $cache;
  483. $output = $a_tag . '????: ' . date( 'Y?m?d?', $cache->config['builddate'] ) . $b_tag;
  484. $output .= $a_tag . '??: ' . $cache->count['article_num'] . ' ?' . $b_tag;
  485. $output .= $a_tag . $cache->menu['laodao']['title'] . ': ' . $cache->count['laodao_num'] . ' ?' . $b_tag;
  486. $output .= $a_tag . '??: ' . $cache->count['comment_num'] . ' ?' . $b_tag;
  487. $output .= $a_tag . '??: ' . $cache->count['guestbook_num'] . ' ?' . $b_tag;
  488. $output .= $a_tag . '??: ' . $cache->count['file_num'] . ' ?' . $b_tag;
  489. return $output;
  490. }
  491. // ??
  492. public function get_navigator( $article_num, $module, $params = '', $extra = '' ){
  493. if( $article_num < $this->max_per_page + 1 ) return;
  494. if( ( $article_num % $this->max_per_page ) == 0 ){
  495. $page_num = floor( $article_num / $this->max_per_page );
  496. }else{
  497. $page_num = floor( $article_num / $this->max_per_page ) + 1;
  498. }
  499. if( $this->current_page > $page_num ) return;
  500. if( $module == '' ) $module = 'index';
  501. $leader = '<div class = "navigator"><span class = "navigator_tip">???' . $this->current_page . '/' . $page_num . '</span>';
  502. $i = 1;
  503. $leader .= '<a href = "' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">Ť</a>';
  504. if( $this->current_page != 1 ){
  505. $i = $this->current_page - 1;
  506. }
  507. $leader .= '<a href = "' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">‹</a>';
  508. if( $this->current_page > 5 ){
  509. $leader .= ' …… ';
  510. for( $i = $this->current_page - 4 ; $i < $this->current_page ; $i ++ ){
  511. $leader .= '<a href="' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">' . $i . '</a>';
  512. }
  513. }else{
  514. for($i = 1 ; $i < $this->current_page ; $i ++ ){
  515. $leader .= '<a href="' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">' . $i . '</a>';
  516. }
  517. }
  518. $leader .= '<span class="navigator_current">' . $this->current_page . '</span>';
  519. if( $page_num - $this->current_page > 4 ){
  520. for($i = $this->current_page + 1 ; $i < $this->current_page + 5 ; $i ++ ){
  521. $leader .= '<a href="' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">' . $i . '</a>';
  522. }
  523. $leader .= ' …… ';
  524. }else{
  525. for( $i = $this->current_page + 1 ; $i < $page_num + 1 ; $i ++ ){
  526. $leader .= '<a href="' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">' . $i . '</a>';
  527. }
  528. }
  529. if( $this->current_page > $page_num - 1 ){
  530. $i = $page_num;
  531. }else{
  532. $i = $this->current_page + 1;
  533. }
  534. $leader .= '<a href = "' . $this->get_navigator_url( $i, $module, $params, $extra ) . '">›</a>';
  535. $leader .= '<a href = "' . $this->get_navigator_url( $page_num, $module, $params, $extra ) . '">ť</a></div>';
  536. return $leader;
  537. }
  538. private function get_navigator_url( $i, $module = 'index', $params = '', $extra = '' ) {
  539. if( $params == '' ) {
  540. $params = $i;
  541. } else {
  542. if( $extra == '' ) {
  543. $extra = array( 'page' => $i );
  544. } else {
  545. if( is_array( $extra ) ) {
  546. $extra = array_merge( $extra, array( 'page' => $i ) );
  547. }
  548. }
  549. }
  550. $url = U( APP_PATH, $module, $params, $extra );
  551. return $url;
  552. }
  553. public function get_relate_article( $aid ) {
  554. global $db,$cache;
  555. //??????
  556. $relate_num = 5;
  557. $tags = $db->result( "SELECT tag FROM `" . DB_PREFIX . "article` WHERE id=$aid" );
  558. if( $tags != '' ) {
  559. $tags = str_replace( '*}{*',',',$tags);
  560. $tags = str_replace( '*}','',$tags);
  561. $tags = str_replace( '{*','',$tags);
  562. $tags = split( ',', $tags );
  563. $sql = '';
  564. foreach( $tags as $tag ) {
  565. $sql .= "tag LIKE '%{*$tag*}%' OR ";
  566. }
  567. $sql = substr( $sql,0,-4 );
  568. $sql = "SELECT id,title,type,address,category,content,`read` FROM `" . DB_PREFIX . "article` WHERE ( $sql ) AND id<>$aid AND isdel=0 AND `type`<3 ORDER BY id DESC,`read` DESC LIMIT 0,$relate_num";
  569. $relate_arr = $db->fetch_all( $sql );
  570. if( !count( $relate_arr ) ) {
  571. return '<li>?????????????? <span class="count">(0)</span> <small class="excerpt">?????????????????????????????</small></li>';
  572. }else{
  573. $output = '';
  574. foreach( $relate_arr as $relate ) {
  575. if( $relate['address'] == '' ) $relate['address'] = $relate['id'];
  576. if( $cache->config['arttype'] == '??' ) {
  577. $output .= '<li><a href="' . APP_PATH . 'index.php?m=article&p=' . $relate['id'] . '">' . $relate['title'] . '</a> <span class="count">(' . $relate['read'] . ')</span> <small class="excerpt">' . cut_str( $relate['content'],70 ) . '</small></li>';
  578. } else {
  579. $output .= '<li><a href="' . APP_PATH . 'article/' . $cache->category[$relate['category']]['alias'] . '/' . $relate['address'] . '.html">' . $relate['title'] . '</a> <span class="count">(' . $relate['read'] . ')</span> <small class="excerpt">' . cut_str( $relate['content'],70 ) . '</small></li>';
  580. }
  581. }
  582. return $output;
  583. }
  584. }else{
  585. return '<li>?????????????? <span class="count">(0)</span> <small class="excerpt">?????????????????????????????</small></li>';
  586. }
  587. }
  588. // ????
  589. public function show_comment( $aid ){
  590. global $cache,$db;
  591. $sql = "SELECT * FROM `" . DB_PREFIX . "comment` WHERE isdel=False AND articleid=$aid ORDER BY cid DESC";
  592. if( $cache->config['comnum'] > 0 ){
  593. $sql .= " LIMIT 0," . $cache->config['comnum'];
  594. }
  595. $temp = array();
  596. $temp = $db->fetch_all( $sql );
  597. if( $temp == array() ){
  598. return;
  599. }
  600. foreach( $temp as $row => $value ){
  601. $this->theme['comment'] = $value;
  602. $this->show_comment_de();
  603. }
  604. }
  605. // ????
  606. public function show_comment_de(){
  607. If( $this->theme['comment']['email'] <> '' ){
  608. $gravatar = split( "\|" , $this->theme['comment']['email'] );
  609. $this->theme['comment']['gravatar'] = '<img src="http://www.gravatar.com/avatar.php?gravatar_id=' . $gravatar[1] . '?s=32&amp;d=wavatar&amp;r=G" height="32" width="32" alt="gravatar" class="gravatar" />';
  610. }else{
  611. $this->theme['comment']['gravatar'] = '<img src="' . THEME_PATH . 'images/gravatar.jpg" height="32" width="32" alt="gravatar" class="gravatar" />';
  612. }
  613. // ????
  614. if( $this->theme['comment']['isshow'] == 0 ) {
  615. $this->theme['comment']['comment'] = '[???????????????]';
  616. } elseif( $this->theme['comment']['isshow'] == 2 ) {
  617. $this->theme['comment']['comment'] = '[??????????????]';
  618. }
  619. $this->load('comment');
  620. }
  621. // ??
  622. public function show_guestbook(){
  623. global $db;
  624. $offset = ( $this->current_page - 1 ) * $this->max_per_page;
  625. $sql = "SELECT C.*,U.u_email,U.u_index FROM `" . DB_PREFIX . "comment` C LEFT JOIN `" . DB_PREFIX . "user` U ON U.u_username=C.replyuser WHERE C.isdel=False AND C.articleid = 0 ORDER BY C.cid DESC LIMIT $offset, $this->max_per_page";
  626. $temp = array();
  627. $temp = $db->fetch_all( $sql );
  628. foreach( $temp as $row => $value ){
  629. $this->theme['comment'] = $value;
  630. $this->show_comment_de();
  631. }
  632. }
  633. public function get_laodao( $offset = 0, $maxperpage = 0 ) {
  634. global $db,$theme;
  635. $admin = $db->fetch_one_array("SELECT * FROM `" . DB_PREFIX . "user` WHERE u_group=8");
  636. If( $admin['u_email'] <> '' ){
  637. $gravatar = split( "\|" , $admin['u_email'] );
  638. $this->theme['laodao']['gravatar'] = '<img src="http://www.gravatar.com/avatar.php?gravatar_id=' . $gravatar[1] . '?s=32&amp;d=wavatar&amp;r=G" height="32" width="32" alt="gravatar" class="gravatar" />';
  639. }else{
  640. $this->theme['laodao']['gravatar'] = '<img src="' . THEME_PATH . 'images/gravatar.jpg" height="32" width="32" alt="gravatar" class="gravatar" />';
  641. }
  642. $this->theme['laodao']['index'] = $admin['u_index'];
  643. $this->theme['laodao']['author'] = $admin['u_username'];
  644. $laodao_arr = $db->fetch_all("SELECT * FROM `" . DB_PREFIX . "laodao` ORDER BY ld_id DESC LIMIT $offset,$maxperpage");
  645. $output = '';
  646. foreach( $laodao_arr as $laodao ) {
  647. $this->theme['laodao']['ld_id'] = $laodao['ld_id'];
  648. $this->theme['laodao']['ld_time'] = $laodao['ld_time'];
  649. $this->theme['laodao']['ld_laodao'] = str_replace( array("\r\n", "\n", "\r"),'<br />', htmlspecialchars( $laodao['ld_laodao'] ) );
  650. $theme->load( 'laodao' );
  651. $output .= ob_get_contents();
  652. obclean();
  653. }
  654. return $output;
  655. }
  656. }
  657. ?>