Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
authorDan
Thu, 28 Jun 2007 15:26:40 -0400
changeset 31 dc8741857bde
parent 30 7e8fd44b36b0
child 32 4d87aad3c4c0
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
TODO
includes/pageprocess.php
includes/sessions.php
plugins/SpecialUserPrefs.php
upgrade.php
--- a/TODO	Thu Jun 28 13:49:40 2007 -0400
+++ b/TODO	Thu Jun 28 15:26:40 2007 -0400
@@ -1,7 +1,7 @@
 Enano Banshee - TODO
 ------------------------------------------
 
-[ ] COPPA compliance
+[x] COPPA compliance
 [x] Add in Moderators group
     [x] Create default ACL rule for mods
 [x] Fix invalid HTML in SF.net logo
@@ -15,9 +15,10 @@
 [x] SQL exporter: fix structure exporting when an auto column is defined
     and it's a named key (see pun_search_words)
 [x] Possibly add these fields: AIM, Yahoo, MSN, XMPP messenger icons, then homepage, location, occupation, hobbies, allow public e-mail display
-    [ ] Put it in a user_extra table and have an option to enable or disable these fields in the admin panel
+    [x] Put it in a user_extra table [XX NO!! and have an option to enable or disable these fields in the admin panel XX]
     [Y] Delay until RC3 or Banshee?
     [x] When added, put a box on the user page that shows the information
+    [x] Fields on user's preferences page
 [x] Fix "this page" bug in ACL editor
     [x] The problem itself got fixed BUT there seem to be deeper problems related to scope selection
         This needs to be FIXED and WORKING PERFECTLY in Banshee!
@@ -27,8 +28,8 @@
 [x] Register users_extra table in system tables list (already done?)
 [x] Trigger form submit on press of enter in Dynano login form
 [x] Rewrite the change theme dialog - it's archaic code that hasn't changed since beta 1!
-    [ ] Come up with some alternative to the "formatting help" link for 1.1
-        [ ] By 1.1, all JWS code should be phased out and removed!
+    [] Come up with some alternative to the "formatting help" link (**IN 1.1**)
+       [] By 1.1, all JWS code should be phased out and removed!
 [ ] Get the new page ID cleaner code working 100% perfectly - this is the core of Enano and should be completely bug free
 
 
--- a/includes/pageprocess.php	Thu Jun 28 13:49:40 2007 -0400
+++ b/includes/pageprocess.php	Thu Jun 28 15:26:40 2007 -0400
@@ -560,7 +560,7 @@
     
     if ( !empty($userdata['real_name']) )
     {
-      echo '<tr><td class="row3">Real name: ' . htmlspecialchars($userdata['real_name']) . '</td></tr>';
+      echo '<tr><td class="row3">Real name: ' . $userdata['real_name'] . '</td></tr>';
     }
     
     // Comments
--- a/includes/sessions.php	Thu Jun 28 13:49:40 2007 -0400
+++ b/includes/sessions.php	Thu Jun 28 15:26:40 2007 -0400
@@ -71,6 +71,13 @@
   var $email;
   
   /**
+   * List of "extra" user information fields (IM handles, etc.)
+   * @var array (associative)
+   */
+  
+  var $user_extra;
+  
+  /**
    * User level of current user
    * USER_LEVEL_GUEST: guest
    * USER_LEVEL_MEMBER: regular user
@@ -942,6 +949,15 @@
       $this->sql('UPDATE '.table_prefix.'session_keys SET time='.time().' WHERE session_key=\''.$keyhash.'\';');
     }
     
+    $user_extra = array();
+    foreach ( array('user_aim', 'user_yahoo', 'user_msn', 'user_xmpp', 'user_homepage', 'user_location', 'user_job', 'user_hobbies', 'email_public') as $column )
+    {
+      $user_extra[$column] = $row[$column];
+    }
+    
+    $this->user_extra = $user_extra;
+    // Leave the rest to PHP's automatic garbage collector ;-)
+    
     $row['password'] = md5($real_pass);
     return $row;
   }
@@ -1353,6 +1369,17 @@
     // We good, create the user
     $this->sql('INSERT INTO '.table_prefix.'users ( username, password, email, real_name, theme, style, reg_time, account_active, activation_key, user_level, user_coppa ) VALUES ( \''.$username.'\', \''.$password.'\', \''.$email.'\', \''.$real_name.'\', \''.$template->default_theme.'\', \''.$template->default_style.'\', '.time().', '.$active.', \''.$actkey.'\', '.USER_LEVEL_CHPREF.', ' . $coppa_col . ' );');
     
+    // Get user ID and create users_extra entry
+    $q = $this->sql('SELECT user_id FROM '.table_prefix."users WHERE username='$username';");
+    if ( $db->numrows() > 0 )
+    {
+      $row = $db->fetchrow();
+      $db->free_result();
+      
+      $user_id =& $row['user_id'];
+      $this->sql('INSERT INTO '.table_prefix.'user_extra(user_id) VALUES(' . $user_id . ');');
+    }
+    
     // Require the account to be activated?
     if ( $coppa )
     {
--- a/plugins/SpecialUserPrefs.php	Thu Jun 28 13:49:40 2007 -0400
+++ b/plugins/SpecialUserPrefs.php	Thu Jun 28 15:26:40 2007 -0400
@@ -403,10 +403,72 @@
       {
         $real_name = htmlspecialchars($_POST['real_name']);
         $real_name = $db->escape($real_name);
+        
+        $imaddr_aim = htmlspecialchars($_POST['imaddr_aim']);
+        $imaddr_aim = $db->escape($imaddr_aim);
+        
+        $imaddr_msn = htmlspecialchars($_POST['imaddr_msn']);
+        $imaddr_msn = $db->escape($imaddr_msn);
+        
+        $imaddr_yahoo = htmlspecialchars($_POST['imaddr_yahoo']);
+        $imaddr_yahoo = $db->escape($imaddr_yahoo);
+        
+        $imaddr_xmpp = htmlspecialchars($_POST['imaddr_xmpp']);
+        $imaddr_xmpp = $db->escape($imaddr_xmpp);
+        
+        $homepage = htmlspecialchars($_POST['homepage']);
+        $homepage = $db->escape($homepage);
+        
+        $location = htmlspecialchars($_POST['location']);
+        $location = $db->escape($location);
+        
+        $occupation = htmlspecialchars($_POST['occupation']);
+        $occupation = $db->escape($occupation);
+        
+        $hobbies = htmlspecialchars($_POST['hobbies']);
+        $hobbies = $db->escape($hobbies);
+        
+        $email_public = ( isset($_POST['email_public']) ) ? '1' : '0';
+        
+        $session->real_name = $real_name;
+        
+        if ( !preg_match('/@([a-z0-9-]+)(\.([a-z0-9-\.]+))?/', $imaddr_msn) )
+        {
+          $imaddr_msn = "$imaddr_msn@hotmail.com";
+        }
+        
+        if ( substr($homepage, 0, 7) != 'http://' )
+        {
+          $homepage = "http://$homepage";
+        }
+        
+        if ( !preg_match('/^http:\/\/([a-z0-9-.]+)([A-z0-9@#\$%\&:;<>,\.\?=\+\(\)\[\]_\/\\\\]*?)$/i', $homepage) )
+        {
+          $homepage = '';
+        }
+        
+        $session->user_extra['user_aim'] = $imaddr_aim;
+        $session->user_extra['user_msn'] = $imaddr_msn;
+        $session->user_extra['user_xmpp'] = $imaddr_xmpp;
+        $session->user_extra['user_yahoo'] = $imaddr_yahoo;
+        $session->user_extra['user_homepage'] = $homepage;
+        $session->user_extra['user_location'] = $location;
+        $session->user_extra['user_job'] = $occupation;
+        $session->user_extra['user_hobbies'] = $hobbies;
+        $session->user_extra['email_public'] = intval($email_public);
+        
         $q = $db->sql_query('UPDATE '.table_prefix."users SET real_name='$real_name' WHERE user_id=$session->user_id;");
         if ( !$q )
           $db->_die();
         
+        $q = $db->sql_query('UPDATE '.table_prefix."users_extra SET user_aim='$imaddr_aim',user_yahoo='$imaddr_yahoo',user_msn='$imaddr_msn',
+                               user_xmpp='$imaddr_xmpp',user_homepage='$homepage',user_location='$location',user_job='$occupation',
+                               user_hobbies='$hobbies',email_public=$email_public
+                               WHERE user_id=$session->user_id;");
+        
+        if ( !$q )
+          $db->_die();
+        
         echo '<div class="info-box" style="margin: 0 0 10px 0;">Your profile has been updated.</div>';
       }
       echo '<form action="'.makeUrl($paths->fullpage).'" method="post">';
@@ -428,7 +490,49 @@
             <td class="row1">If you don't like the look of the site, need a visual break, or are just curious, we might have some different themes for you to try out! <a href="<?php echo makeUrlNS('Special', 'ChangeStyle/' . $paths->page); ?>" onclick="ajaxChangeStyle(); return false;">Change my theme...</a></td>
           </tr>
           <tr>
-            <td colspan="2" class="row3"><small>More is coming soon - planned fields include AOL, WLM, Yahoo, and XMPP messenger fields, allow public display of e-mail address, allow private messages from users not on your buddy list, homepage, occupation, and location.</small></td>
+            <th class="subhead" colspan="2">
+              Instant messenger contact information
+            </th>
+          <tr>
+            <td class="row2" style="width: 50%;">AIM handle:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="imaddr_aim" value="<?php echo $session->user_extra['user_aim']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;"><acronym title="Windows&trade; Live Messenger">WLM</acronym> handle:<br /><small>If you don't specify the domain (@whatever.com), "@hotmail.com" will be assumed.</small></td>
+            <td class="row1" style="width: 50%;"><input type="text" name="imaddr_msn" value="<?php echo $session->user_extra['user_msn']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Yahoo! IM handle:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="imaddr_yahoo" value="<?php echo $session->user_extra['user_yahoo']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Jabber/XMPP handle:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="imaddr_xmpp" value="<?php echo $session->user_extra['user_xmpp']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <th class="subhead" colspan="2">
+              Extra contact information
+            </th>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Your homepage:<br /><small>Please remember the http:// prefix.</small></td>
+            <td class="row1" style="width: 50%;"><input type="text" name="homepage" value="<?php echo $session->user_extra['user_homepage']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Your location:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="location" value="<?php echo $session->user_extra['user_location']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Your job:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="occupation" value="<?php echo $session->user_extra['user_job']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;">Your hobbies:</td>
+            <td class="row1" style="width: 50%;"><input type="text" name="hobbies" value="<?php echo $session->user_extra['user_hobbies']; ?>" size="30" /></td>
+          </tr>
+          <tr>
+            <td class="row2" style="width: 50%;"><label for="chk_email_public">E-mail address is public</label><br /><small>If this is checked, your e-mail address will be displayed on your user page. To protect your address from spambots, your e-mail address will be encrypted.</small></td>
+            <td class="row1" style="width: 50%;"><input type="checkbox" id="chk_email_public" name="email_public" value="<?php if ($session->user_extra['email_public'] == 1) echo 'checked="checked"'; ?>" size="30" /></td>
           </tr>
           <tr>
             <th class="subhead" colspan="2">
--- a/upgrade.php	Thu Jun 28 13:49:40 2007 -0400
+++ b/upgrade.php	Thu Jun 28 15:26:40 2007 -0400
@@ -76,8 +76,9 @@
   );
 $this_version   = '1.0';
 $func_list = Array(
-    '1.0b4' => Array('u_1_0_RC1_update_user_ids', 'u_1_0_RC1_add_admins_to_group', 'u_1_0_RC1_alter_files_table', 'u_1_0_RC1_destroy_session_cookie', 'u_1_0_RC1_set_contact_email', 'u_1_0_RC1_update_page_text') // ,
+    '1.0b4' => Array('u_1_0_RC1_update_user_ids', 'u_1_0_RC1_add_admins_to_group', 'u_1_0_RC1_alter_files_table', 'u_1_0_RC1_destroy_session_cookie', 'u_1_0_RC1_set_contact_email', 'u_1_0_RC1_update_page_text'), // ,
     // '1.0RC2' => Array('u_1_0_populate_userpage_comments')
+    '1.0RC3' => Array('u_1_0_RC3_make_users_extra')
   );
 
 if(!isset($_GET['mode'])) 
@@ -368,6 +369,26 @@
   */
 }
 
+function u_1_0_RC3_make_users_extra()
+{
+  global $db;
+  $q = $db->sql_query('SELECT user_id FROM users WHERE user_id > 1;');
+  if ( !$q )
+    $db->_die();
+  
+  $ids = array();
+  while ( $row = $db->fetchrow() )
+  {
+    $ids[] = intval($row['user_id']);
+  }
+  
+  $ids = '(' . implode('),(', $ids) . ')';
+  $sql = "INSERT INTO " . table_prefix . "users_extra(user_id) VALUES$ids;";
+  
+  if ( !$db->sql_query($sql) )
+    $db->_die();
+}
+
 switch($_GET['mode'])
 {
   case "login":