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