]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Extended profile - make websites save
authorZach Copley <zach@status.net>
Tue, 15 Mar 2011 17:10:18 +0000 (10:10 -0700)
committerZach Copley <zach@status.net>
Tue, 15 Mar 2011 17:10:18 +0000 (10:10 -0700)
plugins/ExtendedProfile/extendedprofile.php
plugins/ExtendedProfile/extendedprofilewidget.php
plugins/ExtendedProfile/profiledetailsettingsaction.php

index 6d78ddd3d89bb280ad33c89fbd6dfcef08a80c71..673680f02704d16b766a8e1e8c24910b53460432 100644 (file)
@@ -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(
index 5d5f1b7ab9a4fbf83ff3fad4316daea95b9fea74..99d5852276e0caa52f0b55233aec2ebdb6cdcfd7 100644 (file)
@@ -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;
index baac80a482d9ff335abe438d9f83c76081f33079..235786088458491c37eecc6c3684daac27392815 100644 (file)
@@ -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: