[Plugins] Incorporated GNUsocialExtendedProfile as part of ExtendedProfile
Also improved a lot of the plugin and made things in a way it would make sense
This commit is contained in:
@@ -32,12 +32,13 @@ class ExtendedProfile
|
||||
* Constructor
|
||||
*
|
||||
* @param Profile $profile
|
||||
* @throws NoSuchUserException
|
||||
*/
|
||||
function __construct(Profile $profile)
|
||||
public function __construct(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->user = $profile->getUser();
|
||||
$this->fields = $this->loadFields();
|
||||
$this->profile = $profile;
|
||||
$this->user = $profile->getUser();
|
||||
$this->fields = $this->loadFields();
|
||||
$this->sections = $this->getSections();
|
||||
//common_debug(var_export($this->sections, true));
|
||||
|
||||
@@ -48,8 +49,9 @@ class ExtendedProfile
|
||||
* Load extended profile fields
|
||||
*
|
||||
* @return array $fields the list of fields
|
||||
* @throws Exception
|
||||
*/
|
||||
function loadFields()
|
||||
public function loadFields()
|
||||
{
|
||||
$detail = new Profile_detail();
|
||||
$detail->profile_id = $this->profile->getID();
|
||||
@@ -69,7 +71,7 @@ class ExtendedProfile
|
||||
*
|
||||
* @return string the concatenated string of tags
|
||||
*/
|
||||
function getTags()
|
||||
public function getTags()
|
||||
{
|
||||
return implode(' ', Profile_tag::getSelfTagsArray($this->profile));
|
||||
}
|
||||
@@ -84,21 +86,22 @@ class ExtendedProfile
|
||||
*
|
||||
* @return string the value
|
||||
*/
|
||||
function getTextValue($name)
|
||||
public function getTextValue($name)
|
||||
{
|
||||
$key = strtolower($name);
|
||||
$key = strtolower($name);
|
||||
$profileFields = array('fullname', 'location', 'bio');
|
||||
|
||||
if (in_array($key, $profileFields)) {
|
||||
return $this->profile->$name;
|
||||
} else if (array_key_exists($key, $this->fields)) {
|
||||
} elseif (array_key_exists($key, $this->fields)) {
|
||||
return $this->fields[$key][0]->field_value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getDateValue($name) {
|
||||
public function getDateValue($name)
|
||||
{
|
||||
$key = strtolower($name);
|
||||
if (array_key_exists($key, $this->fields)) {
|
||||
return $this->fields[$key][0]->date;
|
||||
@@ -109,7 +112,7 @@ class ExtendedProfile
|
||||
|
||||
// XXX: getPhones, getIms, and getWebsites pretty much do the same thing,
|
||||
// so refactor.
|
||||
function getPhones()
|
||||
public function getPhones()
|
||||
{
|
||||
$phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
|
||||
$pArrays = array();
|
||||
@@ -119,9 +122,9 @@ class ExtendedProfile
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Phone'),
|
||||
'index' => 0,
|
||||
'type' => 'phone',
|
||||
'type' => 'phone',
|
||||
'vcard' => 'tel',
|
||||
'rel' => 'office',
|
||||
'rel' => 'office',
|
||||
'value' => null
|
||||
);
|
||||
} else {
|
||||
@@ -129,20 +132,20 @@ class ExtendedProfile
|
||||
$pa = array(
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Phone'),
|
||||
'type' => 'phone',
|
||||
'type' => 'phone',
|
||||
'index' => intval($phones[$i]->value_index),
|
||||
'rel' => $phones[$i]->rel,
|
||||
'rel' => $phones[$i]->rel,
|
||||
'value' => $phones[$i]->field_value,
|
||||
'vcard' => 'tel'
|
||||
);
|
||||
|
||||
$pArrays[] = $pa;
|
||||
$pArrays[] = $pa;
|
||||
}
|
||||
}
|
||||
return $pArrays;
|
||||
}
|
||||
|
||||
function getIms()
|
||||
public function getIms()
|
||||
{
|
||||
$ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
|
||||
$iArrays = array();
|
||||
@@ -158,9 +161,9 @@ class ExtendedProfile
|
||||
$ia = array(
|
||||
// TRANS: Field label for extended profile properties (Instant Messaging).
|
||||
'label' => _m('IM'),
|
||||
'type' => 'im',
|
||||
'type' => 'im',
|
||||
'index' => intval($ims[$i]->value_index),
|
||||
'rel' => $ims[$i]->rel,
|
||||
'rel' => $ims[$i]->rel,
|
||||
'value' => $ims[$i]->field_value,
|
||||
);
|
||||
|
||||
@@ -170,7 +173,7 @@ class ExtendedProfile
|
||||
return $iArrays;
|
||||
}
|
||||
|
||||
function getWebsites()
|
||||
public function getWebsites()
|
||||
{
|
||||
$sites = (isset($this->fields['website'])) ? $this->fields['website'] : null;
|
||||
$wArrays = array();
|
||||
@@ -186,9 +189,9 @@ class ExtendedProfile
|
||||
$wa = array(
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Website'),
|
||||
'type' => 'website',
|
||||
'type' => 'website',
|
||||
'index' => intval($sites[$i]->value_index),
|
||||
'rel' => $sites[$i]->rel,
|
||||
'rel' => $sites[$i]->rel,
|
||||
'value' => $sites[$i]->field_value,
|
||||
);
|
||||
|
||||
@@ -198,44 +201,44 @@ class ExtendedProfile
|
||||
return $wArrays;
|
||||
}
|
||||
|
||||
function getExperiences()
|
||||
public function getExperiences()
|
||||
{
|
||||
$companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
|
||||
$start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
|
||||
$end = (isset($this->fields['end'])) ? $this->fields['end'] : null;
|
||||
$end = (isset($this->fields['end'])) ? $this->fields['end'] : null;
|
||||
|
||||
$eArrays = array();
|
||||
|
||||
if (empty($companies)) {
|
||||
$eArrays[] = array(
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Employer'),
|
||||
'type' => 'experience',
|
||||
'label' => _m('Employer'),
|
||||
'type' => 'experience',
|
||||
'company' => null,
|
||||
'start' => null,
|
||||
'end' => null,
|
||||
'start' => null,
|
||||
'end' => null,
|
||||
'current' => false,
|
||||
'index' => 0
|
||||
'index' => 0
|
||||
);
|
||||
} else {
|
||||
for ($i = 0; $i < sizeof($companies); $i++) {
|
||||
$ea = array(
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Employer'),
|
||||
'type' => 'experience',
|
||||
'label' => _m('Employer'),
|
||||
'type' => 'experience',
|
||||
'company' => $companies[$i]->field_value,
|
||||
'index' => intval($companies[$i]->value_index),
|
||||
'index' => intval($companies[$i]->value_index),
|
||||
'current' => $end[$i]->rel,
|
||||
'start' => $start[$i]->date,
|
||||
'end' => $end[$i]->date
|
||||
'start' => $start[$i]->date,
|
||||
'end' => $end[$i]->date
|
||||
);
|
||||
$eArrays[] = $ea;
|
||||
$eArrays[] = $ea;
|
||||
}
|
||||
}
|
||||
return $eArrays;
|
||||
}
|
||||
|
||||
function getEducation()
|
||||
public function getEducation()
|
||||
{
|
||||
$schools = (isset($this->fields['school'])) ? $this->fields['school'] : null;
|
||||
$degrees = (isset($this->fields['degree'])) ? $this->fields['degree'] : null;
|
||||
@@ -259,17 +262,17 @@ class ExtendedProfile
|
||||
} else {
|
||||
for ($i = 0; $i < sizeof($schools); $i++) {
|
||||
$ia = array(
|
||||
'type' => 'education',
|
||||
'type' => 'education',
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Institution'),
|
||||
'school' => $schools[$i]->field_value,
|
||||
'degree' => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null,
|
||||
'label' => _m('Institution'),
|
||||
'school' => $schools[$i]->field_value,
|
||||
'degree' => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null,
|
||||
'description' => isset($descs[$i]->field_value) ? $descs[$i]->field_value : null,
|
||||
'index' => intval($schools[$i]->value_index),
|
||||
'start' => $start[$i]->date,
|
||||
'end' => $end[$i]->date
|
||||
'index' => intval($schools[$i]->value_index),
|
||||
'start' => $start[$i]->date,
|
||||
'end' => $end[$i]->date
|
||||
);
|
||||
$iArrays[] = $ia;
|
||||
$iArrays[] = $ia;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,9 +283,27 @@ class ExtendedProfile
|
||||
* Return all the sections of the extended profile
|
||||
*
|
||||
* @return array the big list of sections and fields
|
||||
* @throws Exception
|
||||
*/
|
||||
function getSections()
|
||||
public function getSections()
|
||||
{
|
||||
$gsefields = GNUsocialProfileExtensionField::allFields();
|
||||
$extra_fields = [];
|
||||
gnusocial_profile_merge($this->profile);
|
||||
foreach ($gsefields as $field) {
|
||||
$field_key = $field->systemname;
|
||||
switch ($field->type) {
|
||||
case 'text':
|
||||
$extra_fields[$field_key]['type'] = 'custom-textarea';
|
||||
break;
|
||||
case 'str':
|
||||
default:
|
||||
$extra_fields[$field_key]['type'] = 'custom-text';
|
||||
break;
|
||||
}
|
||||
$extra_fields[$field_key]['label'] = $field->title;
|
||||
$extra_fields[$field_key]['value'] = $this->profile->$field_key;
|
||||
}
|
||||
return array(
|
||||
'basic' => array(
|
||||
// TRANS: Field label for extended profile properties.
|
||||
@@ -328,8 +349,8 @@ class ExtendedProfile
|
||||
// TRANS: Field label for extended profile properties.
|
||||
'label' => _m('Contact'),
|
||||
'fields' => array(
|
||||
'phone' => $this->getPhones(),
|
||||
'im' => $this->getIms(),
|
||||
'phone' => $this->getPhones(),
|
||||
'im' => $this->getIms(),
|
||||
'website' => $this->getWebsites()
|
||||
),
|
||||
),
|
||||
@@ -368,6 +389,10 @@ class ExtendedProfile
|
||||
'education' => $this->getEducation()
|
||||
),
|
||||
),
|
||||
'extra' => [
|
||||
'label' => _m('Extra fields'),
|
||||
'fields' => $extra_fields,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -39,18 +39,19 @@ class ExtendedProfileWidget extends Form
|
||||
/**
|
||||
* The extended profile
|
||||
*
|
||||
* @var Extended_profile
|
||||
* @var ExtendedProfile
|
||||
*/
|
||||
protected $ext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param XMLOutputter $out
|
||||
* @param Profile $profile
|
||||
* @param boolean $editable
|
||||
* @param Action $out
|
||||
* @param Profile $profile
|
||||
* @param boolean $editable
|
||||
* @throws NoSuchUserException
|
||||
*/
|
||||
public function __construct(XMLOutputter $out=null, Profile $profile=null, $editable=false)
|
||||
public function __construct(Action $out = null, Profile $profile = null, $editable = false)
|
||||
{
|
||||
parent::__construct($out);
|
||||
|
||||
@@ -103,8 +104,9 @@ class ExtendedProfileWidget extends Form
|
||||
/**
|
||||
* Show an extended profile section
|
||||
*
|
||||
* @param string $name name of the section
|
||||
* @param array $section array of fields for the section
|
||||
* @param string $name name of the section
|
||||
* @param array $section array of fields for the section
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function showExtendedProfileSection($name, $section)
|
||||
{
|
||||
@@ -112,17 +114,16 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->elementStart('table', array('class' => 'extended-profile'));
|
||||
|
||||
foreach ($section['fields'] as $fieldName => $field) {
|
||||
|
||||
switch($fieldName) {
|
||||
case 'phone':
|
||||
case 'im':
|
||||
case 'website':
|
||||
case 'experience':
|
||||
case 'education':
|
||||
$this->showMultiple($fieldName, $field);
|
||||
break;
|
||||
default:
|
||||
$this->showExtendedProfileField($fieldName, $field);
|
||||
switch ($fieldName) {
|
||||
case 'phone':
|
||||
case 'im':
|
||||
case 'website':
|
||||
case 'experience':
|
||||
case 'education':
|
||||
$this->showMultiple($fieldName, $field);
|
||||
break;
|
||||
default:
|
||||
$this->showExtendedProfileField($fieldName, $field);
|
||||
}
|
||||
}
|
||||
$this->out->elementEnd('table');
|
||||
@@ -131,14 +132,15 @@ class ExtendedProfileWidget extends Form
|
||||
/**
|
||||
* Show an extended profile field
|
||||
*
|
||||
* @param string $name name of the field
|
||||
* @param array $field set of key/value pairs for the field
|
||||
* @param string $name name of the field
|
||||
* @param array $field set of key/value pairs for the field
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function showExtendedProfileField($name, $field)
|
||||
{
|
||||
$this->out->elementStart('tr');
|
||||
|
||||
$this->out->element('th', str_replace(' ','_',strtolower($field['label'])), $field['label']);
|
||||
$this->out->element('th', str_replace(' ', '_', strtolower($field['label'])), $field['label']);
|
||||
|
||||
$this->out->elementStart('td');
|
||||
if ($this->editable) {
|
||||
@@ -151,7 +153,8 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->elementEnd('tr');
|
||||
}
|
||||
|
||||
protected function showMultiple($name, $fields) {
|
||||
protected function showMultiple($name, $fields)
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
$this->showExtendedProfileField($name, $field);
|
||||
}
|
||||
@@ -165,9 +168,9 @@ class ExtendedProfileWidget extends Form
|
||||
if (!empty($field['value'])) {
|
||||
$this->out->text($field['value']);
|
||||
if (!empty($field['rel'])) {
|
||||
// TRANS: Value between parentheses (phone number, website, or IM address).
|
||||
$outtext = sprintf(_m('(%s)'),$field['rel']);
|
||||
$this->out->text(' '.$outtext);
|
||||
// TRANS: Value between parentheses (phone number, website, or IM address).
|
||||
$outtext = sprintf(_m('(%s)'), $field['rel']);
|
||||
$this->out->text(' ' . $outtext);
|
||||
}
|
||||
}
|
||||
$this->out->elementEnd('div');
|
||||
@@ -179,8 +182,8 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->text($field['value']);
|
||||
if (!empty($field['rel'])) {
|
||||
// TRANS: Value between parentheses (phone number, website, or IM address).
|
||||
$outtext = sprintf(_m('(%s)'),$field['rel']);
|
||||
$this->out->text(' '.$outtext);
|
||||
$outtext = sprintf(_m('(%s)'), $field['rel']);
|
||||
$this->out->text(' ' . $outtext);
|
||||
}
|
||||
$this->out->elementEnd('div');
|
||||
}
|
||||
@@ -194,8 +197,8 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->element(
|
||||
"a",
|
||||
array(
|
||||
'href' => $url,
|
||||
'class' => 'extended-profile-link',
|
||||
'href' => $url,
|
||||
'class' => 'extended-profile-link',
|
||||
'target' => "_blank"
|
||||
),
|
||||
$url
|
||||
@@ -203,8 +206,8 @@ class ExtendedProfileWidget extends Form
|
||||
|
||||
if (!empty($field['rel'])) {
|
||||
// TRANS: Value between parentheses (phone number, website, or IM address).
|
||||
$outtext = sprintf(_m('(%s)'),$field['rel']);
|
||||
$this->out->text(' '.$outtext);
|
||||
$outtext = sprintf(_m('(%s)'), $field['rel']);
|
||||
$this->out->text(' ' . $outtext);
|
||||
}
|
||||
$this->out->elementEnd('div');
|
||||
}
|
||||
@@ -212,10 +215,11 @@ class ExtendedProfileWidget extends Form
|
||||
protected function showEditableIm($name, $field)
|
||||
{
|
||||
$index = isset($field['index']) ? $field['index'] : 0;
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$this->out->elementStart(
|
||||
'div', array(
|
||||
'div',
|
||||
array(
|
||||
'id' => $id . '-edit',
|
||||
'class' => 'im-item'
|
||||
)
|
||||
@@ -230,12 +234,12 @@ class ExtendedProfileWidget extends Form
|
||||
'Type',
|
||||
array(
|
||||
'jabber' => 'Jabber',
|
||||
'gtalk' => 'GTalk',
|
||||
'aim' => 'AIM',
|
||||
'yahoo' => 'Yahoo! Messenger',
|
||||
'msn' => 'MSN',
|
||||
'skype' => 'Skype',
|
||||
'other' => 'Other'
|
||||
'gtalk' => 'GTalk',
|
||||
'aim' => 'AIM',
|
||||
'yahoo' => 'Yahoo! Messenger',
|
||||
'msn' => 'MSN',
|
||||
'skype' => 'Skype',
|
||||
'other' => 'Other'
|
||||
),
|
||||
null,
|
||||
false,
|
||||
@@ -249,10 +253,11 @@ class ExtendedProfileWidget extends Form
|
||||
protected function showEditablePhone($name, $field)
|
||||
{
|
||||
$index = isset($field['index']) ? $field['index'] : 0;
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$this->out->elementStart(
|
||||
'div', array(
|
||||
'div',
|
||||
array(
|
||||
'id' => $id . '-edit',
|
||||
'class' => 'phone-item'
|
||||
)
|
||||
@@ -268,9 +273,9 @@ class ExtendedProfileWidget extends Form
|
||||
array(
|
||||
'office' => 'Office',
|
||||
'mobile' => 'Mobile',
|
||||
'home' => 'Home',
|
||||
'pager' => 'Pager',
|
||||
'other' => 'Other'
|
||||
'home' => 'Home',
|
||||
'pager' => 'Pager',
|
||||
'other' => 'Other'
|
||||
),
|
||||
null,
|
||||
false,
|
||||
@@ -284,10 +289,11 @@ class ExtendedProfileWidget extends Form
|
||||
protected function showEditableWebsite($name, $field)
|
||||
{
|
||||
$index = isset($field['index']) ? $field['index'] : 0;
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$id = "extprofile-$name-$index";
|
||||
$rel = $id . '-rel';
|
||||
$this->out->elementStart(
|
||||
'div', array(
|
||||
'div',
|
||||
array(
|
||||
'id' => $id . '-edit',
|
||||
'class' => 'website-item'
|
||||
)
|
||||
@@ -301,13 +307,13 @@ class ExtendedProfileWidget extends Form
|
||||
$id . '-rel',
|
||||
'Type',
|
||||
array(
|
||||
'blog' => 'Blog',
|
||||
'blog' => 'Blog',
|
||||
'homepage' => 'Homepage',
|
||||
'facebook' => 'Facebook',
|
||||
'linkedin' => 'LinkedIn',
|
||||
'flickr' => 'Flickr',
|
||||
'other' => 'Other',
|
||||
'twitter' => 'Twitter'
|
||||
'flickr' => 'Flickr',
|
||||
'other' => 'Other',
|
||||
'twitter' => 'Twitter'
|
||||
),
|
||||
null,
|
||||
false,
|
||||
@@ -332,7 +338,9 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($field['start'])
|
||||
date(
|
||||
'j M Y',
|
||||
strtotime($field['start'])
|
||||
)
|
||||
);
|
||||
// TRANS: Field label in extended profile (when did one end a position or education).
|
||||
@@ -340,7 +348,9 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($field['end'])
|
||||
date(
|
||||
'j M Y',
|
||||
strtotime($field['end'])
|
||||
)
|
||||
);
|
||||
|
||||
@@ -359,9 +369,10 @@ class ExtendedProfileWidget extends Form
|
||||
protected function showEditableExperience($name, $field)
|
||||
{
|
||||
$index = isset($field['index']) ? $field['index'] : 0;
|
||||
$id = "extprofile-$name-$index";
|
||||
$id = "extprofile-$name-$index";
|
||||
$this->out->elementStart(
|
||||
'div', array(
|
||||
'div',
|
||||
array(
|
||||
'id' => $id . '-edit',
|
||||
'class' => 'experience-item'
|
||||
)
|
||||
@@ -383,7 +394,7 @@ class ExtendedProfileWidget extends Form
|
||||
isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
|
||||
);
|
||||
|
||||
// TRANS: Field label in extended profile (when did one end a position or education).
|
||||
// TRANS: Field label in extended profile (when did one end a position or education).
|
||||
$this->out->element('div', 'label', _m('End'));
|
||||
|
||||
$this->out->input(
|
||||
@@ -426,7 +437,9 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($field['start'])
|
||||
date(
|
||||
'j M Y',
|
||||
strtotime($field['start'])
|
||||
)
|
||||
);
|
||||
// TRANS: Field label in extended profile (when did one end a position or education).
|
||||
@@ -434,7 +447,9 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($field['end'])
|
||||
date(
|
||||
'j M Y',
|
||||
strtotime($field['end'])
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -444,9 +459,10 @@ class ExtendedProfileWidget extends Form
|
||||
protected function showEditableEducation($name, $field)
|
||||
{
|
||||
$index = isset($field['index']) ? $field['index'] : 0;
|
||||
$id = "extprofile-$name-$index";
|
||||
$id = "extprofile-$name-$index";
|
||||
$this->out->elementStart(
|
||||
'div', array(
|
||||
'div',
|
||||
array(
|
||||
'id' => $id . '-edit',
|
||||
'class' => 'education-item'
|
||||
)
|
||||
@@ -498,7 +514,7 @@ class ExtendedProfileWidget extends Form
|
||||
$this->out->elementEnd('div');
|
||||
}
|
||||
|
||||
function showMultiControls()
|
||||
public function showMultiControls()
|
||||
{
|
||||
$this->out->element(
|
||||
'a',
|
||||
@@ -525,61 +541,63 @@ class ExtendedProfileWidget extends Form
|
||||
/**
|
||||
* Outputs the value of a field
|
||||
*
|
||||
* @param string $name name of the field
|
||||
* @param array $field set of key/value pairs for the field
|
||||
* @param string $name name of the field
|
||||
* @param array $field set of key/value pairs for the field
|
||||
*/
|
||||
protected function showFieldValue($name, $field)
|
||||
{
|
||||
$type = strval(@$field['type']);
|
||||
|
||||
switch($type)
|
||||
{
|
||||
case '':
|
||||
case 'text':
|
||||
case 'textarea':
|
||||
$this->out->text($this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'date':
|
||||
$value = $this->ext->getDateValue($name);
|
||||
if (!empty($value)) {
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($value))
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'person':
|
||||
$this->out->text($this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'tags':
|
||||
$this->out->text($this->ext->getTags());
|
||||
break;
|
||||
case 'phone':
|
||||
$this->showPhone($name, $field);
|
||||
break;
|
||||
case 'website':
|
||||
$this->showWebsite($name, $field);
|
||||
break;
|
||||
case 'im':
|
||||
$this->showIm($name, $field);
|
||||
break;
|
||||
case 'experience':
|
||||
$this->showExperience($name, $field);
|
||||
break;
|
||||
case 'education':
|
||||
$this->showEducation($name, $field);
|
||||
break;
|
||||
default:
|
||||
$this->out->text("TYPE: $type");
|
||||
switch ($type) {
|
||||
case '':
|
||||
case 'text':
|
||||
case 'textarea':
|
||||
case 'person':
|
||||
$this->out->text($this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'custom-text':
|
||||
case 'custom-textarea':
|
||||
$this->out->text(isset($field['value']) ? $field['value'] : null);
|
||||
break;
|
||||
case 'date':
|
||||
$value = $this->ext->getDateValue($name);
|
||||
if (!empty($value)) {
|
||||
$this->out->element(
|
||||
'div',
|
||||
array('class' => 'field date'),
|
||||
date('j M Y', strtotime($value))
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'tags':
|
||||
$this->out->text($this->ext->getTags());
|
||||
break;
|
||||
case 'phone':
|
||||
$this->showPhone($name, $field);
|
||||
break;
|
||||
case 'website':
|
||||
$this->showWebsite($name, $field);
|
||||
break;
|
||||
case 'im':
|
||||
$this->showIm($name, $field);
|
||||
break;
|
||||
case 'experience':
|
||||
$this->showExperience($name, $field);
|
||||
break;
|
||||
case 'education':
|
||||
$this->showEducation($name, $field);
|
||||
break;
|
||||
default:
|
||||
$this->out->text("TYPE: $type");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an editable version of the field
|
||||
*
|
||||
* @param string $name name fo the field
|
||||
* @param array $field array of key/value pairs for the field
|
||||
* @param string $name name fo the field
|
||||
* @param array $field array of key/value pairs for the field
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function showEditableField($name, $field)
|
||||
{
|
||||
@@ -591,45 +609,47 @@ class ExtendedProfileWidget extends Form
|
||||
$value = 'placeholder';
|
||||
|
||||
switch ($type) {
|
||||
case '':
|
||||
case 'text':
|
||||
$out->input($id, null, $this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'date':
|
||||
$value = $this->ext->getDateValue($name);
|
||||
$out->input(
|
||||
$id,
|
||||
null,
|
||||
empty($value) ? null : date('j M Y', strtotime($value))
|
||||
);
|
||||
break;
|
||||
case 'person':
|
||||
$out->input($id, null, $this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'textarea':
|
||||
$out->textarea($id, null, $this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'tags':
|
||||
$out->input($id, null, $this->ext->getTags());
|
||||
break;
|
||||
case 'phone':
|
||||
$this->showEditablePhone($name, $field);
|
||||
break;
|
||||
case 'im':
|
||||
$this->showEditableIm($name, $field);
|
||||
break;
|
||||
case 'website':
|
||||
$this->showEditableWebsite($name, $field);
|
||||
break;
|
||||
case 'experience':
|
||||
$this->showEditableExperience($name, $field);
|
||||
break;
|
||||
case 'education':
|
||||
$this->showEditableEducation($name, $field);
|
||||
break;
|
||||
default:
|
||||
// TRANS: Field label for undefined field in extended profile.
|
||||
$out->input($id, null, sprintf(_m('TYPE: %s'),$type));
|
||||
case '':
|
||||
case 'text':
|
||||
case 'person':
|
||||
$out->input($id, null, $this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'custom-text':
|
||||
case 'custom-textarea':
|
||||
$out->input($id, null, isset($field['value']) ? $field['value'] : null);
|
||||
break;
|
||||
case 'date':
|
||||
$value = $this->ext->getDateValue($name);
|
||||
$out->input(
|
||||
$id,
|
||||
null,
|
||||
empty($value) ? null : date('j M Y', strtotime($value))
|
||||
);
|
||||
break;
|
||||
case 'textarea':
|
||||
$out->textarea($id, null, $this->ext->getTextValue($name));
|
||||
break;
|
||||
case 'tags':
|
||||
$out->input($id, null, $this->ext->getTags());
|
||||
break;
|
||||
case 'phone':
|
||||
$this->showEditablePhone($name, $field);
|
||||
break;
|
||||
case 'im':
|
||||
$this->showEditableIm($name, $field);
|
||||
break;
|
||||
case 'website':
|
||||
$this->showEditableWebsite($name, $field);
|
||||
break;
|
||||
case 'experience':
|
||||
$this->showEditableExperience($name, $field);
|
||||
break;
|
||||
case 'education':
|
||||
$this->showEditableEducation($name, $field);
|
||||
break;
|
||||
default:
|
||||
// TRANS: Field label for undefined field in extended profile.
|
||||
$out->input($id, null, sprintf(_m('TYPE: %s'), $type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,19 +657,20 @@ class ExtendedProfileWidget extends Form
|
||||
* Action elements
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
function formActions()
|
||||
public function formActions()
|
||||
{
|
||||
$this->out->submit(
|
||||
'save',
|
||||
// TRANS: Button text for saving extended profile properties.
|
||||
_m('BUTTON','Save'),
|
||||
_m('BUTTON', 'Save'),
|
||||
'submit form_action-secondary',
|
||||
'save',
|
||||
// TRANS: .
|
||||
// TRANS: Button title for saving extended profile properties.
|
||||
_m('Save details')
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -657,7 +678,7 @@ class ExtendedProfileWidget extends Form
|
||||
*
|
||||
* @return string ID of the form
|
||||
*/
|
||||
function id()
|
||||
public function id()
|
||||
{
|
||||
return 'profile-details-' . $this->profile->id;
|
||||
}
|
||||
@@ -667,7 +688,7 @@ class ExtendedProfileWidget extends Form
|
||||
*
|
||||
* @return string of the form class
|
||||
*/
|
||||
function formClass()
|
||||
public function formClass()
|
||||
{
|
||||
return 'form_profile_details form_settings';
|
||||
}
|
||||
@@ -677,7 +698,7 @@ class ExtendedProfileWidget extends Form
|
||||
*
|
||||
* @return string URL of the action
|
||||
*/
|
||||
function action()
|
||||
public function action()
|
||||
{
|
||||
return common_local_url('profiledetailsettings');
|
||||
}
|
||||
|
52
plugins/ExtendedProfile/lib/profiletools.php
Normal file
52
plugins/ExtendedProfile/lib/profiletools.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Allows administrators to define additional profile fields for the users of a GNU social installation.
|
||||
*
|
||||
* @category Widget
|
||||
* @package GNU social
|
||||
* @author Max Shinn <trombonechamp@gmail.com>
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
defined('GNUSOCIAL') || die();
|
||||
|
||||
function gnusocial_profile_merge(&$profile)
|
||||
{
|
||||
$responses = GNUsocialProfileExtensionResponse::findResponsesByProfile($profile->id);
|
||||
$profile->customfields = [];
|
||||
foreach ($responses as $response) {
|
||||
$title = $response->systemname;
|
||||
$profile->$title = $response->value;
|
||||
$profile->customfields[] = $title;
|
||||
}
|
||||
}
|
||||
|
||||
function gnusocial_field_systemname_validate($systemname)
|
||||
{
|
||||
// Ensure it doesn't exist already
|
||||
$fields = GNUsocialProfileExtensionField::allFields();
|
||||
foreach ($fields as $field) {
|
||||
if ($field->systemname == $systemname) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Ensure that it consist of only alphanumeric characters
|
||||
return ctype_alnum($systemname);
|
||||
}
|
Reference in New Issue
Block a user