diff options
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r-- | application/LinkDB.php | 76 |
1 files changed, 48 insertions, 28 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 0d3c85bd..9308164a 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -417,49 +417,36 @@ You use the community supported version of the original Shaarli project, by Seba | |||
417 | * - searchterm: term search | 417 | * - searchterm: term search |
418 | * @param bool $casesensitive Optional: Perform case sensitive filter | 418 | * @param bool $casesensitive Optional: Perform case sensitive filter |
419 | * @param string $visibility return only all/private/public links | 419 | * @param string $visibility return only all/private/public links |
420 | * @param string $untaggedonly return only untagged links | ||
420 | * | 421 | * |
421 | * @return array filtered links, all links if no suitable filter was provided. | 422 | * @return array filtered links, all links if no suitable filter was provided. |
422 | */ | 423 | */ |
423 | public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all') | 424 | public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all', $untaggedonly = false) |
424 | { | 425 | { |
425 | // Filter link database according to parameters. | 426 | // Filter link database according to parameters. |
426 | $searchtags = !empty($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; | 427 | $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; |
427 | $searchterm = !empty($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; | 428 | $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; |
428 | 429 | ||
429 | // Search tags + fullsearch. | 430 | // Search tags + fullsearch - blank string parameter will return all links. |
430 | if (! empty($searchtags) && ! empty($searchterm)) { | 431 | $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; // == "vuotext" |
431 | $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; | 432 | $request = [$searchtags, $searchterm]; |
432 | $request = array($searchtags, $searchterm); | ||
433 | } | ||
434 | // Search by tags. | ||
435 | elseif (! empty($searchtags)) { | ||
436 | $type = LinkFilter::$FILTER_TAG; | ||
437 | $request = $searchtags; | ||
438 | } | ||
439 | // Fulltext search. | ||
440 | elseif (! empty($searchterm)) { | ||
441 | $type = LinkFilter::$FILTER_TEXT; | ||
442 | $request = $searchterm; | ||
443 | } | ||
444 | // Otherwise, display without filtering. | ||
445 | else { | ||
446 | $type = ''; | ||
447 | $request = ''; | ||
448 | } | ||
449 | 433 | ||
450 | $linkFilter = new LinkFilter($this); | 434 | $linkFilter = new LinkFilter($this); |
451 | return $linkFilter->filter($type, $request, $casesensitive, $visibility); | 435 | return $linkFilter->filter($type, $request, $casesensitive, $visibility, $untaggedonly); |
452 | } | 436 | } |
453 | 437 | ||
454 | /** | 438 | /** |
455 | * Returns the list of all tags | 439 | * Returns the list tags appearing in the links with the given tags |
456 | * Output: associative array key=tags, value=0 | 440 | * @param $filteringTags: tags selecting the links to consider |
441 | * @param $visibility: process only all/private/public links | ||
442 | * @return: a tag=>linksCount array | ||
457 | */ | 443 | */ |
458 | public function allTags() | 444 | public function linksCountPerTag($filteringTags = [], $visibility = 'all') |
459 | { | 445 | { |
446 | $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility); | ||
460 | $tags = array(); | 447 | $tags = array(); |
461 | $caseMapping = array(); | 448 | $caseMapping = array(); |
462 | foreach ($this->links as $link) { | 449 | foreach ($links as $link) { |
463 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { | 450 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { |
464 | if (empty($tag)) { | 451 | if (empty($tag)) { |
465 | continue; | 452 | continue; |
@@ -478,6 +465,39 @@ You use the community supported version of the original Shaarli project, by Seba | |||
478 | } | 465 | } |
479 | 466 | ||
480 | /** | 467 | /** |
468 | * Rename or delete a tag across all links. | ||
469 | * | ||
470 | * @param string $from Tag to rename | ||
471 | * @param string $to New tag. If none is provided, the from tag will be deleted | ||
472 | * | ||
473 | * @return array|bool List of altered links or false on error | ||
474 | */ | ||
475 | public function renameTag($from, $to) | ||
476 | { | ||
477 | if (empty($from)) { | ||
478 | return false; | ||
479 | } | ||
480 | $delete = empty($to); | ||
481 | // True for case-sensitive tag search. | ||
482 | $linksToAlter = $this->filterSearch(['searchtags' => $from], true); | ||
483 | foreach($linksToAlter as $key => &$value) | ||
484 | { | ||
485 | $tags = preg_split('/\s+/', trim($value['tags'])); | ||
486 | if (($pos = array_search($from, $tags)) !== false) { | ||
487 | if ($delete) { | ||
488 | unset($tags[$pos]); // Remove tag. | ||
489 | } else { | ||
490 | $tags[$pos] = trim($to); | ||
491 | } | ||
492 | $value['tags'] = trim(implode(' ', array_unique($tags))); | ||
493 | $this[$value['id']] = $value; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | return $linksToAlter; | ||
498 | } | ||
499 | |||
500 | /** | ||
481 | * Returns the list of days containing articles (oldest first) | 501 | * Returns the list of days containing articles (oldest first) |
482 | * Output: An array containing days (in format YYYYMMDD). | 502 | * Output: An array containing days (in format YYYYMMDD). |
483 | */ | 503 | */ |