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 $aside['$lastusers_title'] = t('Latest users');
39 $aside['$lastusers_items'] = array();
41 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
42 $order = " ORDER BY `register_date` DESC ";
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 ",
50 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
51 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
55 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
56 $entry = replace_macros($tpl,array(
58 '$profile-link' => $profile_link,
59 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
60 '$alt-text' => $rr['name'],
62 $aside['$lastusers_items'][] = $entry;
66 // 12 most active users (by posts and contacts)
67 // this query don't work on some mysql versions
68 $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
69 (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
70 (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`,
72 SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
74 SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
75 ) AS `uni`, `user`, `profile`
76 WHERE `uni`.`uid`=`user`.`uid`
77 AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
79 ORDER BY `items` DESC,`contacts` DESC
82 $aside['$activeusers_title'] = t('Most active users');
83 $aside['$activeusers_items'] = array();
87 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
88 $entry = replace_macros($tpl,array(
90 '$profile-link' => $profile_link,
91 '$photo' => $rr[$photo],
92 '$alt-text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
94 $aside['$activeusers_items'][] = $entry;
99 $aside['$photos_title'] = t('Latest photos');
100 $aside['$photos_items'] = array();
101 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
102 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
103 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
104 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
105 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
107 WHERE `user`.`uid` = `photo`.`uid`
108 AND `user`.`blockwall`=0
109 AND `user`.`hidewall` = 0
110 ORDER BY `photo`.`edited` DESC
112 dbesc(t('Contact Photos')),
113 dbesc(t('Profile Photos'))
118 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
119 $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' );
121 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
122 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
124 $entry = replace_macros($tpl,array(
126 '$profile-link' => $photo_page,
127 '$photo' => $photo_url,
128 '$alt-text' => $rr['username']." : ".$rr['desc'],
131 $aside['$photos_items'][] = $entry;
135 // last 10 liked items
136 $aside['$like_title'] = t('Latest likes');
137 $aside['$like_items'] = array();
138 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
139 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
140 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
141 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
142 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
144 ORDER BY `T1`.`created` DESC
146 $a->get_baseurl(),$a->get_baseurl()
149 foreach ($r as $rr) {
150 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
151 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
153 //var_dump($rr['verb'],$rr['object-type']); killme();
155 case 'http://activitystrea.ms/schema/1.0/post':
156 switch ($rr['object-type']){
157 case 'http://activitystrea.ms/schema/1.0/event':
158 $post_type = t('event');
161 $post_type = t('status');
165 if ($rr['resource-id']){
166 $post_type = t('photo');
167 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
168 $rr['plink'] = $m[1];
170 $post_type = t('status');
173 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
175 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
179 # $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
180 $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
181 $a->page['aside'] = replace_macros($tpl, $aside);
183 $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
185 $oldset = get_config('system','no_community_page');
186 set_config('system','no_community_page', false);
187 $o .= community_content($a,1);
188 set_config('system','no_community_page', $oldset);