Plugin Directory

Changeset 821968


Ignore:
Timestamp:
12/14/2013 05:21:33 PM (12 years ago)
Author:
damiensaunders
Message:

dbf-backup-2 latest v2.3

Location:
dbc-backup-2/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • dbc-backup-2/trunk/dbcbackup-options.php

    r721073 r821968  
    22/*
    33Plugin Options for DBC Backup 2
     4
    45*/
     6
    57if ( ! defined( 'ABSPATH' ) ) exit;
    68if(!defined('WP_ADMIN') OR !current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.'));
    79
    8 // dbcbackup_locale();
    9 $cfg = get_option('dbcbackup_options');
    10 if($_POST['quickdo'] == 'dbc_logerase')
    11 {
    12     check_admin_referer('dbc_quickdo');
    13     $cfg['logs'] = array();
    14     update_option('dbcbackup_options', $cfg);
    15 }
    16 elseif($_POST['quickdo'] == 'dbc_backupnow')
    17 {
    18     check_admin_referer('dbc_quickdo');
    19     $cfg['logs'] = dbcbackup_run('backupnow');
    20 }
    21 elseif($_POST['do'] == 'dbc_setup')
    22 {
    23     check_admin_referer('dbc_options');
    24     $temp['export_dir']     =   rtrim(stripslashes_deep(trim($_POST['export_dir'])), '/');
    25     $temp['compression']    =   stripslashes_deep(trim($_POST['compression']));
    26     $temp['gzip_lvl']       =   intval($_POST['gzip_lvl']);
    27     $temp['period']         =   intval($_POST['severy']) * intval($_POST['speriod']);
    28     $temp['active']         =   (bool)$_POST['active'];
    29     $temp['rotate']         =   intval($_POST['rotate']);
    30     $temp['logs']           =   $cfg['logs'];
    31    
    32     $timenow                =   time();
    33     $year                   =   date('Y', $timenow);
    34     $month                  =   date('n', $timenow);
    35     $day                    =   date('j', $timenow);
    36     $hours                  =   intval($_POST['hours']);
    37     $minutes                =   intval($_POST['minutes']);
    38     $seconds                =   intval($_POST['seconds']);
    39     $temp['schedule']       =   mktime($hours, $minutes, $seconds, $month, $day, $year);
    40     update_option('dbcbackup_options', $temp);
    41 
    42     if($cfg['active'] AND !$temp['active']) $clear = true;
    43     if(!$cfg['active'] AND $temp['active']) $schedule = true;
    44     if($cfg['active'] AND $temp['active'] AND (array($hours, $minutes, $seconds) != explode('-', date('G-i-s', $cfg['schedule'])) OR $temp['period'] != $cfg['period']) )
    45     {
    46         $clear = true;
    47         $schedule = true;
    48     }
    49     if($clear)      wp_clear_scheduled_hook('dbc_backup');
    50     if($schedule)   wp_schedule_event($temp['schedule'], 'dbc_backup', 'dbc_backup');
    51     $cfg = $temp;
    52     ?><div id="message" class="updated fade"><p><?php _e('Options saved.') ?></p></div><?php
    53 }
    54 
    55 $is_safe_mode = ini_get('safe_mode') == '1' ? 1 : 0;
    56 if(!empty($cfg['export_dir']))
    57 {
    58     if(!is_dir($cfg['export_dir']) AND !$is_safe_mode)
    59     {
    60         @mkdir($cfg['export_dir'], 0777, true);
    61         @chmod($cfg['export_dir'], 0777);
    62 
    63         if(is_dir($cfg['export_dir']))
    64         {
    65             $dbc_msg[] = sprintf(__("Folder <strong>%s</strong> was created.", 'dbcbackup'), $cfg['export_dir']);
    66         }
    67         else
    68         {
    69             $dbc_msg[] = $is_safe_mode ? __('PHP Safe Mode Is On', 'dbcbackup') : sprintf(__("Folder <strong>%s</strong> wasn't created, check permissions.", 'dbcbackup'), $cfg['export_dir']);                               
    70         }
    71     }
    72     else
    73     {
    74         $dbc_msg[] = sprintf(__("Folder <strong>%s</strong> exists.", 'dbcbackup'), $cfg['export_dir']);
    75     }
    76    
    77     if(is_dir($cfg['export_dir']))
    78     {
    79         $condoms = array('.htaccess', 'index.html');   
    80         foreach($condoms as $condom)
    81         {
    82             if(!file_exists($cfg['export_dir'].'/'.$condom))
    83             {
    84                 if($file = @fopen($cfg['export_dir'].'/'.$condom, 'w'))
    85                 {   
    86                     $cofipr =  ($condom == 'index.html')? '' : "Order allow,deny\ndeny from all";
    87                     fwrite($file, $cofipr);
    88                     fclose($file);
    89                     $dbc_msg[] =  sprintf(__("File <strong>%s</strong> was created.", 'dbcbackup'), $condom);
    90                 }   
    91                 else
    92                 {
    93                     $dbc_msg[] = sprintf(__("File <strong>%s</strong> wasn't created, check permissions.", 'dbcbackup'), $condom);         
    94                 }
    95             }
    96             else
    97             {
    98                 $dbc_msg[] = sprintf(__("File <strong>%s</strong> exists.", 'dbcbackup'), $condom);
    99             }
    100         }
    101     }
    102 }
    103 else
    104 {
    105     $dbc_msg[] = __('Specify the folder where the backups will be stored', 'dbcbackup');
    106 }
    107 
    108 /**
    109  *
    110  * DBC Backup
    111  * Options Panel
    112  **/
     10//admin page functions
     11require_once ('inc/admin-functions.php');
     12
     13
     14
     15/* ------------------------------------------------------------------------ *
     16 * This is the layout for the Admin Page
     17 * since v2
     18 * thanks to Frank Bueltge for his Admin Page template
     19 * http://bueltge.de/
     20 * ------------------------------------------------------------------------ */
     21
    11322 ?>
    11423        <div class="wrap">
     
    11625            <h2><?php _e('DBC Backup Options', 'dbcbackup'); ?></h2>
    11726            <div class="metabox-holder has-right-sidebar">
    118     <div id="message" class="updated fade"><p><?php echo implode('<br />', $dbc_msg); ?></p></div>
     27                <?php
     28
     29                //$screen = get_current_screen();
     30                //                    print_r($screen->id);
     31                //                        return $screen;
     32                settings_errors();?>
     33
    11934    <!-- SIDEBAR -->               
    12035            <div class="inner-sidebar">
    121            
     36            <div class="postbox">
     37                <h3><span>Backup Settings Status</span></h3>
     38                <div class="inside">
     39                    <?php echo implode('<br />', $dbc_msg); ?>
     40                    </div>
     41                </div>
    12242                        <div class="postbox">
    12343                            <h3><span>Thanks from Damien</span></h3>
    12444                            <div class="inside">
    125                     <p>Thanks for installing this. <a target="_blank" href="http://damien.co/?utm_source=WordPress&utm_medium=dbc-backup-installed&utm_campaign=WordPress-Plugin">Damien</a></p>
    126                     <p>Please add yourself to <a target="_blank" href="http://wordpress.damien.co/wordpress-mailing-list/?utm_source=WordPress&utm_medium=dbc-backup-installed&utm_campaign=WordPress-Plugin">my mailing list</a> to be the first to hear WordPress tips and updates for this plugin.</p>
     45                            <?php echo 'Thank you for using version ' . DBCBACKUP2_VERSION; ?>. <a target="_blank" href="http://damien.co/?utm_source=WordPress&utm_medium=dbc-backup-installed-2.3&utm_campaign=WordPress-Plugin">Damien</a></p>
     46                    <p>Please add yourself to <a target="_blank" href="http://wordpress.damien.co/wordpress-mailing-list/?utm_source=WordPress&utm_medium=dbc-backup-installed-2.3&utm_campaign=WordPress-Plugin">my mailing list</a> to be the first to hear WordPress tips and updates for this plugin.</p>
    12747                    <p>Let me and your friends know you installed this:</p>
    12848                <a href="https://twitter.com/share" class="twitter-share-button" data-text="I just installed DBC Backup 2 for WordPress" data-url="http://damiens.ws/MLLV3H" data-counturl="http://wordpress.damien.co/dbc-backup-2" data-count="horizontal" data-via="damiensaunders">Tweet</a><script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script> 
     
    13555                            <div class="inside">
    13656                                <ul>
    137                                 <li><a target="_blank" href="http://wordpress.damien.co/dbc-backup-2/?utm_source=WordPress&utm_medium=dbc-backup-installed&utm_campaign=WordPress-Plugin">Help & FAQ's</a></li>
    138                                 <li><a target="_blank" href="http://wordpress.damien.co/?utm_source=WordPress&utm_medium=dbc-backup-installed&utm_campaign=WordPress-Plugin">More WordPress Tips & Ideas</a></li>
     57                                <li><a target="_blank" href="http://wordpress.damien.co/dbc-backup-2/?utm_source=WordPress&utm_medium=dbc-backup-installed-2.3&utm_campaign=WordPress-Plugin">Help & FAQ's</a></li>
     58                                <li><a target="_blank" href="http://wordpress.damien.co/?utm_source=WordPress&utm_medium=dbc-backup-installed-2.3&utm_campaign=WordPress-Plugin">More WordPress Tips & Ideas</a></li>
    13959                                </ul>
    14060                            </div>
     
    14565                            <ul>
    14666                                <li><a target="_blank" href="http://wordpress.damien.co/isotope/?utm_source=WordPress&utm_medium=dbc-sitewide-installed&utm_campaign=WordPress-Plugin">Isotope</a> - does amazing visual things for your website.</li>
    147                             <li><a target="_blank" href="http://whitetshirtdigital.com/shop/?utm_source=WordPress&utm_medium=dbc-backup-installed&utm_campaign=WordPress-Plugin">Learn more about digital marketing or WordPress</a> with Damien.</li>
     67                            <li><a target="_blank" href="http://whitetshirtdigital.com/shop/?utm_source=WordPress&utm_medium=dbc-backup-installed-2.3&utm_campaign=WordPress-Plugin">Learn more about digital marketing or WordPress</a> with Damien.</li>
    14868                            </ul>
    14969                            </div>
     
    247167                    </select></label>&nbsp;
    248168                    <?php endforeach;?></p>
    249                 <?php _e('Active:', 'dbcbackup'); ?> <input style="display:inline" type="checkbox" name="active" value="1" <?php echo ($cfg['active'] ? 'checked="checked"' : ''); ?> /></p>       
     169                <?php _e('Active:', 'dbcbackup'); ?> <input type="checkbox" name="active" value="1" <?php echo ($cfg['active'] ? 'checked="checked"' : ''); ?> /></p>
    250170                <?php if($next_scheduled = wp_next_scheduled('dbc_backup')):
    251171                        _e('Next Schedule is on: ', 'dbcbackup');  echo date('Y-m-d H:i:s', $next_scheduled); ?> | <?php
     
    268188            <option value="<?php echo $i; ?>" <?php echo ($cfg['rotate'] == $i ? 'selected' : ''); ?>><?php echo $display; ?></option>
    269189            <?php endfor; ?>
    270            </select></label><br /><?php _e('The deletion of the old backups occurs during new backup generation.', 'dbcbackup'); ?></td>
     190           </select></label><br /><?php _e('Deletion of old backups occurs the next time a backup is run.', 'dbcbackup'); ?></td>
    271191        </tr>
    272192         <tr>
  • dbc-backup-2/trunk/dbcbackup.php

    r721073 r821968  
    44Plugin URI: http://wordpress.damien.co/plugins?utm_source=WordPress&utm_medium=dbc-backup&utm_campaign=WordPress-Plugin&utm_keyword=source
    55Description: Safe & easy backup for your WordPress database. Just schedule and forget.
    6 Version: 2.2
     6Version: 2.3.23
    77Author: Damien Saunders
    8 Author URI: http://damien.co/?utm_source=WordPress&utm_medium=dbc-backup&utm_campaign=WordPress-Plugin&utm_keyword=source
     8Author URI: http://damien.co/?utm_source=WordPress&utm_medium=dbc-backup-2-2.3.23&utm_campaign=WordPress-Plugin&utm_keyword=source
    99License: GPLv2 or later
    1010*/
    1111
     12/**
     13 * You shouldn't be here.
     14 */
    1215if ( ! defined( 'ABSPATH' ) ) exit;
    13 /*
    14  * Save User Options to WPDB
    15  */
    16 add_action('activate_dbcbackup/dbcbackup.php', 'dbcbackup_install');
    17 function dbcbackup_install()
    18 {
    19     $options = array('export_dir' => '', 'compression' => 'none', 'gzip_lvl' => 0, 'period' => 86400,  'schedule' => time(), 'active' => 0, 'rotate' => -1);
    20     add_option('dbcbackup_options', $options, '', 'no');
     16
     17/**
     18 * Globals
     19 */
     20define ("DBCBACKUP2_VERSION", "2.3.23");
     21define ("PLUGIN_NAME", "dbc-backup-2");
     22$plugin = plugin_basename(__FILE__);
     23global $damien_dbc_option;
     24global $plugin;
     25
     26// @todo implement this default location and make it work for 1st time users.
     27define ("DBCBACKUP2_LOCATION", "../wp-content/backup");
     28
     29/**
     30 * Gets the stored presets from the database so we can use them in the Admin page
     31 * since v2.1
     32 * @return mixed
     33 */
     34function dbc_get_global_options(){
     35    $damien_dbc_option  = get_option('dbcbackup_options');
     36    return $dbc_option;
    2137}
    2238
    23 /*
    24  * Uninstall function
    25  */
    26 function dbcbackup_uninstall()
    27 {
    28     wp_clear_scheduled_hook('dbc_backup'); 
    29     delete_option('dbcbackup_options');
     39
     40/**
     41 * Here we add the plugin default settings
     42 * Since v2.3 we set the default directory to wp-content/backup
     43 *
     44 */
     45function damien_dbc_set_default_options() {
     46    if (get_option('dbcbackup_options') === false){
     47        $new_options['compression'] = "none";
     48        $new_options['gzip_lvl'] = 0;
     49        $new_options['period'] = 86400;
     50        $new_options['schedule'] = time();
     51        $new_options['active'] = 0;
     52        $new_options['rotate'] =-1;
     53        $new_options['version'] = DBCBACKUP2_VERSION;
     54        $new_options['export_dir'] = "";
     55        add_option('dbcbackup_options', $new_options);
     56    }
    3057}
    31 register_deactivation_hook(__FILE__, 'dbcbackup_uninstall');
     58add_action('admin_init', 'damien_dbc_set_default_options');
    3259
    33 add_action('dbc_backup', 'dbcbackup_run');
    34 function dbcbackup_run($mode = 'auto')
    35 {
    36     if(defined('DBC_BACKUP_RETURN')) return;
    37     $cfg = get_option('dbcbackup_options');
    38     if(!$cfg['active'] AND $mode == 'auto') return;
    39     if(empty($cfg['export_dir'])) return;
    40     if($mode == 'auto') dbcbackup_locale();
    41    
    42     require_once ('inc/functions.php');
    43     define('DBC_COMPRESSION', $cfg['compression']);
    44     define('DBC_GZIP_LVL', $cfg['gzip_lvl']);
    45     define('DBC_BACKUP_RETURN', true);
    46    
    47     $timenow            =   time();
    48     $mtime              =   explode(' ', microtime());
    49     $time_start         =   $mtime[1] + $mtime[0];
    50     $key                =   substr(md5(md5(DB_NAME.'|'.microtime())), 0, 6);
    51     $date               =   date('m.d.y-H.i.s', $timenow);
    52     list($file, $fp)    =   dbcbackup_open($cfg['export_dir'].'/Backup_'.$date.'_'.$key);
    53    
    54     if($file)
    55     {
    56         $removed = dbcbackup_rotate($cfg, $timenow);
    57         @set_time_limit(0);
    58         $sql = mysql_query("SHOW TABLE STATUS FROM ".DB_NAME);
    59         dbcbackup_write($file, dbcbackup_header());
    60         while ($row = mysql_fetch_array($sql))
    61         {   
    62             dbcbackup_structure($row['Name'], $file);
    63             dbcbackup_data($row['Name'], $file);
    64         }
    65         dbcbackup_close($file);
    66         $result = __('Successful', 'dbcbackup');
    67     }
    68     else
    69     {
    70         $result = sprintf(__("Failed To Open: %s.", 'dbcbackup'), $fp);
    71     }
    72     $mtime          =   explode(' ', microtime());
    73     $time_end       =   $mtime[1] + $mtime[0];
    74     $time_total     =   $time_end - $time_start;
    75     $cfg['logs'][]  =   array ('file' => $fp, 'size' => @filesize($fp), 'started' => $timenow, 'took' => $time_total, 'status'  => $result, 'removed' => $removed);                 
    76     update_option('dbcbackup_options', $cfg);
    77     return ($mode == 'auto' ? true : $cfg['logs']);
    78 }
    79 /*
    80  * i18n -- I need to local at the POT stuff for v2.2
     60
     61
     62
     63
     64/**
     65 * INCLUDED FILES
     66 * since v2.3
     67 * @return array|bool
    8168 */
    82 function dbcbackup_locale()
     69// backup files
     70require_once ('inc/backup_run.php');
     71//functions for the admin page are called at the top of the options.php
     72//require_once ('inc/admin-functions.php');
     73//functions
     74require_once ('inc/functions.php');
     75
     76
     77
     78
     79/**
     80 * i18n -- I need to look at the POT stuff for v2.2
     81 *
     82 */function dbcbackup_locale()
    8383{
    8484    load_plugin_textdomain('dbcbackup', 'wp-content/plugins/dbc-backup-2');
    8585}
    8686
    87 /*
    88  * 2.1 Add Menu - moved to Tools
     87/**
     88 * Add Menu
     89 * since v0
     90 * v2.1 moved to Tools menu
     91 * @todo v2.3 added helptab - work in progress
    8992 */
     93function dbcbackup_menu()
     94{
     95      global $dbc_backup_admin;
     96      $dbc_backup_admin = add_management_page('DBC Backup', 'DBC Backup', 'manage_options', 'dbc_backup_admin', 'damien_dbc_inc_my_page');
     97      include dirname(__FILE__).'/inc/help_tab.php';
     98            // Adds my_help_tab when my_admin_page loads
     99            add_action('load-'.$dbc_backup_admin, 'damien_dbc_admin_add_help_tab');
     100
     101}
    90102add_action('admin_menu', 'dbcbackup_menu');
    91 function dbcbackup_menu()
     103
     104/**
     105 *
     106 */
     107function damien_dbc_inc_my_page()
    92108{
    93     if(function_exists('add_management_page'))
    94     {
    95         add_management_page('DBC Backup', 'DBC Backup', 'manage_options', dirname(__FILE__).'/dbcbackup-options.php');
    96     }
     109    include dirname(__FILE__).'/dbcbackup-options.php';
    97110}
    98111
    99 /*
     112
     113
     114
     115/**
    100116 * Add WP-Cron Job
     117 * since v0
     118 * @return array
    101119 */
    102 add_filter('cron_schedules', 'dbcbackup_interval');
    103 function dbcbackup_interval() {
     120 function dbcbackup_interval() {
    104121    $cfg = get_option('dbcbackup_options');
    105122    $cfg['period'] = ($cfg['period'] == 0) ? 86400 : $cfg['period'];
    106123    return array('dbc_backup' => array('interval' => $cfg['period'], 'display' => __('DBC Backup Interval', 'dbc_backup')));
    107124}
     125add_filter('cron_schedules', 'dbcbackup_interval');
    108126
    109 /*
    110  * 2.1 Add settings link on Installed Plugin page
     127
     128/**
     129 * Add settings link on Installed Plugin page
     130 * since v2.1
     131 * @param $links
     132 * @return mixed
    111133 */
    112 function dbc_backup_settings_link($links) { 
     134function dbc_backup_settings_link($links) {
    113135  $settings_link = '<a href="tools.php?page=dbc-backup-2/dbcbackup-options.php">Settings</a>';
    114136  array_unshift($links, $settings_link);
     
    120142
    121143
    122 /*
     144
     145/* ------------------------------------------------------------------------ *
     146 * Boring stuff
     147 * ------------------------------------------------------------------------ */
     148
     149
     150
     151/**
    123152 * RSS feed
    124153 */
     154
    125155function dbc_backup_rss_display()
    126156{
     
    140170}
    141171
     172
     173/* ------------------------------------------------------------------------ *
     174 * If you delete the plugin - I'll feel sad
     175 * ------------------------------------------------------------------------ */
     176
     177
     178
     179/**
     180 * Uninstall function
     181 * Ill be sorry to see you leave
     182 * since v2.1
     183 */
     184function dbcbackup_uninstall()
     185{
     186    wp_clear_scheduled_hook('dbc_backup');
     187    delete_option('dbcbackup_options');
     188}
     189register_deactivation_hook(__FILE__, 'dbcbackup_uninstall');
     190
     191
     192
    142193?>
  • dbc-backup-2/trunk/inc/functions.php

    r570332 r821968  
    11<?php
    22
    3 function dbcbackup_structure($table, $fp)
     3/**
     4 * @param $table
     5 * @param $fp
     6 *
     7 * @return bool
     8 */
     9 function dbcbackup_structure($table, $fp)
    410{   
    511    $is_safe_mode = ini_get('safe_mode') == '1' ? 1 : 0;
     
    713    $res ='';
    814    $res .= "\n";
    9     $res .= "--\n";
    10     $res .= "-- Table structure of table ".dbcbackup_backquote($table)."\n";
    11     $res .= "--\n";
     15    $res .= "# Table structure of table ".dbcbackup_backquote($table)."\n";
     16    $res .= "# ------------------------------------------------------- \n";
    1217    $res .= "\n";
    1318
     
    1924        unset($row);
    2025        $create_table = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_table);
    21         $create_table = preg_replace("/ENGINE\s?=/", "TYPE=", $create_table);
     26        //@todo delete the next line if this works
     27        //$create_table = preg_replace("/ENGINE\s?=/", "TYPE=", $create_table);
    2228        $create_table .= ";\n";
    2329        $res .= $create_table;
     
    2531        $status = true;
    2632    }
    27     else 
     33    else
    2834    {
    2935        $tmp = mysql_error();
     
    3844/* ------------------ */
    3945
    40 function dbcbackup_data($table, $fp)
     46/**
     47 * @param $table
     48 * @param $fp
     49 * @return bool
     50 */function dbcbackup_data($table, $fp)
    4151{
    4252    $is_safe_mode = ini_get('safe_mode') == '1' ? 1 : 0;
     
    4454    $res ='';
    4555    $res .= "\n";
    46     $res .= "--\n";
    47     $res .= "-- Dumping data for table ".dbcbackup_backquote($table)."\n";
    48     $res .= "--\n";
     56    $res .= "# Dumping data for table ".dbcbackup_backquote($table)."\n";
     57    $res .= "# ----------------------------------------------------- \n";
    4958    $res .= "\n";
    5059    dbcbackup_write($fp, $res);
    51        
     60
    5261    if($sql = mysql_query("SELECT * FROM ".dbcbackup_backquote($table)))
    5362    {
     
    6069        while ($row = mysql_fetch_array($sql))
    6170        {
    62             $res = "INSERT INTO ".dbcbackup_backquote($table)." VALUES ("; 
     71            $res = "INSERT INTO ".dbcbackup_backquote($table)." VALUES (";
    6372            $fieldcounter = -1;
    6473            $firstfield = 1;
    6574            while (++$fieldcounter < $numfields)
    66             {   
     75            {
     76                //tmp array and array dereferencing here
     77                $fields_tmp = array(1,2,3);
     78
    6779                if (!$firstfield){
    6880                    $res .= ', ';
     
    7587                        && ! $fields_meta[$fieldcounter]->blob) {
    7688                    $res .= $row[$fieldcounter];
    77                 } elseif (stristr($field_flags[$j], 'BINARY')
     89                } elseif (stristr($fields_tmp[1], 'BINARY')
    7890                        && isset($GLOBALS['hexforbinary'])
    7991                        && $fields_meta[$fieldcounter]->type != 'datetime'
     
    93105                } // end if
    94106            }
    95             $res .= ");\n"; 
    96             dbcbackup_write($fp, $res); 
     107            $res .= ");\n";
     108            dbcbackup_write($fp, $res);
    97109        }
    98110        //$res = "UNLOCK TABLES;\n";
     
    112124
    113125
    114 function dbcbackup_backquote($a_name)
     126/**
     127 * @param $a_name
     128 * @return array|string
     129 */function dbcbackup_backquote($a_name)
    115130{
    116131    //Add backqouotes to tables and db-names in SQL queries. Taken from phpMyAdmin.
    117     if (!empty($a_name) && $a_name != '*') 
    118     {
    119         if (is_array($a_name)) 
     132    if (!empty($a_name) && $a_name != '*')
     133    {
     134        if (is_array($a_name))
    120135        {
    121136            $result = array();
    122137            reset($a_name);
    123             while(list($key, $val) = each($a_name)) 
     138            while(list($key, $val) = each($a_name))
    124139            {
    125140              $result[$key] = '`' . $val . '`';
    126141            }
    127142             return $result;
    128         } 
    129         else 
     143        }
     144        else
    130145        {
    131146            return '`' . $a_name . '`';
    132147        }
    133     } 
    134     else 
     148    }
     149    else
    135150    {
    136151        return $a_name;
     
    140155/* ------------------ */
    141156
     157/**
     158 * This is the header of the SQL file
     159 * @return string
     160 */
    142161function dbcbackup_header()
    143162{
    144     $header  = "-- Database Cron Backup \n";
    145     $header .= "-- Version 1.0 for Wordpress 2.5+ \n";
    146     $header .= "-- Copyright Chris T aka Tefra http://www.t3-design.com \n";
    147     $header .= "-- Generated: ".date('l dS \of F Y h:i A', time() + (get_option('gmt_offset') * 3600))." \n";
    148     $header .= "-- MySQL Server: ".mysql_get_host_info()."\n";
    149     $header .= "-- MySQL Server version: ".mysql_get_server_info()."\n";
    150     $header .= "-- Database: ".dbcbackup_backquote(DB_NAME)."\n";
    151     $header .= "-- -------------------------------------------------------- \n";
     163    //@todo tidy this up
     164    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
     165    $header = "# ####################################################### \n";
     166    $header .= "#  \n";
     167    $header .= "# DBC Backup 2\n";
     168    $header .= "# Version 2.3 for Wordpress 3.6 \n";
     169    $header .= "# Plugin by Damien Saunders http://wordpress.damien.co \n";
     170    $header .= "# Generated: ".date('l dS \of F Y h:i A', time() + (get_option('gmt_offset') * 3600))." \n";
     171    $header .= "# MySQL Server: ".mysqli_get_host_info($link)."\n";
     172    $header .= "# MySQL Server version: ".mysqli_get_server_info($link)."\n";
     173    $header .= "# Database: ".dbcbackup_backquote(DB_NAME)."\n";
     174    $header .= "#  \n";
     175    $header .= "# ####################################################### \n";
    152176    return $header;
    153177}
     
    155179/* ------------------ */
    156180
    157 function dbcbackup_fields($result) {
     181/**
     182 * @param $result
     183 * @return array
     184 */function dbcbackup_fields($result) {
    158185    $fields       =     array();
    159186    $num_fields   =     mysql_num_fields($result);
    160     for ($i = 0; $i < $num_fields; $i++) 
     187    for ($i = 0; $i < $num_fields; $i++)
    161188    {
    162189        $fields[] = mysql_fetch_field($result, $i);
     
    167194/* ------------------ */
    168195
    169 function dbcbackup_addslashes($a_string = '', $is_like = false, $crlf = false, $php_code = false)
     196/**
     197 * @param string $a_string
     198 * @param bool   $is_like
     199 * @param bool   $crlf
     200 * @param bool   $php_code
     201 * @return mixed
     202 */function dbcbackup_addslashes($a_string = '', $is_like = false, $crlf = false, $php_code = false)
    170203{   //Taken from phpMyAdmin.
    171204    if ($is_like) {
     
    189222/* ------------------ */
    190223
     224/**
     225 * PHP file write and compression settings
     226 * @param        $fp
     227 * @param string $mode
     228 * @return array
     229 */
    191230function dbcbackup_open($fp, $mode='write')
    192231{
     
    219258/* ------------------ */
    220259
    221 function dbcbackup_read($fp)
     260/**
     261 * @param $fp
     262 * @return string
     263 */function dbcbackup_read($fp)
    222264{
    223265    switch(DBC_COMPRESSION)
     
    240282/* ------------------ */
    241283
    242 function dbcbackup_write($fp, $code)
     284/**
     285 * @param $fp
     286 * @param $code
     287 */function dbcbackup_write($fp, $code)
    243288{   
    244289    switch(DBC_COMPRESSION)
     
    261306/* ------------------ */
    262307
    263 function dbcbackup_close($fp)
     308/**
     309 * @param $fp
     310 */function dbcbackup_close($fp)
    264311{
    265312    switch(DBC_COMPRESSION)
     
    282329/* ------------------ */
    283330
    284 function dbcbackup_rotate($cfg, $timenow)
     331/**
     332 * @param $cfg
     333 * @param $timenow
     334 * @return int
     335 */function dbcbackup_rotate($cfg, $timenow)
    285336{
    286337    $removed = 0;
     
    315366    return $removed;
    316367}
    317 
    318 ?>
  • dbc-backup-2/trunk/readme.txt

    r721073 r821968  
    1 === Plugin Name ===
     1=== DBC Backup 2 ===
    22Contributors: damiensaunders
    33Donate link:
    44Tags: Database, Cron, Backup, Schedule, SQL, data, extract
    5 Requires at least: 3.0
    6 Tested up to: 3.6
    7 Stable tag: 2.1.2    #stable tag not the same as the SVN commit tag
     5Requires at least: 3.6
     6Tested up to: 3.8
     7Stable tag: 2.1.2
    88
    99DBC Backup 2 is a safe & simple way to schedule regular WordPress database backups using the wp-cron batch jobs.
     
    2323
    2424= Additional Info =
    25 The plugin will try to auto create the export directory
     25The plugin will try to auto create the export directory.
     26
     27This plugin creates it's own sql file and does not use mysqldump like most other plugins.
    2628
    2729During backup, a log is created that includes, the generation date, file, filesize, status and the duration of the generation.
     
    4446== Changelog ==
    4547
     48= Version 2.3 =
     49- Major update, new layout
     50- FIXED - issue with SQL file that prevented it from being imported
     51- FIXED - a lot of the PHP error notices which annoy many developers
     52- FIXED - now use mysqli.query as mysql_query is deprecated
     53
    4654= Version 2.2 =
    47 - Killed a few bugs. Getting this ready for the next WordPress 3.6 
     55- Killed a few bugs. Getting this ready for the next WordPress 3.6
    4856
    4957= Version 2.1.1 =
Note: See TracChangeset for help on using the changeset viewer.