aboutsummaryrefslogtreecommitdiff
path: root/app/class/Opt.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-01-29 01:23:24 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-01-29 01:23:24 +0100
commitb6173772bdef1eaf067573373ab500d67dfc454d (patch)
tree9ac42ba1d423bbf99edfec45910ebfd54fd67095 /app/class/Opt.php
parenta66df8c97f4aa70977b25478fc3b6413ebd9b9db (diff)
downloadwcms-b6173772bdef1eaf067573373ab500d67dfc454d.tar.gz
wcms-b6173772bdef1eaf067573373ab500d67dfc454d.zip
new feature : better tag view
clickable tags displayed in home interface
Diffstat (limited to 'app/class/Opt.php')
-rw-r--r--app/class/Opt.php49
1 files changed, 48 insertions, 1 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));
+ }
/**