Example #1
0
 /**
  * Main function - actually translates a given HTML
  * @param string $string containing HTML
  * @return string Translated content is here
  */
 function fix_html($string)
 {
     // ready our stats
     $this->stats = new parserstats();
     // handler for possible json (buddypress)
     if ($this->might_json) {
         if ($string[0] == '{') {
             $jsoner = json_decode($string);
             if ($jsoner != null) {
                 tp_logger("json detected (buddypress?)", 4);
                 // currently we only handle contents (which buddypress heavily use)
                 if ($jsoner->contents) {
                     $jsoner->contents = $this->fix_html($jsoner->contents);
                     return json_encode($jsoner);
                 }
             }
         }
     }
     // create our dom
     $string = str_replace(chr(0xc2) . chr(0xa0), ' ', $string);
     // annoying NBSPs?
     $this->html = str_get_html($string);
     // mark translateable elements
     if ($this->html->find('html', 0)) {
         $this->html->find('html', 0)->lang = '';
     }
     // Document defined lang may be preset to correct lang, but should be ignored TODO: Better?
     $this->translate_tagging($this->html->root);
     // first fix the html tag itself - we might need to to the same for all such attributes with flipping
     if ($this->html->find('html', 0)) {
         if ($this->dir_rtl) {
             $this->html->find('html', 0)->dir = 'rtl';
         } else {
             $this->html->find('html', 0)->dir = 'ltr';
         }
     }
     if ($this->lang) {
         if ($this->html->find('html', 0)) {
             $this->html->find('html', 0)->lang = $this->lang;
         }
         // add support for <meta name="language" content="<lang>">
         if ($this->html->find('meta[name=language]')) {
             $this->html->find('meta[name=language]')->content = $this->lang;
         }
     }
     // not much point in further processing if we don't have a function that does it
     if ($this->fetch_translate_func == null) {
         return $this->html;
     }
     // fix feed
     if ($this->feed_fix) {
         // fix urls on feed
         tp_logger('fixing rss feed', 3);
         foreach (array('link', 'wfw:commentrss', 'comments') as $tag) {
             foreach ($this->html->find($tag) as $e) {
                 $e->innertext = htmlspecialchars(call_user_func_array($this->url_rewrite_func, array($e->innertext)));
                 // no need to translate anything here
                 unset($e->nodes);
             }
         }
         // guid is not really a url -- in some future, we can check if permalink is true and probably falsify it
         foreach ($this->html->find('guid') as $e) {
             $e->innertext = $e->innertext . '-' . $this->lang;
             unset($e->nodes);
         }
         // fix feed language
         $this->html->find('language', 0)->innertext = $this->lang;
         unset($this->html->find('language', 0)->nodes);
     } else {
         // since this is not a feed, we might have references to such in the <link rel="alternate">
         foreach ($this->html->find('link') as $e) {
             if (strcasecmp($e->rel, 'alternate') == 0 || strcasecmp($e->rel, 'canonical') == 0) {
                 $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
             }
         }
     }
     // try some prefetching... (//todo - maybe move directly to the phrase create)
     $originals = array();
     if ($this->prefetch_translate_func != null) {
         foreach ($this->html->find('text') as $e) {
             foreach ($e->nodes as $ep) {
                 if ($ep->phrase) {
                     $originals[$ep->phrase] = true;
                 }
             }
         }
         foreach (array('title', 'value') as $title) {
             foreach ($this->html->find('[' . $title . ']') as $e) {
                 if (isset($e->nodes)) {
                     foreach ($e->nodes as $ep) {
                         if ($ep->phrase) {
                             $originals[$ep->phrase] = true;
                         }
                     }
                 }
             }
         }
         foreach ($this->html->find('[content]') as $e) {
             foreach ($e->nodes as $ep) {
                 if ($ep->phrase) {
                     $originals[$ep->phrase] = true;
                 }
             }
         }
         // if we should split, we will split some urls for translation prefetching
         if ($this->split_url_func != null) {
             foreach ($this->atags as $e) {
                 foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) {
                     $originals[$part] = true;
                 }
             }
             foreach ($this->otags as $e) {
                 foreach (call_user_func_array($this->split_url_func, array($e->value)) as $part) {
                     $originals[$part] = true;
                 }
             }
         }
         call_user_func_array($this->prefetch_translate_func, array($originals, $this->lang));
     }
     //fix urls more
     // WORK IN PROGRESS
     /* foreach ($this->atags as $e) {
        $hrefspans = '';
        foreach (call_user_func_array($this->split_url_func, array($e->href)) as $part) {
        // fix - not for dashes
        list ($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($part, $this->lang));
        $hrefspans .= $this->create_edit_span($part, $translated_text, $source, true);
        }
        $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
        $e->outertext .= $hrefspans;
        } */
     // fix urls...
     foreach ($this->atags as $e) {
         if ($e->href) {
             $e->href = call_user_func_array($this->url_rewrite_func, array($e->href));
         }
     }
     foreach ($this->otags as $e) {
         if ($e->value) {
             $e->value = call_user_func_array($this->url_rewrite_func, array($e->value));
         }
     }
     // this is used to reserve spans we cannot add directly (out of body, metas, etc)
     $hiddenspans = '';
     $savedspan = '';
     // actually translate tags
     // texts are first
     foreach ($this->html->find('text') as $e) {
         $replace = array();
         foreach ($e->nodes as $ep) {
             list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
             //stats
             $this->stats->total_phrases++;
             if ($translated_text) {
                 $this->stats->translated_phrases++;
                 if ($source == 0) {
                     $this->stats->human_translated_phrases++;
                 }
             }
             if ($this->is_edit_mode || $this->is_auto_translate && $translated_text == null) {
                 if ($ep->inselect) {
                     $savedspan .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 } elseif (!$ep->inbody) {
                     $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 } else {
                     $translated_text = $this->create_edit_span($ep->phrase, $translated_text, $source, false, $ep->srclang);
                 }
             }
             // store replacements
             if ($translated_text) {
                 $replace[] = array($translated_text, $ep);
             }
         }
         // do replacements in reverse
         foreach (array_reverse($replace) as $epag) {
             list($replacetext, $epg) = $epag;
             $e->outertext = substr_replace($e->outertext, $replacetext, $epg->start, $epg->len);
         }
         // this adds saved spans to the first not in select element which is in the body
         if ($e->nodes && !$ep->inselect && $savedspan && $ep->inbody) {
             // (TODO: might not be...?)
             $e->outertext = $savedspan . $e->outertext;
             $savedspan = '';
         }
     }
     // now we handle the title attributes (and the value of submit buttons)
     $hidden_phrases = array();
     foreach (array('title', 'value') as $title) {
         foreach ($this->html->find('[' . $title . ']') as $e) {
             $replace = array();
             $span = '';
             // when we already have a parent outertext we'll have to update it directly
             if (isset($e->parent->_[HDOM_INFO_OUTER])) {
                 $saved_outertext = $e->outertext;
             }
             tp_logger("{$title}-original: {$e}->{$title}}", 4);
             if (isset($e->nodes)) {
                 foreach ($e->nodes as $ep) {
                     if ($ep->tag == 'phrase') {
                         list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
                         // more stats
                         $this->stats->total_phrases++;
                         if ($ep->inbody) {
                             $this->stats->hidden_phrases++;
                         } else {
                             $this->stats->meta_phrases++;
                         }
                         if ($translated_text) {
                             $this->stats->translated_phrases++;
                             if ($ep->inbody) {
                                 $this->stats->hidden_translated_phrases++;
                             } else {
                                 $this->stats->meta_translated_phrases++;
                             }
                             if ($source == 0) {
                                 $this->stats->human_translated_phrases++;
                             }
                         }
                         if (($this->is_edit_mode || $this->is_auto_translate && $translated_text == null) && $ep->inbody) {
                             // prevent duplicate translation (title = text)
                             if (strpos($e->innertext, transposh_utils::base64_url_encode($ep->phrase)) === false) {
                                 //no need to translate span the same hidden phrase more than once
                                 if (!in_array($ep->phrase, $hidden_phrases)) {
                                     $this->stats->hidden_translateable_phrases++;
                                     $span .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                                     //    logger ($span);
                                     $hidden_phrases[] = $ep->phrase;
                                 }
                             }
                         }
                         // if we need to replace, we store this
                         if ($translated_text) {
                             $replace[$translated_text] = $ep;
                         }
                     }
                 }
             }
             // and later replace
             foreach (array_reverse($replace, true) as $replace => $epg) {
                 $e->title = substr_replace($e->title, $replace, $epg->start, $epg->len);
             }
             $e->outertext .= $span;
             // this is where we update in the outercase issue
             if (isset($e->parent->_[HDOM_INFO_OUTER])) {
                 $e->parent->outertext = implode($e->outertext, explode($saved_outertext, $e->parent->outertext, 2));
             }
         }
     }
     // now we handle the meta content - which is simpler because they can't be edited or auto-translated in place
     // we also don't expect any father modifications here
     // so we now add all those spans right before the <body> tag end
     foreach ($this->html->find('[content]') as $e) {
         $right = '';
         $newtext = '';
         foreach ($e->nodes as $ep) {
             if ($ep->tag == 'phrase') {
                 // even more stats
                 $this->stats->total_phrases++;
                 $this->stats->meta_phrases++;
                 list($source, $translated_text) = call_user_func_array($this->fetch_translate_func, array($ep->phrase, $this->lang));
                 if ($translated_text) {
                     $this->stats->translated_phrases++;
                     $this->stats->meta_translated_phrases++;
                     if ($source == 0) {
                         $this->stats->human_translated_phrases++;
                     }
                     list($left, $right) = explode($ep->phrase, $e->content, 2);
                     $newtext .= $left . $translated_text;
                     $e->content = $right;
                 }
                 if ($this->is_edit_mode) {
                     $hiddenspans .= $this->create_edit_span($ep->phrase, $translated_text, $source, true, $ep->srclang);
                 }
                 if (!$translated_text && $this->is_auto_translate && !$this->is_edit_mode) {
                     tp_logger('untranslated meta for ' . $ep->phrase . ' ' . $this->lang);
                     if ($this->is_edit_mode || $this->is_auto_translate) {
                         // FIX
                     }
                 }
             }
         }
         if ($newtext) {
             $e->content = $newtext . $right;
             tp_logger("content-phrase: {$newtext}", 4);
         }
     }
     if ($hiddenspans) {
         $body = $this->html->find('body', 0);
         if ($body != null) {
             $body->lastChild()->outertext .= $hiddenspans;
         }
     }
     // This adds a meta tag with our statistics json-encoded inside...
     $this->stats->stop_timing();
     $head = $this->html->find('head', 0);
     if ($this->edit_span_created) {
         if ($head != null) {
             $head->lastChild()->outertext .= $this->added_header;
         }
     }
     //exit;
     if ($head != null) {
         $head->lastChild()->outertext .= "\n<meta name=\"translation-stats\" content='" . json_encode($this->stats) . "'/>";
     }
     // we make sure that the result is clear from our shananigans
     return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext);
     // Changed because of places where tostring failed
     //return $this->html;
     //return $this->html->outertext;
 }
 function restore_translation($original, $lang, $translation, $by, $timestamp)
 {
     // TODO in future
     // if there is a newer human translation, just ignore this
     // if there is a newer auto translation, remove it
     // update it
     // TODO - change this part to use the update_translation function
     $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));
     $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8'));
     $source = 0;
     // for now - just update it...
     $values .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')";
     $delvalues .= "(original ='{$original}' AND lang='{$lang}')";
     // Setting the transaction log records
     $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $by . "',FROM_UNIXTIME(" . $timestamp . "),'" . $source . "')";
     $update = "DELETE FROM " . $this->translation_table . " WHERE {$delvalues}";
     tp_logger($update, 3);
     $result = $GLOBALS['wpdb']->query($update);
     $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES {$values}";
     tp_logger($update, 3);
     $result = $GLOBALS['wpdb']->query($update);
     if ($result !== FALSE) {
         // update the transaction log too
         $log = "INSERT INTO " . $this->translation_log_table . " (original, translated, lang, translated_by, timestamp, source) " . "VALUES {$logvalues}";
         tp_logger($log, 3);
         $result = $GLOBALS['wpdb']->query($log);
     } else {
         tp_logger(mysql_error(), 1);
         tp_logger("Error !!! failed to insert to db {$original} , {$translation}, {$lang},", 0);
         header("HTTP/1.0 404 Failed to update language database " . mysql_error());
     }
 }
Example #3
0
    /**
     * Insert supported languages section in admin page
     * @param string $data
     */
    function tp_langs()
    {
        // we need some styles
        global $wp_locale;
        if ($wp_locale->text_direction == 'rtl') {
            echo '<style type="text/css">
	#sortable li, #default_lang li { float: right !important;}
        .logoicon {
            float:left !important;
        }
        </style>';
        }
        // this is the default language location
        list($langname, $langorigname, $flag) = explode(",", transposh_consts::$languages[$this->transposh->options->default_language]);
        echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">';
        $this->header(__('Default Language (drag another language here to make it default)', TRANSPOSH_TEXT_DOMAIN), 'languages');
        echo '<ul id="default_list"><li id="' . $this->transposh->options->default_language . '" class="languages">' . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false) . '<input type="hidden" name="languages[]" value="' . $this->transposh->options->default_language . '" />' . '&nbsp;<span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></li>';
        echo '</ul></div>';
        // list of languages
        echo '<div style="overflow:auto; clear: both;">';
        $this->header(__('Available Languages (Click to toggle language state - Drag to sort in the widget)', TRANSPOSH_TEXT_DOMAIN));
        $this->header(__('Only first five will be saved! Upgrade to full free version by choosing the option at the settings', TRANSPOSH_TEXT_DOMAIN));
        echo '<ul id="sortable">';
        foreach ($this->transposh->options->get_sorted_langs() as $langcode => $langrecord) {
            tp_logger($langcode, 5);
            list($langname, $langorigname, $flag) = explode(",", $langrecord);
            echo '<li id="' . $langcode . '" class="languages ' . ($this->transposh->options->is_active_language($langcode) || $this->transposh->options->is_default_language($langcode) ? "lng_active" : "") . '"><div style="float:' . $this->localeleft . '">' . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false) . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_active_language($langcode) ? ",v" : ",") . '" />' . '&nbsp;<span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>';
            if (in_array($langcode, transposh_consts::$google_languages)) {
                echo '<img width="16" height="16" alt="g" class="logoicon" title="' . esc_attr__('Language supported by google translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/googleicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$bing_languages)) {
                echo '<img width="16" height="16" alt="b" class="logoicon" title="' . esc_attr__('Language supported by bing translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/bingicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$apertium_languages)) {
                echo '<img width="16" height="16" alt="a" class="logoicon" title="' . esc_attr__('Language supported by apertium translate', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/apertiumicon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$oht_languages)) {
                echo '<img width="16" height="16" alt="a" class="logoicon" title="' . esc_attr__('Language supported by one hour translation', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/ohticon.png"/>';
            }
            if (in_array($langcode, transposh_consts::$rtl_languages)) {
                echo '<img width="16" height="16" alt="r" class="logoicon" title="' . esc_attr__('Language is written from right to left', TRANSPOSH_TEXT_DOMAIN) . '" src="' . $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_IMG . '/rtlicon.png"/>';
            }
            echo '</li>';
        }
        echo "</ul></div>";
        // options to play with
        echo '<div style="clear: both;">' . __('Display options:', TRANSPOSH_TEXT_DOMAIN) . '<br/><ul style="list-style-type: disc; margin-' . $this->localeleft . ':20px;font-size:11px">';
        echo '<li><a href="#" id="changename">' . __('Toggle names of languages between English and Original', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="selectall">' . __('Make all languages active', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="sortname">' . __('Sort by language name', TRANSPOSH_TEXT_DOMAIN) . '</a></li>';
        echo '<li><a href="#" id="sortiso">' . __('Sort by lSO code', TRANSPOSH_TEXT_DOMAIN) . '</a></li></ul>';
        echo '</div>';
    }
 function woo_uri_filter($url)
 {
     $lang = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->transposh->home_url);
     tp_logger('altering woo url to:' . transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode));
     return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $lang, $this->transposh->edit_mode);
 }
Example #5
0
 /**
  * Updates options at the wordpress options table if there was a change
  */
 function update_options()
 {
     if ($this->changed) {
         foreach ($this->vars as $name => $var) {
             $this->options[$name] = $var->get_value();
         }
         update_option(TRANSPOSH_OPTIONS, $this->options);
         $this->changed = false;
     } else {
         tp_logger("no changes and no updates done", 3);
     }
 }
Example #6
0
 public static function rewrite_url_lang_param($url, $home_url, $enable_permalinks_rewrite, $lang, $is_edit, $use_params_only = FALSE)
 {
     tp_logger("rewrite old url: {$url}, permalinks: {$enable_permalinks_rewrite}, lang: {$lang}, is_edit: {$is_edit}, home_url: {$home_url}", 5);
     $newurl = str_replace('&#038;', '&', $url);
     $newurl = html_entity_decode($newurl, ENT_NOQUOTES);
     $parsedurl = @parse_url($newurl);
     // if we are dealing with some other url, we won't touch it!
     if (isset($parsedurl['host']) && !($parsedurl['host'] == @parse_url($home_url, PHP_URL_HOST))) {
         return $url;
     }
     //remove prev lang and edit params - from query string - reserve other params
     if (isset($parsedurl['query'])) {
         $params = explode('&', $parsedurl['query']);
         foreach ($params as $key => $param) {
             if (stripos($param, LANG_PARAM) === 0) {
                 unset($params[$key]);
             }
             if (stripos($param, EDIT_PARAM) === 0) {
                 unset($params[$key]);
             }
         }
     }
     // clean the query
     unset($parsedurl['query']);
     // remove the language from the url permalink (if in start of path, and is a defined language)
     $gluebackhome = false;
     $home_path = rtrim(@parse_url($home_url, PHP_URL_PATH), "/");
     tp_logger("home: {$home_path} " . $parsedurl['path'], 5);
     if ($home_path && strpos($parsedurl['path'], $home_path) === 0) {
         tp_logger("homein!: {$home_path}", 5);
         $parsedurl['path'] = substr($parsedurl['path'], strlen($home_path));
         $gluebackhome = true;
     }
     if (strlen($parsedurl['path']) > 2) {
         $secondslashpos = strpos($parsedurl['path'], "/", 1);
         if (!$secondslashpos) {
             $secondslashpos = strlen($parsedurl['path']);
         }
         $prevlang = substr($parsedurl['path'], 1, $secondslashpos - 1);
         if (isset(transposh_consts::$languages[$prevlang])) {
             tp_logger("prevlang: " . $prevlang, 4);
             $parsedurl['path'] = substr($parsedurl['path'], $secondslashpos);
         }
     }
     // override the use only params - admin configured system to not touch permalinks
     if (!$enable_permalinks_rewrite) {
         $use_params_only = TRUE;
     }
     //$params ="";
     if ($is_edit) {
         $params['edit'] = EDIT_PARAM . '=1';
     }
     if ($use_params_only && $lang) {
         $params['lang'] = LANG_PARAM . "={$lang}";
     } else {
         if ($lang) {
             if (!$parsedurl['path']) {
                 $parsedurl['path'] = "/";
             }
             $parsedurl['path'] = "/" . $lang . $parsedurl['path'];
         }
     }
     if ($gluebackhome) {
         $parsedurl['path'] = $home_path . $parsedurl['path'];
     }
     // insert params to url
     if (isset($params) && $params) {
         $parsedurl['query'] = implode('&', $params);
         tp_logger($params, 4);
     }
     // more cleanups
     //$url = preg_replace("/&$/", "", $url);
     //$url = preg_replace("/\?$/", "", $url);
     //    $url = htmlentities($url, ENT_NOQUOTES);
     $url = transposh_utils::glue_url($parsedurl);
     tp_logger("new url: {$url}", 5);
     return $url;
 }
Example #7
0
 /**
  * Creates the widget html
  * @param array $args Contains such as $before_widget, $after_widget, $before_title, $after_title, etc
  */
 function widget($args, $instance, $extcall = false)
 {
     // extract args given by wordpress
     extract($args);
     tp_logger($args, 4);
     // we load the class needed and get its base name for later
     $class = $this->load_widget($instance['widget_file']);
     if (!class_exists($class)) {
         echo __('Transposh subwidget was not loaded correctly', TRANSPOSH_TEXT_DOMAIN) . ": {$class}";
     }
     $clean_page = $this->transposh->get_clean_url();
     tp_logger("WIDGET: clean page url: {$clean_page}", 4);
     $widget_args = $this->create_widget_args($clean_page);
     // at this point the widget args are ready
     tp_logger('Enter widget', 4);
     // widget default title
     //echo $before_widget . $before_title . __('Translation', TRANSPOSH_TEXT_DOMAIN) . $after_title; - hmm? po/mo?
     if (isset($before_widget)) {
         echo $before_widget;
     }
     if ($instance['title']) {
         /* TRANSLATORS: no need to translate this string */
         echo $before_title . __($instance['title'], TRANSPOSH_TEXT_DOMAIN) . $after_title;
     }
     // actually run the external widget code
     //if (version_compare(PHP_VERSION, '5.3.0','gt')) { (for the future)
     //   $class::tp_widget_do($widget_args);
     //} else {
     $tmpclass = new $class();
     $tmpclass->tp_widget_do($widget_args);
     if ($extcall) {
         $tmpclass->tp_widget_css($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         $tmpclass->tp_widget_js($instance['widget_file'], $this->transposh->transposh_plugin_dir, $this->transposh->transposh_plugin_url);
         // don't display edit and other things for shortcode embedding
         if (isset($after_widget)) {
             echo $after_widget;
         }
         // increase the number of calls for unique IDs
         self::$draw_calls++;
         return;
     }
     //}
     //at least one language showing - add the edit box if applicable
     if (!empty($widget_args)) {
         // this is the set default language line
         if ($this->transposh->options->widget_allow_set_deflang) {
             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)) {
                 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/>';
             }
         }
         // add the edit checkbox only for translators for languages marked as editable
         if ($this->transposh->is_editing_permitted()) {
             $ref = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $this->transposh->options->is_default_language($this->transposh->target_language) ? "" : $this->transposh->target_language, !$this->transposh->edit_mode);
             echo '<input type="checkbox" name="' . EDIT_PARAM . '" value="1" ' . ($this->transposh->edit_mode ? 'checked="checked" ' : '') . ' onclick="document.location.href=\'' . $ref . '\';"/>&nbsp;Edit Translation';
         }
     } else {
         //no languages configured - error message
         echo '<p>No languages available for display. Check the Transposh settings (Admin).</p>';
     }
     // Now this is a comment for those wishing to remove our logo (tplogo.png) and link (transposh.org) from the widget
     // first - according to the gpl, you may do so - but since the code has changed - please make in available under the gpl
     // second - we did invest a lot of time and effort into this, and the link is a way to help us grow and show your appreciation, if it
     // upsets you, feel more than free to move this link somewhere else on your page, such as the footer etc.
     // third - feel free to write your own widget, the translation core will work
     // forth - you can ask for permission, with a good reason, if you contributed to the code - it's a good enough reason :)
     // fifth - if you just delete the following line, it means that you have little respect to the whole copyright thing, which as far as we
     // understand means that by doing so - you are giving everybody else the right to do the same and use your work without any attribution
     // last - you can now remove the logo in exchange to a few percentage of ad and affiliate revenues on your pages, isn't that better?
     $plugpath = parse_url($this->transposh->transposh_plugin_url, PHP_URL_PATH);
     echo '<div id="' . SPAN_PREFIX . 'credit' . self::$draw_calls . '">';
     echo '</div>';
     if (isset($after_widget)) {
         echo $after_widget;
     }
     // increase the number of calls for unique IDs
     self::$draw_calls++;
 }
 /**
  * When this happens, the boxes are not created we now use a meta to inform the next step (cleaner)
  * we now also update the tp_language meta for the post
  * @param int $postID
  */
 function on_edit($postID)
 {
     // TODO - CHECK if (!isset($_POST['transposh_tp_language'])) return;
     if ($this->transposh->options->enable_autoposttranslate) {
         add_post_meta($postID, 'transposh_can_translate', 'true', true);
     }
     if ($_POST['transposh_tp_language'] == '') {
         delete_post_meta($postID, 'tp_language');
     } else {
         update_post_meta($postID, 'tp_language', $_POST['transposh_tp_language']);
         // if a language is set for a post, default language translate must be enabled, so we enable it
         if (!$this->transposh->options->enable_default_translate) {
             $this->transposh->options->enable_default_translate = true;
             $this->transposh->options->update_options();
         }
     }
     tp_logger($postID . ' ' . $_POST['transposh_tp_language']);
     //??
 }
Example #9
0
 function check_for_plugin_update($checked_data)
 {
     global $wp_version;
     tp_logger('should we suggest an upgrade?', 4);
     if (!$this->do_update_check) {
         return;
     }
     $this->do_update_check = false;
     // for next time
     // Do response
     tp_logger($checked_data);
     $response = (object) array('slug' => 'transposh-translation-filter-for-wordpress', 'new_version' => 'full version to be downloaded and installed from http://transposh.org', 'url' => 'http://transposh.org/', 'package' => 'http://svc.transposh.org/transposh.latest.zip');
     $checked_data->response[$this->transposh_plugin_basename] = $response;
     tp_logger($checked_data);
     return $checked_data;
 }