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

/www/admin/source/lib/function.smarty.php

http://firmkernel.googlecode.com/
PHP | 597 lines | 480 code | 26 blank | 91 comment | 44 complexity | 804b4132a08634f8b164fd31df321c9f MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------------+
  4. | $Id: function.smarty.php 2010-05-24 11:45:43Z Bleakwind $
  5. | Private Smarty function
  6. | Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
  7. | http://www.weaverdream.com/
  8. | Release under the GNU Lesser General Public License Version 3 (LGPLv3):
  9. | http://www.gnu.org/licenses/lgpl.html
  10. +-----------------------------------------------------------------------------+
  11. */
  12. /*
  13. * Smarty plugin
  14. * -------------------------------------------------------------
  15. * File: function.return_article_info.php
  16. * Type: function
  17. * Name: return_article_info
  18. * Purpose: return article_info
  19. * -------------------------------------------------------------
  20. */
  21. function smarty_function_return_article_info($params, &$smarty)
  22. {
  23. global $sys;
  24. $_output = '';
  25. foreach ($params as $_key => $_val) {
  26. switch ($_key) {
  27. case 'item':
  28. $item = (string)$_val;
  29. break;
  30. case 'article_id':
  31. $article_id = (int)$_val;
  32. break;
  33. default:
  34. $smarty->trigger_error("return_article_info: unknown attribute '$_key'");
  35. }
  36. }
  37. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  38. $smarty->trigger_error("return_article_info: missing 'item' attribute");
  39. }
  40. if ( $article_id == "0") {
  41. $smarty->trigger_error("return_article_info: missing 'article_id' attribute");
  42. }
  43. $smarty->assign($item, $sys->return_article_info($article_id));
  44. return;
  45. }
  46. $t->register_function("return_article_info", "smarty_function_return_article_info");
  47. /*
  48. * Smarty plugin
  49. * -------------------------------------------------------------
  50. * File: function.return_article_list.php
  51. * Type: function
  52. * Name: return_article_list
  53. * Purpose: return article_list
  54. * -------------------------------------------------------------
  55. */
  56. function smarty_function_return_article_list($params, &$smarty)
  57. {
  58. global $sys;
  59. $_output = '';
  60. $condition = array();
  61. $list_article_id = array();
  62. foreach ($params as $_key => $_val) {
  63. switch ($_key) {
  64. case 'item':
  65. $item = (string)$_val;
  66. break;
  67. case 'article_id':
  68. $article_id = (string)$_val;
  69. break;
  70. case 'except_article_id':
  71. $except_article_id = (string)$_val;
  72. break;
  73. case 'cover':
  74. $cover = (int)$_val;
  75. break;
  76. case 'if_top':
  77. $if_top = (int)$_val;
  78. break;
  79. case 'limit':
  80. $limit = (int)$_val;
  81. break;
  82. default:
  83. $smarty->trigger_error("return_article_list: unknown attribute '$_key'");
  84. }
  85. }
  86. if (empty($item)) {
  87. $smarty->trigger_error("return_article_list: missing 'item' attribute");
  88. }
  89. $condition['article_id'] = $article_id;
  90. $condition['except_article_id'] = $except_article_id;
  91. $condition['cover'] = $cover;
  92. $condition['if_top'] = $if_top;
  93. $list = $sys->return_article_list($limit, $condition);
  94. if (!empty($list)) {
  95. foreach ($list as $v) {
  96. $list_article_id[] = $v['id'];
  97. }
  98. }
  99. $smarty->assign($item, $list);
  100. if (!empty($list_article_id)) {
  101. $smarty->assign($item."_id", implode(",", $list_article_id));
  102. }
  103. return;
  104. }
  105. $t->register_function("return_article_list", "smarty_function_return_article_list");
  106. /*
  107. * Smarty plugin
  108. * -------------------------------------------------------------
  109. * File: function.return_datum_info.php
  110. * Type: function
  111. * Name: return_datum_info
  112. * Purpose: return datum_info
  113. * -------------------------------------------------------------
  114. */
  115. function smarty_function_return_datum_info($params, &$smarty)
  116. {
  117. global $sys;
  118. $_output = '';
  119. foreach ($params as $_key => $_val) {
  120. switch ($_key) {
  121. case 'item':
  122. $item = (string)$_val;
  123. break;
  124. case 'datum_id':
  125. $datum_id = (int)$_val;
  126. break;
  127. default:
  128. $smarty->trigger_error("return_datum_info: unknown attribute '$_key'");
  129. }
  130. }
  131. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  132. $smarty->trigger_error("return_datum_info: missing 'item' attribute");
  133. }
  134. if ( $datum_id == "0") {
  135. $smarty->trigger_error("return_datum_info: missing 'datum_id' attribute");
  136. }
  137. $smarty->assign($item, $sys->return_datum_info($datum_id));
  138. return;
  139. }
  140. $t->register_function("return_datum_info", "smarty_function_return_datum_info");
  141. /*
  142. * Smarty plugin
  143. * -------------------------------------------------------------
  144. * File: function.return_datum_list.php
  145. * Type: function
  146. * Name: return_datum_list
  147. * Purpose: return datum_list
  148. * -------------------------------------------------------------
  149. */
  150. function smarty_function_return_datum_list($params, &$smarty)
  151. {
  152. global $sys;
  153. $_output = '';
  154. $condition = array();
  155. $list_datum_id = array();
  156. foreach ($params as $_key => $_val) {
  157. switch ($_key) {
  158. case 'item':
  159. $item = (string)$_val;
  160. break;
  161. case 'datum_id':
  162. $datum_id = (string)$_val;
  163. break;
  164. case 'except_datum_id':
  165. $except_datum_id = (string)$_val;
  166. break;
  167. case 'cover':
  168. $cover = (int)$_val;
  169. break;
  170. case 'if_top':
  171. $if_top = (int)$_val;
  172. break;
  173. case 'limit':
  174. $limit = (int)$_val;
  175. break;
  176. default:
  177. $smarty->trigger_error("return_datum_list: unknown attribute '$_key'");
  178. }
  179. }
  180. if (empty($item)) {
  181. $smarty->trigger_error("return_datum_list: missing 'item' attribute");
  182. }
  183. $condition['datum_id'] = $datum_id;
  184. $condition['except_datum_id'] = $except_datum_id;
  185. $condition['cover'] = $cover;
  186. $condition['if_top'] = $if_top;
  187. $list = $sys->return_datum_list($limit, $condition);
  188. if (!empty($list)) {
  189. foreach ($list as $v) {
  190. $list_datum_id[] = $v['id'];
  191. }
  192. }
  193. $smarty->assign($item, $list);
  194. if (!empty($list_datum_id)) {
  195. $smarty->assign($item."_id", implode(",", $list_datum_id));
  196. }
  197. return;
  198. }
  199. $t->register_function("return_datum_list", "smarty_function_return_datum_list");
  200. /*
  201. * Smarty plugin
  202. * -------------------------------------------------------------
  203. * File: function.return_content_info.php
  204. * Type: function
  205. * Name: return_content_info
  206. * Purpose: return content_info
  207. * -------------------------------------------------------------
  208. */
  209. function smarty_function_return_content_info($params, &$smarty)
  210. {
  211. global $sys;
  212. $_output = '';
  213. $content_info = array();
  214. foreach ($params as $_key => $_val) {
  215. switch ($_key) {
  216. case 'item':
  217. $item = (string)$_val;
  218. break;
  219. case 'act':
  220. $act = (string)$_val;
  221. break;
  222. case 'scheduler_id':
  223. $scheduler_id = (string)$_val;
  224. break;
  225. case 'except_scheduler_id':
  226. $except_scheduler_id = (string)$_val;
  227. break;
  228. case 'content_id':
  229. $content_id = (string)$_val;
  230. break;
  231. case 'except_content_id':
  232. $except_content_id = (string)$_val;
  233. break;
  234. case 'channel_id':
  235. $channel_id = (string)$_val;
  236. break;
  237. case 'prefix':
  238. $prefix = (int)$_val;
  239. break;
  240. case 'if_top':
  241. $if_top = (int)$_val;
  242. break;
  243. case 'cover':
  244. $cover = (int)$_val;
  245. break;
  246. case 'rank':
  247. $rank = (int)$_val;
  248. break;
  249. case 'click':
  250. $click = (int)$_val;
  251. break;
  252. case 'rand':
  253. $rand = (int)$_val;
  254. break;
  255. default:
  256. $smarty->trigger_error("return_content_info: unknown attribute '$_key'");
  257. }
  258. }
  259. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  260. $smarty->trigger_error("return_content_info: missing 'item' attribute");
  261. }
  262. if (preg_match("/^[1-9][0-9]{0,10}$/i", $scheduler_id)) {
  263. $sys->clean_model_info();
  264. $content_info = $sys->return_content_info($scheduler_id);
  265. if ($act == "jump") {
  266. $sys->prompt("jump",$CONFIGURE['common']['control_admin']."?act=content&scheduler_id=".$content_info['scheduler_id']."");
  267. } else {
  268. $smarty->assign($item, $content_info);
  269. }
  270. } elseif (preg_match("/^[1-9][0-9]{0,10}$/i", $content_id) || preg_match("/^[0-9,]+$/i", $channel_id) ) {
  271. $condition['except_scheduler_id'] = $except_scheduler_id;
  272. $condition['content_id'] = $content_id;
  273. $condition['except_content_id'] = $except_content_id;
  274. $condition['channel_id'] = $channel_id;
  275. $condition['prefix'] = $prefix;
  276. $condition['if_top'] = $if_top;
  277. $condition['cover'] = $cover;
  278. $condition['rank'] = $rank;
  279. $condition['click'] = $click;
  280. $condition['rand'] = $rand;
  281. $content_list = $sys->return_content_list("1", $condition);
  282. if (preg_match("/^[1-9][0-9]{0,10}$/i",$content_list[0]['scheduler_id'])) {
  283. if ($act == "jump") {
  284. $sys->prompt("jump",$CONFIGURE['common']['control_admin']."?act=content&scheduler_id=".$content_list[0]['scheduler_id']."");
  285. } else {
  286. $sys->clean_model_info();
  287. $content_info = $sys->return_content_info($content_list[0]['scheduler_id']);
  288. $smarty->assign($item, $content_info);
  289. }
  290. } else {
  291. $smarty->assign($item, $content_info);
  292. }
  293. } else {
  294. $smarty->trigger_error("return_content_info: missing 'scheduler_id|content_id' attribute");
  295. }
  296. return;
  297. }
  298. $t->register_function("return_content_info", "smarty_function_return_content_info");
  299. /*
  300. * Smarty plugin
  301. * -------------------------------------------------------------
  302. * File: function.return_content_list.php
  303. * Type: function
  304. * Name: return_content_list
  305. * Purpose: return content_list
  306. * -------------------------------------------------------------
  307. */
  308. function smarty_function_return_content_list($params, &$smarty)
  309. {
  310. global $sys;
  311. $_output = '';
  312. $condition = array();
  313. $list_content_id = array();
  314. foreach ($params as $_key => $_val) {
  315. switch ($_key) {
  316. case 'item':
  317. $item = (string)$_val;
  318. break;
  319. case 'scheduler_id':
  320. $scheduler_id = (string)$_val;
  321. break;
  322. case 'except_scheduler_id':
  323. $except_scheduler_id = (string)$_val;
  324. break;
  325. case 'content_id':
  326. $content_id = (string)$_val;
  327. break;
  328. case 'except_content_id':
  329. $except_content_id = (string)$_val;
  330. break;
  331. case 'channel_id':
  332. $channel_id = (string)$_val;
  333. break;
  334. case 'prefix':
  335. $prefix = (int)$_val;
  336. break;
  337. case 'if_enable':
  338. $if_enable = (int)$_val;
  339. break;
  340. case 'if_top':
  341. $if_top = (int)$_val;
  342. break;
  343. case 'if_view':
  344. $if_view = (int)$_val;
  345. break;
  346. case 'if_inerface':
  347. $if_inerface = (int)$_val;
  348. break;
  349. case 'if_turn':
  350. $if_turn = (int)$_val;
  351. break;
  352. case 'if_turn_type':
  353. $if_turn_type = (int)$_val;
  354. break;
  355. case 'cover':
  356. $cover = (int)$_val;
  357. break;
  358. case 'rank':
  359. $rank = (int)$_val;
  360. break;
  361. case 'click':
  362. $click = (int)$_val;
  363. break;
  364. case 'rand':
  365. $rand = (int)$_val;
  366. break;
  367. case 'limit':
  368. $limit = (int)$_val;
  369. break;
  370. case 'page_item':
  371. $page_item = (string)$_val;
  372. break;
  373. case 'page_current':
  374. $page_current = (int)$_val;
  375. break;
  376. case 'page_listnum':
  377. $page_listnum = (int)$_val;
  378. break;
  379. case 'page_url':
  380. $page_url = (string)$_val;
  381. break;
  382. default:
  383. $smarty->trigger_error("return_content_list: unknown attribute '$_key'");
  384. }
  385. }
  386. if (empty($item)) {
  387. $smarty->trigger_error("return_content_list: missing 'item' attribute");
  388. }
  389. $condition['scheduler_id'] = $scheduler_id;
  390. $condition['except_scheduler_id'] = $except_scheduler_id;
  391. $condition['content_id'] = $content_id;
  392. $condition['except_content_id'] = $except_content_id;
  393. $condition['channel_id'] = $channel_id;
  394. $condition['prefix'] = $prefix;
  395. $condition['if_enable'] = $if_enable;
  396. $condition['if_top'] = $if_top;
  397. $condition['if_view'] = $if_view;
  398. $condition['if_inerface'] = $if_inerface;
  399. $condition['if_turn'] = $if_turn;
  400. $condition['if_turn_type'] = $if_turn_type;
  401. $condition['cover'] = $cover;
  402. $condition['rank'] = $rank;
  403. $condition['click'] = $click;
  404. $condition['rand'] = $rand;
  405. $condition['page_item'] = preg_match("/^[a-z0-9_]+$/i", $page_item) ? $page_item : "pagination_".$item;
  406. $condition['page_current'] = preg_match("/^[1-9][0-9]{0,10}$/i", $page_current) ? $page_current : "1";
  407. $condition['page_listnum'] = preg_match("/^[1-9][0-9]{0,10}$/i", $page_listnum) ? $page_listnum : $CONFIG['page_record_content_list'];
  408. $condition['page_url'] = $page_url;
  409. $list = $sys->return_content_list($limit, $condition);
  410. if (!empty($list)) {
  411. foreach ($list as $v) {
  412. $list_content_id[] = $v['id'];
  413. }
  414. }
  415. $smarty->assign($item, $list);
  416. if (is_array($list_content_id) && count($list_content_id) > 0) {
  417. $smarty->assign($item."_id", implode(",", $list_content_id));
  418. }
  419. return;
  420. }
  421. $t->register_function("return_content_list", "smarty_function_return_content_list");
  422. /*
  423. * Smarty plugin
  424. * -------------------------------------------------------------
  425. * File: function.return_channel_info.php
  426. * Type: function
  427. * Name: return_channel_info
  428. * Purpose: return channel_info
  429. * -------------------------------------------------------------
  430. */
  431. function smarty_function_return_channel_info($params, &$smarty)
  432. {
  433. global $sys;
  434. $_output = '';
  435. foreach ($params as $_key => $_val) {
  436. switch ($_key) {
  437. case 'item':
  438. $item = (string)$_val;
  439. break;
  440. case 'channel_id':
  441. $channel_id = (int)$_val;
  442. break;
  443. default:
  444. $smarty->trigger_error("return_channel_info: unknown attribute '$_key'");
  445. }
  446. }
  447. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  448. $smarty->trigger_error("return_channel_info: missing 'item' attribute");
  449. }
  450. if ( $channel_id == "0") {
  451. $smarty->trigger_error("return_channel_info: missing 'channel_id' attribute");
  452. }
  453. $smarty->assign($item, $sys->return_channel_info($channel_id));
  454. return;
  455. }
  456. $t->register_function("return_channel_info", "smarty_function_return_channel_info");
  457. /*
  458. * Smarty plugin
  459. * -------------------------------------------------------------
  460. * File: function.return_channel_list.php
  461. * Type: function
  462. * Name: return_channel_list
  463. * Purpose: return channel_list
  464. * -------------------------------------------------------------
  465. */
  466. function smarty_function_return_channel_list($params, &$smarty)
  467. {
  468. global $sys;
  469. $_output = '';
  470. foreach ($params as $_key => $_val) {
  471. switch ($_key) {
  472. case 'item':
  473. $item = (string)$_val;
  474. break;
  475. case 'upper_id':
  476. $upper_id = (int)$_val;
  477. break;
  478. case 'allsub':
  479. $allsub = (int)$_val;
  480. break;
  481. case 'if_enable':
  482. $if_enable = (int)$_val;
  483. break;
  484. case 'if_show':
  485. $if_show = (int)$_val;
  486. break;
  487. case 'if_add':
  488. $if_add = (int)$_val;
  489. break;
  490. case 'if_splitword':
  491. $if_splitword = (int)$_val;
  492. break;
  493. case 'if_recommend':
  494. $if_recommend = (int)$_val;
  495. break;
  496. case 'if_view':
  497. $if_view = (int)$_val;
  498. break;
  499. case 'if_inerface':
  500. $if_inerface = (int)$_val;
  501. break;
  502. case 'if_turn':
  503. $if_turn = (int)$_val;
  504. break;
  505. case 'if_turn_type':
  506. $if_turn_type = (int)$_val;
  507. break;
  508. case 'rank':
  509. $rank = (int)$_val;
  510. break;
  511. case 'limit':
  512. $limit = (int)$_val;
  513. break;
  514. default:
  515. $smarty->trigger_error("return_channel_list: unknown attribute '$_key'");
  516. }
  517. }
  518. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  519. $smarty->trigger_error("return_channel_list: missing 'item' attribute");
  520. }
  521. $condition['allsub'] = $allsub;
  522. $condition['if_enable'] = $if_enable;
  523. $condition['if_show'] = $if_show;
  524. $condition['if_add'] = $if_add;
  525. $condition['if_splitword'] = $if_splitword;
  526. $condition['if_recommend'] = $if_recommend;
  527. $condition['if_view'] = $if_view;
  528. $condition['if_inerface'] = $if_inerface;
  529. $condition['if_turn'] = $if_turn;
  530. $condition['if_turn_type'] = $if_turn_type;
  531. $condition['rank'] = $rank;
  532. $smarty->assign($item, $sys->return_channel_list($upper_id, $limit, $condition));
  533. return;
  534. }
  535. $t->register_function("return_channel_list", "smarty_function_return_channel_list");
  536. /*
  537. * Smarty plugin
  538. * -------------------------------------------------------------
  539. * File: function.return_channel_manage.php
  540. * Type: function
  541. * Name: return_channel_manage
  542. * Purpose: return_channel_manage
  543. * -------------------------------------------------------------
  544. */
  545. function smarty_function_return_channel_manage($params, &$smarty)
  546. {
  547. global $sys;
  548. $_output = '';
  549. foreach ($params as $_key => $_val) {
  550. switch ($_key) {
  551. case 'item':
  552. $item = (string)$_val;
  553. break;
  554. case 'channel_id':
  555. $channel_id = (int)$_val;
  556. break;
  557. default:
  558. $smarty->trigger_error("return_channel_manage: unknown attribute '$_key'");
  559. }
  560. }
  561. if (!preg_match("/^[0-9a-z_]{1,30}$/i", $item)) {
  562. $smarty->trigger_error("return_channel_manage: missing 'item' attribute");
  563. }
  564. if ( $channel_id == "0") {
  565. $smarty->trigger_error("return_channel_manage: missing 'channel_id' attribute");
  566. }
  567. $smarty->assign($item, $sys->return_channel_manage($channel_id));
  568. return;
  569. }
  570. $t->register_function("return_channel_manage", "smarty_function_return_channel_manage");
  571. ?>