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