aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LinkDB.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-03-25 19:20:55 +0100
committerArthur <arthur@hoa.ro>2016-03-25 19:20:55 +0100
commitf66a1990e5d93a6f302ce594968e5e717b93da72 (patch)
tree22e5da81979bc7ee596fcd5c9c56d4c01c599aa4 /application/LinkDB.php
parentb2764886c7b52ed98debb90b2ebf075dec5ae2e8 (diff)
parent528a6f8a232c060faf024008e4f8a09b4aa8dabc (diff)
downloadShaarli-f66a1990e5d93a6f302ce594968e5e717b93da72.tar.gz
Shaarli-f66a1990e5d93a6f302ce594968e5e717b93da72.tar.zst
Shaarli-f66a1990e5d93a6f302ce594968e5e717b93da72.zip
Merge pull request #515 from ArthurHoaro/template-feeds
Refactor RSS feeds generation, and do it through templates
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r--application/LinkDB.php64
1 files changed, 59 insertions, 5 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 1b505620..a62341fc 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -341,17 +341,71 @@ You use the community supported version of the original Shaarli project, by Seba
341 } 341 }
342 342
343 /** 343 /**
344 * Filter links. 344 * Returns the shaare corresponding to a smallHash.
345 * 345 *
346 * @param string $type Type of filter. 346 * @param string $request QUERY_STRING server parameter.
347 * @param mixed $request Search request, string or array. 347 *
348 * @return array $filtered array containing permalink data.
349 *
350 * @throws LinkNotFoundException if the smallhash is malformed or doesn't match any link.
351 */
352 public function filterHash($request)
353 {
354 $request = substr($request, 0, 6);
355 $linkFilter = new LinkFilter($this->_links);
356 return $linkFilter->filter(LinkFilter::$FILTER_HASH, $request);
357 }
358
359 /**
360 * Returns the list of articles for a given day.
361 *
362 * @param string $request day to filter. Format: YYYYMMDD.
363 *
364 * @return array list of shaare found.
365 */
366 public function filterDay($request) {
367 $linkFilter = new LinkFilter($this->_links);
368 return $linkFilter->filter(LinkFilter::$FILTER_DAY, $request);
369 }
370
371 /**
372 * Filter links according to search parameters.
373 *
374 * @param array $filterRequest Search request content. Supported keys:
375 * - searchtags: list of tags
376 * - searchterm: term search
348 * @param bool $casesensitive Optional: Perform case sensitive filter 377 * @param bool $casesensitive Optional: Perform case sensitive filter
349 * @param bool $privateonly Optional: Returns private links only if true. 378 * @param bool $privateonly Optional: Returns private links only if true.
350 * 379 *
351 * @return array filtered links 380 * @return array filtered links, all links if no suitable filter was provided.
352 */ 381 */
353 public function filter($type = '', $request = '', $casesensitive = false, $privateonly = false) 382 public function filterSearch($filterRequest = array(), $casesensitive = false, $privateonly = false)
354 { 383 {
384 // Filter link database according to parameters.
385 $searchtags = !empty($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : '';
386 $searchterm = !empty($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : '';
387
388 // Search tags + fullsearch.
389 if (empty($type) && ! empty($searchtags) && ! empty($searchterm)) {
390 $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT;
391 $request = array($searchtags, $searchterm);
392 }
393 // Search by tags.
394 elseif (! empty($searchtags)) {
395 $type = LinkFilter::$FILTER_TAG;
396 $request = $searchtags;
397 }
398 // Fulltext search.
399 elseif (! empty($searchterm)) {
400 $type = LinkFilter::$FILTER_TEXT;
401 $request = $searchterm;
402 }
403 // Otherwise, display without filtering.
404 else {
405 $type = '';
406 $request = '';
407 }
408
355 $linkFilter = new LinkFilter($this->_links); 409 $linkFilter = new LinkFilter($this->_links);
356 return $linkFilter->filter($type, $request, $casesensitive, $privateonly); 410 return $linkFilter->filter($type, $request, $casesensitive, $privateonly);
357 } 411 }