diff options
Diffstat (limited to 'application/LinkFilter.php')
-rw-r--r-- | application/LinkFilter.php | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/application/LinkFilter.php b/application/LinkFilter.php index e52239b8..8f147974 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php | |||
@@ -62,7 +62,7 @@ class LinkFilter | |||
62 | $visibility = 'all'; | 62 | $visibility = 'all'; |
63 | } | 63 | } |
64 | 64 | ||
65 | switch($type) { | 65 | switch ($type) { |
66 | case self::$FILTER_HASH: | 66 | case self::$FILTER_HASH: |
67 | return $this->filterSmallHash($request); | 67 | return $this->filterSmallHash($request); |
68 | case self::$FILTER_TAG | self::$FILTER_TEXT: // == "vuotext" | 68 | case self::$FILTER_TAG | self::$FILTER_TEXT: // == "vuotext" |
@@ -205,7 +205,6 @@ class LinkFilter | |||
205 | 205 | ||
206 | // Iterate over every stored link. | 206 | // Iterate over every stored link. |
207 | foreach ($this->links as $id => $link) { | 207 | foreach ($this->links as $id => $link) { |
208 | |||
209 | // ignore non private links when 'privatonly' is on. | 208 | // ignore non private links when 'privatonly' is on. |
210 | if ($visibility !== 'all') { | 209 | if ($visibility !== 'all') { |
211 | if (! $link['private'] && $visibility === 'private') { | 210 | if (! $link['private'] && $visibility === 'private') { |
@@ -257,11 +256,11 @@ class LinkFilter | |||
257 | private static function tag2regex($tag) | 256 | private static function tag2regex($tag) |
258 | { | 257 | { |
259 | $len = strlen($tag); | 258 | $len = strlen($tag); |
260 | if(!$len || $tag === "-" || $tag === "*"){ | 259 | if (!$len || $tag === "-" || $tag === "*") { |
261 | // nothing to search, return empty regex | 260 | // nothing to search, return empty regex |
262 | return ''; | 261 | return ''; |
263 | } | 262 | } |
264 | if($tag[0] === "-") { | 263 | if ($tag[0] === "-") { |
265 | // query is negated | 264 | // query is negated |
266 | $i = 1; // use offset to start after '-' character | 265 | $i = 1; // use offset to start after '-' character |
267 | $regex = '(?!'; // create negative lookahead | 266 | $regex = '(?!'; // create negative lookahead |
@@ -271,14 +270,14 @@ class LinkFilter | |||
271 | } | 270 | } |
272 | $regex .= '.*(?:^| )'; // before tag may only be a space or the beginning | 271 | $regex .= '.*(?:^| )'; // before tag may only be a space or the beginning |
273 | // iterate over string, separating it into placeholder and content | 272 | // iterate over string, separating it into placeholder and content |
274 | for(; $i < $len; $i++){ | 273 | for (; $i < $len; $i++) { |
275 | if($tag[$i] === '*'){ | 274 | if ($tag[$i] === '*') { |
276 | // placeholder found | 275 | // placeholder found |
277 | $regex .= '[^ ]*?'; | 276 | $regex .= '[^ ]*?'; |
278 | } else { | 277 | } else { |
279 | // regular characters | 278 | // regular characters |
280 | $offset = strpos($tag, '*', $i); | 279 | $offset = strpos($tag, '*', $i); |
281 | if($offset === false){ | 280 | if ($offset === false) { |
282 | // no placeholder found, set offset to end of string | 281 | // no placeholder found, set offset to end of string |
283 | $offset = $len; | 282 | $offset = $len; |
284 | } | 283 | } |
@@ -310,19 +309,19 @@ class LinkFilter | |||
310 | { | 309 | { |
311 | // get single tags (we may get passed an array, even though the docs say different) | 310 | // get single tags (we may get passed an array, even though the docs say different) |
312 | $inputTags = $tags; | 311 | $inputTags = $tags; |
313 | if(!is_array($tags)) { | 312 | if (!is_array($tags)) { |
314 | // we got an input string, split tags | 313 | // we got an input string, split tags |
315 | $inputTags = preg_split('/(?:\s+)|,/', $inputTags, -1, PREG_SPLIT_NO_EMPTY); | 314 | $inputTags = preg_split('/(?:\s+)|,/', $inputTags, -1, PREG_SPLIT_NO_EMPTY); |
316 | } | 315 | } |
317 | 316 | ||
318 | if(!count($inputTags)){ | 317 | if (!count($inputTags)) { |
319 | // no input tags | 318 | // no input tags |
320 | return $this->noFilter($visibility); | 319 | return $this->noFilter($visibility); |
321 | } | 320 | } |
322 | 321 | ||
323 | // build regex from all tags | 322 | // build regex from all tags |
324 | $re = '/^' . implode(array_map("self::tag2regex", $inputTags)) . '.*$/'; | 323 | $re = '/^' . implode(array_map("self::tag2regex", $inputTags)) . '.*$/'; |
325 | if(!$casesensitive) { | 324 | if (!$casesensitive) { |
326 | // make regex case insensitive | 325 | // make regex case insensitive |
327 | $re .= 'i'; | 326 | $re .= 'i'; |
328 | } | 327 | } |
@@ -342,7 +341,7 @@ class LinkFilter | |||
342 | } | 341 | } |
343 | } | 342 | } |
344 | $search = $link['tags']; // build search string, start with tags of current link | 343 | $search = $link['tags']; // build search string, start with tags of current link |
345 | if(strlen(trim($link['description'])) && strpos($link['description'], '#') !== false){ | 344 | if (strlen(trim($link['description'])) && strpos($link['description'], '#') !== false) { |
346 | // description given and at least one possible tag found | 345 | // description given and at least one possible tag found |
347 | $descTags = array(); | 346 | $descTags = array(); |
348 | // find all tags in the form of #tag in the description | 347 | // find all tags in the form of #tag in the description |
@@ -351,13 +350,13 @@ class LinkFilter | |||
351 | $link['description'], | 350 | $link['description'], |
352 | $descTags | 351 | $descTags |
353 | ); | 352 | ); |
354 | if(count($descTags[1])){ | 353 | if (count($descTags[1])) { |
355 | // there were some tags in the description, add them to the search string | 354 | // there were some tags in the description, add them to the search string |
356 | $search .= ' ' . implode(' ', $descTags[1]); | 355 | $search .= ' ' . implode(' ', $descTags[1]); |
357 | } | 356 | } |
358 | }; | 357 | }; |
359 | // match regular expression with search string | 358 | // match regular expression with search string |
360 | if(!preg_match($re, $search)){ | 359 | if (!preg_match($re, $search)) { |
361 | // this entry does _not_ match our regex | 360 | // this entry does _not_ match our regex |
362 | continue; | 361 | continue; |
363 | } | 362 | } |