4 * Description: Show last community activity in homepage
6 * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
10 require_once('mod/community.php');
13 function communityhome_install() {
14 register_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
15 logger("installed communityhome");
18 function communityhome_uninstall() {
19 unregister_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
20 logger("removed communityhome");
23 function communityhome_home(&$a, &$o){
25 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/communityhome/communityhome.css" media="all" />';
27 if (!get_config('communityhome','hidelogin')){
29 '$tab_1' => t('Login'),
30 '$tab_2' => t('OpenID'),
31 '$noOid' => get_config('system','no_openid'),
35 $aside['$login_title'] = t('Login');
36 $aside['$login_form'] = login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
39 //'$tab_1' => t('Login'),
40 //'$tab_2' => t('OpenID'),
41 //'$noOid' => get_config('system','no_openid'),
45 if (get_config('communityhome','showlastusers')===true){
46 $aside['$lastusers_title'] = t('Latest users');
47 $aside['$lastusers_items'] = array();
49 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
50 $order = " ORDER BY `register_date` DESC ";
52 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
53 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
54 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
58 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
59 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
63 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
64 $entry = replace_macros($tpl,array(
66 '$profile_link' => $profile_link,
67 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
68 '$alt_text' => $rr['name'],
70 $aside['$lastusers_items'][] = $entry;
74 // 12 most active users (by posts and contacts)
75 // this query don't work on some mysql versions
76 if (get_config('communityhome','showactiveusers')===true){
77 $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
78 (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
79 (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`,
81 SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
83 SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
84 ) AS `uni`, `user`, `profile`
85 WHERE `uni`.`uid`=`user`.`uid`
86 AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
88 ORDER BY `items` DESC,`contacts` DESC
91 $aside['$activeusers_title'] = t('Most active users');
92 $aside['$activeusers_items'] = array();
96 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
97 $entry = replace_macros($tpl,array(
99 '$profile_link' => $profile_link,
100 '$photo' => $rr[$photo],
101 '$alt_text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
103 $aside['$activeusers_items'][] = $entry;
108 if (get_config('communityhome','showlastphotos')===true){
109 $aside['$photos_title'] = t('Latest photos');
110 $aside['$photos_items'] = array();
111 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
112 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
113 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
114 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
115 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
117 WHERE `user`.`uid` = `photo`.`uid`
118 AND `user`.`blockwall`=0
119 AND `user`.`hidewall` = 0
120 ORDER BY `photo`.`edited` DESC
122 dbesc(t('Contact Photos')),
123 dbesc(t('Profile Photos'))
128 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
129 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
131 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
132 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
134 $entry = replace_macros($tpl,array(
136 '$profile_link' => $photo_page,
137 '$photo' => $photo_url,
138 '$alt_text' => $rr['username']." : ".$rr['desc'],
141 $aside['$photos_items'][] = $entry;
146 // last 10 liked items
147 if (get_config('communityhome','showlastlike')===true){
148 $aside['$like_title'] = t('Latest likes');
149 $aside['$like_items'] = array();
150 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
151 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
152 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
153 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
154 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
156 ORDER BY `T1`.`created` DESC
158 $a->get_baseurl(),$a->get_baseurl()
161 foreach ($r as $rr) {
162 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
163 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
165 //var_dump($rr['verb'],$rr['object-type']); killme();
167 case 'http://activitystrea.ms/schema/1.0/post':
168 switch ($rr['object-type']){
169 case 'http://activitystrea.ms/schema/1.0/event':
170 $post_type = t('event');
173 $post_type = t('status');
177 if ($rr['resource-id']){
178 $post_type = t('photo');
179 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
180 $rr['plink'] = $m[1];
182 $post_type = t('status');
185 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
187 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
192 # $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
193 $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
194 $a->page['aside'] = replace_macros($tpl, $aside);
196 $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
198 if(file_exists('home.html'))
199 $o = file_get_contents('home.html');
201 if (get_config('communityhome','showcommunitystream')===true){
202 $oldset = get_config('system','no_community_page');
203 set_config('system','no_community_page', false);
204 $o .= community_content($a,1);
205 set_config('system','no_community_page', $oldset);