2011-02-03 00:23:24 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-11 01:13:34 +00:00
|
|
|
class ProfileDetailSettingsAction extends ProfileSettingsAction
|
2011-02-03 00:23:24 +00:00
|
|
|
{
|
|
|
|
function title()
|
|
|
|
{
|
2011-06-05 10:35:11 +01:00
|
|
|
// TRANS: Title for extended profile settings.
|
2011-02-03 00:23:24 +00:00
|
|
|
return _m('Extended profile settings');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
|
|
|
function getInstructions()
|
|
|
|
{
|
|
|
|
// TRANS: Usage instructions for profile settings.
|
2011-03-17 10:38:18 +00:00
|
|
|
return _m('You can update your personal profile info here '.
|
2011-02-03 00:23:24 +00:00
|
|
|
'so people know more about you.');
|
|
|
|
}
|
|
|
|
|
|
|
|
function showStylesheets() {
|
|
|
|
parent::showStylesheets();
|
2011-03-13 23:32:13 +00:00
|
|
|
$this->cssLink('plugins/ExtendedProfile/css/profiledetail.css');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showScripts() {
|
|
|
|
parent::showScripts();
|
|
|
|
$this->script('plugins/ExtendedProfile/js/profiledetail.js');
|
2011-02-03 00:23:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
function handlePost()
|
2011-02-03 00:23:24 +00:00
|
|
|
{
|
2011-03-09 03:20:43 +00:00
|
|
|
// CSRF protection
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2011-03-16 07:23:34 +00:00
|
|
|
$this->showForm(
|
2011-06-05 10:35:11 +01:00
|
|
|
// TRANS: Client error displayed when the session token does not match or is not given.
|
|
|
|
_m('There was a problem with your session token. '
|
2011-03-09 03:20:43 +00:00
|
|
|
. 'Try again, please.'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->arg('save')) {
|
|
|
|
$this->saveDetails();
|
|
|
|
} else {
|
2011-03-17 10:38:18 +00:00
|
|
|
// TRANS: Message given submitting a form with an unknown action.
|
2011-03-09 03:20:43 +00:00
|
|
|
$this->showForm(_m('Unexpected form submission.'));
|
|
|
|
}
|
2011-02-03 00:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showContent()
|
|
|
|
{
|
|
|
|
$cur = common_current_user();
|
|
|
|
$profile = $cur->getProfile();
|
|
|
|
|
2011-03-10 03:27:21 +00:00
|
|
|
$widget = new ExtendedProfileWidget(
|
|
|
|
$this,
|
|
|
|
$profile,
|
|
|
|
ExtendedProfileWidget::EDITABLE
|
|
|
|
);
|
2011-02-03 00:23:24 +00:00
|
|
|
$widget->show();
|
|
|
|
}
|
2011-03-09 03:20:43 +00:00
|
|
|
|
|
|
|
function saveDetails()
|
|
|
|
{
|
|
|
|
common_debug(var_export($_POST, true));
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
try {
|
2011-03-15 00:27:50 +00:00
|
|
|
$this->saveStandardProfileDetails($user);
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-03-15 00:27:50 +00:00
|
|
|
$profile = $user->getProfile();
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-03-16 01:45:08 +00:00
|
|
|
$simpleFieldNames = array('title', 'spouse', 'kids', 'manager');
|
2011-03-15 22:35:00 +00:00
|
|
|
$dateFieldNames = array('birthday');
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-03-15 00:27:50 +00:00
|
|
|
foreach ($simpleFieldNames as $name) {
|
|
|
|
$value = $this->trimmed('extprofile-' . $name);
|
|
|
|
if (!empty($value)) {
|
|
|
|
$this->saveField($user, $name, $value);
|
|
|
|
}
|
2011-03-14 08:49:46 +00:00
|
|
|
}
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-03-15 22:35:00 +00:00
|
|
|
foreach ($dateFieldNames as $name) {
|
|
|
|
$value = $this->trimmed('extprofile-' . $name);
|
2011-03-16 08:09:38 +00:00
|
|
|
$dateVal = $this->parseDate($name, $value);
|
2011-03-15 22:35:00 +00:00
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
$name,
|
2011-03-16 08:09:38 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$dateVal
|
2011-03-15 22:35:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-15 00:27:50 +00:00
|
|
|
$this->savePhoneNumbers($user);
|
2011-03-15 05:38:34 +00:00
|
|
|
$this->saveIms($user);
|
2011-03-15 17:10:18 +00:00
|
|
|
$this->saveWebsites($user);
|
2011-03-15 00:27:50 +00:00
|
|
|
$this->saveExperiences($user);
|
2011-03-15 05:02:24 +00:00
|
|
|
$this->saveEducations($user);
|
2011-03-15 00:27:50 +00:00
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->showForm($e->getMessage(), false);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-10 22:14:21 +00:00
|
|
|
|
2011-06-05 10:35:11 +01:00
|
|
|
// TRANS: Success message after saving extended profile details.
|
2011-03-17 10:38:18 +00:00
|
|
|
$this->showForm(_m('Details saved.'), true);
|
2011-03-09 03:20:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-15 22:35:00 +00:00
|
|
|
function parseDate($fieldname, $datestr, $required = false)
|
|
|
|
{
|
2011-03-16 23:08:49 +00:00
|
|
|
if (empty($datestr)) {
|
|
|
|
if ($required) {
|
|
|
|
$msg = sprintf(
|
2011-03-17 10:38:18 +00:00
|
|
|
// TRANS: Exception thrown when no date was entered in a required date field.
|
|
|
|
// TRANS: %s is the field name.
|
2011-03-16 23:08:49 +00:00
|
|
|
_m('You must supply a date for "%s".'),
|
|
|
|
$fieldname
|
|
|
|
);
|
|
|
|
throw new Exception($msg);
|
|
|
|
}
|
2011-03-15 22:35:00 +00:00
|
|
|
} else {
|
|
|
|
$ts = strtotime($datestr);
|
|
|
|
if ($ts === false) {
|
|
|
|
throw new Exception(
|
|
|
|
sprintf(
|
2011-03-17 10:38:18 +00:00
|
|
|
// TRANS: Exception thrown on incorrect data input.
|
|
|
|
// TRANS: %1$s is a field name, %2$s is the incorrect input.
|
|
|
|
_m('Invalid date entered for "%1$s": %2$s.'),
|
2011-03-15 22:35:00 +00:00
|
|
|
$fieldname,
|
|
|
|
$ts
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return common_sql_date($ts);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
function savePhoneNumbers($user) {
|
|
|
|
$phones = $this->findPhoneNumbers();
|
2011-03-14 08:49:46 +00:00
|
|
|
$this->removeAll($user, 'phone');
|
|
|
|
$i = 0;
|
|
|
|
foreach($phones as $phone) {
|
|
|
|
if (!empty($phone['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'phone',
|
|
|
|
$phone['value'],
|
|
|
|
$phone['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
2011-03-10 22:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function findPhoneNumbers() {
|
2011-03-15 00:53:54 +00:00
|
|
|
|
2011-03-15 03:58:35 +00:00
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-phone-1' => '11332',
|
|
|
|
// 'extprofile-phone-1-rel' => 'mobile',
|
|
|
|
|
|
|
|
$phones = $this->sliceParams('phone', 2);
|
|
|
|
$phoneArray = array();
|
2011-03-10 22:14:21 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
foreach ($phones as $phone) {
|
2011-03-10 22:14:21 +00:00
|
|
|
list($number, $rel) = array_values($phone);
|
2011-03-15 03:58:35 +00:00
|
|
|
$phoneArray[] = array(
|
2011-03-10 22:14:21 +00:00
|
|
|
'value' => $number,
|
|
|
|
'rel' => $rel
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-15 03:58:35 +00:00
|
|
|
return $phoneArray;
|
2011-03-15 00:53:54 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 05:38:34 +00:00
|
|
|
function findIms() {
|
|
|
|
|
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-im-0' => 'jed',
|
|
|
|
// 'extprofile-im-0-rel' => 'yahoo',
|
|
|
|
|
|
|
|
$ims = $this->sliceParams('im', 2);
|
|
|
|
$imArray = array();
|
|
|
|
|
|
|
|
foreach ($ims as $im) {
|
|
|
|
list($id, $rel) = array_values($im);
|
|
|
|
$imArray[] = array(
|
|
|
|
'value' => $id,
|
|
|
|
'rel' => $rel
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $imArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveIms($user) {
|
|
|
|
$ims = $this->findIms();
|
|
|
|
$this->removeAll($user, 'im');
|
|
|
|
$i = 0;
|
|
|
|
foreach($ims as $im) {
|
|
|
|
if (!empty($im['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'im',
|
|
|
|
$im['value'],
|
|
|
|
$im['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 17:10:18 +00:00
|
|
|
function findWebsites() {
|
|
|
|
|
|
|
|
// Form vals look like this:
|
|
|
|
|
|
|
|
$sites = $this->sliceParams('website', 2);
|
|
|
|
$wsArray = array();
|
|
|
|
|
|
|
|
foreach ($sites as $site) {
|
|
|
|
list($id, $rel) = array_values($site);
|
|
|
|
$wsArray[] = array(
|
|
|
|
'value' => $id,
|
|
|
|
'rel' => $rel
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveWebsites($user) {
|
|
|
|
$sites = $this->findWebsites();
|
|
|
|
$this->removeAll($user, 'website');
|
|
|
|
$i = 0;
|
|
|
|
foreach($sites as $site) {
|
2013-10-07 13:46:09 +01:00
|
|
|
if (!empty($site['value']) && !common_valid_http_url($site['value'])) {
|
2011-03-17 10:38:18 +00:00
|
|
|
// TRANS: Exception thrown when entering an invalid URL.
|
|
|
|
// TRANS: %s is the invalid URL.
|
|
|
|
throw new Exception(sprintf(_m('Invalid URL: %s.'), $site['value']));
|
2011-03-16 09:41:32 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 17:10:18 +00:00
|
|
|
if (!empty($site['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'website',
|
|
|
|
$site['value'],
|
|
|
|
$site['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
function findExperiences() {
|
|
|
|
|
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-experience-0' => 'Bozotronix',
|
|
|
|
// 'extprofile-experience-0-current' => 'true'
|
|
|
|
// 'extprofile-experience-0-start' => '1/5/10',
|
|
|
|
// 'extprofile-experience-0-end' => '2/3/11',
|
|
|
|
|
2011-03-15 00:53:54 +00:00
|
|
|
$experiences = $this->sliceParams('experience', 4);
|
2011-03-14 22:29:11 +00:00
|
|
|
$expArray = array();
|
|
|
|
|
|
|
|
foreach ($experiences as $exp) {
|
2011-03-16 09:41:32 +00:00
|
|
|
if (sizeof($experiences) == 4) {
|
|
|
|
list($company, $current, $end, $start) = array_values($exp);
|
|
|
|
} else {
|
|
|
|
$end = null;
|
|
|
|
list($company, $current, $start) = array_values($exp);
|
|
|
|
}
|
2011-03-15 05:02:24 +00:00
|
|
|
if (!empty($company)) {
|
|
|
|
$expArray[] = array(
|
|
|
|
'company' => $company,
|
2011-03-15 22:35:00 +00:00
|
|
|
'start' => $this->parseDate('Start', $start, true),
|
2011-03-16 07:50:43 +00:00
|
|
|
'end' => ($current == 'false') ? $this->parseDate('End', $end, true) : null,
|
2011-03-15 05:02:24 +00:00
|
|
|
'current' => ($current == 'false') ? false : true
|
|
|
|
);
|
|
|
|
}
|
2011-03-14 22:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $expArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveExperiences($user) {
|
|
|
|
common_debug('save experiences');
|
|
|
|
$experiences = $this->findExperiences();
|
|
|
|
|
|
|
|
$this->removeAll($user, 'company');
|
|
|
|
$this->removeAll($user, 'start');
|
|
|
|
$this->removeAll($user, 'end'); // also stores 'current'
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach($experiences as $experience) {
|
|
|
|
if (!empty($experience['company'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'company',
|
|
|
|
$experience['company'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
2011-03-15 00:27:50 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'start',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$experience['start']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Save "current" employer indicator in rel
|
|
|
|
if ($experience['current']) {
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'end',
|
|
|
|
null,
|
|
|
|
'current', // rel
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'end',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$experience['end']
|
|
|
|
);
|
|
|
|
}
|
2011-03-15 00:27:50 +00:00
|
|
|
|
2011-03-14 22:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 05:02:24 +00:00
|
|
|
function findEducations() {
|
|
|
|
|
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-education-0-school' => 'Pigdog',
|
|
|
|
// 'extprofile-education-0-degree' => 'BA',
|
|
|
|
// 'extprofile-education-0-description' => 'Blar',
|
|
|
|
// 'extprofile-education-0-start' => '05/22/99',
|
|
|
|
// 'extprofile-education-0-end' => '05/22/05',
|
|
|
|
|
|
|
|
$edus = $this->sliceParams('education', 5);
|
|
|
|
$eduArray = array();
|
|
|
|
|
|
|
|
foreach ($edus as $edu) {
|
|
|
|
list($school, $degree, $description, $end, $start) = array_values($edu);
|
|
|
|
if (!empty($school)) {
|
|
|
|
$eduArray[] = array(
|
|
|
|
'school' => $school,
|
|
|
|
'degree' => $degree,
|
|
|
|
'description' => $description,
|
2011-03-15 22:35:00 +00:00
|
|
|
'start' => $this->parseDate('Start', $start, true),
|
|
|
|
'end' => $this->parseDate('End', $end, true)
|
2011-03-15 05:02:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $eduArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function saveEducations($user) {
|
|
|
|
common_debug('save education');
|
|
|
|
$edus = $this->findEducations();
|
|
|
|
common_debug(var_export($edus, true));
|
|
|
|
|
|
|
|
$this->removeAll($user, 'school');
|
|
|
|
$this->removeAll($user, 'degree');
|
|
|
|
$this->removeAll($user, 'degree_descr');
|
|
|
|
$this->removeAll($user, 'school_start');
|
|
|
|
$this->removeAll($user, 'school_end');
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach($edus as $edu) {
|
|
|
|
if (!empty($edu['school'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'school',
|
|
|
|
$edu['school'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'degree',
|
|
|
|
$edu['degree'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'degree_descr',
|
|
|
|
$edu['description'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'school_start',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$edu['start']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->saveField(
|
|
|
|
$user,
|
|
|
|
'school_end',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$edu['end']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
function arraySplit($array, $pieces)
|
2011-03-09 19:27:29 +00:00
|
|
|
{
|
2011-03-10 22:14:21 +00:00
|
|
|
if ($pieces < 2) {
|
|
|
|
return array($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
$newCount = ceil(count($array) / $pieces);
|
|
|
|
$a = array_slice($array, 0, $newCount);
|
2011-03-13 23:32:13 +00:00
|
|
|
$b = $this->arraySplit(array_slice($array, $newCount), $pieces - 1);
|
2011-03-09 19:27:29 +00:00
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
return array_merge(array($a), $b);
|
|
|
|
}
|
|
|
|
|
|
|
|
function findMultiParams($type) {
|
|
|
|
$formVals = array();
|
|
|
|
$target = $type;
|
|
|
|
foreach ($_POST as $key => $val) {
|
|
|
|
if (strrpos('extprofile-' . $key, $target) !== false) {
|
|
|
|
$formVals[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $formVals;
|
|
|
|
}
|
|
|
|
|
2011-03-15 03:58:35 +00:00
|
|
|
function sliceParams($key, $size) {
|
|
|
|
$slice = array();
|
|
|
|
$params = $this->findMultiParams($key);
|
|
|
|
ksort($params);
|
|
|
|
$slice = $this->arraySplit($params, sizeof($params) / $size);
|
|
|
|
return $slice;
|
|
|
|
}
|
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
/**
|
|
|
|
* Save an extended profile field as a Profile_detail
|
|
|
|
*
|
|
|
|
* @param User $user the current user
|
|
|
|
* @param string $name field name
|
|
|
|
* @param string $value field value
|
|
|
|
* @param string $rel field rel (type)
|
|
|
|
* @param int $index index (fields can have multiple values)
|
2011-03-14 22:29:11 +00:00
|
|
|
* @param date $date related date
|
2011-03-10 22:14:21 +00:00
|
|
|
*/
|
2011-03-14 22:29:11 +00:00
|
|
|
function saveField($user, $name, $value, $rel = null, $index = null, $date = null)
|
2011-03-10 22:14:21 +00:00
|
|
|
{
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
$detail = new Profile_detail();
|
2011-03-09 19:27:29 +00:00
|
|
|
|
|
|
|
$detail->profile_id = $profile->id;
|
2011-03-10 02:00:24 +00:00
|
|
|
$detail->field_name = $name;
|
2011-03-10 22:14:21 +00:00
|
|
|
$detail->value_index = $index;
|
2011-03-09 19:27:29 +00:00
|
|
|
|
|
|
|
$result = $detail->find(true);
|
|
|
|
|
|
|
|
if (empty($result)) {
|
2011-03-10 22:14:21 +00:00
|
|
|
$detial->value_index = $index;
|
|
|
|
$detail->rel = $rel;
|
2011-03-10 02:00:24 +00:00
|
|
|
$detail->field_value = $value;
|
2011-03-14 22:29:11 +00:00
|
|
|
$detail->date = $date;
|
2011-03-10 22:14:21 +00:00
|
|
|
$detail->created = common_sql_now();
|
2011-03-09 19:27:29 +00:00
|
|
|
$result = $detail->insert();
|
2011-03-10 02:00:24 +00:00
|
|
|
if (empty($result)) {
|
|
|
|
common_log_db_error($detail, 'INSERT', __FILE__);
|
2011-06-05 10:35:11 +01:00
|
|
|
// TRANS: Server error displayed when a field could not be saved in the database.
|
2011-03-10 02:00:24 +00:00
|
|
|
$this->serverError(_m('Could not save profile details.'));
|
|
|
|
}
|
2011-03-09 19:27:29 +00:00
|
|
|
} else {
|
|
|
|
$orig = clone($detail);
|
2011-03-10 22:14:21 +00:00
|
|
|
|
2011-03-10 02:00:24 +00:00
|
|
|
$detail->field_value = $value;
|
2011-03-10 22:14:21 +00:00
|
|
|
$detail->rel = $rel;
|
2011-03-14 22:29:11 +00:00
|
|
|
$detail->date = $date;
|
2011-03-10 02:00:24 +00:00
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
$result = $detail->update($orig);
|
|
|
|
if (empty($result)) {
|
|
|
|
common_log_db_error($detail, 'UPDATE', __FILE__);
|
2011-06-05 10:35:11 +01:00
|
|
|
// TRANS: Server error displayed when a field could not be saved in the database.
|
2011-03-10 22:14:21 +00:00
|
|
|
$this->serverError(_m('Could not save profile details.'));
|
|
|
|
}
|
2011-03-09 19:27:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$detail->free();
|
|
|
|
}
|
|
|
|
|
2011-03-14 08:49:46 +00:00
|
|
|
function removeAll($user, $name)
|
|
|
|
{
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
$detail = new Profile_detail();
|
|
|
|
$detail->profile_id = $profile->id;
|
|
|
|
$detail->field_name = $name;
|
|
|
|
$detail->delete();
|
|
|
|
$detail->free();
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Save fields that should be stored in the main profile object
|
|
|
|
*
|
|
|
|
* XXX: There's a lot of dupe code here from ProfileSettingsAction.
|
|
|
|
* Do not want.
|
|
|
|
*
|
|
|
|
* @param User $user the current user
|
|
|
|
*/
|
|
|
|
function saveStandardProfileDetails($user)
|
|
|
|
{
|
|
|
|
$fullname = $this->trimmed('extprofile-fullname');
|
|
|
|
$location = $this->trimmed('extprofile-location');
|
|
|
|
$tagstring = $this->trimmed('extprofile-tags');
|
|
|
|
$bio = $this->trimmed('extprofile-bio');
|
|
|
|
|
|
|
|
if ($tagstring) {
|
|
|
|
$tags = array_map(
|
|
|
|
'common_canonical_tag',
|
|
|
|
preg_split('/[\s,]+/', $tagstring)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$tags = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($tags as $tag) {
|
|
|
|
if (!common_valid_profile_tag($tag)) {
|
|
|
|
// TRANS: Validation error in form for profile settings.
|
|
|
|
// TRANS: %s is an invalid tag.
|
|
|
|
throw new Exception(sprintf(_m('Invalid tag: "%s".'), $tag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
|
2011-03-09 19:27:29 +00:00
|
|
|
$oldTags = $user->getSelfTags();
|
|
|
|
$newTags = array_diff($tags, $oldTags);
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
if ($fullname != $profile->fullname
|
|
|
|
|| $location != $profile->location
|
2011-03-09 19:27:29 +00:00
|
|
|
|| !empty($newTags)
|
2011-03-09 03:20:43 +00:00
|
|
|
|| $bio != $profile->bio) {
|
2011-03-10 22:14:21 +00:00
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
$orig = clone($profile);
|
|
|
|
|
|
|
|
$profile->nickname = $user->nickname;
|
|
|
|
$profile->fullname = $fullname;
|
|
|
|
$profile->bio = $bio;
|
|
|
|
$profile->location = $location;
|
|
|
|
|
|
|
|
$loc = Location::fromName($location);
|
|
|
|
|
|
|
|
if (empty($loc)) {
|
|
|
|
$profile->lat = null;
|
|
|
|
$profile->lon = null;
|
|
|
|
$profile->location_id = null;
|
|
|
|
$profile->location_ns = null;
|
|
|
|
} else {
|
|
|
|
$profile->lat = $loc->lat;
|
|
|
|
$profile->lon = $loc->lon;
|
|
|
|
$profile->location_id = $loc->location_id;
|
|
|
|
$profile->location_ns = $loc->location_ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
$profile->profileurl = common_profile_url($user->nickname);
|
|
|
|
|
|
|
|
$result = $profile->update($orig);
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
common_log_db_error($profile, 'UPDATE', __FILE__);
|
|
|
|
// TRANS: Server error thrown when user profile settings could not be saved.
|
2011-03-17 10:38:18 +00:00
|
|
|
$this->serverError(_m('Could not save profile.'));
|
2011-03-09 03:20:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the user tags
|
|
|
|
$result = $user->setSelfTags($tags);
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
// TRANS: Server error thrown when user profile settings tags could not be saved.
|
2011-03-17 10:38:18 +00:00
|
|
|
$this->serverError(_m('Could not save tags.'));
|
2011-03-09 03:20:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Event::handle('EndProfileSaveForm', array($this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 00:23:24 +00:00
|
|
|
}
|