From a3ef9e35ec8ef7a0c24f1f90038e5276f7c81612 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Tue, 9 Jan 2018 22:42:04 -0500 Subject: [PATCH] Update functions and calls Update function names and calls. --- include/api.php | 24 ++-- include/contact_widgets.php | 6 +- include/conversation.php | 3 +- include/text.php | 7 +- mod/allfriends.php | 4 +- mod/common.php | 4 +- mod/contacts.php | 15 +-- mod/dirfind.php | 4 +- mod/nogroup.php | 5 +- mod/notifications.php | 10 +- mod/suggest.php | 5 +- mod/viewcontacts.php | 5 +- src/Content/ContactSelector.php | 208 +++++++++++++++++--------------- src/Object/Post.php | 5 +- 14 files changed, 151 insertions(+), 154 deletions(-) diff --git a/include/api.php b/include/api.php index e527cb003b..bc60590a51 100644 --- a/include/api.php +++ b/include/api.php @@ -6,6 +6,7 @@ * @todo Automatically detect if incoming data is HTML or BBCode */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Config; @@ -38,7 +39,6 @@ require_once 'include/html2plain.php'; require_once 'mod/share.php'; require_once 'mod/item.php'; require_once 'include/security.php'; -require_once 'include/contact_selectors.php'; require_once 'include/html2bbcode.php'; require_once 'mod/wall_upload.php'; require_once 'mod/proxy.php'; @@ -610,7 +610,7 @@ function api_get_user(App $a, $contact_id = null) } if (DBM::is_result($r)) { - $network_name = network_to_name($r[0]['network'], $r[0]['url']); + $network_name = ContactSelector::networkToName($r[0]['network'], $r[0]['url']); // If no nick where given, extract it from the address if (($r[0]['nick'] == "") || ($r[0]['name'] == $r[0]['nick'])) { @@ -734,7 +734,7 @@ function api_get_user(App $a, $contact_id = null) $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]); } - $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']); + $network_name = ContactSelector::networkToName($uinfo[0]['network'], $uinfo[0]['url']); $pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, true); @@ -1405,9 +1405,9 @@ function api_status_show($type) } if (($lastwall['item_network'] != "") && ($status["source"] == 'web')) { - $status_info["source"] = network_to_name($lastwall['item_network'], $user_info['url']); - } elseif (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $status_info["source"])) { - $status_info["source"] = trim($status_info["source"].' ('.network_to_name($lastwall['item_network'], $user_info['url']).')'); + $status_info["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']); + } elseif (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $status_info["source"])) { + $status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['item_network'], $user_info['url']).')'); } // "uid" and "self" are only needed for some internal stuff, so remove it from here @@ -1496,11 +1496,11 @@ function api_users_show($type) } if (($lastwall['item_network'] != "") && ($user_info["status"]["source"] == 'web')) { - $user_info["status"]["source"] = network_to_name($lastwall['item_network'], $user_info['url']); + $user_info["status"]["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']); } - if (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) { - $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . network_to_name($lastwall['item_network'], $user_info['url']) . ')'); + if (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) { + $user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) . ')'); } } @@ -3131,9 +3131,9 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") } if (($item['item_network'] != "") && ($status["source"] == 'web')) { - $status["source"] = network_to_name($item['item_network'], $user_info['url']); - } elseif (($item['item_network'] != "") && (network_to_name($item['item_network'], $user_info['url']) != $status["source"])) { - $status["source"] = trim($status["source"].' ('.network_to_name($item['item_network'], $user_info['url']).')'); + $status["source"] = ContactSelector::networkToName($item['item_network'], $user_info['url']); + } elseif (($item['item_network'] != "") && (ContactSelector::networkToName($item['item_network'], $user_info['url']) != $status["source"])) { + $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['item_network'], $user_info['url']).')'); } diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 55e119c3fa..a1c93f142b 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -1,8 +1,8 @@ $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); + $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); } } dba::close($r); diff --git a/include/conversation.php b/include/conversation.php index 472896ffec..423d9884e7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -3,6 +3,7 @@ * @file include/conversation.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; @@ -776,7 +777,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { 'id' => (($preview) ? 'P0' : $item['item_id']), 'guid' => (($preview) ? 'Q0' : $item['guid']), 'network' => $item['item_network'], - 'network_name' => network_to_name($item['item_network'], $profile_link), + 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), diff --git a/include/text.php b/include/text.php index 0b763d687c..7ed561bbbb 100644 --- a/include/text.php +++ b/include/text.php @@ -3,6 +3,7 @@ * @file include/text.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Smilies; use Friendica\Core\Config; @@ -2048,16 +2049,14 @@ function formatBytes($bytes, $precision = 2) { */ function format_network_name($network, $url = 0) { if ($network != "") { - require_once 'include/contact_selectors.php'; if ($url != "") { - $network_name = ''.network_to_name($network, $url).""; + $network_name = ''.ContactSelector::networkToName($network, $url).""; } else { - $network_name = network_to_name($network); + $network_name = ContactSelector::networkToName($network); } return $network_name; } - } /** diff --git a/mod/allfriends.php b/mod/allfriends.php index 9d6a6b0c7b..88dddb3ee6 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -4,12 +4,12 @@ * @file mod/allfriends.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; -require_once 'include/contact_selectors.php'; require_once 'mod/contacts.php'; function allfriends_content(App $a) @@ -86,7 +86,7 @@ function allfriends_content(App $a) 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => Contact::getAccountType($contact_details), - 'network' => network_to_name($contact_details['network'], $contact_details['url']), + 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']), 'photo_menu' => $photo_menu, 'conntxt' => t('Connect'), 'connlnk' => $connlnk, diff --git a/mod/common.php b/mod/common.php index fc8829aa51..1f1e8c3377 100644 --- a/mod/common.php +++ b/mod/common.php @@ -4,11 +4,11 @@ * @file include/common.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; -require_once 'include/contact_selectors.php'; require_once 'mod/contacts.php'; function common_content(App $a) @@ -130,7 +130,7 @@ function common_content(App $a) 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => Contact::getAccountType($contact_details), - 'network' => network_to_name($contact_details['network'], $contact_details['url']), + 'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']), 'photo_menu' => $photo_menu, 'id' => ++$id, ); diff --git a/mod/contacts.php b/mod/contacts.php index f673f84f10..a63591713a 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -1,9 +1,9 @@ System::baseUrl(true), )); - require_once 'include/contact_selectors.php'; - $dir_icon = ''; $relation_text = ''; switch ($contact['rel']) { @@ -552,7 +549,7 @@ function contacts_content(App $a) $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL)); - $nettype = t('Network type: %s', network_to_name($contact['network'], $contact["url"])); + $nettype = t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"])); // tabs $tab_str = contacts_tab($a, $contact_id, 2); @@ -576,12 +573,12 @@ function contacts_content(App $a) $poll_interval = null; if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL))) { - $poll_interval = contact_poll_interval($contact['priority'], (!$poll_enabled)); + $poll_interval = ContactSelector::pollInterval($contact['priority'], (!$poll_enabled)); } $profile_select = null; if ($contact['network'] == NETWORK_DFRN) { - $profile_select = contact_profile_assign($contact['profile-id'], (($contact['network'] !== NETWORK_DFRN) ? true : false)); + $profile_select = ContactSelector::profileAssign($contact['profile-id'], (($contact['network'] !== NETWORK_DFRN) ? true : false)); } $follow = ''; @@ -808,7 +805,7 @@ function contacts_content(App $a) $tpl = get_markup_template("contacts-template.tpl"); $o .= replace_macros($tpl, array( '$baseurl' => System::baseUrl(), - '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''), + '$header' => t('Contacts') . (($nets) ? ' - ' . ContactSelector::networkToName($nets) : ''), '$tabs' => $t, '$total' => $total, '$search' => $search_hdr, @@ -959,7 +956,7 @@ function _contact_detail_for_template($rr) 'sparkle' => $sparkle, 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']), 'url' => $url, - 'network' => network_to_name($rr['network'], $rr['url']), + 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), ); } diff --git a/mod/dirfind.php b/mod/dirfind.php index bef89a4794..06bb1d8da6 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -3,6 +3,7 @@ * @file mod/dirfind.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Core\Worker; @@ -12,7 +13,6 @@ use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; require_once 'include/contact_widgets.php'; -require_once 'include/contact_selectors.php'; require_once 'mod/contacts.php'; function dirfind_init(App $a) { @@ -235,7 +235,7 @@ function dirfind_content(App $a, $prefix = "") { 'tags' => $contact_details['keywords'], 'about' => $contact_details['about'], 'account_type' => Contact::getAccountType($contact_details), - 'network' => network_to_name($jj->network, $jj->url), + 'network' => ContactSelector::networkToName($jj->network, $jj->url), 'id' => ++$id, ); $entries[] = $entry; diff --git a/mod/nogroup.php b/mod/nogroup.php index 9f5425d9eb..7ebb5bd1f2 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -3,12 +3,11 @@ * @file mod/nogroup.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Group; -require_once 'include/contact_selectors.php'; - function nogroup_init(App $a) { if (! local_user()) { @@ -53,7 +52,7 @@ function nogroup_content(App $a) 'about' => $contact_details['about'], 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), 'url' => $rr['url'], - 'network' => network_to_name($rr['network'], $rr['url']), + 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), ); } } diff --git a/mod/notifications.php b/mod/notifications.php index fe8422cc4a..e2de81e6c7 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -1,17 +1,15 @@ "; - $header .= " (".network_to_name($it['network'], $it['url']).")"; + $header .= " (".ContactSelector::networkToName($it['network'], $it['url']).")"; if ($it['network'] != NETWORK_DIASPORA) { $discard = t('Discard'); @@ -260,7 +258,7 @@ function notifications_content(App $a) { '$addr' => $it['addr'], '$lbl_knowyou' => $lbl_knowyou, '$lbl_network' => t('Network:'), - '$network' => network_to_name($it['network'], $it['url']), + '$network' => ContactSelector::networkToName($it['network'], $it['url']), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $it['note'], diff --git a/mod/suggest.php b/mod/suggest.php index deda2b2c6c..05a720f7b9 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -3,6 +3,7 @@ * @file mod/suggest.php */ use Friendica\App; +use Friendica\Content\ContactSelector; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; @@ -76,8 +77,6 @@ function suggest_content(App $a) { return $o; } - require_once 'include/contact_selectors.php'; - foreach ($r as $rr) { $connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']); @@ -106,7 +105,7 @@ function suggest_content(App $a) { 'connlnk' => $connlnk, 'photo_menu' => $photo_menu, 'ignore' => t('Ignore/Hide'), - 'network' => network_to_name($rr['network'], $rr['url']), + 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), 'id' => ++$id, ); $entries[] = $entry; diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index 1b4ff69c00..e4ebe3abb2 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -1,12 +1,11 @@ $url, 'sparkle' => '', 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), - 'network' => network_to_name($rr['network'], $rr['url']), + 'network' => ContactSelector::networkToName($rr['network'], $rr['url']), ); } diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index c3db2406e3..bd8bcc989b 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -6,114 +6,122 @@ namespace Friendica\Content; use Friendica\Database\DBM; use Friendica\Protocol\Diaspora; +use dba; +/** + * @brief ContactSelector class + */ class ContactSelector { - function contact_profile_assign($current,$foreign_net) { + /** + * @param string $current current + * @param string $foreign_net network + */ + public static function profileAssign($current, $foreign_net) + { + $o = ''; - $o = ''; - - $disabled = (($foreign_net) ? ' disabled="true" ' : ''); - - $o .= "\r\n"; - return $o; - } + $disabled = (($foreign_net) ? ' disabled="true" ' : ''); - function contact_reputation($current) { + $o .= "\r\n"; - - $rep = array( - 0 => t('Unknown | Not categorised'), - 1 => t('Block immediately'), - 2 => t('Shady, spammer, self-marketer'), - 3 => t('Known to me, but no opinion'), - 4 => t('OK, probably harmless'), - 5 => t('Reputable, has my trust') - ); - - foreach ($rep as $k => $v) { - $selected = (($k == $current) ? " selected=\"selected\" " : ""); - $o .= "\r\n"; - } - $o .= "\r\n"; - return $o; - } + $s = dba::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $$_SESSION['uid']]); + $r = dba::inArray($s); - function contact_poll_interval($current, $disabled = false) { + if (DBM::is_result($r)) { + foreach ($r as $rr) { + $selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : ""); + $o .= "\r\n"; + } + } + $o .= "\r\n"; + return $o; + } - $dis = (($disabled) ? ' disabled="disabled" ' : ''); - $o = ''; - $o .= "\r\n"; - return $o; - } + private static function contact_reputation($current) + { + $o = ''; + $o .= "\r\n"; + return $o; + } + + public static function pollInterval($current, $disabled = false) + { + $dis = (($disabled) ? ' disabled="disabled" ' : ''); + $o = ''; + $o .= "\r\n"; + return $o; + } + + public static function networkToName($s, $profile = "") + { + $nets = array( + NETWORK_DFRN => t('Friendica'), + NETWORK_OSTATUS => t('OStatus'), + NETWORK_FEED => t('RSS/Atom'), + NETWORK_MAIL => t('Email'), + NETWORK_DIASPORA => t('Diaspora'), + NETWORK_FACEBOOK => t('Facebook'), + NETWORK_ZOT => t('Zot!'), + NETWORK_LINKEDIN => t('LinkedIn'), + NETWORK_XMPP => t('XMPP/IM'), + NETWORK_MYSPACE => t('MySpace'), + NETWORK_GPLUS => t('Google+'), + NETWORK_PUMPIO => t('pump.io'), + NETWORK_TWITTER => t('Twitter'), + NETWORK_DIASPORA2 => t('Diaspora Connector'), + NETWORK_STATUSNET => t('GNU Social Connector'), + NETWORK_PNUT => t('pnut'), + NETWORK_APPNET => t('App.net') + ); + + call_hooks('network_to_name', $nets); + + $search = array_keys($nets); + $replace = array_values($nets); + + $networkname = str_replace($search, $replace, $s); + + if ((in_array($s, array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) && ($profile != "")) { + $r = dba::fetch_first("SELECT `gserver`.`platform` FROM `gcontact` + INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url` + WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile)); + + if (DBM::is_result($r)) { + $networkname = $r['platform']; + } + } + + return $networkname; + } } diff --git a/src/Object/Post.php b/src/Object/Post.php index 97768bf56c..9ef00949f4 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -1,12 +1,11 @@ $thread_level, 'edited' => $edited, 'network' => $item["item_network"], - 'network_name' => network_to_name($item['item_network'], $profile_link), + 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link), 'received' => $item['received'], 'commented' => $item['commented'], 'created_date' => $item['created'],