Ticket #2317: sqlite+wordpress.2.0.2-2.diff
File sqlite+wordpress.2.0.2-2.diff, 30.1 KB (added by , 19 years ago) |
---|
-
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 106 106 $category_parent = 0; 107 107 108 108 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')"); 110 110 $cat_ID = $wpdb->insert_id; 111 111 } else { 112 112 $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 1254 1254 return $title; 1255 1255 } 1256 1256 1257 $hook = get_plugin_page_hook($plugin_page, $pagenow); 1258 1259 $parent = $parent1 = get_admin_page_parent(); 1257 $parent = get_admin_page_parent(); 1260 1258 if (empty ($parent)) { 1261 1259 foreach ($menu as $menu_array) { 1262 1260 if (isset ($menu_array[3])) { … … 1264 1262 $title = $menu_array[3]; 1265 1263 return $menu_array[3]; 1266 1264 } 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])) { 1268 1266 $title = $menu_array[3]; 1269 1267 return $menu_array[3]; 1270 1268 } … … 1278 1276 $title = $submenu_array[3]; 1279 1277 return $submenu_array[3]; 1280 1278 } 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])) { 1282 1280 $title = $submenu_array[3]; 1283 1281 return $submenu_array[3]; 1284 1282 } … … 1727 1725 return $upload_error_handler($file, __('File is empty. Please upload something more substantial.')); 1728 1726 1729 1727 // 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']) ) 1731 1729 return $upload_error_handler($file, __('Specified file failed upload test.')); 1732 1730 1733 1731 // A correct MIME type will pass this test. … … 1771 1769 1772 1770 // Move the file to the uploads dir 1773 1771 $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) ) 1775 1773 die(printf(__('The uploaded file could not be moved to %s.'), $file['path'])); 1776 1774 1777 1775 // 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 156 160 $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/', '');"); 157 161 158 162 // 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', '')"); 160 164 161 165 // First post 162 166 $now = date('Y-m-d H:i:s'); 163 167 $now_gmt = gmdate('Y-m-d H:i:s'); 164 168 $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', '', '', '')"); 165 169 166 $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );167 168 170 // Default comment 169 171 $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.'))."')"); 170 172 … … 182 184 $admin_caps = serialize(array('administrator' => true)); 183 185 $wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}capabilities', '{$admin_caps}');"); 184 186 187 188 $wpdb->query( "INSERT INTO $wpdb->post2cat (rel_id, post_id, category_id) VALUES (1, 1, 1)" ); 189 185 190 $message_headers = 'From: ' . $weblog_title . ' <wordpress@' . $_SERVER['SERVER_NAME'] . '>'; 186 191 $message = sprintf(__("Your new WordPress blog has been successfully set up at: 187 192 -
wp-config-sample.php
diff -wruBN wordpress-2.0.2/wp-config-sample.php wordpress-2.0.2lite/wp-config-sample.php
old new 1 1 <?php 2 2 // ** MySQL settings ** // 3 define('DB_NAME', 'wordpress '); // The name of the database3 define('DB_NAME', 'wordpress.db'); // The name of the database 4 4 define('DB_USER', 'username'); // Your MySQL username 5 5 define('DB_PASSWORD', 'password'); // ...and password 6 6 define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value 7 7 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 15 define('USE_SQLITE', 1); 16 define('DB_PATH', '/home/havard/dev/blogg/db/'); // Writeable by the web server 17 18 8 19 // You can have multiple installations in one database if you give each a unique prefix 9 20 $table_prefix = 'wp_'; // Only numbers, letters, and underscores please! 10 21 -
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 296 296 297 297 if (! is_single() && ! is_page()) { 298 298 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 = $idAND 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';"); 300 300 301 301 $number = $comment_count_cache[$id]; 302 302 -
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 0 2 3 1 4 5 // ORIGINAL CODE FROM: 6 // Justin Vincent (justin@visunet.ie) 7 // http://php.justinvincent.com 8 2 9 10 3 11 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 16 define("EZSQL_VERSION","1.26x"); 4 17 18 define("OBJECT","OBJECT",true); 5 19 20 define("ARRAY_A","ARRAY_A",true); 6 21 22 define("ARRAY_N","ARRAY_N",true); 7 23 24 25 if (!defined('SAVEQUERIES')) 26 define('SAVEQUERIES', false); 8 27 28 9 29 30 // ================================================================== 10 31 32 // The Main Class 11 33 34 12 35 36 class wpdb { 13 37 38 14 39 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; 15 60 61 16 62 63 // ================================================================== 17 64 65 // DB Constructor - connects to the server and selects a database 18 66 67 19 68 69 function wpdb($dbpath, $dbname) { 20 70 71 $this->dbh = sqlite_open($dbpath.$dbname); 21 72 73 if ( ! $this->dbh ) { 22 74 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>"); 23 78 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); 24 85 86 25 87 88 } 26 89 90 27 91 92 // ================================================================== 28 93 94 // Select a DB instance (if another one needs to be selected) 29 95 96 30 97 98 function select($dbpath, $dbname) { 31 99 100 $this->wpdb($dbpath, $dbname); 32 101 102 } 33 103 104 34 105 106 // ==================================================================== 35 107 108 // Format a string correctly for safe insert under all PHP conditions 36 109 110 37 111 112 function escape($str) { 38 113 114 return str_replace("'","''",str_replace("''","'",stripslashes($str))); 39 115 116 } 40 117 118 41 119 120 // ================================================================== 42 121 122 // Print SQL/DB error. 43 123 124 44 125 126 function print_error($str = "") { 45 127 128 46 129 130 // All erros go to the global error array $EZSQL_ERROR.. 47 131 132 global $EZSQL_ERROR; 48 133 134 49 135 136 // If no error string then you're SOL 50 137 138 if ( !$str ) { 51 139 140 $str = "An error occured, quick go tell someone!"; 52 141 142 } 53 143 144 54 145 146 // Log this error to the global array.. 55 147 148 $EZSQL_ERROR[] = array 56 149 150 ( 57 151 152 "query" => $this->last_query, 58 153 154 "error_str" => $str 59 155 156 ); 60 157 158 61 159 160 // Is error output turned on or not.. 62 161 162 if ( $this->show_errors ) { 63 163 164 // If there is an error then take note of it 64 165 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>"; 65 170 171 } 66 172 173 else { 67 174 175 return false; 68 176 177 } 69 178 179 } 70 180 181 71 182 183 // ================================================================== 72 184 185 // Turn error handling on or off.. 73 186 187 74 188 189 function show_errors() { 75 190 191 $this->show_errors = true; 76 192 193 } 77 194 195 78 196 197 function hide_errors() { 79 198 199 $this->show_errors = false; 80 200 201 } 81 202 203 82 204 205 // ================================================================== 83 206 207 // Kill cached query results 84 208 209 85 210 211 function flush() { 86 212 213 87 214 215 // Get rid of these 88 216 217 $this->last_result = null; 89 218 219 $this->col_info = null; 90 220 221 $this->last_query = null; 91 222 223 92 224 225 } 93 226 227 94 228 229 // ================================================================== 95 230 231 // Basic Query - see docs for more detail 96 232 233 97 234 235 function query($query) { 98 236 237 99 238 239 // For reg expressions 240 $query = trim($query); 100 241 242 101 243 244 // Flush cached values.. 102 245 246 $this->flush(); 103 247 248 249 // Parse query to be used in SQLite 250 $query = $this->parse($query); 251 104 252 253 // Log how the function was called 105 254 255 $this->func_call = "\$wpdb->query(\"$query\")"; 106 256 257 107 258 259 // Keep track of the last query for debug.. 108 260 261 $this->last_query = $query; 262 263 if (SAVEQUERIES) 264 $this->timer_start(); 109 265 266 110 267 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() ); 111 274 275 112 276 277 // If there was an insert, delete or update see how many rows were affected 113 278 279 // (Also, If there there was an insert take note of the insert_id 114 280 281 $query_type = array("insert","delete","update","replace"); 115 282 283 116 284 285 // loop through the above array 117 286 287 foreach ( $query_type as $word ) { 118 288 289 // This is true if the query starts with insert, delete or update 119 290 291 if ( preg_match("/^$word\s+/i",$query) ) { 120 292 293 $this->rows_affected = sqlite_changes($this->dbh); 121 294 295 122 296 297 // This gets the insert ID 123 298 299 if ( $word == "insert" || $word == "replace" ) { 124 300 301 $this->insert_id = sqlite_last_insert_rowid($this->dbh); 125 302 303 126 304 305 // If insert id then return it - true evaluation 306 return $this->insert_id; 127 307 308 } 128 309 310 129 311 312 // Set to false if there was no insert id 313 $this->result = false; 130 314 315 131 316 317 } 132 318 319 133 320 321 } 134 322 323 135 324 325 if ( ! $handle ) { 136 326 327 137 328 329 // If there is an error then take note of it.. 138 330 331 $this->print_error($this->db_error_string()); 332 139 333 334 } else { 140 335 336 141 337 338 339 $i=0; 340 while ( $row = sqlite_fetch_object($handle) ) { 341 $this->last_result[$i++] = $row; 342 } 343 142 344 345 // Log number of rows the query returned 143 346 347 $this->num_rows = $i; 144 348 349 145 350 351 // If debug ALL queries 352 $this->debug_all ? $this->debug() : null ; 146 353 354 147 355 356 // If there were results then return true for $db->query 148 357 358 if ( $i ) { 149 359 360 return true; 150 361 362 } else { 151 363 364 return false; 152 365 366 } 153 367 368 154 369 370 } 155 371 372 } 373 374 // ================================================================== 156 375 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 // ================================================================== 157 478 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 158 490 491 159 492 493 // ================================================================== 160 494 495 // Get one variable from the DB - see docs for more detail 161 496 497 162 498 499 function get_var($query=null,$x=0,$y=0) { 163 500 501 164 502 503 // Log how the function was called 165 504 505 $this->func_call = "\$wpdb->get_var(\"$query\",$x,$y)"; 166 506 507 167 508 509 // If there is a query then perform it if not then use cached results.. 168 510 511 if ( $query ) { 169 512 513 $this->query($query); 170 514 515 } 171 516 517 172 518 519 // Extract var out of cached results based x,y vals 173 520 521 if ( $this->last_result[$y] ) { 174 522 523 $values = array_values(get_object_vars($this->last_result[$y])); 175 524 525 } 176 526 527 177 528 529 // If there is a value return it else return null 178 530 531 return (isset($values[$x]) && $values[$x]!=='')?$values[$x]:null; 179 532 533 } 180 534 535 181 536 537 // ================================================================== 182 538 539 // Get one row from the DB - see docs for more detail 183 540 541 184 542 543 function get_row($query=null,$output=OBJECT,$y=0) { 185 544 545 186 546 547 // Log how the function was called 187 548 549 $this->func_call = "\$wpdb->get_row(\"$query\",$output,$y)"; 188 550 551 189 552 553 // If there is a query then perform it if not then use cached results.. 190 554 555 if ( $query ) { 191 556 557 $this->query($query); 192 558 559 } 193 560 561 194 562 563 // If the output is an object then return object using the row offset.. 195 564 565 if ( $output == OBJECT ) { 196 566 567 return $this->last_result[$y]?$this->last_result[$y]:null; 197 568 569 } 198 570 571 // If the output is an associative array then return row as such.. 199 572 573 elseif ( $output == ARRAY_A ) { 200 574 575 return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null; 201 576 577 } 202 578 579 // If the output is an numerical array then return row as such.. 203 580 581 elseif ( $output == ARRAY_N ) { 204 582 583 return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null; 205 584 585 } 206 586 587 // If invalid output type was specified.. 207 588 589 else { 208 590 591 $this->print_error(" \$wpdb->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"); 209 592 593 } 210 594 595 211 596 597 } 212 598 599 213 600 601 // ================================================================== 214 602 603 // Function to get 1 column from the cached result set based in X index 215 604 605 // se docs for usage and info 216 606 607 217 608 609 function get_col($query=null,$x=0) { 218 610 611 219 612 613 // If there is a query then perform it if not then use cached results.. 220 614 615 if ( $query ) { 221 616 617 $this->query($query); 222 618 619 } 223 620 621 224 622 623 // Extract the column values 225 624 625 for ( $i=0; $i < count($this->last_result); $i++ ) { 226 626 627 $new_array[$i] = $this->get_var(null,$x,$i); 227 628 629 } 228 630 631 229 632 633 return $new_array; 230 634 635 } 231 636 637 232 638 639 // ================================================================== 233 640 641 // Return the the query as a result set - see docs for more details 234 642 643 235 644 645 function get_results($query=null, $output = OBJECT) { 236 646 647 237 648 649 // Log how the function was called 238 650 651 $this->func_call = "\$dwpb->get_results(\"$query\", $output)"; 239 652 653 240 654 655 // If there is a query then perform it if not then use cached results.. 241 656 657 if ( $query ) { 242 658 659 $this->query($query); 243 660 661 } 244 662 663 245 664 665 // Send back array of objects. Each row is an object 246 666 667 if ( $output == OBJECT ) { 247 668 669 return $this->last_result; 248 670 671 } 249 672 673 elseif ( $output == ARRAY_A || $output == ARRAY_N ) { 250 674 675 if ( $this->last_result ) { 251 676 677 $i=0; 252 678 679 foreach( $this->last_result as $row ) { 253 680 681 254 682 683 $new_array[$i] = get_object_vars($row); 255 684 685 256 686 687 if ( $output == ARRAY_N ) { 257 688 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 50 50 if ( !(phpversion() >= '4.1') ) 51 51 die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' ); 52 52 53 if ( !extension_loaded('mysql') )53 if ( !extension_loaded('mysql') && !USE_SQLITE ) 54 54 die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' ); 55 55 56 56 function timer_start() { … … 70 70 require (ABSPATH . 'wp-content/advanced-cache.php'); 71 71 72 72 define('WPINC', 'wp-includes'); 73 if ( extension_loaded('mysql') && !USE_SQLITE ) 73 74 require_once (ABSPATH . WPINC . '/wp-db.php'); 74 75 76 if ( USE_SQLITE ) 77 require_once (ABSPATH . WPINC . '/wp-sqlite.php'); 78 75 79 // Table names 76 80 $wpdb->posts = $table_prefix . 'posts'; 77 81 $wpdb->users = $table_prefix . 'users';