diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Opt.php | 49 | ||||
-rw-r--r-- | app/view/templates/home.php | 2 |
2 files changed, 49 insertions, 2 deletions
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 .= '<a class="tag" href="?' . $this->gettagadress($tag) . '" >' . $tag . '</a>' . 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)); + } /** diff --git a/app/view/templates/home.php b/app/view/templates/home.php index ddf4e46..7aa3e69 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -94,7 +94,7 @@ <td class="hidephone"><a href="<?= $this->upage('pagedownload', $item->id()) ?>" download><img src="<?= Wcms\Model::iconpath() ?>download.png" class="icon"></a></td> <?php } if ($columns['tag']) { ?> - <td class="tag"><a title="<?= $item->tag('string') ?>"><?= $item->tag('sort') ?></a></td> + <td class="tag"><?= $opt->tag($item->tag('array')) ?></td> <?php } if ($columns['title']) { ?> <td class="title" title="<?= $item->title() ?>"><?= $item->title() ?></td> |