]> git.mxchange.org Git - friendica-addons.git/blob - communityhome/communityhome.php
Community Home addon
[friendica-addons.git] / communityhome / communityhome.php
1 <?php
2 /**
3  * Name: Community home
4  * Description: Show last community activity in homepage
5  * Version: 1.0
6  * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
7  */
8
9
10 require_once('mod/community.php');
11
12
13 function communityhome_install() {
14         register_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
15         logger("installed communityhome");
16 }
17
18 function communityhome_uninstall() {
19         unregister_hook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
20         logger("removed communityhome");
21 }
22
23 function communityhome_home(&$a, &$o){
24         // custom css
25         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$a->get_baseurl().'/addon/communityhome/communityhome.css" media="all" />';
26         
27         // login form
28         $aside .= "<h3>". t('Login'). "</h3>";
29         $aside .= login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
30         
31         // last 10 users
32         $aside .= "<h3>". t('Last users'). "</h3>";
33         $sql_extra = "";
34         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
35         $order = " ORDER BY `register_date` DESC ";
36
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 ",
40                 0,
41                 10
42         );
43         $aside .= "<div class='items-wrapper'>";
44         if(count($r)) {
45
46                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
47
48                 $photo = 'thumb';
49
50                 foreach($r as $rr) {
51                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
52                 
53                         $entry = replace_macros($tpl,array(
54                                 '$id' => $rr['id'],
55                                 '$profile-link' => $profile_link,
56                                 '$photo' => $rr[$photo],
57                                 '$alt-text' => $rr['name'],
58                         ));
59
60                         $aside .= $entry;
61
62                 }
63         }
64         $aside .= "</div>";
65         
66         // last 10 photos
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`,
73                                 `user` 
74                                 WHERE `user`.`uid` = `photo`.`uid`
75                                 AND `user`.`blockwall`=0
76                                 ORDER BY `photo`.`edited` DESC
77                                 LIMIT 0, 10");
78
79         $aside .= "<div class='items-wrapper'>";                                
80         if(count($r)) {
81                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
82                 foreach($r as $rr) {
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';
85                 
86                         $entry = replace_macros($tpl,array(
87                                 '$id' => $rr['id'],
88                                 '$profile-link' => $photo_page,
89                                 '$photo' => $photo_url,
90                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
91                         ));
92
93                         $aside .= $entry;
94                 }
95         }
96         $aside .= "</div>";
97         
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%%'
105                         GROUP BY `uri`
106                         ORDER BY `T1`.`created` DESC
107                         LIMIT 0,10",
108                         $a->get_baseurl(),$a->get_baseurl()
109                         );
110
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>';
115                 
116                 //var_dump($rr['verb'],$rr['object-type']); killme();
117                 switch($rr['verb']){
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');
122                                                 break;
123                                         default:
124                                                 $post_type = t('status');
125                                 }
126                                 break;
127                         default:
128                                 if ($rr['resource-id']){
129                                         $post_type = t('photo');
130                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
131                                         $rr['plink'] = $m[1];
132                                 } else {
133                                         $post_type = t('status');
134                                 }
135                 }
136                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
137
138                 $aside .= "<li>". sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink) ."</li>";
139                 
140         }
141         $aside .= "</ul>";
142                 
143         
144         $a->page['aside'] = $aside;
145         
146         $o = '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
147         
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);
152 }