/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return bool
 */
function mlp_feature_term_translator(Inpsyde_Property_List_Interface $data)
{
    $taxonomy = empty($_REQUEST['taxonomy']) ? '' : (string) $_REQUEST['taxonomy'];
    $term_taxonomy_id = empty($_REQUEST['tag_ID']) ? 0 : (int) $_REQUEST['tag_ID'];
    $controller = new Mlp_Term_Translation_Controller($data->get('content_relations'), new WPNonce("save_{$taxonomy}_translations_{$term_taxonomy_id}"));
    return $controller->setup();
}
Beispiel #2
0
/**
 * Initialize the redirect controller.
 *
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_redirect(Inpsyde_Property_List_Interface $data)
{
    $image_url = $data->get('image_url');
    $redirect = new Mlp_Redirect($data->get('module_manager'), $data->get('language_api'), "{$image_url}/check.png");
    $redirect->setup();
    $user = new Mlp_Redirect_User_Settings();
    $user->setup();
}
Beispiel #3
0
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_nav_menu_init(Inpsyde_Property_List_Interface $data)
{
    $controller = new Mlp_Nav_Menu_Controller($data->get('language_api'), $data->get('assets'));
    if (is_admin()) {
        $controller->backend_setup($data->get('js_url'));
    } else {
        add_action('template_redirect', array($controller, 'frontend_setup'));
    }
}
 /**
  * @return void
  */
 private function prepare_helpers()
 {
     Mlp_Helpers::$link_table = $this->link_table;
     Mlp_Helpers::insert_dependency('site_relations', $this->plugin_data->get('site_relations'));
     Mlp_Helpers::insert_dependency('language_api', $this->plugin_data->get('language_api'));
     Mlp_Helpers::insert_dependency('plugin_data', $this->plugin_data);
 }
 /**
  * Register separate input fields.
  *
  * @param Mlp_Translation_Metabox_View $view
  * @param WP_Post                      $post
  * @param int                          $blog_id
  *
  * @return void
  */
 private function register_metabox_view_details(Mlp_Translation_Metabox_View $view, WP_Post $post, $blog_id)
 {
     $callbacks = array('title' => array($view, 'show_title'), 'editor' => array($view, 'show_editor'), 'upgrade' => array($view, 'show_upgrade_notice'));
     /**
      * Filter the meta box view callbacks.
      *
      * @param array   $callbacks Array of callback names or class-method arrays.
      * @param WP_Post $post      Post object.
      * @param int     $blog_id   Blog ID.
      *
      * @return array
      */
     $callbacks = apply_filters('mlp_translation_meta_box_view_callbacks', $callbacks, $post, $blog_id);
     if (empty($callbacks)) {
         return;
     }
     if (!empty($callbacks['title']) && post_type_supports($post->post_type, 'title')) {
         add_action('mlp_translation_meta_box_top_' . $blog_id, $callbacks['title'], 10, 3);
     }
     if (!empty($callbacks['editor']) && post_type_supports($post->post_type, 'editor')) {
         add_action('mlp_translation_meta_box_main_' . $blog_id, $callbacks['editor'], 10, 3);
     }
     if (!empty($callbacks['upgrade']) && 'MultilingualPress Pro' !== $this->plugin_data->get('plugin_name')) {
         add_action('mlp_translation_meta_box_bottom_' . $blog_id, $callbacks['upgrade'], 10, 3);
     }
 }
 /**
  * Register our UI for the module manager.
  *
  * @return bool
  */
 private function register_setting()
 {
     /** @var Mlp_Module_Manager_Interface $module_manager */
     $module_manager = $this->plugin_data->get('module_manager');
     $display_name = __('Advanced Translator', 'multilingualpress');
     $description = __('Use the WYSIWYG editor to write all translations on one screen, including thumbnails and taxonomies.', 'multilingualpress');
     return $module_manager->register(array('display_name' => $display_name, 'slug' => 'class-' . __CLASS__, 'description' => $description));
 }
 /**
  * Install plugin tables.
  *
  * @return bool
  */
 public function install_plugin()
 {
     $installer = new Mlp_Db_Installer(new Mlp_Db_Languages_Schema($this->wpdb));
     $installer->install();
     $installer->install(new Mlp_Content_Relations_Schema($this->wpdb));
     $installer->install(new Mlp_Site_Relations_Schema($this->wpdb));
     return update_site_option('mlp_version', $this->plugin_data->get('version'));
 }
 /**
  * Changes the global pagenow to prevent wrong classes on the tab navigation.
  *
  * @return void
  */
 private function set_pagenow()
 {
     $name = $this->config->get_param_name();
     if (!isset($_GET[$name])) {
         return;
     }
     $value = $this->config->get_param_value();
     if ($value !== $_GET[$name]) {
         return;
     }
     $GLOBALS['pagenow'] = $value;
 }
 /**
  * @param string  $post_type
  * @param WP_Post $post
  *
  * @return void
  */
 public function register_meta_boxes($post_type, WP_Post $post)
 {
     if (!in_array($post_type, $this->allowed_post_types)) {
         return;
     }
     $current_blog_id = get_current_blog_id();
     $site_relations = $this->plugin_data->get('site_relations');
     $related_blogs = $site_relations->get_related_sites($current_blog_id, false);
     if (empty($related_blogs)) {
         return;
     }
     foreach ($related_blogs as $blog_id) {
         // Do not allow translations if the user is lacking capabilities for the remote blog
         if (!$this->is_translatable_by_user($post, $blog_id)) {
             continue;
         }
         if ($current_blog_id !== (int) $blog_id) {
             $this->register_metabox_per_language($blog_id, $post, $current_blog_id);
         }
     }
     $assets = $this->plugin_data->get('assets');
     $assets->provide(array('mlp-admin', 'mlp_admin_css'));
 }
/**
 * Check current state of the WordPress installation.
 *
 * @param  string                          $pagenow
 * @param  Inpsyde_Property_List_Interface $data
 * @param  string                          $wp_version
 * @param  wpdb                            $wpdb
 *
 * @return bool
 */
function mlp_pre_run_test($pagenow, Inpsyde_Property_List_Interface $data, $wp_version, wpdb $wpdb)
{
    $self_check = new Mlp_Self_Check(__FILE__, $pagenow);
    $requirements_check = $self_check->pre_install_check($data->get('plugin_name'), $data->get('plugin_base_name'), $wp_version);
    if (Mlp_Self_Check::PLUGIN_DEACTIVATED === $requirements_check) {
        return FALSE;
    }
    $data->set('site_relations', new Mlp_Site_Relations($wpdb, 'mlp_site_relations'));
    if (Mlp_Self_Check::INSTALLATION_CONTEXT_OK === $requirements_check) {
        $deactivator = new Mlp_Network_Plugin_Deactivation();
        $last_version_option = get_site_option('mlp_version');
        $last_version = new Mlp_Semantic_Version_Number($last_version_option);
        $current_version = new Mlp_Semantic_Version_Number($data->get('version'));
        $upgrade_check = $self_check->is_current_version($current_version, $last_version);
        $updater = new Mlp_Update_Plugin_Data($data, $wpdb, $current_version, $last_version);
        if (Mlp_Self_Check::NEEDS_INSTALLATION === $upgrade_check) {
            $updater->install_plugin();
        }
        if (Mlp_Self_Check::NEEDS_UPGRADE === $upgrade_check) {
            $updater->update($deactivator);
        }
    }
    return TRUE;
}
 /**
  * @param string  $post_type
  * @param WP_Post $post
  *
  * @return void
  */
 public function register_meta_boxes($post_type, WP_Post $post)
 {
     if (!in_array($post_type, $this->allowed_post_types, true)) {
         return;
     }
     $current_blog_id = get_current_blog_id();
     $site_relations = $this->plugin_data->get('site_relations');
     $related_blogs = $site_relations->get_related_site_ids($current_blog_id, false);
     if (empty($related_blogs)) {
         return;
     }
     foreach ($related_blogs as $blog_id) {
         // Do not allow translations if the user is lacking capabilities for the remote blog
         if (!$this->is_translatable_by_user($post, $blog_id)) {
             continue;
         }
         if ($current_blog_id !== (int) $blog_id) {
             $this->register_metabox_per_language($blog_id, $post);
         }
     }
     $asset_manager = $this->plugin_data->get('assets');
     $asset_manager->enqueue_script('multilingualpress-admin');
     $asset_manager->enqueue_style('multilingualpress-admin');
 }
Beispiel #12
0
 /**
  * Get the flag URL for the given language.
  *
  * @param string $language Formatted like en_GB
  * @param int    $site_id  Site ID.
  *
  * @return Mlp_Url_Interface
  */
 public function get_flag_by_language($language, $site_id = 0)
 {
     $custom_flag = get_blog_option($site_id, 'inpsyde_multilingual_flag_url');
     if ($custom_flag) {
         return new Mlp_Url($custom_flag);
     }
     $flag_path = $this->data->get('flag_path');
     $language = str_replace('-', '_', $language);
     $sub = strtok($language, '_');
     $file_name = $sub . '.gif';
     if (is_readable("{$flag_path}/{$file_name}")) {
         return new Mlp_Url($this->data->get('flag_url') . $file_name);
     }
     return new Mlp_Url('');
 }
 /**
  * Register separate input fields.
  *
  * @param  Mlp_Translation_Metabox_View $view
  * @param  WP_Post                      $post
  * @param  int                          $blog_id
  * @return void
  */
 private function register_metabox_view_details(Mlp_Translation_Metabox_View $view, WP_Post $post, $blog_id)
 {
     $callbacks = array('title' => array($view, 'show_title'), 'editor' => array($view, 'show_editor'), 'upgrade' => array($view, 'show_upgrade_notice'));
     /**
      * You can change the default actions here.
      *
      * @param array   $callbacks
      * @param WP_Post $post
      * @param int     $blog_id
      */
     $callbacks = apply_filters('mlp_translation_meta_box_view_callbacks', $callbacks, $post, $blog_id);
     if (empty($callbacks)) {
         return;
     }
     if (!empty($callbacks['title']) && post_type_supports($post->post_type, 'title')) {
         add_action('mlp_translation_meta_box_top_' . $blog_id, $callbacks['title'], 10, 3);
     }
     if (!empty($callbacks['editor']) && post_type_supports($post->post_type, 'editor')) {
         add_action('mlp_translation_meta_box_main_' . $blog_id, $callbacks['editor'], 10, 3);
     }
     if (!empty($callbacks['upgrade']) && 'MultilingualPress Pro' !== $this->plugin_data->get('plugin_name')) {
         add_action('mlp_translation_meta_box_bottom_' . $blog_id, $callbacks['upgrade'], 10, 3);
     }
 }
    /**
     * Displays the posts which are not translated yet
     *
     * @access	public
     * @since	0.1
     * @uses	get_option, get_site_option, $wpdb, get_the_time, get_the_title, admin_url,
     * 			switch_to_blog, restore_current_blog, get_current_blog_id
     * @return	void
     */
    public function dashboard_widget()
    {
        $site_relations = $this->plugin_data->get('site_relations');
        $related_blogs = $site_relations->get_related_sites(0, FALSE);
        // We have no related blogs so we can stop here
        if (!is_array($related_blogs)) {
            echo '<p>' . __('Sorry, there are no connected sites in the system for this site.', 'multilingual-press') . '</p>';
            return;
        }
        ?>
		<table class="widefat">
		<?php 
        $related_blogs = array_unique($related_blogs);
        // Let's run each blog to get the posts
        foreach ($related_blogs as $blog_to_translate) {
            switch_to_blog($blog_to_translate);
            ?>
<tr><th colspan="3"><strong><?php 
            _e('Pending Translations for', 'multilingual-press');
            ?>
 <?php 
            bloginfo('name');
            ?>
</strong></th></tr><?php 
            global $wpdb;
            $query = 'SELECT * FROM ' . $wpdb->posts . ' p INNER JOIN ' . $wpdb->postmeta . ' pm ON
							pm.post_id = p.ID WHERE
							( pm.meta_key = "post_is_translated" OR pm.meta_key = "_post_is_translated" ) AND
							pm.meta_value = "0" AND
							p.post_status != "trash"
						ORDER BY
							p.post_date';
            $posts_to_translate = $wpdb->get_results($query);
            if (0 < count($posts_to_translate)) {
                foreach ($posts_to_translate as $post) {
                    ?>
					<tr>
						<td style="width:20%;"><a href="<?php 
                    echo admin_url();
                    ?>
post.php?post=<?php 
                    echo $post->ID;
                    ?>
&action=edit"><?php 
                    _e('Translate', 'multilingual-press');
                    ?>
</a></td>
						<td style="width:55%;"><?php 
                    echo get_the_title($post->ID);
                    ?>
</td>
						<td style="width:25%;"><?php 
                    echo get_the_time(get_option('date_format'), $post->ID);
                    ?>
</td>
					</tr>
					<?php 
                }
            }
            restore_current_blog();
        }
        ?>
		</table>
		<?php 
    }
 /**
  * @return void
  */
 private function show_table()
 {
     $view = new Mlp_Admin_Table_View($this->plugin_data->get('languages'), $this->pagination_data, $this->get_columns(), 'mlp-language-manager-table', 'languages');
     $view->show_table();
 }
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_duplicate_blog(Inpsyde_Property_List_Interface $data)
{
    global $wpdb;
    $duplicator = new Mlp_Duplicate_Blogs($data->get('link_table'), $wpdb, new Mlp_Table_Duplicator($wpdb), $data->get('table_list'));
    $duplicator->setup();
}
/**
 * Sets up the feature.
 *
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_alternative_language_title(Inpsyde_Property_List_Interface $data)
{
    $controller = new Mlp_Alternative_Language_Title(new Mlp_Alternative_Language_Title_Module($data->get('module_manager')), new Mlp_Admin_Bar_Customizer());
    $controller->setup();
}
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_user_backend_language(Inpsyde_Property_List_Interface $data)
{
    $user_lang = new Mlp_User_Backend_Language($data->get('module_manager'));
    $user_lang->setup();
}
 /**
  * Enqueue style.
  *
  * @wp-hook load-{$page}
  *
  * @return void
  */
 public function enqueue_style()
 {
     $assets = $this->plugin_data->get('assets');
     $assets->provide('mlp_admin_css');
 }
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return bool
 */
function mlp_feature_term_translator(Inpsyde_Property_List_Interface $data)
{
    $controller = new Mlp_Term_Translation_Controller($data->get('content_relations'));
    return $controller->setup();
}
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_quicklink(Inpsyde_Property_List_Interface $data)
{
    $controller = new Mlp_Quicklink($data->get('module_manager'), $data->get('language_api'), $data->get('assets'), new WPNonce('save_quicklink_position'));
    $controller->initialize();
}
 /**
  * @param Inpsyde_Property_List_Interface $data
  */
 public function __construct(Inpsyde_Property_List_Interface $data)
 {
     $this->content_relations = $data->get('content_relations');
     $this->prepare_values();
 }
/**
 * Initializes the redirect controller.
 *
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_redirect(Inpsyde_Property_List_Interface $data)
{
    $redirect = new Mlp_Redirect($data->get('module_manager'), $data->get('language_api'), null);
    $redirect->setup();
}
 /**
  * Inner markup for the tab.
  *
  * @return void
  */
 private function create_tab_content()
 {
     $this->show_update_message();
     $view = new Mlp_Network_Site_Settings_Tab_Content($this->plugin_data->get('language_api'), $this->tab_page_data, $this->get_blog_id(), $this->plugin_data->get('site_relations'));
     $view->render_content();
 }
 /**
  * Initial setup handler.
  *
  * @global	$wpdb wpdb WordPress Database Wrapper
  * @global	$pagenow string Current Page Wrapper
  * @return void
  */
 public function setup()
 {
     global $pagenow;
     $this->link_table = $this->wpdb->base_prefix . 'multilingual_linked';
     $this->plugin_dir_path = $this->plugin_data->plugin_dir_path;
     $this->plugin_file_path = $this->plugin_data->plugin_file_path;
     $this->plugin_data->module_manager = new Mlp_Module_Manager('state_modules');
     $this->plugin_data->site_manager = new Mlp_Module_Manager('inpsyde_multilingual');
     $this->plugin_data->link_table = $this->link_table;
     $this->plugin_data->content_relations = new Mlp_Content_Relations($this->wpdb, $this->plugin_data->site_relations, $this->link_table);
     $this->plugin_data->language_api = new Mlp_Language_Api($this->plugin_data, 'mlp_languages', $this->plugin_data->site_relations, $this->plugin_data->content_relations, $this->wpdb);
     $this->plugin_data->assets = new Mlp_Assets($this->plugin_data->locations);
     $this->load_assets();
     Mlp_Helpers::$link_table = $this->link_table;
     Mlp_Helpers::insert_dependency('site_relations', $this->plugin_data->site_relations);
     Mlp_Helpers::insert_dependency('language_api', $this->plugin_data->language_api);
     Mlp_Helpers::insert_dependency('plugin_data', $this->plugin_data);
     $this->plugin_data->freeze();
     // no changes allowed anymore
     require 'functions.php';
     // This check prevents the use of this plugin in a not-setted blog
     if ('admin-post.php' != $pagenow && 'admin-ajax.php' != $pagenow && !is_network_admin() && !array_key_exists(get_current_blog_id(), get_site_option('inpsyde_multilingual', array()))) {
         return;
     }
     // The Plugins Basename
     // used by features/class-Multilingual_Press_Auto_Update.php only
     self::$plugin_base_name = $this->plugin_data->plugin_base_name;
     // The Plugins URL
     self::$plugin_url = $this->plugin_data->plugin_uri;
     // The Plugins Name
     self::$plugin_name = $this->plugin_data->plugin_name;
     // Textdomain Path
     self::$textdomainpath = $this->plugin_data->text_domain_path;
     // Hooks and filters
     add_action('inpsyde_mlp_loaded', array($this, 'load_plugin_textdomain'), 1);
     // Load modules
     $this->load_features();
     /**
      * Kick-Off Init
      * @return  Void
      */
     do_action('inpsyde_mlp_init', $this->plugin_data);
     // Enqueue scripts
     add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
     // Cleanup upon blog delete
     add_filter('delete_blog', array($this, 'delete_blog'), 10, 2);
     // Checkup blog cleanup
     add_filter('admin_head', array($this, 'checkup_blog_message'));
     add_filter('wp_ajax_checkup_blogs', array($this, 'checkup_blog'));
     // Check for errors
     add_filter('all_admin_notices', array($this, 'check_for_user_errors_admin_notice'));
     add_action('wp_loaded', array($this, 'late_load'), 0);
     /**
      * Everything loaded
      * @param   Inpsyde_Property_List_Interface
      */
     do_action('inpsyde_mlp_loaded', $this->plugin_data);
     if (is_admin()) {
         if ($this->plugin_data->module_manager->has_modules()) {
             $this->load_module_settings_page();
         }
         if ($this->plugin_data->site_manager->has_modules()) {
             $this->load_site_settings_page();
         }
         new Mlp_Network_Site_Settings_Controller($this->plugin_data);
         new Mlp_Network_New_Site_Controller($this->plugin_data->language_api, $this->plugin_data->site_relations);
     } else {
         // frontend-hooks
         $hreflang = new Mlp_Hreflang_Header_Output($this->plugin_data->language_api);
         add_action('template_redirect', array($hreflang, 'http_header'));
         add_action('wp_head', array($hreflang, 'wp_head'));
     }
 }
 /**
  * Provides necessary data for the CopyPost JavaScript module.
  *
  * @wp-hook admin_enqueue_scripts
  *
  * @return void
  */
 public function localize_script()
 {
     $this->plugin_data->get('assets')->add_script_data('multilingualpress-admin', 'mlpCopyPostSettings', ['action' => $this->ajax_action, 'siteID' => get_current_blog_id()]);
 }
/**
 * @param Inpsyde_Property_List_Interface $data Plugin data.
 *
 * @return void
 */
function mlp_feature_quicklink(Inpsyde_Property_List_Interface $data)
{
    new Mlp_Quicklink($data->get('module_manager'), $data->get('language_api'), $data->get('assets'));
}
/**
 * @param Inpsyde_Property_List_Interface $plugin_data Plugin data.
 *
 * @return void
 */
function mlp_widget_setup(Inpsyde_Property_List_Interface $plugin_data)
{
    Mlp_Widget::insert_asset_instance($plugin_data->get('assets'));
}