aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-02-12 19:44:00 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-02-12 19:44:00 +0100
commite32f2f1749c691f6c778261a8f8d300573895345 (patch)
tree84a4293c7f0781243259d21f2472273c0f52fada /app/class
parent0937c851313b5098dc15e5d411b6c3638cbd5116 (diff)
downloadwcms-e32f2f1749c691f6c778261a8f8d300573895345.tar.gz
wcms-e32f2f1749c691f6c778261a8f8d300573895345.zip
Link to refactoring close #48
Diffstat (limited to 'app/class')
-rw-r--r--app/class/Controllerpage.php2
-rw-r--r--app/class/Model.php2
-rw-r--r--app/class/Modelanalyse.php73
-rw-r--r--app/class/Modelhome.php2
-rw-r--r--app/class/Modelpage.php4
-rw-r--r--app/class/Modelrender.php28
-rw-r--r--app/class/Opt.php38
-rw-r--r--app/class/Page.php31
8 files changed, 29 insertions, 151 deletions
diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php
index d646184..881f1d3 100644
--- a/app/class/Controllerpage.php
+++ b/app/class/Controllerpage.php
@@ -107,7 +107,7 @@ class Controllerpage extends Controller
$renderengine->render($page);
$page->setdaterender($now);
- $page->setlinkfrom($renderengine->linkfrom());
+ $page->setlinkto($renderengine->linkto());
return $page;
diff --git a/app/class/Model.php b/app/class/Model.php
index 67f50c9..5847f74 100644
--- a/app/class/Model.php
+++ b/app/class/Model.php
@@ -59,7 +59,7 @@ abstract class Model
'' => 'other'
];
- const COLUMNS = ['id', 'favicon', 'title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'authors', 'linkfrom', 'linkto', 'visitcount', 'affcount', 'editcount'];
+ const COLUMNS = ['id', 'favicon', 'title', 'description', 'tag', 'date', 'datemodif', 'datecreation', 'secure', 'authors', 'linkto', 'visitcount', 'affcount', 'editcount'];
const TEXT_ELEMENTS = ['header', 'nav', 'main', 'aside', 'footer'];
diff --git a/app/class/Modelanalyse.php b/app/class/Modelanalyse.php
deleted file mode 100644
index 9f656f5..0000000
--- a/app/class/Modelanalyse.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-namespace Wcms;
-
-class Modelanalyse extends Modelpage
-{
-
-
- public function __construct() {
- parent::__construct();
- }
-
- public function analyseall()
- {
- $pagelist = $this->getlister();
-
- $pagelist2 = [];
- foreach ($pagelist as $page) {
- $page->setlinkfrom($this->analyselinkfrom($page));
- $pagelist2[] = $page;
- }
- foreach ($pagelist2 as $page) {
- $page->setlinkto($this->analyselinkto($page->id(), $pagelist));
- $this->update($page);
- }
- }
-
-
- public function analyse(Page $page)
- {
- $page->setlinkfrom($this->analyselinkfrom($page));
-
- $pagelist = $this->getlister();
- $page->setlinkto($this->analyselinkto($page->id(), $pagelist));
-
- return $page;
- }
-
-
-
-
- public function analyselinkto($id, $pagelist)
- {
- //analyse les liens vers cet pageicle en fouillant tout les linkfrom de la bdd, génere un tableau à stocker dans l'pageicle
- $linkto = [];
- foreach ($pagelist as $link) {
- if (in_array($id, $link->linkfrom('array')) && $id != $link->id()) {
- $linkto[] = $link->id();
- }
- }
- return $linkto;
- }
-
- public function analyselinkfrom(Page $page)
- {
- $linkfrom = [];
- foreach (self::TEXT_ELEMENTS as $element) {
- preg_match_all('#\]\((\?id=|=)(\w+)\)#', $page->$element(), $out);
- $linkfrom = array_merge($linkfrom, $out[2]);
- }
- return array_unique($linkfrom);
-
- }
-
-}
-
-
-
-
-
-
-
-?> \ No newline at end of file
diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php
index 9d9703d..6352282 100644
--- a/app/class/Modelhome.php
+++ b/app/class/Modelhome.php
@@ -13,7 +13,7 @@ class Modelhome extends Modelpage
{
$opt = new Opt(Page::classvarlist());
- $opt->setcol(['id', 'tag', 'linkfrom', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'authors', 'visitcount', 'editcount', 'affcount']);
+ $opt->setcol(['id', 'tag', 'linkto', 'description', 'title', 'datemodif', 'datecreation', 'date', 'secure', 'authors', 'visitcount', 'editcount', 'affcount']);
$opt->settaglist($table);
$opt->setauthorlist($table);
$opt->setpageidlist($table);
diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php
index b39b5db..9344089 100644
--- a/app/class/Modelpage.php
+++ b/app/class/Modelpage.php
@@ -10,7 +10,7 @@ use DateTimeImmutable;
class Modelpage extends Modeldb
{
- const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'main', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkfrom', 'linkto', 'template', 'affcount', 'editcount'];
+ const SELECT = ['title', 'id', 'description', 'tag', 'date', 'datecreation', 'datemodif', 'daterender', 'css', 'quickcss', 'javascript', 'body', 'header', 'main', 'nav', 'aside', 'footer', 'render', 'secure', 'invitepassword', 'interface', 'linkto', 'template', 'affcount', 'editcount'];
const BY = ['datecreation', 'title', 'id', 'description', 'datemodif', 'secure'];
const ORDER = ['DESC', 'ASC'];
@@ -311,7 +311,7 @@ class Modelpage extends Modeldb
{
$filteredlist = [];
foreach ($pagelist as $page) {
- if (in_array( $linkto, $page->linkfrom('array'))) {
+ if (in_array( $linkto, $page->linkto('array'))) {
$filteredlist[] = $page->id();
} elseif (empty($linkto)) {
$filteredlist[] = $page->id();
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index c8aa13d..2338eb4 100644
--- a/app/class/Modelrender.php
+++ b/app/class/Modelrender.php
@@ -12,7 +12,7 @@ class Modelrender extends Modelpage
protected $page;
/** @var array list of ID as strings */
protected $pagelist;
- protected $linkfrom = [];
+ protected $linkto = [];
protected $sum = [];
protected $internallinkblank = '';
protected $externallinkblank = '';
@@ -374,44 +374,44 @@ class Modelrender extends Modelpage
public function wurl(string $text)
{
- $linkfrom = [];
+ $linkto = [];
$rend = $this;
$text = preg_replace_callback(
'%href="([\w-]+)\/?(#?[a-z-_]*)"%',
- function ($matches) use ($rend, &$linkfrom) {
+ function ($matches) use ($rend, &$linkto) {
$matchpage = $rend->get($matches[1]);
if (!$matchpage) {
$link = 'href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot"' . $this->internallinkblank;
} else {
- $linkfrom[] = $matchpage->id();
+ $linkto[] = $matchpage->id();
$link = 'href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'"' . $this->internallinkblank;
}
return $link;
},
$text
);
- $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom));
+ $this->linkto = array_unique(array_merge($this->linkto, $linkto));
return $text;
}
public function wikiurl(string $text)
{
- $linkfrom = [];
+ $linkto = [];
$rend = $this;
$text = preg_replace_callback(
'%\[([\w-]+)\/?#?([a-z-_]*)\]%',
- function ($matches) use ($rend, &$linkfrom) {
+ function ($matches) use ($rend, &$linkto) {
$matchpage = $rend->get($matches[1]);
if (!$matchpage) {
return '<a href="' . $rend->upage($matches[1]) . '"" title="' . Config::existnot() . '" class="internal existnot" '. $this->internallinkblank .' >' . $matches[1] . '</a>';
} else {
- $linkfrom[] = $matchpage->id();
+ $linkto[] = $matchpage->id();
return '<a href="' . $rend->upage($matches[1]) . $matches[2] . '" title="' . $matchpage->description() . '" class="internal exist '. $matchpage->secure('string') .'" '. $this->internallinkblank .' >' . $matchpage->title() . '</a>';
}
},
$text
);
- $this->linkfrom = array_unique(array_merge($this->linkfrom, $linkfrom));
+ $this->linkto = array_unique(array_merge($this->linkto, $linkto));
return $text;
}
@@ -675,12 +675,12 @@ class Modelrender extends Modelpage
- public function linkfrom()
+ public function linkto()
{
- sort($this->linkfrom);
- $linkfrom = $this->linkfrom;
- $this->linkfrom = [];
- return $linkfrom;
+ sort($this->linkto);
+ $linkto = $this->linkto;
+ $this->linkto = [];
+ return $linkto;
}
diff --git a/app/class/Opt.php b/app/class/Opt.php
index e0a8492..5f00141 100644
--- a/app/class/Opt.php
+++ b/app/class/Opt.php
@@ -141,19 +141,19 @@ class Opt extends Item
return '<a class="secure ' . $secure . '" href="?' . $this->getfilteradress(['secure' => $level]) . '">' . $secure . '</a>' . PHP_EOL;
}
- public function linktolink(array $linkfromlist)
+ public function linktolink(array $linktolist)
{
- $linkfromstring = "";
- foreach ($linkfromlist as $linkfrom ) {
- $linkfromstring .= '<a class="linkfrom" href="?' . $this->getfilteradress(['linkto' => $linkfrom]) . '" >' . $linkfrom . '</a>' . PHP_EOL;
+ $linktostring = "";
+ foreach ($linktolist as $linkto ) {
+ $linktostring .= '<a class="linkto" href="?' . $this->getfilteradress(['linkto' => $linkto]) . '" >' . $linkto . '</a>' . PHP_EOL;
}
- return $linkfromstring;
+ return $linktostring;
}
public function getfilteradress(array $vars = [])
{
- $varlist = ['sortby', 'order', 'secure', 'tagfilter', 'tagcompare', 'authorfilter', 'authorcompare', 'invert', 'limit'];
+ $varlist = ['sortby', 'order', 'secure', 'tagfilter', 'tagcompare', 'authorfilter', 'authorcompare', 'linkto', 'invert', 'limit'];
// array_filter($vars, function ())
$object = $this->drylist($varlist);
$object = array_merge($object, $vars);
@@ -352,8 +352,10 @@ class Opt extends Item
public function setlinkto($linkto) : bool
{
if (is_string($linkto)) {
- if (in_array($linkto, $this->pageidlist)) {
-
+ if(empty($this->pageidlist)) {
+ $this->linkto = idclean($linkto);
+ return true;
+ } elseif (in_array($linkto, $this->pageidlist)) {
$this->linkto = idclean($linkto);
return true;
} else {
@@ -364,26 +366,6 @@ class Opt extends Item
}
}
- public function setlinktomin($min)
- {
- $this->linkto['min'] = intval($min);
- }
-
- public function setlinktomax($max)
- {
- $this->linkto['max'] = intval($max);
- }
-
- public function setlinkfrommin($min)
- {
- $this->linkfrom['min'] = intval($min);
- }
-
- public function setlinkfrommax($max)
- {
- $this->linkfrom['max'] = intval($max);
- }
-
public function setcol($col)
{
if (is_array($col)) {
diff --git a/app/class/Page.php b/app/class/Page.php
index c57ecc4..d5b43b5 100644
--- a/app/class/Page.php
+++ b/app/class/Page.php
@@ -28,7 +28,6 @@ class Page extends Dbitem
protected $customhead;
protected $secure;
protected $interface;
- protected $linkfrom;
protected $linkto;
protected $templatebody;
protected $templatecss;
@@ -89,7 +88,6 @@ class Page extends Dbitem
$this->setcustomhead('');
$this->setsecure(Config::defaultprivacy());
$this->setinterface('main');
- $this->setlinkfrom([]);
$this->setlinkto([]);
$this->settemplatebody('');
$this->settemplatecss('');
@@ -257,21 +255,6 @@ class Page extends Dbitem
return $this->interface;
}
- public function linkfrom($option = 'array')
- {
- if ($option == 'json') {
- $linkfrom = json_encode($this->linkfrom);
- } elseif ($option == 'array') {
- $linkfrom = $this->linkfrom;
- } elseif ($option == 'sort') {
- return count($this->linkfrom);
- } elseif ($option == 'string') {
- return implode(', ', $this->linkfrom);
- }
- return $linkfrom;
-
- }
-
public function linkto($option = 'array')
{
if ($option == 'json') {
@@ -597,20 +580,6 @@ class Page extends Dbitem
}
}
- public function setlinkfrom($linkfrom)
- {
- if (is_array($linkfrom)) {
- $this->linkfrom = $linkfrom;
- } elseif (is_string($linkfrom)) {
- $linkfromjson = json_decode($linkfrom);
- if (is_array($linkfromjson)) {
- $this->linkfrom = $linkfromjson;
- }
- } elseif ($linkfrom === null) {
- $this->linkfrom = [];
- }
- }
-
public function setlinkto($linkto)
{
if (is_array($linkto)) {