From 01878a75b93b9966f7366ea2937c118bbc3e459e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 16:16:44 +0100 Subject: Apply the new ID system accros the whole codebase --- application/LinkFilter.php | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'application/LinkFilter.php') diff --git a/application/LinkFilter.php b/application/LinkFilter.php index d4fe28df..7bab46ba 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -33,12 +33,12 @@ class LinkFilter public static $HASHTAG_CHARS = '\p{Pc}\p{N}\p{L}\p{Mn}'; /** - * @var array all available links. + * @var LinkDB all available links. */ private $links; /** - * @param array $links initialization. + * @param LinkDB $links initialization. */ public function __construct($links) { @@ -94,18 +94,16 @@ class LinkFilter private function noFilter($privateonly = false) { if (! $privateonly) { - krsort($this->links); return $this->links; } $out = array(); - foreach ($this->links as $value) { + foreach ($this->links as $key => $value) { if ($value['private']) { - $out[$value['linkdate']] = $value; + $out[$key] = $value; } } - krsort($out); return $out; } @@ -121,10 +119,10 @@ class LinkFilter private function filterSmallHash($smallHash) { $filtered = array(); - foreach ($this->links as $l) { - if ($smallHash == smallHash($l['linkdate'])) { + foreach ($this->links as $key => $l) { + if ($smallHash == smallHash($l['created']->format('Ymd_His'))) { // Yes, this is ugly and slow - $filtered[$l['linkdate']] = $l; + $filtered[$key] = $l; return $filtered; } } @@ -188,7 +186,7 @@ class LinkFilter $keys = array('title', 'description', 'url', 'tags'); // Iterate over every stored link. - foreach ($this->links as $link) { + foreach ($this->links as $id => $link) { // ignore non private links when 'privatonly' is on. if (! $link['private'] && $privateonly === true) { @@ -222,11 +220,10 @@ class LinkFilter } if ($found) { - $filtered[$link['linkdate']] = $link; + $filtered[$id] = $link; } } - krsort($filtered); return $filtered; } @@ -256,7 +253,7 @@ class LinkFilter return $filtered; } - foreach ($this->links as $link) { + foreach ($this->links as $key => $link) { // ignore non private links when 'privatonly' is on. if (! $link['private'] && $privateonly === true) { continue; @@ -278,10 +275,9 @@ class LinkFilter } if ($found) { - $filtered[$link['linkdate']] = $link; + $filtered[$key] = $link; } } - krsort($filtered); return $filtered; } @@ -304,13 +300,14 @@ class LinkFilter } $filtered = array(); - foreach ($this->links as $l) { - if (startsWith($l['linkdate'], $day)) { - $filtered[$l['linkdate']] = $l; + foreach ($this->links as $key => $l) { + if ($l['created']->format('Ymd') == $day) { + $filtered[$key] = $l; } } - ksort($filtered); - return $filtered; + + // sort by date ASC + return array_reverse($filtered, true); } /** -- cgit v1.2.3 From d592daea8343bb4dfecff5d97e93699581ccc58c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 18:24:15 +0100 Subject: Add a persistent 'shorturl' key to all links All existing link will keep their permalinks. New links will have smallhash generated with date+id. The purpose of this is to avoid collision between links due to their creation date. --- application/LinkFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/LinkFilter.php') diff --git a/application/LinkFilter.php b/application/LinkFilter.php index 7bab46ba..daa6d9cc 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -120,7 +120,7 @@ class LinkFilter { $filtered = array(); foreach ($this->links as $key => $l) { - if ($smallHash == smallHash($l['created']->format('Ymd_His'))) { + if ($smallHash == $l['shorturl']) { // Yes, this is ugly and slow $filtered[$key] = $l; return $filtered; -- cgit v1.2.3