]> git.mxchange.org Git - friendica.git/commitdiff
Move Model\Profile::getTabs to new Module\BaseProfile class
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 26 Jan 2020 14:49:11 +0000 (09:49 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 26 Jan 2020 19:21:18 +0000 (14:21 -0500)
mod/cal.php
mod/events.php
mod/notes.php
mod/photos.php
mod/videos.php
src/Model/Profile.php
src/Module/BaseProfile.php [new file with mode: 0644]
src/Module/Profile/Contacts.php
src/Module/Profile/Index.php
src/Module/Profile/Status.php

index e6570018b7cb64aa8fcc972c5ff6b21b3992a2df..9e32b87d6f60bc829eb8a9c7c3936b3c855ddc4b 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
+use Friendica\Module\BaseProfile;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
 
@@ -121,7 +122,7 @@ function cal_content(App $a)
        $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
 
        // 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
        if ($mode == 'view') {
index 5601c4449a86291d08ffb04349c3e70a623235ff..ffe67f67fededc099898f0157159120936157d80 100644 (file)
@@ -16,8 +16,8 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
@@ -251,7 +251,7 @@ function events_content(App $a)
        $tabs = '';
        // tabs
        if ($a->theme_events_in_profile) {
-               $tabs = Profile::getTabs($a, 'events', true);
+               $tabs = BaseProfile::getTabsHTML($a, 'events', true);
        }
 
        $mode = 'view';
index 536029338f815f174969a696fdfc0d59c60976b8..38a72a741fd7e4ba2c3a0bfe62ab22034687fa79 100644 (file)
@@ -9,7 +9,7 @@ use Friendica\Content\Pager;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
-use Friendica\Model\Profile;
+use Friendica\Module\BaseProfile;
 
 function notes_init(App $a)
 {
@@ -28,7 +28,7 @@ function notes_content(App $a, $update = false)
                return;
        }
 
-       $o = Profile::getTabs($a, 'notes', true);
+       $o = BaseProfile::getTabsHTML($a, 'notes', true);
 
        if (!$update) {
                $o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';
index 5b8d22b655fa7ec8fd9103f5b5045643ac77ecb8..0733bbc96001f5e1fe0d98afd04241a5d166145f 100644 (file)
@@ -21,6 +21,7 @@ use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\Activity;
@@ -914,7 +915,7 @@ function photos_content(App $a)
 
        // tabs
        $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
        if ($datatype === 'upload') {
index a7181d4e78aade725eac94e3b57adfc5d2c75393..36ddef68147bcc1e30dbad6ff6053cd403077996 100644 (file)
@@ -15,6 +15,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Util\Security;
 
 function videos_init(App $a)
@@ -171,7 +172,7 @@ function videos_content(App $a)
 
        // tabs
        $_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
index 86fb1a94cbb22aeb48ecef35492eb423bd4a12fe..18b09225e780cad1e661fa8ee8395a1fac1eed4a 100644 (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
         *
diff --git a/src/Module/BaseProfile.php b/src/Module/BaseProfile.php
new file mode 100644 (file)
index 0000000..c6ef1c3
--- /dev/null
@@ -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']]);
+       }
+}
index 1a21df0ece64ec9b49b76ac1544c6405534699cc..122681c1708afb34d7b0be2fb1e3e6e031033d67 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Friendica\Module\Profile;
 
-use Friendica\BaseModule;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Nav;
 use Friendica\Content\Pager;
@@ -13,9 +12,10 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
+use Friendica\Module\BaseProfile;
 use Friendica\Util\Proxy as ProxyUtils;
 
-class Contacts extends BaseModule
+class Contacts extends BaseProfile
 {
        public static function content(array $parameters = [])
        {
@@ -42,8 +42,7 @@ class Contacts extends BaseModule
 
                $is_owner = $a->profile['uid'] == local_user();
 
-               // tabs
-               $o = Profile::getTabs($a, 'contacts', $is_owner, $nickname);
+               $o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
 
                if (!count($a->profile) || $a->profile['hide-friends']) {
                        notice(DI::l10n()->t('Permission denied.') . EOL);
index 521a682dc8a5b1e1e2e46c6e918fd4246413ddfa..176bc84e2effdd6651f357c34a209273e2f47249 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Friendica\Module\Profile;
 
-use Friendica\BaseModule;
 use Friendica\Content\Feature;
 use Friendica\Content\ForumManager;
 use Friendica\Content\Nav;
@@ -19,13 +18,14 @@ use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 use Friendica\Model\Term;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
 
-class Index extends BaseModule
+class Index extends BaseProfile
 {
        public static function rawContent(array $parameters = [])
        {
@@ -82,7 +82,7 @@ class Index extends BaseModule
                Nav::setSelected('home');
 
                $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) {
                        notice(DI::l10n()->t('Access to this profile has been restricted.'));
index 0047f27ed07fb77a607c91ab9a8e75fa7c0620de..5e1ec2538457c6c8eefe6a1d6a5b08ddc4ee6b1f 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Friendica\Module\Profile;
 
-use Friendica\BaseModule;
 use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Widget;
@@ -13,13 +12,14 @@ use Friendica\DI;
 use Friendica\Model\Item;
 use Friendica\Model\Profile as ProfileModel;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
 
-class Status extends BaseModule
+class Status extends BaseProfile
 {
        public static function content(array $parameters = [])
        {
@@ -81,7 +81,7 @@ class Status extends BaseModule
                        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']);