]> git.mxchange.org Git - friendica.git/blob - mod/search.php
23b2ddb7e3884a0445595ab6a34379df2c285845
[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`, `contact`.`writable`, 
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
84         require_once('include/conversation.php');
85
86         $o .= conversation($a,$r,'search',false);
87
88         $o .= paginate($a);
89
90         return $o;
91 }
92