Update functions and calls

Update function names and calls.
This commit is contained in:
Adam Magness 2018-01-09 22:42:04 -05:00
parent 300b1b6af8
commit a3ef9e35ec
14 changed files with 151 additions and 154 deletions

View File

@ -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']).')');
}

View File

@ -1,8 +1,8 @@
<?php
/**
* @file include/contact_widgets.php
*/
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Core\System;
use Friendica\Core\Config;
@ -10,8 +10,6 @@ use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\GContact;
require_once 'include/contact_selectors.php';
function follow_widget($value = "")
{
return replace_macros(get_markup_template('follow.tpl'), array(
@ -119,7 +117,7 @@ function networks_widget($baseurl, $selected = '')
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' => 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);

View File

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

View File

@ -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 = '<a href="'.$url.'">'.network_to_name($network, $url)."</a>";
$network_name = '<a href="'.$url.'">'.ContactSelector::networkToName($network, $url)."</a>";
} else {
$network_name = network_to_name($network);
$network_name = ContactSelector::networkToName($network);
}
return $network_name;
}
}
/**

View File

@ -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,

View File

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

View File

@ -1,9 +1,9 @@
<?php
/**
* @file mod/contacts.php
*/
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
@ -12,7 +12,6 @@ use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Network\Probe;
require_once 'include/contact_selectors.php';
require_once 'include/contact_widgets.php';
require_once 'mod/proxy.php';
@ -506,8 +505,6 @@ function contacts_content(App $a)
'$baseurl' => 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']),
);
}

View File

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

View File

@ -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']),
);
}
}

View File

@ -1,17 +1,15 @@
<?php
/**
* @file mod/notifications.php
* @brief The notifications module
*/
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Core\NotificationsManager;
use Friendica\Core\System;
use Friendica\Database\DBM;
require_once("include/contact_selectors.php");
require_once("include/network.php");
require_once "include/network.php";
function notifications_post(App $a) {
@ -225,7 +223,7 @@ function notifications_content(App $a) {
if ($it["addr"] != "")
$header .= " <".$it["addr"].">";
$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'],

View File

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

View File

@ -1,12 +1,11 @@
<?php
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Core\Config;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
require_once('include/contact_selectors.php');
function viewcontacts_init(App $a) {
if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
@ -116,7 +115,7 @@ function viewcontacts_content(App $a) {
'url' => $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']),
);
}

View File

@ -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 .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
$r = q("SELECT `id`, `profile-name`, `is-default` FROM `profile` WHERE `uid` = %d",
intval($_SESSION['uid']));
if (DBM::is_result($r)) {
foreach ($r as $rr) {
$selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
$o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
}
}
$o .= "</select>\r\n";
return $o;
}
$disabled = (($foreign_net) ? ' disabled="true" ' : '');
function contact_reputation($current) {
$o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
$o = '';
$o .= "<select id=\"contact-reputation-selector\" name=\"reputation\" />\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 .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
$o .= "</select>\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 .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
}
}
$o .= "</select>\r\n";
return $o;
}
$dis = (($disabled) ? ' disabled="disabled" ' : '');
$o = '';
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
$rep = array(
0 => t('Frequently'),
1 => t('Hourly'),
2 => t('Twice daily'),
3 => t('Daily'),
4 => t('Weekly'),
5 => t('Monthly')
);
foreach ($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
$o .= "</select>\r\n";
return $o;
}
private static function contact_reputation($current)
{
$o = '';
$o .= "<select id=\"contact-reputation-selector\" name=\"reputation\" />\r\n";
function network_to_name($s, $profile = "") {
$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')
);
$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;
}
foreach ($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
$o .= "</select>\r\n";
return $o;
}
public static function pollInterval($current, $disabled = false)
{
$dis = (($disabled) ? ' disabled="disabled" ' : '');
$o = '';
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
$rep = array(
0 => t('Frequently'),
1 => t('Hourly'),
2 => t('Twice daily'),
3 => t('Daily'),
4 => t('Weekly'),
5 => t('Monthly')
);
foreach ($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
$o .= "</select>\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;
}
}

View File

@ -1,12 +1,11 @@
<?php
/**
* @file src/Object/Post.php
*/
namespace Friendica\Object;
use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
@ -397,7 +396,7 @@ class Post extends BaseObject
'thread_level' => $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'],