/**
  * Returns the number of posts for a given post_type, date and language combination that is published.
  *
  * @param string       $lang language code to check
  * @param null|int     $year
  * @param null|int     $month
  * @param null|int     $day
  * @param string|array $post_type
  *
  * @return bool
  *
  * @used-by \WPML_Languages::add_date_or_cpt_url_to_ls_lang to determine what languages to show in the Language Switcher
  */
 public function archive_query_has_posts($lang, $year = null, $month = null, $day = null, $post_type = 'post')
 {
     $cache_args = array();
     $cache_args['lang'] = $lang;
     $cache_args['year'] = $year;
     $cache_args['month'] = $month;
     $cache_args['day'] = $day;
     $cache_args['post_type'] = $post_type;
     $cache_key = md5(json_encode($cache_args));
     $cache_group = 'archive_query_has_posts';
     $cache = new WPML_WP_Cache($cache_group);
     $found = false;
     $result = $cache->get($cache_key, $found);
     if (!$found) {
         $post_status_snippet = $this->wp_api->current_user_can('read') ? "p.post_status IN (" . wpml_prepare_in(array('publish', 'private')) . ") " : "p.post_status = 'publish'";
         $post_type_snippet = is_array($post_type) ? " AND post_type IN (" . wpml_prepare_in($post_type) . ") " : $this->wpdb->prepare(' AND p.post_type = %s ', $post_type);
         $year_snippet = (bool) $year === true ? $this->wpdb->prepare(' AND year(p.post_date) = %d ', $year) : '';
         $month_snippet = (bool) $month === true ? $this->wpdb->prepare(' AND month(p.post_date) = %d ', $month) : '';
         $day_snippet = (bool) $day === true ? $this->wpdb->prepare(' AND day(p.post_date) = %d ', $day) : '';
         $lang_snippet = $this->wpdb->prepare(' AND t.language_code = %s ', $lang);
         $result = $this->wpdb->get_var("\n                        SELECT p.ID FROM {$this->wpdb->posts} p\n\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_translations t\n\t\t\t\t\t\t\tON p.ID = t.element_id AND t.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t\t\tWHERE " . $post_status_snippet . $year_snippet . $month_snippet . $day_snippet . $post_type_snippet . $lang_snippet . "\n\t\t\t\t\t\tLIMIT 1");
         $cache->set($cache_key, $result);
     }
     return (bool) $result;
 }
 private function filter_allowed_languages($active_languages, $selected_language)
 {
     global $sitepress;
     $wp_api = new WPML_WP_API();
     $show_all = $wp_api->is_term_edit_page() || $sitepress->get_current_language() === 'all';
     return $show_all ? $active_languages : array($active_languages[$selected_language]);
 }
 private function missing_php_extensions()
 {
     $extensions = array();
     if (ini_get('allow_url_fopen') !== '1') {
         $extensions['allow_url_fopen'] = array('type' => 'setting', 'type_description' => __('PHP Setting', 'wpml-translation-management'), 'value' => '1');
     }
     if (!extension_loaded('openssl')) {
         $extensions['openssl'] = array('type' => 'extension', 'type_description' => __('PHP Extension', 'wpml-translation-management'));
     }
     if (class_exists('ICL_AdminNotifier') && (!defined('ICL_HIDE_TRANSLATION_SERVICES') || !ICL_HIDE_TRANSLATION_SERVICES)) {
         $wpml_wp_api_check = new WPML_WP_API();
         if (count($extensions) > 0 && $wpml_wp_api_check->is_tm_page()) {
             $message = '';
             $message .= '<p>';
             $message .= __('WPML Translation Management requires the following PHP extensions and settings:', 'wpml-translation-management');
             $message .= '</p>';
             $message .= '<ul>';
             foreach ($extensions as $id => $data) {
                 $message .= '<li>';
                 if ('setting' === $data['type']) {
                     $message .= $data['type_description'] . ': <code>' . $id . '=' . $data['value'] . '</code>';
                 }
                 if ('extension' === $data['type']) {
                     $message .= $data['type_description'] . ': <strong>' . $id . '</strong>';
                 }
                 $message .= '</li>';
             }
             $message .= '</ul>';
             $args = array('id' => 'wpml-tm-missing-extensions', 'group' => 'wpml-tm-requirements', 'msg' => $message, 'type' => 'error', 'admin_notice' => true, 'hide' => true);
             ICL_AdminNotifier::add_message($args);
         } else {
             ICL_AdminNotifier::remove_message_group('wpml-tm-requirements');
         }
     }
 }
 /**
  * Makes a http request to the url this points at and checks if the requests
  * returns the correct validation result.
  *
  * @return bool
  */
 public function is_valid()
 {
     $url_glue = false === strpos($this->url, '?') ? '?' : '&';
     $url = trailingslashit($this->url) . ($this->language_code ? '/' . $this->language_code . '/' : '') . $url_glue . '____icl_validate_domain=1';
     $response = $this->http->request($url, 'timeout=15');
     return !is_wp_error($response) && $response['response']['code'] == '200' && ($response['body'] === '<!--' . untrailingslashit($this->wp_api->get_home_url()) . '-->' || $response['body'] === '<!--' . untrailingslashit($this->wp_api->get_site_url()) . '-->');
 }
 /**
  * @param WPML_WP_API $wpml_wp_api
  */
 public function load_pro_translation($wpml_wp_api)
 {
     global $ICL_Pro_Translation;
     if (!isset($ICL_Pro_Translation) && ($wpml_wp_api->is_admin() || defined('XMLRPC_REQUEST'))) {
         $job_factory = wpml_tm_load_job_factory();
         $ICL_Pro_Translation = new WPML_Pro_Translation($job_factory);
     }
 }
 public function admin_url_filter($url, $path)
 {
     if ((strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) && 'admin-ajax.php' === $path && $this->wpml_wp_api->is_front_end()) {
         global $sitepress;
         $url = $this->convert_url($url, $sitepress->get_current_language());
     }
     return $url;
 }
 public function get_redirect_target($language = false)
 {
     if ($this->wp_api->is_admin() && $this->lang_resolution->is_language_hidden($language) && strpos($_SERVER['REQUEST_URI'], 'wp-login.php') === false && !$this->wp_api->user_can(wp_get_current_user(), 'manage_options')) {
         $target = trailingslashit($this->domains[$language]) . 'wp-login.php';
     } else {
         $target = $this->redirect_hidden_home();
     }
     return $target;
 }
 private function get_language_from_fallbacks()
 {
     $lang = get_option('wpml_user_email_language');
     if (!$lang) {
         $lang = apply_filters('wpml_default_language', null);
         if ($this->WPML_WP_API->is_front_end()) {
             $lang = apply_filters('wpml_current_language', null);
         }
     }
     return $this->WPML_Language_Code->sanitize($lang);
 }
 /**
  * Triggers an update to the term count of all terms associated with the
  * input post_id
  *
  * @param int $post_id
  */
 public function update_for_post($post_id)
 {
     $taxonomies = $this->wp_api->get_taxonomies();
     foreach ($taxonomies as $taxonomy) {
         $terms_for_post = $this->wp_api->wp_get_post_terms($post_id, $taxonomy);
         foreach ($terms_for_post as $term) {
             if (isset($term->term_taxonomy_id)) {
                 $this->wp_api->wp_update_term_count($term->term_taxonomy_id, $taxonomy);
             }
         }
     }
 }
Exemplo n.º 10
0
 /**
  * @param int  $limit
  * @param bool $provide_object
  * @param bool $ignore_args
  *
  * @return array
  */
 public function get_backtrace($limit = 0, $provide_object = false, $ignore_args = true)
 {
     $options = false;
     if (version_compare($this->wp_api->phpversion(), '5.3.6') < 0) {
         // Before 5.3.6, the only values recognized are TRUE or FALSE,
         // which are the same as setting or not setting the DEBUG_BACKTRACE_PROVIDE_OBJECT option respectively.
         $options = $provide_object;
     } else {
         // As of 5.3.6, 'options' parameter is a bitmask for the following options:
         if ($provide_object) {
             $options |= DEBUG_BACKTRACE_PROVIDE_OBJECT;
         }
         if ($ignore_args) {
             $options |= DEBUG_BACKTRACE_IGNORE_ARGS;
         }
     }
     if (version_compare($this->wp_api->phpversion(), '5.4.0') >= 0) {
         $actual_limit = $limit == 0 ? 0 : $limit + 1;
         $debug_backtrace = debug_backtrace($options, $actual_limit);
         //add one item to include the current frame
     } elseif (version_compare($this->wp_api->phpversion(), '5.2.4') >= 0) {
         //@link https://core.trac.wordpress.org/ticket/20953
         $debug_backtrace = debug_backtrace();
     } else {
         $debug_backtrace = debug_backtrace($options);
     }
     //Remove the current frame
     if ($debug_backtrace) {
         array_shift($debug_backtrace);
     }
     return $debug_backtrace;
 }
 /**
  * @param array    $lang
  * @param WP_Query $current_query
  * @param bool     $icl_lso_link_empty
  * @param bool     $skip_lang
  *
  * @return array
  */
 public function add_date_or_cpt_url_to_ls_lang($lang, $current_query, $icl_lso_link_empty, $skip_lang)
 {
     list($year, $month, $day) = $this->extract_date_data_from_query($current_query);
     $post_type = ($_type = $current_query->get('post_type')) ? $_type : 'post';
     $lang_code = $lang['code'];
     $mark_missing = false;
     $override = false;
     if ($current_query->is_year() && $this->query_utils->archive_query_has_posts($lang_code, $year, null, null, $post_type)) {
         $date_archive_url = $this->wp_api->get_year_link($year);
     } elseif ($current_query->is_month() && $this->query_utils->archive_query_has_posts($lang_code, $year, $month, null, $post_type)) {
         $date_archive_url = $this->wp_api->get_month_link($year, $month);
     } elseif ($current_query->is_day() && $this->query_utils->archive_query_has_posts($lang_code, $year, $month, $day, $post_type)) {
         $date_archive_url = $this->wp_api->get_day_link($year, $month, $day);
     } else {
         if (!empty($current_query->query_vars['post_type'])) {
             $override = !$this->sitepress->is_translated_post_type($post_type);
             $mark_missing = true;
             if (!$override && $this->query_utils->archive_query_has_posts($lang_code, null, null, null, $post_type)) {
                 $url = $this->sitepress->convert_url($this->wp_api->get_post_type_archive_link($post_type), $lang_code);
                 $lang['translated_url'] = $this->sitepress->adjust_cpt_in_url($url, $post_type, $lang_code);
                 $mark_missing = false;
             }
         } else {
             $mark_missing = true;
         }
     }
     if ($mark_missing) {
         list($lang, $skip_lang) = $this->maybe_mark_lang_missing($lang, $skip_lang, $icl_lso_link_empty, $override);
     } elseif (isset($date_archive_url)) {
         $lang['translated_url'] = $this->sitepress->convert_url($date_archive_url, $lang_code);
     }
     return array($lang, $skip_lang);
 }
 private final function add_ajax_actions()
 {
     if (!$this->wpml_wp_api->is_cron_job()) {
         foreach ($this->ajax_actions as $handle => $callback) {
             if ($this->wpml_wp_api->is_ajax()) {
                 if (stripos($handle, 'wp_ajax_') !== 0) {
                     $handle = 'wp_ajax_' . $handle;
                 }
                 add_action($handle, $callback);
             }
             if ($this->wpml_wp_api->is_back_end() && $this->ajax_actions) {
                 add_action('admin_enqueue_scripts', array($this, 'enqueue_resources'));
             }
         }
     }
 }
 private function save_custom_field_values($fields_in_job, $post_id)
 {
     foreach ($fields_in_job as $name => $contents) {
         $this->wp_api->delete_post_meta($post_id, $name);
         $single = count($contents) === 1;
         $contents = (array) $contents;
         foreach ($contents as $val) {
             $this->wp_api->add_post_meta($post_id, $name, $val, $single);
         }
     }
 }
 public function unescapeURLs($data)
 {
     $results = array();
     foreach ($data as $row) {
         $results_row = array();
         foreach ($row as $column => $value) {
             if ($this->wpml_wp_api->is_url($value)) {
                 $value = urldecode($value);
             }
             $results_row[$column] = $value;
         }
         $results[] = $results_row;
     }
     return $results;
 }
Exemplo n.º 15
0
 function set_up_language_selector()
 {
     $this->get_wp_api();
     if (!$this->wp_api->is_ajax() && !$this->wp_api->is_back_end() && !$this->wp_api->is_cron_job() && !$this->wp_api->is_heartbeat()) {
         // language selector
         // load js and style for js language selector
         if (isset($this->settings['icl_lang_sel_type']) && $this->settings['icl_lang_sel_type'] == 'dropdown' && (!is_admin() || isset($_GET['page']) && $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/languages.php')) {
             if ($this->settings['icl_lang_sel_stype'] == 'mobile-auto') {
                 include ICL_PLUGIN_PATH . '/lib/mobile-detect.php';
                 $WPML_Mobile_Detect = new WPML_Mobile_Detect();
                 $this->is_mobile = $WPML_Mobile_Detect->isMobile();
                 $this->is_tablet = $WPML_Mobile_Detect->isTablet();
             }
             if ($this->settings['icl_lang_sel_stype'] == 'mobile-auto' && (!empty($this->is_mobile) || !empty($this->is_tablet)) || $this->settings['icl_lang_sel_stype'] == 'mobile') {
                 if (!defined('ICL_DONT_LOAD_LANGUAGES_JS') || !ICL_DONT_LOAD_LANGUAGES_JS) {
                     wp_enqueue_script('language-selector', ICL_PLUGIN_URL . '/res/js/language-selector.js', array(), ICL_SITEPRESS_VERSION, true);
                 }
                 if (!defined('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS') || !ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS) {
                     wp_enqueue_style('language-selector', ICL_PLUGIN_URL . '/res/css/language-selector-click.css', ICL_SITEPRESS_VERSION);
                 }
             }
         }
     }
 }
 public function keep_open_local_translators_jobs()
 {
     $this->set_ignore_local_jobs(true);
     return $this->wpml_wp_api->wp_send_json_success('Ok!');
 }
 function upload_flag($id)
 {
     $result = false;
     $validated = !empty($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file']);
     if ($validated) {
         $filename = basename($_FILES['icl_edit_languages']['name'][$id]['flag_file']);
         $target_path = $this->upload_dir . '/' . $filename;
         $wpml_wp_api = new WPML_WP_API();
         $mime = $wpml_wp_api->get_file_mime_type($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file']);
         $allowed_mime_types = array_values($this->allowed_flag_mime_types);
         $validated = in_array($mime, $allowed_mime_types, true);
         if ($validated && move_uploaded_file($_FILES['icl_edit_languages']['tmp_name'][$id]['flag_file'], $target_path)) {
             if (function_exists('wp_get_image_editor') && 'image/svg+xml' !== $mime) {
                 $image = wp_get_image_editor($target_path);
                 if (!is_wp_error($image)) {
                     $image->resize(18, 12, true);
                     $image->save($target_path);
                 }
             }
             $result = $filename;
         }
     }
     if (!$validated) {
         $error_message = __('There was an error uploading the file, please try again!', 'sitepress');
         if (!empty($_FILES['icl_edit_languages']['error'][$id]['flag_file'])) {
             switch ($_FILES['icl_edit_languages']['error'][$id]['flag_file']) {
                 case UPLOAD_ERR_INI_SIZE:
                     $error_message = __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'sitepress');
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $error_message = sprintf(__('The uploaded file exceeds %s bytes.', 'sitepress'), $this->max_file_size);
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $error_message = __('The uploaded file was only partially uploaded.', 'sitepress');
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $error_message = __('No file was uploaded.', 'sitepress');
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $error_message = __('Missing a temporary folder.', 'sitepress');
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $error_message = __('Failed to write file to disk.', 'sitepress');
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $error_message = __('A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.', 'sitepress');
                     break;
             }
         }
         $this->error($error_message);
     }
     return $result;
 }
Exemplo n.º 18
0
<?php

$wp_api = new WPML_WP_API();
if (!defined('ICL_SITEPRESS_DEV_VERSION') && ($wp_api->version_compare_naked(get_option('icl_sitepress_version'), ICL_SITEPRESS_VERSION, '=') || isset($_REQUEST['action']) && $_REQUEST['action'] == 'error_scrape' || !isset($wpdb))) {
    return;
}
if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.0', '<')) {
    define('WPML_UPGRADE_NOT_POSSIBLE', true);
    add_action('admin_notices', 'icl_plugin_too_old');
    return;
}
add_action('plugins_loaded', 'icl_plugin_upgrade', 1);
function icl_plugin_upgrade()
{
    global $wpdb;
    $iclsettings = get_option('icl_sitepress_settings');
    require_once ICL_PLUGIN_PATH . '/inc/cache.php';
    icl_cache_clear('locale_cache_class');
    icl_cache_clear('flags_cache_class');
    icl_cache_clear('language_name_cache_class');
    if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.2', '<')) {
        $wpdb->update($wpdb->prefix . 'icl_flags', array('flag' => 'ku.png'), array('lang_code' => 'ku'));
        $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'Magyar'), array('language_code' => 'hu', 'display_language_code' => 'hu'));
        $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'Hrvatski'), array('language_code' => 'hr', 'display_language_code' => 'hr'));
        $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'فارسی'), array('language_code' => 'fa', 'display_language_code' => 'fa'));
    }
    if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.3', '<')) {
        $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'پارسی'), array('language_code' => 'fa', 'display_language_code' => 'fa'));
    }
    if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.7', '<')) {
        if (!isset($iclsettings['promote_wpml'])) {
 private function get_raw_post_data()
 {
     $wpml_wp_api = new WPML_WP_API();
     return $wpml_wp_api->get_raw_post_data();
 }
 /**
  * @return string
  */
 private function get_main_directory_path()
 {
     $main_directory_path = $this->wp_api->constant('WPML_CACHE_PATH_ROOT') ? trailingslashit($this->wp_api->constant('WPML_CACHE_PATH_ROOT')) . self::MAIN_DIRECTORY_NAME : null;
     $main_directory_path = is_null($main_directory_path) ? trailingslashit($this->filesystem->wp_content_dir()) . 'cache/' . self::MAIN_DIRECTORY_NAME : $main_directory_path;
     return trailingslashit($main_directory_path);
 }
 /**
  * WPML_Translate_Link_Targets_In_Custom_Fields_Hook constructor.
  *
  * @param WPML_Translate_Link_Targets_In_Custom_Fields $translate_links
  * @param WPML_WP_API $wp_api
  */
 public function __construct($translate_links, &$wp_api)
 {
     if ($translate_links->has_meta_keys()) {
         $wp_api->add_filter('get_post_metadata', array($translate_links, 'maybe_translate_link_targets'), 10, 4);
     }
 }
 /**
  * WPML_Translate_Link_Targets_Hooks constructor.
  *
  * @param WPML_Translate_Link_Targets $translate_link_targets
  * @param WPML_WP_API $wp_api
  */
 public function __construct($translate_link_targets, $wp_api)
 {
     $wp_api->add_filter('wpml_translate_link_targets', array($translate_link_targets, 'convert_text'), 10, 1);
 }