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`, `user`.`timezone`
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'>";
46 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
51 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
53 $entry = replace_macros($tpl,array(
55 '$profile-link' => $profile_link,
56 '$photo' => $rr[$photo],
57 '$alt-text' => $rr['name'],
67 $aside .= "<h3>". t('Last photos'). "</h3>";
68 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
69 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
70 WHERE `profile`=0 AND `height` NOT IN ( 175, 80, 48)
71 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
72 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
74 WHERE `user`.`uid` = `photo`.`uid`
75 AND `user`.`blockwall`=0
76 ORDER BY `photo`.`edited` DESC
79 $aside .= "<div class='items-wrapper'>";
81 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
83 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
84 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
86 $entry = replace_macros($tpl,array(
88 '$profile-link' => $photo_page,
89 '$photo' => $photo_url,
90 '$alt-text' => $rr['username']." : ".$rr['desc'],
98 // last 10 liked items
99 $aside .= "<h3>". t('Last likes'). "</h3>";
100 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
101 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
102 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
103 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
104 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
106 ORDER BY `T1`.`created` DESC
108 $a->get_baseurl(),$a->get_baseurl()
111 $aside .= "<ul id='likes'>";
112 foreach ($r as $rr) {
113 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
114 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
116 //var_dump($rr['verb'],$rr['object-type']); killme();
118 case 'http://activitystrea.ms/schema/1.0/post':
119 switch ($rr['object-type']){
120 case 'http://activitystrea.ms/schema/1.0/event':
121 $post_type = t('event');
124 $post_type = t('status');
128 if ($rr['resource-id']){
129 $post_type = t('photo');
130 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
131 $rr['plink'] = $m[1];
133 $post_type = t('status');
136 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
138 $aside .= "<li>". sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink) ."</li>";
144 $a->page['aside'] = $aside;
146 $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
148 $oldset = get_config('system','no_community_page');
149 set_config('system','no_community_page', false);
150 $o .= community_content($a,1);
151 set_config('system','no_community_page', $oldset);