diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-08-16 15:23:42 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-08-16 15:23:42 +0200 |
commit | b5ebee8dea28e3a9c5160de1c56f7715153f3af4 (patch) | |
tree | b7729495fdfa58210612d8280058a7412c57e9ea | |
parent | 566b995bab45355d814ac5a8bfbf18e3a59c14ba (diff) | |
download | wcms-b5ebee8dea28e3a9c5160de1c56f7715153f3af4.tar.gz wcms-b5ebee8dea28e3a9c5160de1c56f7715153f3af4.zip |
Generate list code function working
-rw-r--r-- | app/class/art2.php | 6 | ||||
-rw-r--r-- | app/class/controllerhome.php | 19 | ||||
-rw-r--r-- | app/class/opt.php | 32 | ||||
-rw-r--r-- | app/class/optlist.php | 114 | ||||
-rw-r--r-- | app/class/routes.php | 1 | ||||
-rw-r--r-- | app/fn/fn.php | 19 | ||||
-rw-r--r-- | app/view/templates/editleftbar.php | 2 | ||||
-rw-r--r-- | app/view/templates/home.php | 39 |
8 files changed, 211 insertions, 21 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 56bc74e..a43d35e 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -296,7 +296,11 @@ class Art2 public function customhead($type = "string") { - return $this->customhead; + if($type === 'string') { + return $this->customhead; + } elseif($type === 'int') { + return substr_count($this->customhead, PHP_EOL) + 1; + } } public function footer($type = "string") diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php index 043ac3e..c053270 100644 --- a/app/class/controllerhome.php +++ b/app/class/controllerhome.php @@ -5,6 +5,8 @@ class Controllerhome extends Controller /** @var Modelhome */ protected $modelhome; protected $opt; + /** @var Optlist */ + protected $optlist; public function __construct($render) { parent::__construct($render); @@ -20,6 +22,8 @@ class Controllerhome extends Controller $this->routedirect('artread/', ['art' => Config::homeredirect()]); } else { + + $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); @@ -27,8 +31,19 @@ class Controllerhome extends Controller $table2 = $this->modelhome->table2($table, $this->opt); $columns = $this->modelhome->setcolumns($this->user->columns()); + + $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns]; + + if(isset($_POST['query']) && $this->user->iseditor()) { + $datas = array_merge($_POST, $_SESSION['opt']); + $this->optlist = new Optlist(Art2::classvarlist()); + $this->optlist->settaglist($table); + $this->optlist->setauthorlist($table); + $this->optlist->hydrate($datas); + $vars['optlist'] = $this->optlist; + } - $this->showtemplate('home', ['user' => $this->user, 'table2' => $table2, 'opt' =>$this->opt, 'columns' => $columns]); + $this->showtemplate('home', $vars); } @@ -37,7 +52,7 @@ class Controllerhome extends Controller public function columns() { if(isset($_POST['columns']) && $this->user->iseditor()) { - $user =$this->usermanager->get($this->user->id()); + $user = $this->usermanager->get($this->user->id()); $user->hydrate($_POST); $this->usermanager->add($user); $this->usermanager->writesession($user); diff --git a/app/class/opt.php b/app/class/opt.php index 9eddf9f..0761782 100644 --- a/app/class/opt.php +++ b/app/class/opt.php @@ -1,21 +1,21 @@ <?php class Opt { - private $sortby = 'id'; - private $order = 1; - private $tagfilter = []; - private $tagcompare = 'OR'; - private $authorfilter = []; - private $authorcompare = 'OR'; - private $secure = 4; - private $linkto = ['min' => '0', 'max' => '0']; - private $linkfrom = ['min' => '0', 'max' => '0']; - private $col = ['id']; - private $taglist = []; - private $authorlist = []; - private $invert = 0; - - private $artvarlist; + protected $sortby = 'id'; + protected $order = 1; + protected $tagfilter = []; + protected $tagcompare = 'OR'; + protected $authorfilter = []; + protected $authorcompare = 'OR'; + protected $secure = 4; + protected $linkto = ['min' => '0', 'max' => '0']; + protected $linkfrom = ['min' => '0', 'max' => '0']; + protected $col = ['id']; + protected $taglist = []; + protected $authorlist = []; + protected $invert = 0; + + protected $artvarlist; public function __construct(array $donnees = []) { @@ -202,7 +202,7 @@ class Opt public function setsortby($sortby) { - if (is_string($sortby) && in_array($sortby, $this->artvarlist())) { + if (is_string($sortby) && in_array($sortby, $this->artvarlist)) { $this->sortby = strtolower(strip_tags($sortby)); } } diff --git a/app/class/optlist.php b/app/class/optlist.php new file mode 100644 index 0000000..cf68fa7 --- /dev/null +++ b/app/class/optlist.php @@ -0,0 +1,114 @@ +<?php + +class Optlist extends Opt +{ + private $description = 0; + private $thumbnail = 0; + private $date = 0; + private $author = 0; + private $style = 0; + + + /** + * New constructor dedicated to parse input string + * + * @param string|array $parsedstring parsed query string + */ + public function __construct($datas = []) + { + if(is_string($datas)) { + $datas = parse_str($this->options, $datas); + + } + $this->hydrate($datas); + } + + + /** + * Get the query as http string + * + * @return string The resulted query + */ + public function getquery() : string + { + $class = get_class_vars(get_class($this)); + $object = get_object_vars($this); + $class['artvarlist'] = $object['artvarlist']; + $class['taglist'] = $object['taglist']; + $class['authorlist'] = $object['authorlist']; + $query = array_diff_assoc_recursive($object, $class); + + return urldecode(http_build_query($query)); + } + + /** + * Get the code to insert directly + */ + public function getcode() : string + { + return '%LIST?' . $this->getquery() . '%'; + } + + + + // _______________________________________ G E T _____________________________________ + + + public function description() + { + return $this->description; + } + + public function thumbnail() + { + return $this->thumbnail; + } + + public function date() + { + return $this->date; + } + + public function author() + { + return $this->author; + } + + public function style() + { + return $this->style; + } + + + + // _______________________________________ S E T _____________________________________ + + public function setdescription($description) + { + $this->description = intval($description); + } + + public function setthumbnail($thumbnail) + { + $this->thumbnail = intval($thumbnail); + } + + public function setdate($date) + { + $this->date = intval($date); + } + + public function setauthor($author) + { + $this->author = intval($author); + } + + public function setstyle($style) + { + $this->style = intval($style); + } +} + + + +?>
\ No newline at end of file diff --git a/app/class/routes.php b/app/class/routes.php index bad6e19..f960582 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -15,6 +15,7 @@ class Routes $router->addMatchTypes(array('cid' => '[a-zA-Z0-9-_+,\'!%@&.$€=\(\|\)]+')); $router->addRoutes([ ['GET', '/', 'Controllerhome#desktop', 'home'], + ['POST', '/', 'Controllerhome#desktop', 'homequery'], ['POST', '/columns', 'Controllerhome#columns', 'homecolumns'], ['POST', '/upload', 'Controllerart#upload', 'artupload'], ['POST', '/!co', 'Controllerconnect#log', 'log'], diff --git a/app/fn/fn.php b/app/fn/fn.php index 83391f3..faf5b81 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -193,6 +193,25 @@ function findsize($file) return $return; } +function array_diff_assoc_recursive($array1, $array2) { + $difference=array(); + foreach($array1 as $key => $value) { + if( is_array($value) ) { + if( !isset($array2[$key]) || !is_array($array2[$key]) ) { + $difference[$key] = $value; + } else { + $new_diff = array_diff_assoc_recursive($value, $array2[$key]); + if( !empty($new_diff) ) + $difference[$key] = $new_diff; + } + } else if( !array_key_exists($key,$array2) || $array2[$key] !== $value ) { + $difference[$key] = $value; + } + } + return $difference; +} + + diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index b8f4d4d..bd3fd15 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -174,7 +174,7 @@ ?> <label for="customhead">Custom head</label> - <textarea name="customhead" wrap="off" spellcheck="false"><?= $art->customhead() ?></textarea> + <textarea name="customhead" wrap="off" spellcheck="false" rows="<?= $art->customhead('int') ?>"><?= $art->customhead() ?></textarea> </fieldset> diff --git a/app/view/templates/home.php b/app/view/templates/home.php index e41c2cc..922aaf0 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -31,7 +31,7 @@ <details id="import"> <summary>Import W JSON page file</summary> <i>Upload page file as json</i> - <form action="<?=$this->url('artupload') ?>" method="post" enctype="multipart/form-data"> + <form action="<?= $this->url('artupload') ?>" method="post" enctype="multipart/form-data"> <input type="file" name="pagefile" id="pagefile" accept=".json"> <label for="pagefile">JSON Page file</label> <input type="hidden" name="erase" value="0"> @@ -53,6 +53,43 @@ </form> </details> +<details id="list" <?= isset($optlist) ? 'open' : '' ?>> + <summary>Generate list</summary> + <i>Generate code to display a list of pages</i> + <form action="<?= $this->url('homequery') ?>" method="post"> + <input type="hidden" name="query" value="1"> + + <input type="hidden" name="description" value="0"> + <input type="checkbox" name="description" id="list_description" value="1" <?= isset($optlist) && $optlist->description() ? 'checked' : '' ?>> + <label for="list_description">Show description</label> + </br> + <input type="hidden" name="thumbnail" value="0"> + <input type="checkbox" name="thumbnail" id="list_thumbnail" value="1" <?= isset($optlist) && $optlist->thumbnail() ? 'checked' : '' ?>> + <label for="list_thumbnail">Show thumbnail</label> + </br> + <input type="hidden" name="date" value="0"> + <input type="checkbox" name="date" id="list_date" value="1" <?= isset($optlist) && $optlist->date() ? 'checked' : '' ?>> + <label for="list_date">Show date</label> + </br> + <input type="hidden" name="author" value="0"> + <input type="checkbox" name="author" id="list_author" value="1" <?= isset($optlist) && $optlist->author() ? 'checked' : '' ?>> + <label for="list_author">Show author(s)</label> + </br> + <select name="style" id="list_style"> + <option value="0">list</option> + <option value="1" <?= isset($optlist) && $optlist->style() == 1 ? 'selected' : '' ?>>div</option> + </select> + <input type="submit" value="generate"> + </form> + + <?php + if(isset($optlist)) { + echo '<code>' . $optlist->getcode() . '</code>'; + } + + ?> +</details> + <form action="/massedit" method="post"> |