5 * Description: Show last community activity in homepage
7 * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
11 use Friendica\Core\Addon;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Module\Login;
16 require_once 'mod/community.php';
18 function communityhome_install()
20 Addon::registerHook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
21 logger("installed communityhome");
24 function communityhome_uninstall()
26 Addon::unregisterHook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
27 logger("removed communityhome");
30 function communityhome_getopts()
33 'hidelogin' => L10n::t('Hide login form'),
34 'showlastusers' => L10n::t('Show last new users'),
35 'showlastphotos' => L10n::t('Show last photos'),
36 'showlastlike' => L10n::t('Show last liked items'),
37 'showcommunitystream' => L10n::t('Show community stream')
41 function communityhome_addon_admin(App $a, &$o)
43 $tpl = get_markup_template('settings.tpl', 'addon/communityhome/');
45 $opts = communityhome_getopts();
47 '$submit' => L10n::t("Submit"),
51 foreach ($opts as $k => $v) {
52 $ctx['fields'][] = ['communityhome_' . $k, $v, Config::get('communityhome', $k)];
54 $o = replace_macros($tpl, $ctx);
57 function communityhome_addon_admin_post(App $a)
59 if (x($_POST, 'communityhome-submit')) {
60 $opts = communityhome_getopts();
61 foreach ($opts as $k => $v) {
62 Config::set('communityhome', $k, x($_POST, 'communityhome_' . $k));
67 function communityhome_home(App $a, &$o)
70 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/communityhome/communityhome.css" media="all" />';
72 if (!Config::get('communityhome', 'hidelogin')) {
74 '$tab_1' => L10n::t('Login'),
75 '$tab_2' => L10n::t('OpenID'),
76 '$noOid' => Config::get('system', 'no_openid'),
80 $aside['$login_title'] = L10n::t('Login');
81 $aside['$login_form'] = Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? false : true);
84 //'$tab_1' => L10n::t('Login'),
85 //'$tab_2' => L10n::t('OpenID'),
86 //'$noOid' => Config::get('system','no_openid'),
91 if (Config::get('communityhome', 'showlastusers')) {
92 $aside['$lastusers_title'] = L10n::t('Latest users');
93 $aside['$lastusers_items'] = [];
95 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
96 $order = " ORDER BY `register_date` DESC ";
98 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
99 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
100 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d, %d ",
104 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
105 $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/');
108 foreach ($r as $rr) {
109 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
110 $entry = replace_macros($tpl, [
112 '$profile_link' => $profile_link,
113 '$photo' => $rr[$photo],
114 '$alt_text' => $rr['name'],
116 $aside['$lastusers_items'][] = $entry;
122 if (Config::get('communityhome', 'showlastphotos')) {
123 $aside['$photos_title'] = L10n::t('Latest photos');
124 $aside['$photos_items'] = [];
125 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
126 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
127 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
128 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
129 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
131 WHERE `user`.`uid` = `photo`.`uid`
132 AND `user`.`blockwall`=0
133 AND `user`.`hidewall` = 0
134 ORDER BY `photo`.`edited` DESC
136 dbesc(L10n::t('Contact Photos')),
137 dbesc(L10n::t('Profile Photos'))
142 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
143 $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/');
144 foreach ($r as $rr) {
145 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
146 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg';
148 $entry = replace_macros($tpl, [
150 '$profile_link' => $photo_page,
151 '$photo' => $photo_url,
152 '$photo_user' => $rr['username'],
153 '$photo_title' => $rr['desc']
156 $aside['$photos_items'][] = $entry;
161 // last 10 liked items
162 if (Config::get('communityhome', 'showlastlike')) {
163 $aside['$like_title'] = L10n::t('Latest likes');
164 $aside['$like_items'] = [];
165 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
166 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
167 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
168 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
169 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
171 ORDER BY `T1`.`created` DESC
177 foreach ($r as $rr) {
178 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
179 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
181 //var_dump($rr['verb'],$rr['object-type']); killme();
182 switch ($rr['verb']) {
183 case 'http://activitystrea.ms/schema/1.0/post':
184 switch ($rr['object-type']) {
185 case 'http://activitystrea.ms/schema/1.0/event':
186 $post_type = L10n::t('event');
189 $post_type = L10n::t('status');
193 if ($rr['resource-id']) {
194 $post_type = L10n::t('photo');
196 preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
197 $rr['plink'] = $m[1];
199 $post_type = L10n::t('status');
202 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
204 $aside['$like_items'][] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink);
208 # $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
209 $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
210 $a->page['aside'] = replace_macros($tpl, $aside);
212 $o = '<h1>' . ((x($a->config, 'sitename')) ? L10n::t("Welcome to %s", $a->config['sitename']) : "" ) . '</h1>';
214 if (file_exists('home.html')) $o = file_get_contents('home.html');
216 if (Config::get('communityhome', 'showcommunitystream')) {
217 $oldset = Config::get('system', 'community_page_style');
218 if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', CP_USERS_ON_SERVER);
220 $o .= community_content($a, 1);
222 if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', $oldset);