Changeset 649


Ignore:
Timestamp:
07/31/2011 04:06:43 AM (10 months ago)
Author:
ofer
Message:

Display warnings for some conditions we can detect (low memory, no cache support)

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

Legend:

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

    r587 r649  
    246246 
    247247    jQuery("#transposh-translate").click(do_translate_all); 
     248     
     249    jQuery(".warning-close").click(function() { 
     250        //alert(this); 
     251        jQuery(this).parent().hide(); 
     252        //alert(); 
     253        jQuery.post(ajaxurl, { 
     254            action: 'closed_tpwarn', 
     255            id: jQuery(this).parent().attr('id') 
     256         }); 
     257    }) 
    248258 
    249259}); 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r639 r649  
    2626    /** @var transposh_plugin $transposh father class */ 
    2727    private $transposh; 
     28    private $localeright = 'right'; 
     29    private $localeleft = 'left'; 
    2830 
    2931// constructor of class, PHP4 compatible construction for backward compatibility 
     
    3840        // register the callback been used if options of page been submitted and needs to be processed 
    3941        add_action('admin_post_save_transposh', array(&$this, 'on_save_changes')); 
     42        // register a callback to allow admin removal of warnings 
     43        add_action('wp_ajax_closed_tpwarn', array(&$this, 'on_closed_tpwarn')); 
    4044    } 
    4145 
     
    188192        wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js', array('jquery'), '1.8.2', true); 
    189193 
    190  
    191194        //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 
    192195        add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), $this->pagehook, 'side', 'core'); 
     
    204207    //executed to show the plugins complete admin page 
    205208    function on_show_page() { 
     209        global $wp_locale; 
     210        if ($wp_locale->text_direction == 'rtl') { 
     211            $this->localeleft = 'right'; 
     212            $this->localeright = 'left'; 
     213        } 
     214 
    206215        //we need the global screen column value to beable to have a sidebar in WordPress 2.8 
    207216        //global $screen_layout_columns; 
     
    214223        echo '<div id="transposh-general" class="wrap">'; 
    215224        screen_icon('options-general'); 
    216  
    217225        echo '<h2>' . __('Transposh', TRANSPOSH_TEXT_DOMAIN) . '</h2>' . 
    218226        '<form action="admin-post.php" method="post">'; 
     227 
     228        // add some user warnings that leads to some FAQs 
     229        if ((int) ini_get('memory_limit') < 64) { 
     230            $this->add_warning('tp_mem_warning', sprintf(__('Your current PHP memory limit of %s is quite low, if you experience blank pages please consider increasing it.', TRANSPOSH_TEXT_DOMAIN), ini_get('memory_limit'))); 
     231        } 
     232 
     233        if (!function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
     234            $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)); 
     235        } 
    219236 
    220237        wp_nonce_field(TR_NONCE); 
     
    276293 
    277294    function on_sidebox_about_content($data) { 
    278         global $wp_locale; 
    279         echo '<ul style="list-style-type:disc;margin-' . ($wp_locale->text_direction == 'rtl' ? 'right' : 'left') . ':20px;">'; 
     295        echo '<ul style="list-style-type:disc;margin-' . $this->localeleft . ':20px;">'; 
    280296        echo '<li><a href="http://transposh.org/">' . __('Plugin Homepage', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 
    281297        echo '<li><a href="http://transposh.org/redir/newfeature">' . __('Suggest a Feature', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 
     
    313329    function on_contentbox_languages_content($data) { 
    314330        // we need some styles 
    315         global $wp_locale; 
    316  
    317331        echo '<style type="text/css"> 
    318332        #sortable { list-style-type: none; margin: 0; padding: 0; } 
    319         #sortable li, #default_lang li { margin: 3px 3px 3px 0; padding: 5px; float: ' . ($wp_locale->text_direction == 'rtl' ? 'right' : 'left') . '; width: 190px; height: 14px;} 
     333        #sortable li, #default_lang li { margin: 3px 3px 3px 0; padding: 5px; float: ' . $this->localeleft . '; width: 190px; height: 14px;} 
    320334        .languages { 
    321335            -moz-border-radius: 6px; 
     
    352366        } 
    353367        .logoicon { 
    354             float:' . ($wp_locale->text_direction == 'rtl' ? 'left' : 'right') . '; 
     368            float:' . $this->localeright . '; 
    355369            margin-left:2px; 
    356370            margin-top:-1px; 
     
    372386            list ($langname, $langorigname, $flag) = explode(",", $langrecord); 
    373387            echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_viewable_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "active" : "") 
    374             . (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:' . ($wp_locale->text_direction == 'rtl' ? 'right' : 'left') . '">' 
     388            . (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:' . $this->localeleft . '">' 
    375389            . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */) 
    376390            . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />' 
     
    388402        echo "</ul></div>"; 
    389403        // options to play with 
    390         echo '<div style="clear: both;">' . __('Display options:', TRANSPOSH_TEXT_DOMAIN) . '<br/><ul style="list-style-type: disc; margin-' . ($wp_locale->text_direction == 'rtl' ? 'right' : 'left') . ':20px;font-size:11px">'; 
     404        echo '<div style="clear: both;">' . __('Display options:', TRANSPOSH_TEXT_DOMAIN) . '<br/><ul style="list-style-type: disc; margin-' . $this->localeleft . ':20px;font-size:11px">'; 
    391405        echo '<li><a href="#" id="changename">' . __('Toggle names of languages between English and Original', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 
    392406        echo '<li><a href="#" id="selectall">' . __('Make all languages active', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 
     
    547561    } 
    548562 
     563    function add_warning($id, $message) { 
     564        if (!$this->transposh->options->get_transposh_admin_hide_warning($id)) { 
     565            echo '<div id="' . $id . '" class="error">' . 
     566            '<span class="ui-icon ui-icon-alert" style="float: ' . $this->localeleft . '; margin-' . $this->localeright . ': .3em;"></span>' . 
     567            $message . 
     568            '<span class="warning-close ui-icon ui-icon-closethick" style="float:' . $this->localeright . '; margin-' . $this->localeleft . ': .3em;"></span>' . 
     569            '</div>'; 
     570        } 
     571    } 
     572 
     573    function on_closed_tpwarn() { 
     574        $this->transposh->options->set_transposh_admin_hide_warning($_POST['id']); 
     575        $this->transposh->options->update_options(); 
     576        die(); // this is required to return a proper result 
     577    } 
     578 
    549579} 
    550580 
  • trunk/WordPress/plugin/transposh/wp/transposh_options.php

    r639 r649  
    7373//Stores the site key to transposh services (backup @since 0.5.0) 
    7474define('TRANSPOSH_BACKUP_SCHEDULE', 'transposh_backup_schedule'); 
     75//Stores hidden warnings (@since 0.7.6) 
     76define('TRANSPOSH_ADMIN_HIDE_WARNINGS', 'transposh_admin_hide_warnings'); 
    7577 
    7678class transposh_plugin_options { 
     
    114116        $this->set_default_option_value(TRANSPOSH_KEY); 
    115117        $this->set_default_option_value(TRANSPOSH_BACKUP_SCHEDULE); 
     118        $this->set_default_option_value(TRANSPOSH_ADMIN_HIDE_WARNINGS); 
    116119        $this->migrate_old_config(); 
    117120        logger($this->options, 4); 
     
    267270    } 
    268271 
     272    function get_transposh_admin_hide_warning($id) { 
     273        return strpos($this->options[TRANSPOSH_ADMIN_HIDE_WARNINGS], $id . ',') !== false; 
     274    } 
     275 
    269276    /** 
    270277     * Sets a value at the options array 
     
    315322    } 
    316323 
    317      /** 
     324    /** 
    318325     * Set the widget theme 
    319326     * @since 0.7.0 
     
    401408        $val = ($val) ? 1 : 0; 
    402409        $this->set_value($val, $this->options[TRANSPOSH_DEFAULT_LOCALE_OVERRIDE]); 
     410    } 
     411 
     412    function set_transposh_admin_hide_warning($id) { 
     413        if (!$this->get_transposh_admin_hide_warning($id)) { 
     414            $this->set_value($this->options[TRANSPOSH_ADMIN_HIDE_WARNINGS] . $id . ',', $this->options[TRANSPOSH_ADMIN_HIDE_WARNINGS]); 
     415        } 
    403416    } 
    404417 
Note: See TracChangeset for help on using the changeset viewer.