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" />';
28 '$tab_1' => t('Login'),
29 '$tab_2' => t('OpenID'),
30 '$noOid' => get_config('system','no_openid'),
34 $aside['$login_title'] = t('Login');
35 $aside['$login_form'] = login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
38 if (get_config('communityhome','showlastusers')===true){
39 $aside['$lastusers_title'] = t('Latest users');
40 $aside['$lastusers_items'] = array();
42 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
43 $order = " ORDER BY `register_date` DESC ";
45 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
46 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
47 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
51 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
52 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
56 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
57 $entry = replace_macros($tpl,array(
59 '$profile_link' => $profile_link,
60 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
61 '$alt_text' => $rr['name'],
63 $aside['$lastusers_items'][] = $entry;
67 // 12 most active users (by posts and contacts)
68 // this query don't work on some mysql versions
69 if (get_config('communityhome','showactiveusers')===true){
70 $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
71 (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
72 (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`,
74 SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
76 SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
77 ) AS `uni`, `user`, `profile`
78 WHERE `uni`.`uid`=`user`.`uid`
79 AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
81 ORDER BY `items` DESC,`contacts` DESC
84 $aside['$activeusers_title'] = t('Most active users');
85 $aside['$activeusers_items'] = array();
89 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
90 $entry = replace_macros($tpl,array(
92 '$profile_link' => $profile_link,
93 '$photo' => $rr[$photo],
94 '$alt_text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
96 $aside['$activeusers_items'][] = $entry;
101 if (get_config('communityhome','showlastphotos')===true){
102 $aside['$photos_title'] = t('Latest photos');
103 $aside['$photos_items'] = array();
104 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
105 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
106 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
107 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
108 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
110 WHERE `user`.`uid` = `photo`.`uid`
111 AND `user`.`blockwall`=0
112 AND `user`.`hidewall` = 0
113 ORDER BY `photo`.`edited` DESC
115 dbesc(t('Contact Photos')),
116 dbesc(t('Profile Photos'))
121 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
122 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
124 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
125 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
127 $entry = replace_macros($tpl,array(
129 '$profile_link' => $photo_page,
130 '$photo' => $photo_url,
131 '$alt_text' => $rr['username']." : ".$rr['desc'],
134 $aside['$photos_items'][] = $entry;
139 // last 10 liked items
140 if (get_config('communityhome','showlastlike')===true){
141 $aside['$like_title'] = t('Latest likes');
142 $aside['$like_items'] = array();
143 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
144 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
145 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
146 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
147 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
149 ORDER BY `T1`.`created` DESC
151 $a->get_baseurl(),$a->get_baseurl()
154 foreach ($r as $rr) {
155 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
156 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
158 //var_dump($rr['verb'],$rr['object-type']); killme();
160 case 'http://activitystrea.ms/schema/1.0/post':
161 switch ($rr['object-type']){
162 case 'http://activitystrea.ms/schema/1.0/event':
163 $post_type = t('event');
166 $post_type = t('status');
170 if ($rr['resource-id']){
171 $post_type = t('photo');
172 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
173 $rr['plink'] = $m[1];
175 $post_type = t('status');
178 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
180 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
185 # $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
186 $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
187 $a->page['aside'] = replace_macros($tpl, $aside);
189 $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
191 if(file_exists('home.html'))
192 $o = file_get_contents('home.html');
194 if (get_config('communityhome','showcommunitystream')===true){
195 $oldset = get_config('system','no_community_page');
196 set_config('system','no_community_page', false);
197 $o .= community_content($a,1);
198 set_config('system','no_community_page', $oldset);