albertlast /
SMF2.1
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file contains database functions specific to search related activity. |
||
| 5 | * |
||
| 6 | * Simple Machines Forum (SMF) |
||
| 7 | * |
||
| 8 | * @package SMF |
||
| 9 | * @author Simple Machines http://www.simplemachines.org |
||
| 10 | * @copyright 2017 Simple Machines and individual contributors |
||
| 11 | * @license http://www.simplemachines.org/about/smf/license.php BSD |
||
| 12 | * |
||
| 13 | * @version 2.1 Beta 4 |
||
| 14 | */ |
||
| 15 | |||
| 16 | if (!defined('SMF')) |
||
| 17 | die('No direct access...'); |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Add the file functions to the $smcFunc array. |
||
| 21 | */ |
||
| 22 | function db_search_init() |
||
|
0 ignored issues
–
show
|
|||
| 23 | { |
||
| 24 | global $smcFunc; |
||
| 25 | |||
| 26 | View Code Duplication | if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 27 | $smcFunc += array( |
||
| 28 | 'db_search_query' => 'smf_db_search_query', |
||
| 29 | 'db_search_support' => 'smf_db_search_support', |
||
| 30 | 'db_create_word_search' => 'smf_db_create_word_search', |
||
| 31 | 'db_support_ignore' => false, |
||
| 32 | 'db_search_language' => 'smf_db_search_language', |
||
| 33 | ); |
||
| 34 | |||
| 35 | db_extend(); |
||
| 36 | |||
| 37 | //pg 9.5 got ignore support |
||
| 38 | $version = $smcFunc['db_get_version'](); |
||
| 39 | // if we got a Beta Version |
||
| 40 | View Code Duplication | if (stripos($version, 'beta') !== false) |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 41 | $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
||
| 42 | // or RC |
||
| 43 | View Code Duplication | if (stripos($version, 'rc') !== false) |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 44 | $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
||
| 45 | |||
| 46 | if (version_compare($version,'9.5.0','>=')) |
||
| 47 | $smcFunc['db_support_ignore'] = true; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * This function will tell you whether this database type supports this search type. |
||
| 52 | * |
||
| 53 | * @param string $search_type The search type |
||
| 54 | * @return boolean Whether or not the specified search type is supported by this DB system. |
||
| 55 | */ |
||
| 56 | function smf_db_search_support($search_type) |
||
|
0 ignored issues
–
show
The function
smf_db_search_support() has been defined more than once; this definition is ignored, only the first definition in Sources/DbSearch-mysql.php (L41-46) is considered.
This check looks for functions that have already been defined in other files. Some Codebases, like WordPress, make a practice of defining functions multiple times. This
may lead to problems with the detection of function parameters and types. If you really
need to do this, you can mark the duplicate definition with the /**
* @ignore
*/
function getUser() {
}
function getUser($id, $realm) {
}
See also the PhpDoc documentation for @ignore. Loading history...
|
|||
| 57 | { |
||
| 58 | $supported_types = array('custom','fulltext'); |
||
| 59 | |||
| 60 | return in_array($search_type, $supported_types); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Returns the correct query for this search type. |
||
| 65 | * |
||
| 66 | * @param string $identifier A query identifier |
||
| 67 | * @param string $db_string The query text |
||
| 68 | * @param array $db_values An array of values to pass to $smcFunc['db_query'] |
||
| 69 | * @param resource $connection The current DB connection resource |
||
| 70 | * @return resource The query result resource from $smcFunc['db_query'] |
||
| 71 | */ |
||
| 72 | function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null) |
||
| 73 | { |
||
| 74 | global $smcFunc; |
||
| 75 | |||
| 76 | $replacements = array( |
||
| 77 | 'create_tmp_log_search_topics' => array( |
||
| 78 | '~mediumint\(\d\)~i' => 'int', |
||
| 79 | '~unsigned~i' => '', |
||
| 80 | '~ENGINE=MEMORY~i' => '', |
||
| 81 | ), |
||
| 82 | 'create_tmp_log_search_messages' => array( |
||
| 83 | '~mediumint\(\d\)~i' => 'int', |
||
| 84 | '~unsigned~i' => '', |
||
| 85 | '~ENGINE=MEMORY~i' => '', |
||
| 86 | ), |
||
| 87 | 'drop_tmp_log_search_topics' => array( |
||
| 88 | '~IF\sEXISTS~i' => '', |
||
| 89 | ), |
||
| 90 | 'drop_tmp_log_search_messages' => array( |
||
| 91 | '~IF\sEXISTS~i' => '', |
||
| 92 | ), |
||
| 93 | 'insert_into_log_messages_fulltext' => array( |
||
| 94 | '~LIKE~i' => 'iLIKE', |
||
| 95 | '~NOT\sLIKE~i' => '~NOT iLIKE', |
||
| 96 | '~NOT\sRLIKE~i' => '!~*', |
||
| 97 | '~RLIKE~i' => '~*', |
||
| 98 | ), |
||
| 99 | 'insert_log_search_results_subject' => array( |
||
| 100 | '~LIKE~i' => 'iLIKE', |
||
| 101 | '~NOT\sLIKE~i' => 'NOT iLIKE', |
||
| 102 | '~NOT\sRLIKE~i' => '!~*', |
||
| 103 | '~RLIKE~i' => '~*', |
||
| 104 | ), |
||
| 105 | ); |
||
| 106 | |||
| 107 | View Code Duplication | if (isset($replacements[$identifier])) |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 108 | $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
||
| 109 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
||
| 110 | { |
||
| 111 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
||
| 112 | if ($smcFunc['db_support_ignore']){ |
||
| 113 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
||
| 114 | $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
||
| 115 | } |
||
| 116 | else |
||
| 117 | { |
||
| 118 | // Don't error on multi-insert. |
||
| 119 | $db_values['db_error_skip'] = true; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | //fix double quotes |
||
| 124 | if ($identifier == 'insert_into_log_messages_fulltext') |
||
| 125 | $db_values = str_replace('"', "'", $db_values); |
||
| 126 | |||
| 127 | $return = $smcFunc['db_query']('', $db_string, |
||
| 128 | $db_values, $connection |
||
| 129 | ); |
||
| 130 | |||
| 131 | return $return; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Highly specific function, to create the custom word index table. |
||
| 136 | * |
||
| 137 | * @param string $size The column size type (int, mediumint (8), etc.). Not used here. |
||
| 138 | */ |
||
| 139 | function smf_db_create_word_search($size) |
||
|
0 ignored issues
–
show
The function
smf_db_create_word_search() has been defined more than once; this definition is ignored, only the first definition in Sources/DbSearch-mysql.php (L53-75) is considered.
This check looks for functions that have already been defined in other files. Some Codebases, like WordPress, make a practice of defining functions multiple times. This
may lead to problems with the detection of function parameters and types. If you really
need to do this, you can mark the duplicate definition with the /**
* @ignore
*/
function getUser() {
}
function getUser($id, $realm) {
}
See also the PhpDoc documentation for @ignore. Loading history...
|
|||
| 140 | { |
||
| 141 | global $smcFunc; |
||
| 142 | |||
| 143 | $size = 'int'; |
||
| 144 | |||
| 145 | $smcFunc['db_query']('', ' |
||
| 146 | CREATE TABLE {db_prefix}log_search_words ( |
||
| 147 | id_word {raw:size} NOT NULL default {string:string_zero}, |
||
| 148 | id_msg int NOT NULL default {string:string_zero}, |
||
| 149 | PRIMARY KEY (id_word, id_msg) |
||
| 150 | )', |
||
| 151 | array( |
||
| 152 | 'size' => $size, |
||
| 153 | 'string_zero' => '0', |
||
| 154 | ) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Return the language for the textsearch index |
||
| 160 | */ |
||
| 161 | function smf_db_search_language() |
||
| 162 | { |
||
| 163 | global $smcFunc, $modSettings; |
||
| 164 | |||
| 165 | $language_ftx = 'english'; |
||
| 166 | |||
| 167 | if (!empty($modSettings['search_language'])) |
||
| 168 | $language_ftx = $modSettings['search_language']; |
||
| 169 | else |
||
| 170 | { |
||
| 171 | $request = $smcFunc['db_query']('',' |
||
| 172 | SELECT cfgname FROM pg_ts_config WHERE oid = current_setting({string:default_language})::regconfig', |
||
| 173 | array( |
||
| 174 | 'default_language' => 'default_text_search_config' |
||
| 175 | ) |
||
| 176 | ); |
||
| 177 | |||
| 178 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
||
| 179 | { |
||
| 180 | $row = $smcFunc['db_fetch_assoc']($request); |
||
| 181 | $language_ftx = $row['cfgname']; |
||
| 182 | |||
| 183 | $smcFunc['db_insert']('replace', |
||
| 184 | '{db_prefix}settings', |
||
| 185 | array('variable' => 'string', 'value' => 'string'), |
||
| 186 | array('search_language', $language_ftx), |
||
| 187 | array('variable') |
||
| 188 | ); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return $language_ftx; |
||
| 193 | } |
||
| 194 | |||
| 195 | ?> |
||
|
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. Loading history...
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignoreannotation.See also the PhpDoc documentation for @ignore.