diff --git a/plugins/ExtendedProfile/extendedprofile.php b/plugins/ExtendedProfile/extendedprofile.php index 6d78ddd3d8..673680f027 100644 --- a/plugins/ExtendedProfile/extendedprofile.php +++ b/plugins/ExtendedProfile/extendedprofile.php @@ -98,6 +98,8 @@ class ExtendedProfile } } + // XXX: getPhones, getIms, and getWebsites pretty much do the same thing, + // so refactor. function getPhones() { $phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null; @@ -155,6 +157,32 @@ class ExtendedProfile return $iArrays; } + function getWebsites() + { + $sites = (isset($this->fields['website'])) ? $this->fields['website'] : null; + $wArrays = array(); + + if (empty($sites)) { + $wArrays[] = array( + 'label' => _m('Website'), + 'type' => 'website' + ); + } else { + for ($i = 0; $i < sizeof($sites); $i++) { + $wa = array( + 'label' => _m('Website'), + 'type' => 'website', + 'index' => intval($sites[$i]->value_index), + 'rel' => $sites[$i]->rel, + 'value' => $sites[$i]->field_value, + ); + + $wArrays[] = $wa; + } + } + return $wArrays; + } + function getExperiences() { $companies = (isset($this->fields['company'])) ? $this->fields['company'] : null; @@ -273,13 +301,9 @@ class ExtendedProfile 'contact' => array( 'label' => _m('Contact'), 'fields' => array( - 'phone' => $this->getPhones(), - 'im' => $this->getIms(), - 'website' => array( - 'label' => _m('Websites'), - 'type' => 'website', - 'multi' => true, - ), + 'phone' => $this->getPhones(), + 'im' => $this->getIms(), + 'website' => $this->getWebsites() ), ), 'personal' => array( diff --git a/plugins/ExtendedProfile/extendedprofilewidget.php b/plugins/ExtendedProfile/extendedprofilewidget.php index 5d5f1b7ab9..99d5852276 100644 --- a/plugins/ExtendedProfile/extendedprofilewidget.php +++ b/plugins/ExtendedProfile/extendedprofilewidget.php @@ -107,6 +107,7 @@ class ExtendedProfileWidget extends Form switch($fieldName) { case 'phone': case 'im': + case 'website': case 'experience': case 'education': $this->showMultiple($fieldName, $field); @@ -147,6 +148,8 @@ class ExtendedProfileWidget extends Form } } + // XXX: showPhone, showIm and showWebsite all work the same, so + // combine protected function showPhone($name, $field) { $this->out->elementStart('div', array('class' => 'phone-display')); @@ -167,6 +170,16 @@ class ExtendedProfileWidget extends Form $this->out->elementEnd('div'); } + protected function showWebsite($name, $field) + { + $this->out->elementStart('div', array('class' => 'website-display')); + $this->out->text($field['value']); + if (!empty($field['rel'])) { + $this->out->text(' (' . $field['rel'] . ')'); + } + $this->out->elementEnd('div'); + } + protected function showEditableIm($name, $field) { $index = isset($field['index']) ? $field['index'] : 0; @@ -239,6 +252,44 @@ class ExtendedProfileWidget extends Form $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-edit' + ) + ); + $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'); @@ -421,6 +472,9 @@ class ExtendedProfileWidget extends Form case 'phone': $this->showPhone($name, $field); break; + case 'website': + $this->showWebsite($name, $field); + break; case 'im': $this->showIm($name, $field); break; @@ -467,6 +521,9 @@ class ExtendedProfileWidget extends Form case 'im': $this->showEditableIm($name, $field); break; + case 'website': + $this->showEditableWebsite($name, $field); + break; case 'experience': $this->showEditableExperience($name, $field); break; diff --git a/plugins/ExtendedProfile/profiledetailsettingsaction.php b/plugins/ExtendedProfile/profiledetailsettingsaction.php index baac80a482..2357860884 100644 --- a/plugins/ExtendedProfile/profiledetailsettingsaction.php +++ b/plugins/ExtendedProfile/profiledetailsettingsaction.php @@ -110,6 +110,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction $this->savePhoneNumbers($user); $this->saveIms($user); + $this->saveWebsites($user); $this->saveExperiences($user); $this->saveEducations($user); @@ -198,6 +199,42 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction } } + function findWebsites() { + + // Form vals look like this: + + $sites = $this->sliceParams('website', 2); + $wsArray = array(); + + foreach ($sites as $site) { + list($id, $rel) = array_values($site); + $wsArray[] = array( + 'value' => $id, + 'rel' => $rel + ); + } + + return $wsArray; + } + + function saveWebsites($user) { + $sites = $this->findWebsites(); + $this->removeAll($user, 'website'); + $i = 0; + foreach($sites as $site) { + if (!empty($site['value'])) { + ++$i; + $this->saveField( + $user, + 'website', + $site['value'], + $site['rel'], + $i + ); + } + } + } + function findExperiences() { // Form vals look like this: