From 96b764425ea38cdd0d2f5259549a58d4718315ef Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 9 Nov 2015 15:56:20 +0100 Subject: [PATCH 01/16] 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 From abf9ebd4668a39b702f52106726e765c989c6353 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Tue, 10 Nov 2015 12:53:56 +0100 Subject: [PATCH 02/16] forumlist: small fix --- view/templates/widget_forumlist.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/templates/widget_forumlist.tpl b/view/templates/widget_forumlist.tpl index f3c1cbc4c4..0306332638 100644 --- a/view/templates/widget_forumlist.tpl +++ b/view/templates/widget_forumlist.tpl @@ -18,7 +18,7 @@ function showHideForumlist() { {{foreach $forums as $forum}} {{if $forum.id <= $visible_forums}} -
+ \ No newline at end of file +
From 84bb703a000864b783b11fd68521b8adc54d8286 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Wed, 11 Nov 2015 23:40:26 +0100 Subject: [PATCH 11/16] forumlist: dbupdate - small optical fix --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index b6faa85081..f2fa3d21fc 100644 --- a/update.php +++ b/update.php @@ -1681,7 +1681,7 @@ function update_1190() { $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%d' ", dbesc('forumlist') -); + ); foreach ($r as $rr) { $uid = $rr['uid']; From 666e1198d45dd2f90ac67e558d7a65dd36e18e81 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Wed, 11 Nov 2015 23:47:09 +0100 Subject: [PATCH 12/16] forumlist: dbupdate - small includel fix --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index f2fa3d21fc..45288cb5a0 100644 --- a/update.php +++ b/update.php @@ -1662,7 +1662,7 @@ function update_1188() { function update_1190() { - require_once('/include/plugins.php'); + require_once('include/plugins.php'); if (plugin_enabled('forumlist')) { $plugin = 'forumlist'; From dd2ed42863747c0096d6eb63f2751606140aaa75 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Thu, 12 Nov 2015 16:42:27 +0100 Subject: [PATCH 13/16] forumlist: dbupdate - new try --- update.php | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/update.php b/update.php index 45288cb5a0..8abad1629a 100644 --- a/update.php +++ b/update.php @@ -1662,48 +1662,61 @@ function update_1188() { function update_1190() { - require_once('include/plugins.php'); + require_once('include/plugin.php'); + + set_config('system', 'maintenance', 1); if (plugin_enabled('forumlist')) { $plugin = 'forumlist'; $plugins = get_config('system','addon'); $plugins_arr = array(); + if($plugins) { - $plugins_arr = explode(',',str_replace(' ', '',$plugins)); + $plugins_arr = explode(",",str_replace(" ", "",$plugins)); + $idx = array_search($plugin, $plugins_arr); if ($idx !== false){ unset($plugins_arr[$idx]); uninstall_plugin($plugin); - set_config('system','addon', implode(', ',$plugins_arr)); + set_config('system','addon', implode(", ",$plugins_arr)); } } } - $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%d' ", + // select old formlist addon entries + $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ", dbesc('forumlist') ); - foreach ($r as $rr) { - $uid = $rr['uid']; - $family = $rr['cat']; - $key = $rr['k']; - $value = $rr['v']; + // convert old forumlist addon entries in new config entries + if (count($r)) { + foreach ($r as $rr) { + $uid = $rr['uid']; + $family = $rr['cat']; + $key = $rr['k']; + $value = $rr['v']; - if ($key === 'randomize') - del_pconfig($uid,$family,$key); + if ($key === 'randomise') + del_pconfig($uid,$family,$key); - if ($key === 'show_on_profile') { - if ($value) - set_pconfig($uid,feature,forumlist_profile,$value); + if ($key === 'show_on_profile') { + if ($value) + set_pconfig($uid,feature,forumlist_profile,$value); - del_pconfig($uid,$family,$key); - } + del_pconfig($uid,$family,$key); + } - if ($key === 'show_on_network') { - if ($value) - set_pconfig($uid,feature,forumlist,$value); + if ($key === 'show_on_network') { + if ($value) + set_pconfig($uid,feature,forumlist_widget,$value); - del_pconfig($uid,$family,$key); + del_pconfig($uid,$family,$key); + } } } + + set_config('system', 'maintenance', 0); + + return UPDATE_SUCCESS; + } From e239f0a82e5ec506a42d66852691b88693b31351 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 13 Nov 2015 00:16:39 +0100 Subject: [PATCH 14/16] forumlist: dbupdate - fix - delete hooks and addon entry manually --- update.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index 8abad1629a..caa167617c 100644 --- a/update.php +++ b/update.php @@ -1677,7 +1677,10 @@ function update_1190() { $idx = array_search($plugin, $plugins_arr); if ($idx !== false){ unset($plugins_arr[$idx]); - uninstall_plugin($plugin); + //delete forumlist manually from addon and hook table + // since uninstall_plugin() don't work here + q("DELETE FROM `addon` WHERE `name` = 'forumlist' "); + q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' "); set_config('system','addon', implode(", ",$plugins_arr)); } } From 86e720c99da7748000a3dbe2939db2af7b698ad9 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 13 Nov 2015 00:33:32 +0100 Subject: [PATCH 15/16] forumlist: some more doxygen for plugin.php --- include/plugin.php | 89 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 18 deletions(-) diff --git a/include/plugin.php b/include/plugin.php index c504db5dab..965b823b02 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -1,9 +1,17 @@ * * Author: Jane * * + * *\endcode + * @param string $plugin the name of the plugin + * @return array with the plugin information */ if (! function_exists('get_plugin_info')){ @@ -276,16 +318,20 @@ function get_plugin_info($plugin){ }} -/* - * parse theme comment in search of theme infos. +/** + * @brief Parse theme comment in search of theme infos. + * * like - * - * * Name: My Theme + * \code + * ..* Name: My Theme * * Description: My Cool Theme - * * Version: 1.2.3 + * . * Version: 1.2.3 * * Author: John * * Maintainer: Jane * * + * \endcode + * @param string $theme the name of the theme + * @return array */ if (! function_exists('get_theme_info')){ @@ -351,7 +397,14 @@ function get_theme_info($theme){ return $info; }} - +/** + * @brief Returns the theme's screenshot. + * + * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg]. + * + * @param sring $theme The name of the theme + * @return string + */ function get_theme_screenshot($theme) { $a = get_app(); $exts = array('.png','.jpg'); @@ -413,7 +466,7 @@ function service_class_allows($uid,$property,$usage = false) { $service_class = $a->user['service_class']; } else { - $r = q("select service_class from user where uid = %d limit 1", + $r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid) ); if($r !== false and count($r)) { @@ -443,7 +496,7 @@ function service_class_fetch($uid,$property) { $service_class = $a->user['service_class']; } else { - $r = q("select service_class from user where uid = %d limit 1", + $r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid) ); if($r !== false and count($r)) { From cec5afe2c92dbe2ed0f8fd604b002fc69b7190da Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 13 Nov 2015 23:49:37 +0100 Subject: [PATCH 16/16] forumlist: don't raise db version in dbstructure.php --- include/dbstructure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 7d8f89df6c..0dd74ab15f 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -2,7 +2,7 @@ require_once("boot.php"); require_once("include/text.php"); -define('NEW_UPDATE_ROUTINE_VERSION', 1191); +define('NEW_UPDATE_ROUTINE_VERSION', 1170); /* * send the email and do what is needed to do on update fails