]> git.mxchange.org Git - friendica.git/blob - mod/search.php
file attachments
[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((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
13                 notice( t('Public access denied.') . EOL);
14                 return;
15         }
16
17         require_once("include/bbcode.php");
18         require_once('include/security.php');
19         require_once('include/conversation.php');
20
21         if(x($_SESSION,'theme'))
22                 unset($_SESSION['theme']);
23
24         $o = '<div id="live-search"></div>' . "\r\n";
25
26         $o .= '<h3>' . t('Search') . '</h3>';
27
28         if(x($a->data,'search'))
29                 $search = notags(trim($a->data['search']));
30         else
31                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
32
33         $o .= search($search);
34
35         if(! $search)
36                 return $o;
37
38
39         $sql_extra = "
40                 AND `item`.`allow_cid` = '' 
41                 AND `item`.`allow_gid` = '' 
42                 AND `item`.`deny_cid`  = '' 
43                 AND `item`.`deny_gid`  = '' 
44         ";
45
46         $s_bool  = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
47         $s_regx  = "AND `item`.`body` REGEXP '%s' ";
48
49         if(mb_strlen($search) >= 3)
50                 $search_alg = $s_bool;
51         else
52                 $search_alg = $s_regx;
53
54         $r = q("SELECT COUNT(*) AS `total`
55                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
56                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
57                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
58                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
59                 $search_alg
60                 $sql_extra ",
61                 intval(local_user()),
62                 dbesc($search)
63         );
64
65         if(count($r))
66                 $a->set_pager_total($r[0]['total']);
67
68         if(! $r[0]['total']) {
69                 info( t('No results.') . EOL);
70                 return $o;
71         }
72
73         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
74                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
75                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
76                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
77                 `user`.`nickname`
78                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
79                 LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` 
80                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0
81                 AND ( `wall` = 1 OR `contact`.`uid` = %d )
82                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
83                 $search_alg
84                 $sql_extra
85                 ORDER BY `parent` DESC ",
86                 intval(local_user()),
87                 dbesc($search)
88         );
89
90
91
92         $o .= conversation($a,$r,'search',false);
93
94         $o .= paginate($a);
95
96         return $o;
97 }
98