Mercurial > hg > vamp-website
comparison forum/Sources/DbSearch-sqlite.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* This file contains database functions specific to search related activity. | |
18 | |
19 void db_search_init() | |
20 - adds the functions in this file to the $smcFunc array | |
21 | |
22 boolean smf_db_search_support($search_type) | |
23 - whether this database type support the search type $search_type | |
24 | |
25 void smf_db_create_word_search($size) | |
26 - create the custom word index table | |
27 | |
28 resource smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null) | |
29 - returns the correct query for this search type. | |
30 */ | |
31 | |
32 // Add the file functions to the $smcFunc array. | |
33 function db_search_init() | |
34 { | |
35 global $smcFunc; | |
36 | |
37 if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') | |
38 $smcFunc += array( | |
39 'db_search_query' => 'smf_db_search_query', | |
40 'db_search_support' => 'smf_db_search_support', | |
41 'db_create_word_search' => 'smf_db_create_word_search', | |
42 'db_support_ignore' => false, | |
43 ); | |
44 } | |
45 | |
46 // Does this database type support this search type? | |
47 function smf_db_search_support($search_type) | |
48 { | |
49 $supported_types = array('custom'); | |
50 | |
51 return in_array($search_type, $supported_types); | |
52 } | |
53 | |
54 // Returns the correct query for this search type. | |
55 function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null) | |
56 { | |
57 global $smcFunc; | |
58 | |
59 $replacements = array( | |
60 'create_tmp_log_search_topics' => array( | |
61 '~mediumint\(\d\)~i' => 'int', | |
62 '~TYPE=HEAP~i' => '', | |
63 ), | |
64 'create_tmp_log_search_messages' => array( | |
65 '~mediumint\(\d\)~i' => 'int', | |
66 '~TYPE=HEAP~i' => '', | |
67 ), | |
68 ); | |
69 | |
70 if (isset($replacements[$identifier])) | |
71 $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); | |
72 elseif (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) | |
73 { | |
74 $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); | |
75 // Don't error on multi-insert. | |
76 $db_values['db_error_skip'] = true; | |
77 } | |
78 | |
79 $return = $smcFunc['db_query']('', $db_string, | |
80 $db_values, $connection | |
81 ); | |
82 | |
83 return $return; | |
84 } | |
85 | |
86 // Highly specific - create the custom word index table! | |
87 function smf_db_create_word_search($size) | |
88 { | |
89 global $smcFunc; | |
90 | |
91 $size = 'int'; | |
92 | |
93 $smcFunc['db_query']('', ' | |
94 CREATE TABLE {db_prefix}log_search_words ( | |
95 id_word {raw:size} NOT NULL default {string:string_zero}, | |
96 id_msg int(10) NOT NULL default {string:string_zero}, | |
97 PRIMARY KEY (id_word, id_msg) | |
98 )', | |
99 array( | |
100 'size' => $size, | |
101 'string_zero' => '0', | |
102 ) | |
103 ); | |
104 } | |
105 | |
106 ?> |