Changeset 674 for trunk


Ignore:
Timestamp:
11/26/2011 09:27:16 PM (6 months ago)
Author:
ofer
Message:

Support multiple instances of transposh widget, even a few with different appearnce on same page, and title is editable too! Widgets also no longer post to the site to change language but use javascript direct href manipulation to acheive same goal, code has been significantly simplified all in all.

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

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/constants.php

    r667 r674  
    2121define('TP_ENABLE_CACHE', TRUE); 
    2222//What is the cache items TTL 
    23 define('TP_CACHE_TTL', 3600*24); 
     23define('TP_CACHE_TTL', 3600 * 24); 
    2424//Constants for memcached 
    2525define('TP_MEMCACHED_SRV', '127.0.0.1'); 
     
    128128    // a bit tricky, but we'll see - starting with just esperanto 
    129129    public static $apertium_languages = array('eo'); 
    130  
    131130    // Array for holding po domains we have problems with 
    132131    public static $ignored_po_domains = array('MailPress'); 
     132    // Array holding list of jQueryUI themes 
     133    public static $jqueryui_themes = array('base', 'black-tie', 'blitzer', 'cupertino', 'dark-hive', 'dot-luv', 'eggplant', 'excite-bike', 'flick', 
     134        'hot-sneaks', 'humanity', 'le-frog', 'mint-choc', 'overcast', 'pepper-grinder', 'redmond', 'smoothness', 'south-street', 
     135        'start', 'sunny', 'swanky-purse', 'trontastic', 'ui-darkness', 'ui-lightness', 'vader'); 
    133136 
    134137} 
     
    140143define('TRANSPOSH_PLUGIN_VER', '%VERSION%'); 
    141144 
     145//Current jQuery UI 
    142146define('JQUERYUI_VER', '1.8.16'); 
    143147 
  • trunk/WordPress/plugin/transposh/js/transposh.js

    r671 r674  
    358358            // this is the set_default_language function 
    359359            // attach a function to the set_default_language link if its there 
    360             $('#' + t_jp_prefix + 'setdeflang').click(function () { 
     360            $('.' + t_jp_prefix + 'setdeflang').click(function () { 
    361361                $.ajax({ 
    362362                    url: t_jp.ajaxurl, 
     
    366366                    cache: false 
    367367                } );               
    368                 $(this).hide("slow"); 
     368                $('.' + t_jp_prefix + 'setdeflang').hide("slow"); 
    369369                return false; 
    370370            }); 
  • trunk/WordPress/plugin/transposh/transposh.php

    r672 r674  
    768768    function add_rel_alternate() { 
    769769        if (is_404()) return; 
    770         $widget_args = $this->widget->create_widget_args(true, $this->get_clean_url()); 
     770        $widget_args = $this->widget->create_widget_args($this->get_clean_url()); 
    771771        logger($widget_args, 4); 
    772772        foreach ($widget_args as $lang) { 
  • trunk/WordPress/plugin/transposh/widgets/default/tpw_default.php

    r526 r674  
    3434 * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    3535 */ 
    36 function tp_widget_do($args) { 
    37     echo '<span class="' . NO_TRANSLATE_CLASS . '">'; // wrapping in no_translate to avoid translation of this list 
    38     echo '<select name="lang" id="lang" onchange="Javascript:this.form.submit();">'; // this is a select box which posts on change 
    39     echo '<option value="none">[Language]</option>'; 
    40     foreach ($args as $langrecord) { 
    41         $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 
    42         echo "<option value=\"{$langrecord['isocode']}\"{$is_selected}>{$langrecord['langorig']}</option>"; 
     36class tpw_default extends transposh_base_widget { 
     37 
     38    static function tp_widget_do($args) { 
     39        echo '<span class="' . NO_TRANSLATE_CLASS . '">'; // wrapping in no_translate to avoid translation of this list 
     40 
     41        echo '<select name="lang" id="lang" onchange="document.location.href=this.options[this.selectedIndex].value;">'; // this is a select box which posts on change 
     42        echo '<option value="none">[Language]</option>'; 
     43        foreach ($args as $langrecord) { 
     44            $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 
     45            echo "<option value=\"{$langrecord['url']}\"{$is_selected}>{$langrecord['langorig']}</option>"; 
     46        } 
     47        echo "</select><br/>"; 
     48 
     49        echo "</span>"; 
    4350    } 
    44     echo "</select><br/>"; 
    45     echo "</span>"; 
     51 
    4652} 
     53 
    4754?> 
  • trunk/WordPress/plugin/transposh/widgets/dropdown/tpw_image_dropdown.js

    r435 r674  
    44 
    55    $(document).ready(function() { 
    6         $(".dropdown dt a").click(function() { 
    7             $(".dropdown dd ul").toggle(); 
    8         }); 
     6        $(".dropdown dt a").click(function() { 
     7            $(".dropdown dd ul").toggle(); 
     8            return false; 
     9        }); 
    910 
    10         $(".dropdown dd ul li a").click(function() { 
    11             var text = $(this).html(); 
    12             $(".dropdown dt a span").html(text); 
    13             $(".dropdown dd ul").hide(); 
    14             //$() 
    15             $("form #lang").val( getSelectedValue("tp_dropdown")); 
    16             $("#tp_form").submit(); 
    17         }); 
     11        $(".dropdown dd ul li a").click(function() { 
     12            var text = $(this).html(); 
     13            $(".dropdown dt a span").html(text); 
     14            $(".dropdown dd ul").hide(); 
    1815 
    19         function getSelectedValue(id) { 
    20             return $("#" + id).find("dt a span.value").html(); 
    21         } 
     16            document.location.href=getSelectedValue("tp_dropdown"); 
     17            return false; 
     18        }); 
    2219 
    23         $(document).bind('click', function(e) { 
    24             var $clicked = $(e.target); 
    25             if (! $clicked.parents().hasClass("dropdown")) 
    26                 $(".dropdown dd ul").hide(); 
    27         }); 
     20        function getSelectedValue(id) { 
     21            return $("#" + id).find("dt a span.value").html(); 
     22        } 
     23 
     24        $(document).bind('click', function(e) { 
     25            var $clicked = $(e.target); 
     26            if (! $clicked.parents().hasClass("dropdown")) 
     27                $(".dropdown dd ul").hide(); 
     28        }); 
    2829    }); 
    2930}(jQuery)); // end of closure 
  • trunk/WordPress/plugin/transposh/widgets/dropdown/tpw_image_dropdown.php

    r500 r674  
    2222 */ 
    2323 
    24 /** 
    25  * This function makes sure that the jquery dependency will be met 
    26  * @global transposh_plugin $my_transposh_plugin 
    27  */ 
    28 function tp_widget_js() { 
    29     global $my_transposh_plugin; 
    30     wp_enqueue_script("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/{$my_transposh_plugin->widget->base_widget_file_name}.js", array('jquery'), TRANSPOSH_PLUGIN_VER); 
     24class tpw_image_dropdown extends transposh_base_widget { 
     25 
     26    /** 
     27     * This function makes sure that the jquery dependency will be met 
     28     * @global transposh_plugin $my_transposh_plugin 
     29     */ 
     30    static function tp_widget_js($file, $dir, $url) { 
     31        wp_enqueue_script("transposh_widget", "$url/widgets/dropdown/tpw_image_dropdown.js", array('jquery'), TRANSPOSH_PLUGIN_VER); 
     32    } 
     33 
     34    /** 
     35     * This function does the actual HTML for the widget 
     36     * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
     37     */ 
     38    static function tp_widget_do($args) { 
     39        global $my_transposh_plugin; 
     40        // we calculate the plugin path part, so we can link the images there 
     41        $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
     42 
     43        // we use this hidden field to later post the value 
     44        echo '<input type="hidden" name="lang" id="lang" value=""/>'; 
     45 
     46        echo '<dl id="tp_dropdown" class="dropdown">'; 
     47        echo '<dt><a href="#"><span>' . __('Select language') . '</span></a></dt><dd><ul class="' . NO_TRANSLATE_CLASS . '">'; 
     48        foreach ($args as $langrecord) { 
     49            $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 
     50            echo '<li><a href="#"><img class="flag" src="' . "$plugpath/img/flags/{$langrecord['flag']}" . '.png" alt="' . $langrecord['langorig'] . '"/> ' . $langrecord['langorig'] . '<span class="value">' . $langrecord['url'] . '</span></a></li>'; 
     51        } 
     52 
     53        echo '</ul></dd></dl>'; 
     54    } 
     55 
    3156} 
    3257 
    33 /** 
    34  * This function does the actual HTML for the widget 
    35  * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    36  */ 
    37 function tp_widget_do($args) { 
    38     global $my_transposh_plugin; 
    39     // we calculate the plugin path part, so we can link the images there 
    40     $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
    41  
    42     // we use this hidden field to later post the value 
    43     echo '<input type="hidden" name="lang" id="lang" value=""/>'; 
    44  
    45     echo '<span class="' . NO_TRANSLATE_CLASS . '">'; 
    46     echo '<dl id="tp_dropdown" class="dropdown">'; 
    47     echo '<dt><a href="#"><span>Select language</span></a></dt><dd><ul>'; 
    48  
    49     foreach ($args as $langrecord) { 
    50         $is_selected = $langrecord['active'] ? " selected=\"selected\"" : ""; 
    51         echo '<li><a href="#"><img class="flag" src="' . "$plugpath/img/flags/{$langrecord['flag']}" . '.png" alt="' . $langrecord['langorig'] . '"/> ' . $langrecord['langorig'] . '<span class="value">' . $langrecord['isocode'] . '</span></a></li>'; 
    52     } 
    53  
    54     echo '</ul></dd></dl>'; 
    55     echo '</span>'; 
    56 } 
    5758?> 
  • trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags.php

    r500 r674  
    2626 * @return boolean 
    2727 */ 
    28 function tp_widget_needs_post_url() { 
    29     return true; 
     28class tpw_flags extends transposh_base_widget { 
     29 
     30    static function tp_widget_needs_post_url() { 
     31        return true; 
     32    } 
     33 
     34    /** 
     35     * Creates the list of flags 
     36     * @global transposh_plugin $my_transposh_plugin 
     37     * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
     38     */ 
     39    static function tp_widget_do($args) { 
     40        global $my_transposh_plugin; 
     41        // we calculate the plugin path part, so we can link the images there 
     42        $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
     43 
     44        echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
     45        foreach ($args as $langrecord) { 
     46            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
     47            transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . 
     48            "</a>"; 
     49        } 
     50        echo "</div>"; 
     51    } 
     52 
    3053} 
    3154 
    32 /** 
    33  * Creates the list of flags 
    34  * @global transposh_plugin $my_transposh_plugin 
    35  * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    36  */ 
    37 function tp_widget_do($args) { 
    38     global $my_transposh_plugin; 
    39     // we calculate the plugin path part, so we can link the images there 
    40     $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
    41  
    42     echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
    43     foreach ($args as $langrecord) { 
    44         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
    45         transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . 
    46         "</a>"; 
    47     } 
    48     echo "</div>"; 
    49 } 
    5055?> 
  • trunk/WordPress/plugin/transposh/widgets/flags/tpw_flags_css.php

    r500 r674  
    2222 */ 
    2323 
    24 /** 
    25  * This function allows the widget to tell the invoker if it needs to calculate different urls per language, here it is needed 
    26  * @return boolean 
    27  */ 
    28 function tp_widget_needs_post_url() { 
    29     return true; 
     24class tpw_flags_css extends transposh_base_widget { 
     25 
     26    /** 
     27     * Creates the list of flags (with css) 
     28     * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
     29     */ 
     30    static function tp_widget_do($args) { 
     31        echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
     32        foreach ($args as $langrecord) { 
     33            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
     34            transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) . 
     35            "</a>"; 
     36        } 
     37        echo "</div>"; 
     38    } 
     39 
    3040} 
    3141 
    32 /** 
    33  * Creates the list of flags (with css) 
    34  * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    35  */ 
    36 function tp_widget_do($args) { 
    37     echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
    38     foreach ($args as $langrecord) { 
    39         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
    40         transposh_utils::display_flag("", $langrecord['flag'], $langrecord['langorig'], true) . 
    41         "</a>"; 
    42     } 
    43     echo "</div>"; 
    44 } 
    4542?> 
  • trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags.php

    r500 r674  
    2222 */ 
    2323 
    24 /** 
    25  * This function allows the widget to tell the invoker if it needs to calculate different urls per language 
    26  * @return boolean 
    27  */ 
    28 function tp_widget_needs_post_url() { 
    29     return true; 
     24class tpw_list_with_flags extends transposh_base_widget { 
     25 
     26    /** 
     27     * Instructs usage of a different .css file 
     28     * @global transposh_plugin $my_transposh_plugin 
     29     */ 
     30    static function tp_widget_css($file, $dir, $url) { 
     31        wp_enqueue_style("flags/tpw_flags", "$url/widgets/flags/tpw_flags.css", array(), TRANSPOSH_PLUGIN_VER); 
     32    } 
     33 
     34    /** 
     35     * Creates the list of flags - followed by a language name link 
     36     * @global transposh_plugin $my_transposh_plugin 
     37     * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
     38     */ 
     39    static function tp_widget_do($args) { 
     40        global $my_transposh_plugin; 
     41        // we calculate the plugin path part, so we can link the images there 
     42        $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
     43 
     44        echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
     45        foreach ($args as $langrecord) { 
     46            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
     47            transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>"; 
     48            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 
     49        } 
     50        echo "</div>"; 
     51    } 
     52 
    3053} 
    3154 
    32 /** 
    33  * Instructs usage of a different .css file 
    34  * @global transposh_plugin $my_transposh_plugin 
    35  */ 
    36 function tp_widget_css() { 
    37     global $my_transposh_plugin; 
    38     wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags.css", array(), TRANSPOSH_PLUGIN_VER); 
    39 } 
    40  
    41 /** 
    42  * Creates the list of flags - followed by a language name link 
    43  * @global transposh_plugin $my_transposh_plugin 
    44  * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    45  */ 
    46 function tp_widget_do($args) { 
    47     global $my_transposh_plugin; 
    48     // we calculate the plugin path part, so we can link the images there 
    49     $plugpath = parse_url($my_transposh_plugin->transposh_plugin_url, PHP_URL_PATH); 
    50  
    51     echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
    52     foreach ($args as $langrecord) { 
    53         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
    54         transposh_utils::display_flag("$plugpath/img/flags", $langrecord['flag'], $langrecord['langorig'], false) . "</a>"; 
    55         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 
    56     } 
    57     echo "</div>"; 
    58 } 
    5955?> 
  • trunk/WordPress/plugin/transposh/widgets/flagslist/tpw_list_with_flags_css.php

    r531 r674  
    2222 */ 
    2323 
    24 /** 
    25  * This function allows the widget to tell the invoker if it needs to calculate different urls per language 
    26  * @return boolean 
    27  */ 
    28 function tp_widget_needs_post_url() { 
    29     return true; 
     24class tpw_list_with_flags_css extends transposh_base_widget { 
     25 
     26    /** 
     27     * Instructs usage of a different .css file 
     28     * @global transposh_plugin $my_transposh_plugin 
     29     */ 
     30    static function tp_widget_css($file, $dir, $url) { 
     31        wp_enqueue_style("flags/tpw_flags_css", "$url/widgets/flags/tpw_flags_css.css", array(), TRANSPOSH_PLUGIN_VER); 
     32    } 
     33 
     34    /** 
     35     * Creates the list of flags (using css sprites) - followed by a language name link 
     36     * @global transposh_plugin $my_transposh_plugin 
     37     * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
     38     */ 
     39    static function tp_widget_do($args) { 
     40        echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
     41        foreach ($args as $langrecord) { 
     42            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
     43            transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], true) . '</a>'; 
     44            echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 
     45        } 
     46        echo "</div>"; 
     47    } 
     48 
    3049} 
    3150 
    32 /** 
    33  * Instructs usage of a different .css file 
    34  * @global transposh_plugin $my_transposh_plugin 
    35  */ 
    36 function tp_widget_css() { 
    37     global $my_transposh_plugin; 
    38     wp_enqueue_style("transposh_widget", "{$my_transposh_plugin->transposh_plugin_url}/widgets/flags/tpw_flags_css.css", array(), TRANSPOSH_PLUGIN_VER); 
    39 } 
    40  
    41 /** 
    42  * Creates the list of flags (using css sprites) - followed by a language name link 
    43  * @global transposh_plugin $my_transposh_plugin 
    44  * @param array $args - http://trac.transposh.org/wiki/WidgetWritingGuide#functiontp_widgets_doargs 
    45  */ 
    46 function tp_widget_do($args) { 
    47     echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >"; 
    48     foreach ($args as $langrecord) { 
    49         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . 
    50         transposh_utils::display_flag('', $langrecord['flag'], $langrecord['langorig'], true) . '</a>'; 
    51         echo "<a href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '' ) . '>' . "{$langrecord['langorig']}</a><br/>"; 
    52     } 
    53     echo "</div>"; 
    54 } 
    5551?> 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r667 r674  
    130130        $this->transposh->options->set_google_key($_POST[GOOGLE_TRANSLATE_KEY]); 
    131131        $this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]); 
     132        // frontend stuff 
     133        $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 
     134        $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 
     135        $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 
     136        $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 
    132137 
    133138        // handle change of schedule for backup to daily 
     
    196201        //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 
    197202        add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), $this->pagehook, 'side', 'core'); 
    198         add_meta_box('transposh-sidebox-widget', __('Widget settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_widget_content'), $this->pagehook, 'side', 'core'); 
    199203        add_meta_box('transposh-sidebox-news', __('Plugin news', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_news_content'), $this->pagehook, 'side', 'core'); 
    200204        add_meta_box('transposh-sidebox-stats', __('Plugin stats', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_stats_content'), $this->pagehook, 'side', 'core'); 
     
    203207        add_meta_box('transposh-contentbox-translation', __('Translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core'); 
    204208        add_meta_box('transposh-contentbox-autotranslation', __('Automatic translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core'); 
     209        add_meta_box('transposh-contentbox-frontend', __('Frontend settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_frontend_content'), $this->pagehook, 'normal', 'core'); 
    205210        add_meta_box('transposh-contentbox-general', __('Generic settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core'); 
    206211        add_meta_box('transposh-contentbox-database', __('Database maintenance', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core'); 
     
    302307        // donate with PayPal 
    303308        echo '</ul>'; 
    304     } 
    305  
    306     function on_sidebox_widget_content($data) { 
    307         $this->transposh->widget->transposh_widget_control(); 
    308309    } 
    309310 
     
    423424    } 
    424425 
     426    private function checkbox($id, $value, $head, $text) { 
     427        echo '<h4>' . $head . '</h4>'; 
     428        echo '<input type="checkbox" value="1" name="' . $id . '" ' . $this->checked($value) . '/> ' . $text; 
     429    } 
     430 
    425431    function on_contentbox_translation_content($data) { 
    426432        /* 
     
    440446         * Disabled by default. 
    441447         */ 
    442         echo '<h4>' . __('Enable default language translation', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    443         echo '<input type="checkbox" value="1" name="' . ENABLE_DEFAULT_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_default_translate()) . '/> ' . 
    444         __('Allow translation of default language - useful for sites with more than one major language', TRANSPOSH_TEXT_DOMAIN); 
     448        $this->checkbox(ENABLE_DEFAULT_TRANSLATE, $this->transposh->options->get_enable_default_translate(), __('Enable default language translation', TRANSPOSH_TEXT_DOMAIN), __('Allow translation of default language - useful for sites with more than one major language', TRANSPOSH_TEXT_DOMAIN)); 
    445449 
    446450        /** 
     
    449453         * @since 0.3.6 
    450454         */ 
    451         echo '<h4>' . __('Enable search in translated languages', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    452         echo '<input type="checkbox" value="1" name="' . ENABLE_SEARCH_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_search_translate()) . '/> ' . 
    453         __('Allow search of translated languages (and the original language)', TRANSPOSH_TEXT_DOMAIN); 
     455        $this->checkbox(ENABLE_SEARCH_TRANSLATE, $this->transposh->options->get_enable_search_translate(), __('Enable search in translated languages', TRANSPOSH_TEXT_DOMAIN), __('Allow search of translated languages (and the original language)', TRANSPOSH_TEXT_DOMAIN)); 
    454456 
    455457        /** 
     
    458460         * @since 0.5.3 
    459461         */ 
    460         echo '<h4>' . __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN) . ')</h4>'; 
    461         echo '<input type="checkbox" value="1" name="' . ENABLE_URL_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_url_translate()) . '/> ' . 
    462         __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN); 
     462        $this->checkbox(ENABLE_URL_TRANSLATE, $this->transposh->options->get_enable_url_translate(), __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN)); 
    463463 
    464464        /** 
     
    467467         * @since 0.6.4 
    468468         */ 
    469         echo '<h4>' . __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN) . ')</h4>'; 
    470         echo '<input type="checkbox" value="1" name="' . TRANSPOSH_GETTEXT_INTEGRATION . '" ' . $this->checked($this->transposh->options->get_transposh_gettext_integration()) . '/> ' . 
    471         __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN); 
     469        $this->checkbox(TRANSPOSH_GETTEXT_INTEGRATION, $this->transposh->options->get_transposh_gettext_integration(), __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN)); 
    472470 
    473471        /** 
     
    476474         * @since 0.7.5 
    477475         */ 
    478         echo '<h4>' . __('Enable override for default locale', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    479         echo '<input type="checkbox" value="1" name="' . TRANSPOSH_DEFAULT_LOCALE_OVERRIDE . '" ' . $this->checked($this->transposh->options->get_transposh_default_locale_override()) . '/> ' . 
    480         __('Enable overriding the default locale that is set in WP_LANG on default languages pages (such as untranslated pages and admin pages)', TRANSPOSH_TEXT_DOMAIN); 
     476        $this->checkbox(TRANSPOSH_DEFAULT_LOCALE_OVERRIDE, $this->transposh->options->get_transposh_default_locale_override(), __('Enable override for default locale', TRANSPOSH_TEXT_DOMAIN), __('Enable overriding the default locale that is set in WP_LANG on default languages pages (such as untranslated pages and admin pages)', TRANSPOSH_TEXT_DOMAIN)); 
    481477    } 
    482478 
     
    487483         * Enabled by default. 
    488484         */ 
    489         echo '<h4>' . __('Enable automatic translation', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    490         echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_translate()) . '/> ' . 
    491         __('Allow automatic translation of pages', TRANSPOSH_TEXT_DOMAIN); 
     485        $this->checkbox(ENABLE_AUTO_TRANSLATE, $this->transposh->options->get_enable_auto_translate(), __('Enable automatic translation', TRANSPOSH_TEXT_DOMAIN), __('Allow automatic translation of pages', TRANSPOSH_TEXT_DOMAIN)); 
    492486 
    493487        /** 
     
    495489         * Disabled by default. 
    496490         *  @since 0.3.5 */ 
    497         echo '<h4>' . __('Enable automatic translation after posting', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    498         echo '<input type="checkbox" value="1" name="' . ENABLE_AUTO_POST_TRANSLATE . '" ' . $this->checked($this->transposh->options->get_enable_auto_post_translate()) . '/> ' . 
    499         __('Do automatic translation immediately after a post has been published', TRANSPOSH_TEXT_DOMAIN); 
     491        $this->checkbox(ENABLE_AUTO_POST_TRANSLATE, $this->transposh->options->get_enable_auto_post_translate(), __('Enable automatic translation after posting', TRANSPOSH_TEXT_DOMAIN), __('Do automatic translation immediately after a post has been published', TRANSPOSH_TEXT_DOMAIN)); 
    500492 
    501493        /** 
     
    523515    } 
    524516 
     517    function on_contentbox_frontend_content($data) { 
     518        $this->checkbox(WIDGET_PROGRESSBAR, $this->transposh->options->get_widget_progressbar(), __('Show progress bar', TRANSPOSH_TEXT_DOMAIN), __('Show progress bar when a client triggers automatic translation', TRANSPOSH_TEXT_DOMAIN)); 
     519 
     520        $this->checkbox(WIDGET_ALLOW_SET_DEFLANG, $this->transposh->options->get_widget_allow_set_default_language(), __('Allow user to set current language as default', TRANSPOSH_TEXT_DOMAIN), __('Widget will allow setting this language as user default', TRANSPOSH_TEXT_DOMAIN)); 
     521 
     522        $this->checkbox(WIDGET_REMOVE_LOGO_FOR_AD, $this->transposh->options->get_widget_remove_logo(), __('Remove transposh logo (see <a href="http://transposh.org/logoterms">terms</a>)', TRANSPOSH_TEXT_DOMAIN), __('Transposh logo will not appear on widget', TRANSPOSH_TEXT_DOMAIN)); 
     523 
     524        echo '<h4>' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
     525        echo '<label for="' . WIDGET_THEME . '">' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . 
     526        '<select id="transposh-style" name="' . WIDGET_THEME . '">'; 
     527        foreach (transposh_consts::$jqueryui_themes as $theme) { 
     528            $selected = ($this->transposh->options->get_widget_theme() == $theme) ? ' selected="selected"' : ''; 
     529            echo "<option value=\"$theme\"$selected>{$theme}</option>"; 
     530        } 
     531        echo '</select>' . 
     532        '</label>'; 
     533    } 
     534 
    525535    function on_contentbox_generic_content($data) { 
    526536        /* 
     
    528538         * When disabled only parameters will be used to identify the current language. 
    529539         */ 
    530         echo '<h4>' . __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    531         echo '<input type="checkbox" value="1" name="' . ENABLE_PERMALINKS . '" ' . $this->checked($this->transposh->options->get_enable_permalinks()) . '/> ' . 
    532         __('Rewrite URLs to be search engine friendly, ' . 
    533                 'e.g.  (http://transposh.org/<strong>en</strong>). ' . 
    534                 'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN); 
     540        $this->checkbox(ENABLE_PERMALINKS, $this->transposh->options->get_enable_permalinks(), __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN), __('Rewrite URLs to be search engine friendly, ' . 
     541                        'e.g.  (http://transposh.org/<strong>en</strong>). ' . 
     542                        'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN)); 
    535543 
    536544        /* 
    537545         * Insert the option to enable/disable pushing of scripts to footer. 
    538          * Works on wordpress 2.8 and up 
    539          */ 
    540         if (floatval($GLOBALS['wp_version']) >= 2.8) { 
    541             echo '<h4>' . __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    542             echo '<input type="checkbox" value="1" name="' . ENABLE_FOOTER_SCRIPTS . '" ' . $this->checked($this->transposh->options->get_enable_footer_scripts()) . '/> ' . 
    543             __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 
    544                     'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN); 
    545         } 
     546         * Works on wordpress 2.8 and up (but we no longer care...) 
     547         */ 
     548        $this->checkbox(ENABLE_FOOTER_SCRIPTS, $this->transposh->options->get_enable_footer_scripts(), __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN), __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 
     549                        'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN)); 
    546550 
    547551        /** 
    548552         * Insert the option to enable/disable language auto-detection 
    549553         * @since 0.3.8 */ 
    550         echo '<h4>' . __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    551         echo '<input type="checkbox" value="1" name="' . ENABLE_DETECT_LANG_AND_REDIRECT . '" ' . $this->checked($this->transposh->options->get_enable_detect_language()) . '/> ' . 
    552         __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 
    553                 'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN); 
     554        $this->checkbox(ENABLE_DETECT_LANG_AND_REDIRECT, $this->transposh->options->get_enable_detect_language(), __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN), __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 
     555                        'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN)); 
    554556 
    555557        /** 
    556558         * Insert the option to enable/disable statics collection 
    557          * @since 0.3.8 */ 
    558         echo '<h4>' . __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 
    559         echo '<input type="checkbox" value="1" name="' . TRANSPOSH_COLLECT_STATS . '" ' . $this->checked($this->transposh->options->get_transposh_collect_stats()) . '/> ' . 
    560         __('This option enables collection of statistics by transposh that will be used to improve the product. ', TRANSPOSH_TEXT_DOMAIN); 
     559         * @since 0.7.6 */ 
     560        $this->checkbox(TRANSPOSH_COLLECT_STATS, $this->transposh->options->get_transposh_collect_stats(), __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN), __('This option enables collection of statistics by transposh that will be used to improve the product. ', TRANSPOSH_TEXT_DOMAIN)); 
    561561 
    562562        /* WIP2 
  • trunk/WordPress/plugin/transposh/wp/transposh_options.php

    r664 r674  
    2323//Option to enable/disable msn translation 
    2424define('OLD_ENABLE_MSN_TRANSLATE', 'enable_msntranslate'); 
     25//Option defining transposh widget file used @since 0.5.6 
     26define('OLD_WIDGET_FILE', 'widget_file'); //unset!!! 
    2527//Option to store the msn API key 
    2628define('MSN_TRANSLATE_KEY', 'msn_key'); 
     
    6163//Option defining the default language 
    6264define('DEFAULT_LANG', 'default_language'); 
    63 //Option defining transposh widget file used @since 0.5.6 
    64 define('WIDGET_FILE', 'widget_file'); 
    6565//Option allowing progress bar display 
    6666define('WIDGET_PROGRESSBAR', 'widget_progressbar'); 
     
    8484    /** @var array storing all our options */ 
    8585    private $options = array(); 
     86 
    8687    /** @var boolean set to true if any option was changed */ 
    8788    private $changed = false; 
     
    184185 
    185186    /** 
    186      * return file name of the widget used 
    187      * @since 0.5.6 
    188      * @return string 
    189      */ 
    190     function get_widget_file() { 
    191         return $this->options[WIDGET_FILE]; 
    192     } 
    193  
    194     /** 
    195187     * return theme 
    196188     * @since 0.7.0 
     
    331323 
    332324    /** 
    333      * Set the widget file used 
    334      * @since 0.5.6 
    335      * @param string $val 
    336      */ 
    337     function set_widget_file($val) { 
    338         $this->set_value($val, $this->options[WIDGET_FILE]); 
    339     } 
    340  
    341     /** 
    342325     * Set the widget theme 
    343326     * @since 0.7.0 
     
    388371    } 
    389372 
    390       function set_msn_key($val) { 
     373    function set_msn_key($val) { 
    391374        $this->set_value($val, $this->options[MSN_TRANSLATE_KEY]); 
    392375    } 
    393376 
    394           function set_google_key($val) { 
     377    function set_google_key($val) { 
    395378        $this->set_value($val, $this->options[GOOGLE_TRANSLATE_KEY]); 
    396379    } 
  • trunk/WordPress/plugin/transposh/wp/transposh_widget.php

    r667 r674  
    1313 
    1414/* 
    15  * Provides the sidebar widget for selecting a language and switching between edit/view 
     15 * Provides the sidebar widget instance for selecting a language and switching between edit/view 
    1616 * mode. 
    1717 */ 
    1818 
    19 //Define widget file prefix 
     19//Define subwidget files prefix 
    2020define('TRANSPOSH_WIDGET_PREFIX', 'tpw_'); 
    2121 
    22 //class that reperesent the complete plugin 
    23 class transposh_plugin_widget { 
     22/** 
     23 * Class for subwidgets to inherit from 
     24 */ 
     25class transposh_base_widget { 
     26 
     27    /** 
     28     * Function that performs the actual subwidget rendering 
     29     */ 
     30    static function tp_widget_do() { 
     31        echo "you should override this function in your widget"; 
     32    } 
     33 
     34    /** 
     35     * Attempts inclusion of css needed for the subwidget 
     36     * @param string $file 
     37     * @param string $plugin_dir 
     38     * @param string $plugin_url  
     39     */ 
     40    static function tp_widget_css($file, $plugin_dir, $plugin_url) { 
     41        $basefile = substr($file, 0, -4); 
     42        $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $basefile . ".css"; 
     43        if (file_exists($plugin_dir . $widget_css)) { 
     44            wp_enqueue_style($basefile, $plugin_url . '/' . $widget_css, '', TRANSPOSH_PLUGIN_VER); 
     45        } 
     46    } 
     47 
     48    /** 
     49     * Attempts inclusion of javascript needed for the subwidget 
     50     * @param string $file 
     51     * @param string $plugin_dir 
     52     * @param string $plugin_url  
     53     */ 
     54    static function tp_widget_js($file, $plugin_dir, $plugin_url) { 
     55        $basefile = substr($file, 0, -4); 
     56        $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $basefile . ".js"; 
     57        if (file_exists($plugin_dir . $widget_js)) { 
     58            wp_enqueue_script('transposh_widget', $plugin_url . '/' . $widget_js, '', TRANSPOSH_PLUGIN_VER); 
     59        } 
     60    } 
     61 
     62} 
     63 
     64// END class 
     65//class that reperesent the complete widget 
     66class transposh_plugin_widget extends WP_Widget { 
    2467 
    2568    /** @var transposh_plugin Container class */ 
    2669    private $transposh; 
    27     /** @var string Contains the name of the used widget file */ 
    28     public $base_widget_file_name; 
    29  
    30     //constructor of class, PHP4 compatible construction for backward compatibility 
    31     function transposh_plugin_widget(&$transposh) { 
    32         //Register callback for WordPress events 
    33         $this->transposh = &$transposh; 
    34         add_action('init', array(&$this, 'init_transposh'), 1); 
    35         add_action('widgets_init', array(&$this, 'transposh_widget_init')); 
    36     } 
    37  
    38     /** 
    39      * Intercept init calls to see if it was posted by the widget. 
    40      */ 
    41     function init_transposh() { 
    42         if (isset($_POST['transposh_widget_posted'])) { 
    43             logger("Enter", 4); 
    44  
    45             $ref = getenv('HTTP_REFERER'); 
    46             $lang = $_POST[LANG_PARAM]; 
    47             if ($lang == '') { 
    48                 $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url); 
    49             } 
    50             if ($lang == $this->transposh->options->get_default_language() || $lang == "none") 
    51                     $lang = ''; 
    52             logger("Widget referrer: $ref, lang: $lang", 4); 
    53  
    54             // first, we might need to get the original url back 
    55             if ($this->transposh->options->get_enable_url_translate()) { 
    56                 $ref = transposh_utils::get_original_url($ref, $this->transposh->home_url, transposh_utils::get_language_from_url($ref, $this->transposh->home_url), array($this->transposh->database, 'fetch_original')); 
    57             } 
    58  
    59             //remove existing language settings. 
    60             $ref = transposh_utils::cleanup_url($ref, $this->transposh->home_url); 
    61             logger("cleaned referrer: $ref, lang: $lang", 4); 
    62  
    63             if ($lang && $this->transposh->options->get_enable_url_translate()) { 
    64                 // and then, we might have to translate it 
    65                 $ref = transposh_utils::translate_url($ref, $this->transposh->home_url, $lang, array(&$this->transposh->database, 'fetch_translation')); 
    66                 $ref = transposh_utils::urlencode($ref); 
    67                 logger("translated to referrer: $ref, lang: $lang", 3); 
    68             } 
    69             $ref = transposh_utils::rewrite_url_lang_param($ref, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $_POST[EDIT_PARAM]); 
    70  
    71             logger("Widget redirect url: $ref", 3); 
    72  
    73             $this->transposh->tp_redirect($ref); 
    74             exit; 
    75         } 
    76     } 
    77  
    78     /** 
    79      * Register the widget. 
    80      */ 
    81     function transposh_widget_init() { 
    82         logger('Enter', 4); 
    83         if (!function_exists('register_sidebar_widget')) { 
    84             return; 
    85         } 
    86  
    87         // Register widget 
    88         wp_register_sidebar_widget('Transposh', __('Transposh', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'transposh_widget'), array('description' => __('Transposh language selection widget', TRANSPOSH_TEXT_DOMAIN))); 
    89  
    90         // Register widget control 
    91         wp_register_widget_control('Transposh', __('Transposh', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'transposh_widget_control')); 
    92  
    93         // Register callback for widget's css and js 
    94         add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css')); 
    95         add_action('wp_print_scripts', array(&$this, 'add_transposh_widget_js')); 
    96     } 
    97  
    98     /** 
    99      * Loads the widget code 
    100      */ 
    101     function load_widget() { 
    102         // avoid dual loadings 
    103         if ($this->base_widget_file_name) return; 
    104  
    105         $file = $this->transposh->options->get_widget_file(); 
     70 
     71    /** @staticvar boolean Contains the fact that this is our first run */ 
     72    static $first_init = true; 
     73 
     74    /** @staticvar int Counts call to the widget do to generate unique IDs */ 
     75    static $draw_calls = ''; 
     76 
     77    function transposh_plugin_widget() { 
     78        // We get the transposh details from the global variable 
     79        $this->transposh = &$GLOBALS['my_transposh_plugin']; 
     80 
     81        // Widget control defenitions 
     82        $widget_ops = array('classname' => 'widget_transposh', 'description' => __('Transposh language selection widget', TRANSPOSH_TEXT_DOMAIN)); 
     83        $control_ops = array('width' => 200, 'height' => 300); 
     84        $this->WP_Widget('transposh', __('Transposh'), $widget_ops, $control_ops); 
     85 
     86        // We only need to add those actions once, makes life simpler 
     87        if (is_active_widget(false, false, $this->id_base) && self::$first_init) { 
     88            self::$first_init = false; 
     89            add_action('widgets_init', create_function('', 'register_widget("transposh_plugin_widget");')); 
     90            add_action('wp_print_styles', array(&$this, 'add_transposh_widget_css')); 
     91            add_action('wp_print_scripts', array(&$this, 'add_transposh_widget_js')); 
     92        } 
     93    } 
     94 
     95    /** 
     96     * Saves the widgets settings. (override of wp_widget) 
     97     */ 
     98    function update($new_instance, $old_instance) { 
     99        $instance = $old_instance; 
     100        logger($instance); 
     101        logger($new_instance); 
     102        $instance['title'] = strip_tags(stripslashes($new_instance['title'])); 
     103        $instance['widget_file'] = strip_tags(stripslashes($new_instance['widget_file'])); 
     104        return $instance; 
     105    } 
     106 
     107    /** 
     108     * Creates the edit form for the widget. (override of wp_widget) 
     109     * 
     110     */ 
     111    function form($instance) { 
     112        // Defaults 
     113        $instance = wp_parse_args((array) $instance, array('title' => 'Translation')); 
     114 
     115        // Output the options - title first 
     116        $title = htmlspecialchars($instance['title']); 
     117 
     118        echo '<p><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>'; 
     119 
     120        // Followed by subwisgets selection 
     121        $widgets = $this->get_widgets(); 
     122 
     123        echo '<p><label for="' . $this->get_field_name('widget_file') . '">' . __('Style:', TRANSPOSH_TEXT_DOMAIN) . 
     124        '<select id="' . $this->get_field_id('widget_file') . '" name="' . $this->get_field_name('widget_file') . '">'; 
     125        foreach ($widgets as $file => $widget) { 
     126            logger($widget, 4); 
     127            $selected = ($instance['widget_file'] == $file) ? ' selected="selected"' : ''; 
     128            echo "<option value=\"$file\"$selected>{$widget['Name']}</option>"; 
     129        } 
     130        echo '</select>' . 
     131        '</label></p>' 
     132        ; 
     133    } 
     134 
     135    /** 
     136     * Loads the subwidget class code 
     137     */ 
     138    function load_widget($file) { 
    106139        $widget_src = $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file; 
    107140        if ($file && file_exists($widget_src)) { 
     
    111144            include_once $this->transposh->transposh_plugin_dir . TRANSPOSH_DIR_WIDGETS . '/' . $file; 
    112145        } 
    113         $this->base_widget_file_name = substr($file, 0, -4); 
     146        return substr($file, strpos($file, '/') + 1, -4); 
    114147    } 
    115148 
     
    117150     * Add custom css, i.e. transposh_widget.css, flags now override widget 
    118151     */ 
    119     function add_transposh_widget_css() { //TODO ! goway 
    120         $this->load_widget(); 
    121  
    122         if (function_exists('tp_widget_css')) { 
    123             tp_widget_css(); 
    124         } else { 
    125             $widget_css = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".css"; 
    126             if (file_exists($this->transposh->transposh_plugin_dir . $widget_css)) { 
    127                 wp_enqueue_style('transposh_widget', $this->transposh->transposh_plugin_url . '/' . $widget_css, '', TRANSPOSH_PLUGIN_VER); 
    128             } 
    129         } 
    130  
     152    function add_transposh_widget_css() { 
     153        // first we discover all active widgets of ours, and aggregate the files 
     154        $settings = $this->get_settings(); 
     155        foreach ($settings as $key => $value) { 
     156            if (is_active_widget(false, $this->id_base . '-' . $key, $this->id_base)) { 
     157                $activewidgets[$value['widget_file']] = true; 
     158            } 
     159        } 
     160 
     161        // we than load the classes and perform the css queueing 
     162        foreach ($activewidgets as $key => $v) { 
     163            $class = $this->load_widget($key); 
     164            $class::tp_widget_css($key, $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url); 
     165        } 
    131166        logger('Added transposh_widget_css', 4); 
    132167    } 
    133168 
    134169    /** 
    135      * Add custom css, i.e. transposh_widget.css, flags now override widget 
    136      */ 
    137     function add_transposh_widget_js() { //TODO ! goway 
    138         $this->load_widget(); 
    139  
    140         if (function_exists('tp_widget_js')) { 
    141             tp_widget_js(); 
    142         } else { 
    143             $widget_js = TRANSPOSH_DIR_WIDGETS . '/' . $this->base_widget_file_name . ".js"; 
    144             if (file_exists($this->transposh->transposh_plugin_dir . $widget_js)) { 
    145                 wp_enqueue_script('transposh_widget', $this->transposh->transposh_plugin_url . '/' . $widget_js, '', TRANSPOSH_PLUGIN_VER); 
    146             } 
     170     * Add custom js, i.e. transposh_widget.js 
     171     */ 
     172    function add_transposh_widget_js() { 
     173        $settings = $this->get_settings(); 
     174        foreach ($settings as $key => $value) { 
     175            if (is_active_widget(false, $this->id_base . '-' . $key, $this->id_base)) { 
     176                $activewidgets[$value['widget_file']] = true; 
     177            } 
     178        } 
     179 
     180        // we than load the classes and perform the css queueing 
     181        foreach ($activewidgets as $key => $v) { 
     182            $class = $this->load_widget($key); 
     183            $class::tp_widget_js($key, $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url); 
    147184        } 
    148185        logger('Added transposh_widget_js', 4); 
    149186    } 
    150187 
    151     function create_widget_args($calc_url, $clean_page_url) { 
     188    /** 
     189     * Calculate arguments needed by subwidgets 
     190     * @param string $clean_page_url 
     191     * @return array 
     192     */ 
     193    function create_widget_args($clean_page_url) { 
     194        // only calculate urls once even for multiple instances 
     195        static $widget_args; 
     196        if (is_array($widget_args)) return $widget_args; 
    152197        $widget_args = array(); 
    153198        $page_url = ''; 
    154199        if (is_404()) { 
    155             $clean_page_url = transposh_utils::cleanup_url($this->transposh->home_url,$this->transposh->home_url,true); 
     200            $clean_page_url = transposh_utils::cleanup_url($this->transposh->home_url, $this->transposh->home_url, true); 
    156201        } 
    157202        // loop on the languages 
     
    163208                    ($this->transposh->options->is_editable_language($code) && $this->transposh->is_translator()) || 
    164209                    ($this->transposh->options->is_default_language($code))) { 
    165                 if ($calc_url) { 
    166                     if ($this->transposh->options->get_enable_url_translate() && !$this->transposh->options->is_default_language($code)) { 
    167                         $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation')); 
    168                     } else { 
    169                         $page_url = $clean_page_url; 
    170                     } 
    171                     // clean $code in default lanaguge 
    172                     $page_url = transposh_utils::rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($code) ? '' : $code, $this->transposh->edit_mode); 
     210                // now we alway do this... maybe cache this to APC/Memcache 
     211                if ($this->transposh->options->get_enable_url_translate() && !$this->transposh->options->is_default_language($code)) { 
     212                    $page_url = transposh_utils::translate_url($clean_page_url, '', $code, array(&$this->transposh->database, 'fetch_translation')); 
     213                } else { 
     214                    $page_url = $clean_page_url; 
    173215                } 
     216                // clean $code in default lanaguge 
     217                $page_url = transposh_utils::rewrite_url_lang_param($page_url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($code) ? '' : $code, $this->transposh->edit_mode); 
    174218                $widget_args[] = array( 
    175219                    'lang' => $langname, 
     
    188232     * @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc 
    189233     */ 
    190     function transposh_widget($args) { 
    191         $this->load_widget(); 
    192  
    193         // hmmm, this should actually prepare all vars needed, include the correct widget and send the vars to that function, 
    194         $calc_url = false; // By default, avoid calculating the urls 
    195         if (function_exists('tp_widget_needs_post_url')) 
    196                 $calc_url = tp_widget_needs_post_url(); 
    197  
    198         $clean_page = $this->transposh->get_clean_url(); 
    199  
    200         logger("WIDGET: clean page url: $clean_page", 4); 
    201  
    202         $widget_args = $this->create_widget_args($calc_url, $clean_page); 
    203         // at this point the widget args are ready 
    204  
    205         logger('Enter widget', 4); 
    206  
     234    function widget($args, $instance) { 
    207235        // extract args given by wordpress 
    208236        extract($args); 
    209237        logger($args, 4); 
    210238 
     239        // we load the class needed and get its base name for later 
     240        $class = $this->load_widget($instance['widget_file']); 
     241 
     242        $clean_page = $this->transposh->get_clean_url(); 
     243 
     244        logger("WIDGET: clean page url: $clean_page", 4); 
     245 
     246        $widget_args = $this->create_widget_args($clean_page); 
     247        // at this point the widget args are ready 
     248 
     249        logger('Enter widget', 4); 
     250 
    211251        // widget default title 
    212         echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; 
    213  
    214         // the widget is inside a form used for posting a language change or edit request 
    215         echo '<form id="tp_form" action="' . $clean_page . '" method="post">'; 
     252        //echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; - hmm? po/mo? 
     253        echo $before_widget; 
     254        if ($instance['title']) { 
     255            echo $before_title . __($instance['title'], TRANSPOSH_TEXT_DOMAIN) . $after_title; 
     256        } 
    216257 
    217258        // actually run the external widget code 
    218         tp_widget_do($widget_args); 
     259        $class::tp_widget_do($widget_args); 
    219260 
    220261        //at least one language showing - add the edit box if applicable 
     
    223264            if ($this->transposh->options->get_widget_allow_set_default_language()) { 
    224265                If ((isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language) || (!isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language))) { 
    225                     echo '<a id="' . SPAN_PREFIX . 'setdeflang" onClick="return false;" href="' . admin_url('admin-ajax.php') . '?action=tp_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 
     266                    echo '<a id="' . SPAN_PREFIX . 'setdeflang' . self::$draw_calls . '" class="' . SPAN_PREFIX . 'setdeflang' . '" onClick="return false;" href="' . admin_url('admin-ajax.php') . '?action=tp_cookie_bck">' . __('Set as default language', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 
    226267                } 
    227268            } 
    228269            // add the edit checkbox only for translators for languages marked as editable 
     270            $ref = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->target_language, !$this->transposh->edit_mode); 
    229271            if ($this->transposh->is_editing_permitted()) { 
    230272                echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' . 
    231                 ($this->transposh->edit_mode ? 'checked="checked"' : '') . 
    232                 ' onclick="this.form.submit();"/>&nbsp;Edit Translation'; 
    233             } 
    234  
    235             echo '<input type="hidden" name="transposh_widget_posted" value="1"/>'; 
     273                ($this->transposh->edit_mode ? 'checked="checked" ' : '') . 
     274                ' onclick="document.location.href=\'' . $ref . '\';"/>&nbsp;Edit Translation'; 
     275            } 
    236276        } else { 
    237277            //no languages configured - error message 
    238278            echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>'; 
    239279        } 
    240  
    241         echo "</form>"; 
    242280 
    243281        // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget 
     
    278316        } 
    279317 
    280         echo '<div id="' . SPAN_PREFIX . 'credit">'; 
     318        echo '<div id="' . SPAN_PREFIX . 'credit' . self::$draw_calls . '">'; 
    281319        if (!$this->transposh->options->get_widget_remove_logo()) { 
    282320            echo 'by <a href="http://tran' . 'sposh.org/' . $extralang . '"><img height="16" width="16" src="' . 
     
    285323        echo '</div>'; 
    286324        echo $after_widget; 
    287     } 
    288  
    289     function transposh_widget_post($save = true) { 
    290         logger($_POST); 
    291         logger('handled widget post'); 
    292         $this->transposh->options->set_widget_file($_POST[WIDGET_FILE]); 
    293         $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 
    294         $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 
    295         $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 
    296         $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 
    297         if ($save) $this->transposh->options->update_options(); 
    298         // Avoid coming here twice... 
    299         unset($_POST['transposh-submit']); 
     325        // increase the number of calls for unique IDs 
     326        self::$draw_calls++; 
    300327    } 
    301328 
     
    353380    } 
    354381 
    355     /** 
    356      * This is the widget control, allowing the selection of presentation type. 
    357      */ 
    358     function transposh_widget_control() { 
    359         if (isset($_POST['transposh-submit'])) $this->transposh_widget_post(); 
    360         $themes = array('base', 'black-tie', 'blitzer', 'cupertino', 'dark-hive', 'dot-luv', 'eggplant', 'excite-bike', 'flick', 
    361             'hot-sneaks', 'humanity', 'le-frog', 'mint-choc', 'overcast', 'pepper-grinder', 'redmond', 'smoothness', 'south-street', 
    362             'start', 'sunny', 'swanky-purse', 'trontastic', 'ui-darkness', 'ui-lightness', 'vader'); 
    363  
    364         $widgets = $this->get_widgets(); 
    365  
    366         echo '<p><label for="' . WIDGET_FILE . '">' . __('Style:', TRANSPOSH_TEXT_DOMAIN) . '<br/>' . 
    367         '<select id="transposh-style" name="' . WIDGET_FILE . '">'; 
    368         foreach ($widgets as $file => $widget) { 
    369             logger($widget, 4); 
    370             $selected = ($this->transposh->options->get_widget_file() == $file) ? ' selected="selected"' : ''; 
    371             echo "<option value=\"$file\"$selected>{$widget['Name']}</option>"; 
    372         } 
    373         echo '</select>' . 
    374         '</label></p>' . 
    375         '<p><label for="transposh-progress">' . __('Effects:', TRANSPOSH_TEXT_DOMAIN) . '</label><br/>' . 
    376         '<input type="checkbox" id="' . WIDGET_PROGRESSBAR . '" name="' . WIDGET_PROGRESSBAR . '"' . ($this->transposh->options->get_widget_progressbar() ? ' checked="checked"' : '') . '/>' . 
    377         '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Show progress bar when a client triggers automatic translation', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Show progress bar', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' . 
    378         '<input type="checkbox" id="' . WIDGET_ALLOW_SET_DEFLANG . '" name="' . WIDGET_ALLOW_SET_DEFLANG . '"' . ($this->transposh->options->get_widget_allow_set_default_language() ? ' checked="checked"' : '') . '/>' . 
    379         '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Widget will allow setting this language as user default', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Allow user to set current language as default', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' . 
    380         '<input type="checkbox" id="' . WIDGET_REMOVE_LOGO_FOR_AD . '" name="' . WIDGET_REMOVE_LOGO_FOR_AD . '"' . ($this->transposh->options->get_widget_remove_logo() ? ' checked="checked"' : '') . '/>' . 
    381         '<span style="border-bottom: 1px dotted #333; cursor: help; margin-left: 4px" title="' . esc_attr__('Transposh logo will not appear on widget', TRANSPOSH_TEXT_DOMAIN) . '">' . __('Remove transposh logo (see <a href="http://transposh.org/logoterms">terms</a>)', TRANSPOSH_TEXT_DOMAIN) . '</span><br/>' . 
    382         '</p>'; 
    383  
    384         echo '<p><label for="' . WIDGET_THEME . '">' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '<br/>' . 
    385         '<select id="transposh-style" name="' . WIDGET_THEME . '">'; 
    386         foreach ($themes as $theme) { 
    387             $selected = ($this->transposh->options->get_widget_theme() == $theme) ? ' selected="selected"' : ''; 
    388             echo "<option value=\"$theme\"$selected>{$theme}</option>"; 
    389         } 
    390         echo '</select>' . 
    391         '</label></p>' . 
    392         '<input type="hidden" name="transposh-submit" id="transposh-submit" value="1"/>'; 
    393     } 
    394  
    395382} 
    396383 
     
    399386 * @param array $args Not needed 
    400387 */ 
    401 function transposh_widget($args = array()) { 
    402     $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args); 
     388function transposh_widget($args = array(), $instance= array('title' => 'Translation')) { 
     389    $GLOBALS['my_transposh_plugin']->widget->transposh_widget($args, $instance); 
    403390} 
    404391 
Note: See TracChangeset for help on using the changeset viewer.