Skip to content

Commit

Permalink
new sorting param: externallinks
Browse files Browse the repository at this point in the history
+ new HOME_COLUMN: externallinks
+ rename Page var urls to externallinks
  • Loading branch information
vincent-peugnet committed Oct 18, 2024
1 parent 7ad4648 commit cd46f8a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 43 deletions.
1 change: 1 addition & 0 deletions app/class/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ abstract class Model
'title' => 'title',
'description' => 'description',
'linkto' => 'linkto',
'externallinks' => 'external links',
'geolocalisation' => 'geolocalisation',
'datemodif' => 'modification date',
'datecreation' => 'creation date',
Expand Down
2 changes: 1 addition & 1 deletion app/class/Modelhome.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
2 changes: 1 addition & 1 deletion app/class/Modelpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion app/class/Opt.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Opt extends Item
'tag',
'title',
'linkto',
'externallinks',
'datemodif',
'datecreation',
'date',
Expand Down Expand Up @@ -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)) {
Expand Down
41 changes: 32 additions & 9 deletions app/class/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use DateTimeImmutable;
use DateTimeZone;

use function Clue\StreamFilter\fun;

abstract class Page extends Item
{
protected $id;
Expand Down Expand Up @@ -42,8 +44,8 @@ abstract class Page extends Item
protected $password;
protected $postprocessaction;

/** @var array<string, ?bool> $urls */
protected array $urls = [];
/** @var array<string, ?bool> $externallinks */
protected array $externallinks = [];

protected int $version;

Expand Down Expand Up @@ -122,7 +124,7 @@ public function reset()
$this->setredirection('');
$this->setrefresh(0);
$this->setpassword('');
$this->urls = [];
$this->externallinks = [];
$this->postprocessaction = false;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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 ______________________________________

Expand Down
1 change: 1 addition & 0 deletions app/class/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class User extends Item
'title',
'description',
'linkto',
'externallinks',
'geolocalisation',
'datemodif',
'datecreation',
Expand Down
60 changes: 29 additions & 31 deletions app/view/templates/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,23 @@
<a href="<?= $opt->sortbyorder('title') ?>">title</a>
<?= $this->insert('macro_tablesort', ['opt' => $opt, 'th' => 'title']) ?>
</th>
<?php }
if ($columns['description']) { ?>
<?php } if ($columns['description']) { ?>
<th class="description">description</th>
<?php }
if ($columns['linkto']) { ?>
<?php } if ($columns['linkto']) { ?>
<th class="linkto">
<a href="<?= $opt->sortbyorder('linkto') ?>">linkto</a>
<?= $this->insert('macro_tablesort', ['opt' => $opt, 'th' => 'linkto']) ?>

</th>
<?php } if ($columns['externallinks']) { ?>
<th class="externallinks">
<a href="<?= $opt->sortbyorder('externallinks') ?>">external links</a>
<?= $this->insert('macro_tablesort', ['opt' => $opt, 'th' => 'externallinks' ]) ?>
</th>
<?php } if ($columns['geolocalisation']) { ?>
<th class="geo">
geo
</th>
<th class="geo">
geo
</th>
<?php }
if ($columns['datemodif']) { ?>
<th class="datemodif">
Expand Down Expand Up @@ -309,60 +312,55 @@ class="redirection"
</td>
<?php } if ($columns['tag']) { ?>
<td class="tag"><?= $opt->taglinks($item->tag('array')) ?></td>
<?php }
if ($columns['title']) { ?>
<?php } if ($columns['title']) { ?>
<td class="title" title="<?= $item->title() ?>"><label for="id_<?= $item->id() ?>"><?= $item->title() ?></label></td>
<?php }
if ($columns['description']) { ?>
<?php } if ($columns['description']) { ?>
<td class="description" title="<?= $item->description() ?>"><?= $item->description('short') ?></td>
<?php }
if ($columns['linkto']) { ?>
<?php } if ($columns['linkto']) { ?>
<td class="linkto"><?= $opt->linktolink($item->linkto('array')) ?></td>
<?php }
if ($columns['geolocalisation']) { ?>
<?php } if ($columns['externallinks']) { ?>
<td class="linkto" title="<?= $item->externallinkstitle() ?>">
<?= $item->externallinks('sort') ?>
<?php $deadlinks = $item->deadlinkcount(); if (!empty($deadlinks)) { ?>
<span class="deadlinks"><?= $deadlinks ?></span>
<?php } ?>
</td>
<?php } if ($columns['geolocalisation']) { ?>
<td class="geo" title="This page is geolocated: <?= $item->latitude() ?> <?= $item->longitude() ?>">
<a href="?<?= $opt->getfilteraddress(['geo' => 1]) ?>">
<?= $item->isgeo() ? '<i class="fa fa-globe"></i>' : '' ?>
</a>
</td>
<?php }
if ($columns['datemodif']) { ?>
<?php } if ($columns['datemodif']) { ?>
<td class="datemodif" title="<?= $item->datemodif('dmy') ?> <?= $item->datemodif('ptime') ?>">
<time datetime="<?= $item->datemodif('string') ?>" title="<?= $item->datemodif('dmy') . ' ' . $item->datemodif('ptime') ?>">
<?= $item->datemodif('hrdi') ?>
</time>
</td>
<?php }
if ($columns['datecreation']) { ?>
<?php } if ($columns['datecreation']) { ?>
<td class="datecreation" title="<?= $item->datecreation('dmy') ?> <?= $item->datecreation('ptime') ?>">
<time datetime="<?= $item->datecreation('string') ?>" title="<?= $item->datecreation('dmy') . ' ' . $item->datecreation('ptime') ?>">
<?= $item->datecreation('hrdi') ?>
</time>
</td>
<?php }
if ($columns['date']) { ?>
<?php } if ($columns['date']) { ?>
<td class="date" title="<?= $item->date('dmy') ?> <?= $item->date('ptime') ?>">
<time datetime="<?= $item->date('string') ?>" title="<?= $item->date('dmy') . ' ' . $item->date('ptime') ?>">
<?= $item->date('dmy') ?>
</time>
</td>
<?php }
if ($columns['secure']) { ?>
<?php } if ($columns['secure']) { ?>
<td class="secure">
<?= $opt->securelink($item->secure('int') , $item->secure('string')) ?>
<?= !empty($item->password()) ? '<i class="fa fa-lock" title="This page is password protected"></i>' : '' ?>
</td>
<?php }
if ($columns['authors']) { ?>
<?php } if ($columns['authors']) { ?>
<td class="authors"><?= $opt->authorlinks($item->authors('array')) ?></td>
<?php }
if ($columns['visitcount']) { ?>
<?php } if ($columns['visitcount']) { ?>
<td class="visitcount"><?= $item->visitcount() ?></td>
<?php }
if ($columns['editcount']) { ?>
<?php } if ($columns['editcount']) { ?>
<td class="editcount"><?= $item->editcount() ?></td>
<?php }
if ($columns['displaycount']) { ?>
<?php } if ($columns['displaycount']) { ?>
<td class="displaycount"><?= $item->displaycount() ?></td>
<?php } if ($columns['version']) { ?>
<td class="version"><?= $item->version() ?></td>
Expand Down
9 changes: 9 additions & 0 deletions assets/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd46f8a

Please sign in to comment.