template.func.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function template_compat($filename) {
  8. static $mapping = array(
  9. 'home/home' => 'index',
  10. 'header' => 'common/header',
  11. 'footer' => 'common/footer',
  12. 'slide' => 'common/slide',
  13. );
  14. if(!empty($mapping[$filename])) {
  15. return $mapping[$filename];
  16. }
  17. return '';
  18. }
  19. function template_page($id, $flag = TEMPLATE_DISPLAY) {
  20. global $_W;
  21. $page = pdo_fetch("SELECT * FROM ".tablename('site_page')." WHERE id = :id LIMIT 1", array(':id' => $id));
  22. if (empty($page)) {
  23. return error(1, 'Error: Page is not found');
  24. }
  25. if (empty($page['html'])) {
  26. return '';
  27. }
  28. $page['html'] = str_replace(array('<?', '<%', '<?php', '{php'), '_', $page['html']);
  29. $page['html'] = preg_replace('/<\s*?script.*(src|language)+/i', '_', $page['html']);
  30. $script_start = "<sc<x>ript type=\"text/ja<x>vasc<x>ript\">";
  31. $script_end = "</sc<x>ript>";
  32. $count_down_script = <<<EOF
  33. $(document).ready(function(){\r\n\t\t\t\t\tsetInterval(function(){\r\n\t\t\t\t\t\tvar timer = $('.timer');\r\n\t\t\t\t\t\tfor (var i = 0; i < timer.length; i++) {\r\n\t\t\t\t\t\t\tvar dead = $(timer.get(i)).attr('data');\r\n\t\t\t\t\t\t\tvar deadtime = dead.replace(/-/g,'/');\r\n\t\t\t\t\t\t\tdeadtime = new Date(deadtime).getTime();\r\n\t\t\t\t\t\t\tvar nowtime = Date.parse(Date());\r\n\t\t\t\t\t\t\tvar diff = deadtime - nowtime > 0 ? deadtime - nowtime : 0;\r\n\t\t\t\t\t\t\tvar res = {};\r\n\t\t\t\t\t\t\tres.day = parseInt(diff / (24 * 60 * 60 * 1000));\r\n\t\t\t\t\t\t\tres.hour = parseInt(diff / (60 * 60 * 1000) % 24);\r\n\t\t\t\t\t\t\tres.min = parseInt(diff / (60 * 1000) % 60);\r\n\t\t\t\t\t\t\tres.sec = parseInt(diff / 1000 % 60);\r\n\t\t\t\t\t\t\t$('.timer[data="'+dead+'"] .day').text(res.day);\r\n\t\t\t\t\t\t\t$('.timer[data="'+dead+'"] .hours').text(res.hour);\r\n\t\t\t\t\t\t\t$('.timer[data="'+dead+'"] .minutes').text(res.min);\r\n\t\t\t\t\t\t\t$('.timer[data="'+dead+'"] .seconds').text(res.sec);\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t}, 1000);\r\n\t\t\t\t});
  34. EOF;
  35. if (strexists($page['html'], $script_start . $count_down_script . $script_end)) {
  36. $page['html'] = str_replace($script_start . $count_down_script . $script_end, "<script type=text/javascript>" . $count_down_script . "</script>", $page['html']);
  37. }
  38. $page['params'] = json_decode($page['params'], true);
  39. $GLOBALS['title'] = htmlentities($page['title'], ENT_QUOTES, 'UTF-8');
  40. $GLOBALS['_share'] = array('desc' => $page['description'], 'title' => $page['title'], 'imgUrl' => tomedia($page['params']['0']['params']['thumb']));
  41. $compile = IA_ROOT . "/data/tpl/app/{$id}.{$_W['template']}.tpl.php";
  42. $path = dirname($compile);
  43. if (!is_dir($path)) {
  44. load()->func('file');
  45. mkdirs($path);
  46. }
  47. $content = template_parse($page['html']);
  48. if (!empty($page['params'][0]['params']['bgColor'])) {
  49. $content .= '<style>body{background-color:'.$page['params'][0]['params']['bgColor'].' !important;}</style>';
  50. }
  51. $GLOBALS['bottom_menu'] = $page['params'][0]['property'][0]['params']['bottom_menu'];
  52. file_put_contents($compile, $content);
  53. switch ($flag) {
  54. case TEMPLATE_DISPLAY:
  55. default:
  56. extract($GLOBALS, EXTR_SKIP);
  57. template('common/header');
  58. include $compile;
  59. template('common/footer');
  60. break;
  61. case TEMPLATE_FETCH:
  62. extract($GLOBALS, EXTR_SKIP);
  63. ob_clean();
  64. ob_start();
  65. include $compile;
  66. $contents = ob_get_contents();
  67. ob_clean();
  68. return $contents;
  69. break;
  70. case TEMPLATE_INCLUDEPATH:
  71. return $compile;
  72. break;
  73. }
  74. }
  75. function template($filename, $flag = TEMPLATE_DISPLAY) {
  76. global $_W, $_GPC;
  77. $source = IA_ROOT . "/app/themes/{$_W['template']}/{$filename}.html";
  78. $compile = IA_ROOT . "/data/tpl/app/{$_W['template']}/{$filename}.tpl.php";
  79. if(!is_file($source)) {
  80. $compatFilename = template_compat($filename);
  81. if(!empty($compatFilename)) {
  82. return template($compatFilename, $flag);
  83. }
  84. }
  85. if(!is_file($source)) {
  86. $source = IA_ROOT . "/app/themes/default/{$filename}.html";
  87. $compile = IA_ROOT . "/data/tpl/app/default/{$filename}.tpl.php";
  88. }
  89. if(!is_file($source)) {
  90. exit("Error: template source '{$filename}' is not exist!");
  91. }
  92. $paths = pathinfo($compile);
  93. $compile = str_replace($paths['filename'], $_W['uniacid'] . '_' . intval($_GPC['t']) . '_' . $paths['filename'], $compile);
  94. if(DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) {
  95. template_compile($source, $compile);
  96. }
  97. switch ($flag) {
  98. case TEMPLATE_DISPLAY:
  99. default:
  100. extract($GLOBALS, EXTR_SKIP);
  101. include $compile;
  102. break;
  103. case TEMPLATE_FETCH:
  104. extract($GLOBALS, EXTR_SKIP);
  105. ob_clean();
  106. ob_start();
  107. include $compile;
  108. $contents = ob_get_contents();
  109. ob_clean();
  110. return $contents;
  111. break;
  112. case TEMPLATE_INCLUDEPATH:
  113. return $compile;
  114. break;
  115. }
  116. }
  117. function template_compile($from, $to) {
  118. global $_W;
  119. $path = dirname($to);
  120. if (!is_dir($path)) {
  121. load()->func('file');
  122. mkdirs($path);
  123. }
  124. $content = template_parse(file_get_contents($from));
  125. if (defined('IN_MODULE') &&
  126. $_W['os'] != 'mobile' &&
  127. module_get_direct_enter_status($_W['current_module']['name']) == STATUS_ON &&
  128. !preg_match('/\<script\>var we7CommonForModule.*document\.body\.appendChild\(we7CommonForModule\)\<\/script\>/', $content) &&
  129. !preg_match('/(footer|header|account\/welcome|module\/welcome)+/', $from)) {
  130. $extra_code = "<script>var we7CommonForModule = document.createElement(\"script\");we7CommonForModule.src = '//cdn.w7.cc/we7/w7windowside.js?v=" . IMS_RELEASE_DATE . "';document.body.appendChild(we7CommonForModule)
  131. </script>";
  132. $content .= $extra_code;
  133. }
  134. file_put_contents($to, $content);
  135. }
  136. function template_parse($str) {
  137. load()->model('mc');
  138. $check_repeat_template = array(
  139. "'common\\/header'",
  140. "'common\\/footer'",
  141. );
  142. foreach ($check_repeat_template as $template) {
  143. if (preg_match_all('/{template\s+'.$template.'}/', $str, $match) > 1) {
  144. $replace = stripslashes($template);
  145. $str = preg_replace('/{template\s+'.$template.'}/i', '<?php (!empty($this) && $this instanceof WeModuleSite) ? (include $this->template('.$replace.', TEMPLATE_INCLUDEPATH)) : (include template('.$replace.', TEMPLATE_INCLUDEPATH));?>', $str, 1);
  146. $str = preg_replace('/{template\s+'.$template.'}/i', '', $str);
  147. }
  148. }
  149. $str = preg_replace('/<!--{(.+?)}-->/s', '{$1}', $str);
  150. $str = preg_replace('/{template\s+(.+?)}/', '<?php (!empty($this) && $this instanceof WeModuleSite) ? (include $this->template($1, TEMPLATE_INCLUDEPATH)) : (include template($1, TEMPLATE_INCLUDEPATH));?>', $str);
  151. $str = preg_replace('/{php\s+(.+?)}/', '<?php $1?>', $str);
  152. $str = preg_replace('/{if\s+(.+?)}/', '<?php if($1) { ?>', $str);
  153. $str = preg_replace('/{else}/', '<?php } else { ?>', $str);
  154. $str = preg_replace('/{else ?if\s+(.+?)}/', '<?php } else if($1) { ?>', $str);
  155. $str = preg_replace('/{\/if}/', '<?php } ?>', $str);
  156. $str = preg_replace('/{loop\s+(\S+)\s+(\S+)}/', '<?php if(is_array($1)) { foreach($1 as $2) { ?>', $str);
  157. $str = preg_replace('/{loop\s+(\S+)\s+(\S+)\s+(\S+)}/', '<?php if(is_array($1)) { foreach($1 as $2 => $3) { ?>', $str);
  158. $str = preg_replace('/{\/loop}/', '<?php } } ?>', $str);
  159. $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)}/', '<?php echo $1;?>', $str);
  160. $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\[\]\'\"\$]*)}/', '<?php echo $1;?>', $str);
  161. $str = preg_replace('/{url\s+(\S+)}/', '<?php echo url($1);?>', $str);
  162. $str = preg_replace('/{url\s+(\S+)\s+(array\(.+?\))}/', '<?php echo url($1, $2);?>', $str);
  163. $str = preg_replace('/{media\s+(\S+)}/', '<?php echo tomedia($1);?>', $str);
  164. $str = preg_replace_callback('/{data\s+(.+?)}/s', "moduledata", $str);
  165. $str = preg_replace_callback('/{hook\s+(.+?)}/s', "template_modulehook_parser", $str);
  166. $str = preg_replace('/{\/data}/', '<?php } } ?>', $str);
  167. $str = preg_replace('/{\/hook}/', '<?php ; ?>', $str);
  168. $str = preg_replace_callback('/<\?php([^\?]+)\?>/s', "template_addquote", $str);
  169. $str = preg_replace('/{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)}/s', '<?php echo $1;?>', $str);
  170. $str = str_replace('{##', '{', $str);
  171. $str = str_replace('##}', '}', $str);
  172. $business_stat_script = "</script><script type=\"text/javascript\" src=\"{$GLOBALS['_W']['siteroot']}app/index.php?i=" . mc_current_real_uniacid() . "&c=utility&a=visit&do=showjs&m={$GLOBALS['_W']['current_module']['name']}\">";
  173. if (!empty($GLOBALS['_W']['setting']['remote']['type'])) {
  174. $str = str_replace('</body>', "<script>var imgs = document.getElementsByTagName('img');for(var i=0, len=imgs.length; i < len; i++){imgs[i].onerror = function() {if (!this.getAttribute('check-src') && (this.src.indexOf('http://') > -1 || this.src.indexOf('https://') > -1)) {this.src = this.src.indexOf('{$GLOBALS['_W']['attachurl_local']}') == -1 ? this.src.replace('{$GLOBALS['_W']['attachurl_remote']}', '{$GLOBALS['_W']['attachurl_local']}') : this.src.replace('{$GLOBALS['_W']['attachurl_local']}', '{$GLOBALS['_W']['attachurl_remote']}');this.setAttribute('check-src', true);}}};{$business_stat_script}</script></body>", $str);
  175. } else {
  176. $str = str_replace('</body>', "<script>;{$business_stat_script}</script></body>", $str);
  177. }
  178. $str = "<?php defined('IN_IA') or exit('Access Denied');?>" . $str;
  179. return $str;
  180. }
  181. function template_addquote($matchs) {
  182. $code = "<?php {$matchs[1]}?>";
  183. $code = preg_replace('/\[([a-zA-Z0-9_\-\.\x7f-\xff]+)\](?![a-zA-Z0-9_\-\.\x7f-\xff\[\]]*[\'"])/s', "['$1']", $code);
  184. return str_replace('\\\"', '\"', $code);
  185. }
  186. function moduledata($params = '') {
  187. if (empty($params[1])) {
  188. return '';
  189. }
  190. $params = explode(' ', $params[1]);
  191. if (empty($params)) {
  192. return '';
  193. }
  194. $data = array();
  195. foreach ($params as $row) {
  196. $row = explode('=', $row);
  197. $data[$row[0]] = str_replace(array("'", '"'), '', $row[1]);
  198. $row[1] = urldecode($row[1]);
  199. }
  200. $funcname = $data['func'];
  201. $assign = !empty($data['assign']) ? $data['assign'] : $funcname;
  202. $item = !empty($data['item']) ? $data['item'] : 'row';
  203. $data['limit'] = !empty($data['limit']) ? $data['limit'] : 10;
  204. if (empty($data['return']) || $data['return'] == 'false') {
  205. $return = false;
  206. } else {
  207. $return = true;
  208. }
  209. $data['index'] = !empty($data['index']) ? $data['index'] : 'iteration';
  210. if (!empty($data['module'])) {
  211. $modulename = $data['module'];
  212. } else {
  213. list($modulename) = explode('_', $data['func']);
  214. }
  215. $data['multiid'] = intval($_GET['t']);
  216. $data['uniacid'] = intval($_GET['i']);
  217. $data['acid'] = intval($_GET['j']);
  218. if (empty($modulename) || empty($funcname)) {
  219. return '';
  220. }
  221. $variable = var_export($data, true);
  222. $variable = preg_replace("/'(\\$[a-zA-Z_\x7f-\xff\[\]\']*?)'/", '$1', $variable);
  223. $php = "<?php \${$assign} = modulefunc('$modulename', '{$funcname}', {$variable}); ";
  224. if (empty($return)) {
  225. $php .= "if(is_array(\${$assign})) { \$i=0; foreach(\${$assign} as \$i => \${$item}) { \$i++; \${$item}['{$data['index']}'] = \$i; ";
  226. }
  227. $php .= "?>";
  228. return $php;
  229. }
  230. function modulefunc($modulename, $funcname, $params) {
  231. static $includes;
  232. $includefile = '';
  233. if (!function_exists($funcname)) {
  234. if (!isset($includes[$modulename])) {
  235. if (!file_exists(IA_ROOT . '/addons/'.$modulename.'/model.php')) {
  236. return '';
  237. } else {
  238. $includes[$modulename] = true;
  239. include_once IA_ROOT . '/addons/'.$modulename.'/model.php';
  240. }
  241. }
  242. }
  243. if (function_exists($funcname)) {
  244. return call_user_func_array($funcname, array($params));
  245. } else {
  246. return array();
  247. }
  248. }
  249. function site_navs($params = array()) {
  250. global $_W, $multi, $cid, $ishomepage;
  251. $condition = array();
  252. if(!$cid || !$ishomepage) {
  253. if (!empty($params['section'])) {
  254. $condition['section'] = intval($params['section']);
  255. }
  256. if(empty($params['multiid'])) {
  257. load()->model('account');
  258. $setting = uni_setting($_W['uniacid']);
  259. $multiid = $setting['default_site'];
  260. } else{
  261. $multiid = intval($params['multiid']);
  262. }
  263. $condition['position'] = 1;
  264. $condition['status'] = 1;
  265. $condition['uniacid'] = $_W['uniacid'];
  266. $condition['multiid'] = $multiid;
  267. $fields = array('id', 'name', 'description', 'url', 'icon', 'css', 'position', 'module');
  268. $navs = pdo_getall('site_nav', $condition, $fields, '', array('section ASC', 'displayorder DESC', 'id DESC'));
  269. } else {
  270. $condition = array(
  271. 'parentid' => $cid,
  272. 'enabled' => 1,
  273. 'uniacid' => $_W['uniacid']
  274. );
  275. $navs = pdo_getall('site_category', $condition, array(), '', array('displayorder DESC', 'id DESC'));
  276. }
  277. if(!empty($navs)) {
  278. foreach ($navs as &$row) {
  279. if(!$cid || !$ishomepage) {
  280. if (!strexists($row['url'], 'tel:') && !strexists($row['url'], '://') && !strexists($row['url'], 'www') && !strexists($row['url'], 'i=')) {
  281. $row['url'] .= strexists($row['url'], '?') ? '&i='.$_W['uniacid'] : '?i='.$_W['uniacid'];
  282. }
  283. } else {
  284. if(empty($row['linkurl']) || (!strexists($row['linkurl'], 'http://') && !strexists($row['linkurl'], 'https://'))) {
  285. $row['url'] = murl('site/site/list', array('cid' => $row['id']));
  286. } else {
  287. $row['url'] = $row['linkurl'];
  288. }
  289. }
  290. $row['css'] = iunserializer($row['css']);
  291. if(empty($row['css']['icon']['icon'])){
  292. $row['css']['icon']['icon'] = 'fa fa-external-link';
  293. }
  294. $row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";
  295. $row['css']['name'] = "color:{$row['css']['name']['color']};";
  296. $row['html'] = '<a href="'.$row['url'].'" class="box-item">';
  297. $row['html'] .= '<i '.(!empty($row['icon']) ? "style=\"background:url('".tomedia($row['icon'])."') no-repeat;background-size:cover;\" class=\"icon\"" : "class=\"fa {$row['css']['icon']['icon']} \" style=\"{$row['css']['icon']['style']}\"").'></i>';
  298. $row['html'] .= "<span style=\"{$row['css']['name']}\" title=\"{$row['name']}\">{$row['name']}</span></a>";
  299. }
  300. unset($row);
  301. }
  302. return $navs;
  303. }
  304. function site_article($params = array()) {
  305. global $_GPC, $_W;
  306. extract($params);
  307. $pindex = max(1, intval($_GPC['page']));
  308. if (!isset($limit)) {
  309. $psize = 10;
  310. } else {
  311. $psize = intval($limit);
  312. $psize = max(1, $limit);
  313. }
  314. $result = array();
  315. $condition = " WHERE uniacid = :uniacid ";
  316. $pars = array(':uniacid' => $_W['uniacid']);
  317. if (!empty($cid)) {
  318. $category = pdo_getcolumn('site_category', array('id' => $cid, 'enabled' => 1), 'parentid');
  319. if (!empty($category)) {
  320. $condition .= " AND ccate = :ccate ";
  321. $pars[':ccate'] = $cid;
  322. } else {
  323. $condition .= " AND pcate = :pcate AND (ccate = :ccate OR iscommend = '1')";
  324. $pars[':pcate'] = $cid;
  325. $pars[':ccate'] = ARTICLE_CCATE;
  326. }
  327. } else {
  328. $category_list = pdo_getall('site_category', array('uniacid' => $_W['uniacid'], 'multiid' => $multiid), array(), 'id');
  329. $category_list = implode(',', array_keys($category_list));
  330. if (!empty($category_list)) {
  331. $condition .= " AND (pcate IN (". $category_list .") OR ccate IN (". $category_list .") OR pcate = 0 AND ccate = 0)";
  332. }
  333. }
  334. if ($iscommend == 'true') {
  335. $condition .= " AND iscommend = '1'";
  336. }
  337. if ($ishot == 'true') {
  338. $condition .= " AND ishot = '1'";
  339. }
  340. $sql = "SELECT * FROM ".tablename('site_article'). $condition. ' ORDER BY displayorder DESC, id DESC LIMIT ' . ($pindex - 1) * $psize .',' .$psize;
  341. $result['list'] = pdo_fetchall($sql, $pars);
  342. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('site_article') . $condition, $pars);
  343. $result['pager'] = pagination($total, $pindex, $psize);
  344. if (!empty($result['list'])) {
  345. foreach ($result['list'] as &$row) {
  346. if(empty($row['linkurl'])) {
  347. $row['linkurl'] = murl('site/site/detail', array('id' => $row['id'], 'uniacid' => $_W['uniacid']));
  348. }
  349. $row['thumb'] = tomedia($row['thumb']);
  350. }
  351. }
  352. return $result;
  353. }
  354. function site_category($params = array()) {
  355. global $_GPC, $_W;
  356. extract($params);
  357. if (!isset($parentid)) {
  358. $condition = "";
  359. } else {
  360. $parentid = intval($parentid);
  361. $condition = " AND parentid = '$parentid'";
  362. }
  363. $category = array();
  364. $result = pdo_fetchall("SELECT * FROM ".tablename('site_category')." WHERE uniacid = '{$_W['uniacid']}' $condition ORDER BY parentid ASC, displayorder ASC, id ASC ");
  365. if (!empty($result)) {
  366. foreach ($result as $row) {
  367. if(empty($row['linkurl'])) {
  368. $row['linkurl'] = url('site/site/list', array('cid' =>$row['id']));
  369. }
  370. $row['icon'] = tomedia($row['icon']);
  371. $row['css'] = iunserializer($row['css']);
  372. if(empty($row['css']['icon']['icon'])){
  373. $row['css']['icon']['icon'] = 'fa fa-external-link';
  374. }
  375. $row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";
  376. $row['css']['name'] = "color:{$row['css']['name']['color']};";
  377. if (!isset($parentid)) {
  378. if (empty($row['parentid'])) {
  379. $category[$row['id']] = $row;
  380. } else {
  381. $category[$row['parentid']]['children'][$row['id']] = $row;
  382. }
  383. } else {
  384. $category[] = $row;
  385. }
  386. }
  387. }
  388. return $category;
  389. }
  390. function site_slide_search($params = array()) {
  391. global $_W;
  392. if(empty($params['limit'])) {
  393. $params['limit'] = 8;
  394. }
  395. if(empty($params['multiid'])) {
  396. $multiid = pdo_fetchcolumn('SELECT default_site FROM ' . tablename('uni_settings') . ' WHERE uniacid = :id', array(':id' => $_W['uniacid']));
  397. } else{
  398. $multiid = intval($params['multiid']);
  399. }
  400. $sql = "SELECT * FROM " . tablename('site_slide') . " WHERE uniacid = '{$_W['uniacid']}' AND multiid = {$multiid} ORDER BY `displayorder` DESC, `id` DESC LIMIT " . intval($params['limit']);
  401. $list = pdo_fetchall($sql);
  402. if(!empty($list)) {
  403. foreach($list as &$row) {
  404. if (!strexists($row['url'], './')) {
  405. if (!strexists($row['url'], 'http')) {
  406. $row['url'] = '//' . $row['url'];
  407. }
  408. }
  409. $row['thumb'] = tomedia($row['thumb']);
  410. }
  411. }
  412. return $list;
  413. }
  414. function app_slide($params = array()) {
  415. return site_slide_search($params);
  416. }
  417. function site_widget_link($params = array()) {
  418. $params['widgetdata'] = urldecode($params['widgetdata']);
  419. $widget = json_decode($params['widgetdata'], true);
  420. $widgetparams = !empty($widget['params']) ? $widget['params'] : array();
  421. $sql = 'SELECT * FROM ' .tablename('site_article')." WHERE uniacid = :uniacid ";
  422. $sqlparams = array(':uniacid' => $widget['uniacid']);
  423. if (!empty($widgetparams['selectCate']['pid'])) {
  424. $sql .= " AND pcate = :pid";
  425. $sqlparams[':pid'] = $widgetparams['selectCate']['pid'];
  426. }
  427. if (!empty($widgetparams['selectCate']['cid'])) {
  428. $sql .= " AND ccate = :cid";
  429. $sqlparams[':cid'] = $widgetparams['selectCate']['cid'];
  430. }
  431. if (!empty($widgetparams['iscommend'])) {
  432. $sql .= " AND iscommend = '1'";
  433. }
  434. if (!empty($widgetparams['ishot'])) {
  435. $sql .= " AND ishot = '1'";
  436. }
  437. if (!empty($widgetparams['isnew'])) {
  438. $sql .= " ORDER BY id DESC ";
  439. }
  440. if (!empty($widgetparams['pageSize'])) {
  441. $limit = intval($widgetparams['pageSize']);
  442. $sql .= " LIMIT {$limit}";
  443. }
  444. $list = pdo_fetchall($sql, $sqlparams);
  445. if (!empty($list)) {
  446. foreach ($list as $i => &$row) {
  447. $row['title'] = cutstr($row['title'], 20, true);
  448. $row['thumb_url'] = tomedia($row['thumb']);
  449. $row['url'] = url('site/site/detail', array('id' => $row['id']));
  450. }
  451. unset($row);
  452. }
  453. return (array)$list;
  454. }
  455. function site_quickmenu() {
  456. global $_W, $_GPC;
  457. if ($_GPC['c'] == 'mc' || $_GPC['c'] == 'activity') {
  458. $quickmenu = pdo_fetch("SELECT html, params FROM ".tablename('site_page')." WHERE uniacid = :uniacid AND type = '4' AND status = '1'", array(':uniacid' => $_W['uniacid']));
  459. } elseif ($_GPC['c'] == 'auth') {
  460. return false;
  461. } else {
  462. $multiid = intval($_GPC['t']);
  463. if (empty($multiid) && !empty($_GPC['__multiid'])) {
  464. $id = intval($_GPC['__multiid']);
  465. $site_multi_info = pdo_get('site_multi', array('id' => $id,'uniacid' => $_W['uniacid']));
  466. $multiid = empty($site_multi_info) ? '' : $id;
  467. } else {
  468. if(!($_GPC['c'] == 'home' && $_GPC['a'] == 'page')){
  469. @isetcookie('__multiid', '');
  470. }
  471. }
  472. if (empty($multiid)) {
  473. $setting = uni_setting($_W['uniacid'], array('default_site'));
  474. $multiid = $setting['default_site'];
  475. }
  476. $quickmenu = pdo_fetch("SELECT html, params FROM ".tablename('site_page')." WHERE multiid = :multiid AND type = '2' AND status = '1'", array(':multiid' => $multiid));
  477. }
  478. if (empty($quickmenu)) {
  479. return false;
  480. }
  481. $quickmenu['params'] = json_decode($quickmenu['params'], true);
  482. if ($_GPC['c'] == 'home' && $_GPC['a'] != 'page' && empty($quickmenu['params']['position']['homepage'])) {
  483. return false;
  484. }
  485. if ($_GPC['c'] == 'home' && $_GPC['a'] == 'page' && empty($quickmenu['params']['position']['page'])) {
  486. return false;
  487. }
  488. if ($_GPC['c'] == 'site' && empty($quickmenu['params']['position']['article'])) {
  489. return false;
  490. }
  491. if (!empty($_GPC['m']) && !empty($quickmenu['params']['ignoreModules'][$_GPC['m']])) {
  492. return false;
  493. }
  494. echo $quickmenu['html'];
  495. echo "<script type=\"text/javascript\">
  496. $('.js-quickmenu').find('a').each(function(){
  497. if ($(this).attr('href')) {
  498. var url = $(this).attr('href').replace('./', '');
  499. if (location.href.indexOf(url) > -1) {
  500. var onclass = $(this).find('i').attr('js-onclass-name');
  501. if (onclass) {
  502. $(this).find('i').attr('class', onclass);
  503. $(this).find('i').css('color', $(this).find('i').attr('js-onclass-color'));
  504. }
  505. }
  506. }
  507. });
  508. </script>";
  509. }
  510. function template_modulehook_parser($params = array()) {
  511. load()->model('module');
  512. if (empty($params[1])) {
  513. return '';
  514. }
  515. $params = explode(' ', $params[1]);
  516. if (empty($params)) {
  517. return '';
  518. }
  519. $plugin = array();
  520. foreach ($params as $row) {
  521. $row = explode('=', $row);
  522. $plugin[$row[0]] = str_replace(array("'", '"'), '', $row[1]);
  523. $row[1] = urldecode($row[1]);
  524. }
  525. $plugin_info = module_fetch($plugin['module']);
  526. if (empty($plugin_info)) {
  527. return false;
  528. }
  529. if (empty($plugin['return']) || $plugin['return'] == 'false') {
  530. } else {
  531. }
  532. if (empty($plugin['func']) || empty($plugin['module'])) {
  533. return false;
  534. }
  535. if (defined('IN_SYS')) {
  536. $plugin['func'] = "hookWeb{$plugin['func']}";
  537. } else {
  538. $plugin['func'] = "hookMobile{$plugin['func']}";
  539. }
  540. $plugin_module = WeUtility::createModuleHook($plugin_info['name']);
  541. if (method_exists($plugin_module, $plugin['func']) && $plugin_module instanceof WeModuleHook) {
  542. $hookparams = var_export($plugin, true);
  543. if (!empty($hookparams)) {
  544. $hookparams = preg_replace("/'(\\$[a-zA-Z_\x7f-\xff\[\]\']*?)'/", '$1', $hookparams);
  545. } else {
  546. $hookparams = 'array()';
  547. }
  548. $php = "<?php \$plugin_module = WeUtility::createModuleHook('{$plugin_info['name']}');call_user_func_array(array(\$plugin_module, '{$plugin['func']}'), array('params' => {$hookparams})); ?>";
  549. return $php;
  550. } else {
  551. $php = "<!--模块 {$plugin_info['name']} 不存在嵌入点 {$plugin['func']}-->";
  552. return $php;
  553. }
  554. }