aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-08-17 00:02:21 +0200
committervincent-peugnet <v.peugnet@free.fr>2019-08-17 00:02:21 +0200
commit0d863868d69d9e2c9ae3f6f0b22b4d3a1be73ee2 (patch)
tree976e3466be56ab81969d9ea30604c35f58102c70 /app
parentb5ebee8dea28e3a9c5160de1c56f7715153f3af4 (diff)
downloadwcms-0d863868d69d9e2c9ae3f6f0b22b4d3a1be73ee2.tar.gz
wcms-0d863868d69d9e2c9ae3f6f0b22b4d3a1be73ee2.zip
Feature : list is going to work soon
Diffstat (limited to 'app')
-rw-r--r--app/class/art2.php6
-rw-r--r--app/class/controllerhome.php4
-rw-r--r--app/class/modelart.php5
-rw-r--r--app/class/modelhome.php16
-rw-r--r--app/class/modelrender.php45
-rw-r--r--app/class/optlist.php15
-rw-r--r--app/view/templates/home.php8
7 files changed, 81 insertions, 18 deletions
diff --git a/app/class/art2.php b/app/class/art2.php
index a43d35e..4561773 100644
--- a/app/class/art2.php
+++ b/app/class/art2.php
@@ -431,7 +431,11 @@ class Art2
public function authors($type = 'array')
{
- return $this->authors;
+ if($type == 'string') {
+ return implode(', ', $this->authors);
+ } elseif ($type == 'array') {
+ return $this->authors;
+ }
}
public function invites($type = 'array')
diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php
index c053270..166ada9 100644
--- a/app/class/controllerhome.php
+++ b/app/class/controllerhome.php
@@ -36,9 +36,7 @@ class Controllerhome extends Controller
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 = $this->modelhome->Optlistinit($table);
$this->optlist->hydrate($datas);
$vars['optlist'] = $this->optlist;
}
diff --git a/app/class/modelart.php b/app/class/modelart.php
index f5b4858..8462675 100644
--- a/app/class/modelart.php
+++ b/app/class/modelart.php
@@ -13,6 +13,11 @@ class Modelart extends Modeldb
$this->storeinit(Config::arttable());
}
+ /**
+ * Scan library for all pages as objects
+ *
+ * @return array of Pages objects
+ */
public function getlister()
{
$artlist = [];
diff --git a/app/class/modelhome.php b/app/class/modelhome.php
index 5b3b5a5..3347edf 100644
--- a/app/class/modelhome.php
+++ b/app/class/modelhome.php
@@ -19,6 +19,22 @@ class Modelhome extends Modelart
return $opt;
}
+ /**
+ * Initialise Optlist object using
+ *
+ * @param array $table the list of all pages objects
+ *
+ * @return Optlist Object initialized
+ */
+ public function Optlistinit(array $table)
+ {
+ $optlist = new Optlist(Art2::classvarlist());
+ $optlist->settaglist($table);
+ $optlist->setauthorlist($table);
+
+ return $optlist;
+ }
+
diff --git a/app/class/modelrender.php b/app/class/modelrender.php
index aa444f0..3d8f25f 100644
--- a/app/class/modelrender.php
+++ b/app/class/modelrender.php
@@ -143,6 +143,7 @@ class Modelrender extends Modelart
{
$content = $this->article($element->content());
$content = $this->automedialist($content);
+ $content = $this->pagelist($content);
$content = $this->autotaglistupdate($content);
$content = $this->date($content);
$content = $this->thumbnail($content);
@@ -583,6 +584,50 @@ class Modelrender extends Modelart
return $text;
}
+ /**
+ * Render pages list
+ */
+ public function pagelist(string $text) : string
+ {
+ preg_match_all('~\%LIST\?([a-zA-Z0-9\]\[\&=\-\/\%]*)\%~', $text, $out);
+
+ foreach ($out[0] as $key => $match) {
+ $matches[$key] = ['fullmatch' => $match, 'options' => $out[1][$key]];
+ }
+
+ $modelhome = new Modelhome();
+
+ if(isset($matches)) {
+ foreach ($matches as $match) {
+ $optlist = $modelhome->Optlistinit($this->artlist);
+ $optlist->parsehydrate($match['options']);
+ $table2 = $modelhome->table2($this->artlist, $optlist);
+
+ $content = '<ul>' . PHP_EOL ;
+ foreach ($table2 as $page ) {
+ $content .= '<li>' . PHP_EOL;
+ $content .= '<a href="' . $this->uart($page->id()) . '">' . $page->title() . '</a>' . PHP_EOL;
+ if($optlist->description()) {
+ $content .= '<em>' . $page->description() . '</em>' . PHP_EOL;
+ }
+ if($optlist->date()) {
+ $content .= '<code>' . $page->date('pdate') . '</code>' . PHP_EOL;
+ }
+ if($optlist->author()) {
+ $content .= $page->authors('string') . PHP_EOL;
+ }
+ $content .= '</li>';
+ }
+ $content .= '</ul>';
+
+ $text = str_replace($match['fullmatch'], $content, $text);
+ }
+ }
+ return $text;
+ }
+
+
+
diff --git a/app/class/optlist.php b/app/class/optlist.php
index cf68fa7..5190596 100644
--- a/app/class/optlist.php
+++ b/app/class/optlist.php
@@ -9,18 +9,13 @@ class Optlist extends Opt
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);
+ public function parsehydrate(string $encoded)
+ {
+ if(is_string($encoded)) {
+ parse_str($encoded, $datas);
+ $this->hydrate($datas);
}
- $this->hydrate($datas);
}
diff --git a/app/view/templates/home.php b/app/view/templates/home.php
index 922aaf0..c226a9d 100644
--- a/app/view/templates/home.php
+++ b/app/view/templates/home.php
@@ -26,9 +26,10 @@
<article id="main">
-<h2>Pages</h2>
+<h2>Pages (<?= count($table2) ?>)</h2>
-<details id="import">
+
+<details id="import" class="hidephone">
<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">
@@ -53,7 +54,7 @@
</form>
</details>
-<details id="list" <?= isset($optlist) ? 'open' : '' ?>>
+<details id="list" class="hidephone" <?= isset($optlist) ? 'open' : '' ?>>
<summary>Generate list</summary>
<i>Generate code to display a list of pages</i>
<form action="<?= $this->url('homequery') ?>" method="post">
@@ -111,7 +112,6 @@
- <input type="hidden" name="action" value="massedit">
</div>