]> git.mxchange.org Git - friendica-addons.git/blob - communityhome/twillingham/communityhome.php
Merge remote branch 'friendica/master'
[friendica-addons.git] / communityhome / twillingham / communityhome.php
1 <?php
2 /**
3  * Name: Community home
4  * Description: Show last community activity in homepage
5  * Version: 1.0
6  * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
7  */
8
9
10 require_once('mod/community.php');
11
12
13 function communityhome_install() {
14         register_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
15         logger("installed communityhome");
16 }
17
18 function communityhome_uninstall() {
19         unregister_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
20         logger("removed communityhome");
21 }
22
23 function communityhome_home(&$a, &$o){
24         // custom css
25         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/communityhome/communityhome.css" media="all" />';
26         
27         $aside = array(
28                 '$tab_1' => t('Login'),
29                 '$tab_2' => t('OpenID'),
30                 '$noOid' => get_config('system','no_openid'),
31         );
32         
33         // login form
34         $aside['$login_title'] =  t('Login');
35         $aside['$login_form'] = login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
36         
37         // last 12 users
38         $aside['$lastusers_title'] = t('Latest users');
39         $aside['$lastusers_items'] = array();
40         $sql_extra = "";
41         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
42         $order = " ORDER BY `register_date` DESC ";
43
44         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
45                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
46                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
47                 0,
48                 12
49         );
50         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
51         if(count($r)) {
52                 $photo = 'thumb';
53                 foreach($r as $rr) {
54                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
55                         $entry = replace_macros($tpl,array(
56                                 '$id' => $rr['id'],
57                                 '$profile-link' => $profile_link,
58                                 '$photo' => $rr[$photo],
59                                 '$alt-text' => $rr['name'],
60                         ));
61                         $aside['$lastusers_items'][] = $entry;
62                 }
63         }
64         
65         // 12 most active users (by posts and contacts)
66         // this query don't work on some mysql versions
67         $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`  FROM
68                         (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
69                         (SELECT COUNT(`id`) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`,
70                         (
71                         SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid` 
72                         UNION ALL 
73                         SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
74                         ) AS `uni`, `user`, `profile`
75                         WHERE `uni`.`uid`=`user`.`uid`
76                         AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
77                         GROUP BY `uid`
78                         ORDER BY `items` DESC,`contacts` DESC
79                         LIMIT 0,10");
80         if($r && count($r)) {
81                 $aside['$activeusers_title']  = t('Most active users');
82                 $aside['$activeusers_items']  = array();
83                 
84                 $photo = 'thumb';
85                 foreach($r as $rr) {
86                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
87                         $entry = replace_macros($tpl,array(
88                                 '$id' => $rr['id'],
89                                 '$profile-link' => $profile_link,
90                                 '$photo' => $rr[$photo],
91                                 '$alt-text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
92                         ));
93                         $aside['$activeusers_items'][] = $entry;
94                 }
95         }
96         
97         
98         
99         
100         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
101         $a->page['aside'] = replace_macros($tpl, $aside);
102         $o = '';
103         if(file_exists('home.html'))
104         
105                 $o .= file_get_contents('home.html');
106         
107 }