]> git.mxchange.org Git - friendica.git/blobdiff - mod/profiles.php
Merge pull request #3769 from annando/show-forum-posts
[friendica.git] / mod / profiles.php
index 3d7e9fd96d3485f594de1e79f5c9abd7de2623fb..4a1d1ad93479033342ec504ff7cfa949b3f0ce78 100644 (file)
@@ -1,6 +1,11 @@
 <?php
-require_once("include/Contact.php");
-require_once('include/Probe.php');
+
+use Friendica\App;
+use Friendica\Core\System;
+use Friendica\Network\Probe;
+
+require_once 'include/Contact.php';
+require_once 'include/socgraph.php';
 
 function profiles_init(App $a) {
 
@@ -34,7 +39,7 @@ function profiles_init(App $a) {
                        intval($a->argv[2]),
                        intval(local_user())
                );
-               if ($r) {
+               if (dbm::is_result($r)) {
                        info(t('Profile deleted.').EOL);
                }
 
@@ -42,17 +47,14 @@ function profiles_init(App $a) {
                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);
+
+               $num_profiles = (dbm::is_result($r0) ? count($r0) : 0);
 
                $name = t('Profile-') . ($num_profiles + 1);
 
@@ -74,8 +76,9 @@ 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');
        }
@@ -86,14 +89,15 @@ function profiles_init(App $a) {
 
                $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",
                        intval(local_user()),
                        intval($a->argv[2])
                );
-               if (! dbm::is_result($r1)) {
+               if(! dbm::is_result($r1)) {
                        notice( t('Profile unavailable to clone.') . EOL);
                        killme();
                        return;
@@ -104,21 +108,16 @@ function profiles_init(App $a) {
                $r1[0]['net-publish'] = 0;
                $r1[0]['profile-name'] = dbesc($name);
 
-               dbm::esc_array($r1[0], true);
-
-               $r2 = dbq("INSERT INTO `profile` (`"
-                       . implode("`, `", array_keys($r1[0]))
-                       . "`) VALUES ("
-                       . implode(", ", array_values($r1[0]))
-                       . ")" );
+               dba::insert('profile', $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 ((dbm::is_result($r3)) && (count($r3) == 1))
+               if ((dbm::is_result($r3)) && (count($r3) == 1)) {
                        goaway('profiles/'.$r3[0]['id']);
+               }
 
                goaway('profiles');
 
@@ -137,7 +136,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']);
        }
 
 
@@ -145,15 +144,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);
@@ -177,7 +177,7 @@ function profiles_post(App $a) {
                        intval($a->argv[1]),
                        intval(local_user())
                );
-               if (! count($orig)) {
+               if (! dbm::is_result($orig)) {
                        notice( t('Profile not found.') . EOL);
                        return;
                }
@@ -192,21 +192,24 @@ function profiles_post(App $a) {
                        return;
                }
 
-               $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated?
+               $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0001-01-01'; // 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 (!in_array($dob, array('0000-00-00', '0001-01-01'))) {
+                       if (strpos($dob, '0000-') === 0 || strpos($dob, '0001-') === 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 = '0001-' . $dob;
                        }
-                       $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']));
@@ -215,10 +218,9 @@ function profiles_post(App $a) {
                        $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']));
@@ -237,7 +239,7 @@ function profiles_post(App $a) {
                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
 
@@ -248,13 +250,12 @@ function profiles_post(App $a) {
                                $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;
-                                       /// @TODO Maybe kill those error/debugging-surpressing @ characters
                                        $links = @Probe::lrdd($lookup);
                                        if (count($links)) {
                                                foreach ($links as $link) {
@@ -265,23 +266,12 @@ function profiles_post(App $a) {
                                        }
                                } else {
                                        $newname = $lookup;
-/*                                     if (strstr($lookup,' ')) {
-                                               $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
-                                                       dbesc($newname),
-                                                       intval(local_user())
-                                               );
-                                       } else {
-                                               $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
-                                                       dbesc($lookup),
-                                                       intval(local_user())
-                                               );
-                                       }*/
 
                                        $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
                                                dbesc($newname),
                                                intval(local_user())
                                        );
-                                       if (! $r) {
+                                       if (! dbm::is_result($r)) {
                                                $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
                                                        dbesc($lookup),
                                                        intval(local_user())
@@ -294,15 +284,17 @@ function profiles_post(App $a) {
                                }
 
                                if ($prf) {
-                                       $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname        . '</a>', $with);
-                                       if (strpos($with,'@') === 0)
-                                               $with = substr($with,1);
+                                       $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']));
@@ -330,7 +322,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 = '';
@@ -475,7 +467,7 @@ function profiles_post(App $a) {
                );
 
                if ($r) {
-                       info( t('Profile updated.') . EOL);
+                       info(t('Profile updated.') . EOL);
                }
 
 
@@ -504,12 +496,11 @@ 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);
                        }
 
-                       require_once('include/profile_update.php');
-                       profile_change();
+                       proc_run(PRIORITY_LOW, 'include/profile_update.php', local_user());
 
                        // Update the global contact for the user
                        update_gcontact_for_user(local_user());
@@ -521,23 +512,27 @@ function profiles_post(App $a) {
 function profile_activity($changed, $value) {
        $a = get_app();
 
-       if (! local_user() || ! is_array($changed) || ! count($changed))
+       if (! local_user() || ! is_array($changed) || ! count($changed)) {
                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;
+       }
 
-       require_once('include/items.php');
+       require_once 'include/items.php';
 
        $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
                intval(local_user())
        );
 
-       if (! count($self))
+       if (! dbm::is_result($self)) {
                return;
+       }
 
        $arr = array();
 
@@ -563,10 +558,11 @@ function profile_activity($changed, $value) {
        $z = 0;
        foreach ($changed as $ch) {
                if (strlen($changes)) {
-                       if ($z == ($t - 1))
+                       if ($z == ($t - 1)) {
                                $changes .= t(' and ');
-                       else
+                       } else {
                                $changes .= ', ';
+                       }
                }
                $z ++;
                $changes .= $ch;
@@ -577,9 +573,9 @@ function profile_activity($changed, $value) {
        if ($t == 1 && strlen($value)) {
                $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
                $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
-       }
-       else
+       } else {
                $message =      sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
+       }
 
 
        $arr['body'] = $message;
@@ -622,14 +618,14 @@ function profiles_content(App $a) {
                        return;
                }
 
-               require_once('include/profile_selectors.php');
+               require_once 'include/profile_selectors.php';
 
 
                $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
-                       '$baseurl' => App::get_baseurl(true),
+                       '$baseurl' => System::baseUrl(true),
                ));
                $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
-                       '$baseurl' => App::get_baseurl(true),
+                       '$baseurl' => System::baseUrl(true),
                ));
 
                $opt_tpl = get_markup_template("profile-hide-friends.tpl");
@@ -639,7 +635,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'),
@@ -651,15 +647,16 @@ 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");
-               $o .= replace_macros($tpl,array(
+               $o .= replace_macros($tpl, array(
                        '$personal_account' => $personal_account,
                        '$detailled_profile' => $detailled_profile,
 
@@ -668,13 +665,13 @@ function profiles_content(App $a) {
                                t('Show more profile fields:'), //Label
                                $detailled_profile, //Value
                                '', //Help string
-                               array(t('No'),t('Yes')) //Off - On strings
+                               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'),
@@ -705,7 +702,7 @@ function profiles_content(App $a) {
                        '$lbl_ex2' => t('Example: fishing photography software'),
 
                        '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
-                       '$baseurl' => App::get_baseurl(true),
+                       '$baseurl' => System::baseUrl(true),
                        '$profile_id' => $r[0]['id'],
                        '$profile_name' => array('profile_name', t('Profile Name:'), $r[0]['profile-name'], t('Required'), '*'),
                        '$is_default'   => $is_default,
@@ -740,7 +737,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']),
@@ -750,25 +747,22 @@ function profiles_content(App $a) {
                call_hooks('profile_edit', $arr);
 
                return $o;
-       }
+       } else {
 
-       //Profiles list.
-       else {
-
-               //If we don't support multi profiles, don't display this list.
-               if (!feature_enabled(local_user(),'multi_profiles')){
-                       $r = q(
-                               "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
+               // If we don't support multi profiles, don't display this list.
+               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']);
                        }
                }
 
                $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
                        local_user());
+
                if (dbm::is_result($r)) {
 
                        $tpl = get_markup_template('profile_entry.tpl');