common.func.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 url($segment, $params = array()) {
  8. list($controller, $action, $do) = explode('/', $segment);
  9. $url = './city.php?';
  10. if(!empty($controller)) {
  11. $url .= "c={$controller}&";
  12. }
  13. if(!empty($action)) {
  14. $url .= "a={$action}&";
  15. }
  16. if(!empty($do)) {
  17. $url .= "do={$do}&";
  18. }
  19. if(!empty($params)) {
  20. $queryString = http_build_query($params, '', '&');
  21. $url .= $queryString;
  22. }
  23. //echo $url;die;
  24. return $url;
  25. // return wurl($segment, $params);
  26. }
  27. function message($msg, $redirect = '', $type = '') {
  28. global $_W, $_GPC;
  29. if($redirect == 'refresh') {
  30. $redirect = $_W['script_name'] . '?' . $_SERVER['QUERY_STRING'];
  31. }
  32. if($redirect == 'referer') {
  33. $redirect = referer();
  34. }
  35. if($redirect == '') {
  36. $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'info';
  37. } else {
  38. $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'success';
  39. }
  40. if ($_W['isajax'] || !empty($_GET['isajax']) || $type == 'ajax') {
  41. if($type != 'ajax' && !empty($_GPC['target'])) {
  42. exit("
  43. <script type=\"text/javascript\">
  44. parent.require(['jquery', 'util'], function($, util){
  45. var url = ".(!empty($redirect) ? 'parent.location.href' : "''").";
  46. var modalobj = util.message('".$msg."', '', '".$type."');
  47. if (url) {
  48. modalobj.on('hide.bs.modal', function(){\$('.modal').each(function(){if(\$(this).attr('id') != 'modal-message') {\$(this).modal('hide');}});top.location.reload()});
  49. }
  50. });
  51. </script>");
  52. } else {
  53. $vars = array();
  54. $vars['message'] = $msg;
  55. $vars['redirect'] = $redirect;
  56. $vars['type'] = $type;
  57. exit(json_encode($vars));
  58. }
  59. }
  60. if (empty($msg) && !empty($redirect)) {
  61. header('location: '.$redirect);
  62. }
  63. $label = $type;
  64. if($type == 'error') {
  65. $label = 'danger';
  66. }
  67. if($type == 'ajax' || $type == 'sql') {
  68. $label = 'warning';
  69. }
  70. include template('common/message', TEMPLATE_INCLUDEPATH);
  71. exit();
  72. }
  73. function checklogin() {
  74. global $_W;
  75. if (empty($_W['uid'])) {
  76. $url = url('user/login');
  77. header('location:' . $url);
  78. } else {
  79. $account = pdo_fetch("SELECT * FROM " . tablename("zhtc_account") . " WHERE status=2 AND uid=:uid ORDER BY id DESC LIMIT 1", array(':uid' => $_W['uid']));
  80. if (empty($account)) {
  81. $url = url('user/login');
  82. header('location:' . $url);
  83. }
  84. }
  85. return true;
  86. }
  87. function checkaccount() {
  88. global $_W;
  89. if (empty($_W['uniacid'])) {
  90. message('这项功能需要你选择特定公众号才能使用!', url('account/display'), 'info');
  91. }
  92. }
  93. function url_params($url) {
  94. $result = array();
  95. if (empty($url)) {
  96. return $result;
  97. }
  98. $components = parse_url($url);
  99. $params = explode('&',$components['query']);
  100. foreach ($params as $param) {
  101. if (!empty($param)) {
  102. $param_array = explode('=',$param);
  103. $result[$param_array[0]] = $param_array[1];
  104. }
  105. }
  106. return $result;
  107. }
  108. function buildframes($frame = array('platform')){
  109. global $_W, $_GPC;
  110. if($_W['role'] == 'clerk') {
  111. return false;
  112. }
  113. $GLOBALS['top_nav'] = pdo_fetchall('SELECT name, title, append_title FROM ' . tablename('core_menu') . ' WHERE pid = 0 AND is_display = 1 ORDER BY displayorder DESC');
  114. $ms = cache_load('system_frame');
  115. if(empty($ms)) {
  116. cache_build_frame_menu();
  117. $ms = cache_load('system_frame');
  118. }
  119. load()->model('module');
  120. $frames = array();
  121. $modules = uni_modules(false);
  122. $modules_temp = array_keys($modules);
  123. $status = uni_user_permission_exist();
  124. if(is_error($status)) {
  125. $modules_temp = pdo_fetchall('SELECT type FROM ' . tablename('users_permission') . ' WHERE uniacid = :uniacid AND uid = :uid AND type != :type', array(':uniacid' => $_W['uniacid'], ':uid' => $_W['uid'], ':type' => 'system'), 'type');
  126. if(!empty($modules_temp)) {
  127. $modules_temp = array_keys($modules_temp);
  128. } else {
  129. $modules = array();
  130. }
  131. }
  132. if(!empty($modules)) {
  133. $sysmods = system_modules();
  134. foreach($modules as $m) {
  135. if (empty($m['isdisplay'])) {
  136. continue;
  137. }
  138. if(in_array($m['name'], $sysmods)) {
  139. $_W['setting']['permurls']['modules'][] = $m['name'];
  140. continue;
  141. }
  142. if(in_array($m['name'], $modules_temp)) {
  143. if($m['enabled']) {
  144. $frames[$m['type']][] = $m;
  145. }
  146. $_W['setting']['permurls']['modules'][] = $m['name'];
  147. }
  148. }
  149. }
  150. if(is_error($status)) {
  151. $system = array();
  152. $system = uni_user_permission('system');
  153. if (!empty($system) || !empty($modules_temp)) {
  154. foreach ($ms as $name => $section) {
  155. $hassection = false;
  156. foreach ($section as $i => $menus) {
  157. $hasitems = false;
  158. if(empty($menus['items'])) continue;
  159. foreach ($menus['items'] as $j => $menu) {
  160. if (!in_array($menu['permission_name'], $system)) {
  161. unset($ms[$name][$i]['items'][$j]);
  162. } else {
  163. $hasitems = true;
  164. $hassection = true;
  165. }
  166. }
  167. if (!$hasitems) {
  168. unset($ms[$name][$i]);
  169. }
  170. }
  171. if (!$hassection) {
  172. unset($ms[$name]);
  173. } else {
  174. $_W['setting']['permurls']['sections'][] = $name;
  175. }
  176. }
  177. }
  178. }
  179. $types = module_types();
  180. if(!empty($frames)) {
  181. foreach($frames as $type => $fs) {
  182. $items = array();
  183. if(!empty($fs)) {
  184. foreach($fs as $m) {
  185. $items[] = array(
  186. 'title' => $m['title'],
  187. 'url' => url('home/welcome/ext', array('m' => $m['name']))
  188. );
  189. }
  190. }
  191. $ms['ext'][] = array(
  192. 'title' => $types[$type]['title'],
  193. 'items' => $items
  194. );
  195. }
  196. if(is_error($status)) {
  197. $_W['setting']['permurls']['sections'][] = 'ext';
  198. }
  199. }
  200. $GLOBALS['ext_type'] = 0;
  201. $m = trim($_GPC['m']);
  202. $eid = intval($_GPC['eid']);
  203. if(FRAME == 'ext' && (!empty($m) || !empty($eid)) && $GLOBALS['ext_type'] != 2) {
  204. if(empty($_COOKIE['ext_type'])) {
  205. setcookie('ext_type', 1, TIMESTAMP + 8640000, "/");
  206. $_COOKIE['ext_type'] = 1;
  207. }
  208. $GLOBALS['ext_type'] = $_COOKIE['ext_type'];
  209. if(empty($m)) {
  210. $m = pdo_fetchcolumn('SELECT module FROM ' . tablename('modules_bindings') . ' WHERE eid = :eid', array(':eid' => $eid));
  211. }
  212. $module = module_fetch($m);
  213. $entries = module_entries($m);
  214. if(is_error($status)) {
  215. $permission = uni_user_permission($m);
  216. if($permission[0] != 'all') {
  217. if(!in_array($m.'_rule', $permission)) {
  218. unset($module['isrulefields']);
  219. }
  220. if(!in_array($m.'_settings', $permission)) {
  221. unset($module['settings']);
  222. }
  223. if(!in_array($m.'_home', $permission)) {
  224. unset($entries['home']);
  225. }
  226. if(!in_array($m.'_profile', $permission)) {
  227. unset($entries['profile']);
  228. }
  229. if(!in_array($m.'_shortcut', $permission)) {
  230. unset($entries['shortcut']);
  231. }
  232. if(!empty($entries['cover'])) {
  233. foreach($entries['cover'] as $k => $row) {
  234. if(!in_array($m.'_cover_'.$row['do'], $permission)) {
  235. unset($entries['cover'][$k]);
  236. }
  237. }
  238. }
  239. if(!empty($entries['menu'])) {
  240. foreach($entries['menu'] as $k => $row) {
  241. if(!in_array($m.'_menu_'.$row['do'], $permission)) {
  242. unset($entries['menu'][$k]);
  243. }
  244. }
  245. }
  246. }
  247. }
  248. $entries_filter = array_elements(array('cover', 'menu', 'mine'), $entries);
  249. $navs = array(
  250. array(
  251. 'title' => "模块列表",
  252. 'items' => array(
  253. array(
  254. 'title' => "<i class='fa fa-reply-all'></i> &nbsp;&nbsp;返回模块列表",
  255. 'url' => url('home/welcome/ext', array('a' => 0)),
  256. ),
  257. array(
  258. 'title' => "<i class='fa fa-reply-all'></i> &nbsp;&nbsp;返回{$module['title']}",
  259. 'url' => url('home/welcome/ext', array('m' => $m, 't' => 1)),
  260. ),
  261. ),
  262. ),
  263. );
  264. if($module['isrulefields'] || $module['settings']) {
  265. $navs['rule'] = array(
  266. 'title' => "回复规则",
  267. );
  268. if($module['isrulefields']) {
  269. $navs['rule']['items'][] = array(
  270. 'title' => "<i class='fa fa-comments'></i> &nbsp;&nbsp;回复规则列表",
  271. 'url' => url('platform/reply', array('m' => $m)),
  272. );
  273. }
  274. if($module['settings']) {
  275. $navs['rule']['items'][] = array(
  276. 'title' => "<i class='fa fa-cog'></i> &nbsp;&nbsp;参数设置",
  277. 'url' => url('profile/module/setting', array('m' => $m)),
  278. );
  279. }
  280. }
  281. if($entries['home'] || $entries['profile'] || $entries['shortcut']) {
  282. $navs['nav'] = array(
  283. 'title' => "导航菜单",
  284. );
  285. if($entries['home']) {
  286. $navs['nav']['items'][] = array(
  287. 'title' => "<i class='fa fa-home'></i> &nbsp;&nbsp;微站首页导航",
  288. 'url' => url('site/nav/home', array('m' => $m)),
  289. );
  290. }
  291. if($entries['profile']) {
  292. $navs['nav']['items'][] = array(
  293. 'title' => "<i class='fa fa-user'></i> &nbsp;&nbsp;个人中心导航",
  294. 'url' => url('site/nav/profile', array('m' => $m)),
  295. );
  296. }
  297. if($entries['shortcut']) {
  298. $navs['nav']['items'][] = array(
  299. 'title' => "<i class='fa fa-plane'></i> &nbsp;&nbsp;快捷菜单",
  300. 'url' => url('site/nav/shortcut', array('m' => $m)),
  301. );
  302. }
  303. }
  304. $menus = array(
  305. 'menu' => "业务菜单",
  306. 'cover' => "封面入口",
  307. 'mine' => "自定义菜单",
  308. );
  309. foreach($entries_filter as $key => $row) {
  310. if(empty($row)) continue;
  311. if(!isset($navs[$key])) {
  312. $navs[$key] = array(
  313. 'title' => $menus[$key],
  314. );
  315. }
  316. foreach($row as $li) {
  317. $navs[$key]['items'][] = array(
  318. 'title' => "<i class='{$li["icon"]}'></i> &nbsp;&nbsp;{$li['title']}",
  319. 'url' => $li['url']
  320. );
  321. }
  322. }
  323. }
  324. if($GLOBALS['ext_type'] == 1) {
  325. $ms['ext'] = $navs;
  326. } elseif($GLOBALS['ext_type'] == 3) {
  327. $ms['ext'] = array_merge($navs, $ms['ext']);
  328. }
  329. return $ms;
  330. }
  331. function system_modules() {
  332. return array(
  333. 'basic', 'news', 'music', 'userapi', 'recharge',
  334. 'custom', 'images', 'video', 'voice', 'chats', 'wxcard', 'paycenter'
  335. );
  336. }
  337. function filter_url($params) {
  338. global $_W;
  339. if(empty($params)) {
  340. return '';
  341. }
  342. $query_arr = array();
  343. $parse = parse_url($_W['siteurl']);
  344. if(!empty($parse['query'])) {
  345. $query = $parse['query'];
  346. parse_str($query, $query_arr);
  347. }
  348. $params = explode(',', $params);
  349. foreach($params as $val) {
  350. if(!empty($val)) {
  351. $data = explode(':', $val);
  352. $query_arr[$data[0]] = trim($data[1]);
  353. }
  354. }
  355. $query_arr['page'] = 1;
  356. $query = http_build_query($query_arr);
  357. return './index.php?' . $query;
  358. }
  359. function site_profile_perfect_tips(){
  360. global $_W;
  361. if ($_W['isfounder'] && (empty($_W['setting']['site']) || empty($_W['setting']['site']['profile_perfect']))) {
  362. if (!defined('SITE_PROFILE_PERFECT_TIPS')) {
  363. $url = url('cloud/profile');
  364. return <<<EOF
  365. $(function() {
  366. var html =
  367. '<div id="siteinfo-tips" class="upgrade-tips">'+
  368. '<a href="{$url}" target="_blank">请尽快完善您在微擎云服务平台的站点注册信息。</a>'+
  369. '</div>';
  370. $('body').prepend(html);
  371. });
  372. EOF;
  373. define('SITE_PROFILE_PERFECT_TIPS', true);
  374. }
  375. }
  376. return '';
  377. }