Example #1
0
 /**
  * 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'));
 }
Example #2
0
 /**
  * Creates logger object and stores it for singleton access
  * @return logger
  */
 public static function init()
 {
     return self::$instance = new self();
 }