3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET')) {
25 * Class for outputting a widget to display or edit
28 class ExtendedProfileWidget extends Form
30 const EDITABLE = true;
40 * The extended profile
42 * @var Extended_profile
49 * @param XMLOutputter $out
50 * @param Profile $profile
51 * @param boolean $editable
53 public function __construct(XMLOutputter $out=null, Profile $profile=null, $editable=false)
55 parent::__construct($out);
57 $this->profile = $profile;
58 $this->ext = new ExtendedProfile($this->profile);
60 $this->editable = $editable;
64 * Show the extended profile, or the edit form
66 public function show()
68 if ($this->editable) {
71 $this->showSections();
78 public function formData()
80 // For JQuery UI modal dialog
81 $this->out->elementStart(
83 // TRANS: Title for extended profile entry deletion dialog.
84 array('id' => 'confirm-dialog', 'title' => _m('Confirmation Required'))
86 // TRANS: Confirmation text for extended profile entry deletion dialog.
87 $this->out->text(_m('Really delete this entry?'));
88 $this->out->elementEnd('div');
89 $this->showSections();
93 * Show each section of the extended profile
95 public function showSections()
97 $sections = $this->ext->getSections();
98 foreach ($sections as $name => $section) {
99 $this->showExtendedProfileSection($name, $section);
104 * Show an extended profile section
106 * @param string $name name of the section
107 * @param array $section array of fields for the section
109 protected function showExtendedProfileSection($name, $section)
111 $this->out->element('h3', null, $section['label']);
112 $this->out->elementStart('table', array('class' => 'extended-profile'));
114 foreach ($section['fields'] as $fieldName => $field) {
122 $this->showMultiple($fieldName, $field);
125 $this->showExtendedProfileField($fieldName, $field);
128 $this->out->elementEnd('table');
132 * Show an extended profile field
134 * @param string $name name of the field
135 * @param array $field set of key/value pairs for the field
137 protected function showExtendedProfileField($name, $field)
139 $this->out->elementStart('tr');
141 $this->out->element('th', str_replace(' ','_',strtolower($field['label'])), $field['label']);
143 $this->out->elementStart('td');
144 if ($this->editable) {
145 $this->showEditableField($name, $field);
147 $this->showFieldValue($name, $field);
149 $this->out->elementEnd('td');
151 $this->out->elementEnd('tr');
154 protected function showMultiple($name, $fields) {
155 foreach ($fields as $field) {
156 $this->showExtendedProfileField($name, $field);
160 // XXX: showPhone, showIm and showWebsite all work the same, so
162 protected function showPhone($name, $field)
164 $this->out->elementStart('div', array('class' => 'phone-display'));
165 if (!empty($field['value'])) {
166 $this->out->text($field['value']);
167 if (!empty($field['rel'])) {
168 // TRANS: Value between parentheses (phone number, website, or IM address).
169 $outtext = sprintf(_m('(%s)'),$field['rel']);
170 $this->out->text(' '.$outtext);
173 $this->out->elementEnd('div');
176 protected function showIm($name, $field)
178 $this->out->elementStart('div', array('class' => 'im-display'));
179 $this->out->text($field['value']);
180 if (!empty($field['rel'])) {
181 // TRANS: Value between parentheses (phone number, website, or IM address).
182 $outtext = sprintf(_m('(%s)'),$field['rel']);
183 $this->out->text(' '.$outtext);
185 $this->out->elementEnd('div');
188 protected function showWebsite($name, $field)
190 $this->out->elementStart('div', array('class' => 'website-display'));
192 $url = $field['value'];
198 'class' => 'extended-profile-link',
204 if (!empty($field['rel'])) {
205 // TRANS: Value between parentheses (phone number, website, or IM address).
206 $outtext = sprintf(_m('(%s)'),$field['rel']);
207 $this->out->text(' '.$outtext);
209 $this->out->elementEnd('div');
212 protected function showEditableIm($name, $field)
214 $index = isset($field['index']) ? $field['index'] : 0;
215 $id = "extprofile-$name-$index";
217 $this->out->elementStart(
219 'id' => $id . '-edit',
226 isset($field['value']) ? $field['value'] : null
228 $this->out->dropdown(
232 'jabber' => 'Jabber',
235 'yahoo' => 'Yahoo! Messenger',
242 isset($field['rel']) ? $field['rel'] : null
245 $this->showMultiControls();
246 $this->out->elementEnd('div');
249 protected function showEditablePhone($name, $field)
251 $index = isset($field['index']) ? $field['index'] : 0;
252 $id = "extprofile-$name-$index";
254 $this->out->elementStart(
256 'id' => $id . '-edit',
257 'class' => 'phone-item'
263 isset($field['value']) ? $field['value'] : null
265 $this->out->dropdown(
269 'office' => 'Office',
270 'mobile' => 'Mobile',
277 isset($field['rel']) ? $field['rel'] : null
280 $this->showMultiControls();
281 $this->out->elementEnd('div');
284 protected function showEditableWebsite($name, $field)
286 $index = isset($field['index']) ? $field['index'] : 0;
287 $id = "extprofile-$name-$index";
289 $this->out->elementStart(
291 'id' => $id . '-edit',
292 'class' => 'website-item'
298 isset($field['value']) ? $field['value'] : null
300 $this->out->dropdown(
305 'homepage' => 'Homepage',
306 'facebook' => 'Facebook',
307 'linkedin' => 'LinkedIn',
308 'flickr' => 'Flickr',
309 'google' => 'Google Profile',
311 'twitter' => 'Twitter'
315 isset($field['rel']) ? $field['rel'] : null
318 $this->showMultiControls();
319 $this->out->elementEnd('div');
322 protected function showExperience($name, $field)
324 $this->out->elementStart('div', 'experience-item');
325 // TRANS: Field label in experience area of extended profile.
326 $this->out->element('div', 'label', _m('Company'));
328 if (!empty($field['company'])) {
329 $this->out->element('div', 'field', $field['company']);
331 // TRANS: Field label in extended profile (when did one start a position or education).
332 $this->out->element('div', 'label', _m('Start'));
335 array('class' => 'field date'),
336 date('j M Y', strtotime($field['start'])
339 // TRANS: Field label in extended profile (when did one end a position or education).
340 $this->out->element('div', 'label', _m('End'));
343 array('class' => 'field date'),
344 date('j M Y', strtotime($field['end'])
348 if ($field['current']) {
351 array('class' => 'field current'),
352 // TRANS: Field value in experience area of extended profile (one still holds a position).
357 $this->out->elementEnd('div');
360 protected function showEditableExperience($name, $field)
362 $index = isset($field['index']) ? $field['index'] : 0;
363 $id = "extprofile-$name-$index";
364 $this->out->elementStart(
366 'id' => $id . '-edit',
367 'class' => 'experience-item'
371 // TRANS: Field label in experience edit area of extended profile (which company does one work for).
372 $this->out->element('div', 'label', _m('Company'));
376 isset($field['company']) ? $field['company'] : null
379 // TRANS: Field label in extended profile (when did one start a position or education).
380 $this->out->element('div', 'label', _m('Start'));
384 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
387 // TRANS: Field label in extended profile (when did one end a position or education).
388 $this->out->element('div', 'label', _m('End'));
393 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
399 $this->out->elementStart('div', 'current-checkbox');
400 $this->out->checkbox(
402 // TRANS: Checkbox label in experience edit area of extended profile (one still works at a company).
406 $this->out->elementEnd('div');
408 $this->showMultiControls();
409 $this->out->elementEnd('div');
412 protected function showEducation($name, $field)
414 $this->out->elementStart('div', 'education-item');
415 // TRANS: Field label in education area of extended profile.
416 $this->out->element('div', 'label', _m('Institution'));
417 if (!empty($field['school'])) {
418 $this->out->element('div', 'field', $field['school']);
419 // TRANS: Field label in extended profile for specifying an academic degree.
420 $this->out->element('div', 'label', _m('Degree'));
421 $this->out->element('div', 'field', $field['degree']);
422 // TRANS: Field label in education area of extended profile.
423 $this->out->element('div', 'label', _m('Description'));
424 $this->out->element('div', 'field', $field['description']);
425 // TRANS: Field label in extended profile (when did one start a position or education).
426 $this->out->element('div', 'label', _m('Start'));
429 array('class' => 'field date'),
430 date('j M Y', strtotime($field['start'])
433 // TRANS: Field label in extended profile (when did one end a position or education).
434 $this->out->element('div', 'label', _m('End'));
437 array('class' => 'field date'),
438 date('j M Y', strtotime($field['end'])
442 $this->out->elementEnd('div');
445 protected function showEditableEducation($name, $field)
447 $index = isset($field['index']) ? $field['index'] : 0;
448 $id = "extprofile-$name-$index";
449 $this->out->elementStart(
451 'id' => $id . '-edit',
452 'class' => 'education-item'
455 // TRANS: Field label in education edit area of extended profile.
456 $this->out->element('div', 'label', _m('Institution'));
460 isset($field['school']) ? $field['school'] : null
463 // TRANS: Field label in extended profile for specifying an academic degree.
464 $this->out->element('div', 'label', _m('Degree'));
468 isset($field['degree']) ? $field['degree'] : null
471 // TRANS: Field label in education edit area of extended profile.
472 $this->out->element('div', 'label', _m('Description'));
474 $this->out->textarea(
475 $id . '-description',
477 isset($field['description']) ? $field['description'] : null
480 // TRANS: Field label in extended profile (when did one start a position or education).
481 $this->out->element('div', 'label', _m('Start'));
485 // @todo FIXME: does date format need i18n? If so, should probly be dealt with in core.
486 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
489 // TRANS: Field label in extended profile (when did one end a position or education).
490 $this->out->element('div', 'label', _m('End'));
494 // @todo FIXME: does date format need i18n? If so, should probly be dealt with in core.
495 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
498 $this->showMultiControls();
499 $this->out->elementEnd('div');
502 function showMultiControls()
507 'class' => 'remove_row',
508 'href' => 'javascript://',
509 'style' => 'display: none;'
517 'class' => 'add_row',
518 'href' => 'javascript://',
519 'style' => 'display: none;'
521 // TRANS: Link description in extended profile page to add another profile element.
522 _m('Add another item')
527 * Outputs the value of a field
529 * @param string $name name of the field
530 * @param array $field set of key/value pairs for the field
532 protected function showFieldValue($name, $field)
534 $type = strval(@$field['type']);
541 $this->out->text($this->ext->getTextValue($name));
544 $value = $this->ext->getDateValue($name);
545 if (!empty($value)) {
548 array('class' => 'field date'),
549 date('j M Y', strtotime($value))
554 $this->out->text($this->ext->getTextValue($name));
557 $this->out->text($this->ext->getTags());
560 $this->showPhone($name, $field);
563 $this->showWebsite($name, $field);
566 $this->showIm($name, $field);
569 $this->showExperience($name, $field);
572 $this->showEducation($name, $field);
575 $this->out->text("TYPE: $type");
580 * Show an editable version of the field
582 * @param string $name name fo the field
583 * @param array $field array of key/value pairs for the field
585 protected function showEditableField($name, $field)
589 $type = strval(@$field['type']);
590 $id = "extprofile-" . $name;
592 $value = 'placeholder';
597 $out->input($id, null, $this->ext->getTextValue($name));
600 $value = $this->ext->getDateValue($name);
604 empty($value) ? null : date('j M Y', strtotime($value))
608 $out->input($id, null, $this->ext->getTextValue($name));
611 $out->textarea($id, null, $this->ext->getTextValue($name));
614 $out->input($id, null, $this->ext->getTags());
617 $this->showEditablePhone($name, $field);
620 $this->showEditableIm($name, $field);
623 $this->showEditableWebsite($name, $field);
626 $this->showEditableExperience($name, $field);
629 $this->showEditableEducation($name, $field);
632 // TRANS: Field label for undefined field in extended profile.
633 $out->input($id, null, sprintf(_m('TYPE: %s'),$type));
642 function formActions()
646 // TRANS: Button text for saving extended profile properties.
648 'submit form_action-secondary',
651 // TRANS: Button title for saving extended profile properties.
659 * @return string ID of the form
663 return 'profile-details-' . $this->profile->id;
669 * @return string of the form class
673 return 'form_profile_details form_settings';
679 * @return string URL of the action
683 return common_local_url('profiledetailsettings');