/**
  * @param string              $notice
  * @param array               $custom_posts
  * @param WPML_Admin_Notifier $admin_notifier
  *
  * @return string
  */
 public function filter_cpt_dashboard_notice($notice, $custom_posts, $admin_notifier)
 {
     $slug_settings = $this->sitepress->get_setting('posts_slug_translation');
     foreach ($custom_posts as $k => $custom_post) {
         $_has_slug = isset($custom_post->rewrite['slug']) && $custom_post->rewrite['slug'];
         if ($_has_slug) {
             if ($slug_settings['on'] && !empty($slug_settings['types'][$k]) && ICL_TM_COMPLETE !== $this->string_factory->find_by_name('Url slug: ' . $k)->get_status()) {
                 $message = sprintf(__("%s slugs are set to be translated, but they are missing their translation", 'sitepress'), $custom_post->labels->name);
                 $notice .= $admin_notifier->display_instant_message($message, 'error', 'below-h2', true);
             }
         }
     }
     return $notice;
 }
 public function change_language_of_strings($domain, $langs, $to_lang, $set_as_default)
 {
     $package_translation = new WPML_Package_Helper();
     $package_translation->change_language_of_strings_in_domain($domain, $langs, $to_lang);
     if (!empty($langs)) {
         foreach ($langs as &$lang) {
             $lang = "'" . $lang . "'";
         }
         $langs = implode(',', $langs);
         $string_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT id FROM {$this->wpdb->prefix}icl_strings WHERE context=%s AND language IN ({$langs})", $domain));
         foreach ($string_ids as $str_id) {
             $this->string_factory->find_by_id($str_id)->set_language($to_lang);
         }
     }
     if ($set_as_default) {
         $lang_of_domain = new WPML_Language_Of_Domain($this->sitepress);
         $lang_of_domain->set_language($domain, $to_lang);
     }
     $string_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT id FROM {$this->wpdb->prefix}icl_strings WHERE context = %s", $domain));
     foreach ($string_ids as $strid) {
         $this->string_factory->find_by_id($strid)->update_status();
     }
     return array('success' => true);
 }
 public function register_string($context, $name, $value, $allow_empty_value = false, $source_lang = '')
 {
     global $WPML_Sticky_Links;
     $name = trim($name) ? $name : md5($value);
     /* cpt slugs - do not register them when scanning themes and plugins
      * if name starting from 'URL slug: '
      * and context is different from 'WordPress'
      */
     if (substr($name, 0, 10) === 'URL slug: ' && 'WordPress' !== $context) {
         return false;
     }
     list($domain, $context, $key) = $this->key_by_name_and_context($name, $context);
     list($name, $context) = $this->truncate_name_and_context($name, $context);
     if ($source_lang == '') {
         $lang_of_domain = new WPML_Language_Of_Domain($this->sitepress);
         $domain_lang = $lang_of_domain->get_language($domain);
         $source_lang = $domain_lang ? $domain_lang : (strpos($domain, 'admin_texts_') === 0 || $name === 'Tagline' || $name === 'Blog Title' ? $this->sitepress->get_user_admin_language(get_current_user_id()) : 'en');
         $source_lang = $source_lang ? $source_lang : 'en';
     }
     $res = $this->get_registered_string($domain, $context, $name);
     if ($res) {
         $string_id = $res['id'];
         /*
          * If Sticky Links plugin is active and set to change links in Strings,
          * we need to process $value and change links into sticky before comparing
          * with saved in DB $res->value.
          * Otherwise after every String Translation screen refresh status of this string
          * will be changed into 'needs update'
          */
         $alp_settings = get_option('alp_settings');
         if (!empty($alp_settings['sticky_links_strings']) && $alp_settings['sticky_links_strings'] && defined('WPML_STICKY_LINKS_VERSION')) {
             // sticky links plugin is active?
             require_once ICL_PLUGIN_PATH . '/inc/absolute-links/absolute-links.class.php';
             $absolute_links_object = new AbsoluteLinks();
             $alp_broken_links = array();
             $value = $absolute_links_object->_process_generic_text($value, $alp_broken_links);
         }
         $update_string = array();
         if ($value != $res['value']) {
             $update_string['value'] = $value;
         }
         $existing_lang = $this->string_factory->find_by_id($res['id'])->get_language();
         if (!empty($update_string)) {
             if ($existing_lang == $source_lang) {
                 $this->wpdb->update($this->wpdb->prefix . 'icl_strings', $update_string, array('id' => $string_id));
                 $this->wpdb->update($this->wpdb->prefix . 'icl_string_translations', array('status' => ICL_TM_NEEDS_UPDATE), array('string_id' => $string_id));
                 icl_update_string_status($string_id);
             } else {
                 $orig_data = array('string_id' => $string_id, 'language' => $source_lang);
                 $update_string['status'] = ICL_TM_COMPLETE;
                 if ($this->wpdb->get_var($this->wpdb->prepare("SELECT COUNT(*)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  FROM {$this->wpdb->prefix}icl_string_translations\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE string_id = %d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  \tAND language = %s", $string_id, $source_lang))) {
                     $this->wpdb->update($this->wpdb->prefix . 'icl_string_translations', $update_string, $orig_data);
                 } else {
                     $this->wpdb->insert($this->wpdb->prefix . 'icl_string_translations', array_merge($update_string, $orig_data));
                 }
                 icl_update_string_status($string_id);
             }
         }
     } else {
         $string_id = $this->save_string($value, $allow_empty_value, $source_lang, $domain, $context, $name);
     }
     if (defined('WPML_TM_PATH') && !empty($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']) {
         require_once WPML_TM_PATH . '/inc/translation-proxy/wpml-pro-translation.class.php';
         WPML_Pro_Translation::_content_make_links_sticky($string_id, 'string', false);
     }
     if (!isset($this->name_cache[$key])) {
         $this->name_cache[$key] = $value;
     }
     return $string_id;
 }