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 array('id' => 'confirm-dialog', 'title' => 'Confirmation Required')
85 $this->out->text('Really delete this entry?');
86 $this->out->elementEnd('div');
87 $this->showSections();
91 * Show each section of the extended profile
93 public function showSections()
95 $sections = $this->ext->getSections();
96 foreach ($sections as $name => $section) {
97 $this->showExtendedProfileSection($name, $section);
102 * Show an extended profile section
104 * @param string $name name of the section
105 * @param array $section array of fields for the section
107 protected function showExtendedProfileSection($name, $section)
109 $this->out->element('h3', null, $section['label']);
110 $this->out->elementStart('table', array('class' => 'extended-profile'));
112 foreach ($section['fields'] as $fieldName => $field) {
120 $this->showMultiple($fieldName, $field);
123 $this->showExtendedProfileField($fieldName, $field);
126 $this->out->elementEnd('table');
130 * Show an extended profile field
132 * @param string $name name of the field
133 * @param array $field set of key/value pairs for the field
135 protected function showExtendedProfileField($name, $field)
137 $this->out->elementStart('tr');
139 $this->out->element('th', str_replace(' ','_',strtolower($field['label'])), $field['label']);
141 $this->out->elementStart('td');
142 if ($this->editable) {
143 $this->showEditableField($name, $field);
145 $this->showFieldValue($name, $field);
147 $this->out->elementEnd('td');
149 $this->out->elementEnd('tr');
152 protected function showMultiple($name, $fields) {
153 foreach ($fields as $field) {
154 $this->showExtendedProfileField($name, $field);
158 // XXX: showPhone, showIm and showWebsite all work the same, so
160 protected function showPhone($name, $field)
162 $this->out->elementStart('div', array('class' => 'phone-display'));
163 if (!empty($field['value'])) {
164 $this->out->text($field['value']);
165 if (!empty($field['rel'])) {
166 $this->out->text(' (' . $field['rel'] . ')');
169 $this->out->elementEnd('div');
172 protected function showIm($name, $field)
174 $this->out->elementStart('div', array('class' => 'im-display'));
175 $this->out->text($field['value']);
176 if (!empty($field['rel'])) {
177 $this->out->text(' (' . $field['rel'] . ')');
179 $this->out->elementEnd('div');
182 protected function showWebsite($name, $field)
184 $this->out->elementStart('div', array('class' => 'website-display'));
186 $url = $field['value'];
192 'class' => 'extended-profile-link',
198 if (!empty($field['rel'])) {
199 $this->out->text(' (' . $field['rel'] . ')');
201 $this->out->elementEnd('div');
204 protected function showEditableIm($name, $field)
206 $index = isset($field['index']) ? $field['index'] : 0;
207 $id = "extprofile-$name-$index";
209 $this->out->elementStart(
211 'id' => $id . '-edit',
218 isset($field['value']) ? $field['value'] : null
220 $this->out->dropdown(
224 'jabber' => 'Jabber',
227 'yahoo' => 'Yahoo! Messenger',
234 isset($field['rel']) ? $field['rel'] : null
237 $this->showMultiControls();
238 $this->out->elementEnd('div');
241 protected function showEditablePhone($name, $field)
243 $index = isset($field['index']) ? $field['index'] : 0;
244 $id = "extprofile-$name-$index";
246 $this->out->elementStart(
248 'id' => $id . '-edit',
249 'class' => 'phone-item'
255 isset($field['value']) ? $field['value'] : null
257 $this->out->dropdown(
261 'office' => 'Office',
262 'mobile' => 'Mobile',
269 isset($field['rel']) ? $field['rel'] : null
272 $this->showMultiControls();
273 $this->out->elementEnd('div');
276 protected function showEditableWebsite($name, $field)
278 $index = isset($field['index']) ? $field['index'] : 0;
279 $id = "extprofile-$name-$index";
281 $this->out->elementStart(
283 'id' => $id . '-edit',
284 'class' => 'website-item'
290 isset($field['value']) ? $field['value'] : null
292 $this->out->dropdown(
297 'homepage' => 'Homepage',
298 'facebook' => 'Facebook',
299 'linkedin' => 'LinkedIn',
300 'flickr' => 'Flickr',
301 'google' => 'Google Profile',
303 'twitter' => 'Twitter'
307 isset($field['rel']) ? $field['rel'] : null
310 $this->showMultiControls();
311 $this->out->elementEnd('div');
314 protected function showExperience($name, $field)
316 $this->out->elementStart('div', 'experience-item');
317 $this->out->element('div', 'label', _m('Company'));
319 if (!empty($field['company'])) {
320 $this->out->element('div', 'field', $field['company']);
322 $this->out->element('div', 'label', _m('Start'));
325 array('class' => 'field date'),
326 date('j M Y', strtotime($field['start'])
329 $this->out->element('div', 'label', _m('End'));
332 array('class' => 'field date'),
333 date('j M Y', strtotime($field['end'])
337 if ($field['current']) {
340 array('class' => 'field current'),
341 '(' . _m('Current') . ')'
345 $this->out->elementEnd('div');
348 protected function showEditableExperience($name, $field)
350 $index = isset($field['index']) ? $field['index'] : 0;
351 $id = "extprofile-$name-$index";
352 $this->out->elementStart(
354 'id' => $id . '-edit',
355 'class' => 'experience-item'
359 $this->out->element('div', 'label', _m('Company'));
363 isset($field['company']) ? $field['company'] : null
366 $this->out->element('div', 'label', _m('Start'));
370 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
373 $this->out->element('div', 'label', _m('End'));
378 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
384 $this->out->elementStart('div', 'current-checkbox');
385 $this->out->checkbox(
390 $this->out->elementEnd('div');
392 $this->showMultiControls();
393 $this->out->elementEnd('div');
396 protected function showEducation($name, $field)
398 $this->out->elementStart('div', 'education-item');
399 $this->out->element('div', 'label', _m('Institution'));
400 if (!empty($field['school'])) {
402 $this->out->element('div', 'field', $field['school']);
403 $this->out->element('div', 'label', _m('Degree'));
404 $this->out->element('div', 'field', $field['degree']);
405 $this->out->element('div', 'label', _m('Description'));
406 $this->out->element('div', 'field', $field['description']);
407 $this->out->element('div', 'label', _m('Start'));
410 array('class' => 'field date'),
411 date('j M Y', strtotime($field['start'])
414 $this->out->element('div', 'label', _m('End'));
417 array('class' => 'field date'),
418 date('j M Y', strtotime($field['end'])
422 $this->out->elementEnd('div');
425 protected function showEditableEducation($name, $field)
427 $index = isset($field['index']) ? $field['index'] : 0;
428 $id = "extprofile-$name-$index";
429 $this->out->elementStart(
431 'id' => $id . '-edit',
432 'class' => 'education-item'
435 $this->out->element('div', 'label', _m('Institution'));
439 isset($field['school']) ? $field['school'] : null
442 $this->out->element('div', 'label', _m('Degree'));
446 isset($field['degree']) ? $field['degree'] : null
449 $this->out->element('div', 'label', _m('Description'));
451 $this->out->textarea(
452 $id . '-description',
454 isset($field['description']) ? $field['description'] : null
457 $this->out->element('div', 'label', _m('Start'));
461 isset($field['start']) ? date('j M Y', strtotime($field['start'])) : null
464 $this->out->element('div', 'label', _m('End'));
468 isset($field['end']) ? date('j M Y', strtotime($field['end'])) : null
471 $this->showMultiControls();
472 $this->out->elementEnd('div');
475 function showMultiControls()
480 'class' => 'remove_row',
481 'href' => 'javascript://',
482 'style' => 'display: none;'
490 'class' => 'add_row',
491 'href' => 'javascript://',
492 'style' => 'display: none;'
499 * Outputs the value of a field
501 * @param string $name name of the field
502 * @param array $field set of key/value pairs for the field
504 protected function showFieldValue($name, $field)
506 $type = strval(@$field['type']);
513 $this->out->text($this->ext->getTextValue($name));
516 $value = $this->ext->getDateValue($name);
517 if (!empty($value)) {
520 array('class' => 'field date'),
521 date('j M Y', strtotime($value))
526 $this->out->text($this->ext->getTextValue($name));
529 $this->out->text($this->ext->getTags());
532 $this->showPhone($name, $field);
535 $this->showWebsite($name, $field);
538 $this->showIm($name, $field);
541 $this->showExperience($name, $field);
544 $this->showEducation($name, $field);
547 $this->out->text("TYPE: $type");
552 * Show an editable version of the field
554 * @param string $name name fo the field
555 * @param array $field array of key/value pairs for the field
557 protected function showEditableField($name, $field)
561 $type = strval(@$field['type']);
562 $id = "extprofile-" . $name;
564 $value = 'placeholder';
569 $out->input($id, null, $this->ext->getTextValue($name));
572 $value = $this->ext->getDateValue($name);
576 empty($value) ? null : date('j M Y', strtotime($value))
580 $out->input($id, null, $this->ext->getTextValue($name));
583 $out->textarea($id, null, $this->ext->getTextValue($name));
586 $out->input($id, null, $this->ext->getTags());
589 $this->showEditablePhone($name, $field);
592 $this->showEditableIm($name, $field);
595 $this->showEditableWebsite($name, $field);
598 $this->showEditableExperience($name, $field);
601 $this->showEditableEducation($name, $field);
604 $out->input($id, null, "TYPE: $type");
614 function formActions()
619 'submit form_action-secondary',
628 * @return string ID of the form
633 return 'profile-details-' . $this->profile->id;
639 * @return string of the form class
644 return 'form_profile_details form_settings';
650 * @return string URL of the action
655 return common_local_url('profiledetailsettings');