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',
310 'twitter' => 'Twitter'
314 isset($field['rel']) ? $field['rel'] : null
317 $this->showMultiControls();
318 $this->out->elementEnd('div');
321 protected function showExperience($name, $field)
323 $this->out->elementStart('div', 'experience-item');
324 // TRANS: Field label in experience area of extended profile.
325 $this->out->element('div', 'label', _m('Company'));
327 if (!empty($field['company'])) {
328 $this->out->element('div', 'field', $field['company']);
330 // TRANS: Field label in extended profile (when did one start a position or education).
331 $this->out->element('div', 'label', _m('Start'));
334 array('class' => 'field date'),
335 date('j M Y', strtotime($field['start'])
338 // TRANS: Field label in extended profile (when did one end a position or education).
339 $this->out->element('div', 'label', _m('End'));
342 array('class' => 'field date'),
343 date('j M Y', strtotime($field['end'])
347 if ($field['current']) {
350 array('class' => 'field current'),
351 // TRANS: Field value in experience area of extended profile (one still holds a position).
356 $this->out->elementEnd('div');
359 protected function showEditableExperience($name, $field)
361 $index = isset($field['index']) ? $field['index'] : 0;
362 $id = "extprofile-$name-$index";
363 $this->out->elementStart(
365 'id' => $id . '-edit',
366 'class' => 'experience-item'
370 // TRANS: Field label in experience edit area of extended profile (which company does one work for).
371 $this->out->element('div', 'label', _m('Company'));
375 isset($field['company']) ? $field['company'] : null
378 // TRANS: Field label in extended profile (when did one start a position or education).
379 $this->out->element('div', 'label', _m('Start'));
383 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
386 // TRANS: Field label in extended profile (when did one end a position or education).
387 $this->out->element('div', 'label', _m('End'));
392 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
398 $this->out->elementStart('div', 'current-checkbox');
399 $this->out->checkbox(
401 // TRANS: Checkbox label in experience edit area of extended profile (one still works at a company).
405 $this->out->elementEnd('div');
407 $this->showMultiControls();
408 $this->out->elementEnd('div');
411 protected function showEducation($name, $field)
413 $this->out->elementStart('div', 'education-item');
414 // TRANS: Field label in education area of extended profile.
415 $this->out->element('div', 'label', _m('Institution'));
416 if (!empty($field['school'])) {
417 $this->out->element('div', 'field', $field['school']);
418 // TRANS: Field label in extended profile for specifying an academic degree.
419 $this->out->element('div', 'label', _m('Degree'));
420 $this->out->element('div', 'field', $field['degree']);
421 // TRANS: Field label in education area of extended profile.
422 $this->out->element('div', 'label', _m('Description'));
423 $this->out->element('div', 'field', $field['description']);
424 // TRANS: Field label in extended profile (when did one start a position or education).
425 $this->out->element('div', 'label', _m('Start'));
428 array('class' => 'field date'),
429 date('j M Y', strtotime($field['start'])
432 // TRANS: Field label in extended profile (when did one end a position or education).
433 $this->out->element('div', 'label', _m('End'));
436 array('class' => 'field date'),
437 date('j M Y', strtotime($field['end'])
441 $this->out->elementEnd('div');
444 protected function showEditableEducation($name, $field)
446 $index = isset($field['index']) ? $field['index'] : 0;
447 $id = "extprofile-$name-$index";
448 $this->out->elementStart(
450 'id' => $id . '-edit',
451 'class' => 'education-item'
454 // TRANS: Field label in education edit area of extended profile.
455 $this->out->element('div', 'label', _m('Institution'));
459 isset($field['school']) ? $field['school'] : null
462 // TRANS: Field label in extended profile for specifying an academic degree.
463 $this->out->element('div', 'label', _m('Degree'));
467 isset($field['degree']) ? $field['degree'] : null
470 // TRANS: Field label in education edit area of extended profile.
471 $this->out->element('div', 'label', _m('Description'));
473 $this->out->textarea(
474 $id . '-description',
476 isset($field['description']) ? $field['description'] : null
479 // TRANS: Field label in extended profile (when did one start a position or education).
480 $this->out->element('div', 'label', _m('Start'));
484 // @todo FIXME: does date format need i18n? If so, should probly be dealt with in core.
485 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
488 // TRANS: Field label in extended profile (when did one end a position or education).
489 $this->out->element('div', 'label', _m('End'));
493 // @todo FIXME: does date format need i18n? If so, should probly be dealt with in core.
494 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
497 $this->showMultiControls();
498 $this->out->elementEnd('div');
501 function showMultiControls()
506 'class' => 'remove_row',
507 'href' => 'javascript://',
508 'style' => 'display: none;'
516 'class' => 'add_row',
517 'href' => 'javascript://',
518 'style' => 'display: none;'
520 // TRANS: Link description in extended profile page to add another profile element.
521 _m('Add another item')
526 * Outputs the value of a field
528 * @param string $name name of the field
529 * @param array $field set of key/value pairs for the field
531 protected function showFieldValue($name, $field)
533 $type = strval(@$field['type']);
540 $this->out->text($this->ext->getTextValue($name));
543 $value = $this->ext->getDateValue($name);
544 if (!empty($value)) {
547 array('class' => 'field date'),
548 date('j M Y', strtotime($value))
553 $this->out->text($this->ext->getTextValue($name));
556 $this->out->text($this->ext->getTags());
559 $this->showPhone($name, $field);
562 $this->showWebsite($name, $field);
565 $this->showIm($name, $field);
568 $this->showExperience($name, $field);
571 $this->showEducation($name, $field);
574 $this->out->text("TYPE: $type");
579 * Show an editable version of the field
581 * @param string $name name fo the field
582 * @param array $field array of key/value pairs for the field
584 protected function showEditableField($name, $field)
588 $type = strval(@$field['type']);
589 $id = "extprofile-" . $name;
591 $value = 'placeholder';
596 $out->input($id, null, $this->ext->getTextValue($name));
599 $value = $this->ext->getDateValue($name);
603 empty($value) ? null : date('j M Y', strtotime($value))
607 $out->input($id, null, $this->ext->getTextValue($name));
610 $out->textarea($id, null, $this->ext->getTextValue($name));
613 $out->input($id, null, $this->ext->getTags());
616 $this->showEditablePhone($name, $field);
619 $this->showEditableIm($name, $field);
622 $this->showEditableWebsite($name, $field);
625 $this->showEditableExperience($name, $field);
628 $this->showEditableEducation($name, $field);
631 // TRANS: Field label for undefined field in extended profile.
632 $out->input($id, null, sprintf(_m('TYPE: %s'),$type));
641 function formActions()
645 // TRANS: Button text for saving extended profile properties.
647 'submit form_action-secondary',
650 // TRANS: Button title for saving extended profile properties.
658 * @return string ID of the form
662 return 'profile-details-' . $this->profile->id;
668 * @return string of the form class
672 return 'form_profile_details form_settings';
678 * @return string URL of the action
682 return common_local_url('profiledetailsettings');