人人商城

site.ctrl.php 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. $do = in_array($do, array('list', 'detail', 'handsel', 'comment')) ? $do : 'list';
  8. load()->model('site');
  9. load()->model('mc');
  10. load()->model('article');
  11. load()->model('account');
  12. if ($do == 'list') {
  13. $cid = intval($_GPC['cid']);
  14. $category = pdo_fetch("SELECT * FROM " . tablename('site_category') . " WHERE id = '{$cid}' AND uniacid = '{$_W['uniacid']}'");
  15. if (empty($category)) {
  16. message('分类不存在或是已经被删除!');
  17. }
  18. if (! empty($category['linkurl'])) {
  19. header('Location: ' . $category['linkurl']);
  20. exit();
  21. }
  22. $_share['desc'] = $category['description'];
  23. $_share['title'] = $category['name'];
  24. $title = $category['name'];
  25. $category['template'] = pdo_fetchcolumn('SELECT b.name FROM ' . tablename('site_styles') . ' AS a LEFT JOIN ' . tablename('site_templates') . ' AS b ON a.templateid = b.id WHERE a.id = :id', array(
  26. ':id' => $category['styleid']
  27. ));
  28. if (! empty($category['template'])) {
  29. $styles_vars = pdo_fetchall('SELECT * FROM ' . tablename('site_styles_vars') . ' WHERE styleid = :styleid', array(
  30. ':styleid' => $category['styleid']
  31. ));
  32. if (! empty($styles_vars)) {
  33. foreach ($styles_vars as $row) {
  34. if (strexists($row['variable'], 'img')) {
  35. $row['content'] = tomedia($row['content']);
  36. }
  37. $_W['styles'][$row['variable']] = $row['content'];
  38. }
  39. }
  40. }
  41. if (empty($category['ishomepage'])) {
  42. $ishomepage = 0;
  43. if (! empty($category['template'])) {
  44. $_W['template'] = $category['template'];
  45. }
  46. template('site/list');
  47. exit();
  48. } else {
  49. if (! empty($category['template'])) {
  50. $_W['template'] = $category['template'];
  51. }
  52. $ishomepage = 1;
  53. $navs = pdo_fetchall("SELECT * FROM " . tablename('site_category') . " WHERE uniacid = '{$_W['uniacid']}' AND parentid = '$cid' ORDER BY displayorder DESC,id DESC");
  54. if (! empty($navs)) {
  55. foreach ($navs as &$row) {
  56. if (empty($row['linkurl']) || (! strexists($row['linkurl'], 'http://') && ! strexists($row['linkurl'], 'https://'))) {
  57. $row['url'] = url('site/site/list', array(
  58. 'cid' => $row['id']
  59. ));
  60. } else {
  61. $row['url'] = $row['linkurl'];
  62. }
  63. if (! empty($row['icontype']) && $row['icontype'] == 1) {
  64. $row['css'] = iunserializer($row['css']);
  65. $row['icon'] = '';
  66. $row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";
  67. $row['css']['name'] = "color:{$row['css']['name']['color']};";
  68. }
  69. if (! empty($row['icontype']) && $row['icontype'] == 2) {
  70. $row['css'] = '';
  71. }
  72. }
  73. }
  74. template('home/home');
  75. exit();
  76. }
  77. } elseif ($do == 'detail') {
  78. $id = intval($_GPC['id']);
  79. $sql = "SELECT * FROM " . tablename('site_article') . " WHERE `id`=:id AND uniacid = :uniacid";
  80. $detail = pdo_fetch($sql, array(
  81. ':id' => $id,
  82. ':uniacid' => $_W['uniacid']
  83. ));
  84. if (empty($detail)) {
  85. message('文章已不存在或已被删除!', referer(), 'info');
  86. }
  87. if (! empty($detail['linkurl'])) {
  88. if (strtolower(substr($detail['linkurl'], 0, 4)) != 'tel:' && ! strexists($detail['linkurl'], 'http://') && ! strexists($detail['linkurl'], 'https://')) {
  89. $detail['linkurl'] = $_W['siteroot'] . 'app/' . $detail['linkurl'];
  90. }
  91. header('Location: ' . $detail['linkurl']);
  92. exit();
  93. }
  94. $detail = istripslashes($detail);
  95. $detail['content'] = preg_replace("/<img(.*?)(http[s]?\:\/\/mmbiz.qpic.cn[^\?]*?)(\?[^\"]*?)?\"/i", '<img $1$2"', $detail['content']);
  96. if (! empty($detail['incontent'])) {
  97. $detail['content'] = '<p><img src="' . tomedia($detail['thumb']) . '" title="' . $detail['title'] . '" /></p>' . $detail['content'];
  98. }
  99. if (! empty($detail['thumb'])) {
  100. $detail['thumb'] = tomedia($detail['thumb']);
  101. } else {
  102. $detail['thumb'] = '';
  103. }
  104. $title = $_W['page']['title'] = '';
  105. if (! empty($detail['template'])) {
  106. $_W['template'] = $detail['template'];
  107. }
  108. if ($_W['os'] == 'android' && $_W['container'] == 'wechat' && $_W['account']['account']) {
  109. $subscribeurl = "weixin://profile/{$_W['account']['account']}";
  110. } else {
  111. $sql = 'SELECT `subscribeurl` FROM ' . tablename('account_wechats') . " WHERE `acid` = :acid";
  112. $subscribeurl = pdo_fetchcolumn($sql, array(
  113. ':acid' => intval($_W['acid'])
  114. ));
  115. }
  116. $detail['click'] = intval($detail['click']) + 1;
  117. pdo_update('site_article', array(
  118. 'click' => $detail['click']
  119. ), array(
  120. 'uniacid' => $_W['uniacid'],
  121. 'id' => $id
  122. ));
  123. $_share = array(
  124. 'desc' => $detail['description'],
  125. 'title' => $detail['title'],
  126. 'imgUrl' => $detail['thumb']
  127. );
  128. $setting = uni_setting($_W['uniacid']);
  129. if (!empty($setting['comment_status'])) {
  130. mc_oauth_userinfo();
  131. $pindex = max(1, intval($_GPC['page']));
  132. $psize = 10;
  133. $comment_table = table('sitearticlecomment');
  134. $comment_table->searchWithArticleid($id);
  135. $comment_table->searchWithParentid(ARTICLE_COMMENT_DEFAULT);
  136. $comment_table->searchWithPage($pindex, $psize);
  137. $article_lists = $comment_table->articleCommentList();
  138. $total = $comment_table->getLastQueryTotal();
  139. $pager = pagination($total, $pindex, $psize);
  140. $article_lists = article_comment_detail($article_lists);
  141. }
  142. template('site/detail');
  143. } elseif ($do == 'handsel') {
  144. if ($_W['ispost']) {
  145. $id = intval($_GPC['id']);
  146. $article = pdo_fetch('SELECT id, credit FROM ' . tablename('site_article') . ' WHERE uniacid = :uniacid AND id = :id', array(
  147. ':uniacid' => $_W['uniacid'],
  148. ':id' => $id
  149. ));
  150. $credit = iunserializer($article['credit']) ? iunserializer($article['credit']) : array();
  151. if (! empty($article) && $credit['status'] == 1) {
  152. if ($_GPC['action'] == 'share') {
  153. $touid = $_W['member']['uid'];
  154. $formuid = - 1;
  155. $handsel = array(
  156. 'module' => 'article',
  157. 'sign' => md5(iserializer(array(
  158. 'id' => $id
  159. ))),
  160. 'action' => 'share',
  161. 'credit_value' => $credit['share'],
  162. 'credit_log' => '分享文章,赠送积分'
  163. );
  164. } elseif ($_GPC['action'] == 'click') {
  165. $touid = intval($_GPC['u']);
  166. $formuid = CLIENT_IP;
  167. $handsel = array(
  168. 'module' => 'article',
  169. 'sign' => md5(iserializer(array(
  170. 'id' => $id
  171. ))),
  172. 'action' => 'click',
  173. 'credit_value' => $credit['click'],
  174. 'credit_log' => '分享的文章在朋友圈被阅读,赠送积分'
  175. );
  176. }
  177. $total = pdo_fetchcolumn('SELECT SUM(credit_value) FROM ' . tablename('mc_handsel') . ' WHERE uniacid = :uniacid AND module = :module AND sign = :sign', array(
  178. ':uniacid' => $_W['uniacid'],
  179. ':module' => 'article',
  180. ':sign' => $handsel['sign']
  181. ));
  182. if (($total >= $credit['limit']) || (($total + $handsel['credit_value']) > $credit['limit'])) {
  183. exit(json_encode(error(- 1, '赠送积分已达到上限')));
  184. }
  185. $status = mc_handsel($touid, $formuid, $handsel, $_W['uniacid']);
  186. if (is_error($status)) {
  187. exit(json_encode($status));
  188. } else {
  189. if ($handsel['action'] == 'share') {
  190. $send_msg = '分享文章,赠送积分';
  191. }else if ($handsel['action'] == 'click') {
  192. $send_msg = '分享的文章被阅读,赠送积分';
  193. }
  194. $openid = pdo_getcolumn('mc_mapping_fans', array('uniacid' => $_W['uniacid'], 'uid' => $_W['member']['uid']), 'openid');
  195. mc_notice_credit1($openid, $touid, $credit['share'], $send_msg);
  196. exit('success');
  197. }
  198. } else {
  199. exit(json_encode(array(
  200. - 1,
  201. '文章没有设置赠送积分'
  202. )));
  203. }
  204. } else {
  205. exit(json_encode(array(
  206. - 1,
  207. '非法操作'
  208. )));
  209. }
  210. }
  211. if ($do == 'comment') {
  212. $article_id = intval($_GPC['article_id']);
  213. $parent_id = intval($_GPC['parent_id']);
  214. $article_info = pdo_get('site_article', array('id' => $article_id, 'uniacid' => $_W['uniacid']));
  215. if ($_W['ispost']) {
  216. $comment = array(
  217. 'uniacid' => $_W['uniacid'],
  218. 'articleid' => intval($_GPC['article_id']),
  219. 'openid' => $_W['openid'],
  220. 'content' => safe_gpc_html(htmlspecialchars_decode($_GPC['content']))
  221. );
  222. $comment_add = article_comment_add($comment);
  223. if (is_error($comment_add)) {
  224. message($comment_add['message'], referer(), 'error');
  225. }
  226. header('Location: ' . murl('site/site/detail', array('id' => intval($_GPC['article_id']))));
  227. exit();
  228. }
  229. template('site/comment');
  230. }