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