add cms, add todo
[ssproject1617.git] / testcms-final-anon / system / functions / search.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 /**
4 Theme functions for search
5 */
6 function has_search_results() {
7 if($items = IoC::resolve('search')) {
8 return $items->length() > 0;
9 }
10
11 return false;
12 }
13
14 function total_search_results() {
15 if($total = IoC::resolve('total_search')) {
16 return $total;
17 }
18
19 return 0;
20 }
21
22 function search_results() {
23 $posts = IoC::resolve('search');
24
25 if($result = $posts->valid()) {
26 // register single post
27 IoC::instance('article', $posts->current(), true);
28
29 // move to next
30 $posts->next();
31 }
32
33 return $result;
34 }
35
36 function search_term() {
37 return (Request::uri_segment(1) == 'search' ? Request::uri_segment(2) : '');
38 }
39
40 function search_next($text = 'Next', $default = '') {
41 $per_page = Config::get('metadata.posts_per_page');
42 $offset = Input::get('offset', 0);
43 $total = IoC::resolve('total_search');
44
45 $pages = floor($total / $per_page);
46 $page = $offset / $per_page;
47
48 if($page < $pages) {
49 return '<a href="' . current_url() . '?offset=' . ($offset + $per_page) . '">' . $text . '</a>';
50 }
51
52 return $default;
53 }
54
55 function search_prev($text = 'Previous', $default = '') {
56 $per_page = Config::get('metadata.posts_per_page');
57 $offset = Input::get('offset', 0);
58 $total = IoC::resolve('total_search');
59
60 $pages = ceil($total / $per_page);
61 $page = $offset / $per_page;
62
63 if($offset > 0) {
64 return '<a href="' . current_url() . '?offset=' . ($offset - $per_page) . '">' . $text . '</a>';
65 }
66
67 return $default;
68 }