]> git.mxchange.org Git - friendica.git/blob - mod/community.php
Merge develop into 0602_contact_profile
[friendica.git] / mod / community.php
1 <?php
2 if(! function_exists('community_init')) {
3 function community_init(&$a) {
4         if(! local_user()) {
5                 unset($_SESSION['theme']);
6                 unset($_SESSION['mobile-theme']);
7         }
8 }
9 }
10
11 if(! function_exists('community_content')) {
12 function community_content(&$a, $update = 0) {
13
14         $o = '';
15
16         // Currently the community page isn't able to handle update requests
17         if ($update)
18                 return;
19
20         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
21                 notice( t('Public access denied.') . EOL);
22                 return;
23         }
24
25         if(get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) {
26                 notice( t('Not available.') . EOL);
27                 return;
28         }
29
30         require_once("include/bbcode.php");
31         require_once('include/security.php');
32         require_once('include/conversation.php');
33
34
35         $o .= '<h3>' . t('Community') . '</h3>';
36         if(! $update) {
37                 nav_set_selected('community');
38         }
39
40         if(x($a->data,'search'))
41                 $search = notags(trim($a->data['search']));
42         else
43                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
44
45
46         // Here is the way permissions work in this module...
47         // Only public posts can be shown
48         // OR your own posts if you are a logged in member
49
50         if(get_config('system', 'old_pager')) {
51                 $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total`
52                         FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
53                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
54                         INNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0
55                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
56                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
57                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
58                         AND `item`.`private` = 0 AND `item`.`wall` = 1"
59                 );
60
61                 if(count($r))
62                         $a->set_pager_total($r[0]['total']);
63
64                 if(! $r[0]['total']) {
65                         info( t('No results.') . EOL);
66                         return $o;
67                 }
68
69         }
70
71         $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
72
73         if(! count($r)) {
74                 info( t('No results.') . EOL);
75                 return $o;
76         }
77
78         $maxpostperauthor = get_config('system','max_author_posts_community_page');
79
80         if ($maxpostperauthor != 0) {
81                 $count = 1;
82                 $previousauthor = "";
83                 $numposts = 0;
84                 $s = array();
85
86                 do {
87                         foreach ($r AS $row=>$item) {
88                                 if ($previousauthor == $item["author-link"])
89                                         ++$numposts;
90                                 else
91                                         $numposts = 0;
92
93                                 $previousauthor = $item["author-link"];
94
95                                 if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage']))
96                                         $s[] = $item;
97                         }
98                         if ((sizeof($s) < $a->pager['itemspage']))
99                                 $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
100
101                 } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
102         } else
103                 $s = $r;
104
105         // we behave the same in message lists as the search module
106
107         $o .= conversation($a,$s,'community',$update);
108
109         if(!get_config('system', 'old_pager')) {
110                 $o .= alt_pager($a,count($r));
111         } else {
112                 $o .= paginate($a);
113         }
114
115         return $o;
116 }
117 }
118
119 if(! function_exists('community_getitems')) {
120 function community_getitems($start, $itemspage) {
121         if (get_config('system','community_page_style') == CP_GLOBAL_COMMUNITY)
122                 return(community_getpublicitems($start, $itemspage));
123
124         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
125                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
126                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
127                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
128                 `user`.`nickname`, `user`.`hidewall`
129                 FROM `thread` FORCE INDEX (`wall_private_received`)
130                 INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
131                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
132                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
133                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
134                 INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
135                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
136                 WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
137                 AND `thread`.`private` = 0 AND `thread`.`wall` = 1
138                 ORDER BY `thread`.`received` DESC LIMIT %d, %d ",
139                 intval($start),
140                 intval($itemspage)
141         );
142
143         return($r);
144 }
145 }
146
147 if(! function_exists('community_getpublicitems')) {
148 function community_getpublicitems($start, $itemspage) {
149         $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
150                         `author-name` AS `name`, `owner-avatar` AS `photo`,
151                         `owner-link` AS `url`, `owner-avatar` AS `thumb`
152                 FROM `thread`
153                 INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
154                 WHERE `thread`.`uid` = 0
155                 ORDER BY `thread`.`created` DESC LIMIT %d, %d",
156                 intval($start),
157                 intval($itemspage)
158         );
159
160         return($r);
161 }
162 }