From 0409aae7194ec2211039cf7b8cfa3e201dc087d5 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 15 Jan 2018 09:22:01 -0500 Subject: [PATCH 1/3] Create Widget class create widget class in Friendica/Content. --- src/Content/Widget.php | 277 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 src/Content/Widget.php diff --git a/src/Content/Widget.php b/src/Content/Widget.php new file mode 100644 index 000000000..4c7aecf95 --- /dev/null +++ b/src/Content/Widget.php @@ -0,0 +1,277 @@ + t('Add New Contact'), + '$desc' => t('Enter address or web location'), + '$hint' => t('Example: bob@example.com, http://example.com/barbara'), + '$value' => $value, + '$follow' => t('Connect') + )); + } + + function findpeople_widget() + { + $a = get_app(); + $global_dir = Config::get('system', 'directory'); + + if (Config::get('system', 'invitation_only')) { + $x = PConfig::get(local_user(), 'system', 'invites_remaining'); + if ($x || is_site_admin()) { + $a->page['aside'] .= '' . $inv; + } + } + + return replace_macros(get_markup_template('peoplefind.tpl'), array( + '$findpeople' => t('Find People'), + '$desc' => t('Enter name or interest'), + '$label' => t('Connect/Follow'), + '$hint' => t('Examples: Robert Morgenstein, Fishing'), + '$findthem' => t('Find'), + '$suggest' => t('Friend Suggestions'), + '$similar' => t('Similar Interests'), + '$random' => t('Random Profile'), + '$inv' => t('Invite Friends'), + '$directory' => t('View Global Directory'), + '$global_dir' => $global_dir + )); + } + + function unavailable_networks() + { + $networks = array(); + + if (!plugin_enabled("appnet")) { + $networks[] = NETWORK_APPNET; + } + + if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) { + $networks[] = NETWORK_FACEBOOK; + } + + if (!plugin_enabled("statusnet")) { + $networks[] = NETWORK_STATUSNET; + } + + if (!plugin_enabled("pumpio")) { + $networks[] = NETWORK_PUMPIO; + } + + if (!plugin_enabled("twitter")) { + $networks[] = NETWORK_TWITTER; + } + + if (Config::get("system", "ostatus_disabled")) { + $networks[] = NETWORK_OSTATUS; + } + + if (!Config::get("system", "diaspora_enabled")) { + $networks[] = NETWORK_DIASPORA; + } + + if (!plugin_enabled("pnut")) { + $networks[] = NETWORK_PNUT; + } + + if (!sizeof($networks)) { + return ""; + } + + $network_filter = implode("','", $networks); + + $network_filter = "AND `network` NOT IN ('$network_filter')"; + + return $network_filter; + } + + function networks_widget($baseurl, $selected = '') + { + if (!local_user()) { + return ''; + } + + if (!Feature::isEnabled(local_user(), 'networks')) { + return ''; + } + + $extra_sql = unavailable_networks(); + + $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`", + local_user() + ); + + $nets = array(); + while ($rr = dba::fetch($r)) { + /// @TODO If 'network' is not there, this triggers an E_NOTICE + if ($rr['network']) { + $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); + } + } + dba::close($r); + + if (count($nets) < 2) { + return ''; + } + + return replace_macros(get_markup_template('nets.tpl'), array( + '$title' => t('Networks'), + '$desc' => '', + '$sel_all' => (($selected == '') ? 'selected' : ''), + '$all' => t('All Networks'), + '$nets' => $nets, + '$base' => $baseurl, + )); + } + + function fileas_widget($baseurl, $selected = '') + { + if (!local_user()) { + return ''; + } + + if (!Feature::isEnabled(local_user(), 'filing')) { + return ''; + } + + $saved = PConfig::get(local_user(), 'system', 'filetags'); + if (!strlen($saved)) { + return; + } + + $matches = false; + $terms = array(); + $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER); + if ($cnt) { + foreach ($matches as $mtch) { + $unescaped = xmlify(file_tag_decode($mtch[1])); + $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : '')); + } + } + + return replace_macros(get_markup_template('fileas_widget.tpl'), array( + '$title' => t('Saved Folders'), + '$desc' => '', + '$sel_all' => (($selected == '') ? 'selected' : ''), + '$all' => t('Everything'), + '$terms' => $terms, + '$base' => $baseurl, + )); + } + + function categories_widget($baseurl, $selected = '') + { + $a = get_app(); + + if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) { + return ''; + } + + $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags'); + if (!strlen($saved)) { + return; + } + + $matches = false; + $terms = array(); + $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER); + + if ($cnt) { + foreach ($matches as $mtch) { + $unescaped = xmlify(file_tag_decode($mtch[1])); + $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : '')); + } + } + + return replace_macros(get_markup_template('categories_widget.tpl'), array( + '$title' => t('Categories'), + '$desc' => '', + '$sel_all' => (($selected == '') ? 'selected' : ''), + '$all' => t('Everything'), + '$terms' => $terms, + '$base' => $baseurl, + )); + } + + function common_friends_visitor_widget($profile_uid) + { + if (local_user() == $profile_uid) { + return; + } + + $cid = $zcid = 0; + + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $visitor) { + if ($visitor['uid'] == $profile_uid) { + $cid = $visitor['cid']; + break; + } + } + } + + if (!$cid) { + if (Profile::getMyURL()) { + $contact = dba::selectFirst('contact', ['id'], + ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]); + if (DBM::is_result($contact)) { + $cid = $contact['id']; + } else { + $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]); + if (DBM::is_result($gcontact)) { + $zcid = $gcontact['id']; + } + } + } + } + + if ($cid == 0 && $zcid == 0) { + return; + } + + if ($cid) { + $t = GContact::countCommonFriends($profile_uid, $cid); + } else { + $t = GContact::countCommonFriendsZcid($profile_uid, $zcid); + } + + if (!$t) { + return; + } + + if ($cid) { + $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true); + } else { + $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true); + } + + return replace_macros(get_markup_template('remote_friends_common.tpl'), array( + '$desc' => tt("%d contact in common", "%d contacts in common", $t), + '$base' => System::baseUrl(), + '$uid' => $profile_uid, + '$cid' => (($cid) ? $cid : '0'), + '$linkmore' => (($t > 5) ? 'true' : ''), + '$more' => t('show more'), + '$items' => $r) + ); + } +} From 6cf6029ff5b240efa6af23223b04c9218e43ab93 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 15 Jan 2018 09:50:06 -0500 Subject: [PATCH 2/3] Rename functions and calls Rename functions and update calls --- include/acl_selectors.php | 4 ++-- mod/contacts.php | 12 +++++----- mod/directory.php | 10 ++++---- mod/dirfind.php | 6 ++--- mod/match.php | 6 ++--- mod/network.php | 10 ++++---- mod/profile.php | 7 +++--- mod/suggest.php | 11 +++------ src/Content/Widget.php | 50 ++++++++++++++++++++++++++++++++------- view/theme/frio/theme.php | 5 ++-- 10 files changed, 73 insertions(+), 48 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index b71173e25..a93393d80 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -4,12 +4,12 @@ */ use Friendica\App; use Friendica\Content\Feature; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; -require_once "include/contact_widgets.php"; require_once "mod/proxy.php"; /** @@ -425,7 +425,7 @@ function acl_lookup(App $a, $out_type = 'json') $group_count = 0; } - $sql_extra2 .= " ".unavailable_networks(); + $sql_extra2 .= " ".Widget::unavailableNetworks(); if ($type == '' || $type == 'c') { // autocomplete for editor mentions diff --git a/mod/contacts.php b/mod/contacts.php index 22b5b87e7..7089cf05a 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -4,6 +4,7 @@ */ use Friendica\App; use Friendica\Content\ContactSelector; +use Friendica\Content\Widget; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; @@ -13,7 +14,6 @@ use Friendica\Model\Group; use Friendica\Model\Profile; use Friendica\Network\Probe; -require_once 'include/contact_widgets.php'; require_once 'mod/proxy.php'; function contacts_init(App $a) @@ -63,14 +63,14 @@ function contacts_init(App $a) $networks_widget = ''; } else { $vcard_widget = ''; - $networks_widget = networks_widget('contacts', $nets); + $networks_widget = Widget::networks('contacts', $nets); if (isset($_GET['add'])) { - $follow_widget = follow_widget($_GET['add']); + $follow_widget = Widget::follow($_GET['add']); } else { - $follow_widget = follow_widget(); + $follow_widget = Widget::follow(); } - $findpeople_widget = findpeople_widget(); + $findpeople_widget = Widget::findPeople(); } $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 0, $contact_id); @@ -781,7 +781,7 @@ function contacts_content(App $a) $total = $r[0]['total']; } - $sql_extra3 = unavailable_networks(); + $sql_extra3 = Widget::unavailableNetworks(); $contacts = array(); diff --git a/mod/directory.php b/mod/directory.php index 9dc08f0fb..a711f7231 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -3,6 +3,7 @@ * @file mod/directory.php */ use Friendica\App; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\Contact; @@ -12,13 +13,10 @@ function directory_init(App $a) { $a->set_pager_itemspage(60); if(local_user()) { - require_once('include/contact_widgets.php'); + $a->page['aside'] .= Widget::findPeople(); - $a->page['aside'] .= findpeople_widget(); - - $a->page['aside'] .= follow_widget(); - } - else { + $a->page['aside'] .= Widget::follow(); + } else { unset($_SESSION['theme']); unset($_SESSION['mobile-theme']); } diff --git a/mod/dirfind.php b/mod/dirfind.php index 4260ce827..9a91d0652 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -4,6 +4,7 @@ */ use Friendica\App; use Friendica\Content\ContactSelector; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Core\Worker; @@ -13,7 +14,6 @@ use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; -require_once 'include/contact_widgets.php'; require_once 'mod/contacts.php'; function dirfind_init(App $a) { @@ -27,9 +27,9 @@ function dirfind_init(App $a) { $a->page['aside'] = ''; } - $a->page['aside'] .= findpeople_widget(); + $a->page['aside'] .= Widget::findPeople(); - $a->page['aside'] .= follow_widget(); + $a->page['aside'] .= Widget::follow(); } function dirfind_content(App $a, $prefix = "") { diff --git a/mod/match.php b/mod/match.php index 7da56bffa..9ccf5a955 100644 --- a/mod/match.php +++ b/mod/match.php @@ -3,6 +3,7 @@ * @file mod/match.php */ use Friendica\App; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBM; @@ -10,7 +11,6 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; require_once 'include/text.php'; -require_once 'include/contact_widgets.php'; require_once 'mod/proxy.php'; /** @@ -30,8 +30,8 @@ function match_content(App $a) return; } - $a->page['aside'] .= findpeople_widget(); - $a->page['aside'] .= follow_widget(); + $a->page['aside'] .= Widget::findPeople(); + $a->page['aside'] .= Widget::follow(); $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd; diff --git a/mod/network.php b/mod/network.php index b9c908caa..ef5437213 100644 --- a/mod/network.php +++ b/mod/network.php @@ -5,6 +5,7 @@ use Friendica\App; use Friendica\Content\Feature; use Friendica\Content\ForumManager; +use Friendica\Content\Widget; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\PConfig; @@ -15,7 +16,6 @@ use Friendica\Model\Profile; use Friendica\Module\Login; require_once 'include/conversation.php'; -require_once 'include/contact_widgets.php'; require_once 'include/items.php'; require_once 'include/acl_selectors.php'; @@ -159,12 +159,12 @@ function network_init(App $a) { $a->page['aside'] = ''; } - $a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? Group::sidebarWidget('network/0','network','standard',$group_id) : ''); + $a->page['aside'] .= (Feature::isEnabled(local_user(), 'groups') ? Group::sidebarWidget('network/0', 'network', 'standard', $group_id) : ''); $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : ''); - $a->page['aside'] .= posted_date_widget('network',local_user(),false); - $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : '')); + $a->page['aside'] .= posted_date_widget('network', local_user(),false); + $a->page['aside'] .= Widget::networks('network', (x($_GET, 'nets') ? $_GET['nets'] : '')); $a->page['aside'] .= saved_searches($search); - $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : '')); + $a->page['aside'] .= Widget::fileAs('network', (x($_GET, 'file') ? $_GET['file'] : '')); } function saved_searches($search) { diff --git a/mod/profile.php b/mod/profile.php index 59762f479..77f8e069d 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -3,6 +3,7 @@ * @file mod/profile.php */ use Friendica\App; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; @@ -12,8 +13,6 @@ use Friendica\Model\Profile; use Friendica\Module\Login; use Friendica\Protocol\DFRN; -require_once 'include/contact_widgets.php'; - function profile_init(App $a) { if (!x($a->page, 'aside')) { @@ -184,7 +183,7 @@ function profile_content(App $a, $update = 0) return $o; } - $o .= common_friends_visitor_widget($a->profile['profile_uid']); + $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']); if (x($_SESSION, 'new_member') && $is_owner) { $o .= '' . t('Tips for New Members') . '' . EOL; @@ -194,7 +193,7 @@ function profile_content(App $a, $update = 0) $commvisitor = $commpage && $remote_contact; $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true); - $a->page['aside'] .= categories_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (x($category) ? xmlify($category) : '')); + $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (x($category) ? xmlify($category) : '')); $a->page['aside'] .= tagcloud_wall_widget(); if (can_write_wall($a->profile['profile_uid'])) { diff --git a/mod/suggest.php b/mod/suggest.php index a3da9a445..c3986e255 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -4,14 +4,13 @@ */ use Friendica\App; use Friendica\Content\ContactSelector; +use Friendica\Content\Widget; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Profile; -require_once 'include/contact_widgets.php'; - function suggest_init(App $a) { if (! local_user()) { return; @@ -51,10 +50,6 @@ function suggest_init(App $a) { } - - - - function suggest_content(App $a) { require_once("mod/proxy.php"); @@ -67,8 +62,8 @@ function suggest_content(App $a) { $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd; - $a->page['aside'] .= findpeople_widget(); - $a->page['aside'] .= follow_widget(); + $a->page['aside'] .= Widget::findPeople(); + $a->page['aside'] .= Widget::follow(); $r = GContact::suggestionQuery(local_user()); diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 4c7aecf95..40579d7c4 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -17,7 +17,12 @@ require_once 'boot.php'; class Widget { - function follow_widget($value = "") + /** + * Return the follow widget + * + * @param string $value optional, default empty + */ + public static function follow($value = "") { return replace_macros(get_markup_template('follow.tpl'), array( '$connect' => t('Add New Contact'), @@ -28,7 +33,10 @@ class Widget )); } - function findpeople_widget() + /** + * Return Find People widget + */ + public static function findPeople() { $a = get_app(); $global_dir = Config::get('system', 'directory'); @@ -57,7 +65,10 @@ class Widget )); } - function unavailable_networks() + /** + * Return unavailable networks + */ + public static function unavailableNetworks() { $networks = array(); @@ -104,7 +115,13 @@ class Widget return $network_filter; } - function networks_widget($baseurl, $selected = '') + /** + * Return networks widget + * + * @param string $baseurl baseurl + * @param string $selected optional, default empty + */ + public static function networks($baseurl, $selected = '') { if (!local_user()) { return ''; @@ -114,7 +131,7 @@ class Widget return ''; } - $extra_sql = unavailable_networks(); + $extra_sql = self::unavailableNetworks(); $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`", local_user() @@ -143,7 +160,13 @@ class Widget )); } - function fileas_widget($baseurl, $selected = '') + /** + * Return file as widget + * + * @param string $baseurl baseurl + * @param string $selected optional, default empty + */ + public static function fileAs($baseurl, $selected = '') { if (!local_user()) { return ''; @@ -178,7 +201,13 @@ class Widget )); } - function categories_widget($baseurl, $selected = '') + /** + * Return categories widget + * + * @param string $baseurl baseurl + * @param string $selected optional, default empty + */ + public static function categories($baseurl, $selected = '') { $a = get_app(); @@ -212,7 +241,12 @@ class Widget )); } - function common_friends_visitor_widget($profile_uid) + /** + * Return common friends visitor widget + * + * @param string $profile_uid uid + */ + public static function commonFriendsVisitor($profile_uid) { if (local_user() == $profile_uid) { return; diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index b135fa0d6..18cc1aeef 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -1,5 +1,4 @@ ReadMe. @@ -7,8 +6,8 @@ * Author: Rabuzarus * */ - use Friendica\App; +use Friendica\Content\Widget; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; @@ -315,7 +314,7 @@ function frio_acl_lookup(App $a, &$results) $total = $r[0]["total"]; } - $sql_extra3 = unavailable_networks(); + $sql_extra3 = Widget::unavailableNetworks(); $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra3 ORDER BY `name` ASC LIMIT 100 ", intval($_SESSION['uid']) From d4178d482b99e6c8d74cd689c17f34e7ae32fda0 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 15 Jan 2018 09:50:45 -0500 Subject: [PATCH 3/3] Remove old file remove include/contact_widgets.php --- include/contact_widgets.php | 270 ------------------------------------ 1 file changed, 270 deletions(-) delete mode 100644 include/contact_widgets.php diff --git a/include/contact_widgets.php b/include/contact_widgets.php deleted file mode 100644 index f8fb80c59..000000000 --- a/include/contact_widgets.php +++ /dev/null @@ -1,270 +0,0 @@ - t('Add New Contact'), - '$desc' => t('Enter address or web location'), - '$hint' => t('Example: bob@example.com, http://example.com/barbara'), - '$value' => $value, - '$follow' => t('Connect') - )); -} - -function findpeople_widget() -{ - $a = get_app(); - $global_dir = Config::get('system', 'directory'); - - if (Config::get('system', 'invitation_only')) { - $x = PConfig::get(local_user(), 'system', 'invites_remaining'); - if ($x || is_site_admin()) { - $a->page['aside'] .= '' . $inv; - } - } - - return replace_macros(get_markup_template('peoplefind.tpl'), array( - '$findpeople' => t('Find People'), - '$desc' => t('Enter name or interest'), - '$label' => t('Connect/Follow'), - '$hint' => t('Examples: Robert Morgenstein, Fishing'), - '$findthem' => t('Find'), - '$suggest' => t('Friend Suggestions'), - '$similar' => t('Similar Interests'), - '$random' => t('Random Profile'), - '$inv' => t('Invite Friends'), - '$directory' => t('View Global Directory'), - '$global_dir' => $global_dir - )); -} - -function unavailable_networks() -{ - $networks = array(); - - if (!plugin_enabled("appnet")) { - $networks[] = NETWORK_APPNET; - } - - if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) { - $networks[] = NETWORK_FACEBOOK; - } - - if (!plugin_enabled("statusnet")) { - $networks[] = NETWORK_STATUSNET; - } - - if (!plugin_enabled("pumpio")) { - $networks[] = NETWORK_PUMPIO; - } - - if (!plugin_enabled("twitter")) { - $networks[] = NETWORK_TWITTER; - } - - if (Config::get("system", "ostatus_disabled")) { - $networks[] = NETWORK_OSTATUS; - } - - if (!Config::get("system", "diaspora_enabled")) { - $networks[] = NETWORK_DIASPORA; - } - - if (!plugin_enabled("pnut")) { - $networks[] = NETWORK_PNUT; - } - - if (!sizeof($networks)) { - return ""; - } - - $network_filter = implode("','", $networks); - - $network_filter = "AND `network` NOT IN ('$network_filter')"; - - return $network_filter; -} - -function networks_widget($baseurl, $selected = '') -{ - if (!local_user()) { - return ''; - } - - if (!Feature::isEnabled(local_user(), 'networks')) { - return ''; - } - - $extra_sql = unavailable_networks(); - - $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`", - local_user() - ); - - $nets = array(); - while ($rr = dba::fetch($r)) { - /// @TODO If 'network' is not there, this triggers an E_NOTICE - if ($rr['network']) { - $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); - } - } - dba::close($r); - - if (count($nets) < 2) { - return ''; - } - - return replace_macros(get_markup_template('nets.tpl'), array( - '$title' => t('Networks'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('All Networks'), - '$nets' => $nets, - '$base' => $baseurl, - )); -} - -function fileas_widget($baseurl, $selected = '') -{ - if (!local_user()) { - return ''; - } - - if (!Feature::isEnabled(local_user(), 'filing')) { - return ''; - } - - $saved = PConfig::get(local_user(), 'system', 'filetags'); - if (!strlen($saved)) { - return; - } - - $matches = false; - $terms = array(); - $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER); - if ($cnt) { - foreach ($matches as $mtch) { - $unescaped = xmlify(file_tag_decode($mtch[1])); - $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : '')); - } - } - - return replace_macros(get_markup_template('fileas_widget.tpl'), array( - '$title' => t('Saved Folders'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => $baseurl, - )); -} - -function categories_widget($baseurl, $selected = '') -{ - $a = get_app(); - - if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) { - return ''; - } - - $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags'); - if (!strlen($saved)) { - return; - } - - $matches = false; - $terms = array(); - $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER); - - if ($cnt) { - foreach ($matches as $mtch) { - $unescaped = xmlify(file_tag_decode($mtch[1])); - $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : '')); - } - } - - return replace_macros(get_markup_template('categories_widget.tpl'), array( - '$title' => t('Categories'), - '$desc' => '', - '$sel_all' => (($selected == '') ? 'selected' : ''), - '$all' => t('Everything'), - '$terms' => $terms, - '$base' => $baseurl, - )); -} - -function common_friends_visitor_widget($profile_uid) -{ - if (local_user() == $profile_uid) { - return; - } - - $cid = $zcid = 0; - - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { - if ($visitor['uid'] == $profile_uid) { - $cid = $visitor['cid']; - break; - } - } - } - - if (!$cid) { - if (Profile::getMyURL()) { - $contact = dba::selectFirst('contact', ['id'], - ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]); - if (DBM::is_result($contact)) { - $cid = $contact['id']; - } else { - $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]); - if (DBM::is_result($gcontact)) { - $zcid = $gcontact['id']; - } - } - } - } - - if ($cid == 0 && $zcid == 0) { - return; - } - - if ($cid) { - $t = GContact::countCommonFriends($profile_uid, $cid); - } else { - $t = GContact::countCommonFriendsZcid($profile_uid, $zcid); - } - - if (!$t) { - return; - } - - if ($cid) { - $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true); - } else { - $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true); - } - - return replace_macros(get_markup_template('remote_friends_common.tpl'), array( - '$desc' => tt("%d contact in common", "%d contacts in common", $t), - '$base' => System::baseUrl(), - '$uid' => $profile_uid, - '$cid' => (($cid) ? $cid : '0'), - '$linkmore' => (($t > 5) ? 'true' : ''), - '$more' => t('show more'), - '$items' => $r) - ); -}