2011-02-03 09:23:24 +09: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/>.
|
|
|
|
*/
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
if (!defined('GNUSOCIAL')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-03 09:23:24 +09:00
|
|
|
|
2011-03-11 10:13:34 +09:00
|
|
|
class ProfileDetailSettingsAction extends ProfileSettingsAction
|
2011-02-03 09:23:24 +09:00
|
|
|
{
|
2019-08-10 21:40:47 +09:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2019-08-09 23:22:55 +09:00
|
|
|
public function title()
|
2011-02-03 09:23:24 +09:00
|
|
|
{
|
2011-06-05 18:35:11 +09:00
|
|
|
// TRANS: Title for extended profile settings.
|
2019-08-10 21:40:47 +09:00
|
|
|
// TRANS: %%site.name%% is the name of the site.
|
2011-02-03 09:23:24 +09:00
|
|
|
return _m('Extended profile settings');
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function showStylesheets()
|
|
|
|
{
|
2011-02-03 09:23:24 +09:00
|
|
|
parent::showStylesheets();
|
2011-03-14 08:32:13 +09:00
|
|
|
$this->cssLink('plugins/ExtendedProfile/css/profiledetail.css');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function showScripts()
|
|
|
|
{
|
2011-03-14 08:32:13 +09:00
|
|
|
parent::showScripts();
|
|
|
|
$this->script('plugins/ExtendedProfile/js/profiledetail.js');
|
2011-02-03 09:23:24 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
protected function doPost()
|
2011-02-03 09:23:24 +09:00
|
|
|
{
|
2011-03-09 12:20:43 +09:00
|
|
|
if ($this->arg('save')) {
|
2015-07-17 19:46:09 +09:00
|
|
|
return $this->saveDetails();
|
2011-03-09 12:20:43 +09:00
|
|
|
}
|
2015-07-17 19:46:09 +09:00
|
|
|
|
|
|
|
// TRANS: Message given submitting a form with an unknown action.
|
|
|
|
throw new ClientException(_m('Unexpected form submission.'));
|
2011-02-03 09:23:24 +09:00
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function showContent()
|
2011-02-03 09:23:24 +09:00
|
|
|
{
|
2011-03-10 12:27:21 +09:00
|
|
|
$widget = new ExtendedProfileWidget(
|
|
|
|
$this,
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->scoped,
|
2011-03-10 12:27:21 +09:00
|
|
|
ExtendedProfileWidget::EDITABLE
|
|
|
|
);
|
2011-02-03 09:23:24 +09:00
|
|
|
$widget->show();
|
|
|
|
}
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveDetails()
|
2011-03-09 12:20:43 +09:00
|
|
|
{
|
|
|
|
common_debug(var_export($_POST, true));
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->saveStandardProfileDetails();
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$simpleFieldNames = array('title', 'spouse', 'kids', 'manager');
|
2019-08-09 23:22:55 +09:00
|
|
|
$dateFieldNames = array('birthday');
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
foreach ($simpleFieldNames as $name) {
|
|
|
|
$value = $this->trimmed('extprofile-' . $name);
|
|
|
|
if (!empty($value)) {
|
|
|
|
$this->saveField($name, $value);
|
2011-03-14 17:49:46 +09:00
|
|
|
}
|
2015-07-17 19:46:09 +09:00
|
|
|
}
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
foreach ($dateFieldNames as $name) {
|
|
|
|
$value = $this->trimmed('extprofile-' . $name);
|
|
|
|
$dateVal = $this->parseDate($name, $value);
|
|
|
|
$this->saveField(
|
|
|
|
$name,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$dateVal
|
|
|
|
);
|
2011-03-15 09:27:50 +09:00
|
|
|
}
|
2011-03-11 07:14:21 +09:00
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->savePhoneNumbers();
|
|
|
|
$this->saveIms();
|
|
|
|
$this->saveWebsites();
|
|
|
|
$this->saveExperiences();
|
|
|
|
$this->saveEducations();
|
2019-08-09 23:22:55 +09:00
|
|
|
$this->saveCustomFields($this);
|
2015-07-17 19:46:09 +09:00
|
|
|
|
2011-06-05 18:35:11 +09:00
|
|
|
// TRANS: Success message after saving extended profile details.
|
2015-07-17 19:46:09 +09:00
|
|
|
return _m('Details saved.');
|
2011-03-09 12:20:43 +09:00
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function parseDate($fieldname, $datestr, $required = false)
|
2011-03-16 07:35:00 +09:00
|
|
|
{
|
2011-03-17 08:08:49 +09:00
|
|
|
if (empty($datestr)) {
|
|
|
|
if ($required) {
|
|
|
|
$msg = sprintf(
|
2019-08-09 23:22:55 +09:00
|
|
|
// TRANS: Exception thrown when no date was entered in a required date field.
|
|
|
|
// TRANS: %s is the field name.
|
2011-03-17 08:08:49 +09:00
|
|
|
_m('You must supply a date for "%s".'),
|
|
|
|
$fieldname
|
|
|
|
);
|
|
|
|
throw new Exception($msg);
|
|
|
|
}
|
2011-03-16 07:35:00 +09:00
|
|
|
} else {
|
|
|
|
$ts = strtotime($datestr);
|
|
|
|
if ($ts === false) {
|
|
|
|
throw new Exception(
|
|
|
|
sprintf(
|
2019-08-09 23:22:55 +09:00
|
|
|
// TRANS: Exception thrown on incorrect data input.
|
|
|
|
// TRANS: %1$s is a field name, %2$s is the incorrect input.
|
2011-03-17 19:38:18 +09:00
|
|
|
_m('Invalid date entered for "%1$s": %2$s.'),
|
2011-03-16 07:35:00 +09:00
|
|
|
$fieldname,
|
|
|
|
$ts
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return common_sql_date($ts);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function savePhoneNumbers()
|
|
|
|
{
|
2011-03-11 07:14:21 +09:00
|
|
|
$phones = $this->findPhoneNumbers();
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->removeAll('phone');
|
2011-03-14 17:49:46 +09:00
|
|
|
$i = 0;
|
2019-08-09 23:22:55 +09:00
|
|
|
foreach ($phones as $phone) {
|
2011-03-14 17:49:46 +09:00
|
|
|
if (!empty($phone['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
'phone',
|
|
|
|
$phone['value'],
|
|
|
|
$phone['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
2011-03-11 07:14:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findPhoneNumbers()
|
|
|
|
{
|
2011-03-15 09:53:54 +09:00
|
|
|
|
2011-03-15 12:58:35 +09:00
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-phone-1' => '11332',
|
|
|
|
// 'extprofile-phone-1-rel' => 'mobile',
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
$phones = $this->sliceParams('phone', 2);
|
2011-03-15 12:58:35 +09:00
|
|
|
$phoneArray = array();
|
2011-03-11 07:14:21 +09:00
|
|
|
|
2011-03-15 07:29:11 +09:00
|
|
|
foreach ($phones as $phone) {
|
2011-03-11 07:14:21 +09:00
|
|
|
list($number, $rel) = array_values($phone);
|
2011-03-15 12:58:35 +09:00
|
|
|
$phoneArray[] = array(
|
2011-03-11 07:14:21 +09:00
|
|
|
'value' => $number,
|
2019-08-09 23:22:55 +09:00
|
|
|
'rel' => $rel
|
2011-03-11 07:14:21 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-15 12:58:35 +09:00
|
|
|
return $phoneArray;
|
2011-03-15 09:53:54 +09:00
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findIms()
|
|
|
|
{
|
2011-03-15 14:38:34 +09:00
|
|
|
|
|
|
|
// Form vals look like this:
|
|
|
|
// 'extprofile-im-0' => 'jed',
|
|
|
|
// 'extprofile-im-0-rel' => 'yahoo',
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
$ims = $this->sliceParams('im', 2);
|
2011-03-15 14:38:34 +09:00
|
|
|
$imArray = array();
|
|
|
|
|
|
|
|
foreach ($ims as $im) {
|
|
|
|
list($id, $rel) = array_values($im);
|
|
|
|
$imArray[] = array(
|
|
|
|
'value' => $id,
|
2019-08-09 23:22:55 +09:00
|
|
|
'rel' => $rel
|
2011-03-15 14:38:34 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $imArray;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveIms()
|
|
|
|
{
|
2011-03-15 14:38:34 +09:00
|
|
|
$ims = $this->findIms();
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->removeAll('im');
|
2011-03-15 14:38:34 +09:00
|
|
|
$i = 0;
|
2019-08-09 23:22:55 +09:00
|
|
|
foreach ($ims as $im) {
|
2011-03-15 14:38:34 +09:00
|
|
|
if (!empty($im['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
'im',
|
|
|
|
$im['value'],
|
|
|
|
$im['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findWebsites()
|
|
|
|
{
|
2011-03-16 02:10:18 +09:00
|
|
|
|
|
|
|
// 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,
|
2019-08-09 23:22:55 +09:00
|
|
|
'rel' => $rel
|
2011-03-16 02:10:18 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $wsArray;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveWebsites()
|
|
|
|
{
|
2011-03-16 02:10:18 +09:00
|
|
|
$sites = $this->findWebsites();
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->removeAll('website');
|
2011-03-16 02:10:18 +09:00
|
|
|
$i = 0;
|
2019-08-09 23:22:55 +09:00
|
|
|
foreach ($sites as $site) {
|
2013-10-07 21:46:09 +09:00
|
|
|
if (!empty($site['value']) && !common_valid_http_url($site['value'])) {
|
2011-03-17 19:38:18 +09: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 18:41:32 +09:00
|
|
|
}
|
|
|
|
|
2011-03-16 02:10:18 +09:00
|
|
|
if (!empty($site['value'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
'website',
|
|
|
|
$site['value'],
|
|
|
|
$site['rel'],
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findExperiences()
|
|
|
|
{
|
2011-03-15 07:29:11 +09:00
|
|
|
|
|
|
|
// 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 09:53:54 +09:00
|
|
|
$experiences = $this->sliceParams('experience', 4);
|
2011-03-15 07:29:11 +09:00
|
|
|
$expArray = array();
|
|
|
|
|
|
|
|
foreach ($experiences as $exp) {
|
2011-03-16 18:41:32 +09: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 14:02:24 +09:00
|
|
|
if (!empty($company)) {
|
|
|
|
$expArray[] = array(
|
|
|
|
'company' => $company,
|
2019-08-09 23:22:55 +09:00
|
|
|
'start' => $this->parseDate('Start', $start, true),
|
|
|
|
'end' => ($current == 'false') ? $this->parseDate('End', $end, true) : null,
|
2011-03-15 14:02:24 +09:00
|
|
|
'current' => ($current == 'false') ? false : true
|
|
|
|
);
|
|
|
|
}
|
2011-03-15 07:29:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $expArray;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveExperiences()
|
|
|
|
{
|
2011-03-15 07:29:11 +09:00
|
|
|
common_debug('save experiences');
|
|
|
|
$experiences = $this->findExperiences();
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->removeAll('company');
|
|
|
|
$this->removeAll('start');
|
|
|
|
$this->removeAll('end'); // also stores 'current'
|
2011-03-15 07:29:11 +09:00
|
|
|
|
|
|
|
$i = 0;
|
2019-08-09 23:22:55 +09:00
|
|
|
foreach ($experiences as $experience) {
|
2011-03-15 07:29:11 +09:00
|
|
|
if (!empty($experience['company'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
'company',
|
|
|
|
$experience['company'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
2011-03-15 09:27:50 +09:00
|
|
|
|
2011-03-15 07:29:11 +09:00
|
|
|
$this->saveField(
|
|
|
|
'start',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$experience['start']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Save "current" employer indicator in rel
|
|
|
|
if ($experience['current']) {
|
|
|
|
$this->saveField(
|
|
|
|
'end',
|
|
|
|
null,
|
|
|
|
'current', // rel
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->saveField(
|
|
|
|
'end',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$experience['end']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findEducations()
|
|
|
|
{
|
2011-03-15 14:02:24 +09:00
|
|
|
|
|
|
|
// 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(
|
2019-08-09 23:22:55 +09:00
|
|
|
'school' => $school,
|
|
|
|
'degree' => $degree,
|
2011-03-15 14:02:24 +09:00
|
|
|
'description' => $description,
|
2019-08-09 23:22:55 +09:00
|
|
|
'start' => $this->parseDate('Start', $start, true),
|
|
|
|
'end' => $this->parseDate('End', $end, true)
|
2011-03-15 14:02:24 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $eduArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveEducations()
|
|
|
|
{
|
|
|
|
common_debug('save education');
|
|
|
|
$edus = $this->findEducations();
|
|
|
|
common_debug(var_export($edus, true));
|
|
|
|
|
|
|
|
$this->removeAll('school');
|
|
|
|
$this->removeAll('degree');
|
|
|
|
$this->removeAll('degree_descr');
|
|
|
|
$this->removeAll('school_start');
|
|
|
|
$this->removeAll('school_end');
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach ($edus as $edu) {
|
|
|
|
if (!empty($edu['school'])) {
|
|
|
|
++$i;
|
|
|
|
$this->saveField(
|
|
|
|
'school',
|
|
|
|
$edu['school'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
'degree',
|
|
|
|
$edu['degree'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
'degree_descr',
|
|
|
|
$edu['description'],
|
|
|
|
null,
|
|
|
|
$i
|
|
|
|
);
|
|
|
|
$this->saveField(
|
|
|
|
'school_start',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$edu['start']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->saveField(
|
|
|
|
'school_end',
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$i,
|
|
|
|
$edu['end']
|
|
|
|
);
|
2011-03-15 14:02:24 +09:00
|
|
|
}
|
2019-08-09 23:22:55 +09:00
|
|
|
}
|
|
|
|
}
|
2011-03-15 14:02:24 +09:00
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function arraySplit($array, $pieces)
|
2011-03-10 04:27:29 +09:00
|
|
|
{
|
2011-03-11 07:14:21 +09:00
|
|
|
if ($pieces < 2) {
|
|
|
|
return array($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
$newCount = ceil(count($array) / $pieces);
|
|
|
|
$a = array_slice($array, 0, $newCount);
|
2011-03-14 08:32:13 +09:00
|
|
|
$b = $this->arraySplit(array_slice($array, $newCount), $pieces - 1);
|
2011-03-10 04:27:29 +09:00
|
|
|
|
2011-03-11 07:14:21 +09:00
|
|
|
return array_merge(array($a), $b);
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function findMultiParams($type)
|
|
|
|
{
|
2011-03-11 07:14:21 +09:00
|
|
|
$formVals = array();
|
2019-08-09 23:22:55 +09:00
|
|
|
$target = $type;
|
2011-03-11 07:14:21 +09:00
|
|
|
foreach ($_POST as $key => $val) {
|
|
|
|
if (strrpos('extprofile-' . $key, $target) !== false) {
|
|
|
|
$formVals[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $formVals;
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function sliceParams($key, $size)
|
|
|
|
{
|
2011-03-15 12:58:35 +09:00
|
|
|
$slice = array();
|
|
|
|
$params = $this->findMultiParams($key);
|
|
|
|
ksort($params);
|
|
|
|
$slice = $this->arraySplit($params, sizeof($params) / $size);
|
|
|
|
return $slice;
|
|
|
|
}
|
|
|
|
|
2011-03-11 07:14:21 +09:00
|
|
|
/**
|
|
|
|
* Save an extended profile field as a Profile_detail
|
|
|
|
*
|
2019-08-09 23:22:55 +09:00
|
|
|
* @param string $name field name
|
|
|
|
* @param string $value field value
|
|
|
|
* @param string|null $rel field rel (type)
|
|
|
|
* @param int|null $index index (fields can have multiple values)
|
|
|
|
* @param string|null $date date related date
|
|
|
|
* @throws ServerException
|
2011-03-11 07:14:21 +09:00
|
|
|
*/
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveField(string $name, ?string $value, ?string $rel = null, ?int $index = null, ?string $date = null)
|
2011-03-11 07:14:21 +09:00
|
|
|
{
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail = new Profile_detail();
|
2011-03-10 04:27:29 +09:00
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail->profile_id = $this->scoped->getID();
|
|
|
|
$detail->field_name = $name;
|
2011-03-11 07:14:21 +09:00
|
|
|
$detail->value_index = $index;
|
2011-03-10 04:27:29 +09:00
|
|
|
|
|
|
|
$result = $detail->find(true);
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
if (!$result instanceof Profile_detail) {
|
|
|
|
$detail->value_index = $index;
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail->rel = $rel;
|
2011-03-10 11:00:24 +09:00
|
|
|
$detail->field_value = $value;
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail->date = $date;
|
|
|
|
$detail->created = common_sql_now();
|
2011-03-10 04:27:29 +09:00
|
|
|
$result = $detail->insert();
|
2015-07-17 19:46:09 +09:00
|
|
|
if ($result === false) {
|
2011-03-10 11:00:24 +09:00
|
|
|
common_log_db_error($detail, 'INSERT', __FILE__);
|
2011-06-05 18:35:11 +09:00
|
|
|
// TRANS: Server error displayed when a field could not be saved in the database.
|
2015-07-17 19:46:09 +09:00
|
|
|
throw new ServerException(_m('Could not save profile details.'));
|
2011-03-10 11:00:24 +09:00
|
|
|
}
|
2011-03-10 04:27:29 +09:00
|
|
|
} else {
|
|
|
|
$orig = clone($detail);
|
2011-03-11 07:14:21 +09:00
|
|
|
|
2011-03-10 11:00:24 +09:00
|
|
|
$detail->field_value = $value;
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail->rel = $rel;
|
|
|
|
$detail->date = $date;
|
2011-03-10 11:00:24 +09:00
|
|
|
|
2011-03-11 07:14:21 +09:00
|
|
|
$result = $detail->update($orig);
|
2015-07-17 19:46:09 +09:00
|
|
|
if ($result === false) {
|
2011-03-11 07:14:21 +09:00
|
|
|
common_log_db_error($detail, 'UPDATE', __FILE__);
|
2011-06-05 18:35:11 +09:00
|
|
|
// TRANS: Server error displayed when a field could not be saved in the database.
|
2015-07-17 19:46:09 +09:00
|
|
|
throw new ServerException(_m('Could not save profile details.'));
|
2011-03-11 07:14:21 +09:00
|
|
|
}
|
2011-03-10 04:27:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$detail->free();
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
public function removeAll($name)
|
2011-03-14 17:49:46 +09:00
|
|
|
{
|
2019-08-09 23:22:55 +09:00
|
|
|
$detail = new Profile_detail();
|
|
|
|
$detail->profile_id = $this->scoped->getID();
|
|
|
|
$detail->field_name = $name;
|
2011-03-14 17:49:46 +09:00
|
|
|
$detail->delete();
|
|
|
|
$detail->free();
|
|
|
|
}
|
|
|
|
|
2011-03-09 12:20:43 +09: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.
|
|
|
|
*/
|
2019-08-09 23:22:55 +09:00
|
|
|
public function saveStandardProfileDetails()
|
2011-03-09 12:20:43 +09:00
|
|
|
{
|
2019-08-09 23:22:55 +09:00
|
|
|
$fullname = $this->trimmed('extprofile-fullname');
|
|
|
|
$location = $this->trimmed('extprofile-location');
|
2011-03-09 12:20:43 +09:00
|
|
|
$tagstring = $this->trimmed('extprofile-tags');
|
2019-08-09 23:22:55 +09:00
|
|
|
$bio = $this->trimmed('extprofile-bio');
|
2011-03-09 12:20:43 +09:00
|
|
|
|
|
|
|
if ($tagstring) {
|
|
|
|
$tags = array_map(
|
|
|
|
'common_canonical_tag',
|
|
|
|
preg_split('/[\s,]+/', $tagstring)
|
|
|
|
);
|
|
|
|
} else {
|
2019-08-09 23:22:55 +09:00
|
|
|
$tags = [];
|
2011-03-09 12:20:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$oldTags = Profile_tag::getSelfTagsArray($this->scoped);
|
2011-03-10 04:27:29 +09:00
|
|
|
$newTags = array_diff($tags, $oldTags);
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
if ($fullname != $this->scoped->getFullname()
|
2015-07-17 19:46:09 +09:00
|
|
|
|| $location != $this->scoped->location
|
2011-03-10 04:27:29 +09:00
|
|
|
|| !empty($newTags)
|
2019-08-09 23:22:55 +09:00
|
|
|
|| $bio != $this->scoped->getDescription()) {
|
2015-07-17 19:46:09 +09:00
|
|
|
$orig = clone($this->scoped);
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
// Skipping nickname change here until we add logic for when the site allows it or not
|
|
|
|
// old Profilesettings will still let us do that.
|
|
|
|
|
|
|
|
$this->scoped->fullname = $fullname;
|
2019-08-09 23:22:55 +09:00
|
|
|
$this->scoped->bio = $bio;
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->scoped->location = $location;
|
2011-03-09 12:20:43 +09:00
|
|
|
|
|
|
|
$loc = Location::fromName($location);
|
|
|
|
|
|
|
|
if (empty($loc)) {
|
2019-08-09 23:22:55 +09:00
|
|
|
$this->scoped->lat = null;
|
|
|
|
$this->scoped->lon = null;
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->scoped->location_id = null;
|
|
|
|
$this->scoped->location_ns = null;
|
2011-03-09 12:20:43 +09:00
|
|
|
} else {
|
2019-08-09 23:22:55 +09:00
|
|
|
$this->scoped->lat = $loc->lat;
|
|
|
|
$this->scoped->lon = $loc->lon;
|
2015-07-17 19:46:09 +09:00
|
|
|
$this->scoped->location_id = $loc->location_id;
|
|
|
|
$this->scoped->location_ns = $loc->location_ns;
|
2011-03-09 12:20:43 +09:00
|
|
|
}
|
|
|
|
|
2015-07-17 19:46:09 +09:00
|
|
|
$result = $this->scoped->update($orig);
|
2011-03-09 12:20:43 +09:00
|
|
|
|
|
|
|
if ($result === false) {
|
2015-07-17 19:46:09 +09:00
|
|
|
common_log_db_error($this->scoped, 'UPDATE', __FILE__);
|
2011-03-09 12:20:43 +09:00
|
|
|
// TRANS: Server error thrown when user profile settings could not be saved.
|
2015-07-17 19:46:09 +09:00
|
|
|
throw new ServerException(_m('Could not save profile.'));
|
2011-03-09 12:20:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the user tags
|
2015-07-17 19:46:09 +09:00
|
|
|
$result = Profile_tag::setSelfTags($this->scoped, $tags);
|
2011-03-09 12:20:43 +09:00
|
|
|
|
|
|
|
Event::handle('EndProfileSaveForm', array($this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 23:22:55 +09:00
|
|
|
private function saveCustomFields($action)
|
|
|
|
{
|
|
|
|
$fields = GNUsocialProfileExtensionField::allFields();
|
|
|
|
$user = common_current_user();
|
|
|
|
$profile = $user->getProfile();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$val = $action->trimmed('extprofile-'.$field->systemname);
|
|
|
|
|
|
|
|
if (empty($val)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = new GNUsocialProfileExtensionResponse();
|
|
|
|
$response->profile_id = $profile->id;
|
|
|
|
$response->extension_id = $field->id;
|
|
|
|
|
|
|
|
if ($response->find()) {
|
|
|
|
$response->fetch();
|
|
|
|
$response->value = $val;
|
|
|
|
if ($response->validate()) {
|
|
|
|
if (empty($val)) {
|
|
|
|
$response->delete();
|
|
|
|
} else {
|
|
|
|
$response->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$response->value = $val;
|
|
|
|
$response->insert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 09:23:24 +09:00
|
|
|
}
|