PageRenderTime 25ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/www/source/search.php

http://firmkernel.googlecode.com/
PHP | 220 lines | 209 code | 1 blank | 10 comment | 1 complexity | 293ea95635c710f0c850178870edc1fc MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------------+
  4. | $Id: search.php 2010-05-24 12:37:44Z Bleakwind $
  5. | Site search
  6. | Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
  7. | http://www.weaverdream.com/
  8. | Release under the GNU Lesser General Public License Version 3 (LGPLv3):
  9. | http://www.gnu.org/licenses/lgpl.html
  10. +-----------------------------------------------------------------------------+
  11. */
  12. if (!defined( 'ENTRY_INDEX')){
  13. echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
  14. exit;
  15. }
  16. if ($sys->get['ope'] == "save"){
  17. $sys->post['search_type'] = strtolower(trim($sys->post['search_type']));
  18. $sys->get['search_type'] = strtolower(trim($sys->get['search_type']));
  19. $search_type = !empty($sys->post['search_type']) ? $sys->post['search_type'] : $sys->get['search_type'];
  20. if(!preg_match("/^content$/i", $search_type)){ $search_type = "content"; }
  21. $sys->post['search_model'] = strtolower(trim($sys->post['search_model']));
  22. $sys->get['search_model'] = strtolower(trim($sys->get['search_model']));
  23. $search_model = !empty($sys->post['search_model']) ? $sys->post['search_model'] : $sys->get['search_model'];
  24. if(!preg_match("/^[1-9][0-9]{0,10}$/i", $search_model)){ $search_model = "0"; }
  25. $sys->post['search_keyword'] = strtolower(trim($sys->post['search_keyword']));
  26. $sys->get['search_keyword'] = strtolower(trim($sys->get['search_keyword']));
  27. $search_keyword = !empty($sys->post['search_keyword']) ? $sys->post['search_keyword'] : $sys->get['search_keyword'];
  28. if(empty($search_keyword)){
  29. $sys->prompt("failed", $LANGUAGE['s']['search']['keyword_empty']);
  30. } elseif(mb_strwidth($search_keyword,"UTF-8") > 30){
  31. $sys->prompt("failed", $LANGUAGE['s']['search']['keyword_long']);
  32. } elseif(in_array($search_keyword, $LANGUAGE['s']['search']['keyword_default'])){
  33. $sys->prompt("failed", $$LANGUAGE['s']['search']['keyword_default_error']);
  34. } else {
  35. $keyword_array = preg_split("/[\s,]+/", $search_keyword);
  36. if (is_array($keyword_array) && count($keyword_array) > 0) {
  37. $where_keyword = "";
  38. foreach ($keyword_array as $v) {
  39. $where_keyword .= " AND FIND_IN_SET('".addslashes($v)."', content.keyword) > 0";
  40. }
  41. $where_keyword = substr(trim($where_keyword), 0, 3) == "AND" ? substr(trim($where_keyword), 3) : trim($where_keyword);
  42. }
  43. $where = " AND (".$where_keyword.")";
  44. if (preg_match("/^[1-9][0-9]{0,10}$/i", $search_model)) {
  45. $where .= " AND channel.setmodel_id=".$search_model."";
  46. }
  47. $where .= " AND ((content.if_enable=1) || (content.if_enable=3 AND content.if_enable_begin<".time()." AND content.if_enable_begin>".time()."))";
  48. $where = substr(trim($where), 0, 3) == "AND" ? substr(trim($where), 3) : trim($where);
  49. $where = $where != "" ? "WHERE ".$where : "";
  50. //////
  51. $search_result['id_array'] = array();
  52. $sql = "SELECT scheduler.id as scheduler_id
  53. FROM ".DB_TABLE_SCHEDULER." scheduler
  54. LEFT JOIN ".DB_TABLE_CONTENT." content ON content.content_id=scheduler.content_id
  55. LEFT JOIN ".DB_TABLE_CONTENT_COVER." cover ON cover.content_id=scheduler.content_id
  56. LEFT JOIN ".DB_TABLE_CHANNEL." channel ON channel.id=scheduler.channel_id
  57. ".$where."
  58. GROUP BY scheduler.id
  59. ORDER BY content.if_top DESC, content.post_time DESC";
  60. $result = &$db->Execute($sql);
  61. if (!$result) {
  62. echo $db->ErrorMsg();
  63. } else {
  64. while (!$result->EOF) {
  65. $search_result['id_array'][] = $result->fields['scheduler_id'];
  66. $result->MoveNext();
  67. }
  68. }
  69. if (!is_array($search_result['id_array']) || count($search_result['id_array'])<=0) {
  70. $sys->prompt("failed", $LANGUAGE['s']['search']['result_empty']);
  71. } else {
  72. $search_result['id_list'] = implode(",", $search_result['id_array']);
  73. $error = false;
  74. for($i=0;$i<3;$i++) {
  75. $search_id = sha1($MEMBER['id'].microtime());
  76. $total_record = func::db_count_record(DB_TABLE_SEARCH, "sid='".$search_id."'");
  77. if ($total_record <= 0) {
  78. break;
  79. }else {
  80. if ($i == "2") {
  81. $error = true;
  82. $sys->prompt("failed", $LANGUAGE['s']['search']['build_sid_error']);
  83. }
  84. }
  85. }
  86. if (!$error) {
  87. $sql_data = array(
  88. "sid" => "'".$search_id."'",
  89. "type" => "'".$search_type."'",
  90. "keyword" => "'".$search_keyword."'",
  91. "result" => "'".$search_result['id_list']."'",
  92. "mid" => "'".(int)$MEMBER['id']."'",
  93. "time" => "'".time()."'",
  94. "ip" => "'".func::return_ip()."'",
  95. );
  96. $result = func::db_insert(DB_TABLE_SEARCH, $sql_data);
  97. if (!$result) {
  98. $sys->prompt("failed", $LANGUAGE['s']['search']['insert_error']);
  99. } else {
  100. $sys->prompt("jump",$CONFIGURE['common']['control_index']."?act=search&sid=".$search_id."&pag=".$sys->get['pag']);
  101. }
  102. }
  103. }
  104. }
  105. } else {
  106. if(!preg_match("/^[a-z0-9_]{40}$/i", $sys->get['sid'])){
  107. $sys->prompt("failed", $LANGUAGE['s']['search']['sid_error']);
  108. } else {
  109. $sid = $sys->get['sid'];
  110. $search_info = func::db_select(DB_TABLE_SEARCH, "*", "sid='".$sid."'");
  111. $search_info = $search_info[0];
  112. if(!preg_match("/^[a-z0-9_]{40}$/i", $search_info['sid'])){
  113. $sys->prompt("failed", $LANGUAGE['s']['search']['select_sid_error']);
  114. } else {
  115. $search_result = $search_info['result'];
  116. $search_array = explode(",", $search_result);
  117. $total_record = count($search_array);
  118. $bwpage->set_record($total_record);
  119. $bwpage->set_record_listnum($CONFIG['page_record_content_search']);
  120. $bwpage->page($CONFIGURE['common']['control_index']."?act=search&sid=".$sid."&pag=%s");
  121. $sql = "SELECT scheduler.id as scheduler_id,
  122. content.*,
  123. cover.id as cover_id, cover.dir as cover_dir, cover.filename as cover_filename,
  124. channel.id as channel_id, channel.name as channel_name
  125. FROM ".DB_TABLE_SCHEDULER." scheduler
  126. LEFT JOIN ".DB_TABLE_CONTENT." content ON content.content_id=scheduler.content_id
  127. LEFT JOIN ".DB_TABLE_CONTENT_COVER." cover ON cover.content_id=scheduler.content_id
  128. LEFT JOIN ".DB_TABLE_CHANNEL." channel ON channel.id=scheduler.channel_id
  129. WHERE scheduler.id IN (".$search_result.")
  130. AND ((content.if_enable=1) || (content.if_enable=3 AND content.if_enable_begin<".time()." AND content.if_enable_begin>".time()."))
  131. GROUP BY scheduler.id
  132. ORDER BY content.if_top DESC, content.post_time DESC
  133. LIMIT ".$bwpage->record_listfirst.",".$bwpage->record_listnum;
  134. $result = &$db->Execute($sql);
  135. if (!$result) {
  136. echo $db->ErrorMsg();
  137. } else {
  138. while (!$result->EOF) {
  139. $search_content_list[] = array(
  140. 'scheduler_id' => $result->fields['scheduler_id'],
  141. 'content_id' => $result->fields['content_id'],
  142. 'phrase' => $result->fields['phrase'],
  143. 'phrase_len' => mb_strwidth($result->fields['phrase'],"UTF-8"),
  144. 'subject' => $result->fields['subject'],
  145. 'subject_len' => mb_strwidth($result->fields['subject'],"UTF-8"),
  146. 'color' => $result->fields['color'],
  147. 'fontstyle' => $result->fields['fontstyle'],
  148. 'decoration' => $result->fields['decoration'],
  149. 'prefix' => $result->fields['prefix'],
  150. 'author' => $result->fields['author'],
  151. 'excerpt' => $result->fields['excerpt'],
  152. 'template_content' => $result->fields['template_content'],
  153. 'click' => $result->fields['click'],
  154. 'keyword' => $result->fields['keyword'],
  155. 'brief' => $result->fields['brief'],
  156. 'post_id' => $result->fields['post_id'],
  157. 'post_username' => $result->fields['post_username'],
  158. 'post_ip' => $result->fields['post_ip'],
  159. 'post_time' => $result->fields['post_time'],
  160. 'verify_id' => $result->fields['verify_id'],
  161. 'verify_username' => $result->fields['verify_username'],
  162. 'verify_ip' => $result->fields['verify_ip'],
  163. 'verify_time' => $result->fields['verify_time'],
  164. 'if_enable' => $result->fields['if_enable'],
  165. 'if_enable_begin' => $result->fields['if_enable_begin'],
  166. 'if_enable_end' => $result->fields['if_enable_end'],
  167. 'if_top' => $result->fields['if_top'],
  168. 'if_top_begin' => $result->fields['if_top_begin'],
  169. 'if_top_end' => $result->fields['if_top_end'],
  170. 'if_view' => $result->fields['if_view'],
  171. 'if_view_privilege' => $result->fields['if_view_privilege'],
  172. 'if_inerface' => $result->fields['if_inerface'],
  173. 'if_inerface_privilege' => $result->fields['if_inerface_privilege'],
  174. 'if_inerface_identity' => $result->fields['if_inerface_identity'],
  175. 'if_inerface_check' => $result->fields['if_inerface_check'],
  176. 'if_turn' => $result->fields['if_turn'],
  177. 'if_turn_type' => $result->fields['if_turn_type'],
  178. 'if_turn_url' => $result->fields['if_turn_url'],
  179. 'rank' => $result->fields['rank'],
  180. 'cover_id' => $result->fields['cover_id'],
  181. 'cover_dir' => $result->fields['cover_dir'],
  182. 'cover_filename' => $result->fields['cover_filename'],
  183. 'channel_id' => $result->fields['channel_id'],
  184. 'channel_name' => $result->fields['channel_name'],
  185. 'channel_name_len' => mb_strwidth($result->fields['channel_name'],"UTF-8"),
  186. );
  187. $result->MoveNext();
  188. }
  189. }
  190. if (!is_array($search_content_list) || count($search_content_list)<=0) {
  191. $sys->prompt("failed", $LANGUAGE['s']['search']['result_empty']);
  192. } else {
  193. $t->assign(array(
  194. "search_info" => $search_info,
  195. "search_content_list" => $search_content_list,
  196. "pagination" => $bwpage->pagination,
  197. ));
  198. }
  199. }
  200. }
  201. }
  202. $public_var['page_place'][] = $LANGUAGE['s']['search']['page_place'];
  203. ?>