]> git.mxchange.org Git - friendica.git/blob - mod/search.php
missing pagination in photo collections
[friendica.git] / mod / search.php
1 <?php
2
3
4 function search_post(&$a) {
5         if(x($_POST,'search'))
6                 $a->data['search'] = $_POST['search'];
7 }
8
9
10 function search_content(&$a) {
11
12         $o = '<div id="live-search"></div>' . "\r\n";
13
14         $o .= '<h3>' . t('Search') . '</h3>';
15
16         if(x($a->data,'search'))
17                 $search = notags(trim($a->data['search']));
18         else
19                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
20
21         $o .= search($search);
22
23         if(! $search)
24                 return $o;
25
26         require_once("include/bbcode.php");
27         require_once('include/security.php');
28
29         $sql_extra = "
30                 AND `item`.`allow_cid` = '' 
31                 AND `item`.`allow_gid` = '' 
32                 AND `item`.`deny_cid`  = '' 
33                 AND `item`.`deny_gid`  = '' 
34         ";
35
36         $r = q("SELECT COUNT(*) AS `total`
37                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
38                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
39                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
40                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
41                 AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )
42                 $sql_extra ",
43                 intval(local_user()),
44                 dbesc($search)
45         );
46
47         if(count($r))
48                 $a->set_pager_total($r[0]['total']);
49
50         if(! $r[0]['total']) {
51                 notice('No results.');
52                 return $o;
53         }
54
55         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
56                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
57                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, 
58                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
59                 `user`.`nickname`
60                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
61                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` 
62                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
63                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
64                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
65                 AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )
66                 $sql_extra
67                 ORDER BY `parent` DESC ",
68                 intval(local_user()),
69                 dbesc($search)
70         );
71
72         $tpl = load_view_file('view/search_item.tpl');
73         $droptpl = load_view_file('view/wall_fake_drop.tpl');
74
75         $return_url = $_SESSION['return_url'] = $a->cmd;
76
77         if(count($r)) {
78
79                 foreach($r as $item) {
80
81                         $comment     = '';
82                         $owner_url   = '';
83                         $owner_photo = '';
84                         $owner_name  = '';
85                         $sparkle     = '';
86                         
87                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
88                                 && ($item['id'] != $item['parent']))
89                                 continue;
90
91                         $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
92                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
93                         $profile_link   = ((strlen($item['author-link']))   ? $item['author-link']   : $item['url']);
94
95
96                         $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
97                         $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
98                         if($coord) {
99                                 if($location)
100                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
101                                 else
102                                         $location = '<span class="smalltext">' . $coord . '</span>';
103                         }
104
105                         $drop = replace_macros($droptpl,array('$id' => $item['id']));
106                         $lock = '<div class="wall-item-lock"></div>';
107
108                         $o .= replace_macros($tpl,array(
109                                 '$id' => $item['item_id'],
110                                 '$profile_url' => $profile_link,
111                                 '$name' => $profile_name,
112                                 '$sparkle' => $sparkle,
113                                 '$lock' => $lock,
114                                 '$thumb' => $profile_avatar,
115                                 '$title' => $item['title'],
116                                 '$body' => bbcode($item['body']),
117                                 '$ago' => relative_date($item['created']),
118                                 '$location' => $location,
119                                 '$indent' => '',
120                                 '$owner_url' => $owner_url,
121                                 '$owner_photo' => $owner_photo,
122                                 '$owner_name' => $owner_name,
123                                 '$drop' => $drop,
124                                 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $item['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
125                         ));
126
127                 }
128         }
129
130         $o .= paginate($a);
131
132         return $o;
133 }
134