link.ctrl.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. load()->model('module');
  8. load()->model('site');
  9. $dos = array('entry', 'modulelink', 'articlelist', 'pagelist', 'newslist', 'catelist', 'page', 'news', 'article');
  10. $do = in_array($do, $dos) ? $do : 'entry';
  11. $_W['page']['title'] = '';
  12. $callback = $_GPC['callback'];
  13. if ($do == 'modulelink') {
  14. $modules = uni_modules_app_binding();
  15. $entries = array();
  16. foreach ($modules as $module => $item) {
  17. $entries[$module] = module_entries($module, array('menu'));
  18. $entries[$module]['title'] = $item['title'];
  19. }
  20. }
  21. if ($do == 'articlelist') {
  22. $result = array();
  23. $psize = 10;
  24. $pindex = max(1, intval($_GPC['page']));
  25. $condition = '';
  26. if (!empty($_GPC['keyword'])) {
  27. $condition .= " AND title LIKE :title";
  28. $param = array(':uniacid' => $_W['uniacid'], ':title' => '%'. trim($_GPC['keyword']) .'%');
  29. } else {
  30. $param = array(':uniacid' => $_W['uniacid']);
  31. }
  32. $result['list'] = pdo_fetchall("SELECT id, title, thumb, description, content, author, incontent, linkurl, createtime, uniacid FROM ".tablename('site_article')." WHERE uniacid = :uniacid". $condition ." ORDER BY displayorder DESC, id LIMIT " . ($pindex - 1) * $psize . ',' . $psize, $param, 'id');
  33. if (!empty($result['list'])) {
  34. foreach ($result['list'] as $k => &$v) {
  35. $v['thumb_url'] = tomedia($v['thumb']);
  36. $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
  37. $v['name'] = cutstr($v['name'], 10);
  38. }
  39. unset($v);
  40. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('site_article')." WHERE uniacid = :uniacid". $condition, $param);
  41. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'null'));
  42. }
  43. iajax(0, $result);
  44. }
  45. if ($do == 'pagelist') {
  46. $result = array();
  47. $psize = 10;
  48. $pindex = max(1, intval($_GPC['page']));
  49. $condition = '';
  50. if (!empty($_GPC['keyword'])) {
  51. $condition .= " AND title LIKE :title";
  52. $param = array(':uniacid' => $_W['uniacid'], ':title' => '%'. trim($_GPC['keyword']) .'%');
  53. } else {
  54. $param = array(':uniacid' => $_W['uniacid']);
  55. }
  56. $result['list'] = pdo_fetchall("SELECT * FROM ".tablename('site_page')." WHERE uniacid = :uniacid AND type = '1'".$condition." ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, $param, 'id');
  57. if (!empty($result['list'])) {
  58. foreach ($result['list'] as $k => &$v) {
  59. $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
  60. }
  61. unset($v);
  62. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " .tablename('site_page'). " WHERE uniacid = :uniacid AND type = 1" . $condition, $param);
  63. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'true'));
  64. }
  65. iajax(0, $result);
  66. }
  67. if ($do == 'newslist') {
  68. $result = array();
  69. $psize = 10;
  70. $pindex = max(1, intval($_GPC['page']));
  71. $condition = '';
  72. if (!empty($_GPC['keyword'])) {
  73. $condition .= " AND n.title LIKE :title";
  74. $param = array(':uniacid' => $_W['uniacid'], ':title' => '%'. trim($_GPC['keyword']) .'%');
  75. } else {
  76. $param = array(':uniacid' => $_W['uniacid']);
  77. }
  78. $sql = "SELECT n.id, n.title, n.url FROM ". tablename('rule')."AS r,". tablename('news_reply'). " AS n WHERE r.id = n.rid AND r.module IN ('reply', 'news') AND r.uniacid = :uniacid". $condition ." ORDER BY n.displayorder DESC LIMIT ". ($pindex - 1) * $psize . ',' . $psize;
  79. $result['list'] = pdo_fetchall($sql, $param, 'id');
  80. if (!empty($result['list'])) {
  81. foreach ($result['list'] as $key => &$list) {
  82. if (empty($list['url'])) {
  83. $list['url'] = './index.php?i=' . $_W['uniacid'] . '&c=entry&id=' . $list['id'] . '&do=detail&m=core';
  84. }
  85. }
  86. $sql = "SELECT COUNT(*) FROM ". tablename('rule')."AS r,". tablename('news_reply'). " AS n WHERE r.id = n.rid AND r.module IN ('reply', 'news') AND r.uniacid = :uniacid ". $condition;
  87. $total = pdo_fetchcolumn($sql, $param);
  88. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'null'));
  89. }
  90. iajax(0, $result);
  91. }
  92. if ($do == 'catelist') {
  93. $condition = '';
  94. if (!empty($_GPC['keyword'])) {
  95. $condition .= " AND name LIKE :name";
  96. $param = array(':uniacid' => $_W['uniacid'], ':name' => '%'.trim($_GPC['keyword']).'%');
  97. } else {
  98. $param = array(':uniacid' => $_W['uniacid']);
  99. }
  100. $category = pdo_fetchall("SELECT id, uniacid, parentid, name FROM ".tablename('site_category')." WHERE uniacid = :uniacid ". $condition." ORDER BY parentid, displayorder DESC, id", $param, 'id');
  101. foreach ($category as $index => $row) {
  102. if (!empty($row['parentid'])){
  103. $category[$row['parentid']]['children'][$row['id']] = $row;
  104. unset($category[$index]);
  105. }
  106. }
  107. iajax(0, $category);
  108. }
  109. if ($do == 'page') {
  110. $result = array();
  111. $psize = 10;
  112. $pindex = max(1, intval($_GPC['page']));
  113. $result['list'] = pdo_fetchall("SELECT * FROM ".tablename('site_page')." WHERE uniacid = :uniacid AND type = '1' ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid']), 'id');
  114. if (!empty($result['list'])) {
  115. foreach ($result['list'] as $k => &$v) {
  116. $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
  117. }
  118. unset($v);
  119. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('site_page'). ' WHERE uniacid = :uniacid AND type = 1', array(':uniacid' => $_W['uniacid']));
  120. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'true'));
  121. }
  122. }
  123. if ($do == 'news') {
  124. $result = array();
  125. $psize = 10;
  126. $pindex = max(1, intval($_GPC['page']));
  127. $sql = "SELECT n.id, n.title FROM ". tablename('rule')."AS r,". tablename('news_reply'). " AS n WHERE r.id = n.rid AND r.module = :news AND r.uniacid = :uniacid ORDER BY n.displayorder DESC LIMIT ". ($pindex - 1) * $psize . ',' . $psize;
  128. $result['list'] = pdo_fetchall($sql, array(':news' => 'news', ':uniacid' => $_W['uniacid']), 'id');
  129. if (!empty($result['list'])) {
  130. $sql = "SELECT COUNT(*) FROM ". tablename('rule')."AS r,". tablename('news_reply'). " AS n WHERE r.id = n.rid AND r.module = :news AND r.uniacid = :uniacid ";
  131. $total = pdo_fetchcolumn($sql, array(':news' => 'news', ':uniacid' => $_W['uniacid']));
  132. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'null'));
  133. }
  134. }
  135. if ($do == 'article') {
  136. $result = array();
  137. $psize = 10;
  138. $pindex = max(1, intval($_GPC['page']));
  139. $result['list'] = pdo_fetchall("SELECT id, title, thumb, description, content, author, incontent, linkurl, createtime, uniacid FROM ".tablename('site_article')." WHERE uniacid = :uniacid ORDER BY displayorder DESC, id LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid']), 'id');
  140. if (!empty($result['list'])) {
  141. foreach ($result['list'] as $k => &$v) {
  142. $v['thumb_url'] = tomedia($v['thumb']);
  143. $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
  144. $v['name'] = cutstr($v['name'], 10);
  145. }
  146. unset($v);
  147. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('site_article').' WHERE uniacid = :uniacid', array(':uniacid' => $_W['uniacid']));
  148. $result['pager'] = pagination($total, $pindex, $psize, '', array('before' => '2', 'after' => '3', 'ajaxcallback'=>'null'));
  149. }
  150. $category = pdo_fetchall("SELECT id, uniacid, parentid, name FROM ".tablename('site_category')." WHERE uniacid = :uniacid ORDER BY parentid, displayorder DESC, id", array(':uniacid' => $_W['uniacid']), 'id');
  151. foreach ($category as $index => $row) {
  152. if (!empty($row['parentid'])){
  153. $category[$row['parentid']]['children'][$row['id']] = $row;
  154. unset($category[$index]);
  155. }
  156. }
  157. }
  158. if ($do == 'entry') {
  159. $has_permission = array();
  160. if(permission_account_user_permission_exist()) {
  161. $has_permission = array(
  162. 'system' => array(),
  163. 'modules' => array()
  164. );
  165. $has_permission['system'] = permission_account_user('system');
  166. $module_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], 'modules');
  167. if(!is_error($module_permission) && !empty($module_permission)) {
  168. $has_permission['modules'] = array_keys($module_permission);
  169. foreach($module_permission as $row) {
  170. if($row['permission'] == 'all') {
  171. $has_permission[$row['type']] = array('all');
  172. } else {
  173. $has_permission[$row['type']] = explode('|', $row['permission']);
  174. }
  175. }
  176. }
  177. }
  178. $modulemenus = array();
  179. $modules = uni_modules_app_binding();
  180. foreach($modules as $module) {
  181. $m = $module['name'];
  182. if(empty($has_permission) || (!empty($has_permission) && in_array($m, $has_permission['modules']))) {
  183. $entries = $module['entries'];
  184. if(!empty($has_permission[$m]) && $has_permission[$m][0] != 'all') {
  185. if(!in_array($m.'_home', $has_permission[$m])) {
  186. unset($entries['home']);
  187. }
  188. if(!in_array($m.'_profile', $has_permission[$m])) {
  189. unset($entries['profile']);
  190. }
  191. if(!in_array($m.'_shortcut', $has_permission[$m])) {
  192. unset($entries['shortcut']);
  193. }
  194. if(!empty($entries['cover'])) {
  195. foreach($entries['cover'] as $k => $row) {
  196. if(!in_array($m.'_cover_'.$row['do'], $has_permission[$m])) {
  197. unset($entries['cover'][$k]);
  198. }
  199. }
  200. }
  201. }
  202. $module['cover'] = $entries['cover'];
  203. $module['home'] = $entries['home'];
  204. $module['profile'] = $entries['profile'];
  205. $module['shortcut'] = $entries['shortcut'];
  206. $module['function'] = $entries['function'];
  207. $modulemenus[$module['type']][$module['name']] = $module;
  208. }
  209. }
  210. $modtypes = module_types();
  211. $sysmenus = array(
  212. array('title'=>'微站首页','url'=> murl('home')),
  213. array('title'=>'个人中心','url'=> rtrim(murl('mc'), '&')),
  214. );
  215. if(empty($has_permission) || (!empty($has_permission) && in_array('site_multi_display', $has_permission['system']))) {
  216. $multi_list = pdo_getall('site_multi', array('uniacid' => $_W['uniacid'], 'status !=' => 0), array('id', 'title'));
  217. if(!empty($multi_list)) {
  218. foreach($multi_list as $multi) {
  219. $multimenus[] = array('title' => $multi['title'], 'url' => murl('home', array('t' => $multi['id'])));
  220. }
  221. }
  222. }
  223. $linktypes = array(
  224. 'cover' => '封面链接',
  225. 'home' => '微站首页导航',
  226. 'profile'=>'微站个人中心导航',
  227. 'shortcut' => '微站快捷功能导航',
  228. 'function' => '微站独立功能',
  229. );
  230. }
  231. template('utility/link');