static function allFields()
 {
     $field = new GNUsocialProfileExtensionField();
     $fields = array();
     if ($field->find()) {
         while ($field->fetch()) {
             $fields[] = clone $field;
         }
     }
     return $fields;
 }
示例#2
0
 function showContent()
 {
     if (empty($this->profile)) {
         return;
     }
     $profilelistitem = new ProfileListItem($this->profile, $this);
     $profilelistitem->show();
     $this->elementStart('ul');
     $fields = GNUsocialProfileExtensionField::allFields();
     foreach ($fields as $field) {
         $fieldname = $field->systemname;
         if (!empty($this->profile->{$fieldname})) {
             $this->elementStart('li', array('class' => 'biolistitem'));
             $this->elementStart('div', array('class' => 'biolistitemcontainer'));
             if ($field->type == 'text') {
                 $this->element('h3', array(), $field->title);
                 $this->element('p', array('class' => 'biovalue'), $this->profile->{$fieldname});
             } else {
                 $this->element('span', array('class' => 'biotitle'), $field->title);
                 $this->text(' ');
                 $this->element('span', array('class' => 'biovalue'), $this->profile->{$fieldname});
             }
             $this->elementEnd('div');
             $this->elementEnd('li');
         }
     }
     $this->elementEnd('ul');
 }
 function onEndProfileSaveForm($action)
 {
     $fields = GNUsocialProfileExtensionField::allFields();
     $user = common_current_user();
     $profile = $user->getProfile();
     foreach ($fields as $field) {
         $val = $action->trimmed($field->systemname);
         $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();
         }
     }
 }
示例#4
0
function gnusocial_field_systemname_validate($systemname)
{
    $fields = GNUsocialProfileExtensionField::allFields();
    foreach ($fields as $field) {
        if ($field->systemname == $systemname) {
            return false;
        }
    }
    return ctype_alphanum($systemname);
}
示例#5
0
 function formData()
 {
     $title = null;
     $description = null;
     $type = null;
     $systemname = null;
     $id = null;
     $fieldsettitle = _("New Profile Field");
     //Edit a field
     if ($this->out->trimmed('edit')) {
         $field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
         $title = $field->title;
         $description = $field->description;
         $type = $field->type;
         $systemname = $field->systemname;
         $this->out->hidden('id', $field->id, 'id');
         $fieldsettitle = _("Edit Profile Field");
     } else {
         $this->out->elementStart('fieldset');
         $this->out->element('legend', null, _('Existing Custom Profile Fields'));
         $this->out->elementStart('ul', 'form_data');
         $fields = GNUsocialProfileExtensionField::allFields();
         foreach ($fields as $field) {
             $this->li();
             $content = $this->out->elementStart('div');
             $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id), $field->title);
             $this->out->text(' (' . $field->type . '): ' . $field->description);
             $this->out->elementEnd('div');
             $this->unli();
         }
         $this->out->elementEnd('ul');
         $this->out->elementEnd('fieldset');
     }
     //New fields
     $this->out->elementStart('fieldset');
     $this->out->element('legend', null, $fieldsettitle);
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('title', _('Title'), $title, _('The title of the field'));
     $this->unli();
     $this->li();
     $this->out->input('systemname', _('Internal name'), $systemname, _('The alphanumeric name used internally for this field.  Also the key used in OStatus user info. (optional)'));
     $this->unli();
     $this->li();
     $this->out->input('description', _('Description'), $description, _('An optional more detailed description of the field'));
     $this->unli();
     $this->li();
     $this->out->dropdown('type', _('Type'), array('text' => _("Text"), 'str' => _("String")), _('The type of the datafield'), false, $type);
     $this->unli();
     $this->out->elementEnd('ul');
     $this->out->elementEnd('fieldset');
 }