人人商城

template.func.php 20KB

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