Completed
Push — release-2.1 ( 02c5c7...5a39ee )
by Colin
09:26
created

search_api::supportsMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Simple Machines Forum (SMF)
5
 *
6
 * @package SMF
7
 * @author Simple Machines http://www.simplemachines.org
8
 * @copyright 2018 Simple Machines and individual contributors
9
 * @license http://www.simplemachines.org/about/smf/license.php BSD
10
 *
11
 * @version 2.1 Beta 4
12
 */
13
14
/**
15
 * Interface search_api_interface
16
 */
17
interface search_api_interface
18
{
19
	/**
20
	 * Check whether the specific search operation can be performed by this API.
21
	 * The operations are the functions listed in the interface, if not supported
22
	 * they need not be declared
23
	 *
24
	 * @access public
25
	 * @param string $methodName The method
26
	 * @param array $query_params Any parameters for the query
27
	 * @return boolean Whether or not the specified method is supported
28
	 */
29
	public function supportsMethod($methodName, $query_params = array());
30
31
	/**
32
	 * Whether this method is valid for implementation or not
33
	 *
34
	 * @access public
35
	 * @return bool Whether or not this method is valid
36
	 */
37
	public function isValid();
38
39
	/**
40
	 * Callback function for usort used to sort the fulltext results.
41
	 * the order of sorting is: large words, small words, large words that
42
	 * are excluded from the search, small words that are excluded.
43
	 *
44
	 * @access public
45
	 * @param string $a Word A
46
	 * @param string $b Word B
47
	 * @return int An integer indicating how the words should be sorted
48
	 */
49
	public function searchSort($a, $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
50
51
	/**
52
	 * Callback while preparing indexes for searching
53
	 *
54
	 * @access public
55
	 * @param string $word A word to index
56
	 * @param array $wordsSearch Search words
57
	 * @param array $wordsExclude Words to exclude
58
	 * @param bool $isExcluded Whether the specfied word should be excluded
59
	 */
60
	public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
61
62
	/**
63
	 * Search for indexed words.
64
	 *
65
	 * @access public
66
	 * @param array $words An array of words
67
	 * @param array $search_data An array of search data
68
	 * @return mixed
69
	 */
70
	public function indexedWordQuery(array $words, array $search_data);
71
72
	/**
73
	 * Callback when a post is created
74
	 * @see createPost()
75
	 *
76
	 * @access public
77
	 * @param array $msgOptions An array of post data
78
	 * @param array $topicOptions An array of topic data
79
	 * @param array $posterOptions An array of info about the person who made this post
80
	 * @return void
81
	 */
82
	public function postCreated(array &$msgOptions, array &$topicOptions, array &$posterOptions);
83
84
	/**
85
	 * Callback when a post is modified
86
	 * @see modifyPost()
87
	 *
88
	 * @access public
89
	 * @param array $msgOptions An array of post data
90
	 * @param array $topicOptions An array of topic data
91
	 * @param array $posterOptions An array of info about the person who made this post
92
	 * @return void
93
	 */
94
	public function postModified(array &$msgOptions, array &$topicOptions, array &$posterOptions);
95
96
	/**
97
	 * Callback when a post is removed
98
	 *
99
	 * @access public
100
	 * @param int $id_msg The ID of the post that was removed
101
	 * @return void
102
	 */
103
	public function postRemoved($id_msg);
104
105
	/**
106
	 * Callback when a topic is removed
107
	 *
108
	 * @access public
109
	 * @param array $topics The ID(s) of the removed topic(s)
110
	 * @return void
111
	 */
112
	public function topicsRemoved(array $topics);
113
114
	/**
115
	 * Callback when a topic is moved
116
	 *
117
	 * @access public
118
	 * @param array $topics The ID(s) of the moved topic(s)
119
	 * @param int $board_to The board that the topics were moved to
120
	 * @return void
121
	 */
122
	public function topicsMoved(array $topics, $board_to);
123
124
	/**
125
	 * Callback for actually performing the search query
126
	 *
127
	 * @access public
128
	 * @param array $query_params An array of parameters for the query
129
	 * @param array $searchWords The words that were searched for
130
	 * @param array $excludedIndexWords Indexed words that should be excluded
131
	 * @param array $participants
132
	 * @param array $searchArray
133
	 * @return mixed
134
	 */
135
	public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray);
136
}
137
138
/**
139
 * Class search_api
140
 */
141
abstract class search_api implements search_api_interface
142
{
143
	/**
144
	 * @var string The last version of SMF that this was tested on. Helps protect against API changes.
145
	 */
146
	public $version_compatible = 'SMF 2.1 Beta 4';
147
148
	/**
149
	 * @var string The minimum SMF version that this will work with
150
	 */
151
	public $min_smf_version = 'SMF 2.1 Beta 4';
152
153
	/**
154
	 * @var bool Whether or not it's supported
155
	 */
156
	public $is_supported = true;
157
158
	/**
159
	 * {@inheritDoc}
160
	 */
161
	public function supportsMethod($methodName, $query_params = null)
162
	{
163
		switch ($methodName)
164
		{
165
			case 'postRemoved':
166
				return true;
167
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
168
169
			// All other methods, too bad dunno you.
170
			default:
171
				return false;
172
			break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
173
		}
174
	}
175
176
	/**
177
	 * {@inheritDoc}
178
	 */
179
	public function isValid()
180
	{
181
	}
182
183
	/**
184
	 * {@inheritDoc}
185
	 */
186
	public function searchSort($a, $b)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
187
	{
188
	}
189
190
	/**
191
	 * {@inheritDoc}
192
	 */
193
	public function prepareIndexes($word, array &$wordsSearch, array &$wordsExclude, $isExcluded)
194
	{
195
	}
196
197
	/**
198
	 * {@inheritDoc}
199
	 */
200
	public function indexedWordQuery(array $words, array $search_data)
201
	{
202
	}
203
204
	/**
205
	 * {@inheritDoc}
206
	 */
207
	public function postCreated(array &$msgOptions, array &$topicOptions, array &$posterOptions)
208
	{
209
	}
210
211
	/**
212
	 * {@inheritDoc}
213
	 */
214
	public function postModified(array &$msgOptions, array &$topicOptions, array &$posterOptions)
215
	{
216
	}
217
218
	/**
219
	 * {@inheritDoc}
220
	 */
221
	public function postRemoved($id_msg)
222
	{
223
224
		global $smcFunc;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
225
226
		$result = $smcFunc['db_query']('','
227
			SELECT DISTINCT id_search
228
			FROM {db_prefix}log_search_results
229
			WHERE id_msg = {int:id_msg}',
230
			array(
231
				'id_msg' => $id_msg,
232
			)
233
		);
234
235
		$id_searchs = array();
236
		while ($row = $smcFunc['db_fetch_assoc']($result))
237
			$id_searchs[] = $row['id_search'];
238
239
		if (count($id_searchs) < 1)
240
			return;
241
242
		$smcFunc['db_query']('','
243
			DELETE FROM {db_prefix}log_search_results
244
			WHERE id_search in ({array_int:id_searchs})',
245
			array(
246
				'id_searchs' => $id_searchs,
247
			)
248
		);
249
250
		$smcFunc['db_query']('','
251
			DELETE FROM {db_prefix}log_search_topics
252
			WHERE id_search in ({array_int:id_searchs})',
253
			array(
254
				'id_searchs' => $id_searchs,
255
			)
256
		);
257
258
		$smcFunc['db_query']('','
259
			DELETE FROM {db_prefix}log_search_messages
260
			WHERE id_search in ({array_int:id_searchs})',
261
			array(
262
				'id_searchs' => $id_searchs,
263
			)
264
		);
265
	}
266
267
	/**
268
	 * {@inheritDoc}
269
	 */
270
	public function topicsRemoved(array $topics)
271
	{
272
	}
273
274
	/**
275
	 * {@inheritDoc}
276
	 */
277
	public function topicsMoved(array $topics, $board_to)
278
	{
279
	}
280
281
	/**
282
	 * {@inheritDoc}
283
	 */
284
	public function searchQuery(array $query_params, array $searchWords, array $excludedIndexWords, array &$participants, array &$searchArray)
285
	{
286
	}
287
}
288
289
?>