5 * Description: Show last community activity in homepage
7 * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
12 use Friendica\Core\Addon;
13 use Friendica\Core\Config;
14 use Friendica\Core\L10n;
15 use Friendica\Module\Login;
17 require_once 'mod/community.php';
19 function communityhome_install()
21 Addon::registerHook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
22 logger("installed communityhome");
25 function communityhome_uninstall()
27 Addon::unregisterHook('home_content', 'addon/communityhome/communityhome.php', 'communityhome_home');
28 logger("removed communityhome");
31 function communityhome_getopts()
34 'hidelogin' => L10n::t('Hide login form'),
35 'showlastusers' => L10n::t('Show last new users'),
36 'showlastphotos' => L10n::t('Show last photos'),
37 'showlastlike' => L10n::t('Show last liked items'),
38 'showcommunitystream' => L10n::t('Show community stream')
42 function communityhome_addon_admin(App $a, &$o)
44 $tpl = get_markup_template('settings.tpl', 'addon/communityhome/');
46 $opts = communityhome_getopts();
48 '$submit' => L10n::t("Submit"),
52 foreach ($opts as $k => $v) {
53 $ctx['fields'][] = ['communityhome_' . $k, $v, Config::get('communityhome', $k)];
55 $o = replace_macros($tpl, $ctx);
58 function communityhome_addon_admin_post(App $a)
60 if (x($_POST, 'communityhome-submit')) {
61 $opts = communityhome_getopts();
62 foreach ($opts as $k => $v) {
63 Config::set('communityhome', $k, x($_POST, 'communityhome_' . $k));
68 function communityhome_home(App $a, &$o)
71 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/communityhome/communityhome.css" media="all" />';
73 if (!Config::get('communityhome', 'hidelogin')) {
75 '$tab_1' => L10n::t('Login'),
76 '$tab_2' => L10n::t('OpenID'),
77 '$noOid' => Config::get('system', 'no_openid'),
81 $aside['$login_title'] = L10n::t('Login');
82 $aside['$login_form'] = Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? false : true);
85 //'$tab_1' => L10n::t('Login'),
86 //'$tab_2' => L10n::t('OpenID'),
87 //'$noOid' => Config::get('system','no_openid'),
92 if (Config::get('communityhome', 'showlastusers')) {
93 $aside['$lastusers_title'] = L10n::t('Latest users');
94 $aside['$lastusers_items'] = [];
96 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
97 $order = " ORDER BY `register_date` DESC ";
99 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
100 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
101 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d, %d ",
105 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
106 $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/');
109 foreach ($r as $rr) {
110 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
111 $entry = replace_macros($tpl, [
113 '$profile_link' => $profile_link,
114 '$photo' => $rr[$photo],
115 '$alt_text' => $rr['name'],
117 $aside['$lastusers_items'][] = $entry;
123 if (Config::get('communityhome', 'showlastphotos')) {
124 $aside['$photos_title'] = L10n::t('Latest photos');
125 $aside['$photos_items'] = [];
126 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
127 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
128 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
129 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
130 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
132 WHERE `user`.`uid` = `photo`.`uid`
133 AND `user`.`blockwall`=0
134 AND `user`.`hidewall` = 0
135 ORDER BY `photo`.`edited` DESC
137 dbesc(L10n::t('Contact Photos')),
138 dbesc(L10n::t('Profile Photos'))
143 # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
144 $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/');
145 foreach ($r as $rr) {
146 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
147 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg';
149 $entry = replace_macros($tpl, [
151 '$profile_link' => $photo_page,
152 '$photo' => $photo_url,
153 '$photo_user' => $rr['username'],
154 '$photo_title' => $rr['desc']
157 $aside['$photos_items'][] = $entry;
162 // last 10 liked items
163 if (Config::get('communityhome', 'showlastlike')) {
164 $aside['$like_title'] = L10n::t('Latest likes');
165 $aside['$like_items'] = [];
166 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
167 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
168 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
169 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
170 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
172 ORDER BY `T1`.`created` DESC
178 foreach ($r as $rr) {
179 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
180 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
182 //var_dump($rr['verb'],$rr['object-type']); killme();
183 switch ($rr['verb']) {
184 case 'http://activitystrea.ms/schema/1.0/post':
185 switch ($rr['object-type']) {
186 case 'http://activitystrea.ms/schema/1.0/event':
187 $post_type = L10n::t('event');
190 $post_type = L10n::t('status');
194 if ($rr['resource-id']) {
195 $post_type = L10n::t('photo');
197 preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
198 $rr['plink'] = $m[1];
200 $post_type = L10n::t('status');
203 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
205 $aside['$like_items'][] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink);
209 # $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
210 $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/');
211 $a->page['aside'] = replace_macros($tpl, $aside);
213 $o = '<h1>' . ((x($a->config, 'sitename')) ? L10n::t("Welcome to %s", $a->config['sitename']) : "" ) . '</h1>';
215 if (file_exists('home.html')) $o = file_get_contents('home.html');
217 if (Config::get('communityhome', 'showcommunitystream')) {
218 $oldset = Config::get('system', 'community_page_style');
219 if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', CP_USERS_ON_SERVER);
221 $o .= community_content($a, 1);
223 if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', $oldset);