From e32f2f1749c691f6c778261a8f8d300573895345 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 12 Feb 2020 19:44:00 +0100 Subject: Link to refactoring close #48 --- app/class/Controllerpage.php | 2 +- app/class/Model.php | 2 +- app/class/Modelanalyse.php | 73 ------------------------------------ app/class/Modelhome.php | 2 +- app/class/Modelpage.php | 4 +- app/class/Modelrender.php | 28 +++++++------- app/class/Opt.php | 38 +++++-------------- app/class/Page.php | 31 --------------- app/view/templates/confirmdelete.php | 13 ------- app/view/templates/home.php | 10 +---- 10 files changed, 31 insertions(+), 172 deletions(-) delete mode 100644 app/class/Modelanalyse.php (limited to 'app') 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 @@ -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 'internallinkblank .' >' . $matches[1] . ''; } else { - $linkfrom[] = $matchpage->id(); + $linkto[] = $matchpage->id(); return 'internallinkblank .' >' . $matchpage->title() . ''; } }, $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 '' . $secure . '' . PHP_EOL; } - public function linktolink(array $linkfromlist) + public function linktolink(array $linktolist) { - $linkfromstring = ""; - foreach ($linkfromlist as $linkfrom ) { - $linkfromstring .= '' . $linkfrom . '' . PHP_EOL; + $linktostring = ""; + foreach ($linktolist as $linkto ) { + $linktostring .= '' . $linkto . '' . 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)) { diff --git a/app/view/templates/confirmdelete.php b/app/view/templates/confirmdelete.php index 24de454..ae8639b 100644 --- a/app/view/templates/confirmdelete.php +++ b/app/view/templates/confirmdelete.php @@ -12,23 +12,10 @@ -linkto())) { ?> -

Article linked to :

- - - - diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 63a63e1..1d15a8d 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -74,10 +74,7 @@ summary - to - - from + linkto last modification @@ -129,10 +126,7 @@ description('short') ?> - linkto('sort') ?> - - linktolink($item->linkfrom('array')) ?> + linktolink($item->linkto('array')) ?> -- cgit v1.2.3