WordPress.org

Make WordPress Core

Ticket #2317: sqlite+wordpress.2.0.2-2.diff

File sqlite+wordpress.2.0.2-2.diff, 30.1 KB (added by havarddahle, 12 years ago)

Second patch. Code cleanup and syntactic errors removed.

  • wp-admin/admin-db.php

    diff -wruBN wordpress-2.0.2/wp-admin/admin-db.php wordpress-2.0.2lite/wp-admin/admin-db.php
    old new  
    106106                $category_parent = 0;
    107107
    108108        if (!$update) {
    109                 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent')");
     109                $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('1', '$cat_name', '$category_nicename', '$category_description', '$category_parent')");
    110110                $cat_ID = $wpdb->insert_id;
    111111        } else {
    112112                $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'");
  • wp-admin/admin-functions.php

    diff -wruBN wordpress-2.0.2/wp-admin/admin-functions.php wordpress-2.0.2lite/wp-admin/admin-functions.php
    old new  
    12541254                return $title;
    12551255        }
    12561256
    1257         $hook = get_plugin_page_hook($plugin_page, $pagenow);
    1258 
    1259         $parent = $parent1 = get_admin_page_parent();
     1257        $parent = get_admin_page_parent();
    12601258        if (empty ($parent)) {
    12611259                foreach ($menu as $menu_array) {
    12621260                        if (isset ($menu_array[3])) {
     
    12641262                                        $title = $menu_array[3];
    12651263                                        return $menu_array[3];
    12661264                                } else
    1267                                         if (isset ($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) {
     1265                                        if (isset ($plugin_page) && ($plugin_page == $menu_array[2])) {
    12681266                                                $title = $menu_array[3];
    12691267                                                return $menu_array[3];
    12701268                                        }
     
    12781276                                                $title = $submenu_array[3];
    12791277                                                return $submenu_array[3];
    12801278                                        } else
    1281                                                 if (isset ($plugin_page) && ($plugin_page == $submenu_array[2]) && (($parent == $pagenow) || ($parent == $plugin_page) || ($plugin_page == $hook) || (($pagenow == 'admin.php') && ($parent1 != $submenu_array[2])))) {
     1279                                                if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) {
    12821280                                                        $title = $submenu_array[3];
    12831281                                                        return $submenu_array[3];
    12841282                                                }
     
    17271725                return $upload_error_handler($file, __('File is empty. Please upload something more substantial.'));
    17281726
    17291727        // A properly uploaded file will pass this test. There should be no reason to override this one.
    1730         if (! @ is_uploaded_file($file['tmp_name']) )
     1728        if (! is_uploaded_file($file['tmp_name']) )
    17311729                return $upload_error_handler($file, __('Specified file failed upload test.'));
    17321730
    17331731        // A correct MIME type will pass this test.
     
    17711769
    17721770        // Move the file to the uploads dir
    17731771        $new_file = $uploads['path'] . "/$filename";
    1774         if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) )
     1772        if ( false === move_uploaded_file($file['tmp_name'], $new_file) )
    17751773                die(printf(__('The uploaded file could not be moved to %s.'), $file['path']));
    17761774
    17771775        // Set correct file permissions
  • wp-admin/install.php

    diff -wruBN wordpress-2.0.2/wp-admin/install.php wordpress-2.0.2lite/wp-admin/install.php
    old new  
    156160$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 1, 'http://dougal.gunters.org/feed/', '');");
    157161
    158162// Default category
    159 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
     163$wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('1', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
    160164
    161165// First post
    162166$now = date('Y-m-d H:i:s');
    163167$now_gmt = gmdate('Y-m-d H:i:s');
    164168$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");
    165169
    166 $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
    167 
    168170// Default comment
    169171$wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.'))."')");
    170172
     
    182184$admin_caps = serialize(array('administrator' => true));
    183185$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}capabilities', '{$admin_caps}');");
    184186
     187
     188$wpdb->query( "INSERT INTO $wpdb->post2cat (rel_id, post_id, category_id) VALUES (1, 1, 1)" );
     189
    185190$message_headers = 'From: ' . $weblog_title . ' <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
    186191$message = sprintf(__("Your new WordPress blog has been successfully set up at:
    187192
  • wp-config-sample.php

    diff -wruBN wordpress-2.0.2/wp-config-sample.php wordpress-2.0.2lite/wp-config-sample.php
    old new  
    11<?php
    22// ** MySQL settings ** //
    3 define('DB_NAME', 'wordpress');    // The name of the database
     3define('DB_NAME', 'wordpress.db');    // The name of the database
    44define('DB_USER', 'username');     // Your MySQL username
    55define('DB_PASSWORD', 'password'); // ...and password
    66define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
    77
     8// ** SQLite settings ** //
     9
     10// SQLite in three easy steps
     11// 1. Fill in DB_NAME above
     12// 2. Fill in DB_PATH below to a directory that is NB! NB! _writeable_ by the web server
     13// 3. Ensure that USE_SQLITE is 1
     14
     15define('USE_SQLITE', 1);
     16define('DB_PATH', '/home/havard/dev/blogg/db/'); // Writeable by the web server
     17
     18
    819// You can have multiple installations in one database if you give each a unique prefix
    920$table_prefix  = 'wp_';   // Only numbers, letters, and underscores please!
    1021
  • wp-includes/comment-functions.php

    diff -wruBN wordpress-2.0.2/wp-includes/comment-functions.php wordpress-2.0.2lite/wp-includes/comment-functions.php
    old new  
    296296       
    297297        if (! is_single() && ! is_page()) {
    298298        if ( !isset($comment_count_cache[$id]) )
    299                 $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
     299                $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = '$id' AND comment_approved = '1';");
    300300       
    301301        $number = $comment_count_cache[$id];
    302302       
  • wp-includes/wp-sqlite.php

    diff -wruBN wordpress-2.0.2/wp-includes/wp-sqlite.php wordpress-2.0.2lite/wp-includes/wp-sqlite.php
    old new  
     1<?php
    02
     3
    14
     5//  ORIGINAL CODE FROM:
     6//  Justin Vincent (justin@visunet.ie)
     7//      http://php.justinvincent.com
     8
    29
     10
    311
     12# I don't know anything about EZSQL versioning, but since I've added a
     13# helper function, thus changing the api, I'm modifying the version string.
     14# I'm adding an 'x'. Advanced.
     15# havard@dahle.no 2006-03-13
     16define("EZSQL_VERSION","1.26x");
    417
     18define("OBJECT","OBJECT",true);
    519
     20define("ARRAY_A","ARRAY_A",true);
    621
     22define("ARRAY_N","ARRAY_N",true);
    723
     24
     25if (!defined('SAVEQUERIES'))
     26        define('SAVEQUERIES', false);
    827
     28
    929
     30        // ==================================================================
    1031
     32        //      The Main Class
    1133
     34
    1235
     36class wpdb {
    1337
     38
    1439
     40        var $show_errors = true;
     41        var $num_queries = 0;   
     42        var $last_query;
     43        var $col_info;
     44        var $queries;
     45
     46        // Our tables
     47        var $posts;
     48        var $users;
     49        var $categories;
     50        var $post2cat;
     51        var $comments;
     52        var $links;
     53        var $linkcategories;
     54        var $options;
     55        var $optiontypes;
     56        var $optionvalues;
     57        var $optiongroups;
     58        var $optiongroup_options;
     59        var $postmeta;
    1560
     61               
    1662
     63        // ==================================================================
    1764
     65        //      DB Constructor - connects to the server and selects a database
    1866
     67
    1968
     69        function wpdb($dbpath, $dbname) {
    2070
     71                $this->dbh = sqlite_open($dbpath.$dbname);
    2172
     73                if ( ! $this->dbh ) {
    2274
     75            $reason = $this->db_error_string();
     76                        $this->print_error("<ol><b>Error establishing a database! [{$reason}]</b><li>Are you sure that the web
     77            server has write access to the SQLite database at <em>'{$dbpath}${dbname}'</em>?<li>Are you sure you have the correct path?<li>Are you sure that you have typed the correct database instance name?<li>Are you sure that the database is installed?</ol>");
    2378
     79                }
     80               
     81                sqlite_query($this->dbh, 'PRAGMA short_column_names = 1');
     82               
     83                // User defined functions to use in SQLite
     84                sqlite_create_function($this->dbh, 'trim', 'trim', 1);         
    2485
     86
    2587
     88        }
    2689
     90
    2791
     92        // ==================================================================
    2893
     94        //      Select a DB instance (if another one needs to be selected)
    2995
     96
    3097
     98        function select($dbpath, $dbname) {
    3199
     100                $this->wpdb($dbpath, $dbname);
    32101
     102        }
    33103
     104
    34105
     106        // ====================================================================
    35107
     108        //      Format a string correctly for safe insert under all PHP conditions
    36109
     110
    37111
     112        function escape($str) {
    38113
     114                return str_replace("'","''",str_replace("''","'",stripslashes($str)));
    39115
     116        }
    40117
     118
    41119
     120        // ==================================================================
    42121
     122        //      Print SQL/DB error.
    43123
     124
    44125
     126        function print_error($str = "") {
    45127
     128
    46129
     130                // All erros go to the global error array $EZSQL_ERROR..
    47131
     132                global $EZSQL_ERROR;
    48133
     134
    49135
     136                // If no error string then you're SOL
    50137
     138                if ( !$str ) {
    51139
     140                        $str = "An error occured, quick go tell someone!";
    52141
     142                }
    53143
     144
    54145
     146                // Log this error to the global array..
    55147
     148                $EZSQL_ERROR[] = array
    56149
     150                                                (
    57151
     152                                                        "query" => $this->last_query,
    58153
     154                                                        "error_str"  => $str
    59155
     156                                                );
    60157
     158
    61159
     160                // Is error output turned on or not..
    62161
     162                if ( $this->show_errors ) {
    63163
     164                        // If there is an error then take note of it
    64165
     166                        print "<div id='error'>
     167                        <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
     168                        <code>$this->last_query</code></p>
     169                        </div>";
    65170
     171                }
    66172
     173                else {
    67174
     175                        return false;
    68176
     177                }
    69178
     179        }
    70180
     181
    71182
     183        // ==================================================================
    72184
     185        //      Turn error handling on or off..
    73186
     187
    74188
     189        function show_errors() {
    75190
     191                $this->show_errors = true;
    76192
     193        }
    77194
     195
    78196
     197        function hide_errors() {
    79198
     199                $this->show_errors = false;
    80200
     201        }
    81202
     203
    82204
     205        // ==================================================================
    83206
     207        //      Kill cached query results
    84208
     209
    85210
     211        function flush() {
    86212
     213
    87214
     215                // Get rid of these
    88216
     217                $this->last_result = null;
    89218
     219                $this->col_info = null;
    90220
     221                $this->last_query = null;
    91222
     223
    92224
     225        }
    93226
     227
    94228
     229        // ==================================================================
    95230
     231        //      Basic Query     - see docs for more detail
    96232
     233
    97234
     235        function query($query) {
    98236
     237
    99238
     239                // For reg expressions
     240                $query = trim($query);
    100241
     242
    101243
     244                // Flush cached values..
    102245
     246                $this->flush();
    103247
     248               
     249                // Parse query to be used in SQLite
     250                $query = $this->parse($query);
     251
    104252
     253                // Log how the function was called
    105254
     255                $this->func_call = "\$wpdb->query(\"$query\")";
    106256
     257               
    107258
     259                // Keep track of the last query for debug..
    108260
     261                $this->last_query = $query;
     262
     263                if (SAVEQUERIES)
     264                        $this->timer_start();
    109265
     266
    110267
     268                # DEBUG: $handle = @sqlite_query($this->dbh,$query);
     269                $handle = @sqlite_query($this->dbh,$query);
     270               
     271                       
     272                if (SAVEQUERIES)
     273                        $this->queries[] = array( $query, $this->timer_stop() );
    111274
     275                       
    112276
     277                // If there was an insert, delete or update see how many rows were affected
    113278
     279                // (Also, If there there was an insert take note of the insert_id
    114280
     281                $query_type = array("insert","delete","update","replace");
    115282
     283
    116284
     285                // loop through the above array
    117286
     287                foreach ( $query_type as $word ) {
    118288
     289                        // This is true if the query starts with insert, delete or update
    119290
     291                        if ( preg_match("/^$word\s+/i",$query) ) {
    120292
     293                                $this->rows_affected = sqlite_changes($this->dbh);
    121294
     295
    122296
     297                                // This gets the insert ID
    123298
     299                                if ( $word == "insert" || $word == "replace" ) {
    124300
     301                                        $this->insert_id = sqlite_last_insert_rowid($this->dbh);
    125302
     303                                               
    126304
     305                                        // If insert id then return it - true evaluation
     306                                        return $this->insert_id;
    127307
     308                                }
    128309
     310
    129311
     312                                // Set to false if there was no insert id
     313                                $this->result = false;
    130314
     315
    131316
     317                        }
    132318
     319
    133320
     321                }
    134322
     323
    135324
     325                if ( ! $handle ) {
    136326
     327
    137328
     329                        // If there is an error then take note of it..
    138330
     331            $this->print_error($this->db_error_string());
     332
    139333
     334                } else {
    140335
     336
    141337
     338
     339                                $i=0;
     340                                while ( $row = sqlite_fetch_object($handle) ) {
     341                                        $this->last_result[$i++] = $row;
     342                                }
     343
    142344
     345                                // Log number of rows the query returned
    143346
     347                                $this->num_rows = $i;
    144348
     349
    145350
     351                                // If debug ALL queries
     352                                $this->debug_all ? $this->debug() : null ;
    146353
     354
    147355
     356                                // If there were results then return true for $db->query
    148357
     358                                if ( $i ) {
    149359
     360                                        return true;
    150361
     362                                } else {
    151363
     364                                        return false;
    152365
     366                                }
    153367
     368
    154369
     370                }
    155371
     372        }
     373       
     374        // ==================================================================
    156375
     376        //      Parse statement and make it SQLite friendly
     377        //      original code from tikiwiki project
     378
     379        function parse($stmt) {
     380
     381                // variable for statements that have to be appended
     382                global $poststmt;
     383                $poststmt = "\n\n";
     384               
     385                // SQLite don't support 'SHOW TABLES'
     386                $stmt = preg_replace("/SHOW TABLES/", "SELECT name FROM sqlite_master WHERE type='table'", $stmt);
     387               
     388
     389                $stmt = preg_replace("/COUNT[(]DISTINCT([^)]*)[)] FROM ([^'']*) (.*)/","COUNT(*) FROM (SELECT DISTINCT $1 FROM $2 $3)",$stmt);
     390               
     391                // Date and time functions
     392                $stmt = preg_replace("/YEAR[(]([^)]*)[)]/","strftime(\"%Y\", $1)",$stmt);
     393                $stmt = preg_replace("/MONTH[(]([^)]*)[)]/","strftime(\"%m\", $1)",$stmt);
     394                $stmt = preg_replace("/DAY[(]([^)]*)[)]/","strftime(\"%d\", $1)",$stmt);
     395                $stmt = preg_replace("/NOW[(][)]/","date('now')",$stmt);
     396                $stmt = preg_replace("/INTERVAL ([0-9]*)([^)]*)/","\"+$1 $2\"",$stmt);
     397                $stmt = preg_replace("/DATE_ADD[(]([^,]*),([^)]*)[)]/","datetime($1, $2)",$stmt);
     398                $stmt = preg_replace("/UNIX_TIMESTAMP[(]([^)]*)[)]/","strftime('%s',$1)",$stmt);
     399               
     400                $stmt = preg_replace("/[`]/","'",$stmt);
     401               
     402                // MD5
     403                $stmt = preg_replace("/MD5[(][']([^']*)['][)]/e", "'\''.md5('$1').'\''" ,$stmt);
     404               
     405                // Enum
     406                $stmt = preg_replace("/enum[(][^)]*[)]/","varchar(255)",$stmt);
     407       
     408                // Random function
     409                $stmt = preg_replace("/rand[(][)]/","random()",$stmt);
     410
     411                // IF statement ##FIXME not a good way to do this               
     412                $stmt = preg_replace("/IF [(](.*)[,] [0-1][,][0-1][)]/","$1",$stmt);
     413
     414                //replace comments
     415                $stmt = preg_replace("/#/","--",$stmt);
     416               
     417                $stmt = preg_replace("/TYPE=MyISAM/","",$stmt);
     418                //$stmt = preg_replace("/AUTO_INCREMENT=1/","",$stmt);
     419               
     420                //postgres cannot DROP TABLE IF EXISTS ( sqlite?? )
     421                $stmt = preg_replace("/DROP TABLE IF EXISTS/","DROP TABLE",$stmt);
     422               
     423                //auto_increment things
     424                $stmt = preg_replace("/(big)int\(.\) (unsigned )*NOT NULL auto_increment/","INTEGER",$stmt);
     425                $stmt = preg_replace("/(big)int\(..\) (unsigned )*NOT NULL auto_increment/","INTEGER",$stmt);
     426               
     427                // integer types
     428                $stmt = preg_replace("/tinyint\([1-4]\)/","smallint",$stmt);
     429                $stmt = preg_replace("/int\([1-4]\)/","smallint",$stmt);
     430                $stmt = preg_replace("/int\([5-9]\)/","integer",$stmt);
     431                $stmt = preg_replace("/int\(..\)/","bigint",$stmt);
     432       
     433                // timestamps
     434                $stmt = preg_replace("/timestamp\([^\)]+\)/","timestamp(3)",$stmt);
     435               
     436                // blobs
     437                $stmt = preg_replace("/longblob|tinyblob|blob/","bytea",$stmt);
     438               
     439                // ##FIXME quote column names, not sure if needed...
     440                //$stmt = preg_replace("/\n[ \t]+([a-zA-Z0-9_]+)/","\n  \"$1\"",$stmt);
     441
     442                // quote and record table names
     443                $stmt = preg_replace("/(DROP TABLE |CREATE TABLE )([a-zA-Z0-9_]+)( \()*/e","record_tablename('$1','$2','$3')",$stmt);
     444               
     445                // unquote the PRIMARY and other Keys
     446                $stmt = preg_replace("/\n[ \t]+\"(PRIMARY|KEY|FULLTEXT|UNIQUE)\"/","\n  $1",$stmt);
     447               
     448                // convert enums
     449                $stmt = preg_replace("/\n[ \t]+(\"[a-zA-Z0-9_]+\") enum\(([^\)]+)\)/e","convert_enums('$1','$2')",$stmt);
     450                // quote column names in primary keys
     451                $stmt = preg_replace("/\n[ \t]+(PRIMARY KEY)  \((.+)\),*/e","quote_prim_cols('$1','$2')",$stmt);
     452               
     453                // create indexes from KEY ...
     454                $stmt = preg_replace("/\n[ \t]+KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt);
     455                $stmt = preg_replace("/\n[ \t]+FULLTEXT KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$1','$2')",$stmt);
     456                $stmt = preg_replace("/\n[ \t]+(UNIQUE) KEY ([a-zA-Z0-9_]+) \((.+)\),*/e","create_index('$2','$3','$1')",$stmt);
     457               
     458                // handle inserts
     459                $stmt = preg_replace("/INSERT INTO ([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES (.*)/e","do_inserts('$1','$2','$3')",$stmt);
     460                $stmt = preg_replace("/INSERT IGNORE INTO ([a-zA-Z0-9_]*).*\(([^\)]+)\) VALUES (.*)/e","do_inserts('$1','$2','$3')",    $stmt);
     461               
     462                // why does i modifier not work???
     463                $stmt = preg_replace("/insert into ([a-zA-Z0-9_]*).*\(([^\)]+)\) values(.*)/e","do_inserts('$1','$2','$3')",$stmt);
     464               
     465                // the update
     466                $stmt = preg_replace("/update ([a-zA-Z0-9_]+) set (.*)/e","do_updates('$1','$2')",$stmt);
     467                $stmt = preg_replace("/UPDATE ([a-zA-Z0-9_]+) set (.*)/e","do_updates('$1','$2')",$stmt);
     468               
     469                // Ignore 'IGNORE'
     470                $stmt = preg_replace("/IGNORE/","",$stmt);
     471
     472                // clean cases where UNIQUE was alone at the end
     473                $stmt = preg_replace("/,(\s*)\)/","$1)",$stmt);
     474                return $stmt.";".$poststmt;
     475        }
     476
     477        // ==================================================================
    157478
     479        //      Get human friendly error message from sqlite
     480        //      If $code is false, the last error from the current session
     481    //  is returned
     482
     483        function db_error_string($code = false) {
     484        if($code === false) $code = sqlite_last_error($this->dbh);
     485
     486        return sqlite_error_string($code);
     487    }
     488
     489
    158490
     491
    159492
     493        // ==================================================================
    160494
     495        //      Get one variable from the DB - see docs for more detail
    161496
     497
    162498
     499        function get_var($query=null,$x=0,$y=0) {
    163500
     501               
    164502
     503                // Log how the function was called
    165504
     505                $this->func_call = "\$wpdb->get_var(\"$query\",$x,$y)";
    166506
     507
    167508
     509                // If there is a query then perform it if not then use cached results..
    168510
     511                if ( $query ) {
    169512
     513                        $this->query($query);
    170514
     515                }
    171516
     517
    172518
     519                // Extract var out of cached results based x,y vals
    173520
     521                if ( $this->last_result[$y] ) {
    174522
     523                        $values = array_values(get_object_vars($this->last_result[$y]));
    175524
     525                }
    176526
     527
    177528
     529                // If there is a value return it else return null
    178530
     531                return (isset($values[$x]) && $values[$x]!=='')?$values[$x]:null;
    179532
     533        }
    180534
     535
    181536
     537        // ==================================================================
    182538
     539        //      Get one row from the DB - see docs for more detail
    183540
     541
    184542
     543        function get_row($query=null,$output=OBJECT,$y=0) {
    185544
     545
    186546
     547                // Log how the function was called
    187548
     549                $this->func_call = "\$wpdb->get_row(\"$query\",$output,$y)";
    188550
     551
    189552
     553                // If there is a query then perform it if not then use cached results..
    190554
     555                if ( $query ) {
    191556
     557                        $this->query($query);
    192558
     559                }
    193560
     561
    194562
     563                // If the output is an object then return object using the row offset..
    195564
     565                if ( $output == OBJECT ) {
    196566
     567                        return $this->last_result[$y]?$this->last_result[$y]:null;
    197568
     569                }
    198570
     571                // If the output is an associative array then return row as such..
    199572
     573                elseif ( $output == ARRAY_A ) {
    200574
     575                        return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null;
    201576
     577                }
    202578
     579                // If the output is an numerical array then return row as such..
    203580
     581                elseif ( $output == ARRAY_N ) {
    204582
     583                        return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null;
    205584
     585                }
    206586
     587                // If invalid output type was specified..
    207588
     589                else {
    208590
     591                        $this->print_error(" \$wpdb->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N");
    209592
     593                }
    210594
     595
    211596
     597        }
    212598
     599
    213600
     601        // ==================================================================
    214602
     603        //      Function to get 1 column from the cached result set based in X index
    215604
     605        // se docs for usage and info
    216606
     607
    217608
     609        function get_col($query=null,$x=0) {
    218610
     611
    219612
     613                // If there is a query then perform it if not then use cached results..
    220614
     615                if ( $query ) {
    221616
     617                        $this->query($query);
    222618
     619                }
    223620
     621
    224622
     623                // Extract the column values
    225624
     625                for ( $i=0; $i < count($this->last_result); $i++ ) {
    226626
     627                        $new_array[$i] = $this->get_var(null,$x,$i);
    227628
     629                }
    228630
     631
    229632
     633                return $new_array;
    230634
     635        }
    231636
     637
    232638
     639        // ==================================================================
    233640
     641        // Return the the query as a result set - see docs for more details
    234642
     643
    235644
     645        function get_results($query=null, $output = OBJECT) {
    236646
     647
    237648
     649                // Log how the function was called
    238650
     651                $this->func_call = "\$dwpb->get_results(\"$query\", $output)";
    239652
     653
    240654
     655                // If there is a query then perform it if not then use cached results..
    241656
     657                if ( $query ) {
    242658
     659                        $this->query($query);
    243660
     661                }
    244662
     663
    245664
     665                // Send back array of objects. Each row is an object
    246666
     667                if ( $output == OBJECT ) {
    247668
     669                        return $this->last_result;
    248670
     671                }
    249672
     673                elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
    250674
     675                        if ( $this->last_result ) {
    251676
     677                                $i=0;
    252678
     679                                foreach( $this->last_result as $row ) {
    253680
     681
    254682
     683                                        $new_array[$i] = get_object_vars($row);
    255684
     685
    256686
     687                                        if ( $output == ARRAY_N ) {
    257688
     689                                                $new_array[$i] = array_values($new_array[$i]);
  • wp-settings.php

    +					}
    
    +
    
    +					$i++;
    
    +				}
    
    +
    
    +				return $new_array;
    
    +			} else {
    
    +				return null;
    
    +			}
    
    +		}
    
    +	}
    
    +
    
    +	// ==================================================================
    
    +	// Function to get column meta data info pertaining to the last query
    
    +	// see docs for more info and usage
    
    +
    
    +	function get_col_info($info_type="name",$col_offset=-1) {
    
    +
    
    +		if ( $this->col_info ) {
    
    +			if ( $col_offset == -1 ) {
    
    +				$i=0;
    
    +				foreach($this->col_info as $col ) {
    
    +					$new_array[$i] = $col->{$info_type};
    
    +					$i++;
    
    +				}
    
    +				return $new_array;
    
    +			} else {
    
    +				return $this->col_info[$col_offset]->{$info_type};
    
    +			}
    
    +
    
    +		}
    
    +
    
    +	}
    +
    +	function timer_start() {
    +		$mtime = microtime();
    +		$mtime = explode(' ', $mtime);
    +		$this->time_start = $mtime[1] + $mtime[0];
    +		return true;
    +	}
    +	
    +	function timer_stop($precision = 3) {
    +		$mtime = microtime();
    +		$mtime = explode(' ', $mtime);
    +		$time_end = $mtime[1] + $mtime[0];
    +		$time_total = $time_end - $this->time_start;
    +		return $time_total;
    +	}
    
    +
    
    +	// ==================================================================
    +	// Dumps the contents of any input variable to screen in a nicely
    +	// formatted and easy to understand way - any type: Object, Var or Array
    +
    +	function vardump($mixed='') {
    +
    +		echo "<p><table><tr><td bgcolor=ffffff><blockquote><font color=000090>";
    +		echo "<pre><font face=arial>";
    +
    +		if ( ! $this->vardump_called ) {
    +			echo "<font color=800080><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Variable Dump..</b></font>\n\n";
    +		}
    +
    +		$var_type = gettype ($mixed);
    +		print_r(($mixed?$mixed:"<font color=red>No Value / False</font>"));
    +		echo "\n\n<b>Type:</b> " . ucfirst($var_type) . "\n";
    +		echo "<b>Last Query</b> [$this->num_queries]<b>:</b> ".($this->last_query?$this->last_query:"NULL")."\n";
    +		echo "<b>Last Function Call:</b> " . ($this->func_call?$this->func_call:"None")."\n";
    +		echo "<b>Last Rows Returned:</b> ".count($this->last_result)."\n";
    +		echo "</font></pre></font></blockquote></td></tr></table>".$this->donation();
    +		echo "\n<hr size=1 noshade color=dddddd>";
    +
    +		$this->vardump_called = true;
    +
    +	}
    +
    +	// Alias for the above function
    +	function dumpvar($mixed) {
    +		$this->vardump($mixed);
    +	}
    +
    +	// ==================================================================
    +	// Displays the last query string that was sent to the database & a
    +	// table listing results (if there were any).
    +	// (abstracted into a seperate file to save server overhead).
    +
    +	function debug() {
    +
    +		echo "<blockquote>";
    +
    +		// Only show ezSQL credits once..
    +		if ( ! $this->debug_called ) {
    +			echo "<font color=800080 face=arial size=2><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Debug..</b></font><p>\n";
    +		}
    +		echo "<font face=arial size=2 color=000099><b>Query</b> [$this->num_queries] <b>--</b> ";
    +		echo "[<font color=000000><b>$this->last_query</b></font>]</font><p>";
    +
    +			echo "<font face=arial size=2 color=000099><b>Query Result..</b></font>";
    +			echo "<blockquote>";
    +
    +		if ( $this->col_info ) {
    +
    +			// =====================================================
    +			// Results top rows
    +
    +			echo "<table cellpadding=5 cellspacing=1 bgcolor=555555>";
    +			echo "<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>";
    +
    +
    +			for ( $i=0; $i < count($this->col_info); $i++ ) {
    +				echo "<td nowrap align=left valign=top><font size=1 color=555599 face=arial>{$this->col_info[$i]->type} {$this->col_info[$i]->max_length}</font><br><span style='font-family: arial; font-size: 10pt; font-weight: bold;'>{$this->col_info[$i]->name}</span></td>";
    +			}
    +
    +			echo "</tr>";
    +
    +			// ======================================================
    +			// print main results
    +
    +		if ( $this->last_result ) {
    +
    +			$i=0;
    +			foreach ( $this->get_results(null,ARRAY_N) as $one_row ) {
    +				$i++;
    +				echo "<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>$i</font></td>";
    +
    +				foreach ( $one_row as $item ) {
    +					echo "<td nowrap><font face=arial size=2>$item</font></td>";
    +				}
    +
    +				echo "</tr>";
    +			}
    +
    +		} // if last result
    +		else {
    +			echo "<tr bgcolor=ffffff><td colspan=".(count($this->col_info)+1)."><font face=arial size=2>No Results</font></td></tr>";
    +		}
    +
    +		echo "</table>";
    +
    +		} // if col_info
    +		else {
    +			echo "<font face=arial size=2>No Results</font>";
    +		}
    +
    +		echo "</blockquote></blockquote>".$this->donation()."<hr noshade color=dddddd size=1>";
    +
    +
    +		$this->debug_called = true;
    +	}
    +
    +
    
    +}
    +
    +	function record_tablename($stmt,$tabnam,$tail) {
    +	
    +		global $table_name;
    +		$table_name = $tabnam;
    +		return ($stmt."\"".$tabnam."\"".$tail);
    +	}
    +
    +	function create_index($name,$content,$type=""){
    +	
    +		global $table_name;
    +		global $poststmt;
    +		$poststmt.="CREATE $type INDEX \"".$table_name."_".$name."\" ON \"".$table_name."\"(";
    +		$cols=split(",",$content);
    +		$allvals="";
    +
    +		foreach ($cols as $vals) {
    +			$vals=preg_replace("/\(.*\)/","",$vals);
    +			$vals=preg_replace("/([a-zA-Z0-9_]+)/","\"$1\"",$vals);
    +			$allvals.=$vals;
    +		}
    +
    +		$allvals=preg_replace("/\"\"/","\",\"",$allvals);
    +		$poststmt.=$allvals.");\n";
    +	}
    +
    +	function do_updates($tab,$content) {
    +	
    +		$ret="UPDATE \"".$tab."\" SET ";
    +		$cols=split(",",$content);
    +
    +		foreach ($cols as $vals) {
    +			$vals=preg_replace("/([a-zA-Z0-9_]+)=([a-zA-Z0-9_]+)/","\"$1\"=\"$2\"",$vals);
    +			$ret.=$vals;
    +		}
    +		
    +		$ret=preg_replace("/\"\"/","\",\"",$ret);
    +		$ret=preg_replace("/`/","",$ret);
    +		
    +		return($ret);
    +	}
    +
    +	function do_inserts($tab,$content,$tail) {
    +	
    +		// for some reason are the quotes in $tail addslashed. i dont know why
    +		$tail=preg_replace('/\\\"/','"',$tail);
    +		$ret="INSERT INTO \"".$tab."\" (";
    +		$cols=split(",",$content);
    +
    +		foreach ($cols as $vals) {
    +			$vals=preg_replace("/ /","",$vals);
    +			$ret.="\"$vals\"";
    +		}
    +	
    +		$ret=preg_replace("/\"\"/","\",\"",$ret);
    +		$ret.=")";
    +  
    +		$tail=preg_replace("/md5\(\'(.+)\'\)/e","quotemd5('$1')",$tail);
    +		return $ret." VALUES ".$tail;
    +	}
    +
    +	function quotemd5($a) {
    +		return ("'".md5($a)."'");
    +	}
    +
    +	function quote_prim_cols($key,$content) {
    +	
    +		$ret="\n  $key (";
    +		$cols=split(",",$content);
    +
    +		foreach ($cols as $vals) {
    +			$vals=preg_replace("/\(.*\)/","",$vals);
    +			$ret.="\"".trim($vals)."\"";
    +		}
    +		
    +		$ret=preg_replace("/\"\"/","\",\"",$ret);
    +		$ret.=")";
    +
    +		return $ret;
    +	}
    +
    +	function convert_enums($colname,$content) {
    +	
    +		$enumvals=split(",",$content);
    +		$isnum=true;
    +		$length=0;
    +		$colname=stripslashes($colname);
    +		$ret="\n  $colname ";
    +		foreach ($enumvals as $vals) {
    +			if (!is_int($vals)) $isnum=false;
    +			if (strlen($vals)>$length) $length=strlen($vals);
    +		}
    +		if ($isnum) {
    +			if ($length < 4) $ret.="smallint ";
    +			elseif ($length < 9) $ret.="integer ";
    +				else $ret.="bigint ";
    +		} else {
    +			$ret.="varchar($length) ";
    +		}
    +		$ret.="CHECK ($colname IN ($content))";
    +		
    +		return $ret;
    +	}
    
    +
    
    +$wpdb = new wpdb( DB_PATH, DB_NAME );
    
    +
    
    +?>
    diff -wruBN wordpress-2.0.2/wp-settings.php wordpress-2.0.2lite/wp-settings.php
    old new  
    5050if ( !(phpversion() >= '4.1') )
    5151        die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' );
    5252
    53 if ( !extension_loaded('mysql') )
     53if ( !extension_loaded('mysql') && !USE_SQLITE )
    5454        die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
    5555
    5656function timer_start() {
     
    7070        require (ABSPATH . 'wp-content/advanced-cache.php');
    7171
    7272define('WPINC', 'wp-includes');
     73if ( extension_loaded('mysql') && !USE_SQLITE )
    7374require_once (ABSPATH . WPINC . '/wp-db.php');
    7475
     76if ( USE_SQLITE )
     77        require_once (ABSPATH . WPINC . '/wp-sqlite.php');
     78
    7579// Table names
    7680$wpdb->posts            = $table_prefix . 'posts';
    7781$wpdb->users            = $table_prefix . 'users';