/** * * @param string $option_name * @param string $new_value * @param int|bool $status * @param int $translator_id * @param int $rec_level * * @return boolean|mixed */ public function update_option($option_name = '', $new_value = null, $status = false, $translator_id = null, $rec_level = 0) { $option_name = $option_name ? $option_name : $this->option_name; $new_value = (array) $new_value; $updated = array(); foreach ($new_value as $index => $value) { if (is_array($value)) { $name = "[" . $option_name . "][" . $index . "]"; $result = $this->update_option($name, $value, $status, $translator_id, $rec_level + 1); $updated[] = array_sum(explode(",", $result)); } else { if (is_string($index)) { $name = ($rec_level == 0 ? "[" . $option_name . "]" : $option_name) . $index; } else { $name = $option_name; } $string = $this->st_instance->string_factory()->find_by_name($name); $string_id = $string->string_id(); if ($string_id) { $updated[] = $string->set_translation($this->language, $value, $status, $translator_id); } } } return array_sum($updated) > 0 ? join(",", $updated) : false; }
/** * WPML_ST_Admin_Blog_Option constructor. * * @param SitePress $sitepress * @param WPML_String_Translation $st_instance * @param string $option_name */ public function __construct(&$sitepress, &$st_instance, $option_name) { if (!in_array($option_name, array('Tagline', 'Blog Title'), true)) { throw new InvalidArgumentException($option_name . ' Is not a valid blog option that is handled by this class, allowed values are "Tagline" and "Blog Title"'); } parent::__construct($sitepress); $this->admin_option = $st_instance->get_admin_option($option_name); }
public function run() { $string_settings = $this->sitepress->get_setting('st', array()); if (!isset($string_settings['sw']) || $this->pagenow === 'admin.php' && strpos($this->get_page, 'theme-localization.php') !== false) { $string_settings['sw'] = isset($string_settings['sw']) ? $string_settings['sw'] : array(); $this->sitepress->set_setting('st', $string_settings, true); $this->st_instance->initialize_wp_and_widget_strings(); $this->st_instance->scan_theme_for_strings(true); } }
public function run() { $string_settings = $this->sitepress->get_setting('st', array()); if (!isset($string_settings['sw']) || $this->pagenow === 'admin.php' && strpos($this->get_page, 'theme-localization.php') !== false) { $string_settings['sw'] = isset($string_settings['sw']) ? $string_settings['sw'] : array(); $this->sitepress->set_setting('st', $string_settings, true); $this->st_instance->initialize_wp_and_widget_strings(); if (1 === $this->sitepress->get_setting('theme_localization_type', null) && true !== $this->sitepress->get_wp_api()->constant('WPML_DISABLE_AUTOMATIC_THEME_SCANNING')) { $this->st_instance->scan_theme_for_strings(true); } } }
function load_wpml_st_basics() { global $WPML_String_Translation, $wpdb, $wpml_st_string_factory, $sitepress; $wpml_st_string_factory = new WPML_ST_String_Factory($wpdb); require WPML_ST_PATH . '/inc/functions-load.php'; require WPML_ST_PATH . '/inc/wpml-string-translation.class.php'; require WPML_ST_PATH . '/inc/constants.php'; $WPML_String_Translation = new WPML_String_Translation($sitepress, $wpml_st_string_factory); $WPML_String_Translation->set_basic_hooks(); require WPML_ST_PATH . '/inc/package-translation/wpml-package-translation.php'; add_action('wpml_loaded', 'wpml_st_setup_label_menu_hooks', 10, 0); add_action('wpml_loaded', 'wpml_st_core_loaded', 10); }
public function pre_update_option_settings_filter($old_value, $new_value) { // This is special handling for Blog Title and Tagline. global $switched; if (!$switched || $switched && wpml_get_setting_filter(false, 'setup_complete')) { $current_language = $this->st_instance->get_current_string_language($this->option_name); WPML_Config::load_config_run(); $result = $this->update_translation($this->option_name, $current_language, $new_value, ICL_TM_COMPLETE); if ($result) { return $old_value; } } return $new_value; }
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0) { $lang = $this->st_instance->get_current_string_language($name); $option_name = substr(current_filter(), 7); $name = $name === '' ? $option_name : $name; if (isset($this->icl_st_cache[$lang][$name])) { return $this->icl_st_cache[$lang][$name]; } $serialized = is_serialized($option_value); $option_value = $serialized ? unserialize($option_value) : $option_value; if (is_array($option_value) || is_object($option_value)) { foreach ($option_value as $k => &$value) { $value = $this->icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1); } } else { if ($this->is_admin_text($key, $name)) { $tr = icl_t('admin_texts_' . $option_name, $key . $name, $option_value, $hast, true); $option_value = $hast ? $tr : $option_value; } } $option_value = $serialized ? serialize($option_value) : $option_value; /* * if sticky links plugin is enabled and set to change links into sticky * in strings, change those links back into permalinks when displayed */ if (is_string($option_value) && $this->sticky_links_exist) { $option_value = apply_filters('wpml_sticky_link_string', $option_value); } if ($rec_level === 0) { $this->icl_st_cache[$lang][$name] = $option_value; } return $option_value; }
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0) { $lang = $this->st_instance->get_current_string_language($name); $option_name = substr(current_filter(), 7); $name = $name === '' ? $option_name : $name; if (isset($this->icl_st_cache[$lang][$name])) { return $this->icl_st_cache[$lang][$name]; } $serialized = is_serialized($option_value); $option_value = $serialized ? unserialize($option_value) : $option_value; if (is_array($option_value) || is_object($option_value)) { foreach ($option_value as $k => &$value) { $value = $this->icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1); } } else { if ($this->is_admin_text($key, $name)) { $tr = icl_t('admin_texts_' . $option_name, $key . $name, $option_value, $hast, true); $option_value = $hast ? $tr : $option_value; } } $option_value = $serialized ? serialize($option_value) : $option_value; if ($rec_level === 0) { $this->icl_st_cache[$lang][$name] = $option_value; } return $option_value; }
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0) { if (!defined('ICL_SITEPRESS_VERSION') || ICL_PLUGIN_INACTIVE) { return $option_value; } $lang = $this->st_instance->get_current_string_language($name); $option_name = substr(current_filter(), 7); $name = $name === '' ? $option_name : $name; if (isset($this->icl_st_cache[$lang][$name])) { return $this->icl_st_cache[$lang][$name]; } $serialized = is_serialized($option_value); $option_value = $serialized ? unserialize($option_value) : $option_value; if (is_array($option_value) || is_object($option_value)) { foreach ($option_value as $k => &$value) { $value = $this->icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1); } } else { if ($this->is_admin_text($key, $name)) { $tr = icl_t('admin_texts_' . $option_name, $key . $name, $option_value, $hast, true); $option_value = $hast ? $tr : $option_value; } } $option_value = $serialized ? serialize($option_value) : $option_value; /* * if sticky links plugin is enabled and set to change links into sticky * in strings, change those links back into permalinks when displayed */ if (is_string($option_value) and class_exists("WPML_Sticky_links")) { global $WPML_Sticky_Links; if (isset($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']) { $option_value = $WPML_Sticky_Links->show_permalinks($option_value); } } if ($rec_level === 0) { $this->icl_st_cache[$lang][$name] = $option_value; } return $option_value; }
protected function cleanup_wrong_contexts() { global $wpdb; $old_context = $this->get_old_context(); $results = $wpdb->get_results($wpdb->prepare("\n\t SELECT id, name, value\n\t FROM {$wpdb->prefix}icl_strings\n\t WHERE context = %s", $old_context)); foreach ($results as $string) { // See if the string has no translations $old_translations = $wpdb->get_results($wpdb->prepare("\n\t\t\t\tSELECT id, language, status, value\n\t\t\t\tFROM {$wpdb->prefix}icl_string_translations\n\t\t\t\tWHERE string_id = %d", $string->id)); if (empty($old_translations)) { // We don't have any translations so we can delete the string. $wpdb->delete($wpdb->prefix . 'icl_strings', array('id' => $string->id), array('%d')); } else { // check if we have a new string in the right context $domains = $this->get_domains_found(); foreach ($domains as $domain => $count) { $new_string_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT id\n\t\t\t\t\t\tFROM {$wpdb->prefix}icl_strings\n\t\t\t\t\t\tWHERE context = %s AND name = %s AND value = %s", $domain, $string->name, $string->value)); if ($new_string_id) { // See if it has the same translations $new_translations = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT id, language, status, value\n\t\t\t\t\t\t\tFROM {$wpdb->prefix}icl_string_translations\n\t\t\t\t\t\t\tWHERE string_id = %d", $new_string_id)); foreach ($new_translations as $new_translation) { foreach ($old_translations as $index => $old_translation) { if ($new_translation->language == $old_translation->language && $new_translation->status == $old_translation->status && $new_translation->value == $old_translation->value) { unset($old_translations[$index]); } } } if (empty($old_translations)) { // We don't have any old translations that are not in the new strings so we can delete the string. $wpdb->delete($wpdb->prefix . 'icl_strings', array('id' => $string->id), array('%d')); break; } } } } } // Rename the context for any strings that are in the old context // This way the update message will no longer show. $obsolete_context = str_replace('plugin ', '', $old_context); $obsolete_context = str_replace('theme ', '', $obsolete_context); $obsolete_context = $obsolete_context . ' (obsolete)'; $wpdb->query($wpdb->prepare("\n\t\t\t\t\t\t\t\t\t UPDATE {$wpdb->prefix}icl_strings\n\t\t\t\t\t\t\t\t\t SET context = %s\n\t\t\t\t\t\t\t\t\t WHERE context = %s\n\t\t\t\t\t\t\t\t\t ", $obsolete_context, $old_context)); WPML_String_Translation::clear_use_original_cache_setting(); }