]> git.mxchange.org Git - friendica.git/blobdiff - mod/profiles.php
Fix profile wrong DISTINCT + ORDER BY
[friendica.git] / mod / profiles.php
index 0aea672021916962f6c93b48a5e61f367385348a..2b8d812c18da19c30400f769540db3478a501064 100644 (file)
@@ -10,7 +10,7 @@ function profiles_init(App $a) {
                return;
        }
 
-       if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
+       if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
                $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
                        intval($a->argv[2]),
                        intval(local_user())
@@ -34,24 +34,22 @@ function profiles_init(App $a) {
                        intval($a->argv[2]),
                        intval(local_user())
                );
-               if($r)
+               if (dbm::is_result($r)) {
                        info(t('Profile deleted.').EOL);
+               }
 
                goaway('profiles');
                return; // NOTREACHED
        }
 
-
-
-
-
-       if(($a->argc > 1) && ($a->argv[1] === 'new')) {
+       if (($a->argc > 1) && ($a->argv[1] === 'new')) {
 
                check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
 
                $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
                        intval(local_user()));
-               $num_profiles = count($r0);
+
+               $num_profiles = (dbm::is_result($r0) ? count($r0) : 0);
 
                $name = t('Profile-') . ($num_profiles + 1);
 
@@ -73,19 +71,21 @@ function profiles_init(App $a) {
                );
 
                info( t('New profile created.') . EOL);
-               if(count($r3) == 1)
-                       goaway('profiles/'.$r3[0]['id']);
+               if (dbm::is_result($r3) && count($r3) == 1) {
+                       goaway('profiles/' . $r3[0]['id']);
+               }
 
                goaway('profiles');
        }
 
-       if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
+       if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
 
                check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
 
                $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
                        intval(local_user()));
-               $num_profiles = count($r0);
+
+               $num_profiles = (dbm::is_result($r0) ? count($r0) : 0);
 
                $name = t('Profile-') . ($num_profiles + 1);
                $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
@@ -116,8 +116,9 @@ function profiles_init(App $a) {
                        dbesc($name)
                );
                info( t('New profile created.') . EOL);
-               if ((dbm::is_result($r3)) && (count($r3) == 1))
+               if ((dbm::is_result($r3)) && (count($r3) == 1)) {
                        goaway('profiles/'.$r3[0]['id']);
+               }
 
                goaway('profiles');
 
@@ -125,7 +126,7 @@ function profiles_init(App $a) {
        }
 
 
-       if(($a->argc > 1) && (intval($a->argv[1]))) {
+       if (($a->argc > 1) && (intval($a->argv[1]))) {
                $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($a->argv[1]),
                        intval(local_user())
@@ -136,7 +137,7 @@ function profiles_init(App $a) {
                        return;
                }
 
-               profile_load($a,$a->user['nickname'],$r[0]['id']);
+               profile_load($a,$a->user['nickname'], $r[0]['id']);
        }
 
 
@@ -144,15 +145,16 @@ function profiles_init(App $a) {
 }
 
 function profile_clean_keywords($keywords) {
-       $keywords = str_replace(","," ",$keywords);
+       $keywords = str_replace(",", " ", $keywords);
        $keywords = explode(" ", $keywords);
 
        $cleaned = array();
        foreach ($keywords as $keyword) {
                $keyword = trim(strtolower($keyword));
                $keyword = trim($keyword, "#");
-               if ($keyword != "")
+               if ($keyword != "") {
                        $cleaned[] = $keyword;
+               }
        }
 
        $keywords = implode(", ", $cleaned);
@@ -171,12 +173,12 @@ function profiles_post(App $a) {
 
        call_hooks('profile_post', $_POST);
 
-       if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
+       if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
                $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($a->argv[1]),
                        intval(local_user())
                );
-               if(! count($orig)) {
+               if (! dbm::is_result($orig)) {
                        notice( t('Profile not found.') . EOL);
                        return;
                }
@@ -186,38 +188,40 @@ function profiles_post(App $a) {
                $is_default = (($orig[0]['is-default']) ? 1 : 0);
 
                $profile_name = notags(trim($_POST['profile_name']));
-               if(! strlen($profile_name)) {
+               if (! strlen($profile_name)) {
                        notice( t('Profile Name is required.') . EOL);
                        return;
                }
 
                $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated?
 
-               $y = substr($dob,0,4);
-               if((! ctype_digit($y)) || ($y < 1900))
+               $y = substr($dob, 0, 4);
+               if ((! ctype_digit($y)) || ($y < 1900)) {
                        $ignore_year = true;
-               else
+               } else {
                        $ignore_year = false;
-               if($dob != '0000-00-00') {
-                       if(strpos($dob,'0000-') === 0) {
+               }
+               if ($dob != '0000-00-00') {
+                       if (strpos($dob, '0000-') === 0) {
                                $ignore_year = true;
-                               $dob = substr($dob,5);
+                               $dob = substr($dob, 5);
                        }
-                       $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d'));
-                       if($ignore_year)
+                       $dob = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d'));
+
+                       if ($ignore_year) {
                                $dob = '0000-' . $dob;
+                       }
                }
 
                $name = notags(trim($_POST['name']));
 
-               if(! strlen($name)) {
+               if (! strlen($name)) {
                        $name = '[No Name]';
                }
 
-               if($orig[0]['name'] != $name)
+               if ($orig[0]['name'] != $name) {
                        $namechanged = true;
-
-
+               }
 
                $pdesc = notags(trim($_POST['pdesc']));
                $gender = notags(trim($_POST['gender']));
@@ -233,29 +237,30 @@ function profiles_post(App $a) {
 
                $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
 
-               if(! strlen($howlong)) {
+               if (! strlen($howlong)) {
                        $howlong = NULL_DATE;
                } else {
-                       $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
+                       $howlong = datetime_convert(date_default_timezone_get(), 'UTC', $howlong);
                }
                // linkify the relationship target if applicable
 
                $withchanged = false;
 
-               if(strlen($with)) {
-                       if($with != strip_tags($orig[0]['with'])) {
+               if (strlen($with)) {
+                       if ($with != strip_tags($orig[0]['with'])) {
                                $withchanged = true;
                                $prf = '';
                                $lookup = $with;
-                               if(strpos($lookup,'@') === 0)
-                                       $lookup = substr($lookup,1);
+                               if (strpos($lookup, '@') === 0) {
+                                       $lookup = substr($lookup, 1);
+                               }
                                $lookup = str_replace('_',' ', $lookup);
-                               if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
+                               if (strpos($lookup, '@') || (strpos($lookup, 'http://'))) {
                                        $newname = $lookup;
                                        $links = @Probe::lrdd($lookup);
-                                       if(count($links)) {
-                                               foreach($links as $link) {
-                                                       if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
+                                       if (count($links)) {
+                                               foreach ($links as $link) {
+                                                       if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
                                                                $prf = $link['@attributes']['href'];
                                                        }
                                                }
@@ -280,16 +285,17 @@ function profiles_post(App $a) {
                                }
 
                                if ($prf) {
-                                       $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
-                                       if (strpos($with,'@') === 0) {
+                                       $with = str_replace($lookup, '<a href="' . $prf . '">' . $newname . '</a>', $with);
+                                       if (strpos($with, '@') === 0) {
                                                $with = substr($with, 1);
                                        }
                                }
-                       }
-                       else
+                       } else {
                                $with = $orig[0]['with'];
+                       }
                }
 
+               /// @TODO Not flexible enough for later expansion, let's have more OOP here
                $sexual = notags(trim($_POST['sexual']));
                $xmpp = notags(trim($_POST['xmpp']));
                $homepage = notags(trim($_POST['homepage']));
@@ -317,7 +323,7 @@ function profiles_post(App $a) {
 
                $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
 
-               set_pconfig(local_user(),'system','detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
+               set_pconfig(local_user(), 'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
 
                $changes = array();
                $value = '';
@@ -461,9 +467,8 @@ function profiles_post(App $a) {
                        intval(local_user())
                );
 
-               /// @TODO decide to use dbm::is_result() here and check $r
                if ($r) {
-                       info( t('Profile updated.') . EOL);
+                       info(t('Profile updated.') . EOL);
                }
 
 
@@ -492,7 +497,7 @@ function profiles_post(App $a) {
 
                        // Update global directory in background
                        $url = $_SESSION['my_url'];
-                       if ($url && strlen(get_config('system','directory'))) {
+                       if ($url && strlen(get_config('system', 'directory'))) {
                                proc_run(PRIORITY_LOW, "include/directory.php", $url);
                        }
 
@@ -513,11 +518,11 @@ function profile_activity($changed, $value) {
                return;
        }
 
-       if ($a->user['hidewall'] || get_config('system','block_public')) {
+       if ($a->user['hidewall'] || get_config('system', 'block_public')) {
                return;
        }
 
-       if (! get_pconfig(local_user(),'system','post_profilechange')) {
+       if (! get_pconfig(local_user(), 'system', 'post_profilechange')) {
                return;
        }
 
@@ -632,7 +637,7 @@ function profiles_content(App $a) {
                                t('Hide contacts and friends:'), //Label
                                !!$r[0]['hide-friends'], //Value
                                '', //Help string
-                               array(t('No'),t('Yes')) //Off - On strings
+                               array(t('No'), t('Yes')) //Off - On strings
                        ),
                        '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
                        '$yes_str' => t('Yes'),
@@ -644,11 +649,12 @@ function profiles_content(App $a) {
                $personal_account = !(in_array($a->user["page-flags"],
                                        array(PAGE_COMMUNITY, PAGE_PRVGROUP)));
 
-               $detailled_profile = (get_pconfig(local_user(),'system','detailled_profile') AND $personal_account);
+               $detailled_profile = (get_pconfig(local_user(), 'system', 'detailled_profile') AND $personal_account);
 
-               $f = get_config('system','birthday_input_format');
-               if(! $f)
+               $f = get_config('system', 'birthday_input_format');
+               if (! $f) {
                        $f = 'ymd';
+               }
 
                $is_default = (($r[0]['is-default']) ? 1 : 0);
                $tpl = get_markup_template("profile_edit.tpl");
@@ -664,10 +670,10 @@ function profiles_content(App $a) {
                                array(t('No'), t('Yes')) //Off - On strings
                        ),
 
-                       '$multi_profiles'               => feature_enabled(local_user(),'multi_profiles'),
+                       '$multi_profiles'               => feature_enabled(local_user(), 'multi_profiles'),
                        '$form_security_token'          => get_form_security_token("profile_edit"),
                        '$form_security_token_photo'    => get_form_security_token("profile_photo"),
-                       '$profile_clone_link'           => ((feature_enabled(local_user(),'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
+                       '$profile_clone_link'           => ((feature_enabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
                        '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
 
                        '$profile_action' => t('Profile Actions'),
@@ -733,7 +739,7 @@ function profiles_content(App $a) {
                        '$tv' => array('tv', t('Television'), $r[0]['tv']),
                        '$film' => array('film', t('Film/dance/culture/entertainment'), $r[0]['film']),
                        '$interest' => array('interest', t('Hobbies/Interests'), $r[0]['interest']),
-                       '$romance' => array('romance',t('Love/romance'), $r[0]['romance']),
+                       '$romance' => array('romance', t('Love/romance'), $r[0]['romance']),
                        '$work' => array('work', t('Work/employment'), $r[0]['work']),
                        '$education' => array('education', t('School/education'), $r[0]['education']),
                        '$contact' => array('contact', t('Contact information and Social Networks'), $r[0]['contact']),
@@ -746,13 +752,13 @@ function profiles_content(App $a) {
        } else {
 
                // If we don't support multi profiles, don't display this list.
-               if (!feature_enabled(local_user(),'multi_profiles')){
+               if (!feature_enabled(local_user(), 'multi_profiles')) {
                        $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
                                local_user()
                        );
-                       if (dbm::is_result($r)){
+                       if (dbm::is_result($r)) {
                                //Go to the default profile.
-                               goaway('profiles/'.$r[0]['id']);
+                               goaway('profiles/' . $r[0]['id']);
                        }
                }