diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-11-02 02:03:52 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-11-02 02:03:52 +0100 |
commit | 85824de70ded75c98bd50220160e2171fdc8df41 (patch) | |
tree | 11480f65ff97ddbb3ea4806ff1f313628ced15a0 /w/class | |
parent | 36ef34af2abcdea63a73b578208f20ca40b52f49 (diff) | |
download | wcms-85824de70ded75c98bd50220160e2171fdc8df41.tar.gz wcms-85824de70ded75c98bd50220160e2171fdc8df41.zip |
render working and url auto link
Diffstat (limited to 'w/class')
-rw-r--r-- | w/class/art.php | 506 | ||||
-rw-r--r-- | w/class/art2.php | 129 | ||||
-rw-r--r-- | w/class/controllerart.php | 50 | ||||
-rw-r--r-- | w/class/controllerconnect.php | 18 | ||||
-rw-r--r-- | w/class/controllerdb.php | 23 | ||||
-rw-r--r-- | w/class/controllerhome.php | 6 | ||||
-rw-r--r-- | w/class/model.php | 2 | ||||
-rw-r--r-- | w/class/modelanalyse.php | 4 | ||||
-rw-r--r-- | w/class/modelart.php | 23 | ||||
-rw-r--r-- | w/class/modeldb.php | 25 | ||||
-rw-r--r-- | w/class/modelrender.php | 173 | ||||
-rw-r--r-- | w/class/router.php | 1 |
12 files changed, 193 insertions, 767 deletions
diff --git a/w/class/art.php b/w/class/art.php deleted file mode 100644 index a4c93eb..0000000 --- a/w/class/art.php +++ /dev/null @@ -1,506 +0,0 @@ -<?php - -use Michelf\MarkdownExtra; - - -class Art -{ - private $id; - private $titre; - private $soustitre; - private $intro; - private $tag; - private $datecreation; - private $datemodif; - private $css; - private $html; - private $secure; - private $couleurtext; - private $couleurbkg; - private $couleurlien; - private $couleurlienblank; - private $lien; - private $liento; - private $template; - - const LEN = 255; - const LENHTML = 20000; - const SECUREMAX = 2; - const LENCOULEUR = 7; - const DEBUT = '(?id='; - const FIN = ')'; - - - - -// _____________________________________________________ F U N ____________________________________________________ - - public function __construct(array $donnees) - { - $this->hydrate($donnees); - } - - public function hydrate(array $donnees) - { - foreach ($donnees as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function reset() - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $this->settitre($this->id()); - $this->setsoustitre(''); - $this->setintro(''); - $this->settag(''); - $this->setdatecreation($now); - $this->setcss(''); - $this->sethtml(''); - $this->setsecure(2); - $this->setcouleurtext('#000000'); - $this->setcouleurbkg('#FFFFFF'); - $this->setcouleurlien('#000000'); - $this->setcouleurlienblank('#000000'); - $this->setlien(''); - $this->settemplate(''); - } - - public function updatelien() - { - $this->lien = []; - $this->lien = array_unique(search($this->md(true), self::DEBUT, self::FIN)); - - } - - public static function classvarlist() - { - $classvarlist = []; - foreach (get_class_vars(__class__) as $var => $default) { - $classvarlist[] = $var; - } - return ['artvarlist' => $classvarlist]; - } - - - - - public function calcliento($getlist) - { - $liento = []; - foreach ($getlist as $lien) { - if (in_array($this->id(), $lien->lien('array'))) { - $liento[] = $lien->id(); - } - } - $this->setliento($liento); - } - - - public function autotaglist() - { - $pattern = "/%%(\w*)%%/"; - preg_match_all($pattern, $this->md(), $out); - return $out[1]; - - } - - public function autotaglistupdate($taglist) - { - foreach ($taglist as $tag => $artlist) { - $replace = '<ul>'; - foreach ($artlist as $art) { - $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->intro() . '">' . $art->titre() . '</a></li>'; - } - $replace .= '</ul>'; - $this->html = str_replace('%%' . $tag . '%%', $replace, $this->html); - } - } - - public function autotaglistcalc($taglist) - { - foreach ($taglist as $tag => $artlist) { - foreach ($artlist as $art) { - if(!in_array($art->id(), $this->lien('array')) && $art->id() != $this->id()) { - $this->lien[] = $art->id(); - } - } - } - } - - public function templaterender() - { - - } - - - // _____________________________________________________ G E T ____________________________________________________ - - public function id($type = 'string') - { - return $this->id; - } - - public function titre($type = 'string') - { - return $this->titre; - } - - public function soustitre($type = 'string') - { - return $this->soustitre; - } - - public function intro($type = 'string') - { - return $this->intro; - } - - public function tag($option) - { - if ($option == 'string') { - return implode(", ", $this->tag); - } elseif ($option == 'array') { - return $this->tag; - } elseif ($option == 'sort') { - return count($this->tag); - } - } - - public function datecreation($option) - { - if ($option == 'string') { - return $this->datecreation->format('Y-m-d H:i:s'); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datecreation; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datecreation->diff($now)); - } - } - - - public function datemodif($option) - { - if ($option == 'string') { - return $this->datemodif->format('Y-m-d H:i:s'); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datemodif; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datemodif->diff($now)); - } - } - - public function css($type = 'string') - { - return $this->css; - } - - public function cssprint() - { - return $cssprint; - } - - public function csstemplate(App $app) - { - $data = []; - $temp = ''; - if (!empty($this->template())) { - if ($app->exist($this->template()) and !in_array($this->template(), $data)) { - $template = $app->get($this->template()); - $temp = $temp . $template->css($app); - $data[] = $template->id(); - - } - - } - $cssprint = str_replace('url(/', 'url('.$app::MEDIA_DIR , $temp . $this->css); - return $cssprint; - } - - public function md($expand = false) - { - if ($expand == true) { - $md = str_replace('](=', '](?id=', $this->html); - } else { - $md = $this->html; - } - return $md; - } - - public function html(App $app) - { - - // %%%% TITLE & DESCIPTION - $html = str_replace('%TITLE%', $this->titre(), $this->html); - $html = str_replace('%DESCRIPTION%', $this->intro(), $html); - - $parser = new MarkdownExtra; - - // id in headers - $parser->header_id_func = function ($header) { - return preg_replace('/[^\w]/', '', strtolower($header)); - }; - $html = $parser->transform($html); - - // replace = > ?id= - $html = str_replace('href="=', 'href="?id=', $html); - - - // infobulles tooltip - foreach ($this->lien('array') as $id) { - $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'intro']) as $item) { - if ($item->id() == $id) { - $title = $item->intro(); - } - } - $lien = 'href="?id=' . $id . '"'; - $titlelien = ' title="' . $title . '" ' . $lien; - $html = str_replace($lien, $titlelien, $html); - } - - if(!empty(strstr($html, '%SUMMARY%'))) { - - - - $html = str_replace('%SUMMARY%', sumparser($html), $html); - } - - - $html = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $html); - $html = str_replace('href="http', ' class="external" target="_blank" href="http', $html); - $html = str_replace('<img src="/', '<img src="./media/', $html); - $html = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $html); - $html = str_replace('</iframe>', '</iframe></div></div>', $html); - return $html; - - - } - - public function secure($type = 'int') - { - if ($type == 'string') { - if ($this->secure == 0) $secure = 'public'; - if ($this->secure == 1) $secure = 'private'; - if ($this->secure == 2) $secure = 'not published'; - return $secure; - } else { - return $this->secure; - } - } - - public function couleurtext() - { - return $this->couleurtext; - } - - public function couleurbkg() - { - return $this->couleurbkg; - } - - public function couleurlien() - { - return $this->couleurlien; - } - - public function couleurlienblank() - { - return $this->couleurlienblank; - } - - public function lien($option) - { - if ($option == 'string') { - $lien = implode(", ", $this->lien); - } elseif ($option == 'array') { - $lien = $this->lien; - } elseif ($option == 'sort') { - return count($this->lien); - } - return $lien; - - } - - public function liento($option) - { - if ($option == 'string') { - $liento = implode(", ", $this->liento); - } elseif ($option == 'array') { - $liento = $this->liento; - } elseif ($option == 'sort') { - return count($this->liento); - } - return $liento; - - } - - public function template($type = 'string') - { - return $this->template; - } - - - - - - // _____________________________________________________ S E T ____________________________________________________ - - public function setid($id) - { - if (strlen($id) < self::LEN and is_string($id)) { - $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); - } - } - - public function settitre($titre) - { - if (strlen($titre) < self::LEN and is_string($titre)) { - $this->titre = strip_tags(trim($titre)); - } - } - - public function setsoustitre($soustitre) - { - if (strlen($soustitre) < self::LEN and is_string($soustitre)) { - $this->soustitre = strip_tags(trim($soustitre)); - } - } - - public function setintro($intro) - { - if (strlen($intro) < self::LEN and is_string($intro)) { - $this->intro = strip_tags(trim($intro)); - } - } - - public function settag($tag) - { - if (is_string($tag)) { - - if (strlen($tag) < self::LEN and is_string($tag)) { - $tag = strip_tags(trim(strtolower($tag))); - $tag = str_replace('*', '', $tag); - $tag = str_replace(' ', '', $tag); - - $taglist = explode(",", $tag); - $taglist = array_filter($taglist); - $this->tag = $taglist; - } - } elseif (is_array($tag)) { - $this->tag = $tag; - } - } - - public function setdatecreation($datecreation) - { - if ($datecreation instanceof DateTimeImmutable) { - $this->datecreation = $datecreation; - } else { - $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris')); - } - } - - public function setdatemodif($datemodif) - { - if ($datemodif instanceof DateTimeImmutable) { - $this->datemodif = $datemodif; - } else { - $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris')); - } - } - - public function setcss($css) - { - if (strlen($css) < self::LENHTML and is_string($css)) { - $this->css = strip_tags(trim(strtolower($css))); - } - } - - public function sethtml($html) - { - if (strlen($html) < self::LENHTML and is_string($html)) { - $this->html = $html; - } - } - - public function setsecure($secure) - { - if ($secure >= 0 and $secure <= self::SECUREMAX) { - $this->secure = intval($secure); - } - } - - public function setcouleurtext($couleurtext) - { - $couleurtext = strval($couleurtext); - if (strlen($couleurtext) <= self::LENCOULEUR) { - $this->couleurtext = strip_tags(trim($couleurtext)); - } - } - - public function setcouleurbkg($couleurbkg) - { - $couleurbkg = strval($couleurbkg); - if (strlen($couleurbkg) <= self::LENCOULEUR) { - $this->couleurbkg = strip_tags(trim($couleurbkg)); - } - } - - public function setcouleurlien($couleurlien) - { - $couleurlien = strval($couleurlien); - if (strlen($couleurlien) <= self::LENCOULEUR) { - $this->couleurlien = strip_tags(trim($couleurlien)); - } - } - - public function setcouleurlienblank($couleurlienblank) - { - $couleurlienblank = strval($couleurlienblank); - if (strlen($couleurlienblank) <= self::LENCOULEUR) { - $this->couleurlienblank = strip_tags(trim($couleurlienblank)); - } - } - - public function setlien($lien) - { - if (!empty($lien) && strlen($lien) < self::LEN && is_string($lien)) { - $lien = strip_tags(trim(strtolower($lien))); - $lienlist = explode(", ", $lien); - $this->lien = $lienlist; - } else { - $this->lien = []; - } - } - - public function setliento($liento) - { - if (is_array($liento)) { - $this->liento = $liento; - } - - - } - - public function settemplate($template) - { - $template = strip_tags($template); - if (strlen($template) == 0) { - $template = 'NULL'; - } - $this->template = $template; - } - - -} - - -?>
\ No newline at end of file diff --git a/w/class/art2.php b/w/class/art2.php index 2298147..5bad524 100644 --- a/w/class/art2.php +++ b/w/class/art2.php @@ -92,12 +92,7 @@ class Art2 $this->seteditcount(0); } - public function updatelinkfrom() - { - $this->linkfrom = []; - $this->linkfrom = array_unique(search($this->md(true), self::DEBUT, self::FIN)); - } public static function classvarlist() { @@ -108,64 +103,6 @@ class Art2 return ['artvarlist' => $classvarlist]; } - - - - public function calclinkto($getlist) - { - $linkto = []; - if (!empty($getlist)) { - foreach ($getlist as $link) { - if (in_array($this->id(), $link->linkfrom('array'))) { - $linkto[] = $link->id(); - } - } - $this->setlinkto($linkto); - } - } - - - public function autotaglist() - { - $pattern = "/%%(\w*)%%/"; - preg_match_all($pattern, $this->md(), $out); - return $out[1]; - - } - - public function autotaglistupdate($taglist) - { - foreach ($taglist as $tag => $artlist) { - $replace = '<ul>'; - foreach ($artlist as $art) { - $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->description() . '">' . $art->title() . '</a></li>'; - } - $replace .= '</ul>'; - $this->section = str_replace('%%' . $tag . '%%', $replace, $this->section); - } - } - - public function autotaglistcalc($taglist) - { - foreach ($taglist as $tag => $artlist) { - foreach ($artlist as $art) { - if (!in_array($art->id(), $this->linkfrom('array')) && $art->id() != $this->id()) { - $this->linkfrom[] = $art->id(); - } - } - } - } - - public function templaterender(array $vars) - { - $datas = []; - foreach ($vars as $var) { - if (method_exists($this, $var)) - $datas[$var] = $this->$var(); - } - return $datas; - } - public function dry() { $array = []; @@ -211,7 +148,7 @@ class Art2 public function date($option = 'date') { if ($option == 'string') { - return $this->date->format('Y-m-d H:i:s'); + return $this->date->format(DateTime::ISO8601); } elseif ($option == 'date' || $option == 'sort') { return $this->date; } elseif ($option == 'hrdi') { @@ -225,7 +162,7 @@ class Art2 public function datecreation($option = 'date') { if ($option == 'string') { - return $this->datecreation->format('Y-m-d H:i:s'); + return $this->datecreation->format(DateTime::ISO8601); } elseif ($option == 'date' || $option == 'sort') { return $this->datecreation; } elseif ($option == 'hrdi') { @@ -238,7 +175,7 @@ class Art2 public function datemodif($option = 'date') { if ($option == 'string') { - return $this->datemodif->format('Y-m-d H:i:s'); + return $this->datemodif->format(DateTime::ISO8601); } elseif ($option == 'date' || $option == 'sort') { return $this->datemodif; } elseif ($option == 'hrdi') { @@ -250,7 +187,7 @@ class Art2 public function daterender($option = 'date') { if ($option == 'string') { - return $this->daterender->format('Y-m-d H:i:s'); + return $this->daterender->format(DateTime::ISO8601); } elseif ($option == 'date' || $option == 'sort') { return $this->daterender; } elseif ($option == 'hrdi') { @@ -322,56 +259,6 @@ class Art2 return $this->section; } - public function section888(App $app) - { - - // %%%% TITLE & DESCIPTION - $section = str_replace('%TITLE%', $this->title(), $this->section); - $section = str_replace('%DESCRIPTION%', $this->description(), $section); - - $parser = new MarkdownExtra; - - // id in headers - $parser->headerid_func = function ($header) { - return preg_replace('/[^\w]/', '', strtolower($header)); - }; - $section = $parser->transform($section); - - // replace = > ?id= - $section = str_replace('href="=', 'href="?id=', $section); - - - // infobulles tooltip - foreach ($this->linkfrom('array') as $id) { - $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'description']) as $item) { - if ($item->id() == $id) { - $title = $item->description(); - } - } - $linkfrom = 'href="?id=' . $id . '"'; - $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; - $section = str_replace($linkfrom, $titlelinkfrom, $section); - } - - if (!empty(strstr($section, '%SUMMARY%'))) { - - - - $section = str_replace('%SUMMARY%', sumparser($section), $section); - } - - - $section = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $section); - $section = str_replace('href="http', ' class="external" target="_blank" href="http', $section); - $section = str_replace('<img src="/', '<img src="./media/', $section); - $section = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $section); - $section = str_replace('</iframe>', '</iframe></div></div>', $section); - return $section; - - - } - public function nav($type = "string") { return $this->nav; @@ -509,7 +396,7 @@ class Art2 if ($date instanceof DateTimeImmutable) { $this->date = $date; } else { - $this->date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $date, new DateTimeZone('Europe/Paris')); + $this->date = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $date, new DateTimeZone('Europe/Paris')); } } @@ -518,7 +405,7 @@ class Art2 if ($datecreation instanceof DateTimeImmutable) { $this->datecreation = $datecreation; } else { - $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris')); + $this->datecreation = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datecreation, new DateTimeZone('Europe/Paris')); } } @@ -527,7 +414,7 @@ class Art2 if ($datemodif instanceof DateTimeImmutable) { $this->datemodif = $datemodif; } else { - $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris')); + $this->datemodif = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $datemodif, new DateTimeZone('Europe/Paris')); } } @@ -536,7 +423,7 @@ class Art2 if ($daterender instanceof DateTimeImmutable) { $this->daterender = $daterender; } else { - $this->daterender = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $daterender, new DateTimeZone('Europe/Paris')); + $this->daterender = DateTimeImmutable::createFromFormat(DateTime::ISO8601, $daterender, new DateTimeZone('Europe/Paris')); } } diff --git a/w/class/controllerart.php b/w/class/controllerart.php index 064474a..340e8e5 100644 --- a/w/class/controllerart.php +++ b/w/class/controllerart.php @@ -4,19 +4,23 @@ class Controllerart extends Controllerdb { /** @var Art2 */ protected $art; - - - public function __construct($id) { - parent::__construct(); + protected $artmanager; + protected $renderengine; - + public function __construct($id) + { + parent::__construct(); + + $this->art = new Art2(['id' => $id]); + $this->artmanager = new Modelart(); + $this->renderengine = new Modelrender(); } public function importart() { $art = $this->artmanager->get($this->art); - if($art !== false) { + if ($art !== false) { $this->art = $art; //$this->art->autotaglistupdate($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'description', 'tag']), $this->art->autotaglist())); return true; @@ -32,20 +36,22 @@ class Controllerart extends Controllerdb $display = $this->user->level() >= $this->art->secure(); $cancreate = $this->user->cancreate(); - $this->showtemplate('read', ['art' => $this->art, 'artexist' => $artexist, 'display' => $display, 'cancreate' => $cancreate]); - + $renderbody = $this->renderengine->render($this->art); + + //$this->showtemplate('read', ['art' => $this->art, 'artexist' => $artexist, 'display' => $display, 'cancreate' => $cancreate]); + } public function edit() { - if($this->importart() && $this->user->canedit()) { + if ($this->importart() && $this->user->canedit()) { $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true]); } else { $this->redirect('?id=' . $this->art->id()); } - + } public function log() @@ -63,25 +69,33 @@ class Controllerart extends Controllerdb public function delete() { - echo '<h2>Delete</h2>'; - $this->artmanager->delete($this->art); + if ($this->user->canedit() && $this->importart()) { + + if (isset($_POST['deleteconfirm']) && $_POST['deleteconfirm'] == true) { + $this->artmanager->delete($this->art); + $this->redirect('?id=' . $this->art->id()); + } else { + $this->showtemplate('delete', ['art' => $this->art, 'artexist' => true]); + } + } else { + $this->redirect('?id=' . $this->art->id()); + } } public function update() { - if($this->importart()) { + if ($this->importart() && $this->user->canedit()) { $this->art->hydrate($_POST); - } + $this->art->updateedited(); + $this->artmanager->update($this->art); - // $this->art->updatelinkfrom(); - // $this->art->autotaglistcalc($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'tag']), $this->art->autotaglist())); - $this->artmanager->update($this->art); + } $this->redirect('?id=' . $this->art->id() . '&aff=edit'); - + } } diff --git a/w/class/controllerconnect.php b/w/class/controllerconnect.php new file mode 100644 index 0000000..2bda1b0 --- /dev/null +++ b/w/class/controllerconnect.php @@ -0,0 +1,18 @@ +<?php + +class Controllerconnect extends Controller +{ + + public function desktop() + { + $this->showtemplate('connect', ['user' => $this->user]); + } + +} + + + + + + +?>
\ No newline at end of file diff --git a/w/class/controllerdb.php b/w/class/controllerdb.php index f21d265..54a9de1 100644 --- a/w/class/controllerdb.php +++ b/w/class/controllerdb.php @@ -11,31 +11,8 @@ class Controllerdb extends Controller public function __construct() { parent::__construct(); - $this->artmanager = new Modelart(); - - } - - public function fetch() - { - $datas = $this->artstore->fetch(); - return $datas; - } - - public function desktop() - { - - - $this->dbinit(); - var_dump( $this->fetch()); - - - } - - public function add() - { - $user = $usersDB->where( 'name', '=', 'Joshua Edwards' )->fetch(); } diff --git a/w/class/controllerhome.php b/w/class/controllerhome.php index 6e62426..31d27c3 100644 --- a/w/class/controllerhome.php +++ b/w/class/controllerhome.php @@ -22,7 +22,7 @@ class Controllerhome extends Controllerdb public function table2() { - $table = $this->artmanager->getlister(); + $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); $table2 = $this->modelhome->table2($table, $this->opt); @@ -37,8 +37,8 @@ class Controllerhome extends Controllerdb if($this->user->level() >= Modeluser::EDITOR) { $scan = new Modelanalyse; $scan->analyseall(); - - $this->table2(); + $this->redirect('./'); + } } diff --git a/w/class/model.php b/w/class/model.php index 0eb3a2f..24c2404 100644 --- a/w/class/model.php +++ b/w/class/model.php @@ -9,7 +9,7 @@ class Model const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; - const TEXT_ELEMENTS = ['section', 'header', 'nav', 'aside', 'footer']; + const TEXT_ELEMENTS = ['header', 'nav', 'section', 'aside', 'footer']; diff --git a/w/class/modelanalyse.php b/w/class/modelanalyse.php index b7819aa..379c41a 100644 --- a/w/class/modelanalyse.php +++ b/w/class/modelanalyse.php @@ -12,7 +12,7 @@ class Modelanalyse extends Modelart public function analyseall() { - $artlist = $this->getlister(['*']); + $artlist = $this->getlister(); $artlist2 = []; foreach ($artlist as $art) { @@ -30,7 +30,7 @@ class Modelanalyse extends Modelart { $art->setlinkfrom($this->analyselinkfrom($art)); - $artlist = $this->getlister(['id', 'linkfrom']); + $artlist = $this->getlister(); $art->setlinkto($this->analyselinkto($art->id(), $artlist)); return $art; diff --git a/w/class/modelart.php b/w/class/modelart.php index be72611..37262ad 100644 --- a/w/class/modelart.php +++ b/w/class/modelart.php @@ -34,9 +34,12 @@ class Modelart extends Modeldb $this->artstore->store($artdata); } - public function get(Art2 $art) + public function get($art) { - $artdata = $this->artstore->findById($art->id()); + if($art instanceof Art2) { + $id = $art->id(); + } + $artdata = $this->artstore->findById($id); if($artdata !== false) { return new Art2($artdata); } else { @@ -44,24 +47,18 @@ class Modelart extends Modeldb } } + public function delete(Art2 $art) + { + $this->artstore->delete($art->id()); + } + public function update(Art2 $art) { - $art->updateedited(); $artdata = new \JamesMoss\Flywheel\Document($art->dry()); $artdata->setId($art->id()); $this->artstore->store($artdata); } - public function getlister() - { - $artlist = []; - $list = $this->artstore->findAll(); - foreach ($list as $artdata) { - $artlist[] = new Art2($artdata); - } - return $artlist; - } - public function exist3($id) { diff --git a/w/class/modeldb.php b/w/class/modeldb.php index d6a4c18..0d4e630 100644 --- a/w/class/modeldb.php +++ b/w/class/modeldb.php @@ -20,5 +20,30 @@ class Modeldb extends Model $this->artstore = new \JamesMoss\Flywheel\Repository(Config::arttable(), $this->database); } + + public function getlister() + { + $artlist = []; + $list = $this->artstore->findAll(); + foreach ($list as $artdata) { + $artlist[$artdata->id] = new Art2($artdata); + } + return $artlist; + } + + public function getlisterid(array $idlist = []) + { + $artdatalist = $this->artstore->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $artlist = []; + foreach ($artdatalist as $id => $artdata) { + $artlist[$id] = new Art2($artdata); + } + return $artlist; + } + + } diff --git a/w/class/modelrender.php b/w/class/modelrender.php index 219e88e..838765f 100644 --- a/w/class/modelrender.php +++ b/w/class/modelrender.php @@ -4,64 +4,80 @@ class Modelrender extends Modelart { const SUMMARY = '%SUMMARY%'; - - public function __construct() { + + public function __construct() + { parent::__construct(); } - - public function getelements(Art2 $art) + public function render(Art2 $art) { - $templates = []; - foreach ($art->template('array') as $element => $tempalteid) { - if(isset($tempalteid) && $tempalteid != $art->id()) { - $templateart = new Art2(['id' => $templateid]); - $templateart = $this->get($templateart); - $templates[$element] = $templateart->$element(); - } - } + $body = $this->getbody($art); + + var_dump($body); + + $parsebody = $this->parser($art, $body); + + echo $parsebody; - $elements = []; - foreach ($art->template('array') as $element) { - if(array_key_exists($element, $templates)) { - $elements[$element] = $templates[$element] . PHP_EOL . $art->$element(); + return $parsebody; + } + + + + public function getbody(Art2 $art) + { + $body = ''; + foreach (self::TEXT_ELEMENTS as $element) { + if (array_key_exists($element, $art->template('array'))) { + $tempalteart = $this->get($art->template('array')[$element]); + $text = $tempalteart->$element() . PHP_EOL . $art->$element(); } else { - $elements[$element] = $art->$element(); + $text = $art->$element(); } + $body .= PHP_EOL . '<' . $element . '>' . PHP_EOL . $this->markdown($text) . PHP_EOL . '</' . $element . '>' . PHP_EOL; } - return $elements; + + return $body; } - public function elementsrender(array $elements) + public function elementsrender(Art2 $art) { - foreach ($elements as $element => $text) { - if(in_array($element, self::TEXT_ELEMENTS)) { - $elements[$element] = $this->textrender($text); + foreach ($this->getelements($art) as $element => $text) { + if (in_array($element, self::TEXT_ELEMENTS)) { + $elements[$element] = $this->markdown($text); } } return $elements; } - - public function textrender($text) + + public function parser(Art2 $art, string $text) { + $text = str_replace('%TITLE%', $art->title(), $text); + $text = str_replace('%DESCRIPTION%', $art->description(), $text); + + + $text = str_replace(self::SUMMARY, $this->sumparser($text), $text); + + $text = str_replace('href="=', 'href="?id=', $text); + $text = $this->tooltip($art->linkfrom('array'), $text); + + $text = str_replace('href="http', ' class="external" target="_blank" href="http', $text); + $text = str_replace('<img src="/', '<img src="./media/', $text); + + $text = $this->autourl($text); + + return $text; } - public function parser($text) + public function autourl($text) { - $text = str_replace('%TITLE%', $this->title(), $this->text); - $text = str_replace('%DESCRIPTION%', $this->description(), $text); - - $text = $this->markdown($text); - - $text = str_replace('%SUMMARY%', sumparser($text), $text); - - $text = str_replace('href="=', 'href="?id=', $text); - + $text = preg_replace('#( |\R|>)(https?:\/\/((\S+)\.([^< ]+)))#', '$1<a href="$2" class="external" target="_blank">$3</a>', $text); return $text; } @@ -81,64 +97,27 @@ class Modelrender extends Modelart - public function tooltip($linkfrom, $text) + public function tooltip(array $linkfrom, string $text) { $descriptions = []; - $artlist = $app->getlisterwhere(['id', 'description'], $linkfrom); + $artlist = $this->getlisterid($linkfrom); foreach ($artlist as $art) { $descriptions[$art->id()] = $art->description(); } - - foreach ($linkfrom as $id) { - if(isset($descriptions[$id])) { + if (isset($descriptions[$id])) { $title = $descriptions[$id]; - } else { - $title = "This page does not exist yet"; } $linkfrom = 'href="?id=' . $id . '"'; $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; $text = str_replace($linkfrom, $titlelinkfrom, $text); } + return $text; } - public function parserff($text) - { - $section = str_replace('%TITLE%', $this->title(), $this->section); - $section = str_replace('%DESCRIPTION%', $this->description(), $section); - - // replace = > ?id= - $section = str_replace('href="=', 'href="?id=', $section); - - - // infobulles tooltip - - - - - if (!empty(strstr($section, '%SUMMARY%'))) { - - - - - } - - - $section = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $section); - $section = str_replace('href="http', ' class="external" target="_blank" href="http', $section); - $section = str_replace('<img src="/', '<img src="./media/', $section); - $section = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $section); - $section = str_replace('</iframe>', '</iframe></div></div>', $section); - return $section; - - } - - - - function sumparser($text) { preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out); @@ -154,18 +133,18 @@ class Modelrender extends Modelart $last = 0; foreach ($sum as $title => $list) { foreach ($list as $h => $link) { - if($h > $last) { + if ($h > $last) { for ($i = 1; $i <= ($h - $last); $i++) { $sumstring .= '<ul>'; - } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + } + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; } elseif ($h < $last) { for ($i = 1; $i <= ($last - $h); $i++) { $sumstring .= '</ul>'; } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; } elseif ($h = $last) { - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; } $last = $h; } @@ -178,6 +157,40 @@ class Modelrender extends Modelart + //tag auto menu + + + public function autotaglist() + { + $pattern = "/%%(\w*)%%/"; + preg_match_all($pattern, $this->md(), $out); + return $out[1]; + + } + + public function autotaglistupdate($taglist) + { + foreach ($taglist as $tag => $artlist) { + $replace = '<ul>'; + foreach ($artlist as $art) { + $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->description() . '">' . $art->title() . '</a></li>'; + } + $replace .= '</ul>'; + $text = str_replace('%%' . $tag . '%%', $replace, $text); + } + } + + public function autotaglistcalc($taglist) + { + foreach ($taglist as $tag => $artlist) { + foreach ($artlist as $art) { + if (!in_array($art->id(), $this->linkfrom('array')) && $art->id() != $this->id()) { + $this->linkfrom[] = $art->id(); + } + } + } + } + } diff --git a/w/class/router.php b/w/class/router.php index 27ac4e4..604fb84 100644 --- a/w/class/router.php +++ b/w/class/router.php @@ -32,6 +32,7 @@ class Router 'aff=media' => ['media', 'desktop'], 'aff=media action=addmedia' => ['media', 'addmedia'], 'aff=admin' => ['admin', 'desktop'], + 'aff=co' => ['connect', 'desktop'], ]; public function __construct() { |