template.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class AppTemplate
  10. {
  11. var $template_dir = '';
  12. var $cache_dir = '';
  13. var $compile_dir = '';
  14. var $cache_lifetime = 3600; // 缓存更新时间, 默认 3600 秒
  15. var $direct_output = false;
  16. var $caching = false;
  17. var $template = array();
  18. var $force_compile = false;
  19. var $_var = array();
  20. var $_hash = '554fcae493e564ee0dc75bdf2ebf94ca';
  21. var $_foreach = array();
  22. var $_current_file = '';
  23. var $_expires = 0;
  24. var $_errorlevel = 0;
  25. var $_nowtime = null;
  26. var $_checkfile = true;
  27. var $_foreachmark = '';
  28. var $_seterror = 0;
  29. var $_temp_key = array(); // 临时存放 foreach 里 key 的数组
  30. var $_temp_val = array(); // 临时存放 foreach 里 item 的数组
  31. var $_domain = SITE_DOMAIN;
  32. function __construct()
  33. {
  34. $this->APP_TMPL_PATH();
  35. }
  36. function APP_TMPL_PATH()
  37. {
  38. $this->_errorlevel = error_reporting();
  39. $this->_nowtime = time();
  40. header('Content-type: text/html; charset=utf-8');
  41. }
  42. /**
  43. * 注册变量
  44. *
  45. * @access public
  46. * @param mix $tpl_var
  47. * @param mix $value
  48. *
  49. * @return void
  50. */
  51. function assign($tpl_var, $value = '')
  52. {
  53. if (is_array($tpl_var))
  54. {
  55. foreach ($tpl_var AS $key => $val)
  56. {
  57. if ($key != '')
  58. {
  59. $this->_var[$key] = $val;
  60. }
  61. }
  62. }
  63. else
  64. {
  65. if ($tpl_var != '')
  66. {
  67. $this->_var[$tpl_var] = $value;
  68. }
  69. }
  70. }
  71. /**
  72. * 处理模板文件
  73. *
  74. * @access public
  75. * @param string $filename
  76. * @param sting $cache_id
  77. *
  78. * @return sring
  79. */
  80. function fetch($filename, $cache_id = '')
  81. {
  82. $domain = SITE_DOMAIN.APP_ROOT;
  83. if (!$this->_seterror)
  84. {
  85. // error_reporting(E_ALL ^ E_NOTICE);
  86. }
  87. $this->_seterror++;
  88. if (strncmp($filename,'str:', 4) == 0)
  89. {
  90. $out = $this->_eval($this->fetch_str(substr($filename, 4)));
  91. $out = $this->es_tmpl($out);
  92. }
  93. else
  94. {
  95. if ($this->_checkfile)
  96. {
  97. if (!is_file($filename))
  98. {
  99. $filename = $this->template_dir . '/' . $filename;
  100. }
  101. }
  102. else
  103. {
  104. $filename = $this->template_dir . '/' . $filename;
  105. }
  106. if ($this->direct_output)
  107. {
  108. $this->_current_file = $filename;
  109. $out = $this->_eval($this->fetch_str(file_get_contents($filename)));
  110. $out = $this->es_tmpl($out);
  111. }
  112. else
  113. {
  114. if (app_conf("TMPL_CACHE_ON")==1&&$cache_id && $this->caching&&!IS_DEBUG)
  115. {
  116. $out = $this->template_out;
  117. }
  118. else
  119. {
  120. if (!in_array($filename, $this->template))
  121. {
  122. $this->template[] = $filename;
  123. }
  124. $out = $this->make_compiled($filename);
  125. $out = $this->es_tmpl($out);
  126. if (app_conf("TMPL_CACHE_ON")==1&&$cache_id)
  127. {
  128. $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;
  129. $data = serialize(array('template' => $this->template, 'expires' => $this->_nowtime + $this->cache_lifetime, 'maketime' => $this->_nowtime));
  130. $out = str_replace("\r", '', $out);
  131. while (strpos($out, "\n\n") !== false)
  132. {
  133. $out = str_replace("\n\n", "\n", $out);
  134. }
  135. $hash_dir = $this->cache_dir . '/c' . substr(md5($cachename), 0, 1);
  136. //$hash_dir = $this->cache_dir;
  137. if (!is_dir($hash_dir))
  138. {
  139. mkdir($hash_dir);
  140. @chmod($hash_dir, 0777);
  141. }
  142. if (file_put_contents($hash_dir . '/' . $cachename . '.php', '<?php exit;?>' . $data . $out, LOCK_EX) === false)
  143. {
  144. trigger_error('can\'t write:' . $hash_dir . '/' . $cachename . '.php');
  145. }
  146. $this->template = array();
  147. }
  148. }
  149. }
  150. }
  151. $this->_seterror--;
  152. if (!$this->_seterror)
  153. {
  154. error_reporting($this->_errorlevel);
  155. }
  156. //end
  157. return $out; // 返回html数据
  158. }
  159. function es_tmpl($out)
  160. {
  161. //对延时加载的修正 .lazy
  162. preg_match_all("/<img.*?lazy=[\"|\']\S*[\"\'][^\>]*>/",$out,$lazy_array);
  163. foreach($lazy_array[0] as $lazy_item)
  164. {
  165. $lazy_item_replace = str_replace(" src="," data-src=",$lazy_item);
  166. $out = str_replace($lazy_item,$lazy_item_replace,$out);
  167. }
  168. //对图片路径的修复
  169. //对图片路径的修复
  170. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  171. {
  172. $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
  173. }
  174. else
  175. {
  176. $domain = SITE_DOMAIN.APP_ROOT;
  177. }
  178. $out = str_replace(APP_ROOT."./public/",$domain."/public/",$out);
  179. $out = str_replace("./public/",$domain."/public/",$out);
  180. //修复url的路径
  181. $out = str_replace("./",SITE_DOMAIN.APP_ROOT."/",$out);
  182. //修复url的路径
  183. // $out = str_replace("./",get_domain().APP_ROOT."/",$out);
  184. $out = preg_replace("/href=([\'\"]*)\.\//","href=\\1".get_domain().APP_ROOT."/",$out);
  185. //对广告位的解析
  186. preg_match_all("/<adv(\s+)adv_id=\"(\S+)\"([^>]*)>/",$out,$layout_array);
  187. foreach($layout_array[2] as $k=>$adv_id)
  188. {
  189. if(trim($layout_array[3][$k])!='/') //有关联数据
  190. {
  191. preg_match_all("/rel_table=\"(\S+)\"(\s+)rel_id=\"(\S+)\"/",$layout_array[3][$k],$rel_array);
  192. $adv = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."adv where tmpl='".app_conf("TEMPLATE")."' and adv_id='".$adv_id."' and rel_table = '".$rel_array[1][0]."' and rel_id = ".intval($rel_array[3][0])." and is_effect = 1");
  193. }
  194. else
  195. {
  196. $adv = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."adv where tmpl='".app_conf("TEMPLATE")."' and adv_id='".$adv_id."' and is_effect = 1");
  197. }
  198. if($adv['city_ids']!='')
  199. {
  200. $city_ids = explode(',',$adv['city_ids']);
  201. if(in_array($GLOBALS['city']['id'],$city_ids))
  202. {
  203. $out = preg_replace("/<adv(\s+)adv_id=\"".$adv_id."\"([^>]*)>/i",$adv['code'],$out,1);
  204. //对图片路径的修复
  205. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  206. {
  207. $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
  208. }
  209. else
  210. {
  211. $domain = SITE_DOMAIN.APP_ROOT;
  212. }
  213. $out = str_replace($GLOBALS['IMG_APP_ROOT']."./public/",$domain."/public/",$out);
  214. $out = str_replace("./public/",$domain."/public/",$out);
  215. //修复url的路径
  216. $out = str_replace("./",SITE_DOMAIN.APP_ROOT."/",$out);
  217. }
  218. }
  219. else
  220. {
  221. $out = preg_replace("/<adv(\s+)adv_id=\"".$adv_id."\"([^>]*)>/i",$adv['code'],$out,1);
  222. //对图片路径的修复
  223. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']!="NONE")
  224. {
  225. $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN'];
  226. }
  227. else
  228. {
  229. $domain = SITE_DOMAIN.APP_ROOT;
  230. }
  231. $out = str_replace($GLOBALS['IMG_APP_ROOT']."./public/",$domain."/public/",$out);
  232. $out = str_replace("./public/",$domain."/public/",$out);
  233. //修复url的路径
  234. $out = str_replace("./",SITE_DOMAIN.APP_ROOT."/",$out);
  235. }
  236. unset($adv);
  237. }
  238. //end
  239. return $out;
  240. }
  241. /**
  242. * 显示页面函数
  243. *
  244. * @access public
  245. * @param string $filename
  246. * @param sting $cache_id
  247. *
  248. * @return void
  249. */
  250. function display($filename, $cache_id = '',$is_return=false)
  251. {
  252. $this->_seterror++;
  253. error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
  254. $this->_checkfile = false;
  255. $out = $this->fetch($filename, $cache_id);
  256. if (strpos($out, $this->_hash) !== false)
  257. {
  258. $k = explode($this->_hash, $out);
  259. foreach ($k AS $key => $val)
  260. {
  261. if (($key % 2) == 1)
  262. {
  263. $k[$key] = $this->insert_mod($val);
  264. }
  265. }
  266. $out = implode('', $k);
  267. }
  268. error_reporting($this->_errorlevel);
  269. $this->_seterror--;
  270. //sql_check();
  271. if($is_return)
  272. return $out;
  273. else
  274. gzip_out($out.run_info());
  275. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']=="ES_FILE")
  276. {
  277. if(count($GLOBALS['curl_param']['images'])>0)
  278. {
  279. $GLOBALS['curl_param']['images'] = base64_encode(serialize($GLOBALS['curl_param']['images']));
  280. curl_setopt($GLOBALS['syn_image_ci'], CURLOPT_POSTFIELDS, $GLOBALS['curl_param']);
  281. $rss = curl_exec($GLOBALS['syn_image_ci']);
  282. }
  283. curl_close($GLOBALS['syn_image_ci']);
  284. //echo $rss;exit;
  285. }
  286. }
  287. /**
  288. * 编译模板函数
  289. *
  290. * @access public
  291. * @param string $filename
  292. *
  293. * @return sring 编译后文件地址
  294. */
  295. function make_compiled($filename)
  296. {
  297. $name = $this->compile_dir . '/' . basename($filename) . '.php';
  298. if ($this->_expires)
  299. {
  300. $expires = $this->_expires - $this->cache_lifetime;
  301. }
  302. else
  303. {
  304. $filestat = @stat($name);
  305. $expires = $filestat['mtime'];
  306. }
  307. $filestat = @stat($filename);
  308. if ($filestat['mtime'] <= $expires && !$this->force_compile)
  309. {
  310. if (file_exists($name))
  311. {
  312. $source = $this->_require($name);
  313. if ($source == '')
  314. {
  315. $expires = 0;
  316. }
  317. }
  318. else
  319. {
  320. $source = '';
  321. $expires = 0;
  322. }
  323. }
  324. if ($this->force_compile || $filestat['mtime'] > $expires)
  325. {
  326. $this->_current_file = $filename;
  327. $source = $this->fetch_str(@file_get_contents($filename));
  328. @file_put_contents($name, $source, LOCK_EX);
  329. $source = $this->_eval($source);
  330. }
  331. return $source;
  332. }
  333. /**
  334. * 处理字符串函数
  335. *
  336. * @access public
  337. * @param string $source
  338. *
  339. * @return sring
  340. */
  341. function fetch_str($source)
  342. {
  343. return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
  344. }
  345. public function clear_cache($filename,$cached_id)
  346. {
  347. $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cached_id;
  348. $hash_dir = $this->cache_dir . '/c' . substr(md5($cachename), 0, 1);
  349. @unlink($hash_dir . '/' . $cachename . '.php');
  350. }
  351. /**
  352. * 判断是否缓存
  353. *
  354. * @access public
  355. * @param string $filename
  356. * @param sting $cache_id
  357. *
  358. * @return bool
  359. */
  360. function is_cached($filename, $cache_id = '')
  361. {
  362. $cachename = basename($filename, strrchr($filename, '.')) . '_' . $cache_id;
  363. if (app_conf("TMPL_CACHE_ON")==1&&$this->caching == true && $this->direct_output == false&&!IS_DEBUG)
  364. {
  365. $hash_dir = $this->cache_dir . '/c' . substr(md5($cachename), 0, 1);
  366. //$hash_dir = $this->cache_dir;
  367. if ($data = @file_get_contents($hash_dir . '/' . $cachename . '.php'))
  368. {
  369. $data = substr($data, 13);
  370. $pos = strpos($data, '<');
  371. $paradata = substr($data, 0, $pos);
  372. $para = @unserialize($paradata);
  373. if ($para === false || $this->_nowtime > $para['expires'])
  374. {
  375. $this->caching = false;
  376. return false;
  377. }
  378. $this->_expires = $para['expires'];
  379. $this->template_out = substr($data, $pos);
  380. foreach ($para['template'] AS $val)
  381. {
  382. $stat = @stat($val);
  383. if ($para['maketime'] < $stat['mtime'])
  384. {
  385. $this->caching = false;
  386. return false;
  387. }
  388. }
  389. }
  390. else
  391. {
  392. $this->caching = false;
  393. return false;
  394. }
  395. return true;
  396. }
  397. else
  398. {
  399. return false;
  400. }
  401. }
  402. /**
  403. * 处理{}标签
  404. *
  405. * @access public
  406. * @param string $tag
  407. *
  408. * @return sring
  409. */
  410. function select($tag)
  411. {
  412. $tag = stripslashes(trim($tag));
  413. if (empty($tag))
  414. {
  415. return '{}';
  416. }
  417. elseif ($tag{0} == '*' && substr($tag, -1) == '*') // 注释部分
  418. {
  419. return '';
  420. }
  421. elseif ($tag{0} == '$') // 变量
  422. {
  423. return '<?php echo ' . $this->get_val(substr($tag, 1)) . '; ?>';
  424. }
  425. elseif ($tag{0} == '/') // 结束 tag
  426. {
  427. switch (substr($tag, 1))
  428. {
  429. case 'if':
  430. return '<?php endif; ?>';
  431. break;
  432. case 'foreach':
  433. if ($this->_foreachmark == 'foreachelse')
  434. {
  435. $output = '<?php endif; unset($_from); ?>';
  436. }
  437. else
  438. {
  439. array_pop($this->_patchstack);
  440. $output = '<?php endforeach; endif; unset($_from); ?>';
  441. }
  442. $output .= "<?php \$this->pop_vars();; ?>";
  443. return $output;
  444. break;
  445. case 'literal':
  446. return '';
  447. break;
  448. default:
  449. return '{'. $tag .'}';
  450. break;
  451. }
  452. }
  453. else
  454. {
  455. //$tag_sel = array_shift(explode(' ', $tag));
  456. $tag_array=explode(' ', $tag);
  457. $tag_sel = array_shift($tag_array);
  458. switch ($tag_sel)
  459. {
  460. case 'if':
  461. return $this->_compile_if_tag(substr($tag, 3));
  462. break;
  463. case 'else':
  464. return '<?php else: ?>';
  465. break;
  466. case 'elseif':
  467. return $this->_compile_if_tag(substr($tag, 7), true);
  468. break;
  469. case 'foreachelse':
  470. $this->_foreachmark = 'foreachelse';
  471. return '<?php endforeach; else: ?>';
  472. break;
  473. case 'foreach':
  474. $this->_foreachmark = 'foreach';
  475. if(!isset($this->_patchstack))
  476. {
  477. $this->_patchstack = array();
  478. }
  479. return $this->_compile_foreach_start(substr($tag, 8));
  480. break;
  481. case 'assign':
  482. $t = $this->get_para(substr($tag, 7),0);
  483. if ($t['value']{0} == '$')
  484. {
  485. /* 如果传进来的值是变量,就不用用引号 */
  486. $tmp = '$this->assign(\'' . $t['var'] . '\',' . $t['value'] . ');';
  487. }
  488. else
  489. {
  490. $tmp = '$this->assign(\'' . $t['var'] . '\',\'' . addcslashes($t['value'], "'") . '\');';
  491. }
  492. // $tmp = $this->assign($t['var'], $t['value']);
  493. return '<?php ' . $tmp . ' ?>';
  494. break;
  495. case 'include':
  496. $t = $this->get_para(substr($tag, 8), 0);
  497. if(substr($t[file],-4,4)!='html')
  498. {
  499. $code = var_export($this->_var[$t['inc_var']],1);
  500. if($t['inc_var'])
  501. {
  502. return '<?php $this->assign(\'inc_var\','.$code.');echo $this->fetch(' . "$t[file]" . '); ?>';
  503. }
  504. else
  505. {
  506. return '<?php echo $this->fetch(' . "$t[file]" . '); ?>';
  507. }
  508. }
  509. else
  510. {
  511. $code = var_export($this->_var[$t['inc_var']],1);
  512. if($t['inc_var'])
  513. return '<?php $this->assign(\'inc_var\','.$code.');echo $this->fetch(' . "'$t[file]'" . '); ?>';
  514. else
  515. return '<?php echo $this->fetch(' . "'$t[file]'" . '); ?>';
  516. }
  517. break;
  518. case 'insert_scripts':
  519. $t = $this->get_para(substr($tag, 15), 0);
  520. return '<?php echo $this->smarty_insert_scripts(' . $this->make_array($t) . '); ?>';
  521. break;
  522. case 'create_pages':
  523. $t = $this->get_para(substr($tag, 13), 0);
  524. return '<?php echo $this->smarty_create_pages(' . $this->make_array($t) . '); ?>';
  525. break;
  526. case 'insert' :
  527. $t = $this->get_para(substr($tag, 7), false);
  528. $out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
  529. $out .= 'echo $this->_hash . $k[\'name\'] . \'|\' . base64_encode(serialize($k)) . $this->_hash;' . "\n?>";
  530. return $out;
  531. break;
  532. case 'literal':
  533. return '';
  534. break;
  535. case 'cycle' :
  536. $t = $this->get_para(substr($tag, 6), 0);
  537. return '<?php echo $this->cycle(' . $this->make_array($t) . '); ?>';
  538. break;
  539. case 'html_options':
  540. $t = $this->get_para(substr($tag, 13), 0);
  541. return '<?php echo $this->html_options(' . $this->make_array($t) . '); ?>';
  542. break;
  543. case 'html_select_date':
  544. $t = $this->get_para(substr($tag, 17), 0);
  545. return '<?php echo $this->html_select_date(' . $this->make_array($t) . '); ?>';
  546. break;
  547. case 'html_radios':
  548. $t = $this->get_para(substr($tag, 12), 0);
  549. return '<?php echo $this->html_radios(' . $this->make_array($t) . '); ?>';
  550. break;
  551. case 'html_select_time':
  552. $t = $this->get_para(substr($tag, 12), 0);
  553. return '<?php echo $this->html_select_time(' . $this->make_array($t) . '); ?>';
  554. break;
  555. case 'function' :
  556. $t = $this->get_para(substr($tag, 8), false);
  557. $out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
  558. $out .= 'echo $k[\'name\'](';
  559. $first = true;
  560. foreach($t as $n => $v)
  561. {
  562. if($n != "name")
  563. {
  564. if($first)
  565. {
  566. $out .='$k[\''.$n.'\']';
  567. $first = false;
  568. }
  569. else
  570. {
  571. $out .=',$k[\''.$n.'\']';
  572. }
  573. }
  574. }
  575. $out .= ');' . "\n?>";
  576. return $out;
  577. break;
  578. case 'url_wap' :
  579. $reg_text = "/\"([^\"]+)\"/";
  580. preg_match_all($reg_text,$tag,$matches);
  581. if(count($matches[0])>0)
  582. {
  583. //url格式正确
  584. $param_str = "\"\"";
  585. if(isset($matches[0][1])&&$matches[0][1]!='')
  586. {
  587. //有额外传参
  588. //return print_r($matches[0][2],true);
  589. preg_match_all("/[$]([^\"&]+)/",$matches[0][1],$param_matches);
  590. $replacement = array();
  591. $finder = array();
  592. if(count($param_matches[0])>0)
  593. {
  594. foreach($param_matches[0] as $m_item)
  595. {
  596. $finder[] = $m_item;
  597. }
  598. //有参数
  599. foreach($param_matches[1] as $p_item)
  600. {
  601. $p_item_arr = explode(".",$p_item);
  602. $var_str = '".$this->_var';
  603. foreach($p_item_arr as $var_item)
  604. {
  605. $var_str = $var_str."['".$var_item."']";
  606. }
  607. $var_str.='."';
  608. $replacement[] = $var_str;
  609. }
  610. }
  611. $param_str = str_replace($finder,$replacement,$matches[0][1]);
  612. }
  613. //$app_index = $matches[1][0];
  614. $route = $matches[1][0];
  615. if(empty($route))
  616. $route = "index";
  617. $code = "<?php\r\n";
  618. $code.= "echo parse_url_tag_wap(\"";
  619. $code.="u:";
  620. $code.= $route."|\".";
  621. $code.=$param_str.".";
  622. $code.="\"\"); \r\n";
  623. $code.="?>";
  624. return $code;
  625. }
  626. else
  627. {
  628. return '{' . $tag . '}';
  629. }
  630. break;
  631. case 'url' :
  632. $reg_text = "/\"([^\"]+)\"/";
  633. preg_match_all($reg_text,$tag,$matches);
  634. if(count($matches[0])>0)
  635. {
  636. //url格式正确
  637. $param_str = "\"\"";
  638. if(isset($matches[0][1])&&$matches[0][1]!='')
  639. {
  640. //有额外传参
  641. //return print_r($matches[0][2],true);
  642. preg_match_all("/[$]([^\"&]+)/",$matches[0][1],$param_matches);
  643. $replacement = array();
  644. $finder = array();
  645. if(count($param_matches[0])>0)
  646. {
  647. foreach($param_matches[0] as $m_item)
  648. {
  649. $finder[] = $m_item;
  650. }
  651. //有参数
  652. foreach($param_matches[1] as $p_item)
  653. {
  654. $p_item_arr = explode(".",$p_item);
  655. $var_str = '".$this->_var';
  656. foreach($p_item_arr as $var_item)
  657. {
  658. $var_str = $var_str."['".$var_item."']";
  659. }
  660. $var_str.='."';
  661. $replacement[] = $var_str;
  662. }
  663. }
  664. $param_str = str_replace($finder,$replacement,$matches[0][1]);
  665. }
  666. //$app_index = $matches[1][0];
  667. $route = $matches[1][0];
  668. if(empty($route))
  669. $route = "index";
  670. $code = "<?php\r\n";
  671. $code.= "echo parse_url_tag(\"";
  672. $code.="u:";
  673. $code.= $route."|\".";
  674. $code.=$param_str.".";
  675. $code.="\"\"); \r\n";
  676. $code.="?>";
  677. return $code;
  678. }
  679. else
  680. {
  681. return '{' . $tag . '}';
  682. }
  683. break;
  684. default:
  685. return '{' . $tag . '}';
  686. break;
  687. }
  688. }
  689. }
  690. /**
  691. * 处理smarty标签中的变量标签
  692. *
  693. * @access public
  694. * @param string $val
  695. *
  696. * @return bool
  697. */
  698. function get_val($val)
  699. {
  700. if (strrpos($val, '[') !== false)
  701. {
  702. $val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
  703. }
  704. if (strrpos($val, '|') !== false)
  705. {
  706. $moddb = explode('|', $val);
  707. $val = array_shift($moddb);
  708. }
  709. if (empty($val))
  710. {
  711. return '';
  712. }
  713. if (strpos($val, '.$') !== false)
  714. {
  715. $all = explode('.$', $val);
  716. foreach ($all AS $key => $val)
  717. {
  718. $all[$key] = $key == 0 ? $this->make_var($val) : '['. $this->make_var($val) . ']';
  719. }
  720. $p = implode('', $all);
  721. }
  722. else
  723. {
  724. $p = $this->make_var($val);
  725. }
  726. if (!empty($moddb))
  727. {
  728. foreach ($moddb AS $key => $mod)
  729. {
  730. $s = explode(':', $mod);
  731. switch ($s[0])
  732. {
  733. case 'escape':
  734. $s[1] = trim($s[1], '"');
  735. if ($s[1] == 'html')
  736. {
  737. $p = 'htmlspecialchars(' . $p . ')';
  738. }
  739. elseif ($s[1] == 'url')
  740. {
  741. $p = 'urlencode(' . $p . ')';
  742. }
  743. elseif ($s[1] == 'decode_url')
  744. {
  745. $p = 'urldecode(' . $p . ')';
  746. }
  747. elseif ($s[1] == 'quotes')
  748. {
  749. $p = 'addslashes(' . $p . ')';
  750. }
  751. elseif ($s[1] == 'u8_url')
  752. {
  753. if (EC_CHARSET != 'utf-8')
  754. {
  755. $p = 'urlencode(ecs_iconv("' . EC_CHARSET . '", "utf-8",' . $p . '))';
  756. }
  757. else
  758. {
  759. $p = 'urlencode(' . $p . ')';
  760. }
  761. }
  762. else
  763. {
  764. $p = 'htmlspecialchars(' . $p . ')';
  765. }
  766. break;
  767. case 'nl2br':
  768. $p = 'nl2br(' . $p . ')';
  769. break;
  770. case 'default':
  771. $s[1] = $s[1]{0} == '$' ? $this->get_val(substr($s[1], 1)) : "'$s[1]'";
  772. $p = 'empty(' . $p . ') ? ' . $s[1] . ' : ' . $p;
  773. break;
  774. case 'truncate':
  775. $p = 'sub_str(' . $p . ",$s[1])";
  776. break;
  777. case 'strip_tags':
  778. $p = 'strip_tags(' . $p . ')';
  779. break;
  780. default:
  781. # code...
  782. break;
  783. }
  784. }
  785. }
  786. return $p;
  787. }
  788. /**
  789. * 处理去掉$的字符串
  790. *
  791. * @access public
  792. * @param string $val
  793. *
  794. * @return bool
  795. */
  796. function make_var($val)
  797. {
  798. if (strrpos($val, '.') === false)
  799. {
  800. if (isset($this->_var[$val]) && isset($this->_patchstack[$val]))
  801. {
  802. $val = $this->_patchstack[$val];
  803. }
  804. $p = '$this->_var[\'' . $val . '\']';
  805. }
  806. else
  807. {
  808. $t = explode('.', $val);
  809. $_var_name = array_shift($t);
  810. if (isset($this->_var[$_var_name]) && isset($this->_patchstack[$_var_name]))
  811. {
  812. $_var_name = $this->_patchstack[$_var_name];
  813. }
  814. if ($_var_name == 'smarty')
  815. {
  816. $p = $this->_compile_smarty_ref($t);
  817. }
  818. else
  819. {
  820. $p = '$this->_var[\'' . $_var_name . '\']';
  821. }
  822. foreach ($t AS $val)
  823. {
  824. $p.= '[\'' . $val . '\']';
  825. }
  826. }
  827. return $p;
  828. }
  829. /**
  830. * 处理insert外部函数/需要include运行的函数的调用数据
  831. *
  832. * @access public
  833. * @param string $val
  834. * @param int $type
  835. *
  836. * @return array
  837. */
  838. function get_para($val, $type = 1) // 处理insert外部函数/需要include运行的函数的调用数据
  839. {
  840. $pa = $this->str_trim($val);
  841. foreach ($pa AS $value)
  842. {
  843. if (strrpos($value, '='))
  844. {
  845. list($a, $b) = explode('=', str_replace(array(' ', '"', "'", '&quot;'), '', $value));
  846. if ($b{0} == '$')
  847. {
  848. if ($type)
  849. {
  850. eval('$para[\'' . $a . '\']=' . $this->get_val(substr($b, 1)) . ';');
  851. }
  852. else
  853. {
  854. $para[$a] = $this->get_val(substr($b, 1));
  855. }
  856. }
  857. else
  858. {
  859. $para[$a] = $b;
  860. }
  861. }
  862. }
  863. return $para;
  864. }
  865. /**
  866. * 判断变量是否被注册并返回值
  867. *
  868. * @access public
  869. * @param string $name
  870. *
  871. * @return mix
  872. */
  873. function &get_template_vars($name = null)
  874. {
  875. if (empty($name))
  876. {
  877. return $this->_var;
  878. }
  879. elseif (!empty($this->_var[$name]))
  880. {
  881. return $this->_var[$name];
  882. }
  883. else
  884. {
  885. $_tmp = null;
  886. return $_tmp;
  887. }
  888. }
  889. /**
  890. * 处理if标签
  891. *
  892. * @access public
  893. * @param string $tag_args
  894. * @param bool $elseif
  895. *
  896. * @return string
  897. */
  898. function _compile_if_tag($tag_args, $elseif = false)
  899. {
  900. preg_match_all('/\-?\d+[\.\d]+|\'[^\'|\s]*\'|"[^"|\s]*"|[\$\w\.]+|!==|===|==|!=|<>|<<|>>|<=|>=|&&|\|\||\(|\)|,|\!|\^|=|&|<|>|~|\||\%|\+|\-|\/|\*|\@|\S/', $tag_args, $match);
  901. $tokens = $match[0];
  902. // make sure we have balanced parenthesis
  903. $token_count = array_count_values($tokens);
  904. if (!empty($token_count['(']) && $token_count['('] != $token_count[')'])
  905. {
  906. // $this->_syntax_error('unbalanced parenthesis in if statement', E_USER_ERROR, __FILE__, __LINE__);
  907. }
  908. for ($i = 0, $count = count($tokens); $i < $count; $i++)
  909. {
  910. $token = &$tokens[$i];
  911. switch (strtolower($token))
  912. {
  913. case 'eq':
  914. $token = '==';
  915. break;
  916. case 'ne':
  917. case 'neq':
  918. $token = '!=';
  919. break;
  920. case 'lt':
  921. $token = '<';
  922. break;
  923. case 'le':
  924. case 'lte':
  925. $token = '<=';
  926. break;
  927. case 'gt':
  928. $token = '>';
  929. break;
  930. case 'ge':
  931. case 'gte':
  932. $token = '>=';
  933. break;
  934. case 'and':
  935. $token = '&&';
  936. break;
  937. case 'or':
  938. $token = '||';
  939. break;
  940. case 'not':
  941. $token = '!';
  942. break;
  943. case 'mod':
  944. $token = '%';
  945. break;
  946. default:
  947. if ($token[0] == '$')
  948. {
  949. $token = $this->get_val(substr($token, 1));
  950. }
  951. break;
  952. }
  953. }
  954. if ($elseif)
  955. {
  956. return '<?php elseif (' . implode(' ', $tokens) . '): ?>';
  957. }
  958. else
  959. {
  960. return '<?php if (' . implode(' ', $tokens) . '): ?>';
  961. }
  962. }
  963. /**
  964. * 处理foreach标签
  965. *
  966. * @access public
  967. * @param string $tag_args
  968. *
  969. * @return string
  970. */
  971. function _compile_foreach_start($tag_args)
  972. {
  973. $attrs = $this->get_para($tag_args, 0);
  974. $arg_list = array();
  975. $from = $attrs['from'];
  976. if(isset($this->_var[$attrs['item']]) && !isset($this->_patchstack[$attrs['item']]))
  977. {
  978. $this->_patchstack[$attrs['item']] = $attrs['item'] . '_' . str_replace(array(' ', '.'), '_', microtime());
  979. $attrs['item'] = $this->_patchstack[$attrs['item']];
  980. }
  981. else
  982. {
  983. $this->_patchstack[$attrs['item']] = $attrs['item'];
  984. }
  985. $item = $this->get_val($attrs['item']);
  986. if (!empty($attrs['key']))
  987. {
  988. $key = $attrs['key'];
  989. $key_part = $this->get_val($key).' => ';
  990. }
  991. else
  992. {
  993. $key = null;
  994. $key_part = '';
  995. }
  996. if (!empty($attrs['name']))
  997. {
  998. $name = $attrs['name'];
  999. }
  1000. else
  1001. {
  1002. $name = null;
  1003. }
  1004. $output = '<?php ';
  1005. $output .= "\$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array'); }; \$this->push_vars('$attrs[key]', '$attrs[item]');";
  1006. if (!empty($name))
  1007. {
  1008. $foreach_props = "\$this->_foreach['$name']";
  1009. $output .= "{$foreach_props} = array('total' => count(\$_from), 'iteration' => 0);\n";
  1010. $output .= "if ({$foreach_props}['total'] > 0):\n";
  1011. $output .= " foreach (\$_from AS $key_part$item):\n";
  1012. $output .= " {$foreach_props}['iteration']++;\n";
  1013. }
  1014. else
  1015. {
  1016. $output .= "if (count(\$_from)):\n";
  1017. $output .= " foreach (\$_from AS $key_part$item):\n";
  1018. }
  1019. return $output . '?>';
  1020. }
  1021. /**
  1022. * 将 foreach 的 key, item 放入临时数组
  1023. *
  1024. * @param mixed $key
  1025. * @param mixed $val
  1026. *
  1027. * @return void
  1028. */
  1029. function push_vars($key, $val)
  1030. {
  1031. if (!empty($key))
  1032. {
  1033. array_push($this->_temp_key, "\$this->_vars['$key']='" .$this->_vars[$key] . "';");
  1034. }
  1035. if (!empty($val))
  1036. {
  1037. array_push($this->_temp_val, "\$this->_vars['$val']='" .$this->_vars[$val] ."';");
  1038. }
  1039. }
  1040. /**
  1041. * 弹出临时数组的最后一个
  1042. *
  1043. * @return void
  1044. */
  1045. function pop_vars()
  1046. {
  1047. $key = array_pop($this->_temp_key);
  1048. $val = array_pop($this->_temp_val);
  1049. if (!empty($key))
  1050. {
  1051. eval($key);
  1052. }
  1053. }
  1054. /**
  1055. * 处理smarty开头的预定义变量
  1056. *
  1057. * @access public
  1058. * @param array $indexes
  1059. *
  1060. * @return string
  1061. */
  1062. function _compile_smarty_ref(&$indexes)
  1063. {
  1064. /* Extract the reference name. */
  1065. $_ref = $indexes[0];
  1066. switch ($_ref)
  1067. {
  1068. case 'now':
  1069. $compiled_ref = 'time()';
  1070. break;
  1071. case 'foreach':
  1072. array_shift($indexes);
  1073. $_var = $indexes[0];
  1074. $_propname = $indexes[1];
  1075. switch ($_propname)
  1076. {
  1077. case 'index':
  1078. array_shift($indexes);
  1079. $compiled_ref = "(\$this->_foreach['$_var']['iteration'] - 1)";
  1080. break;
  1081. case 'first':
  1082. array_shift($indexes);
  1083. $compiled_ref = "(\$this->_foreach['$_var']['iteration'] <= 1)";
  1084. break;
  1085. case 'last':
  1086. array_shift($indexes);
  1087. $compiled_ref = "(\$this->_foreach['$_var']['iteration'] == \$this->_foreach['$_var']['total'])";
  1088. break;
  1089. case 'show':
  1090. array_shift($indexes);
  1091. $compiled_ref = "(\$this->_foreach['$_var']['total'] > 0)";
  1092. break;
  1093. default:
  1094. $compiled_ref = "\$this->_foreach['$_var']";
  1095. break;
  1096. }
  1097. break;
  1098. case 'get':
  1099. $compiled_ref = '$_GET';
  1100. break;
  1101. case 'post':
  1102. $compiled_ref = '$_POST';
  1103. break;
  1104. case 'cookies':
  1105. $compiled_ref = '$_COOKIE';
  1106. break;
  1107. case 'env':
  1108. $compiled_ref = '$_ENV';
  1109. break;
  1110. case 'server':
  1111. $compiled_ref = '$_SERVER';
  1112. break;
  1113. case 'request':
  1114. $compiled_ref = '$_REQUEST';
  1115. break;
  1116. case 'session':
  1117. $compiled_ref = '$_SESSION';
  1118. break;
  1119. default:
  1120. // $this->_syntax_error('$smarty.' . $_ref . ' is an unknown reference', E_USER_ERROR, __FILE__, __LINE__);
  1121. break;
  1122. }
  1123. array_shift($indexes);
  1124. return $compiled_ref;
  1125. }
  1126. function smarty_insert_scripts($args)
  1127. {
  1128. static $scripts = array();
  1129. $arr = explode(',', str_replace(' ', '', $args['files']));
  1130. $str = '';
  1131. foreach ($arr AS $val)
  1132. {
  1133. if (in_array($val, $scripts) == false)
  1134. {
  1135. $scripts[] = $val;
  1136. if ($val{0} == '.')
  1137. {
  1138. $str .= '<script type="text/javascript" src="' . $val . '"></script>';
  1139. }
  1140. else
  1141. {
  1142. $str .= '<script type="text/javascript" src="js/' . $val . '"></script>';
  1143. }
  1144. }
  1145. }
  1146. return $str;
  1147. }
  1148. function insert_mod($name) // 处理动态内容
  1149. {
  1150. list($fun, $para) = explode('|', $name);
  1151. $para = unserialize(base64_decode($para));
  1152. $insert_func = 'insert_' . $fun;
  1153. require_once APP_ROOT_PATH."app/Lib/insert_libs.php";
  1154. if(!function_exists($insert_func))//也可调用module中的静态方法
  1155. {
  1156. require_once APP_ROOT_PATH."app/Lib/inserts/".strtolower(MODULE_NAME)."_insert_libs.php";
  1157. }
  1158. else
  1159. return $insert_func($para);
  1160. }
  1161. function str_trim($str)
  1162. {
  1163. /* 处理'a=b c=d k = f '类字符串,返回数组 */
  1164. while (strpos($str, '= ') != 0)
  1165. {
  1166. $str = str_replace('= ', '=', $str);
  1167. }
  1168. while (strpos($str, ' =') != 0)
  1169. {
  1170. $str = str_replace(' =', '=', $str);
  1171. }
  1172. return explode(' ', trim($str));
  1173. }
  1174. function _eval($content)
  1175. {
  1176. ob_start();
  1177. eval('?' . '>' . trim($content));
  1178. $content = ob_get_contents();
  1179. ob_end_clean();
  1180. return $content;
  1181. }
  1182. function _require($filename)
  1183. {
  1184. ob_start();
  1185. include $filename;
  1186. $content = ob_get_contents();
  1187. ob_end_clean();
  1188. return $content;
  1189. }
  1190. function html_options($arr)
  1191. {
  1192. $out = '';
  1193. $selected = $arr['selected'];
  1194. if ($arr['options'])
  1195. {
  1196. $options = (array)$arr['options'];
  1197. }
  1198. elseif ($arr['output'])
  1199. {
  1200. if ($arr['values'])
  1201. {
  1202. foreach ($arr['output'] AS $key => $val)
  1203. {
  1204. $options["{$arr[values][$key]}"] = $val;
  1205. }
  1206. }
  1207. else
  1208. {
  1209. $options = array_values((array)$arr['output']);
  1210. }
  1211. }
  1212. if ($options)
  1213. {
  1214. foreach ($options AS $key => $val)
  1215. {
  1216. $out .= $key == $selected ? "<option value=\"$key\" selected>$val</option>" : "<option value=\"$key\">$val</option>";
  1217. }
  1218. }
  1219. return $out;
  1220. }
  1221. function html_select_date($arr)
  1222. {
  1223. $pre = $arr['prefix'];
  1224. if (isset($arr['time']))
  1225. {
  1226. if (intval($arr['time']) > 10000)
  1227. {
  1228. $arr['time'] = gmdate('Y-m-d', $arr['time'] + 8*3600);
  1229. }
  1230. $t = explode('-', $arr['time']);
  1231. $year = strval($t[0]);
  1232. $month = strval($t[1]);
  1233. $day = strval($t[2]);
  1234. }
  1235. $now = gmdate('Y', $this->_nowtime);
  1236. if (isset($arr['start_year']))
  1237. {
  1238. if (abs($arr['start_year']) == $arr['start_year'])
  1239. {
  1240. $startyear = $arr['start_year'];
  1241. }
  1242. else
  1243. {
  1244. $startyear = $arr['start_year'] + $now;
  1245. }
  1246. }
  1247. else
  1248. {
  1249. $startyear = $now - 3;
  1250. }
  1251. if (isset($arr['end_year']))
  1252. {
  1253. if (strlen(abs($arr['end_year'])) == strlen($arr['end_year']))
  1254. {
  1255. $endyear = $arr['end_year'];
  1256. }
  1257. else
  1258. {
  1259. $endyear = $arr['end_year'] + $now;
  1260. }
  1261. }
  1262. else
  1263. {
  1264. $endyear = $now + 3;
  1265. }
  1266. $out = "<select name=\"{$pre}Year\">";
  1267. for ($i = $startyear; $i <= $endyear; $i++)
  1268. {
  1269. $out .= $i == $year ? "<option value=\"$i\" selected>$i</option>" : "<option value=\"$i\">$i</option>";
  1270. }
  1271. if ($arr['display_months'] != 'false')
  1272. {
  1273. $out .= "</select>&nbsp;<select name=\"{$pre}Month\">";
  1274. for ($i = 1; $i <= 12; $i++)
  1275. {
  1276. $out .= $i == $month ? "<option value=\"$i\" selected>" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>" : "<option value=\"$i\">" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>";
  1277. }
  1278. }
  1279. if ($arr['display_days'] != 'false')
  1280. {
  1281. $out .= "</select>&nbsp;<select name=\"{$pre}Day\">";
  1282. for ($i = 1; $i <= 31; $i++)
  1283. {
  1284. $out .= $i == $day ? "<option value=\"$i\" selected>" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>" : "<option value=\"$i\">" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>";
  1285. }
  1286. }
  1287. return $out . '</select>';
  1288. }
  1289. function html_radios($arr)
  1290. {
  1291. $name = $arr['name'];
  1292. $checked = $arr['checked'];
  1293. $options = $arr['options'];
  1294. $out = '';
  1295. foreach ($options AS $key => $val)
  1296. {
  1297. $out .= $key == $checked ? "<input type=\"radio\" name=\"$name\" value=\"$key\" checked>&nbsp;{$val}&nbsp;"
  1298. : "<input type=\"radio\" name=\"$name\" value=\"$key\">&nbsp;{$val}&nbsp;";
  1299. }
  1300. return $out;
  1301. }
  1302. function html_select_time($arr)
  1303. {
  1304. $pre = $arr['prefix'];
  1305. if (isset($arr['time']))
  1306. {
  1307. $arr['time'] = gmdate('H-i-s', $arr['time'] + 8*3600);
  1308. $t = explode('-', $arr['time']);
  1309. $hour = strval($t[0]);
  1310. $minute = strval($t[1]);
  1311. $second = strval($t[2]);
  1312. }
  1313. $out = '';
  1314. if (!isset($arr['display_hours']))
  1315. {
  1316. $out .= "<select name=\"{$pre}Hour\">";
  1317. for ($i = 0; $i <= 23; $i++)
  1318. {
  1319. $out .= $i == $hour ? "<option value=\"$i\" selected>" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>" : "<option value=\"$i\">" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>";
  1320. }
  1321. $out .= "</select>&nbsp;";
  1322. }
  1323. if (!isset($arr['display_minutes']))
  1324. {
  1325. $out .= "<select name=\"{$pre}Minute\">";
  1326. for ($i = 0; $i <= 59; $i++)
  1327. {
  1328. $out .= $i == $minute ? "<option value=\"$i\" selected>" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>" : "<option value=\"$i\">" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>";
  1329. }
  1330. $out .= "</select>&nbsp;";
  1331. }
  1332. if (!isset($arr['display_seconds']))
  1333. {
  1334. $out .= "<select name=\"{$pre}Second\">";
  1335. for ($i = 0; $i <= 59; $i++)
  1336. {
  1337. $out .= $i == $second ? "<option value=\"$i\" selected>" . str_pad($i, 2, '0', STR_PAD_LEFT) . "</option>" : "<option value=\"$i\">$i</option>";
  1338. }
  1339. $out .= "</select>&nbsp;";
  1340. }
  1341. return $out;
  1342. }
  1343. function cycle($arr)
  1344. {
  1345. static $k, $old;
  1346. $value = explode(',', $arr['values']);
  1347. if ($old != $value)
  1348. {
  1349. $old = $value;
  1350. $k = 0;
  1351. }
  1352. else
  1353. {
  1354. $k++;
  1355. if (!isset($old[$k]))
  1356. {
  1357. $k = 0;
  1358. }
  1359. }
  1360. echo $old[$k];
  1361. }
  1362. function make_array($arr)
  1363. {
  1364. $out = '';
  1365. foreach ($arr AS $key => $val)
  1366. {
  1367. if ($val{0} == '$')
  1368. {
  1369. $out .= $out ? ",'$key'=>$val" : "array('$key'=>$val";
  1370. }
  1371. else
  1372. {
  1373. $out .= $out ? ",'$key'=>'$val'" : "array('$key'=>'$val'";
  1374. }
  1375. }
  1376. return $out . ')';
  1377. }
  1378. function smarty_create_pages($params)
  1379. {
  1380. extract($params);
  1381. if (empty($page))
  1382. {
  1383. $page = 1;
  1384. }
  1385. if (!empty($count))
  1386. {
  1387. $str = "<option value='1'>1</option>";
  1388. $min = min($count - 1, $page + 3);
  1389. for ($i = $page - 3 ; $i <= $min ; $i++)
  1390. {
  1391. if ($i < 2)
  1392. {
  1393. continue;
  1394. }
  1395. $str .= "<option value='$i'";
  1396. $str .= $page == $i ? " selected='true'" : '';
  1397. $str .= ">$i</option>";
  1398. }
  1399. if ($count > 1)
  1400. {
  1401. $str .= "<option value='$count'";
  1402. $str .= $page == $count ? " selected='true'" : '';
  1403. $str .= ">$count</option>";
  1404. }
  1405. }
  1406. else
  1407. {
  1408. $str = '';
  1409. }
  1410. return $str;
  1411. }
  1412. }
  1413. ?>