From c21bf0fba1ce24dcc3f844ad46e1592a7646ca50 Mon Sep 17 00:00:00 2001 From: Kevin Pouget Date: Fri, 26 Sep 2014 13:48:10 +0200 Subject: [PATCH] allow hidding tags with '@' symbol in their name --- daos/Items.php | 13 ++++++++++++- daos/Sources.php | 14 ++++++++++++++ daos/Tags.php | 16 +++++++++++++++- helpers/Authentication.php | 10 ++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/daos/Items.php b/daos/Items.php index d288d9e679..f6fe6ea5b6 100644 --- a/daos/Items.php +++ b/daos/Items.php @@ -80,6 +80,17 @@ public function get($options = array()) { $options ); - return $this->backend->get($options); + $items = $this->backend->get($options); + + if(!\F3::get('auth')->showHiddenTags()) { + foreach($items as $idx => $item) { + if (strpos($item['tags'], "@") !== false) { + unset($items[$idx]); + } + } + $items = array_values($items); + } + + return $items; } } diff --git a/daos/Sources.php b/daos/Sources.php index a5c153ba4b..e9438aa57c 100644 --- a/daos/Sources.php +++ b/daos/Sources.php @@ -47,6 +47,20 @@ public function __call($name, $args) { \F3::get('logger')->log('Unimplemented method for ' . \F3::get('db_type') . ': ' . $name, \ERROR); } + public function get() { + $sources = $this->backend->get(); + + if(!\F3::get('auth')->showHiddenTags()) { + foreach($sources as $idx => $source) { + if (strpos($source['tags'], "@") !== false) { + unset($sources[$idx]); + } + } + $sources = array_values($sources); + } + + return $sources; + } /** * validate new data for a given source diff --git a/daos/Tags.php b/daos/Tags.php index f0bfcfb78d..cae5eb4a6e 100644 --- a/daos/Tags.php +++ b/daos/Tags.php @@ -30,7 +30,21 @@ public function __construct() { $this->backend = new $class(); parent::__construct(); } - + + public function get() { + $tags = $this->backend->get(); + + if(!\F3::get('auth')->showHiddenTags()) { + foreach($tags as $idx => $tag) { + if (strpos($tag['tag'], "@") !== false) { + unset($tags[$idx]); + } + } + $tags = array_values($tags); + } + + return $tags; + } /** * pass any method call to the backend. diff --git a/helpers/Authentication.php b/helpers/Authentication.php index 699cf177dd..d553b325a2 100644 --- a/helpers/Authentication.php +++ b/helpers/Authentication.php @@ -129,6 +129,16 @@ public function isLoggedin() { return $this->loggedin; } + + /** + * showHiddenTags + * + * @return bool + */ + public function showHiddenTags() { + return $this->isLoggedin(); + } + /** * logout