diff options
Diffstat (limited to 'application/LinkFilter.php')
-rw-r--r-- | application/LinkFilter.php | 37 |
1 files changed, 17 insertions, 20 deletions
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 | |||
33 | public static $HASHTAG_CHARS = '\p{Pc}\p{N}\p{L}\p{Mn}'; | 33 | public static $HASHTAG_CHARS = '\p{Pc}\p{N}\p{L}\p{Mn}'; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * @var array all available links. | 36 | * @var LinkDB all available links. |
37 | */ | 37 | */ |
38 | private $links; | 38 | private $links; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * @param array $links initialization. | 41 | * @param LinkDB $links initialization. |
42 | */ | 42 | */ |
43 | public function __construct($links) | 43 | public function __construct($links) |
44 | { | 44 | { |
@@ -94,18 +94,16 @@ class LinkFilter | |||
94 | private function noFilter($privateonly = false) | 94 | private function noFilter($privateonly = false) |
95 | { | 95 | { |
96 | if (! $privateonly) { | 96 | if (! $privateonly) { |
97 | krsort($this->links); | ||
98 | return $this->links; | 97 | return $this->links; |
99 | } | 98 | } |
100 | 99 | ||
101 | $out = array(); | 100 | $out = array(); |
102 | foreach ($this->links as $value) { | 101 | foreach ($this->links as $key => $value) { |
103 | if ($value['private']) { | 102 | if ($value['private']) { |
104 | $out[$value['linkdate']] = $value; | 103 | $out[$key] = $value; |
105 | } | 104 | } |
106 | } | 105 | } |
107 | 106 | ||
108 | krsort($out); | ||
109 | return $out; | 107 | return $out; |
110 | } | 108 | } |
111 | 109 | ||
@@ -121,10 +119,10 @@ class LinkFilter | |||
121 | private function filterSmallHash($smallHash) | 119 | private function filterSmallHash($smallHash) |
122 | { | 120 | { |
123 | $filtered = array(); | 121 | $filtered = array(); |
124 | foreach ($this->links as $l) { | 122 | foreach ($this->links as $key => $l) { |
125 | if ($smallHash == smallHash($l['linkdate'])) { | 123 | if ($smallHash == smallHash($l['created']->format('Ymd_His'))) { |
126 | // Yes, this is ugly and slow | 124 | // Yes, this is ugly and slow |
127 | $filtered[$l['linkdate']] = $l; | 125 | $filtered[$key] = $l; |
128 | return $filtered; | 126 | return $filtered; |
129 | } | 127 | } |
130 | } | 128 | } |
@@ -188,7 +186,7 @@ class LinkFilter | |||
188 | $keys = array('title', 'description', 'url', 'tags'); | 186 | $keys = array('title', 'description', 'url', 'tags'); |
189 | 187 | ||
190 | // Iterate over every stored link. | 188 | // Iterate over every stored link. |
191 | foreach ($this->links as $link) { | 189 | foreach ($this->links as $id => $link) { |
192 | 190 | ||
193 | // ignore non private links when 'privatonly' is on. | 191 | // ignore non private links when 'privatonly' is on. |
194 | if (! $link['private'] && $privateonly === true) { | 192 | if (! $link['private'] && $privateonly === true) { |
@@ -222,11 +220,10 @@ class LinkFilter | |||
222 | } | 220 | } |
223 | 221 | ||
224 | if ($found) { | 222 | if ($found) { |
225 | $filtered[$link['linkdate']] = $link; | 223 | $filtered[$id] = $link; |
226 | } | 224 | } |
227 | } | 225 | } |
228 | 226 | ||
229 | krsort($filtered); | ||
230 | return $filtered; | 227 | return $filtered; |
231 | } | 228 | } |
232 | 229 | ||
@@ -256,7 +253,7 @@ class LinkFilter | |||
256 | return $filtered; | 253 | return $filtered; |
257 | } | 254 | } |
258 | 255 | ||
259 | foreach ($this->links as $link) { | 256 | foreach ($this->links as $key => $link) { |
260 | // ignore non private links when 'privatonly' is on. | 257 | // ignore non private links when 'privatonly' is on. |
261 | if (! $link['private'] && $privateonly === true) { | 258 | if (! $link['private'] && $privateonly === true) { |
262 | continue; | 259 | continue; |
@@ -278,10 +275,9 @@ class LinkFilter | |||
278 | } | 275 | } |
279 | 276 | ||
280 | if ($found) { | 277 | if ($found) { |
281 | $filtered[$link['linkdate']] = $link; | 278 | $filtered[$key] = $link; |
282 | } | 279 | } |
283 | } | 280 | } |
284 | krsort($filtered); | ||
285 | return $filtered; | 281 | return $filtered; |
286 | } | 282 | } |
287 | 283 | ||
@@ -304,13 +300,14 @@ class LinkFilter | |||
304 | } | 300 | } |
305 | 301 | ||
306 | $filtered = array(); | 302 | $filtered = array(); |
307 | foreach ($this->links as $l) { | 303 | foreach ($this->links as $key => $l) { |
308 | if (startsWith($l['linkdate'], $day)) { | 304 | if ($l['created']->format('Ymd') == $day) { |
309 | $filtered[$l['linkdate']] = $l; | 305 | $filtered[$key] = $l; |
310 | } | 306 | } |
311 | } | 307 | } |
312 | ksort($filtered); | 308 | |
313 | return $filtered; | 309 | // sort by date ASC |
310 | return array_reverse($filtered, true); | ||
314 | } | 311 | } |
315 | 312 | ||
316 | /** | 313 | /** |