From cd46f8a1469ec0afe91c6afa3a717e84b2c60e1f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 18 Oct 2024 13:10:19 +0200 Subject: [PATCH] new sorting param: externallinks + new HOME_COLUMN: externallinks + rename Page var urls to externallinks --- app/class/Model.php | 1 + app/class/Modelhome.php | 2 +- app/class/Modelpage.php | 2 +- app/class/Opt.php | 3 +- app/class/Page.php | 41 +++++++++++++++++++------ app/class/User.php | 1 + app/view/templates/home.php | 60 ++++++++++++++++++------------------- assets/css/home.css | 9 ++++++ 8 files changed, 76 insertions(+), 43 deletions(-) diff --git a/app/class/Model.php b/app/class/Model.php index 3b2c3070..45403a67 100644 --- a/app/class/Model.php +++ b/app/class/Model.php @@ -44,6 +44,7 @@ abstract class Model 'title' => 'title', 'description' => 'description', 'linkto' => 'linkto', + 'externallinks' => 'external links', 'geolocalisation' => 'geolocalisation', 'datemodif' => 'modification date', 'datecreation' => 'creation date', diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index c0bbc354..a4f166bf 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -209,7 +209,7 @@ public function mapdata( // external links if ($showexternallinks) { - foreach ($page->urls() as $url => $ok) { + foreach ($page->externallinks() as $url => $ok) { $domain = parse_url($url, PHP_URL_HOST); diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 0099f9ea..4cb3bcd4 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -467,7 +467,7 @@ public function renderpage(Page $page, AltoRouter $router): Page $page->setdaterender($now); $page->setlinkto($renderengine->linkto()); - $page->seturls($renderengine->urls()); + $page->setexternallinks($renderengine->urls()); $page->setpostprocessaction($renderengine->postprocessaction()); return $page; diff --git a/app/class/Opt.php b/app/class/Opt.php index d2203862..ed8485e2 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -78,6 +78,7 @@ class Opt extends Item 'tag', 'title', 'linkto', + 'externallinks', 'datemodif', 'datecreation', 'date', @@ -209,7 +210,7 @@ public function getaddress(): string /** * Used to generate links in home table header */ - public function sortbyorder($sortby = "") + public function sortbyorder(string $sortby = ''): string { $object = $this->drylist(self::DATALIST, self::HTML_DATETIME_LOCAL); if (!empty($sortby)) { diff --git a/app/class/Page.php b/app/class/Page.php index 3abd7ba2..6658e9cb 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use DateTimeZone; +use function Clue\StreamFilter\fun; + abstract class Page extends Item { protected $id; @@ -42,8 +44,8 @@ abstract class Page extends Item protected $password; protected $postprocessaction; - /** @var array $urls */ - protected array $urls = []; + /** @var array $externallinks */ + protected array $externallinks = []; protected int $version; @@ -122,7 +124,7 @@ public function reset() $this->setredirection(''); $this->setrefresh(0); $this->setpassword(''); - $this->urls = []; + $this->externallinks = []; $this->postprocessaction = false; } @@ -378,9 +380,15 @@ public function postprocessaction($type = 'int'): bool return $this->postprocessaction; } - public function urls($type = 'array'): array + /** + * @return array|int + */ + public function externallinks($option = 'array'): mixed { - return $this->urls; + if ($option === 'sort') { + return count($this->externallinks); + } + return $this->externallinks; } public function version($type = 'int'): int @@ -724,10 +732,10 @@ public function setpostprocessaction($postprocessaction): void $this->postprocessaction = boolval($postprocessaction); } - public function seturls($urls): void + public function setexternallinks($externallinks): void { - if (is_array($urls)) { - $this->urls = $urls; + if (is_array($externallinks)) { + $this->externallinks = $externallinks; } } @@ -798,12 +806,27 @@ public function addtag($tag) public function deadlinkcount(): int { - $deadurls = array_filter($this->urls, function ($ok): bool { + $deadurls = array_filter($this->externallinks, function ($ok): bool { return !$ok; }); return count($deadurls); } + /** + * Used in the title of external links column in hme view + * + * @return string All links separated by new lines followed by a emoji ✅ or 💀 + */ + public function externallinkstitle(): string + { + $links = $this->externallinks; + array_walk($links, function (&$value, string $key) { + $symbol = $value ? '✅' : '💀'; + $value = $key . ' ' . $symbol; + }); + return implode("\n", $links); + } + // _________________________________ T O O L S ______________________________________ diff --git a/app/class/User.php b/app/class/User.php index 0d6e3d6a..d8ca9905 100644 --- a/app/class/User.php +++ b/app/class/User.php @@ -45,6 +45,7 @@ class User extends Item 'title', 'description', 'linkto', + 'externallinks', 'geolocalisation', 'datemodif', 'datecreation', diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 2c6dfb17..62c783b9 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -179,20 +179,23 @@ title insert('macro_tablesort', ['opt' => $opt, 'th' => 'title']) ?> - + description - + linkto insert('macro_tablesort', ['opt' => $opt, 'th' => 'linkto']) ?> + + + external links + insert('macro_tablesort', ['opt' => $opt, 'th' => 'externallinks' ]) ?> + - - geo - + + geo + @@ -309,60 +312,55 @@ class="redirection" taglinks($item->tag('array')) ?> - + - + description('short') ?> - + linktolink($item->linkto('array')) ?> - + + + externallinks('sort') ?> + deadlinkcount(); if (!empty($deadlinks)) { ?> + + + + isgeo() ? '' : '' ?> - + - + - + - + securelink($item->secure('int') , $item->secure('string')) ?> password()) ? '' : '' ?> - + authorlinks($item->authors('array')) ?> - + visitcount() ?> - + editcount() ?> - + displaycount() ?> version() ?> diff --git a/assets/css/home.css b/assets/css/home.css index a1ccd3da..65b3f0a2 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -126,6 +126,15 @@ table .favicon img { max-width: 32px; } +table .deadlinks { + background-color: red; + color: white; + border-radius: 15px; + display: inline-block; + height: 17px; + width: 17px; + text-align: center; +} td.title { max-width: 150px;