123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ExtendedProfileWidget extends Form
- {
- const EDITABLE = true;
-
- protected $profile;
-
- protected $ext;
-
- public function __construct(XMLOutputter $out=null, Profile $profile=null, $editable=false)
- {
- parent::__construct($out);
- $this->profile = $profile;
- $this->ext = new ExtendedProfile($this->profile);
- $this->editable = $editable;
- }
-
- public function show()
- {
- if ($this->editable) {
- parent::show();
- } else {
- $this->showSections();
- }
- }
-
- public function formData()
- {
-
- $this->out->elementStart(
- 'div',
-
- array('id' => 'confirm-dialog', 'title' => _m('Confirmation Required'))
- );
-
- $this->out->text(_m('Really delete this entry?'));
- $this->out->elementEnd('div');
- $this->showSections();
- }
-
- public function showSections()
- {
- $sections = $this->ext->getSections();
- foreach ($sections as $name => $section) {
- $this->showExtendedProfileSection($name, $section);
- }
- }
-
- protected function showExtendedProfileSection($name, $section)
- {
- $this->out->element('h3', null, $section['label']);
- $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);
- }
- }
- $this->out->elementEnd('table');
- }
-
- protected function showExtendedProfileField($name, $field)
- {
- $this->out->elementStart('tr');
- $this->out->element('th', str_replace(' ','_',strtolower($field['label'])), $field['label']);
- $this->out->elementStart('td');
- if ($this->editable) {
- $this->showEditableField($name, $field);
- } else {
- $this->showFieldValue($name, $field);
- }
- $this->out->elementEnd('td');
- $this->out->elementEnd('tr');
- }
- protected function showMultiple($name, $fields) {
- foreach ($fields as $field) {
- $this->showExtendedProfileField($name, $field);
- }
- }
-
-
- protected function showPhone($name, $field)
- {
- $this->out->elementStart('div', array('class' => 'phone-display'));
- if (!empty($field['value'])) {
- $this->out->text($field['value']);
- if (!empty($field['rel'])) {
-
- $outtext = sprintf(_m('(%s)'),$field['rel']);
- $this->out->text(' '.$outtext);
- }
- }
- $this->out->elementEnd('div');
- }
- protected function showIm($name, $field)
- {
- $this->out->elementStart('div', array('class' => 'im-display'));
- $this->out->text($field['value']);
- if (!empty($field['rel'])) {
-
- $outtext = sprintf(_m('(%s)'),$field['rel']);
- $this->out->text(' '.$outtext);
- }
- $this->out->elementEnd('div');
- }
- protected function showWebsite($name, $field)
- {
- $this->out->elementStart('div', array('class' => 'website-display'));
- $url = $field['value'];
- $this->out->element(
- "a",
- array(
- 'href' => $url,
- 'class' => 'extended-profile-link',
- 'target' => "_blank"
- ),
- $url
- );
- if (!empty($field['rel'])) {
-
- $outtext = sprintf(_m('(%s)'),$field['rel']);
- $this->out->text(' '.$outtext);
- }
- $this->out->elementEnd('div');
- }
- protected function showEditableIm($name, $field)
- {
- $index = isset($field['index']) ? $field['index'] : 0;
- $id = "extprofile-$name-$index";
- $rel = $id . '-rel';
- $this->out->elementStart(
- 'div', array(
- 'id' => $id . '-edit',
- 'class' => 'im-item'
- )
- );
- $this->out->input(
- $id,
- null,
- isset($field['value']) ? $field['value'] : null
- );
- $this->out->dropdown(
- $id . '-rel',
- 'Type',
- array(
- 'jabber' => 'Jabber',
- 'gtalk' => 'GTalk',
- 'aim' => 'AIM',
- 'yahoo' => 'Yahoo! Messenger',
- 'msn' => 'MSN',
- 'skype' => 'Skype',
- 'other' => 'Other'
- ),
- null,
- false,
- isset($field['rel']) ? $field['rel'] : null
- );
- $this->showMultiControls();
- $this->out->elementEnd('div');
- }
- protected function showEditablePhone($name, $field)
- {
- $index = isset($field['index']) ? $field['index'] : 0;
- $id = "extprofile-$name-$index";
- $rel = $id . '-rel';
- $this->out->elementStart(
- 'div', array(
- 'id' => $id . '-edit',
- 'class' => 'phone-item'
- )
- );
- $this->out->input(
- $id,
- null,
- isset($field['value']) ? $field['value'] : null
- );
- $this->out->dropdown(
- $id . '-rel',
- 'Type',
- array(
- 'office' => 'Office',
- 'mobile' => 'Mobile',
- 'home' => 'Home',
- 'pager' => 'Pager',
- 'other' => 'Other'
- ),
- null,
- false,
- isset($field['rel']) ? $field['rel'] : null
- );
- $this->showMultiControls();
- $this->out->elementEnd('div');
- }
- protected function showEditableWebsite($name, $field)
- {
- $index = isset($field['index']) ? $field['index'] : 0;
- $id = "extprofile-$name-$index";
- $rel = $id . '-rel';
- $this->out->elementStart(
- 'div', array(
- 'id' => $id . '-edit',
- 'class' => 'website-item'
- )
- );
- $this->out->input(
- $id,
- null,
- isset($field['value']) ? $field['value'] : null
- );
- $this->out->dropdown(
- $id . '-rel',
- 'Type',
- array(
- 'blog' => 'Blog',
- 'homepage' => 'Homepage',
- 'facebook' => 'Facebook',
- 'linkedin' => 'LinkedIn',
- 'flickr' => 'Flickr',
- 'google' => 'Google Profile',
- 'other' => 'Other',
- 'twitter' => 'Twitter'
- ),
- null,
- false,
- isset($field['rel']) ? $field['rel'] : null
- );
- $this->showMultiControls();
- $this->out->elementEnd('div');
- }
- protected function showExperience($name, $field)
- {
- $this->out->elementStart('div', 'experience-item');
-
- $this->out->element('div', 'label', _m('Company'));
- if (!empty($field['company'])) {
- $this->out->element('div', 'field', $field['company']);
-
- $this->out->element('div', 'label', _m('Start'));
- $this->out->element(
- 'div',
- array('class' => 'field date'),
- date('j M Y', strtotime($field['start'])
- )
- );
-
- $this->out->element('div', 'label', _m('End'));
- $this->out->element(
- 'div',
- array('class' => 'field date'),
- date('j M Y', strtotime($field['end'])
- )
- );
- if ($field['current']) {
- $this->out->element(
- 'div',
- array('class' => 'field current'),
-
- _m('(Current)')
- );
- }
- }
- $this->out->elementEnd('div');
- }
- protected function showEditableExperience($name, $field)
- {
- $index = isset($field['index']) ? $field['index'] : 0;
- $id = "extprofile-$name-$index";
- $this->out->elementStart(
- 'div', array(
- 'id' => $id . '-edit',
- 'class' => 'experience-item'
- )
- );
-
- $this->out->element('div', 'label', _m('Company'));
- $this->out->input(
- $id,
- null,
- isset($field['company']) ? $field['company'] : null
- );
-
- $this->out->element('div', 'label', _m('Start'));
- $this->out->input(
- $id . '-start',
- null,
- isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
- );
-
- $this->out->element('div', 'label', _m('End'));
- $this->out->input(
- $id . '-end',
- null,
- isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
- );
- $this->out->hidden(
- $id . '-current',
- 'false'
- );
- $this->out->elementStart('div', 'current-checkbox');
- $this->out->checkbox(
- $id . '-current',
-
- _m('Current'),
- $field['current']
- );
- $this->out->elementEnd('div');
- $this->showMultiControls();
- $this->out->elementEnd('div');
- }
- protected function showEducation($name, $field)
- {
- $this->out->elementStart('div', 'education-item');
-
- $this->out->element('div', 'label', _m('Institution'));
- if (!empty($field['school'])) {
- $this->out->element('div', 'field', $field['school']);
-
- $this->out->element('div', 'label', _m('Degree'));
- $this->out->element('div', 'field', $field['degree']);
-
- $this->out->element('div', 'label', _m('Description'));
- $this->out->element('div', 'field', $field['description']);
-
- $this->out->element('div', 'label', _m('Start'));
- $this->out->element(
- 'div',
- array('class' => 'field date'),
- date('j M Y', strtotime($field['start'])
- )
- );
-
- $this->out->element('div', 'label', _m('End'));
- $this->out->element(
- 'div',
- array('class' => 'field date'),
- date('j M Y', strtotime($field['end'])
- )
- );
- }
- $this->out->elementEnd('div');
- }
- protected function showEditableEducation($name, $field)
- {
- $index = isset($field['index']) ? $field['index'] : 0;
- $id = "extprofile-$name-$index";
- $this->out->elementStart(
- 'div', array(
- 'id' => $id . '-edit',
- 'class' => 'education-item'
- )
- );
-
- $this->out->element('div', 'label', _m('Institution'));
- $this->out->input(
- $id,
- null,
- isset($field['school']) ? $field['school'] : null
- );
-
- $this->out->element('div', 'label', _m('Degree'));
- $this->out->input(
- $id . '-degree',
- null,
- isset($field['degree']) ? $field['degree'] : null
- );
-
- $this->out->element('div', 'label', _m('Description'));
- $this->out->textarea(
- $id . '-description',
- null,
- isset($field['description']) ? $field['description'] : null
- );
-
- $this->out->element('div', 'label', _m('Start'));
- $this->out->input(
- $id . '-start',
- null,
-
- isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
- );
-
- $this->out->element('div', 'label', _m('End'));
- $this->out->input(
- $id . '-end',
- null,
-
- isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
- );
- $this->showMultiControls();
- $this->out->elementEnd('div');
- }
- function showMultiControls()
- {
- $this->out->element(
- 'a',
- array(
- 'class' => 'remove_row',
- 'href' => 'javascript://',
- 'style' => 'display: none;'
- ),
- '-'
- );
- $this->out->element(
- 'a',
- array(
- 'class' => 'add_row',
- 'href' => 'javascript://',
- 'style' => 'display: none;'
- ),
-
- _m('Add another item')
- );
- }
-
- 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");
- }
- }
-
- protected function showEditableField($name, $field)
- {
- $out = $this->out;
- $type = strval(@$field['type']);
- $id = "extprofile-" . $name;
- $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:
-
- $out->input($id, null, sprintf(_m('TYPE: %s'),$type));
- }
- }
-
- function formActions()
- {
- $this->out->submit(
- 'save',
-
- _m('BUTTON','Save'),
- 'submit form_action-secondary',
- 'save',
-
-
- _m('Save details')
- );
- }
-
- function id()
- {
- return 'profile-details-' . $this->profile->id;
- }
-
- function formClass()
- {
- return 'form_profile_details form_settings';
- }
-
- function action()
- {
- return common_local_url('profiledetailsettings');
- }
- }
|