From cc6108d9caa35384e16a050012cd7def687c2262 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 7 Mar 2018 13:59:02 -0500 Subject: [PATCH 1/4] [communityhome] Fix formatting --- communityhome/communityhome.php | 132 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/communityhome/communityhome.php b/communityhome/communityhome.php index 78d9fe8a..11309635 100644 --- a/communityhome/communityhome.php +++ b/communityhome/communityhome.php @@ -1,4 +1,5 @@ L10n::t('Hide login form'), - 'showlastusers'=>L10n::t('Show last new users'), - 'showactiveusers'=>L10n::t('Show last active users'), - 'showlastphotos'=>L10n::t('Show last photos'), - 'showlastlike'=>L10n::t('Show last liked items'), - 'showcommunitystream'=>L10n::t('Show community stream') + 'hidelogin' => L10n::t('Hide login form'), + 'showlastusers' => L10n::t('Show last new users'), + 'showactiveusers' => L10n::t('Show last active users'), + 'showlastphotos' => L10n::t('Show last photos'), + 'showlastlike' => L10n::t('Show last liked items'), + 'showcommunitystream' => L10n::t('Show community stream') ]; } @@ -45,7 +48,7 @@ function communityhome_addon_admin(&$a, &$o) ]; foreach ($opts as $k => $v) { - $ctx['fields'][] = ['communityhome_'.$k, $v, Config::get('communityhome', $k)]; + $ctx['fields'][] = ['communityhome_' . $k, $v, Config::get('communityhome', $k)]; } $o = replace_macros($tpl, $ctx); } @@ -55,27 +58,27 @@ function communityhome_addon_admin_post(&$a, &$b) if (x($_POST, 'communityhome-submit')) { $opts = communityhome_getopts(); foreach ($opts as $k => $v) { - Config::set('communityhome', $k, x($_POST, 'communityhome_'.$k)); + Config::set('communityhome', $k, x($_POST, 'communityhome_' . $k)); } } } - -function communityhome_home(&$a, &$o){ +function communityhome_home(&$a, &$o) +{ // custom css - $a->page['htmlhead'] .= ''; + $a->page['htmlhead'] .= ''; - if (!Config::get('communityhome','hidelogin')){ + if (!Config::get('communityhome', 'hidelogin')) { $aside = [ '$tab_1' => L10n::t('Login'), '$tab_2' => L10n::t('OpenID'), - '$noOid' => Config::get('system','no_openid'), + '$noOid' => Config::get('system', 'no_openid'), ]; // login form - $aside['$login_title'] = L10n::t('Login'); + $aside['$login_title'] = L10n::t('Login'); $aside['$login_form'] = Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? false : true); - } else { + } else { $aside = [ //'$tab_1' => L10n::t('Login'), //'$tab_2' => L10n::t('OpenID'), @@ -84,26 +87,26 @@ function communityhome_home(&$a, &$o){ } // last 12 users - if (Config::get('communityhome','showlastusers')){ + if (Config::get('communityhome', 'showlastusers')) { $aside['$lastusers_title'] = L10n::t('Latest users'); $aside['$lastusers_items'] = []; $sql_extra = ""; - $publish = (Config::get('system','publish_all') ? '' : " AND `publish` = 1 " ); + $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " ); $order = " ORDER BY `register_date` DESC "; $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ", + WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d, %d ", 0, 12 ); - # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl'); - $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' ); - if(count($r)) { + # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl'); + $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/'); + if (count($r)) { $photo = 'thumb'; - foreach($r as $rr) { + foreach ($r as $rr) { $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); - $entry = replace_macros($tpl,[ + $entry = replace_macros($tpl, [ '$id' => $rr['id'], '$profile_link' => $profile_link, '$photo' => $rr[$photo], @@ -115,7 +118,7 @@ function communityhome_home(&$a, &$o){ } // 12 most active users (by posts and contacts) // this query don't work on some mysql versions - if (Config::get('communityhome','showactiveusers')){ + if (Config::get('communityhome', 'showactiveusers')) { $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM (SELECT COUNT(*) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`, (SELECT COUNT(*) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`, @@ -129,25 +132,26 @@ function communityhome_home(&$a, &$o){ GROUP BY `uid` ORDER BY `items` DESC,`contacts` DESC LIMIT 0,10"); - if($r && count($r)) { - $aside['$activeusers_title'] = L10n::t('Most active users'); - $aside['$activeusers_items'] = []; + if ($r && count($r)) { + $aside['$activeusers_title'] = L10n::t('Most active users'); + $aside['$activeusers_items'] = []; $photo = 'thumb'; - foreach($r as $rr) { + foreach ($r as $rr) { $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); - $entry = replace_macros($tpl,[ + $entry = replace_macros($tpl, [ '$id' => $rr['id'], '$profile_link' => $profile_link, '$photo' => $rr[$photo], - '$photo_user' => sprintf("%s (%s posts, %s contacts)",$rr['name'], ($rr['items']?$rr['items']:'0'), ($rr['contacts']?$rr['contacts']:'0')) + '$photo_user' => sprintf("%s (%s posts, %s contacts)", $rr['name'], ($rr['items'] ? $rr['items'] : '0'), + ($rr['contacts'] ? $rr['contacts'] : '0')) ]); $aside['$activeusers_items'][] = $entry; } } } // last 12 photos - if (Config::get('communityhome','showlastphotos')){ + if (Config::get('communityhome', 'showlastphotos')) { $aside['$photos_title'] = L10n::t('Latest photos'); $aside['$photos_items'] = []; $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM @@ -161,19 +165,19 @@ function communityhome_home(&$a, &$o){ AND `user`.`hidewall` = 0 ORDER BY `photo`.`edited` DESC LIMIT 0, 12", - dbesc(L10n::t('Contact Photos')), - dbesc(L10n::t('Profile Photos')) - ); + dbesc(L10n::t('Contact Photos')), + dbesc(L10n::t('Profile Photos')) + ); - if(count($r)) { - # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl'); - $tpl = get_markup_template( 'directory_item.tpl', 'addon/communityhome/' ); - foreach($r as $rr) { + if (count($r)) { + # $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl'); + $tpl = get_markup_template('directory_item.tpl', 'addon/communityhome/'); + foreach ($r as $rr) { $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id']; - $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg'; + $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg'; - $entry = replace_macros($tpl,[ + $entry = replace_macros($tpl, [ '$id' => $rr['id'], '$profile_link' => $photo_page, '$photo' => $photo_url, @@ -187,7 +191,7 @@ function communityhome_home(&$a, &$o){ } // last 10 liked items - if (Config::get('communityhome','showlastlike')){ + if (Config::get('communityhome', 'showlastlike')) { $aside['$like_title'] = L10n::t('Latest likes'); $aside['$like_items'] = []; $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM @@ -198,17 +202,18 @@ function communityhome_home(&$a, &$o){ GROUP BY `uri` ORDER BY `T1`.`created` DESC LIMIT 0,10", - $a->get_baseurl(),$a->get_baseurl() - ); + $a->get_baseurl(), + $a->get_baseurl() + ); foreach ($r as $rr) { - $author = '' . $rr['liker'] . ''; - $objauthor = '' . $rr['author-name'] . ''; + $author = '' . $rr['liker'] . ''; + $objauthor = '' . $rr['author-name'] . ''; //var_dump($rr['verb'],$rr['object-type']); killme(); - switch($rr['verb']){ + switch ($rr['verb']) { case 'http://activitystrea.ms/schema/1.0/post': - switch ($rr['object-type']){ + switch ($rr['object-type']) { case 'http://activitystrea.ms/schema/1.0/event': $post_type = L10n::t('event'); break; @@ -217,9 +222,10 @@ function communityhome_home(&$a, &$o){ } break; default: - if ($rr['resource-id']){ + if ($rr['resource-id']) { $post_type = L10n::t('photo'); - $m=[]; preg_match("/\[url=([^]]*)\]/", $rr['body'], $m); + $m = []; + preg_match("/\[url=([^]]*)\]/", $rr['body'], $m); $rr['plink'] = $m[1]; } else { $post_type = L10n::t('status'); @@ -228,7 +234,6 @@ function communityhome_home(&$a, &$o){ $plink = '' . $post_type . ''; $aside['$like_items'][] = L10n::t('%1$s likes %2$s\'s %3$s', $author, $objauthor, $plink); - } } @@ -236,19 +241,16 @@ function communityhome_home(&$a, &$o){ $tpl = get_markup_template('communityhome.tpl', 'addon/communityhome/'); $a->page['aside'] = replace_macros($tpl, $aside); - $o = '

' . ((x($a->config,'sitename')) ? L10n::t("Welcome to %s", $a->config['sitename']) : "" ) . '

'; + $o = '

' . ((x($a->config, 'sitename')) ? L10n::t("Welcome to %s", $a->config['sitename']) : "" ) . '

'; - if(file_exists('home.html')) - $o = file_get_contents('home.html'); + if (file_exists('home.html')) $o = file_get_contents('home.html'); - if (Config::get('communityhome','showcommunitystream')){ - $oldset = Config::get('system','community_page_style'); - if ($oldset == CP_NO_COMMUNITY_PAGE) - Config::set('system','community_page_style', CP_USERS_ON_SERVER); + if (Config::get('communityhome', 'showcommunitystream')) { + $oldset = Config::get('system', 'community_page_style'); + if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', CP_USERS_ON_SERVER); - $o .= community_content($a,1); + $o .= community_content($a, 1); - if ($oldset == CP_NO_COMMUNITY_PAGE) - Config::set('system','community_page_style', $oldset); + if ($oldset == CP_NO_COMMUNITY_PAGE) Config::set('system', 'community_page_style', $oldset); } } From 9a30d2663dc693de1dd66fcbbb051f2611b7f159 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 7 Mar 2018 14:00:48 -0500 Subject: [PATCH 2/4] [communityhome] Remove extra parameter in communityhome_addon_admin_post() - Add type hint for Friendica\App object --- communityhome/communityhome.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/communityhome/communityhome.php b/communityhome/communityhome.php index 11309635..a4c956c2 100644 --- a/communityhome/communityhome.php +++ b/communityhome/communityhome.php @@ -6,6 +6,8 @@ * Version: 2.0 * Author: Fabio Comuni */ + +use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -37,7 +39,7 @@ function communityhome_getopts() ]; } -function communityhome_addon_admin(&$a, &$o) +function communityhome_addon_admin(App $a, &$o) { $tpl = get_markup_template('settings.tpl', 'addon/communityhome/'); @@ -53,7 +55,7 @@ function communityhome_addon_admin(&$a, &$o) $o = replace_macros($tpl, $ctx); } -function communityhome_addon_admin_post(&$a, &$b) +function communityhome_addon_admin_post(App $a) { if (x($_POST, 'communityhome-submit')) { $opts = communityhome_getopts(); @@ -63,7 +65,7 @@ function communityhome_addon_admin_post(&$a, &$b) } } -function communityhome_home(&$a, &$o) +function communityhome_home(App $a, &$o) { // custom css $a->page['htmlhead'] .= ''; From b739a08e22319851aafc2b507f0001f8183455f4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 7 Mar 2018 14:13:02 -0500 Subject: [PATCH 3/4] [communityhome] Remove active user feature - Updated README with latest addon state --- communityhome/README.md | 35 ++++++----------------- communityhome/communityhome.php | 34 ---------------------- communityhome/templates/communityhome.tpl | 13 ++------- 3 files changed, 11 insertions(+), 71 deletions(-) diff --git a/communityhome/README.md b/communityhome/README.md index 91838d9f..61bbc99a 100644 --- a/communityhome/README.md +++ b/communityhome/README.md @@ -1,34 +1,17 @@ Community Home -------------- -This addon overwrites the default home page shown to not logged users. -On sidebar there are the login form, last ten users (if they have -choosed to be in site directory), last ten public photos and last ten -"likes" sent by a site user or about a site user's item +This addon overwrites the default home page shown to anonymous users. +On the sidebar there are the login form, last ten users (if they chose +to be in the site directory), last ten public photos and last ten +"likes" sent by a site user or about a site user's item. -In main content is shown the community stream. This addon doesn't -honour your community page visibility site setting: the community +In the main content is shown the community stream. This addon doesn't +honor your community page visibility site setting: the community stream is shown also if you have choose to not show the community page. -If 'home.html' is found in your friendica root, its content is inserted +If 'home.html' is found in your friendica root, its content is inserted before community stream -Each elements can be show or not. At the moment, there is no admin page -for settings, so this settings must be added to yout .htconfig.php - - - $a->config['communityhome']['showcommunitystream'] = true; - $a->config['communityhome']['showlastlike'] = true; - $a->config['communityhome']['showlastphotos'] = true; - $a->config['communityhome']['showactiveusers'] = true; - $a->config['communityhome']['showlastusers'] = true; - -If you don't want to show something, set it to false. - -Note: ------ - -- Default is "false". With no settings in .htconfig.php, nothing is -shown, except login form and content of 'home.html' - -- Active users query can be heavy for db, and on some system don't work +By default no features are enabled, you can edit this addon's settings +through the admin panel. \ No newline at end of file diff --git a/communityhome/communityhome.php b/communityhome/communityhome.php index a4c956c2..2024133f 100644 --- a/communityhome/communityhome.php +++ b/communityhome/communityhome.php @@ -32,7 +32,6 @@ function communityhome_getopts() return [ 'hidelogin' => L10n::t('Hide login form'), 'showlastusers' => L10n::t('Show last new users'), - 'showactiveusers' => L10n::t('Show last active users'), 'showlastphotos' => L10n::t('Show last photos'), 'showlastlike' => L10n::t('Show last liked items'), 'showcommunitystream' => L10n::t('Show community stream') @@ -118,40 +117,7 @@ function communityhome_home(App $a, &$o) } } } - // 12 most active users (by posts and contacts) - // this query don't work on some mysql versions - if (Config::get('communityhome', 'showactiveusers')) { - $r = q("SELECT `uni`.`contacts`,`uni`.`items`, `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname` FROM - (SELECT COUNT(*) as `contacts`, `uid` FROM `contact` WHERE `self`=0 GROUP BY `uid`) AS `con`, - (SELECT COUNT(*) as `items`, `uid` FROM `item` WHERE `item`.`changed` > DATE(NOW() - INTERVAL 1 MONTH) AND `item`.`wall` = 1 GROUP BY `uid`) AS `ite`, - ( - SELECT `contacts`,`items`,`ite`.`uid` FROM `con` RIGHT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid` - UNION ALL - SELECT `contacts`,`items`,`con`.`uid` FROM `con` LEFT OUTER JOIN `ite` ON `con`.`uid`=`ite`.`uid` - ) AS `uni`, `user`, `profile` - WHERE `uni`.`uid`=`user`.`uid` - AND `uni`.`uid`=`profile`.`uid` AND `profile`.`publish`=1 - GROUP BY `uid` - ORDER BY `items` DESC,`contacts` DESC - LIMIT 0,10"); - if ($r && count($r)) { - $aside['$activeusers_title'] = L10n::t('Most active users'); - $aside['$activeusers_items'] = []; - $photo = 'thumb'; - foreach ($r as $rr) { - $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); - $entry = replace_macros($tpl, [ - '$id' => $rr['id'], - '$profile_link' => $profile_link, - '$photo' => $rr[$photo], - '$photo_user' => sprintf("%s (%s posts, %s contacts)", $rr['name'], ($rr['items'] ? $rr['items'] : '0'), - ($rr['contacts'] ? $rr['contacts'] : '0')) - ]); - $aside['$activeusers_items'][] = $entry; - } - } - } // last 12 photos if (Config::get('communityhome', 'showlastphotos')) { $aside['$photos_title'] = L10n::t('Latest photos'); diff --git a/communityhome/templates/communityhome.tpl b/communityhome/templates/communityhome.tpl index b8f80381..c2e458be 100644 --- a/communityhome/templates/communityhome.tpl +++ b/communityhome/templates/communityhome.tpl @@ -15,9 +15,9 @@ $("#tab_1").removeClass("active"); e.preventDefault(); return false; - + }); - + }); {{if $noOid}} @@ -41,15 +41,6 @@ {{/if}} -{{if $activeusers_title}} -

{{$activeusers_title}}

-
-{{foreach $activeusers_items as $i}} - {{$i}} -{{/foreach}} -
-{{/if}} - {{if $photos_title}}

{{$photos_title}}

From 35dfae16454a44e9428cc8e673a71d31bfee09db Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 8 Mar 2018 04:47:47 -0500 Subject: [PATCH 4/4] [communityhome] Add Unsupported flag --- communityhome/communityhome.php | 1 + 1 file changed, 1 insertion(+) diff --git a/communityhome/communityhome.php b/communityhome/communityhome.php index 2024133f..dc0a6baf 100644 --- a/communityhome/communityhome.php +++ b/communityhome/communityhome.php @@ -5,6 +5,7 @@ * Description: Show last community activity in homepage * Version: 2.0 * Author: Fabio Comuni + * Status: Unsupported */ use Friendica\App;