Make WordPress Core


Ignore:
Timestamp:
02/12/2006 07:53:23 AM (19 years ago)
Author:
ryan
Message:

Death to trailing tabs. Props Mark J. fixes #2405

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/plugins/wp-db-backup.php

    r3447 r3517  
    3737
    3838    function wpdbBackup() {
    39                
     39
    4040        add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
    4141
    4242        $this->backup_dir = trailingslashit($this->backup_dir);
    4343        $this->basename = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', __FILE__);
    44    
     44
    4545        if (isset($_POST['do_backup'])) {
    4646            switch($_POST['do_backup']) {
     
    5050            case 'fragments':
    5151                add_action('admin_menu', array(&$this, 'fragment_menu'));
    52                 break;             
     52                break;
    5353            }
    5454        } elseif (isset($_GET['fragment'] )) {
     
    6060        }
    6161    }
    62    
     62
    6363    function init() {
    6464        global $user_level;
     
    6969        if (isset($_GET['backup'])) {
    7070            $via = isset($_GET['via']) ? $_GET['via'] : 'http';
    71            
     71
    7272            $this->backup_file = $_GET['backup'];
    73            
     73
    7474            switch($via) {
    7575            case 'smtp':
     
    102102        die();
    103103    }
    104    
     104
    105105    function build_backup_script() {
    106106        global $table_prefix, $wpdb;
    107    
     107
    108108        $datum = date("Ymd_B");
    109109        $backup_filename = DB_NAME . "_$table_prefix$datum.sql";
    110110        if ($this->gzip()) $backup_filename .= '.gz';
    111        
     111
    112112        echo "<div class='wrap'>";
    113113        //echo "<pre>" . print_r($_POST, 1) . "</pre>";
     
    144144
    145145            function backup(table, segment) {
    146                 var fram = document.getElementById("backuploader");             
     146                var fram = document.getElementById("backuploader");
    147147                fram.src = "' . $_SERVER['REQUEST_URI'] . '&fragment=" + table + ":" + segment + ":' . $backup_filename . '";
    148148            }
    149            
     149
    150150            var curStep = 0;
    151            
     151
    152152            function nextStep() {
    153153                backupStep(curStep);
    154154                curStep++;
    155155            }
    156            
     156
    157157            function finishBackup() {
    158                 var fram = document.getElementById("backuploader");             
     158                var fram = document.getElementById("backuploader");
    159159                setMeter(100);
    160160        ';
     
    180180            ';
    181181        }
    182        
     182
    183183        echo '
    184184            }
    185            
     185
    186186            function backupStep(step) {
    187187                switch(step) {
    188188                case 0: backup("", 0); break;
    189189        ';
    190        
     190
    191191        $also_backup = array();
    192192        if (isset($_POST['other_tables'])) {
     
    211211        }
    212212        echo "case {$step_count}: finishBackup(); break;";
    213        
     213
    214214        echo '
    215215                }
     
    225225    function backup_fragment($table, $segment, $filename) {
    226226        global $table_prefix, $wpdb;
    227            
     227
    228228        echo "$table:$segment:$filename";
    229        
     229
    230230        if($table == '') {
    231231            $msg = __('Creating backup file...');
     
    237237            }
    238238        }
    239        
     239
    240240        echo '<script type="text/javascript"><!--//
    241241        var msg = "' . $msg . '";
    242242        window.parent.setProgress(msg);
    243243        ';
    244            
     244
    245245        if (is_writable(ABSPATH . $this->backup_dir)) {
    246246            $this->fp = $this->open(ABSPATH . $this->backup_dir . $filename, 'a');
     
    250250            }
    251251            else {
    252                 if($table == '') {     
     252                if($table == '') {
    253253                    //Begin new backup of MySql
    254254                    $this->stow("# WordPress MySQL database backup\n");
     
    267267                        $this->stow("# Table: " . $this->backquote($table) . "\n");
    268268                        $this->stow("# --------------------------------------------------------\n");
    269                     }           
     269                    }
    270270                    $this->backup_table($table, $segment);
    271271                }
     
    277277
    278278        if($this->fp) $this->close($this->fp);
    279        
     279
    280280        if($this->backup_errors) {
    281281            foreach($this->backup_errors as $error) {
     
    295295            ';
    296296        }
    297        
     297
    298298        die();
    299299    }
     
    305305            $also_backup = $_POST['other_tables'];
    306306        }
    307        
     307
    308308        $core_tables = $_POST['core_tables'];
    309309        $this->backup_file = $this->db_backup($core_tables, $also_backup);
     
    319319        }
    320320    }
    321    
     321
    322322    ///////////////////////////////
    323323    function admin_menu() {
     
    388388        }
    389389    }
    390    
     390
    391391    //////////////
    392392    function stow($query_line) {
     
    403403        }
    404404    }
    405    
     405
    406406    function backup_error($err) {
    407407        if(count($this->backup_errors) < 20) {
     
    411411        }
    412412    }
    413    
     413
    414414    /////////////////////////////
    415415    function backup_table($table, $segment = 'none') {
    416416        global $wpdb;
    417        
     417
    418418        /*
    419419        Taken partially from phpMyAdmin and partially from
    420420        Alain Wolf, Zurich - Switzerland
    421421        Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
    422        
     422
    423423        Modified by Scott Merril (http://www.skippy.net/)
    424424        to use the WordPress $wpdb object
     
    430430            return FALSE;
    431431        }
    432    
     432
    433433        if(($segment == 'none') || ($segment == 0)) {
    434434            //
     
    440440            $this->stow("\n");
    441441            $this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n");
    442            
     442
    443443            //
    444444            //Table structure
     
    449449            $this->stow("#\n");
    450450            $this->stow("\n");
    451            
     451
    452452            $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
    453453            if (FALSE === $create_table) {
     
    456456            }
    457457            $this->stow($create_table[0][1] . ' ;');
    458            
     458
    459459            if (FALSE === $table_structure) {
    460460                $this->backup_error(sprintf(__("Error getting table structure of %s"), $table));
    461461                $this->stow("#\n# Error getting table structure of $table!\n#\n");
    462462            }
    463        
     463
    464464            //
    465465            // Comment in SQL-file
     
    469469            $this->stow("#\n");
    470470        }
    471        
     471
    472472        if(($segment == 'none') || ($segment >= 0)) {
    473473            $ints = array();
     
    482482                }
    483483            }
    484            
    485            
     484
     485
    486486            // Batch by $row_inc
    487            
     487
    488488            if($segment == 'none') {
    489489                $row_start = 0;
     
    493493                $row_inc = ROWS_PER_SEGMENT;
    494494            }
    495            
    496             do {   
     495
     496            do {
    497497                if ( !ini_get('safe_mode')) @set_time_limit(15*60);
    498498                $table_data = $wpdb->get_results("SELECT * FROM $table LIMIT {$row_start}, {$row_inc}", ARRAY_A);
     
    504504                }
    505505                */
    506                    
    507                 $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; 
     506
     507                $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
    508508                //    \x08\\x09, not required
    509509                $search = array("\x00", "\x0a", "\x0d", "\x1a");
     
    525525            } while((count($table_data) > 0) and ($segment=='none'));
    526526        }
    527        
    528        
     527
     528
    529529        if(($segment == 'none') || ($segment < 0)) {
    530530            // Create footer/closing comment in SQL-file
     
    535535            $this->stow("\n");
    536536        }
    537        
     537
    538538    } // end backup_table()
    539    
     539
    540540    function return_bytes($val) {
    541541       $val = trim($val);
     
    550550               $val *= 1024;
    551551       }
    552    
     552
    553553       return $val;
    554554    }
    555    
     555
    556556    ////////////////////////////
    557557    function db_backup($core_tables, $other_tables) {
    558558        global $table_prefix, $wpdb;
    559        
     559
    560560        $datum = date("Ymd_B");
    561561        $wp_backup_filename = DB_NAME . "_$table_prefix$datum.sql";
     
    563563                $wp_backup_filename .= '.gz';
    564564            }
    565        
     565
    566566        if (is_writable(ABSPATH . $this->backup_dir)) {
    567567            $this->fp = $this->open(ABSPATH . $this->backup_dir . $wp_backup_filename);
     
    574574            return false;
    575575        }
    576        
     576
    577577        //Begin new backup of MySql
    578578        $this->stow("# WordPress MySQL database backup\n");
     
    582582        $this->stow("# Database: " . $this->backquote(DB_NAME) . "\n");
    583583        $this->stow("# --------------------------------------------------------\n");
    584        
     584
    585585            if ( (is_array($other_tables)) && (count($other_tables) > 0) )
    586586            $tables = array_merge($core_tables, $other_tables);
    587587        else
    588588            $tables = $core_tables;
    589        
     589
    590590        foreach ($tables as $table) {
    591591            // Increase script execution time-limit to 15 min for every table.
     
    597597            $this->backup_table($table);
    598598        }
    599                
     599
    600600        $this->close($this->fp);
    601        
     601
    602602        if (count($this->backup_errors)) {
    603603            return false;
     
    605605            return $wp_backup_filename;
    606606        }
    607        
     607
    608608    } //wp_db_backup
    609    
     609
    610610    ///////////////////////////
    611611    function deliver_backup ($filename = '', $delivery = 'http', $recipient = '') {
    612612        if ('' == $filename) { return FALSE; }
    613        
     613
    614614        $diskfile = ABSPATH . $this->backup_dir . $filename;
    615615        if ('http' == $delivery) {
     
    641641            $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
    642642            $headers .= 'From: ' . get_settings('admin_email') . "\n";
    643        
     643
    644644            $message = sprintf(__("Attached to this email is\n   %1s\n   Size:%2s kilobytes\n"), $filename, round(filesize($diskfile)/1024));
    645645            // Add a multipart boundary above the plain message
     
    649649                "Content-Transfer-Encoding: 7bit\n\n" .
    650650                $message . "\n\n";
    651            
     651
    652652            // Add file attachment to the message
    653653            $message .= "--{$boundary}\n" .
     
    659659                $data . "\n\n" .
    660660                "--{$boundary}--\n";
    661            
     661
    662662            if (function_exists('wp_mail')) {
    663663                wp_mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup'), $message, $headers);
     
    665665                mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup'), $message, $headers);
    666666            }
    667            
     667
    668668            unlink($diskfile);
    669669        }
    670670        return;
    671671    }
    672    
     672
    673673    ////////////////////////////
    674674    function backup_menu() {
     
    676676        $feedback = '';
    677677        $WHOOPS = FALSE;
    678        
     678
    679679        // did we just do a backup?  If so, let's report the status
    680680        if ( $this->backup_complete ) {
     
    699699            $feedback .= '</p></div>';
    700700        }
    701        
     701
    702702        if (count($this->backup_errors)) {
    703703            $feedback .= '<div class="updated error">' . __('The following errors were reported:') . "<pre>";
     
    707707            $feedback .= "</pre></div>";
    708708        }
    709        
     709
    710710        // did we just save options for wp-cron?
    711711        if ( (function_exists('wp_cron_init')) && isset($_POST['wp_cron_backup_options']) ) {
     
    717717            $feedback .= '<div class="updated"><p>' . __('Scheduled Backup Options Saved!') . '</p></div>';
    718718        }
    719        
     719
    720720        // Simple table name storage
    721721        $wp_table_names = explode(',','categories,comments,linkcategories,links,options,post2cat,postmeta,posts,users,usermeta');
    722722        // Apply WP DB prefix to table names
    723723        $wp_table_names = array_map(create_function('$a', 'global $table_prefix;return "{$table_prefix}{$a}";'), $wp_table_names);
    724        
     724
    725725        $other_tables = array();
    726726        $also_backup = array();
    727    
    728         // Get complete db table list   
     727
     728        // Get complete db table list
    729729        $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
    730730        $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables);
     
    733733        // Get list of non-WP tables
    734734        $other_tables = array_diff($all_tables, $wp_backup_default_tables);
    735        
     735
    736736        if ('' != $feedback) {
    737737            echo $feedback;
     
    750750            }
    751751        }
    752        
     752
    753753        if ( !is_writable( ABSPATH . $this->backup_dir) ) {
    754754            echo '<div class="updated error"><p align="center">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable! We can not create the backup directory.') . '<br />' . ABSPATH . "</p></div>";
     
    782782        echo '<div><input type="radio" name="deliver" id="do_email" value="smtp" /> ';
    783783        echo '<label for="do_email">'.__('Email backup to:').'</label><input type="text" name="backup_recipient" size="20" value="' . get_settings('admin_email') . '" />';
    784        
     784
    785785        // Check DB dize.
    786786        $table_status = $wpdb->get_results("SHOW TABLE STATUS FROM " . $this->backquote(DB_NAME));
     
    789789            $table_size = $table->Data_length - $table->Data_free;
    790790            if(in_array($table->Name, $wp_backup_default_tables)) {
    791                 $core_size += $table_size; 
     791                $core_size += $table_size;
    792792            }
    793793            $db_size += $table_size;
     
    796796        $mem_limit = $this->return_bytes($mem_limit);
    797797        $mem_limit = ($mem_limit == 0) ? 8*1024*1024 :  $mem_limit - 2000000;
    798        
     798
    799799        if (! $WHOOPS) {
    800800            echo '<input type="hidden" name="do_backup" id="do_backup" value="backup" /></div>';
     
    805805        echo '</fieldset>';
    806806        echo '</form>';
    807        
     807
    808808        // this stuff only displays if wp_cron is installed
    809809        if (function_exists('wp_cron_init')) {
     
    851851        }
    852852        // end of wp_cron section
    853        
     853
    854854        echo '</div>';
    855        
     855
    856856    }// end wp_backup_menu()
    857    
     857
    858858    /////////////////////////////
    859859    function wp_cron_daily() {
    860        
     860
    861861        $schedule = intval(get_option('wp_cron_backup_schedule'));
    862862        if (0 == $schedule) {
     
    864864                return;
    865865        }
    866        
     866
    867867        global $table_prefix, $wpdb;
    868868
     
    873873        $core_tables = array_intersect($all_tables, $wp_table_names);
    874874        $other_tables = get_option('wp_cron_backup_tables');
    875        
     875
    876876        $recipient = get_option('wp_cron_backup_recipient');
    877        
     877
    878878        $backup_file = $this->db_backup($core_tables, $other_tables);
    879879        if (FALSE !== $backup_file) {
    880880            $this->deliver_backup ($backup_file, 'smtp', $recipient);
    881881        }
    882        
     882
    883883        return;
    884884    } // wp_cron_db_backup
Note: See TracChangeset for help on using the changeset viewer.