Move Model\Profile::getTabs to new Module\BaseProfile class

This commit is contained in:
Hypolite Petovan 2020-01-26 09:49:11 -05:00
parent 0f5d6a009f
commit f2d917114f
10 changed files with 148 additions and 132 deletions

View file

@ -19,6 +19,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Event; use Friendica\Model\Event;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
@ -121,7 +122,7 @@ function cal_content(App $a)
$sql_extra = " AND `event`.`cid` = 0 " . $sql_perms; $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
// get the tab navigation bar // get the tab navigation bar
$tabs = Profile::getTabs($a, 'cal', false, $a->data['user']['nickname']); $tabs = BaseProfile::getTabsHTML($a, 'cal', false, $a->data['user']['nickname']);
// The view mode part is similiar to /mod/events.php // The view mode part is similiar to /mod/events.php
if ($mode == 'view') { if ($mode == 'view') {

View file

@ -16,8 +16,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Event; use Friendica\Model\Event;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -251,7 +251,7 @@ function events_content(App $a)
$tabs = ''; $tabs = '';
// tabs // tabs
if ($a->theme_events_in_profile) { if ($a->theme_events_in_profile) {
$tabs = Profile::getTabs($a, 'events', true); $tabs = BaseProfile::getTabsHTML($a, 'events', true);
} }
$mode = 'view'; $mode = 'view';

View file

@ -9,7 +9,7 @@ use Friendica\Content\Pager;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Module\BaseProfile;
function notes_init(App $a) function notes_init(App $a)
{ {
@ -28,7 +28,7 @@ function notes_content(App $a, $update = false)
return; return;
} }
$o = Profile::getTabs($a, 'notes', true); $o = BaseProfile::getTabsHTML($a, 'notes', true);
if (!$update) { if (!$update) {
$o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>'; $o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';

View file

@ -21,6 +21,7 @@ use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -914,7 +915,7 @@ function photos_content(App $a)
// tabs // tabs
$is_owner = (local_user() && (local_user() == $owner_uid)); $is_owner = (local_user() && (local_user() == $owner_uid));
$o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']); $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
// Display upload form // Display upload form
if ($datatype === 'upload') { if ($datatype === 'upload') {

View file

@ -15,6 +15,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Util\Security; use Friendica\Util\Security;
function videos_init(App $a) function videos_init(App $a)
@ -171,7 +172,7 @@ function videos_content(App $a)
// tabs // tabs
$_is_owner = (local_user() && (local_user() == $owner_uid)); $_is_owner = (local_user() && (local_user() == $owner_uid));
$o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']); $o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $a->data['user']['nickname']);
// //
// dispatch request // dispatch request

View file

@ -675,121 +675,6 @@ class Profile
]); ]);
} }
/**
* @param App $a
* @param string $current
* @param bool $is_owner
* @param string $nickname
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getTabs(App $a, string $current, bool $is_owner, string $nickname = null)
{
if (is_null($nickname)) {
$nickname = $a->user['nickname'];
}
$baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
$tabs = [
[
'label' => DI::l10n()->t('Profile'),
'url' => $baseProfileUrl,
'sel' => $current == 'profile' ? 'active' : '',
'title' => DI::l10n()->t('Profile Details'),
'id' => 'profile-tab',
'accesskey' => 'r',
],
[
'label' => DI::l10n()->t('Status'),
'url' => $baseProfileUrl . '/status',
'sel' => $current == 'status' ? 'active' : '',
'title' => DI::l10n()->t('Status Messages and Posts'),
'id' => 'status-tab',
'accesskey' => 'm',
],
[
'label' => DI::l10n()->t('Photos'),
'url' => DI::baseUrl() . '/photos/' . $nickname,
'sel' => $current == 'photos' ? 'active' : '',
'title' => DI::l10n()->t('Photo Albums'),
'id' => 'photo-tab',
'accesskey' => 'h',
],
[
'label' => DI::l10n()->t('Videos'),
'url' => DI::baseUrl() . '/videos/' . $nickname,
'sel' => $current == 'videos' ? 'active' : '',
'title' => DI::l10n()->t('Videos'),
'id' => 'video-tab',
'accesskey' => 'v',
],
];
// the calendar link for the full featured events calendar
if ($is_owner && $a->theme_events_in_profile) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/events',
'sel' => $current == 'events' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
// if the user is not the owner of the calendar we only show a calendar
// with the public events of the calendar owner
} elseif (!$is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/cal/' . $nickname,
'sel' => $current == 'cal' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
}
if ($is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Personal Notes'),
'url' => DI::baseUrl() . '/notes',
'sel' => $current == 'notes' ? 'active' : '',
'title' => DI::l10n()->t('Only You Can See This'),
'id' => 'notes-tab',
'accesskey' => 't',
];
}
if (empty($a->profile['hide-friends'])) {
$tabs[] = [
'label' => DI::l10n()->t('Contacts'),
'url' => $baseProfileUrl . '/contacts',
'sel' => $current == 'contacts' ? 'active' : '',
'title' => DI::l10n()->t('Contacts'),
'id' => 'viewcontacts-tab',
'accesskey' => 'k',
];
}
if (!empty($_SESSION['new_member']) && $is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Tips for New Members'),
'url' => DI::baseUrl() . '/newmember',
'sel' => false,
'title' => DI::l10n()->t('Tips for New Members'),
'id' => 'newmember-tab',
];
}
$arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs];
Hook::callAll('profile_tabs', $arr);
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
}
/** /**
* Retrieves the my_url session variable * Retrieves the my_url session variable
* *

129
src/Module/BaseProfile.php Normal file
View file

@ -0,0 +1,129 @@
<?php
namespace Friendica\Module;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
class BaseProfile extends BaseModule
{
/**
* Returns the HTML for the profile pages tabs
*
* @param App $a
* @param string $current
* @param bool $is_owner
* @param string $nickname
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getTabsHTML(App $a, string $current, bool $is_owner, string $nickname = null)
{
if (is_null($nickname)) {
$nickname = $a->user['nickname'];
}
$baseProfileUrl = DI::baseUrl() . '/profile/' . $nickname;
$tabs = [
[
'label' => DI::l10n()->t('Profile'),
'url' => $baseProfileUrl,
'sel' => $current == 'profile' ? 'active' : '',
'title' => DI::l10n()->t('Profile Details'),
'id' => 'profile-tab',
'accesskey' => 'r',
],
[
'label' => DI::l10n()->t('Status'),
'url' => $baseProfileUrl . '/status',
'sel' => $current == 'status' ? 'active' : '',
'title' => DI::l10n()->t('Status Messages and Posts'),
'id' => 'status-tab',
'accesskey' => 'm',
],
[
'label' => DI::l10n()->t('Photos'),
'url' => DI::baseUrl() . '/photos/' . $nickname,
'sel' => $current == 'photos' ? 'active' : '',
'title' => DI::l10n()->t('Photo Albums'),
'id' => 'photo-tab',
'accesskey' => 'h',
],
[
'label' => DI::l10n()->t('Videos'),
'url' => DI::baseUrl() . '/videos/' . $nickname,
'sel' => $current == 'videos' ? 'active' : '',
'title' => DI::l10n()->t('Videos'),
'id' => 'video-tab',
'accesskey' => 'v',
],
];
// the calendar link for the full featured events calendar
if ($is_owner && $a->theme_events_in_profile) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/events',
'sel' => $current == 'events' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
// if the user is not the owner of the calendar we only show a calendar
// with the public events of the calendar owner
} elseif (!$is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Events'),
'url' => DI::baseUrl() . '/cal/' . $nickname,
'sel' => $current == 'cal' ? 'active' : '',
'title' => DI::l10n()->t('Events and Calendar'),
'id' => 'events-tab',
'accesskey' => 'e',
];
}
if ($is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Personal Notes'),
'url' => DI::baseUrl() . '/notes',
'sel' => $current == 'notes' ? 'active' : '',
'title' => DI::l10n()->t('Only You Can See This'),
'id' => 'notes-tab',
'accesskey' => 't',
];
}
if (empty($a->profile['hide-friends'])) {
$tabs[] = [
'label' => DI::l10n()->t('Contacts'),
'url' => $baseProfileUrl . '/contacts',
'sel' => $current == 'contacts' ? 'active' : '',
'title' => DI::l10n()->t('Contacts'),
'id' => 'viewcontacts-tab',
'accesskey' => 'k',
];
}
if (DI::session()->get('new_member') && $is_owner) {
$tabs[] = [
'label' => DI::l10n()->t('Tips for New Members'),
'url' => DI::baseUrl() . '/newmember',
'sel' => false,
'title' => DI::l10n()->t('Tips for New Members'),
'id' => 'newmember-tab',
];
}
$arr = ['is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $current, 'tabs' => $tabs];
Hook::callAll('profile_tabs', $arr);
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
}
}

View file

@ -2,7 +2,6 @@
namespace Friendica\Module\Profile; namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\ContactSelector; use Friendica\Content\ContactSelector;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Pager; use Friendica\Content\Pager;
@ -13,9 +12,10 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\BaseProfile;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
class Contacts extends BaseModule class Contacts extends BaseProfile
{ {
public static function content(array $parameters = []) public static function content(array $parameters = [])
{ {
@ -42,8 +42,7 @@ class Contacts extends BaseModule
$is_owner = $a->profile['uid'] == local_user(); $is_owner = $a->profile['uid'] == local_user();
// tabs $o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
$o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
if (!count($a->profile) || $a->profile['hide-friends']) { if (!count($a->profile) || $a->profile['hide-friends']) {
notice(DI::l10n()->t('Permission denied.') . EOL); notice(DI::l10n()->t('Permission denied.') . EOL);

View file

@ -2,7 +2,6 @@
namespace Friendica\Module\Profile; namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Content\ForumManager; use Friendica\Content\ForumManager;
use Friendica\Content\Nav; use Friendica\Content\Nav;
@ -19,13 +18,14 @@ use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Term; use Friendica\Model\Term;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
class Index extends BaseModule class Index extends BaseProfile
{ {
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
@ -82,7 +82,7 @@ class Index extends BaseModule
Nav::setSelected('home'); Nav::setSelected('home');
$is_owner = local_user() == $a->profile['uid']; $is_owner = local_user() == $a->profile['uid'];
$o = Profile::getTabs($a, 'profile', $is_owner, $a->profile['nickname']); $o = self::getTabsHTML($a, 'profile', $is_owner, $a->profile['nickname']);
if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) { if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
notice(DI::l10n()->t('Access to this profile has been restricted.')); notice(DI::l10n()->t('Access to this profile has been restricted.'));

View file

@ -2,7 +2,6 @@
namespace Friendica\Module\Profile; namespace Friendica\Module\Profile;
use Friendica\BaseModule;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Content\Widget; use Friendica\Content\Widget;
@ -13,13 +12,14 @@ use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile as ProfileModel; use Friendica\Model\Profile as ProfileModel;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Security; use Friendica\Util\Security;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
class Status extends BaseModule class Status extends BaseProfile
{ {
public static function content(array $parameters = []) public static function content(array $parameters = [])
{ {
@ -81,7 +81,7 @@ class Status extends BaseModule
return ''; return '';
} }
$o .= ProfileModel::getTabs($a, 'status', $is_owner, $a->profile['nickname']); $o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
$o .= Widget::commonFriendsVisitor($a->profile['uid']); $o .= Widget::commonFriendsVisitor($a->profile['uid']);