the options page Want to help? visit our development site at trac.transposh.org.
Author: Team Transposh
Version: 0.9.3
Author URI: http://transposh.org/
License: GPL (http://www.gnu.org/licenses/gpl.txt)
Text Domain: transposh
Domain Path: /langs
*/
/*
* Transposh v0.9.3
* http://transposh.org/
*
* Copyright 2013, Team Transposh
* Licensed under the GPL Version 2 or higher.
* http://transposh.org/license
*
* Date: Mon, 06 May 2013 02:15:55 +0300
*/
//avoid direct calls to this file where wp core files not present
if (!function_exists('add_action')) {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden');
exit();
}
require_once("core/logging.php");
require_once("core/constants.php");
require_once("core/utils.php");
require_once("core/jsonwrapper/jsonwrapper.php");
require_once("core/parser.php");
require_once("wp/transposh_db.php");
require_once("wp/transposh_widget.php");
require_once("wp/transposh_admin.php");
require_once("wp/transposh_options.php");
require_once("wp/transposh_postpublish.php");
require_once("wp/transposh_backup.php");
require_once("wp/transposh_3rdparty.php");
/**
* This class represents the complete plugin
*/
class transposh_plugin {
// List of contained objects
/** @var transposh_plugin_options An options object */
public $options;
/** @var transposh_plugin_admin Admin page */
private $admin;
/** @var transposh_plugin_widget Widget control */
public $widget;
/** @var transposh_database The database class */
public $database;
/** @var transposh_postpublish Happens after editing */
public $postpublish;
/** @var transposh_3rdparty Happens after editing */
private $third_party;
// list of properties
/** @var string The site url */
public $home_url;
/** @var a url of the request, assuming there was no language */
private $clean_url;
/** @var string The url to the plugin directory */
public $transposh_plugin_url;
/** @var string The directory of the plugin */
public $transposh_plugin_dir;
/** @var string Plugin main file and dir */
public $transposh_plugin_basename;
/** @var boolean Enable rewriting of URLs */
public $enable_permalinks_rewrite;
/** @var string The language to translate the page to, from params */
public $target_language;
/** @var string The language extracted from the url */
public $tgl;
/** @var boolean Are we currently editing the page? */
public $edit_mode;
/** @var string Error message displayed for the admin in case of failure */
private $admin_msg;
/** @var string Saved search variables */
private $search_s;
/** @var variable to make sure we only attempt to fix the url once, could have used remove_filter */
private $got_request = false;
/** @var might be that page is json... */
private $attempt_json = false;
/** @var boolean Is the wp_redirect being called by transposh? */
private $transposh_redirect = false;
/** @var boolean Did we get to process but got an empty buffer with no language? (someone flushed us) */
private $tried_buffer = false;
/** @var boolean Do I need to check for updates by myself? After wordpress checked his */
private $do_update_check = false;
/**
* class constructor
*/
function transposh_plugin() {
// create and initialize sub-objects
$this->options = new transposh_plugin_options();
$this->database = new transposh_database($this);
$this->admin = new transposh_plugin_admin($this);
$this->widget = new transposh_plugin_widget($this);
$this->postpublish = new transposh_postpublish($this);
$this->third_party = new transposh_3rdparty($this);
// initialize logger
if ($this->options->debug_enable) {
$GLOBALS['tp_logger'] = tp_logger::getInstance(true);
$GLOBALS['tp_logger']->show_caller = true;
$GLOBALS['tp_logger']->set_debug_level($this->options->debug_loglevel);
$GLOBALS['tp_logger']->set_log_file($this->options->debug_logfile);
$GLOBALS['tp_logger']->set_remoteip($this->options->debug_remoteip);
}
// "global" vars
$this->home_url = get_option('home');
// Handle windows ('C:\wordpress')
$local_dir = preg_replace("/\\\\/", "/", dirname(__FILE__));
// Get last directory name
$local_dir = preg_replace("/.*\//", "", $local_dir);
$this->transposh_plugin_url = WP_PLUGIN_URL . '/' . $local_dir;
// TODO - test on more platforms - this failed in 2.7.1 so I am reverting for now...
//$tr_plugin_url= plugins_url('', __FILE__);
$this->transposh_plugin_dir = plugin_dir_path(__FILE__);
if ($this->options->debug_enable)
tp_logger('Transposh object created: ' . $_SERVER['REQUEST_URI'], 3);
$this->transposh_plugin_basename = plugin_basename(__FILE__);
//Register some functions into wordpress
if ($this->options->debug_enable) {
//tp_logger(preg_replace('|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__), 4); // includes transposh dir and php
// tp_logger($this->get_plugin_name());
tp_logger(plugin_basename(__FILE__));
}
// TODO: get_class_methods to replace said mess, other way?
add_filter('plugin_action_links_' . $this->transposh_plugin_basename, array(&$this, 'plugin_action_links'));
add_filter('query_vars', array(&$this, 'parameter_queryvars'));
add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
if ($this->options->enable_url_translate) {
add_filter('request', array(&$this, 'request_filter'));
}
add_filter('comment_post_redirect', array(&$this, 'comment_post_redirect_filter'));
add_filter('comment_text', array(&$this, 'comment_text_wrap'), 9999); // this is a late filter...
add_action('init', array(&$this, 'on_init'), 0); // really high priority
// add_action('admin_init', array(&$this, 'on_admin_init')); might use to mark where not to work?
add_action('parse_request', array(&$this, 'on_parse_request'), 0); // should have high enough priority
add_action('plugins_loaded', array(&$this, 'plugin_loaded'));
add_action('shutdown', array(&$this, 'on_shutdown'));
add_action('wp_print_styles', array(&$this, 'add_transposh_css'));
add_action('wp_print_scripts', array(&$this, 'add_transposh_js'));
if (!$this->options->dont_add_rel_alternate) {
add_action('wp_head', array(&$this, 'add_rel_alternate'));
}
// add_action('wp_head', array(&$this,'add_transposh_async'));
add_action('transposh_backup_event', array(&$this, 'run_backup'));
add_action('transposh_oht_event', array(&$this, 'run_oht'));
add_action('comment_post', array(&$this, 'add_comment_meta_settings'), 1);
// our translation proxy
add_action('wp_ajax_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp'));
add_action('wp_ajax_nopriv_tp_gp', array(&$this, 'on_ajax_nopriv_tp_gp'));
add_action('wp_ajax_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp'));
add_action('wp_ajax_nopriv_tp_gsp', array(&$this, 'on_ajax_nopriv_tp_gsp'));
add_action('wp_ajax_tp_oht', array(&$this, 'on_ajax_nopriv_tp_oht'));
add_action('wp_ajax_nopriv_tp_oht', array(&$this, 'on_ajax_nopriv_tp_oht'));
// ajax actions in editor
// TODO - remove some for non translators
add_action('wp_ajax_tp_history', array(&$this, 'on_ajax_nopriv_tp_history'));
add_action('wp_ajax_nopriv_tp_history', array(&$this, 'on_ajax_nopriv_tp_history'));
add_action('wp_ajax_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation'));
add_action('wp_ajax_nopriv_tp_translation', array(&$this, 'on_ajax_nopriv_tp_translation'));
add_action('wp_ajax_tp_ohtcallback', array(&$this, 'on_ajax_nopriv_tp_ohtcallback'));
add_action('wp_ajax_nopriv_tp_ohtcallback', array(&$this, 'on_ajax_nopriv_tp_ohtcallback'));
add_action('wp_ajax_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts'));
add_action('wp_ajax_nopriv_tp_trans_alts', array(&$this, 'on_ajax_nopriv_tp_trans_alts'));
add_action('wp_ajax_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie'));
add_action('wp_ajax_nopriv_tp_cookie', array(&$this, 'on_ajax_nopriv_tp_cookie'));
add_action('wp_ajax_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck'));
add_action('wp_ajax_nopriv_tp_cookie_bck', array(&$this, 'on_ajax_nopriv_tp_cookie_bck'));
// comment_moderation_text - future filter TODO
// full post wrapping (should happen late)
add_filter('the_content', array(&$this, 'post_content_wrap'), 9999);
add_filter('the_excerpt', array(&$this, 'post_content_wrap'), 9999);
add_filter('the_title', array(&$this, 'post_wrap'), 9999, 2);
// allow to mark the language?
// add_action('admin_menu', array(&$this, 'transposh_post_language'));
// add_action('save_post', array(&$this, 'transposh_save_post_language'));
//TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav'));
//TODO comment_row_actions (filter)
// Intergrating with the gettext interface
if ($this->options->transposh_gettext_integration) {
add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 3);
add_filter('gettext_with_context', array(&$this, 'transposh_gettext_filter'), 10, 3);
add_filter('ngettext', array(&$this, 'transposh_ngettext_filter'), 10, 4);
add_filter('ngettext_with_context', array(&$this, 'transposh_ngettext_filter'), 10, 4);
add_filter('locale', array(&$this, 'transposh_locale_filter'));
}
// internal update mechnism
if ($this->options->allow_full_version_upgrade) {
add_filter('http_request_args', array(&$this, 'filter_wordpress_org_update'), 10, 2);
add_filter('pre_set_site_transient_update_plugins', array(&$this, 'check_for_plugin_update'));
//add_filter('plugins_api', array(&$this, 'plugin_api_call'), 10, 3);
}
// debug function for bad redirects
add_filter('wp_redirect', array(&$this, 'on_wp_redirect'), 10, 2);
add_filter('redirect_canonical', array(&$this, 'on_redirect_canonical'), 10, 2);
// support shortcodes
add_shortcode('tp', array(&$this, 'tp_shortcode'));
//
// FUTURE add_action('update-custom_transposh', array(&$this, 'update'));
// CHECK TODO!!!!!!!!!!!!
$this->tgl = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url);
if (!$this->options->is_active_language($this->tgl)) {
$this->tgl = '';
}
register_activation_hook(__FILE__, array(&$this, 'plugin_activate'));
register_deactivation_hook(__FILE__, array(&$this, 'plugin_deactivate'));
}
/**
* Attempt to fix a wp_redirect being called by someone else to include the language
* hoping for no cycles
* @param string $location
* @param int $status
* @return string
*/
function on_wp_redirect($location, $status) {
// no point in mangling redirection if its our own or its the default language
if ($this->transposh_redirect) return $location;
if ($this->options->is_default_language($this->target_language))
return $location;
tp_logger($status . ' ' . $location);
// $trace = debug_backtrace();
// tp_logger($trace);
// tp_logger($this->target_language);
$location = $this->rewrite_url($location);
return $location;
}
/**
* Internally used by transposh redirection, to avoid being rewritten by self
* assuming we know what we are doing when redirecting
* @param string $location
* @param int $status
*/
function tp_redirect($location, $status = 302) {
$this->transposh_redirect = true;
wp_redirect($location, $status);
}
/**
* Function to fix canonical redirection for some translated urls (such as tags with params)
* @param string $red - url wordpress assumes it will redirect to
* @param string $req - url that was originally requested
* @return mixed false if redirect unneeded - new url if we think we should
*/
function on_redirect_canonical($red, $req) {
tp_logger("$red .. $req", 4);
// if the urls are actually the same, don't redirect (same - if it had our proper take care of)
if ($this->rewrite_url($red) == urldecode($req)) return false;
// if this is not the default language, we need to make sure it redirects to what we believe is the proper url
if (!$this->options->is_default_language($this->target_language)) {
$red = str_replace(array('%2F', '%3A', '%3B', '%3F', '%3D', '%26'), array('/', ':', ';', '?', '=', '&'), urlencode($this->rewrite_url($red)));
}
return $red;
}
function get_clean_url() {
if (isset($this->clean_url)) return $this->clean_url;
//remove any language identifier and find the "clean" url, used for posting and calculating urls if needed
$this->clean_url = transposh_utils::cleanup_url($_SERVER['REQUEST_URI'], $this->home_url, true);
// we need this if we are using url translations
if ($this->options->enable_url_translate) {
$this->clean_url = transposh_utils::get_original_url($this->clean_url, '', $this->target_language, array($this->database, 'fetch_original'));
}
return $this->clean_url;
}
// function update() {file_location
// require_once('./admin-header.php');
/* $nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
$upgrader->upgrade($plugin);
*/
// include('./admin-footer.php');
// }
/**
* Check if page is special (one that we normally should not touch
* @param string $url Url to check
* @return boolean Is it a special page?
*/
function is_special_page($url) {
return ( stripos($url, '/wp-login.php') !== FALSE ||
stripos($url, '/wp-admin/') !== FALSE ||
stripos($url, '/wp-comments-post') !== FALSE ||
stripos($url, '/xmlrpc.php') !== FALSE);
}
/**
* Called when the buffer containing the original page is flushed. Triggers the translation process.
* @param string $buffer Original page
* @return string Modified page buffer
*/
function process_page(&$buffer) {
/* if (!$this->target_language) {
global $wp;
$this->on_parse_request($wp);
} */
tp_logger('processing page hit with language:' . $this->target_language, 1);
$start_time = microtime(TRUE);
// Refrain from touching the administrative interface and important pages
if ($this->is_special_page($_SERVER['REQUEST_URI'])) {
tp_logger("Skipping translation for admin pages", 3);
}
// This one fixed a bug transposh created with other pages (xml generator for other plugins - such as the nextgen gallery)
// TODO: need to further investigate (will it be needed?)
elseif ($this->target_language == '') {
tp_logger("Skipping translation where target language is unset", 3);
if (!$buffer) {
tp_logger("seems like we had a premature flushing");
$this->tried_buffer = true;
}
}
// Don't translate the default language unless specifically allowed to...
elseif ($this->options->is_default_language($this->target_language) && !$this->options->enable_default_translate) {
tp_logger("Skipping translation for default language {$this->target_language}", 3);
} else {
// This one allows to redirect to a static element which we can find, since the redirection will remove
// the target language, we are able to avoid nasty redirection loops
if (is_404()) {
global $wp;
if (isset($wp->query_vars['pagename']) && file_exists(ABSPATH . $wp->query_vars['pagename'])) { // Hmm
tp_logger('Redirecting a static file ' . $wp->query_vars['pagename'], 1);
$this->tp_redirect('/' . $wp->query_vars['pagename'], 301);
}
}
tp_logger("Translating {$_SERVER['REQUEST_URI']} to: {$this->target_language}", 1);
//translate the entire page
$parse = new parser();
$parse->fetch_translate_func = array(&$this->database, 'fetch_translation');
$parse->prefetch_translate_func = array(&$this->database, 'prefetch_translations');
$parse->url_rewrite_func = array(&$this, 'rewrite_url');
$parse->split_url_func = array(&$this, 'split_url');
$parse->dir_rtl = (in_array($this->target_language, transposh_consts::$rtl_languages));
$parse->lang = $this->target_language;
$parse->default_lang = $this->options->is_default_language($this->target_language);
$parse->is_edit_mode = $this->edit_mode;
$parse->might_json = $this->attempt_json;
$parse->is_auto_translate = $this->is_auto_translate_permitted();
// TODO - check this!
if (stripos($_SERVER['REQUEST_URI'], '/feed/') !== FALSE) {
tp_logger("in rss feed!", 2);
$parse->is_auto_translate = false;
$parse->is_edit_mode = false;
$parse->feed_fix = true;
}
$parse->change_parsing_rules(!$this->options->parser_dont_break_puncts, !$this->options->parser_dont_break_numbers, !$this->options->parser_dont_break_entities);
$buffer = $parse->fix_html($buffer);
$end_time = microtime(TRUE);
tp_logger('Translation completed in ' . ($end_time - $start_time) . ' seconds', 1);
}
return $buffer;
}
// function on_admin_init() {
// tp_logger("admin init called");
// }
/**
* Setup a buffer that will contain the contents of the html page.
* Once processing is completed the buffer will go into the translation process.
*/
function on_init() {
tp_logger('init ' . $_SERVER['REQUEST_URI'], 4);
// the wp_rewrite is not available earlier so we can only set the enable_permalinks here
if (is_object($GLOBALS['wp_rewrite'])) {
if ($GLOBALS['wp_rewrite']->using_permalinks() && $this->options->enable_permalinks) {
tp_logger("enabling permalinks");
$this->enable_permalinks_rewrite = TRUE;
}
}
// this is an ajax special case, currently crafted and tested on buddy press, lets hope this won't make hell break loose.
// it basically sets language based on referred when accessing wp-load.php (which is the way bp does ajax)
tp_logger(substr($_SERVER['SCRIPT_FILENAME'], -11), 5);
if (substr($_SERVER['SCRIPT_FILENAME'], -11) == 'wp-load.php') {
$this->target_language = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
$this->attempt_json = true;
}
tp_logger($_SERVER['REQUEST_URI'], 5);
if (strpos($_SERVER['REQUEST_URI'], '/wpv-ajax-pagination/') === true) {
tp_logger('wpv pagination', 5);
$this->target_language = transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url);
}
// load translation files for transposh
load_plugin_textdomain(TRANSPOSH_TEXT_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/langs');
//set the callback for translating the page when it's done
ob_start(array(&$this, "process_page"));
}
/**
* Page generation completed - flush buffer.
*/
function on_shutdown() {
//TODO !!!!!!!!!!!! ob_flush();
}
/**
* Update the url rewrite rules to include language identifier
* @param array $rules Old rewrite rules
* @return array New rewrite rules
*/
function update_rewrite_rules($rules) {
tp_logger("Enter update_rewrite_rules", 2);
if (!$this->options->enable_permalinks) {
tp_logger("Not touching rewrite rules - permalinks modification disabled by admin", 2);
return $rules;
}
$newRules = array();
$lang_prefix = "([a-z]{2,2}(\-[a-z]{2,2})?)/";
$lang_parameter = "&" . LANG_PARAM . '=$matches[1]';
//catch the root url
$newRules[$lang_prefix . "?$"] = "index.php?lang=\$matches[1]";
tp_logger("\t {$lang_prefix} ?$ ---> index.php?lang=\$matches[1]", 4);
foreach ($rules as $key => $value) {
$original_key = $key;
$original_value = $value;
$key = $lang_prefix . $key;
//Shift existing matches[i] two step forward as we pushed new elements
//in the beginning of the expression
for ($i = 6; $i > 0; $i--) {
$value = str_replace('[' . $i . ']', '[' . ($i + 2) . ']', $value);
}
$value .= $lang_parameter;
tp_logger("\t $key ---> $value", 5);
$newRules[$key] = $value;
$newRules[$original_key] = $original_value;
tp_logger(": \t{$original_key} ---> {$original_value}", 4);
}
tp_logger("Exit update_rewrite_rules", 2);
return $newRules;
}
//function flush_transposh_rewrite_rules() {
//add_filter('rewrite_rules_array', array(&$this, 'update_rewrite_rules'));
// $GLOBALS['wp_rewrite']->flush_rules();
//}
/**
* Let WordPress know which parameters are of interest to us.
* @param array $vars Original queried variables
* @return array Modified array
*/
function parameter_queryvars($vars) {
tp_logger('inside query vars', 4);
$vars[] = LANG_PARAM;
$vars[] = EDIT_PARAM;
tp_logger($vars, 4);
return $vars;
}
/**
* Grabs and set the global language and edit params, they should be here
* @param WP $wp - here we get the WP class
*/
function on_parse_request($wp) {
tp_logger('on_parse_req', 3);
tp_logger($wp->query_vars);
// fix for custom-permalink (and others that might be double parsing?)
if ($this->target_language) return;
// first we get the target language
/* $this->target_language = (isset($wp->query_vars[LANG_PARAM])) ? $wp->query_vars[LANG_PARAM] : '';
if (!$this->target_language)
$this->target_language = $this->options->default_language;
tp_logger("requested language: {$this->target_language}"); */
// TODO TOCHECK!!!!!!!!!!!!!!!!!!!!!!!!!!1
$this->target_language = $this->tgl;
if (!$this->target_language)
$this->target_language = $this->options->default_language;
tp_logger("requested language: {$this->target_language}", 3);
if ($this->tried_buffer) {
tp_logger("we will retrigger the output buffering");
ob_start(array(&$this, "process_page"));
}
// make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10
if (in_array($this->target_language, transposh_consts::$rtl_languages)) {
global $wp_locale;
$wp_locale->text_direction = 'rtl';
}
// we'll go into this code of redirection only if we have options that need it (and no bot is involved, for the non-cookie)
// and this is not a special page or one that is refered by our site
// bots can skip this altogether
if (($this->options->enable_detect_redirect || $this->options->widget_allow_set_deflang) &&
!($this->is_special_page($_SERVER['REQUEST_URI']) || (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $this->home_url) !== false)) &&
!(transposh_utils::is_bot())) {
// we are starting a session if needed
if (!session_id()) session_start();
// no redirections if we already redirected in this session or we suspect cyclic redirections
if (!isset($_SESSION['TR_REDIRECTED']) && !(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == $_SERVER['REQUEST_URI'])) {
tp_logger('session redirection never happened (yet)', 2);
// we redirect once per session
$_SESSION['TR_REDIRECTED'] = true;
// redirect according to stored lng cookie, and than according to detection
if (isset($_COOKIE['TR_LNG']) && $this->options->widget_allow_set_deflang) {
if ($_COOKIE['TR_LNG'] != $this->target_language) {
$url = transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, $_COOKIE['TR_LNG'], $this->edit_mode);
if ($this->options->is_default_language($_COOKIE['TR_LNG']))
//TODO - fix wrt translation
$url = transposh_utils::cleanup_url($_SERVER["REQUEST_URI"], $this->home_url);
tp_logger("redirected to $url because of cookie", 4);
$this->tp_redirect($url);
exit;
}
} else {
$bestlang = transposh_utils::prefered_language(explode(',', $this->options->viewable_languages), $this->options->default_language);
// we won't redirect if we should not, or this is a presumable bot
if ($bestlang && $bestlang != $this->target_language && $this->options->enable_detect_redirect) {
$url = transposh_utils::rewrite_url_lang_param($_SERVER['REQUEST_URI'], $this->home_url, $this->enable_permalinks_rewrite, $bestlang, $this->edit_mode);
if ($this->options->is_default_language($bestlang))
//TODO - fix wrt translation
$url = transposh_utils::cleanup_url($_SERVER['REQUEST_URI'], $this->home_url);
tp_logger("redirected to $url because of bestlang", 4);
$this->tp_redirect($url);
exit;
}
}
} else {
tp_logger('session was already redirected', 2);
}
}
// this method allows posts from the search box to maintain the language,
// TODO - it has a bug of returning to original language following search, which can be resolved by removing search from widget urls, but maybe later...
if (isset($wp->query_vars['s'])) {
if ($this->options->enable_search_translate) {
add_action('pre_get_posts', array(&$this, 'pre_post_search'));
add_action('posts_where_request', array(&$this, 'posts_where_request'));
}
if (transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url) && !transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url)) {
$this->tp_redirect(transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, transposh_utils::get_language_from_url($_SERVER['HTTP_REFERER'], $this->home_url), false)); //."&stop=y");
exit;
}
}
if (isset($wp->query_vars[EDIT_PARAM]) && $wp->query_vars[EDIT_PARAM] && $this->is_editing_permitted()) {
$this->edit_mode = true;
// redirect bots away from edit pages to avoid double indexing
if (transposh_utils::is_bot()) {
$this->tp_redirect(transposh_utils::rewrite_url_lang_param($_SERVER["REQUEST_URI"], $this->home_url, $this->enable_permalinks_rewrite, transposh_utils::get_language_from_url($_SERVER["REQUEST_URI"], $this->home_url), false), 301);
exit;
}
} else {
$this->edit_mode = false;
}
// We are removing our query vars since they are no longer needed and also make issues when a user select a static page as his home
unset($wp->query_vars[LANG_PARAM]);
unset($wp->query_vars[EDIT_PARAM]);
tp_logger("edit mode: " . (($this->edit_mode) ? 'enabled' : 'disabled'), 2);
}
// TODO ? move to options?
/**
* Determine if the current user is allowed to translate.
* @return boolean Is allowed to translate?
*/
function is_translator() {
//if anonymous translation is allowed - let anyone enjoy it
if ($this->options->allow_anonymous_translation) {
return TRUE;
}
if (is_user_logged_in() && current_user_can(TRANSLATOR)) {
return TRUE;
}
return FALSE;
}
/**
* Plugin activation
*/
function plugin_activate() {
tp_logger("plugin_activate enter: " . dirname(__FILE__), 1);
$this->database->setup_db();
// this handles the permalink rewrite
$GLOBALS['wp_rewrite']->flush_rules();
// attempt to remove old files
@unlink($this->transposh_plugin_dir . 'widgets/tpw_default.php');
@unlink($this->transposh_plugin_dir . 'core/globals.php');
tp_logger("plugin_activate exit: " . dirname(__FILE__), 1);
tp_logger("testing name:" . plugin_basename(__FILE__), 4);
// tp_logger("testing name2:" . $this->get_plugin_name(), 4);
//activate_plugin($plugin);
}
/**
* Plugin deactivation
*/
function plugin_deactivate() {
tp_logger("plugin_deactivate enter: " . dirname(__FILE__), 2);
// this handles the permalink rewrite
$GLOBALS['wp_rewrite']->flush_rules();
tp_logger("plugin_deactivate exit: " . dirname(__FILE__), 2);
}
/**
* Callback from admin_notices - display error message to the admin.
*/
function plugin_install_error() {
tp_logger("install error!", 1);
echo '
';
echo 'Error has occured in the installation process of the translation plugin: ';
echo $this->admin_msg;
if (function_exists('deactivate_plugins')) {
// FIXME :wtf?
//deactivate_plugins(array(&$this, 'get_plugin_name'), "translate.php");
////!!! deactivate_plugins($this->transposh_plugin_basename, "translate.php");
echo ' This plugin has been automatically deactivated.';
}
echo '