人人商城

reply.mod.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 reply_search($condition = '', $params = array(), $pindex = 0, $psize = 10, &$total = 0) {
  8. if (!empty($condition)) {
  9. $where = " WHERE {$condition}";
  10. }
  11. $sql = "SELECT * FROM " . tablename('rule') . $where . " ORDER BY status DESC, displayorder DESC, id DESC";
  12. if ($pindex > 0) {
  13. $start = ($pindex - 1) * $psize;
  14. $sql .= " LIMIT {$start},{$psize}";
  15. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('rule') . $where, $params);
  16. }
  17. return pdo_fetchall($sql, $params);
  18. }
  19. function reply_single($id) {
  20. $id = intval($id);
  21. $result = table('rule')->getById($id);
  22. if (empty($result)) {
  23. return $result;
  24. }
  25. $result['keywords'] = table('rulekeyword')->whereRid($id)->getall();
  26. return $result;
  27. }
  28. function reply_keywords_search($condition = '', $params = array(), $pindex = 0, $psize = 10, &$total = 0) {
  29. if (!empty($condition)) {
  30. $where = " WHERE {$condition} ";
  31. }
  32. $sql = 'SELECT * FROM ' . tablename('rule_keyword') . $where . ' ORDER BY displayorder DESC, `type` ASC, id DESC';
  33. if ($pindex > 0) {
  34. $start = ($pindex - 1) * $psize;
  35. $sql .= " LIMIT {$start},{$psize}";
  36. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('rule_keyword') . $where, $params);
  37. }
  38. $result = pdo_fetchall($sql, $params);
  39. if (!empty($result)) {
  40. foreach ($result as $key => $val) {
  41. $containtypes = pdo_get('rule', array('id' => $val['rid']), array('containtype'));
  42. if (!empty($containtypes)) {
  43. $containtype = explode(',', $containtypes['containtype']);
  44. $containtype = array_filter($containtype);
  45. } else {
  46. $containtype = array();
  47. }
  48. $result[$key]['reply_type'] = $containtype;
  49. }
  50. } else {
  51. $result = array();
  52. }
  53. return $result;
  54. }
  55. function reply_contnet_search($rid = 0) {
  56. $result = array();
  57. $rid = intval($rid);
  58. if (empty($rid)) {
  59. return $result;
  60. }
  61. $modules = array('basic', 'images', 'news', 'music', 'voice', 'video');
  62. $result = table('reply')->getModuleReplayCount($modules, $rid);
  63. return $result;
  64. }
  65. function reply_predefined_service() {
  66. $predefined_service = array(
  67. 'weather.php' => array(
  68. 'title' => '城市天气',
  69. 'description' => '"城市名+天气", 如: "北京天气"',
  70. 'keywords' => array(
  71. array('3', '^.+天气$')
  72. )
  73. ),
  74. 'baike.php' => array(
  75. 'title' => '百度百科',
  76. 'description' => '"百科+查询内容" 或 "定义+查询内容", 如: "百科姚明", "定义自行车"',
  77. 'keywords' => array(
  78. array('3', '^百科.+$'),
  79. array('3', '^定义.+$'),
  80. )
  81. ),
  82. 'translate.php' => array(
  83. 'title' => '即时翻译',
  84. 'description' => '"@查询内容(中文或英文)"',
  85. 'keywords' => array(
  86. array('3', '^@.+$'),
  87. )
  88. ),
  89. 'calendar.php' => array(
  90. 'title' => '今日老黄历',
  91. 'description' => '"日历", "万年历", "黄历"或"几号"',
  92. 'keywords' => array(
  93. array('1', '日历'),
  94. array('1', '万年历'),
  95. array('1', '黄历'),
  96. array('1', '几号'),
  97. )
  98. ),
  99. 'news.php' => array(
  100. 'title' => '看新闻',
  101. 'description' => '"新闻"',
  102. 'keywords' => array(
  103. array('1', '新闻'),
  104. )
  105. ),
  106. 'express.php' => array(
  107. 'title' => '快递查询',
  108. 'description' => '"快递+单号", 如: "申通1200041125"',
  109. 'keywords' => array(
  110. array('3', '^(申通|圆通|中通|汇通|韵达|顺丰|EMS) *[a-z0-9]{1,}$')
  111. )
  112. ),
  113. );
  114. return $predefined_service;
  115. }
  116. function reply_getall_common_service() {
  117. global $_W;
  118. $rule_setting_select = table('uniaccountmodules')->whereUniacid($_W['uniacid'])->whereModule('userapi')->getcolumn('settings');
  119. $rule_setting_select = iunserializer($rule_setting_select);
  120. $exists_rule = table('rule')->where(array('uniacid' => 0, 'module' => 'userapi', 'status' => 1))->getall();
  121. $service_list = array();
  122. $rule_ids = array();
  123. $api_url = array();
  124. if (!empty($exists_rule)) {
  125. foreach ($exists_rule as $rule_detail) {
  126. $rule_ids[] = $rule_detail['id'];
  127. $service_list[$rule_detail['id']] = $rule_detail;
  128. }
  129. $all_description = table('userapireply')->whereRid($rule_ids)->getall();
  130. if (!empty($all_description)) {
  131. foreach ($all_description as $description) {
  132. $service_list[$description['rid']]['description'] = $description['description'];
  133. $service_list[$description['rid']]['switch'] = isset($rule_setting_select[$description['rid']]) && $rule_setting_select[$description['rid']] ? 'checked' : '';
  134. $api_url[] = $description['apiurl'];
  135. }
  136. }
  137. }
  138. $all_service = reply_predefined_service();
  139. $all_url = array_keys($all_service);
  140. $diff_url = array_diff($all_url, $api_url);
  141. if (!empty($diff_url)) {
  142. foreach ($diff_url as $url) {
  143. $service_list[$url]['id'] = $all_service[$url];
  144. $service_list[$url]['name'] = $all_service[$url]['title'];
  145. $service_list[$url]['description'] = $all_service[$url]['description'];
  146. $service_list[$url]['switch'] = '';
  147. }
  148. }
  149. return $service_list;
  150. }
  151. function reply_insert_without_service($file) {
  152. $rule_id = table('userapireply')->whereApiurl($file)->getcolumn('rid');
  153. if (!empty($rule_id)) {
  154. return $rule_id;
  155. }
  156. $all_service = reply_predefined_service();
  157. $all_url = array_keys($all_service);
  158. if (!in_array($file, $all_url)) {
  159. return false;
  160. }
  161. $rule_id = table('userapireply')->userapiSave($all_service, $file);
  162. return $rule_id;
  163. }