From 21979ff11ceee0042642ac17147858a4155d54c5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 20 Jan 2016 23:34:33 +0100 Subject: Add exclusion in tag search * Searching '-mytag' will now exlude all shaares with 'mytag' tag. * All tags starting with a '-' are renamed without it (through the Updater). * Unit tests. Minor code changes: * LinkDB->filter() can now take no parameters (get all link depending on logged status). * tagsStrToArray() is now static and filters blank tags. --- application/Updater.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'application/Updater.php') diff --git a/application/Updater.php b/application/Updater.php index 20ae0c4d..773a1ffa 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -131,6 +131,21 @@ class Updater return true; } + + /** + * Rename tags starting with a '-' to work with tag exclusion search. + */ + public function updateMethodRenameDashTags() + { + $linklist = $this->linkDB->filter(); + foreach ($linklist as $link) { + $link['tags'] = preg_replace('/(^| )\-/', '$1', $link['tags']); + $link['tags'] = implode(' ', array_unique(LinkFilter::tagsStrToArray($link['tags'], true))); + $this->linkDB[$link['linkdate']] = $link; + } + $this->linkDB->savedb($this->config['config']['PAGECACHE']); + return true; + } } /** -- cgit v1.2.3