Changeset 387


Ignore:
Timestamp:
03/19/2010 02:07:09 AM (23 months ago)
Author:
ofer
Message:

Backup code to out google app is here, no restore yet

Location:
trunk/WordPress/plugin/transposh
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposhcontrol.js

    r386 r387  
    122122 
    123123    // backup button 
    124     jQuery("#transposh-backup").click(function () { 
    125         jQuery.get(t_jp.post_url + "?backup=" + Math.random()); 
     124    backupclick = function () { 
     125        jQuery("#transposh-backup").click(function(){ 
     126            return false 
     127            }).text("Backup In Progress"); 
     128        jQuery.get(t_jp.post_url + "?backup=" + Math.random(),function(data) { 
     129            var color = 'red'; 
     130            if (data[0] == '2') color = 'green'; 
     131            jQuery('#backup_result').html(data).css('color',color); 
     132            jQuery("#transposh-backup").click(backupclick).text("Do Backup Now"); 
     133        }); 
    126134        return false; 
    127     }); 
     135    }; 
     136    jQuery("#transposh-backup").click(backupclick); 
    128137 
    129138    // translate all button 
  • trunk/WordPress/plugin/transposh/transposh.php

    r374 r387  
    4444require_once("wp/transposh_options.php"); 
    4545require_once("wp/transposh_postpublish.php"); 
     46require_once("wp/transposh_backup.php"); 
    4647 
    4748/** 
     
    118119//        add_action('wp_head', array(&$this,'add_transposh_async')); 
    119120        add_action("sm_addurl",array(&$this,'add_sm_transposh_urls')); 
     121        add_action('transposh_backup_event', array(&$this,'run_backup')); 
     122 
    120123        register_activation_hook(__FILE__, array(&$this,'plugin_activate')); 
    121124        register_deactivation_hook(__FILE__,array(&$this,'plugin_deactivate')); 
     
    701704        } 
    702705    } 
     706 
     707    /** 
     708     * Runs a scheduled backup 
     709     */ 
     710    function run_backup() { 
     711        logger ("backup run.."); 
     712        $my_transposh_backup = new transposh_backup($this); 
     713        $my_transposh_backup->do_backup(); 
     714    } 
    703715} 
     716 
    704717$my_transposh_plugin = new transposh_plugin(); 
    705718 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r386 r387  
    119119        $this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]); 
    120120        $this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]); 
     121        $this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]); 
     122 
     123        // handle change of schedule for backup to daily 
     124        if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] != $this->transposh->options->get_transposh_backup_schedule()) { 
     125            wp_clear_scheduled_hook('transposh_backup_event'); 
     126            if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] == 1) 
     127                wp_schedule_event(time(), 'daily', 'transposh_backup_event'); 
     128        } 
     129        $this->transposh->options->set_transposh_backup_schedule($_POST[TRANSPOSH_BACKUP_SCHEDULE]); 
     130 
    121131        $this->transposh->options->update_options(); 
    122132    } 
     
    201211        //add a 3rd content box now for demonstration purpose, boxes added at start of page rendering can't be switched on/off, 
    202212        //may be needed to ensure that a special box is always available 
    203         add_meta_box('transposh-contentbox-community', 'Transposh community features (upcoming)', array(&$this, 'on_contentbox_community_content'), $this->pagehook, 'normal', 'core'); 
     213        add_meta_box('transposh-contentbox-community', 'Transposh community features', array(&$this, 'on_contentbox_community_content'), $this->pagehook, 'normal', 'core'); 
    204214        //define some data can be given to each metabox during rendering - not used now 
    205215        //$data = array('My Data 1', 'My Data 2', 'Available Data 1'); 
     
    531541 
    532542    function on_contentbox_community_content($data) { 
    533    /*     echo '<a tabindex="4" id="transposh-backup" href="/wp-admin/post-new.php?preview=true" class="button">Do Backup Now</a><br/>'; 
    534         //  echo "<p id=\"backup\">Do backup.</p>"; 
    535         echo 'Service Key: <input type="text" size="32" class="regular-text" value="'.$this->transposh->options->get_transposh_key().'" id="'.TRANSPOSH_KEY.'" name="'.TRANSPOSH_KEY.'"/>'; 
    536         echo ' 
    537 <script type="text/javascript"> 
    538     //<![CDATA[ 
    539     jQuery(document).ready( function($) { 
    540         // close postboxes that should be closed 
    541         $("#backup").click(function () { 
    542         $.get("'.$this->transposh->post_url.'?backup=" + Math.random()); 
    543         //alert ("hi"); 
    544         }); 
    545     }); 
    546     //]]> 
    547 </script>';*/ 
    548         echo "<p>This space is reserved for the coming community features of Transposh that will help you find translators to help with your site.</p>"; 
     543        echo '<h4>Backup service for human translation</h4>'; 
     544        echo '<input type="radio" value="1" name="'.TRANSPOSH_BACKUP_SCHEDULE.'" '. $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>Enable daily backup<br/>'; 
     545        echo '<input type="radio" value="2" name="'.TRANSPOSH_BACKUP_SCHEDULE.'" '. $this->checked($this->transposh->options->get_transposh_backup_schedule() == 2) . '/>Enable live backup<br/>'; 
     546        echo '<input type="radio" value="0" name="'.TRANSPOSH_BACKUP_SCHEDULE.'" '. $this->checked($this->transposh->options->get_transposh_backup_schedule() == 0) . '/>Disable backup (Can be run manually by clicking the button below)<br/>'; 
     547        echo 'Service Key: <input type="text" size="32" class="regular-text" value="'.$this->transposh->options->get_transposh_key().'" id="'.TRANSPOSH_KEY.'" name="'.TRANSPOSH_KEY.'"/> <a target="_blank" href="http://transposh.org/faq/#restore">How to restore?</a><br/>'; 
     548        echo '<div id="backup_result"></div>'; 
     549        echo '<div style="margin:10px 0"><a id="transposh-backup" href="#" class="button">Do Backup Now</a></div>'; 
    549550    } 
    550551} 
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r386 r387  
    9090} 
    9191// Start backup on demand 
    92 /*elseif (isset($_GET['backup'])) { 
    93     $my_transposh_backup = new transposh_backup($my_transposh_plugin); 
    94     $my_transposh_backup->do_backup(); 
    95 }*/ 
     92elseif (isset($_GET['backup'])) { 
     93    $my_transposh_plugin->run_backup(); 
     94} 
    9695 
    9796?> 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r382 r387  
    172172                $source = $_POST["sr$i"]; 
    173173            } 
    174  
     174            // should we backup? 
     175            if ($source ==0) $backup_immidiate_possible = true; 
    175176 
    176177            //Here we check we are not redoing stuff 
    177178            list($translated_text, $old_source) = $this->fetch_translation($original, $lang); 
    178179            if ($translated_text) { 
    179                 if ($source == 1) { 
     180                if ($source > 0) { 
    180181                    logger("Warning auto-translation for already translated: $original $lang", 0); 
    181182                    continue; 
     
    220221            logger("Error !!! failed to insert to db $original , $translation, $lang," , 0); 
    221222            header("HTTP/1.0 404 Failed to update language database ".mysql_error()); 
     223        } 
     224 
     225        // Should we backup now? 
     226        if ($backup_immidiate_possible && $this->transposh->options->get_transposh_backup_schedule() == 2) { 
     227            $this->transposh->run_backup(); 
    222228        } 
    223229        // this is a termination for the ajax sequence 
  • trunk/WordPress/plugin/transposh/wp/transposh_options.php

    r364 r387  
    8585//Allows user to set his default language per #63 @since 0.3.8 
    8686define("WIDGET_ALLOW_SET_DEFLANG", "widget_allow_set_deflang"); 
     87//Stores the site key to transposh services (backup @since 0.5.0) 
     88define("TRANSPOSH_KEY","transposh_key"); 
     89//Stores the site key to transposh services (backup @since 0.5.0) 
     90define("TRANSPOSH_BACKUP_SCHEDULE","transposh_backup_schedule"); 
    8791 
    8892 
     
    248252    } 
    249253 
     254    function get_transposh_key() { 
     255        return $this->options[TRANSPOSH_KEY]; 
     256    } 
     257 
     258    function get_transposh_backup_schedule() { 
     259        return $this->options[TRANSPOSH_BACKUP_SCHEDULE]; 
     260    } 
     261 
    250262    /** 
    251263     * Sets a value at the options array 
     
    361373    } 
    362374 
     375    function set_transposh_key($val) { 
     376        $this->set_value($val, $this->options[TRANSPOSH_KEY]); 
     377    } 
     378 
     379    function set_transposh_backup_schedule($val) { 
     380        $this->set_value($val, $this->options[TRANSPOSH_BACKUP_SCHEDULE]); 
     381    } 
     382 
    363383    /** 
    364384     * Updates options at the wordpress options table if there was a change 
Note: See TracChangeset for help on using the changeset viewer.