Renaming functions and class

This commit is contained in:
Jonny Tischbein 2018-10-13 11:23:52 +02:00
parent 93ab82b7f0
commit cdbddd0103
8 changed files with 84 additions and 1212 deletions

View file

@ -8,11 +8,10 @@ use Friendica\Content\ContactSelector;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Profile;
use Friendica\Model;\
use Friendica\Module\Contact;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Module\Contacts;
require_once 'include/dba.php';
@ -42,13 +41,13 @@ function allfriends_content(App $a)
}
$a->page['aside'] = "";
Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
$total = GContact::countAllFriends(local_user(), $cid);
$total = Model\GContact::countAllFriends(local_user(), $cid);
$a->setPagerTotal($total);
$r = GContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
$r = Model\GContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
if (!DBA::isResult($r)) {
$o .= L10n::t('No friends to display.');
return $o;
@ -59,7 +58,7 @@ function allfriends_content(App $a)
$entries = [];
foreach ($r as $rr) {
//get further details of the contact
$contact_details = Contact::getDetailsByURL($rr['url'], $uid, $rr);
$contact_details = Model\Contact::getDetailsByURL($rr['url'], $uid, $rr);
$photo_menu = '';
@ -68,11 +67,11 @@ function allfriends_content(App $a)
// If the contact is not common to the user, Connect/Follow' will be added to the photo menu
if ($rr['cid']) {
$rr['id'] = $rr['cid'];
$photo_menu = Contact::photoMenu($rr);
$photo_menu = Model\Contact::photoMenu($rr);
} else {
$connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
$photo_menu = [
'profile' => [L10n::t("View Profile"), Contact::magicLink($rr['url'])],
'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($rr['url'])],
'follow' => [L10n::t("Connect/Follow"), $connlnk]
];
}
@ -86,7 +85,7 @@ function allfriends_content(App $a)
'details' => $contact_details['location'],
'tags' => $contact_details['keywords'],
'about' => $contact_details['about'],
'account_type' => Contact::getAccountType($contact_details),
'account_type' => Model\Contact::getAccountType($contact_details),
'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
'photo_menu' => $photo_menu,
'conntxt' => L10n::t('Connect'),
@ -96,7 +95,7 @@ function allfriends_content(App $a)
$entries[] = $entry;
}
$tab_str = Contacts::contacts_tab($a, $contact, 4);
$tab_str = Contact::getTabsHTML($a, $contact, 4);
$tpl = get_markup_template('viewcontact_template.tpl');

View file

@ -7,11 +7,10 @@ use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Profile;
use Friendica\Model;
use Friendica\Module\Contact;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Module\Contacts;
require_once 'include/dba.php';
@ -42,7 +41,7 @@ function common_content(App $a)
if (DBA::isResult($contact)) {
$a->page['aside'] = "";
Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
Model\Profile::load($a, "", 0,Model\Contact::getDetailsByURL($contact["url"]));
}
} else {
$contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['self' => true, 'uid' => $uid]);
@ -65,12 +64,12 @@ function common_content(App $a)
return;
}
if (!$cid && Profile::getMyURL()) {
$contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $uid]);
if (!$cid &&Model\Profile::getMyURL()) {
$contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link(Model\Profile::getMyURL()), 'uid' => $uid]);
if (DBA::isResult($contact)) {
$cid = $contact['id'];
} else {
$gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
$gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Model\Profile::getMyURL())]);
if (DBA::isResult($gcontact)) {
$zcid = $gcontact['id'];
}
@ -82,9 +81,9 @@ function common_content(App $a)
}
if ($cid) {
$t = GContact::countCommonFriends($uid, $cid);
$t =Model\GContact::countCommonFriends($uid, $cid);
} else {
$t = GContact::countCommonFriendsZcid($uid, $zcid);
$t =Model\GContact::countCommonFriendsZcid($uid, $zcid);
}
if ($t > 0) {
@ -95,9 +94,9 @@ function common_content(App $a)
}
if ($cid) {
$r = GContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
$r =Model\GContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
} else {
$r = GContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
$r =Model\GContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
}
if (!DBA::isResult($r)) {
@ -109,13 +108,13 @@ function common_content(App $a)
$entries = [];
foreach ($r as $rr) {
//get further details of the contact
$contact_details = Contact::getDetailsByURL($rr['url'], $uid);
$contact_details =Model\Contact::getDetailsByURL($rr['url'], $uid);
// $rr['id'] is needed to use contact_photo_menu()
/// @TODO Adding '/" here avoids E_NOTICE on missing constants
$rr['id'] = $rr['cid'];
$photo_menu = Contact::photoMenu($rr);
$photo_menu =Model\Contact::photoMenu($rr);
$entry = [
'url' => $rr['url'],
@ -126,7 +125,7 @@ function common_content(App $a)
'details' => $contact_details['location'],
'tags' => $contact_details['keywords'],
'about' => $contact_details['about'],
'account_type' => Contact::getAccountType($contact_details),
'account_type' =>Model\Contact::getAccountType($contact_details),
'network' => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
'photo_menu' => $photo_menu,
'id' => ++$id,
@ -137,7 +136,7 @@ function common_content(App $a)
$title = '';
$tab_str = '';
if ($cmd === 'loc' && $cid && local_user() == $uid) {
$tab_str = Contacts::contacts_tab($a, $contact, 4);
$tab_str = Contact::getTabsHTML($a, $contact, 4);
} else {
$title = L10n::t('Common Friends');
}

File diff suppressed because it is too large Load diff

View file

@ -8,9 +8,8 @@ use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\Contacts;
use Friendica\Model;
use Friendica\Module\Contact;
require_once 'mod/contacts.php';
@ -83,7 +82,7 @@ function crepair_post(App $a)
if ($photo) {
logger('mod-crepair: updating photo from ' . $photo);
Contact::updateAvatar($photo, local_user(), $contact['id']);
Model\Contact::updateAvatar($photo, local_user(), $contact['id']);
}
if ($r) {
@ -136,7 +135,7 @@ function crepair_content(App $a)
$update_profile = in_array($contact['network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]);
$tab_str = Contacts::contacts_tab($a, $contact, 5);
$tab_str = Contact::getTabsHTML($a, $contact, 5);
$tpl = get_markup_template('crepair.tpl');
$o = replace_macros($tpl, [

View file

@ -12,13 +12,13 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model;
use Friendica\Module\Contact;
use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Module\Contacts;
function dirfind_init(App $a) {
@ -82,7 +82,7 @@ function dirfind_content(App $a, $prefix = "") {
$objresult->tags = "";
$objresult->network = $user_data["network"];
$contact = Contact::getDetailsByURL($user_data["url"], local_user());
$contact = Model\Contact::getDetailsByURL($user_data["url"], local_user());
$objresult->cid = $contact["cid"];
$objresult->pcid = $contact["zid"];
@ -90,7 +90,7 @@ function dirfind_content(App $a, $prefix = "") {
// Add the contact to the global contacts if it isn't already in our system
if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
GContact::update($user_data);
Model\GContact::update($user_data);
}
} elseif ($local) {
@ -155,7 +155,7 @@ function dirfind_content(App $a, $prefix = "") {
continue;
}
$result = Contact::getDetailsByURL($result["nurl"], local_user());
$result = Model\Contact::getDetailsByURL($result["nurl"], local_user());
if ($result["name"] == "") {
$result["name"] = end(explode("/", $urlparts["path"]));
@ -199,7 +199,7 @@ function dirfind_content(App $a, $prefix = "") {
$alt_text = "";
$contact_details = Contact::getDetailsByURL($jj->url, local_user());
$contact_details = Model\Contact::getDetailsByURL($jj->url, local_user());
$itemurl = (($contact_details["addr"] != "") ? $contact_details["addr"] : $jj->url);
@ -209,8 +209,8 @@ function dirfind_content(App $a, $prefix = "") {
$conntxt = "";
$contact = DBA::selectFirst('contact', [], ['id' => $jj->cid]);
if (DBA::isResult($contact)) {
$photo_menu = Contact::photoMenu($contact);
$details = Contacts::_contact_detail_for_template($contact);
$photo_menu =Model\Contact::photoMenu($contact);
$details = Contact::getContactTemplateVars($contact);
$alt_text = $details['alt_text'];
} else {
$photo_menu = [];
@ -221,7 +221,7 @@ function dirfind_content(App $a, $prefix = "") {
$contact = DBA::selectFirst('contact', [], ['id' => $jj->pcid]);
if (DBA::isResult($contact)) {
$photo_menu = Contact::photoMenu($contact);
$photo_menu = Model\Contact::photoMenu($contact);
} else {
$photo_menu = [];
}
@ -234,7 +234,7 @@ function dirfind_content(App $a, $prefix = "") {
$entry = [
'alt_text' => $alt_text,
'url' => Contact::magicLink($jj->url),
'url' => Model\Contact::magicLink($jj->url),
'itemurl' => $itemurl,
'name' => htmlentities($jj->name),
'thumb' => ProxyUtils::proxifyUrl($jj->photo, false, ProxyUtils::SIZE_THUMB),
@ -245,7 +245,7 @@ function dirfind_content(App $a, $prefix = "") {
'details' => $contact_details['location'],
'tags' => $contact_details['keywords'],
'about' => $contact_details['about'],
'account_type' => Contact::getAccountType($contact_details),
'account_type' => Model\Contact::getAccountType($contact_details),
'network' => ContactSelector::networkToName($jj->network, $jj->url),
'id' => ++$id,
];

View file

@ -11,9 +11,8 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Module\Contacts;
use Friendica\Model;
use Friendica\Module\Contact;
function group_init(App $a) {
if (local_user()) {
@ -186,7 +185,7 @@ function group_content(App $a) {
}
$group = $r[0];
$members = Contact::getByGroupId($group['id']);
$members = Model\Contact::getByGroupId($group['id']);
$preselected = [];
$entry = [];
$id = 0;
@ -204,7 +203,7 @@ function group_content(App $a) {
Group::addMember($group['id'], $change);
}
$members = Contact::getByGroupId($group['id']);
$members = Model\Contact::getByGroupId($group['id']);
$preselected = [];
if (count($members)) {
foreach ($members as $member) {
@ -250,7 +249,7 @@ function group_content(App $a) {
// Format the data of the group members
foreach ($members as $member) {
if ($member['url']) {
$entry = Contacts::_contact_detail_for_template($member);
$entry = Contact::getContactTemplateVars($member);
$entry['label'] = 'members';
$entry['photo_menu'] = '';
$entry['change_member'] = [
@ -267,7 +266,7 @@ function group_content(App $a) {
}
if ($nogroup) {
$r = Contact::getUngroupedList(local_user());
$r = Model\Contact::getUngroupedList(local_user());
} else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC",
intval(local_user())
@ -279,7 +278,7 @@ function group_content(App $a) {
// Format the data of the contacts who aren't in the contact group
foreach ($r as $member) {
if (!in_array($member['id'], $preselected)) {
$entry = Contacts::_contact_detail_for_template($member);
$entry = Contact::getContactTemplateVars($member);
$entry['label'] = 'contacts';
if (!$nogroup)
$entry['photo_menu'] = [];

View file

@ -29,7 +29,7 @@ use Friendica\Module\Login;
*
* @brief manages contacts
*/
class Contacts extends BaseModule
class Contact extends BaseModule
{
public static function init()
{
@ -129,7 +129,7 @@ class Contacts extends BaseModule
]);
}
private static function contacts_batch_actions(App $a)
private static function batchActions(App $a)
{
if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) {
return;
@ -146,25 +146,25 @@ class Contacts extends BaseModule
foreach ($orig_records as $orig_record) {
$contact_id = $orig_record['id'];
if (x($_POST, 'contacts_batch_update')) {
self::_contact_update($contact_id);
self::updateContactFromPoll($contact_id);
$count_actions++;
}
if (x($_POST, 'contacts_batch_block')) {
self::_contact_block($contact_id);
self::blockContact($contact_id);
$count_actions++;
}
if (x($_POST, 'contacts_batch_ignore')) {
self::_contact_ignore($contact_id);
self::ignoreContact($contact_id);
$count_actions++;
}
if (x($_POST, 'contacts_batch_archive')) {
$r = self::_contact_archive($contact_id, $orig_record);
$r = self::archiveContact($contact_id, $orig_record);
if ($r) {
$count_actions++;
}
}
if (x($_POST, 'contacts_batch_drop')) {
self::_contact_drop($orig_record);
self::dropContact($orig_record);
$count_actions++;
}
}
@ -184,7 +184,7 @@ class Contacts extends BaseModule
}
if ($a->argv[1] === "batch") {
self::contacts_batch_actions($a);
self::batchActions($a);
return;
}
@ -253,7 +253,7 @@ class Contacts extends BaseModule
/* contact actions */
private static function _contact_update($contact_id)
private static function updateContactFromPoll($contact_id)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
if (!DBA::isResult($contact)) {
@ -274,7 +274,7 @@ class Contacts extends BaseModule
}
}
private static function _contact_update_profile($contact_id)
private static function updateContactFromProbe($contact_id)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]);
if (!DBA::isResult($contact)) {
@ -340,19 +340,19 @@ class Contacts extends BaseModule
GContact::updateFromProbe($data["url"]);
}
private static function _contact_block($contact_id)
private static function blockContact($contact_id)
{
$blocked = !Contact::isBlockedByUser($contact_id, local_user());
Contact::setBlockedForUser($contact_id, local_user(), $blocked);
}
private static function _contact_ignore($contact_id)
private static function ignoreContact($contact_id)
{
$ignored = !Contact::isIgnoredByUser($contact_id, local_user());
Contact::setIgnoredForUser($contact_id, local_user(), $ignored);
}
private static function _contact_archive($contact_id, $orig_record)
private static function archiveContact($contact_id, $orig_record)
{
$archived = (($orig_record['archive']) ? 0 : 1);
$r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
@ -363,7 +363,7 @@ class Contacts extends BaseModule
return DBA::isResult($r);
}
private static function _contact_drop($orig_record)
private static function dropContact($orig_record)
{
$a = get_app();
@ -407,19 +407,19 @@ class Contacts extends BaseModule
}
if ($cmd === 'update' && ($orig_record['uid'] != 0)) {
self::_contact_update($contact_id);
self::updateContactFromPoll($contact_id);
goaway('contacts/' . $contact_id);
// NOTREACHED
}
if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
self::_contact_update_profile($contact_id);
self::updateContactFromProbe($contact_id);
goaway('crepair/' . $contact_id);
// NOTREACHED
}
if ($cmd === 'block') {
self::_contact_block($contact_id);
self::blockContact($contact_id);
$blocked = Contact::isBlockedByUser($contact_id, local_user());
info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL);
@ -429,7 +429,7 @@ class Contacts extends BaseModule
}
if ($cmd === 'ignore') {
self::_contact_ignore($contact_id);
self::ignoreContact($contact_id);
$ignored = Contact::isIgnoredByUser($contact_id, local_user());
info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL);
@ -439,7 +439,7 @@ class Contacts extends BaseModule
}
if ($cmd === 'archive' && ($orig_record['uid'] != 0)) {
$r = self::_contact_archive($contact_id, $orig_record);
$r = self::archiveContact($contact_id, $orig_record);
if ($r) {
$archived = (($orig_record['archive']) ? 0 : 1);
info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL);
@ -467,7 +467,7 @@ class Contacts extends BaseModule
return replace_macros(get_markup_template('contact_drop_confirm.tpl'), [
'$header' => L10n::t('Drop contact'),
'$contact' => self::_contact_detail_for_template($orig_record),
'$contact' => self::getContactTemplateVars($orig_record),
'$method' => 'get',
'$message' => L10n::t('Do you really want to delete this contact?'),
'$extra_inputs' => $inputs,
@ -482,17 +482,17 @@ class Contacts extends BaseModule
goaway('contacts');
}
self::_contact_drop($orig_record);
self::dropContact($orig_record);
info(L10n::t('Contact has been removed.') . EOL);
goaway('contacts');
return; // NOTREACHED
}
if ($cmd === 'posts') {
return self::contact_posts($a, $contact_id);
return self::getPostsHTML($a, $contact_id);
}
if ($cmd === 'conversations') {
return self::contact_conversations($a, $contact_id, $update);
return self::getConversationsHMTL($a, $contact_id, $update);
}
}
@ -562,7 +562,7 @@ class Contacts extends BaseModule
$nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"]));
// tabs
$tab_str = self::contacts_tab($a, $contact, 3);
$tab_str = self::getTabsHTML($a, $contact, 3);
$lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < DateTimeFormat::utcNow()) ? L10n::t('Communications lost with this contact!') : '');
@ -605,7 +605,7 @@ class Contacts extends BaseModule
}
// Load contactact related actions like hide, suggest, delete and others
$contact_actions = self::contact_actions($contact);
$contact_actions = self::getContactActions($contact);
if ($contact['uid'] != 0) {
$lbl_vis1 = L10n::t('Profile Visibility');
@ -822,7 +822,7 @@ class Contacts extends BaseModule
foreach ($r as $rr) {
$rr['blocked'] = Contact::isBlockedByUser($rr['id'], local_user());
$rr['readonly'] = Contact::isIgnoredByUser($rr['id'], local_user());
$contacts[] = self::_contact_detail_for_template($rr);
$contacts[] = self::getContactTemplateVars($rr);
}
}
@ -865,7 +865,7 @@ class Contacts extends BaseModule
*
* @return string
*/
public static function contacts_tab($a, $contact, $active_tab)
public static function getTabsHTML($a, $contact, $active_tab)
{
// tabs
$tabs = [
@ -934,7 +934,7 @@ class Contacts extends BaseModule
return $tab_str;
}
private static function contact_conversations($a, $contact_id, $update)
private static function getConversationsHMTL($a, $contact_id, $update)
{
$o = '';
@ -959,7 +959,7 @@ class Contacts extends BaseModule
$contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
if (!$update) {
$o .= self::contacts_tab($a, $contact, 1);
$o .= self::getTabsHTML($a, $contact, 1);
}
if (DBA::isResult($contact)) {
@ -980,11 +980,11 @@ class Contacts extends BaseModule
return $o;
}
private static function contact_posts($a, $contact_id)
private static function getPostsHTML($a, $contact_id)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id]);
$o = self::contacts_tab($a, $contact, 2);
$o = self::getTabsHTML($a, $contact, 2);
if (DBA::isResult($contact)) {
$a->page['aside'] = "";
@ -1004,7 +1004,7 @@ class Contacts extends BaseModule
return $o;
}
public static function _contact_detail_for_template(array $rr)
public static function getContactTemplateVars(array $rr)
{
$dir_icon = '';
$alt_text = '';
@ -1071,7 +1071,7 @@ class Contacts extends BaseModule
* @param array $contact Data about the Contact
* @return array with contact related actions
*/
private static function contact_actions($contact)
private static function getContactActions($contact)
{
$poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]);
$contact_actions = [];
@ -1133,5 +1133,4 @@ class Contacts extends BaseModule
return $contact_actions;
}
}
}

View file

@ -333,7 +333,7 @@ function frio_acl_lookup(App $a, &$results)
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$contacts[] = Contacts::_contact_detail_for_template($rr);
$contacts[] = Contacts::getContactTemplateVars($rr);
}
}