Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
authorDan
Wed, 23 Jan 2008 12:48:22 -0500
changeset 371 dc6026376919
parent 370 b251818286b1
child 372 5bd429428101
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
includes/common.php
includes/functions.php
includes/lang.php
includes/render.php
includes/search.php
includes/sessions.php
includes/template.php
includes/wikiformat.php
install/includes/stages/finish.php
install/schemas/postgresql_stage2.sql
language/english/admin.json
language/english/core.json
language/english/tools.json
language/english/user.json
plugins/SpecialUserFuncs.php
--- a/includes/common.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/common.php	Wed Jan 23 12:48:22 2008 -0500
@@ -154,7 +154,8 @@
 // even be installed. If this connection attempt fails and it's because of a missing or corrupt config file, the
 // user will be redirected (intelligently) to install.php.
 
-@include(ENANO_ROOT . '/config.php');
+$config_file = ( defined('IN_ENANO_INSTALL') ) ? '/config.new.php' : '/config.php';
+@include(ENANO_ROOT . $config_file);
 unset($dbuser, $dbpasswd);
 if ( !isset($dbdriver) )
   $dbdriver = 'mysql';
--- a/includes/functions.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/functions.php	Wed Jan 23 12:48:22 2008 -0500
@@ -3232,7 +3232,7 @@
 {
   global $db, $session, $paths, $template, $plugins; // Common objects
   
-  $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = "' . $db->escape($lang_code) . '";');
+  $q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
   if ( !$q )
     $db->_die('functions.php - checking for language existence');
   
@@ -3242,17 +3242,27 @@
   
   $q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native) 
                          VALUES(
-                           "' . $db->escape($lang_code) . '",
-                           "' . $db->escape($lang_name_neutral) . '",
-                           "' . $db->escape($lang_name_native) . '"
+                           \'' . $db->escape($lang_code) . '\',
+                           \'' . $db->escape($lang_name_neutral) . '\',
+                           \'' . $db->escape($lang_name_native) . '\'
                          );');
   if ( !$q )
     $db->_die('functions.php - installing language');
   
-  $lang_id = $db->insert_id();
-  if ( empty($lang_id) || $lang_id == 0 )
+  if ( ENANO_DBLAYER == 'PGSQL' )
   {
-    $db->_die('functions.php - invalid returned lang_id');
+    // exception for Postgres, which doesn't support insert IDs
+    // This will cause the Language class to just load by lang code
+    // instead of by numeric ID
+    $lang_id = $lang_code;
+  }
+  else
+  {
+    $lang_id = $db->insert_id();
+    if ( empty($lang_id) || $lang_id == 0 )
+    {
+      $db->_die('functions.php - invalid returned lang_id');
+    }
   }
   
   // Do we also need to install a language file?
--- a/includes/lang.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/lang.php	Wed Jan 23 12:48:22 2008 -0500
@@ -77,7 +77,7 @@
     }
     if ( is_string($lang) )
     {
-      $sql_col = 'lang_code="' . $db->escape($lang) . '"';
+      $sql_col = 'lang_code=\'' . $db->escape($lang) . '\'';
     }
     else if ( is_int($lang) )
     {
@@ -132,7 +132,7 @@
         do
         {
           $cat =& $row['string_category'];
-          if ( !is_array($strings[$cat]) )
+          if ( !is_array(@$strings[$cat]) )
           {
             $strings[$cat] = array();
           }
--- a/includes/render.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/render.php	Wed Jan 23 12:48:22 2008 -0500
@@ -15,7 +15,7 @@
  
 class RenderMan {
   
-  function strToPageID($string)
+  public static function strToPageID($string)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     $k = array_keys($paths->nslist);
@@ -38,7 +38,7 @@
     return Array($pg, $ns);
   }
   
-  function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
+  public static function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -112,7 +112,7 @@
     return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message;
   }
   
-  function getTemplate($id, $parms)
+  public static function getTemplate($id, $parms)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
@@ -150,7 +150,7 @@
     return $text;
   }
   
-  function fetch_template_text($id)
+  public static function fetch_template_text($id)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     if(!isset($paths->pages[$paths->nslist['Template'].$id])) 
@@ -176,7 +176,7 @@
     return $text;
   }
   
-  function render($text, $wiki = 1, $smilies = true, $filter_links = true)
+  public static function render($text, $wiki = 1, $smilies = true, $filter_links = true)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     if($smilies)
@@ -194,7 +194,7 @@
     return $text;
   }
   
-  function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true)
+  public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     if($smilies)
@@ -212,7 +212,7 @@
     return $text;
   }
   
-  function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false)
+  public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     $random_id = md5( time() . mt_rand() );
@@ -278,7 +278,7 @@
     $text = process_tables($text);
     $text = RenderMan::parse_internal_links($text);
     
-    $wiki =& Text_Wiki::singleton('Mediawiki');
+    $wiki = Text_Wiki::singleton('Mediawiki');
     if($plaintext)
     {
       $wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath);
@@ -328,7 +328,7 @@
     
   }
   
-  function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
+  public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -411,7 +411,7 @@
     return $result;
   }
   
-  function destroy_javascript($message, $_php = false)
+  public static function destroy_javascript($message, $_php = false)
   {
     $message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '&lt;\\1\\2&gt;', $message);
     $message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '&lt;/\\1\\2&gt;', $message);
@@ -428,12 +428,12 @@
     return $message;
   }
   
-  function strip_php($message)
+  public static function strip_php($message)
   {
     return RenderMan::destroy_javascript($message, true);
   }
   
-  function sanitize_html($text)
+  public static function sanitize_html($text)
   {
     $text = htmlspecialchars($text);
     $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
@@ -452,7 +452,7 @@
    * @return string
    */
   
-  function parse_internal_links($text)
+  public static function parse_internal_links($text)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -506,7 +506,7 @@
    * [bar] => dolor sit amet
    */
   
-  function parse_template_vars($input)
+  public static function parse_template_vars($input)
   {
     if ( !preg_match('/^(\|[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?))*$/is', trim($input)) )
     {
@@ -573,7 +573,7 @@
    * </code>
    */
   
-  function include_templates($text)
+  public static function include_templates($text)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     // $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
@@ -612,7 +612,7 @@
    * @param string $text
    * @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN.
    */
-  function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
+  public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     $random_id = md5( time() . mt_rand() );
@@ -667,7 +667,7 @@
     return $text;
   }
   
-  function smilieyize($text, $complete_urls = false)
+  public static function smilieyize($text, $complete_urls = false)
   {
     
     $random_id = md5( time() . mt_rand() );
@@ -767,7 +767,7 @@
    * @return array key 0 is the escaped text, key 1 is the character tag
    * /
    
-  function escape_page_text($text)
+  public static function escape_page_text($text)
   {
     $char_tag = md5(microtime() . mt_rand());
     $text = str_replace("'",  "{APOS:$char_tag}",  $text);
@@ -784,7 +784,7 @@
    * @return string
    * /
    
-  function unescape_page_text($text, $char_tag)
+  public static function unescape_page_text($text, $char_tag)
   {
     $text = str_replace("{APOS:$char_tag}",  "'",  $text);
     $text = str_replace("{QUOT:$char_tag}",  '"',  $text);
@@ -799,7 +799,7 @@
    * @param $str2 string the second block of text
    * @return string
    */
-  function diff($str1, $str2)
+  public static function diff($str1, $str2)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     $str1 = explode("\n", $str1);
@@ -816,7 +816,7 @@
    * @return string
    */
   
-  function process_image_tags($text, &$taglist)
+  public static function process_image_tags($text, &$taglist)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -968,7 +968,7 @@
    * @param array The list of image tags created by RenderMan::process_image_tags()
    */
    
-  function process_imgtags_stage2($text, $taglist)
+  public static function process_imgtags_stage2($text, $taglist)
   {
     $s_delim = "\xFF";
     $f_delim = "\xFF";
--- a/includes/search.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/search.php	Wed Jan 23 12:48:22 2008 -0500
@@ -75,7 +75,7 @@
       $words = explode(' ', $letters);
       foreach($words as $c => $w)
       {
-        if(strlen($w) < 2 || in_array($w, $stopwords) || strlen($w) > 63)
+        if(strlen($w) < 2 || in_array($w, $stopwords) || strlen($w) > 63 || preg_match('/[\']{2,}/', $w))
           unset($words[$c]);
         else
           $words[$c] = $w;
--- a/includes/sessions.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/sessions.php	Wed Jan 23 12:48:22 2008 -0500
@@ -1201,7 +1201,7 @@
     $salt = $db->escape($keydata[3]);
     // using a normal call to $db->sql_query to avoid failing on errors here
     $query = $db->sql_query('SELECT u.user_id AS uid,u.username,u.password,u.email,u.real_name,u.user_level,u.theme,u.style,u.signature,' . "\n"
-                             . '    u.reg_time,u.account_active,u.activation_key,k.source_ip,k.time,k.auth_level,COUNT(p.message_id) AS num_pms,' . "\n"
+                             . '    u.reg_time,u.account_active,u.activation_key,u.user_lang,k.source_ip,k.time,k.auth_level,COUNT(p.message_id) AS num_pms,' . "\n"
                              . '    x.* FROM '.table_prefix.'session_keys AS k' . "\n"
                              . '  LEFT JOIN '.table_prefix.'users AS u' . "\n"
                              . '    ON ( u.user_id=k.user_id )' . "\n"
@@ -1211,7 +1211,7 @@
                              . '    ON ( p.message_to=u.username AND p.message_read=0 )' . "\n"
                              . '  WHERE k.session_key=\''.$keyhash.'\'' . "\n"
                              . '    AND k.salt=\''.$salt.'\'' . "\n"
-                             . '  GROUP BY u.user_id,u.username,u.password,u.email,u.real_name,u.user_level,u.theme,u.style,u.signature,u.reg_time,u.account_active,u.activation_key,k.source_ip,k.time,k.auth_level,x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;');
+                             . '  GROUP BY u.user_id,u.username,u.password,u.email,u.real_name,u.user_level,u.theme,u.style,u.signature,u.reg_time,u.account_active,u.activation_key,u.user_lang,k.source_ip,k.time,k.auth_level,x.user_id, x.user_aim, x.user_yahoo, x.user_msn, x.user_xmpp, x.user_homepage, x.user_location, x.user_job, x.user_hobbies, x.email_public;');
     
     if ( !$query )
     {
@@ -1727,7 +1727,7 @@
         $str .= '_realname';
       }
       
-      return $lang->get($r);
+      return $lang->get($str);
     }
     
     // Is the password strong enough?
--- a/includes/template.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/template.php	Wed Jan 23 12:48:22 2008 -0500
@@ -42,7 +42,7 @@
     $this->theme_loaded = false;
     
     $this->fading_button = '<div style="background-image: url('.scriptPath.'/images/about-powered-enano-hover.png); background-repeat: no-repeat; width: 88px; height: 31px; margin: 0 auto 5px auto;">
-                              <a href="http://enanocms.org/" onclick="window.open(this.href); return false;"><img style="border-width: 0;" alt=" " src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
+                              <a style="background-image: none; padding-right: 0;" href="http://enanocms.org/" onclick="window.open(this.href); return false;"><img style="border-width: 0;" alt=" " src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
                             </div>';
     
     $this->theme_list = Array();
--- a/includes/wikiformat.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/includes/wikiformat.php	Wed Jan 23 12:48:22 2008 -0500
@@ -119,11 +119,11 @@
 
     }
 
-    function &singleton($parser = 'Default', $rules = null)
+    public static function singleton($parser = 'Default', $rules = null)
     {
         static $only = array();
         if (!isset($only[$parser])) {
-            $ret =& Text_Wiki::factory($parser, $rules);
+            $ret = Text_Wiki::factory($parser, $rules);
             if (!$ret) {
                 return $ret;
             }
@@ -132,7 +132,7 @@
         return $only[$parser];
     }
 
-    function &factory($parser = 'Default', $rules = null)
+    public static function factory($parser = 'Default', $rules = null)
     {
         $d=getcwd();
         chdir(ENANO_ROOT);
@@ -613,7 +613,7 @@
 
     function isError(&$obj)
     {
-        return is_a($obj, 'PEAR_Error');
+        return ( @get_class($obj) == 'PEAR_Error' );
     }
 }
 
--- a/install/includes/stages/finish.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/install/includes/stages/finish.php	Wed Jan 23 12:48:22 2008 -0500
@@ -29,9 +29,6 @@
   return true;
 }
 
-$db = new $dbdriver();
-$db->connect();
-
 $ui->show_header();
 flush();
 
--- a/install/schemas/postgresql_stage2.sql	Tue Jan 22 01:08:15 2008 -0500
+++ b/install/schemas/postgresql_stage2.sql	Wed Jan 23 12:48:22 2008 -0500
@@ -104,7 +104,7 @@
   user_has_avatar smallint NOT NULL,
   avatar_type varchar(3) NOT NULL,
   user_registration_ip varchar(39),
-  CHECK (user_has_avatar IN ('jpg', 'png', 'gif')),
+  CHECK (avatar_type IN ('jpg', 'png', 'gif')),
   PRIMARY KEY  (user_id)
 );
 
@@ -318,9 +318,9 @@
   ('oxygen', 'Oxygen', 1, 'bleu.css', 1),
   ('stpatty', 'St. Patty', 2, 'shamrock.css', 1);
 
-INSERT INTO {{TABLE_PREFIX}}users(user_id, username, password, email, real_name, user_level, theme, style, signature, reg_time, account_active, user_registration_ip) VALUES
-  (1, 'Anonymous', 'invalid-pass-hash', 'anonspam@enanocms.org', 'None', 1, 'oxygen', 'bleu', '', 0, 0),
-  (2, '{{ADMIN_USER}}', '{{ADMIN_PASS}}', '{{ADMIN_EMAIL}}', '{{REAL_NAME}}', 9, 'oxygen', 'bleu', '', {{UNIX_TIME}}, 1, '{{IP_ADDRESS}}');
+INSERT INTO {{TABLE_PREFIX}}users(user_id, username, password, email, real_name, user_level, theme, style, signature, reg_time, account_active, user_registration_ip, user_lang, user_has_avatar, avatar_type) VALUES
+  (1, 'Anonymous', 'invalid-pass-hash', 'anonspam@enanocms.org', 'None', 1, 'oxygen', 'bleu', '', 0, 0, '', 0, 0, 'png'),
+  (2, '{{ADMIN_USER}}', '{{ADMIN_PASS}}', '{{ADMIN_EMAIL}}', '{{REAL_NAME}}', 9, 'oxygen', 'bleu', '', {{UNIX_TIME}}, 1, '{{IP_ADDRESS}}', 0, 0, 'png');
   
 INSERT INTO {{TABLE_PREFIX}}users_extra(user_id) VALUES
   (2);
--- a/language/english/admin.json	Tue Jan 22 01:08:15 2008 -0500
+++ b/language/english/admin.json	Wed Jan 23 12:48:22 2008 -0500
@@ -12,7 +12,7 @@
 
 var enano_lang = {
   categories: [
-    'adm', 'acl', 'adminusers',
+    'meta', 'adm', 'acl', 'adminusers',
     'acphome', 'acpgc', 'acpup', 'acpft', 'acppl', 'acppm', 'acped', 'acpdb', 'acppg', 'acpum', 'acpug', 'acpcp', 'acpmm', 'acpsl', 'acpbc',
     'acplo', 'sbedit',
   ],
--- a/language/english/core.json	Tue Jan 22 01:08:15 2008 -0500
+++ b/language/english/core.json	Wed Jan 23 12:48:22 2008 -0500
@@ -17,7 +17,7 @@
 
 var enano_lang = {
   categories: [
-    'page', 'comment', 'onpage', 'etc', 'editor', 'history', 'catedit', 'tags', 'delvote', 'ajax', 'sidebar', 'perm', 'plugin', 'paginate', 'upload',
+    'meta', 'page', 'comment', 'onpage', 'etc', 'editor', 'history', 'catedit', 'tags', 'delvote', 'ajax', 'sidebar', 'perm', 'plugin', 'paginate', 'upload',
   ],
   strings: {
     meta: {
@@ -45,6 +45,7 @@
       enano_about_lbl_serverplatform: 'Server platform:',
       enano_about_lbl_phpversion: '<a href="http://www.php.net/">PHP</a> version:',
       enano_about_lbl_mysqlversion: '<a href="http://www.mysql.com/">MySQL</a> version:',
+      enano_about_lbl_pgsqlversion: '<a href="http://www.postgresql.org/">PostgreSQL</a> version:',
     },
     page: {
       protect_lbl_success_title: 'Page protected',
--- a/language/english/tools.json	Tue Jan 22 01:08:15 2008 -0500
+++ b/language/english/tools.json	Wed Jan 23 12:48:22 2008 -0500
@@ -12,7 +12,7 @@
 
 var enano_lang = {
   categories: [
-    'search', 'specialpage', 'pagetools'
+    'meta', 'search', 'specialpage', 'pagetools'
   ],
   strings: {
     meta: {
--- a/language/english/user.json	Tue Jan 22 01:08:15 2008 -0500
+++ b/language/english/user.json	Wed Jan 23 12:48:22 2008 -0500
@@ -12,7 +12,7 @@
 
 var enano_lang = {
   categories: [
-    'user', 'usercp', 'groupcp', 'privmsgs', 'userfuncs', 'userpage',
+    'meta', 'user', 'usercp', 'groupcp', 'privmsgs', 'userfuncs', 'userpage',
   ],
   strings: {
     meta: {
--- a/plugins/SpecialUserFuncs.php	Tue Jan 22 01:08:15 2008 -0500
+++ b/plugins/SpecialUserFuncs.php	Wed Jan 23 12:48:22 2008 -0500
@@ -752,7 +752,7 @@
                 </div>
                 <p style="text-align: center;">
                   <label>
-                    <input type="checkbox" name="tou_agreed" />
+                    <input tabindex="7" type="checkbox" name="tou_agreed" />
                     <b><?php echo $lang->get('user_reg_lbl_field_tou'); ?></b>
                   </label>
                 </p>
@@ -766,7 +766,7 @@
             <!-- FIELD: submit button -->
             <tr>
               <th class="subhead" colspan="3" style="text-align: center;">
-                <input tabindex="7" type="submit" name="submit" value="<?php echo $lang->get('user_reg_btn_create_account'); ?>" />
+                <input tabindex="8" type="submit" name="submit" value="<?php echo $lang->get('user_reg_btn_create_account'); ?>" />
               </td>
             </tr>