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