move forumlist addon to core

This commit is contained in:
rabuzarus 2015-11-09 15:56:20 +01:00
parent b609aca456
commit 96b764425e
7 changed files with 267 additions and 24 deletions

View file

@ -38,6 +38,7 @@ function get_features() {
'widgets' => array(
t('Network Sidebar Widgets'),
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')),
@ -63,6 +64,12 @@ function get_features() {
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')),
),
);
call_hooks('get_features',$arr);

148
include/forums.php Normal file
View file

@ -0,0 +1,148 @@
<?php
/**
* @file include/forums.php
* @brief functions related to forum functionality *
*/
/**
* @brief function to list all forums a user is connected with
*
* @param int $uid of the profile owner
* @param boolean $showhidden
* show frorums which are not hidden
* @param boolean $lastitem
* sort by lastitem
* @param boolean $showprivate
* show private groups
*
* @returns array
* 'url' => 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;
}

View file

@ -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')
@ -604,6 +605,13 @@ function advanced_profile(&$a) {
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'));

View file

@ -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);

View file

@ -286,3 +286,30 @@ ul.credits li {
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;
}

View file

@ -167,5 +167,11 @@
{{/if}}
{{if $profile.forumlist}}
<dl id="aprofile-forumlist" class="aprofile">
<dt>{{$profile.forumlist.0}}</dt>
<dd>{{$profile.forumlist.1}}</dd>
</dl>
{{/if}}

View file

@ -0,0 +1,45 @@
<script>
function showHideForumlist() {
if( $('#forum-widget-entry-extended').is(':visible')) {
$('#forum-widget-entry-extended').hide();
$('#forum-widget-collapse').html(window.showMore);
}
else {
$('#forum-widget-entry-extended').show();
$('#forum-widget-collapse').html(window.showFewer);
}
}
</script>
<div id="forumlist-sidebar" class="widget">
<h3 id="forumlist">{{$title}}</h3>
{{foreach $forums as $forum}}
{{if $forum.id <= $visible_forums}}
<div class="forum-widget-entry" id="forum-widget-entry role="menuitem">
<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
</a>
<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
</div>
{{/if}}
{{if $forum.id > $visible_forums}}
<div class="forum-widget-entry" id="forum-widget-entry-extended" role="menuitem" style="display: none;">
<a href="{{$forum.external_url}}" title="{{$forum.link_desc}}" class="label sparkle" target="_blank">
<img class="forumlist-img" src="{{$forum.micro}}" alt="{{$forum.link_desc}}" />
</a>
<a class="forum-widget-link" id="forum-widget-link-{{$forum.id}}" href="{{$forum.url}}" >{{$forum.name}}</a>
</div>
{{/if}}
{{/foreach}}
{{if $total > $visible_forums }}
<ul class="forum-widget-ul">
<li onclick="showHideForumlist(); return false;" id="forum-widget-collapse" class="fakelink tool">{{$showmore}}</li>
</ul>
{{/if}}
</div>