site.ctrl.php 6.6 KB

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