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 $aside .= "<h3>". t('Login'). "</h3>";
29 $aside .= login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
32 $aside .= "<h3>". t('Last users'). "</h3>";
34 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
35 $order = " ORDER BY `register_date` DESC ";
37 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
38 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
39 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
43 $aside .= "<div class='items-wrapper'>";
44 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
48 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
49 $entry = replace_macros($tpl,array(
51 '$profile-link' => $profile_link,
52 '$photo' => $rr[$photo],
53 '$alt-text' => $rr['name'],
60 // 12 most active users (by posts and contacts)
61 // this query don't work on some mysql versions
62 $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM
63 (SELECT COUNT(`id`) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`,
64 (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`,
66 SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
68 SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid`
69 ) AS `uni`, `user`, `profile`
70 WHERE `uni`.`uid`=`user`.`uid`
71 AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1
73 ORDER BY `items` DESC,`contacts` DESC
76 $aside .= "<h3>". t('Most active users'). "</h3>";
77 $aside .= "<div class='items-wrapper'>";
81 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
82 $entry = replace_macros($tpl,array(
84 '$profile-link' => $profile_link,
85 '$photo' => $rr[$photo],
86 '$alt-text' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0'))
94 $aside .= "<h3>". t('Last photos'). "</h3>";
95 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
96 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
97 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
98 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
99 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
101 WHERE `user`.`uid` = `photo`.`uid`
102 AND `user`.`blockwall`=0
103 ORDER BY `photo`.`edited` DESC
105 dbesc(t('Contact Photos')),
106 dbesc(t('Profile Photos'))
109 $aside .= "<div class='items-wrapper'>";
111 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
113 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
114 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
116 $entry = replace_macros($tpl,array(
118 '$profile-link' => $photo_page,
119 '$photo' => $photo_url,
120 '$alt-text' => $rr['username']." : ".$rr['desc'],
128 // last 10 liked items
129 $aside .= "<h3>". t('Last likes'). "</h3>";
130 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
131 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
132 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
133 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
134 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
136 ORDER BY `T1`.`created` DESC
138 $a->get_baseurl(),$a->get_baseurl()
141 $aside .= "<ul id='likes'>";
142 foreach ($r as $rr) {
143 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
144 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
146 //var_dump($rr['verb'],$rr['object-type']); killme();
148 case 'http://activitystrea.ms/schema/1.0/post':
149 switch ($rr['object-type']){
150 case 'http://activitystrea.ms/schema/1.0/event':
151 $post_type = t('event');
154 $post_type = t('status');
158 if ($rr['resource-id']){
159 $post_type = t('photo');
160 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
161 $rr['plink'] = $m[1];
163 $post_type = t('status');
166 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
168 $aside .= "<li>". sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink) ."</li>";
174 $a->page['aside'] = $aside;
176 $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
178 $oldset = get_config('system','no_community_page');
179 set_config('system','no_community_page', false);
180 $o .= community_content($a,1);
181 set_config('system','no_community_page', $oldset);