From 96b764425ea38cdd0d2f5259549a58d4718315ef Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 9 Nov 2015 15:56:20 +0100 Subject: [PATCH] move forumlist addon to core --- include/features.php | 41 ++++---- include/forums.php | 148 ++++++++++++++++++++++++++++ include/identity.php | 8 ++ mod/network.php | 2 + view/global.css | 41 ++++++-- view/templates/profile_advanced.tpl | 6 ++ view/templates/widget_forumlist.tpl | 45 +++++++++ 7 files changed, 267 insertions(+), 24 deletions(-) create mode 100644 include/forums.php create mode 100644 view/templates/widget_forumlist.tpl diff --git a/include/features.php b/include/features.php index 1307132a64..8eee2daa17 100644 --- a/include/features.php +++ b/include/features.php @@ -29,39 +29,46 @@ function get_features() { // Post composition 'composition' => array( t('Post Composition Features'), - array('richtext', t('Richtext Editor'), t('Enable richtext editor')), - array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them')), + array('richtext', t('Richtext Editor'), t('Enable richtext editor')), + array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them')), array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a fourm page is selected/deselected in ACL window.')), ), // Network sidebar widgets 'widgets' => array( t('Network Sidebar Widgets'), - array('archives', t('Search by Date'), t('Ability to select posts by date ranges')), - array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group')), - array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network')), - array('savedsearch', t('Saved Searches'), t('Save search terms for re-use')), + array('archives', t('Search by Date'), t('Ability to select posts by date ranges')), + array('forumlist', t('List Forums'), t('Enable widget to display the forums your are connected with')), + array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group')), + array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network')), + array('savedsearch', t('Saved Searches'), t('Save search terms for re-use')), ), // Network tabs 'net_tabs' => array( t('Network Tabs'), - array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on')), - array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)')), - array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them')), + array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on')), + array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)')), + array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them')), ), // Item tools 'tools' => array( t('Post/Comment Tools'), - array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once')), - array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending')), - array('commtag', t('Tagging'), t('Ability to tag existing posts')), - array('categories', t('Post Categories'), t('Add categories to your posts')), - array('filing', t('Saved Folders'), t('Ability to file posts under folders')), - array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments')), - array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator')), - array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread')), + array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once')), + array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending')), + array('commtag', t('Tagging'), t('Ability to tag existing posts')), + array('categories', t('Post Categories'), t('Add categories to your posts')), + array('filing', t('Saved Folders'), t('Ability to file posts under folders')), + array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments')), + array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator')), + array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread')), + ), + + // Advanced Profile Settings + 'advanced_profile' => array( + t('Advanced Profile Settings'), + array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page')), ), ); diff --git a/include/forums.php b/include/forums.php new file mode 100644 index 0000000000..c515162420 --- /dev/null +++ b/include/forums.php @@ -0,0 +1,148 @@ + forum url + * 'name' => forum name + * 'id' => number of the key from the array + * 'micro' => contact photo in format micro + */ +function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) { + + $forumlist = array(); + + $order = (($showhidden) ? '' : " AND `hidden` = 0 "); + $order .= (($lastitem) ? ' ORDER BY `last-item` ASC ' : ' ORDER BY `name` ASC '); + $select = "`forum` = 1"; + if ($showprivate) { + $select = "( `forum` = 1 OR `prv` = 1 )"; + } + + $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM contact + WHERE `network`= 'dfrn' AND $select AND `uid` = %d + AND `blocked` = 0 AND `hidden` = 0 AND `pending` = 0 AND `archive` = 0 + $order ", + intval($uid) + ); + + foreach($contacts as $contact) { + $forumlist[] = array( + 'url' => $contact['url'], + 'name' => $contact['name'], + 'id' => $contact['id'], + 'micro' => $contact['micro'], + ); + } + return($forumlist); +} + + +/* + * @brief forumlist widget + * + * Sidebar widget to show subcribed friendica forums. If activated + * in the settings, it appears at the notwork page sidebar + * + * @param App $a + * @return string + */ +function widget_forumlist($a) { + + if(! intval(feature_enabled(local_user(),'forumlist'))) + return; + + $o = ''; + + //sort by last updated item + $lastitem = true; + + $contacts = get_forumlist($a->user['uid'],true,$lastitem, true); + $total = count($contacts); + $visible_forums = 10; + + if(count($contacts)) { + + $id = 0; + + foreach($contacts as $contact) { + + $entry = array( + 'url' => $a->get_baseurl() . '/network?f=&cid=' . $contact['id'], + 'external_url' => $a->get_baseurl() . '/redir/' . $contact['id'], + 'name' => $contact['name'], + 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO), + 'id' => ++$id, + ); + $entries[] = $entry; + } + + $tpl = get_markup_template('widget_forumlist.tpl'); + + $o .= replace_macros($tpl,array( + '$title' => t("Forums"), + '$forums' => $entries, + '$link_desc' => t('External link to forum'), + '$total' => $total, + '$visible_forums' => $visible_forums, + '$showmore' => t('show more'), + )); + } + + return $o; +} + +/* + * @brief format forumlist as contact block + * + * This function is used to show the forumlist in + * the advanced profile. + * + * @param int $uid + * @return string + * + */ +function forumlist_profile_advanced($uid) { + + $profile = intval(feature_enabled($uid,'forumlist_profile')); + if(! $profile) + return; + + $o = ''; + + // place holder in case somebody wants configurability + $show_total = 9999; + + //don't sort by last updated item + $lastitem = false; + + $contacts = get_forumlist($uid,false,$lastitem,false); + + $total_shown = 0; + + foreach($contacts as $contact) { + $forumlist .= micropro($contact,false,'forumlist-profile-advanced'); + $total_shown ++; + if($total_shown == $show_total) + break; + } + + if(count($contacts) > 0) + $o .= $forumlist; + return $o; +} \ No newline at end of file diff --git a/include/identity.php b/include/identity.php index 6faddffd3c..fad7c99ddc 100644 --- a/include/identity.php +++ b/include/identity.php @@ -525,6 +525,7 @@ if(! function_exists('get_events')) { function advanced_profile(&$a) { $o = ''; + $uid = $a->profile['uid']; $o .= replace_macros(get_markup_template("section_title.tpl"),array( '$title' => t('Profile') @@ -603,6 +604,13 @@ function advanced_profile(&$a) { if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt); if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt ); + + //show subcribed forum if it is enabled in the usersettings + if (feature_enabled($uid,'forumlist_profile')) { + require_once('include/forums.php'); + $show_forumlist = true; + $profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid)); + } if ($a->profile['uid'] == local_user()) $profile['edit'] = array($a->get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile')); diff --git a/mod/network.php b/mod/network.php index 42c416b32f..07a6bbd8e6 100644 --- a/mod/network.php +++ b/mod/network.php @@ -112,6 +112,7 @@ function network_init(&$a) { require_once('include/group.php'); require_once('include/contact_widgets.php'); require_once('include/items.php'); + require_once('include/forums.php'); if(! x($a->page,'aside')) $a->page['aside'] = ''; @@ -145,6 +146,7 @@ function network_init(&$a) { } $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network',true,$group_id) : ''); + $a->page['aside'] .= (feature_enabled(local_user(),'forumlist') ? widget_forumlist($a) : ''); $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false); $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : '')); $a->page['aside'] .= saved_searches($search); diff --git a/view/global.css b/view/global.css index 1a71b21951..29373941e3 100644 --- a/view/global.css +++ b/view/global.css @@ -260,29 +260,56 @@ a { } /* poke */ #poke-desc { - margin: 5px 0 10px; + margin: 5px 0 10px; } #poke-wrapper { - padding: 10px 0 0px; + padding: 10px 0 0px; } #poke-recipient, #poke-action, #poke-privacy-settings { - margin: 10px 0 30px; + margin: 10px 0 30px; } #poke-recip-label, #poke-action-label, #prvmail-message-label { - margin: 10px 0 10px; + margin: 10px 0 10px; } ul.credits { - list-style: none; + list-style: none; } ul.credits li { - float: left; - width: 240px; + float: left; + width: 240px; } .contact-entry-photo img { max-width: 80px; max-height: 80px; } + +/* forumlist widget */ +#hide-forum-list { + opacity: 0.3; + filter:alpha(opacity=30); +} + +#hide-forum-list:hover { + opacity: 1.0; + filter:alpha(opacity=100); +} + + +#forumlist-settings-label, #forumlist-random-label, #forumlist-profile-label, #forumlist-network-label { + float: left; + width: 200px; + margin-bottom: 25px; +} + +#forumlist-max-forumlists, #forumlist-random, #forumlist-profile, #forumlist-network { + float: left; +} + +.forumlist-img { + height: 20px; + width: 20px; +} \ No newline at end of file diff --git a/view/templates/profile_advanced.tpl b/view/templates/profile_advanced.tpl index 40b3f24f72..084fdf3b77 100644 --- a/view/templates/profile_advanced.tpl +++ b/view/templates/profile_advanced.tpl @@ -167,5 +167,11 @@ {{/if}} +{{if $profile.forumlist}} +
+
{{$profile.forumlist.0}}
+
{{$profile.forumlist.1}}
+
+{{/if}} diff --git a/view/templates/widget_forumlist.tpl b/view/templates/widget_forumlist.tpl new file mode 100644 index 0000000000..f3c1cbc4c4 --- /dev/null +++ b/view/templates/widget_forumlist.tpl @@ -0,0 +1,45 @@ + + +
+

{{$title}}

+ + {{foreach $forums as $forum}} + {{if $forum.id <= $visible_forums}} +
+ + {{$forum.link_desc}} + + {{$forum.name}} +
+ {{/if}} + + {{if $forum.id > $visible_forums}} + + {{/if}} + {{/foreach}} + + {{if $total > $visible_forums }} + + {{/if}} + +
\ No newline at end of file