Changeset 755


Ignore:
Timestamp:
12/09/12 02:49:53 (23 months ago)
Author:
ofer
Message:

Allow to reset configuration in utils, closing warnings will work again

Location:
trunk/WordPress/plugin/transposh
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/admin/utils.js

    r752 r755  
    99        $.ajaxSetup({ 
    1010            cache: false 
     11        }); 
     12 
     13        $("#transposh-reset-options").click(function() { 
     14            if (!confirm("Are you sure you want to do this?")) return false; 
     15            if (!confirm("Are you REALLY sure you want to do this, your configuration will be reset?")) return false; 
     16            $.post(ajaxurl, { 
     17                action: 'tp_reset' 
     18            }); 
    1119        }); 
    1220 
     
    5159            return false; 
    5260        }; 
     61         
    5362        $("#transposh-clean-auto").click(function() { 
    5463            cleanautoclick(0,$(this)); 
  • trunk/WordPress/plugin/transposh/js/admin/warningclose.js

    r752 r755  
    22    $(function() { 
    33        $(".warning-close").click(function() { 
    4             $(this).parent().hide(); 
     4            $(this).parents('div:first').hide(); 
    55            $.post(ajaxurl, { 
    66                action: 'tp_close_warning', 
  • trunk/WordPress/plugin/transposh/transposh.php

    r754 r755  
    398398        // this is an ajax special case, currently crafted and tested on buddy press, lets hope this won't make hell break loose. 
    399399        // it basically sets language based on referred when accessing wp-load.php (which is the way bp does ajax) 
    400         tp_logger(substr($_SERVER['SCRIPT_FILENAME'], -11), 4); 
     400        tp_logger(substr($_SERVER['SCRIPT_FILENAME'], -11), 5); 
    401401        if (substr($_SERVER['SCRIPT_FILENAME'], -11) == 'wp-load.php') { 
    402402            $this->target_language = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url); 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r753 r755  
    3030    private $pages = array(); 
    3131    private $contains_settings = false; 
     32    private $page = ''; 
    3233 
    3334    // constructor of class, PHP4 compatible construction for backward compatibility 
     
    4445        // register ajax callbacks 
    4546        add_action('wp_ajax_tp_close_warning', array(&$this, 'on_ajax_tp_close_warning')); 
     47        add_action('wp_ajax_tp_reset', array(&$this, 'on_ajax_tp_reset')); 
    4648        add_action('wp_ajax_tp_backup', array(&$this, 'on_ajax_tp_backup')); 
    4749        add_action('wp_ajax_tp_restore', array(&$this, 'on_ajax_tp_restore')); 
     
    6365            'tp_support' => array(__('Support', TRANSPOSH_TEXT_DOMAIN)), 
    6466        ); 
     67        if (isset($_GET['page']) && isset($this->pages[$_GET['page']])) $this->page = $_GET['page']; 
    6568    } 
    6669 
     
    227230     */ 
    228231    function admin_print_scripts() { 
    229         switch ($_GET['page']) { 
     232        switch ($this->page) { 
    230233            case 'tp_main': 
    231234                wp_enqueue_script('common'); 
     
    274277            // retrieve the function output and set it as tab content 
    275278            'content' => $this->on_contextual_help())); 
    276         if ($_GET['page'] == 'tp_main') { 
     279        if ($this->page == 'tp_main') { 
    277280            add_screen_option('layout_columns', array('max' => 4, 'default' => 2)); 
    278281            add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), '', 'side', 'core'); 
     
    287290        echo '<form action="admin-post.php" method="post">'; 
    288291        echo '<input type="hidden" name="action" value="save_transposh"/>'; 
    289         echo '<input type="hidden" name="page" value="' . $_GET['page'] . '"/>'; 
     292        echo '<input type="hidden" name="page" value="' . $this->page . '"/>'; 
    290293        echo wp_nonce_field(TR_NONCE); 
    291294        screen_icon('transposh-logo'); 
     
    293296        echo '<h2 class="nav-tab-wrapper">'; 
    294297        foreach ($this->pages as $slug => $titles) { 
    295             $active = ($slug === $_GET['page']) ? ' nav-tab-active' : ''; 
     298            $active = ($slug === $this->page) ? ' nav-tab-active' : ''; 
    296299            echo '<a href="admin.php?page=' . $slug . '" class="nav-tab' . $active . '">'; 
    297300            echo esc_html($titles[0]); 
     
    300303        echo '</h2>'; 
    301304 
    302         // TODO: look at this... 
    303         call_user_func(array(&$this, $_GET['page'])); 
     305        if ($this->page) call_user_func(array(&$this, $this->page)); 
    304306 
    305307        // Add submission for pages that can be modified 
     
    573575         * Insert buttons allowing removal of automated translations from database and maintenence 
    574576         */ 
     577        echo '<div style="margin:10px 0"><a id="transposh-reset-options" href="#" nonce="' . wp_create_nonce('transposh-clean') . '" class="button">' . __('Reset configuration to default (saves keys)', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 
    575578        echo '<div style="margin:10px 0"><a id="transposh-clean-auto" href="#" nonce="' . wp_create_nonce('transposh-clean') . '" class="button">' . __('Delete all automated translations', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 
    576579        echo '<div style="margin:10px 0"><a id="transposh-clean-auto14" href="#" nonce="' . wp_create_nonce('transposh-clean') . '" class="button">' . __('Delete automated translations older than 14 days', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 
     
    738741        } 
    739742 
    740         if (!(class_exists('Memcache') /* !!&& $this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) */) && !function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
     743        if ($this->page && !(class_exists('Memcache') /* !!&& $this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) */) && !function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
    741744            $this->add_warning('tp_cache_warning', __('We were not able to find a supported in-memory caching engine, installing one can improve performance.', TRANSPOSH_TEXT_DOMAIN) . ' <a href="http://transposh.org/faq#performance">' . __('Check Transposh FAQs', TRANSPOSH_TEXT_DOMAIN) . '</a>', 'updated'); 
    742745        } 
     
    746749        if (!$this->transposh->options->get_transposh_admin_hide_warning($id)) { 
    747750            //$this->add_warning_script(); 
    748             wp_enqueue_script('transposh_warningclose', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/warningclose.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 
     751            wp_enqueue_script('transposh_warningclose', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/admin/warningclose.js', array('jquery'), TRANSPOSH_PLUGIN_VER, true); 
    749752            echo '<div class="' . $level . '"><p>&#9888;&nbsp;' . 
    750753            $message . 
     
    770773        $this->transposh->options->update_options(); 
    771774        die(); // this is required to return a proper result 
     775    } 
     776 
     777    function on_ajax_tp_reset() { 
     778        $this->transposh->options->reset_options(); 
     779        die(); 
    772780    } 
    773781 
  • trunk/WordPress/plugin/transposh/wp/transposh_options.php

    r753 r755  
    188188            $value = $_POST[$name]; 
    189189        } 
    190  
     190         
    191191        if (TP_OPT_BOOLEAN == $this->vars[$name]->get_type()) { 
    192192            $value = ($value) ? 1 : 0; 
    193193        } 
    194  
    195         if ($this->vars[$name]->get_value() != $value) { 
     194         
     195        if ($this->vars[$name]->get_value() !== $value) { 
    196196            tp_logger("option '$name' value set: $value"); 
    197197            $this->vars[$name]->set_value($value); 
     
    306306 
    307307    /** 
     308     * Resets all options except keys 
     309     */ 
     310    function reset_options() { 
     311        $this->options = array(); 
     312        foreach (array('msn_key', 'google_key', 'oht_id', 'oht_key','transposh_key') as $key) { 
     313            $this->options[$key] = $this->vars[$key]->get_value(); 
     314        } 
     315            update_option(TRANSPOSH_OPTIONS, $this->options); 
     316    } 
     317 
     318    /** 
    308319     * Determine if the given language code is the default language 
    309320     * @param string $language 
Note: See TracChangeset for help on using the changeset viewer.