X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fprofiles.php;h=01030914c47bd095b7806403ab52ea63eead1a44;hb=47bd3243cdb4a4840ca4d40452402a86b792ce1b;hp=233b276a37aef2003542cbc6a6910f725aec8a07;hpb=239dfea4e63061bb2e7c31ce058f74ac10d46a5a;p=friendica.git diff --git a/mod/profiles.php b/mod/profiles.php index 233b276a37..01030914c4 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -1,6 +1,10 @@ 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 +38,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 +75,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 +120,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 +130,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 +141,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 +149,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); @@ -191,29 +197,29 @@ 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); + $y = substr($dob, 0, 4); if ((! ctype_digit($y)) || ($y < 1900)) { $ignore_year = true; } 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 = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d')); if ($ignore_year) { - $dob = '0000-' . $dob; + $dob = '0001-' . $dob; } } $name = notags(trim($_POST['name'])); - if(! strlen($name)) { + if (! strlen($name)) { $name = '[No Name]'; } @@ -235,10 +241,10 @@ 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 @@ -249,7 +255,7 @@ function profiles_post(App $a) { $withchanged = true; $prf = ''; $lookup = $with; - if (strpos($lookup,'@') === 0) { + if (strpos($lookup, '@') === 0) { $lookup = substr($lookup, 1); } $lookup = str_replace('_',' ', $lookup); @@ -465,7 +471,6 @@ 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); } @@ -500,8 +505,7 @@ function profiles_post(App $a) { 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()); @@ -525,7 +529,7 @@ function profile_activity($changed, $value) { 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()) @@ -619,7 +623,7 @@ 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( @@ -636,7 +640,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'), @@ -738,7 +742,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']),