]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Profile.php
Fix backticks
[friendica.git] / src / Model / Profile.php
index a7f35f578213442158381d6a5ad0f7ed15ace67b..573af02c94f1c90d51ff446d37f962fb575ac607 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @file src/Model/Profile.php
  */
@@ -17,7 +16,9 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Protocol\Diaspora;
+use dba;
 
+require_once 'include/dba.php';
 require_once 'include/bbcode.php';
 require_once 'mod/proxy.php';
 
@@ -59,7 +60,7 @@ class Profile
 
        /**
         *
-        * @brief Loads a profile into the page sidebar.
+        * Loads a profile into the page sidebar.
         *
         * The function requires a writeable copy of the main App structure, and the nickname
         * of a registered local account.
@@ -76,18 +77,16 @@ class Profile
         *      the theme is chosen before the _init() function of a theme is run, which will usually
         *      load a lot of theme-specific content
         *
-        * @param object $a           App
-        * @param string $nickname    string
-        * @param int    $profile     int
-        * @param array  $profiledata array
+        * @brief Loads a profile into the page sidebar.
+        * @param object  $a            App
+        * @param string  $nickname     string
+        * @param int     $profile      int
+        * @param array   $profiledata  array
         * @param boolean $show_connect Show connect link
         */
-       function profile_load(App $a, $nickname, $profile = 0, $profiledata = array(), $show_connect = true)
+       public static function load(App $a, $nickname, $profile = 0, $profiledata = array(), $show_connect = true)
        {
-               $user = q(
-                       "SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
-                       dbesc($nickname)
-               );
+               $user = dba::selectFirst('user', ['uid'], ['nickname' => $nickname]);
 
                if (!$user && !count($user) && !count($profiledata)) {
                        logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
@@ -101,14 +100,14 @@ class Profile
                }
 
                if ($profiledata) {
-                       $a->page['aside'] .= profile_sidebar($profiledata, true, $show_connect);
+                       $a->page['aside'] .= self::sidebar($profiledata, true, $show_connect);
 
                        if (!DBM::is_result($user)) {
                                return;
                        }
                }
 
-               $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile);
+               $pdata = self::getByNickname($nickname, $user[0]['uid'], $profile);
 
                if (empty($pdata) && empty($profiledata)) {
                        logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
@@ -176,14 +175,14 @@ class Profile
                 * But: When this profile was on the same server, then we could display the contacts
                 */
                if (!$profiledata) {
-                       $a->page['aside'] .= profile_sidebar($a->profile, $block, $show_connect);
+                       $a->page['aside'] .= self::sidebar($a->profile, $block, $show_connect);
                }
 
                return;
        }
 
        /**
-        * @brief Get all profil data of a local user
+        * Get all profile data of a local user
         *
         * If the viewer is an authenticated remote viewer, the profile displayed is the
         * one that has been configured for his/her viewing in the Contact manager.
@@ -192,12 +191,13 @@ class Profile
         *
         * Includes all available profile data
         *
+        * @brief Get all profile data of a local user
         * @param string $nickname nick
         * @param int    $uid      uid
         * @param int    $profile_id  ID of the profile
-        * @returns array
+        * @return array
         */
-       function get_profiledata_by_nick($nickname, $uid = 0, $profile_id = 0)
+       public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
        {
                if (remote_user() && count($_SESSION['remote'])) {
                        foreach ($_SESSION['remote'] as $visitor) {
@@ -245,11 +245,12 @@ class Profile
        }
 
        /**
-        * @brief Formats a profile for display in the sidebar.
+        * Formats a profile for display in the sidebar.
         *
         * It is very difficult to templatise the HTML completely
         * because of all the conditional logic.
         *
+        * @brief Formats a profile for display in the sidebar.
         * @param array $profile
         * @param int $block
         * @param boolean $show_connect Show connect link
@@ -263,7 +264,7 @@ class Profile
         * @hooks 'profile_sidebar'
         *      array $arr
         */
-       function profile_sidebar($profile, $block = 0, $show_connect = true)
+       private static function sidebar($profile, $block = 0, $show_connect = true)
        {
                $a = get_app();
 
@@ -333,7 +334,7 @@ class Profile
                        $subscribe_feed = false;
                }
 
-               if (remote_user() || (get_my_url() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
+               if (remote_user() || (self::getMyURL() && x($profile, 'unkmail') && ($profile['uid'] != local_user()))) {
                        $wallmessage = t('Message');
                        $wallmessage_link = 'wallmessage/' . $profile['nickname'];
 
@@ -348,7 +349,7 @@ class Profile
                                $r = q(
                                        "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
                                        intval($profile['uid']),
-                                       dbesc(normalise_link(get_my_url())),
+                                       dbesc(normalise_link(self::getMyURL())),
                                        intval(CONTACT_IS_FRIEND)
                                );
                        }
@@ -524,7 +525,7 @@ class Profile
                return $o;
        }
 
-       function get_birthdays()
+       public static function getBirthdays()
        {
                $a = get_app();
                $o = '';
@@ -615,7 +616,7 @@ class Profile
                ));
        }
 
-       function get_events()
+       public static function getEvents()
        {
                require_once 'include/bbcode.php';
 
@@ -700,7 +701,7 @@ class Profile
                ));
        }
 
-       function advanced_profile(App $a)
+       public static function getAdvanced(App $a)
        {
                $o = '';
                $uid = $a->profile['uid'];
@@ -844,7 +845,7 @@ class Profile
                return '';
        }
 
-       function profile_tabs($a, $is_owner = false, $nickname = null)
+       public static function getTabs($a, $is_owner = false, $nickname = null)
        {
                if (is_null($nickname)) {
                        $nickname = $a->user['nickname'];
@@ -950,7 +951,7 @@ class Profile
         *
         * @return string
         */
-       function get_my_url()
+       public static function getMyURL()
        {
                if (x($_SESSION, 'my_url')) {
                        return $_SESSION['my_url'];
@@ -958,9 +959,9 @@ class Profile
                return null;
        }
 
-       function zrl_init(App $a)
+       public static function zrlInit(App $a)
        {
-               $my_url = get_my_url();
+               $my_url = self::getMyURL();
                $my_url = validate_url($my_url);
                if ($my_url) {
                        // Is it a DDoS attempt?
@@ -979,7 +980,7 @@ class Profile
                }
        }
 
-       function zrl($s, $force = false)
+       public static function zrl($s, $force = false)
        {
                if (!strlen($s)) {
                        return $s;
@@ -991,7 +992,7 @@ class Profile
                        $s = $s . '/';
                }
                $achar = strpos($s, '?') ? '&' : '?';
-               $mine = get_my_url();
+               $mine = self::getMyURL();
                if ($mine && !link_compare($mine, $s)) {
                        return $s . $achar . 'zrl=' . urlencode($mine);
                }
@@ -999,7 +1000,7 @@ class Profile
        }
 
        /**
-        * @brief Get the user ID of the page owner
+        * Get the user ID of the page owner.
         *
         * Used from within PCSS themes to set theme parameters. If there's a
         * puid request variable, that is the "page owner" and normally their theme
@@ -1007,12 +1008,13 @@ class Profile
         * system pconfig, which means they don't want to see anybody else's theme
         * settings except their own while on this site.
         *
+        * @brief Get the user ID of the page owner
         * @return int user ID
         *
         * @note Returns local_user instead of user ID if "always_my_theme"
         *      is set to true
         */
-       function get_theme_uid()
+       public static function getThemeUid()
        {
                $uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
                if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
@@ -1021,5 +1023,4 @@ class Profile
 
                return $uid;
        }
-
 }