From b6173772bdef1eaf067573373ab500d67dfc454d Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 29 Jan 2020 01:23:24 +0100 Subject: new feature : better tag view clickable tags displayed in home interface --- app/class/Opt.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'app/class') diff --git a/app/class/Opt.php b/app/class/Opt.php index 803edce..cbbac02 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -7,7 +7,7 @@ class Opt protected $sortby = 'id'; protected $order = 1; protected $tagfilter = []; - protected $tagcompare = 'OR'; + protected $tagcompare = 'AND'; protected $authorfilter = []; protected $authorcompare = 'OR'; protected $secure = 4; @@ -37,6 +37,22 @@ class Opt } } + /** + * Return any asked vars and their values of an object as associative array + * + * @param array $vars list of vars + * @return array Associative array `$var => $value` + */ + public function drylist(array $vars) : array + { + $array = []; + foreach ($vars as $var) { + if (property_exists($this, $var)) + $array[$var] = $this->$var; + } + return $array; + } + public function resetall() { @@ -123,6 +139,37 @@ class Opt return $adress; } + /** + * Get the link list for each tags of an page + * + * @param array $taglist List of tag to be + * @return string html code to be printed + */ + public function tag(array $taglist = []) : string + { + $tagstring = ""; + foreach ($taglist as $tag ) { + $tagstring .= '' . $tag . '' . PHP_EOL; + } + return $tagstring; + } + + /** + * Generate http query based on a new tagfilter input + * + * @param string $tag The tag to be selected + * @return string Query string without `?` + */ + public function gettagadress(string $tag = "") : string + { + $object = $this->drylist(['sortby', 'order', 'secure', 'tagcompare', 'authorcompare', 'author', 'invert', 'limit']); + if(!empty($tag)) { + $object['tagfilter'][] = $tag; + } + $object['submit'] = 'filter'; + + return urldecode(http_build_query($object)); + } /** -- cgit v1.2.3