]> git.mxchange.org Git - friendica.git/blobdiff - mod/profiles.php
Merge pull request #970 from annando/master
[friendica.git] / mod / profiles.php
index d4a3db83e0b104516c9c28fcdbfb49e3533825c2..06b85045001a5bcd41ca19cf6e1ed397d36e581f 100644 (file)
@@ -1,6 +1,145 @@
 <?php
 
 
+function profiles_init(&$a) {
+
+       nav_set_selected('profiles');
+
+       if(! local_user()) {
+               return;
+       }
+
+       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())
+               );
+               if(! count($r)) {
+                       notice( t('Profile not found.') . EOL);
+                       goaway($a->get_baseurl(true) . '/profiles');
+                       return; // NOTREACHED
+               }
+
+               check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
+
+               // move every contact using this profile as their default to the user default
+
+               $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
+                       intval(local_user()),
+                       intval($a->argv[2]),
+                       intval(local_user())
+               );
+               $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
+                       intval($a->argv[2]),
+                       intval(local_user())
+               );
+               if($r)
+                       info( t('Profile deleted.') . EOL);
+
+               goaway($a->get_baseurl(true) . '/profiles');
+               return; // NOTREACHED
+       }
+
+
+
+
+
+       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);
+
+               $name = t('Profile-') . ($num_profiles + 1);
+
+               $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
+                       intval(local_user()));
+
+               $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
+                       VALUES ( %d, '%s', '%s', '%s', '%s' )",
+                       intval(local_user()),
+                       dbesc($name),
+                       dbesc($r1[0]['name']),
+                       dbesc($r1[0]['photo']),
+                       dbesc($r1[0]['thumb'])
+               );
+
+               $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
+                       intval(local_user()),
+                       dbesc($name)
+               );
+
+               info( t('New profile created.') . EOL);
+               if(count($r3) == 1)
+                       goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
+
+               goaway($a->get_baseurl(true) . '/profiles');
+       }
+
+       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);
+
+               $name = t('Profile-') . ($num_profiles + 1);
+               $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                       intval(local_user()),
+                       intval($a->argv[2])
+               );
+               if(! count($r1)) {
+                       notice( t('Profile unavailable to clone.') . EOL);
+                       killme();
+                       return;
+               }
+               unset($r1[0]['id']);
+               $r1[0]['is-default'] = 0;
+               $r1[0]['publish'] = 0;
+               $r1[0]['net-publish'] = 0;
+               $r1[0]['profile-name'] = dbesc($name);
+
+               dbesc_array($r1[0]);
+
+               $r2 = dbq("INSERT INTO `profile` (`"
+                       . implode("`, `", array_keys($r1[0]))
+                       . "`) VALUES ('"
+                       . implode("', '", array_values($r1[0]))
+                       . "')" );
+
+               $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
+                       intval(local_user()),
+                       dbesc($name)
+               );
+               info( t('New profile created.') . EOL);
+               if(count($r3) == 1)
+                       goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
+
+               goaway($a->get_baseurl(true) . '/profiles');
+
+               return; // NOTREACHED
+       }
+
+
+       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())
+               );
+               if(! count($r)) {
+                       notice( t('Profile not found.') . EOL);
+                       killme();
+                       return;
+               }
+
+               profile_load($a,$a->user['nickname'],$r[0]['id']);
+       }
+
+}
+
 function profiles_post(&$a) {
 
        if(! local_user()) {
@@ -21,9 +160,9 @@ function profiles_post(&$a) {
                        notice( t('Profile not found.') . EOL);
                        return;
                }
-               
+
                check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
-               
+
                $is_default = (($orig[0]['is-default']) ? 1 : 0);
 
                $profile_name = notags(trim($_POST['profile_name']));
@@ -31,7 +170,7 @@ function profiles_post(&$a) {
                        notify( t('Profile Name is required.') . EOL);
                        return;
                }
-       
+
                $year = intval($_POST['year']);
                if($year < 1900 || $year > 2100 || $year < 0)
                        $year = 0;
@@ -120,7 +259,7 @@ function profiles_post(&$a) {
                                                        intval(local_user())
                                                );
                                        }*/
-                                       
+
                                        $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
                                                dbesc($newname),
                                                intval(local_user())
@@ -149,6 +288,10 @@ function profiles_post(&$a) {
 
                $sexual = notags(trim($_POST['sexual']));
                $homepage = notags(trim($_POST['homepage']));
+               if (strpos($homepage, 'http') !== 0) {
+                   // neither http nor https in URL, add them
+                   $homepage = 'http://'.$homepage;
+               }
                $hometown = notags(trim($_POST['hometown']));
                $politic = notags(trim($_POST['politic']));
                $religion = notags(trim($_POST['religion']));
@@ -233,9 +376,9 @@ function profiles_post(&$a) {
 
                        profile_activity($changes,$value);
 
-               }                       
-                       
-               $r = q("UPDATE `profile` 
+               }
+
+               $r = q("UPDATE `profile`
                        SET `profile-name` = '%s',
                        `name` = '%s',
                        `pdesc` = '%s',
@@ -269,7 +412,7 @@ function profiles_post(&$a) {
                        `work` = '%s',
                        `education` = '%s',
                        `hide-friends` = %d
-                       WHERE `id` = %d AND `uid` = %d LIMIT 1",
+                       WHERE `id` = %d AND `uid` = %d",
                        dbesc($profile_name),
                        dbesc($name),
                        dbesc($pdesc),
@@ -312,10 +455,14 @@ function profiles_post(&$a) {
 
 
                if($namechanged && $is_default) {
-                       $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
+                       $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
                                dbesc(datetime_convert()),
                                intval(local_user())
                        );
+                       $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
+                               dbesc($name),
+                               intval(local_user())
+                       );
                }
 
                if($is_default) {
@@ -411,7 +558,7 @@ function profile_activity($changed, $value) {
        if($i) {
 
                // give it a permanent link
-               q("update item set plink = '%s' where id = %d limit 1",
+               q("update item set plink = '%s' where id = %d",
                        dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
                        intval($i)
                );
@@ -424,127 +571,12 @@ function profile_activity($changed, $value) {
 
 function profiles_content(&$a) {
 
-       $o = '';
-       nav_set_selected('profiles');
-
        if(! local_user()) {
                notice( t('Permission denied.') . EOL);
                return;
        }
 
-       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())
-               );
-               if(! count($r)) {
-                       notice( t('Profile not found.') . EOL);
-                       goaway($a->get_baseurl(true) . '/profiles');
-                       return; // NOTREACHED
-               }
-               
-               check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
-
-               // move every contact using this profile as their default to the user default
-
-               $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
-                       intval(local_user()),
-                       intval($a->argv[2]),
-                       intval(local_user())
-               );
-               $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                       intval($a->argv[2]),
-                       intval(local_user())
-               );
-               if($r)
-                       info( t('Profile deleted.') . EOL);
-
-               goaway($a->get_baseurl(true) . '/profiles');
-               return; // NOTREACHED
-       }
-
-
-
-
-
-       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);
-
-               $name = t('Profile-') . ($num_profiles + 1);
-
-               $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
-                       intval(local_user()));
-               
-               $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
-                       VALUES ( %d, '%s', '%s', '%s', '%s' )",
-                       intval(local_user()),
-                       dbesc($name),
-                       dbesc($r1[0]['name']),
-                       dbesc($r1[0]['photo']),
-                       dbesc($r1[0]['thumb'])
-               );
-
-               $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
-                       intval(local_user()),
-                       dbesc($name)
-               );
-
-               info( t('New profile created.') . EOL);
-               if(count($r3) == 1)
-                       goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
-               
-               goaway($a->get_baseurl(true) . '/profiles');
-       } 
-
-       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);
-
-               $name = t('Profile-') . ($num_profiles + 1);
-               $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
-                       intval(local_user()),
-                       intval($a->argv[2])
-               );
-               if(! count($r1)) {
-                       notice( t('Profile unavailable to clone.') . EOL);
-                       return;
-               }
-               unset($r1[0]['id']);
-               $r1[0]['is-default'] = 0;
-               $r1[0]['publish'] = 0;  
-               $r1[0]['net-publish'] = 0;      
-               $r1[0]['profile-name'] = dbesc($name);
-
-               dbesc_array($r1[0]);
-
-               $r2 = dbq("INSERT INTO `profile` (`" 
-                       . implode("`, `", array_keys($r1[0])) 
-                       . "`) VALUES ('" 
-                       . implode("', '", array_values($r1[0])) 
-                       . "')" );
-
-               $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
-                       intval(local_user()),
-                       dbesc($name)
-               );
-               info( t('New profile created.') . EOL);
-               if(count($r3) == 1)
-                       goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
-               
-               goaway($a->get_baseurl(true) . '/profiles');
-               
-               return; // NOTREACHED
-       }
-
+       $o = '';
 
        if(($a->argc > 1) && (intval($a->argv[1]))) {
                $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -556,8 +588,6 @@ function profiles_content(&$a) {
                        return;
                }
 
-               profile_load($a,$a->user['nickname'],$r[0]['id']);
-
                require_once('include/profile_selectors.php');
 
 
@@ -602,6 +632,7 @@ function profiles_content(&$a) {
                        '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
                        '$banner' => t('Edit Profile Details'),
                        '$submit' => t('Submit'),
+                       '$profpic' => t('Change Profile Photo'),
                        '$viewprof' => t('View this profile'),
                        '$cr_prof' => t('Create a new profile using these settings'),
                        '$cl_prof' => t('Clone this profile'),