PageRenderTime 98ms CodeModel.GetById 47ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wpml-string-translation/inc/functions.php

https://bitbucket.org/acipriani/madeinapulia.com
PHP | 2963 lines | 2343 code | 469 blank | 151 comment | 546 complexity | c25a6991b5a201f95a94d3a846626dd6 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. $icl_st_string_translation_statuses = array(
  3. ICL_STRING_TRANSLATION_COMPLETE => __('Translation complete','wpml-string-translation'),
  4. ICL_STRING_TRANSLATION_PARTIAL => __('Partial translation','wpml-string-translation'),
  5. ICL_STRING_TRANSLATION_NEEDS_UPDATE => __('Translation needs update','wpml-string-translation'),
  6. ICL_STRING_TRANSLATION_NOT_TRANSLATED => __('Not translated','wpml-string-translation'),
  7. ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR => __('Waiting for translator','wpml-string-translation')
  8. );
  9. add_action('plugins_loaded', 'icl_st_init');
  10. if(!defined('XMLRPC')){
  11. // called separately for XMLRPC post saves
  12. add_action('save_post', 'icl_st_fix_links_in_strings', 19);
  13. }
  14. //add_filter('xmlrpc_methods','icl_add_custom_xmlrpc_methods');
  15. function icl_st_init(){
  16. global $sitepress_settings, $sitepress, $wpdb, $icl_st_err_str;
  17. if ( $GLOBALS['pagenow'] == 'site-new.php' && isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) return;
  18. add_action('icl_update_active_languages', 'icl_update_string_status_all');
  19. add_action('update_option_blogname', 'icl_st_update_blogname_actions',5,2);
  20. add_action('update_option_blogdescription', 'icl_st_update_blogdescription_actions',5,2);
  21. if(isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_page'){
  22. icl_st_string_in_page($_GET['string_id']);
  23. exit;
  24. }
  25. if(isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_source'){
  26. icl_st_string_in_source($_GET['string_id']);
  27. exit;
  28. }
  29. if ( get_magic_quotes_gpc() && isset($_GET['page']) && $_GET['page'] == WPML_ST_FOLDER . '/menu/string-translation.php'){
  30. $_POST = stripslashes_deep( $_POST );
  31. }
  32. if(!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']){
  33. return;
  34. }
  35. if(!isset($sitepress_settings['st']['sw'])){
  36. $sitepress_settings['st']['sw'] = array(); //no settings for now
  37. $sitepress->save_settings($sitepress_settings);
  38. $init_all = true;
  39. }
  40. if(!isset($sitepress_settings['st']['strings_per_page'])){
  41. $sitepress_settings['st']['strings_per_page'] = 10;
  42. $sitepress->save_settings($sitepress_settings);
  43. }elseif(isset($_GET['strings_per_page']) && $_GET['strings_per_page'] > 0){
  44. $sitepress_settings['st']['strings_per_page'] = $_GET['strings_per_page'];
  45. $sitepress->save_settings($sitepress_settings);
  46. }
  47. if(!isset($sitepress_settings['st']['icl_st_auto_reg'])){
  48. $sitepress_settings['st']['icl_st_auto_reg'] = 'disable';
  49. $sitepress->save_settings($sitepress_settings);
  50. }
  51. if(empty($sitepress_settings['st']['strings_language'])){
  52. $iclsettings['st']['strings_language'] = $sitepress_settings['st']['strings_language'] = 'en';
  53. $sitepress->save_settings($iclsettings);
  54. }
  55. if(!isset($sitepress_settings['st']['translated-users'])) $sitepress_settings['st']['translated-users'] = array();
  56. if((isset($_POST['iclt_st_sw_save']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_sw_form')) || isset($init_all)){
  57. if(isset($init_all)){
  58. icl_register_string('WP',__('Blog Title','wpml-string-translation'), get_option('blogname'));
  59. icl_register_string('WP',__('Tagline', 'wpml-string-translation'), get_option('blogdescription'));
  60. __icl_st_init_register_widget_titles();
  61. // create a list of active widgets
  62. $active_text_widgets = array();
  63. $widgets = (array)get_option('sidebars_widgets');
  64. foreach($widgets as $k=>$w){
  65. if('wp_inactive_widgets' != $k && $k != 'array_version'){
  66. if(is_array($widgets[$k])){
  67. foreach($widgets[$k] as $v){
  68. if(preg_match('#text-([0-9]+)#i',$v, $matches)){
  69. $active_text_widgets[] = $matches[1];
  70. }
  71. }
  72. }
  73. }
  74. }
  75. $widget_text = get_option('widget_text');
  76. if(is_array($widget_text)){
  77. foreach($widget_text as $k=>$w){
  78. if(!empty($w) && isset($w['title']) && in_array($k, $active_text_widgets)){
  79. icl_register_string('Widgets', 'widget body - ' . md5($w['text']), $w['text']);
  80. }
  81. }
  82. }
  83. }
  84. if(isset($_POST['iclt_st_sw_save'])){
  85. $updat_string_statuses = false;
  86. $sitepress_settings['st']['sw'] = $_POST['icl_st_sw'];
  87. if($sitepress_settings['st']['strings_language'] != $_POST['icl_st_sw']['strings_language']){
  88. $updat_string_statuses = true;
  89. }
  90. $sitepress_settings['st']['strings_language'] = $_POST['icl_st_sw']['strings_language'];
  91. $sitepress->save_settings($sitepress_settings);
  92. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_strings SET language=%s WHERE language <> %s",
  93. $sitepress_settings['st']['strings_language'], $sitepress_settings['st']['strings_language']));
  94. if($updat_string_statuses){
  95. icl_update_string_status_all();
  96. }
  97. //register author strings
  98. if(!empty($sitepress_settings['st']['translated-users'])){
  99. icl_st_register_user_strings_all();
  100. }
  101. wp_redirect(admin_url('admin.php?page='. WPML_ST_FOLDER .'/menu/string-translation.php&updated=true'));
  102. }
  103. }
  104. // handle po file upload
  105. if ( isset( $_POST[ 'icl_po_upload' ] ) && wp_verify_nonce( $_POST[ '_wpnonce' ], 'icl_po_form' ) ) {
  106. global $icl_st_po_strings;
  107. if ( $_FILES[ 'icl_po_file' ][ 'size' ] == 0 ) {
  108. $icl_st_err_str = __( 'File upload error', 'wpml-string-translation' );
  109. } else {
  110. $lines = file( $_FILES[ 'icl_po_file' ][ 'tmp_name' ] );
  111. $icl_st_po_strings = array();
  112. $fuzzy = 0;
  113. for ( $k = 0; $k < count( $lines ); $k ++ ) {
  114. $date_time_flag = false;
  115. if ( 0 === strpos( $lines[ $k ], '#, fuzzy' ) ) {
  116. $fuzzy = 1;
  117. $k ++;
  118. }
  119. $name = false;
  120. if ( 0 === strpos( $lines[ $k ], '# wpml-name: ' ) ) {
  121. $name = preg_replace( "/^# wpml-name: /i", '', trim( $lines[ $k ] ) );
  122. $k ++;
  123. }
  124. if ( preg_match( '/msgctxt/', $lines[ $k ] ) ) { //we look for the line that poedit needs for unique identification of the string
  125. if ( preg_match( '/wpmldatei18/', $lines[ $k ] ) ) { //if it contains the date_time setting we add the flag to escape the control structures in the date time placeholder string
  126. $date_time_flag = true;
  127. }
  128. $k ++;
  129. }
  130. $int = preg_match( '#msgid "(.+)"#im', trim( $lines[ $k ] ), $matches );
  131. if ( $int ) {
  132. $string = str_replace( '\"', '"', $matches[ 1 ] );
  133. $int = preg_match( '#msgstr "(.+)"#im', trim( $lines[ $k + 1 ] ), $matches );
  134. if ( $int ) {
  135. $translation = str_replace( '\"', '"', $matches[ 1 ] );
  136. } else {
  137. $translation = "";
  138. }
  139. if ( $name === false ) {
  140. $name = md5( $string );
  141. }
  142. $string_exists = $wpdb->get_var( "
  143. SELECT id FROM {$wpdb->prefix}icl_strings
  144. WHERE context='" . esc_sql( $_POST[ 'icl_st_i_context_new' ] ? $_POST[ 'icl_st_i_context_new' ] : $_POST[ 'icl_st_i_context' ] ) . "'
  145. AND name='" . $name . "'" );
  146. if ( $date_time_flag ) {
  147. $string = str_replace( "\\\\", "\\", $string );
  148. $translation = str_replace( "\\\\", "\\", $translation );
  149. $name = str_replace( "\\\\", "\\", $name );
  150. }
  151. $icl_st_po_strings[ ] = array(
  152. 'string' => $string,
  153. 'translation' => $translation,
  154. 'name' => $name,
  155. 'fuzzy' => $fuzzy,
  156. 'exists' => $string_exists
  157. );
  158. $k ++;
  159. }
  160. if ( ! trim( $lines[ $k ] ) ) {
  161. $fuzzy = 0;
  162. }
  163. }
  164. if ( empty( $icl_st_po_strings ) ) {
  165. $icl_st_err_str = __( 'No string found', 'wpml-string-translation' );
  166. }
  167. }
  168. } elseif ( isset( $_POST[ 'action' ] ) && 'icl_st_save_strings' == $_POST[ 'action' ] ) {
  169. $arr = array_intersect_key( $_POST[ 'icl_strings' ], array_flip( $_POST[ 'icl_strings_selected' ] ) );
  170. //$arr = array_map('html_entity_decode', $arr);
  171. if ( isset( $_POST[ 'icl_st_po_language' ] ) ) {
  172. $arr_t = array_intersect_key( $_POST[ 'icl_translations' ], array_flip( $_POST[ 'icl_strings_selected' ] ) );
  173. $arr_f = array_intersect_key( $_POST[ 'icl_fuzzy' ], array_flip( $_POST[ 'icl_strings_selected' ] ) );
  174. //$arr_t = array_map('html_entity_decode', $arr_t);
  175. }
  176. foreach ( $arr as $k => $string ) {
  177. $name = isset( $_POST[ 'icl_name' ][ $k ] ) && $_POST[ 'icl_name' ][ $k ] ? $_POST[ 'icl_name' ][ $k ] : md5( $string );
  178. $string_id = icl_register_string( $_POST[ 'icl_st_domain_name' ], $name, $string );
  179. if ( $string_id && isset( $_POST[ 'icl_st_po_language' ] ) ) {
  180. if ( $arr_t[ $k ] != "" ) {
  181. if ( $arr_f[ $k ] ) {
  182. $_status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  183. } else {
  184. $_status = ICL_STRING_TRANSLATION_COMPLETE;
  185. }
  186. icl_add_string_translation( $string_id, $_POST[ 'icl_st_po_language' ], $arr_t[ $k ], $_status );
  187. icl_update_string_status( $string_id );
  188. }
  189. }
  190. }
  191. }
  192. //handle po export
  193. if(isset($_POST['icl_st_pie_e']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_export')){
  194. //force some filters
  195. if(isset($_GET['status'])) unset($_GET['status']);
  196. $_GET['show_results']='all';
  197. if($_POST['icl_st_e_context']){
  198. $_GET['context'] = $_POST['icl_st_e_context'];
  199. }
  200. $_GET['translation_language'] = $_POST['icl_st_e_language'];
  201. $strings = icl_get_string_translations();
  202. if(!empty($strings)){
  203. $po = icl_st_generate_po_file($strings, !isset($_POST['icl_st_pe_translations']));
  204. }else{
  205. $po = "";
  206. }
  207. if(!isset($_POST['icl_st_pe_translations'])){
  208. $popot = 'pot';
  209. $poname = $_POST['icl_st_e_context'] ? urlencode($_POST['icl_st_e_context']) : 'all_context';
  210. }else{
  211. $popot = 'po';
  212. $poname = $_GET['translation_language'];
  213. }
  214. header("Content-Type: application/force-download");
  215. header("Content-Type: application/octet-stream");
  216. header("Content-Type: application/download");
  217. header("Content-Disposition: attachment; filename=".$poname.'.'.$popot.";");
  218. header("Content-Length: ". strlen($po));
  219. echo $po;
  220. exit(0);
  221. }
  222. // handle string translation request
  223. elseif(isset($_POST['icl_st_action']) && $_POST['icl_st_action'] == 'send_strings'){
  224. if($_POST['iclnonce'] == wp_create_nonce('icl-string-translation')){
  225. $_POST = stripslashes_deep($_POST);
  226. $services = $_POST['service'];
  227. $string_ids = explode(',', $_POST['strings']);
  228. $translate_to = array();
  229. foreach($_POST['translate_to'] as $lang_to=>$one){
  230. if(isset($services[$lang_to])){
  231. $translate_to[$lang_to] = $services[$lang_to];
  232. }
  233. }
  234. if(!empty($translate_to)){
  235. icl_translation_send_strings($string_ids, $translate_to);
  236. }
  237. }
  238. }
  239. // hook into blog title and tag line
  240. add_filter('option_blogname', 'icl_sw_filters_blogname');
  241. add_filter('option_blogdescription', 'icl_sw_filters_blogdescription');
  242. add_filter('widget_title', 'icl_sw_filters_widget_title', 0); //highest priority
  243. add_filter('widget_text', 'icl_sw_filters_widget_text', 0); //highest priority
  244. if(isset($sitepress_settings['theme_localization_type']) && $sitepress_settings['theme_localization_type']==1){
  245. add_filter('gettext', 'icl_sw_filters_gettext', 9, 3);
  246. add_filter('gettext_with_context', 'icl_sw_filters_gettext_with_context', 1, 4);
  247. add_filter('ngettext', 'icl_sw_filters_ngettext', 9, 5);
  248. add_filter('ngettext_with_context', 'icl_sw_filters_nxgettext', 9, 6);
  249. }
  250. $widget_groups = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%'");
  251. foreach($widget_groups as $w){
  252. add_action('update_option_' . $w->option_name, 'icl_st_update_widget_title_actions', 5, 2);
  253. }
  254. add_action('update_option_widget_text', 'icl_st_update_text_widgets_actions', 5, 2);
  255. add_action('update_option_sidebars_widgets', '__icl_st_init_register_widget_titles');
  256. if($icl_st_err_str){
  257. add_action('admin_notices', 'icl_st_admin_notices');
  258. }
  259. if (isset($_REQUEST['string-translated']) && $_REQUEST['string-translated'] == true) {
  260. add_action('admin_notices', 'icl_st_admin_notices_string_updated');
  261. }
  262. add_filter('get_the_author_first_name', 'icl_st_author_first_name_filter', 10, 2);
  263. add_filter('get_the_author_last_name', 'icl_st_author_last_name_filter', 10, 2);
  264. add_filter('get_the_author_nickname', 'icl_st_author_nickname_filter', 10, 2);
  265. add_filter('get_the_author_description', 'icl_st_author_description_filter', 10, 2);
  266. add_filter('the_author', 'icl_st_author_displayname_filter', 10);
  267. }
  268. add_action('profile_update', 'icl_st_register_user_strings');
  269. add_action('user_register', 'icl_st_register_user_strings');
  270. function __icl_st_init_register_widget_titles(){
  271. global $wpdb;
  272. // create a list of active widgets
  273. $active_widgets = array();
  274. $widgets = (array)get_option('sidebars_widgets');
  275. foreach($widgets as $k=>$w){
  276. if('wp_inactive_widgets' != $k && $k != 'array_version'){
  277. if(is_array($widgets[$k]))
  278. foreach($widgets[$k] as $v){
  279. $active_widgets[] = $v;
  280. }
  281. }
  282. }
  283. foreach($active_widgets as $aw){
  284. $int = preg_match('#-([0-9]+)$#i',$aw, $matches);
  285. if($int){
  286. $suffix = $matches[1];
  287. }else{
  288. $suffix = 1;
  289. }
  290. $name = preg_replace('#-[0-9]+#','',$aw);
  291. //if($name == 'rss-links') $name = 'rss';
  292. //$w = $wpdb->get_row("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name = 'widget_{$name}'");
  293. //$value = unserialize($w->option_value);
  294. $value = get_option("widget_".$name);
  295. if(isset($value[$suffix]['title']) && $value[$suffix]['title']){
  296. $w_title = $value[$suffix]['title'];
  297. }else{
  298. $w_title = __icl_get_default_widget_title($aw);
  299. $value[$suffix]['title'] = $w_title;
  300. update_option("widget_".$name, $value);
  301. }
  302. if($w_title){
  303. icl_register_string('Widgets', 'widget title - ' . md5($w_title), $w_title);
  304. }
  305. }
  306. }
  307. function __icl_get_default_widget_title($id){
  308. if(preg_match('#archives(-[0-9]+)?$#i',$id)){
  309. $w_title = 'Archives';
  310. }elseif(preg_match('#categories(-[0-9]+)?$#i',$id)){
  311. $w_title = 'Categories';
  312. }elseif(preg_match('#calendar(-[0-9]+)?$#i',$id)){
  313. $w_title = 'Calendar';
  314. }elseif(preg_match('#links(-[0-9]+)?$#i',$id)){
  315. $w_title = 'Links';
  316. }elseif(preg_match('#meta(-[0-9]+)?$#i',$id)){
  317. $w_title = 'Meta';
  318. }elseif(preg_match('#pages(-[0-9]+)?$#i',$id)){
  319. $w_title = 'Pages';
  320. }elseif(preg_match('#recent-posts(-[0-9]+)?$#i',$id)){
  321. $w_title = 'Recent Posts';
  322. }elseif(preg_match('#recent-comments(-[0-9]+)?$#i',$id)){
  323. $w_title = 'Recent Comments';
  324. }elseif(preg_match('#rss-links(-[0-9]+)?$#i',$id)){
  325. $w_title = 'RSS';
  326. }elseif(preg_match('#search(-[0-9]+)?$#i',$id)){
  327. $w_title = 'Search';
  328. }elseif(preg_match('#tag-cloud(-[0-9]+)?$#i',$id)){
  329. $w_title = 'Tag Cloud';
  330. }else{
  331. $w_title = false;
  332. }
  333. return $w_title;
  334. }
  335. function icl_register_string($context, $name, $value, $allow_empty_value = false){
  336. global $wpdb, $sitepress_settings;
  337. /* cpt slugs - do not register them when scanning themes and plugins
  338. * if name starting from 'URL slug: '
  339. * and context is different from 'WordPress'
  340. */
  341. if (substr($name, 0, 10) === 'URL slug: ' && 'WordPress' !== $context) {
  342. return false;
  343. }
  344. // if the default language is not set up return without doing anything
  345. if(
  346. !isset($sitepress_settings['existing_content_language_verified']) ||
  347. !$sitepress_settings['existing_content_language_verified']
  348. ){
  349. return false;
  350. }
  351. // Check if cached (so exists)
  352. $cached = icl_t_cache_lookup($context, $name);
  353. if ($cached && isset($cached['original']) && $cached['original'] == $value) {
  354. return false;
  355. }
  356. $language = isset($sitepress_settings['st']['strings_language']) ? $sitepress_settings['st']['strings_language'] : 'en';
  357. $res = $wpdb->get_row("SELECT id, value, status, language FROM {$wpdb->prefix}icl_strings WHERE context='".esc_sql($context)."' AND name='".esc_sql($name)."'");
  358. if($res){
  359. $string_id = $res->id;
  360. $update_string = array();
  361. /*
  362. * If Sticky Links plugin is active and set to change links in Strings,
  363. * we need to process $value and change links into sticky before comparing
  364. * with saved in DB $res->value.
  365. * Otherwise after every String Translation screen refresh status of this string
  366. * will be changed into 'needs update'
  367. */
  368. $alp_settings = get_option('alp_settings');
  369. if (!empty($alp_settings['sticky_links_strings']) // do we have setting about sticky links in strings?
  370. && $alp_settings['sticky_links_strings'] // is this set to TRUE?
  371. && defined('WPML_STICKY_LINKS_VERSION')) { // sticky links plugin is active?
  372. require_once ICL_PLUGIN_PATH . '/inc/absolute-links/absolute-links.class.php';
  373. $absolute_links_object = new AbsoluteLinks;
  374. $alp_broken_links = array();
  375. $value = $absolute_links_object->_process_generic_text($value, $alp_broken_links);
  376. }
  377. if($value != $res->value){
  378. $update_string['value'] = $value;
  379. }
  380. if($language != $res->language){
  381. $update_string['language'] = $language;
  382. }
  383. if(!empty($update_string)){
  384. $wpdb->update($wpdb->prefix.'icl_strings', $update_string, array('id'=>$string_id));
  385. $wpdb->update($wpdb->prefix.'icl_string_translations', array('status'=>ICL_STRING_TRANSLATION_NEEDS_UPDATE), array('string_id'=>$string_id));
  386. icl_update_string_status($string_id);
  387. }
  388. }else{
  389. if(!empty($value) && is_scalar($value) && trim($value) || $allow_empty_value){
  390. $string = array(
  391. 'language' => $language,
  392. 'context' => $context,
  393. 'name' => $name,
  394. 'value' => $value,
  395. 'status' => ICL_STRING_TRANSLATION_NOT_TRANSLATED,
  396. );
  397. $wpdb->insert($wpdb->prefix.'icl_strings', $string);
  398. $string_id = $wpdb->insert_id;
  399. }else{
  400. $string_id = 0;
  401. }
  402. }
  403. global $WPML_Sticky_Links;
  404. if(!empty($WPML_Sticky_Links) && $WPML_Sticky_Links->settings['sticky_links_strings']){
  405. require_once ICL_PLUGIN_PATH . '/inc/translation-management/pro-translation.class.php';
  406. ICL_Pro_Translation::_content_make_links_sticky($string_id, 'string', false);
  407. }
  408. return $string_id;
  409. }
  410. add_filter('register_string_for_translation', 'icl_register_string', 10, 4);
  411. function icl_translate($context, $name, $original_value = false, $allow_empty_value = false, &$has_translation = null) {
  412. global $sitepress;
  413. $current_language = $sitepress->get_current_language();
  414. static $cache = null;
  415. if (isset($cache[$context][$name][$current_language])) {
  416. if ( $cache[$context][$name][$current_language] != $original_value ) {
  417. $has_translation = true;
  418. } else {
  419. $has_translation = false;
  420. }
  421. return $cache[$context][$name][$current_language];
  422. }
  423. icl_register_string($context, $name, $original_value, $allow_empty_value);
  424. $cache[$context][$name][$current_language] = icl_t($context, $name, $original_value, $has_translation);
  425. return $cache[$context][$name][$current_language];
  426. }
  427. function icl_st_is_registered_string($context, $name){
  428. global $wpdb;
  429. static $cache = array();
  430. if(isset($cache[$context][$name])){
  431. $string_id = $cache[$context][$name];
  432. }else{
  433. $string_id = $wpdb->get_var("
  434. SELECT id
  435. FROM {$wpdb->prefix}icl_strings WHERE context='".esc_sql($context)."' AND name='".esc_sql($name)."'");
  436. $cache[$context][$name] = $string_id;
  437. }
  438. return $string_id;
  439. }
  440. function icl_st_string_has_translations($context, $name){
  441. global $wpdb;
  442. $sql = "
  443. SELECT COUNT(st.id)
  444. FROM {$wpdb->prefix}icl_string_translations st
  445. JOIN {$wpdb->prefix}icl_strings s ON s.id=st.string_id
  446. WHERE s.name='".esc_sql($name)."' AND s.context='".esc_sql($context)."'
  447. ";
  448. return $wpdb->get_var($sql);
  449. }
  450. function icl_rename_string($context, $old_name, $new_name){
  451. global $wpdb;
  452. $wpdb->update($wpdb->prefix.'icl_strings', array('name'=>$new_name), array('context'=>$context, 'name'=>$old_name));
  453. }
  454. function icl_update_string_status($string_id){
  455. global $wpdb, $sitepress, $sitepress_settings;
  456. $st = $wpdb->get_results($wpdb->prepare("SELECT language, status FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d", $string_id));
  457. if($st){
  458. if (isset($sitepress_settings['st']['strings_language'])) {
  459. $strings_language = $sitepress_settings['st']['strings_language'];
  460. } else {
  461. $strings_language = false;
  462. }
  463. foreach($st as $t){
  464. if( $strings_language != $t->language){
  465. $translations[$t->language] = $t->status;
  466. }
  467. }
  468. $active_languages = $sitepress->get_active_languages();
  469. if(empty($translations) || max($translations) == ICL_STRING_TRANSLATION_NOT_TRANSLATED){
  470. $status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  471. }elseif( in_array(ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR,$translations) ){
  472. $status = ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR;
  473. }elseif(count($translations) < count($active_languages) - intval(in_array($strings_language, array_keys($active_languages)))){
  474. if(in_array(ICL_STRING_TRANSLATION_NEEDS_UPDATE,$translations)){
  475. $status = ICL_STRING_TRANSLATION_NEEDS_UPDATE;
  476. }elseif(in_array(ICL_STRING_TRANSLATION_COMPLETE,$translations)){
  477. $status = ICL_STRING_TRANSLATION_PARTIAL;
  478. }else{
  479. $status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  480. }
  481. }elseif(ICL_STRING_TRANSLATION_NEEDS_UPDATE == array_unique($translations)){
  482. $status = ICL_STRING_TRANSLATION_NEEDS_UPDATE;
  483. }else{
  484. if(in_array(ICL_STRING_TRANSLATION_NEEDS_UPDATE,$translations)){
  485. $status = ICL_STRING_TRANSLATION_NEEDS_UPDATE;
  486. }elseif(in_array(ICL_STRING_TRANSLATION_NOT_TRANSLATED,$translations)){
  487. $status = ICL_STRING_TRANSLATION_PARTIAL;
  488. }else{
  489. $status = ICL_STRING_TRANSLATION_COMPLETE;
  490. }
  491. }
  492. }else{
  493. $status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  494. }
  495. $wpdb->update($wpdb->prefix.'icl_strings', array('status'=>$status), array('id'=>$string_id));
  496. return $status;
  497. }
  498. function icl_update_string_status_all(){
  499. global $wpdb;
  500. $res = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}icl_strings");
  501. foreach($res as $id){
  502. icl_update_string_status($id);
  503. }
  504. }
  505. function icl_unregister_string($context, $name){
  506. global $wpdb;
  507. $string_id = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_strings WHERE context='".esc_sql($context)."' AND name='".esc_sql($name)."'");
  508. if($string_id){
  509. $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_strings WHERE id=%d", $string_id));
  510. $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d", $string_id));
  511. $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_string_positions WHERE string_id=%d", $string_id));
  512. }
  513. do_action('icl_st_unregister_string', $string_id);
  514. }
  515. function __icl_unregister_string_multi($arr){
  516. global $wpdb;
  517. $str = join(',', array_map('intval', $arr));
  518. $wpdb->query("
  519. DELETE s.*, t.* FROM {$wpdb->prefix}icl_strings s LEFT JOIN {$wpdb->prefix}icl_string_translations t ON s.id = t.string_id
  520. WHERE s.id IN ({$str})");
  521. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_string_positions WHERE string_id IN ({$str})");
  522. do_action('icl_st_unregister_string_multi', $arr);
  523. }
  524. function icl_t($context, $name, $original_value=false, &$has_translation=null, $dont_auto_register = false){
  525. global $sitepress, $sitepress_settings;
  526. // we need this to devide static $results cache by blogs in multiblog
  527. $blog_id = 0;
  528. if (isset($GLOBALS['blog_id'])) {
  529. $blog_id = $GLOBALS['blog_id'];
  530. }
  531. // if the default language is not set up return
  532. if(!isset($sitepress_settings['existing_content_language_verified'])){
  533. if(isset($has_translation)) $has_translation = false;
  534. return $original_value !== false ? $original_value : $name;
  535. }
  536. $current_language = get_current_string_language( $name );
  537. $default_language = !empty($sitepress_settings['st']['strings_language']) ? $sitepress_settings['st']['strings_language'] : $sitepress->get_default_language();
  538. $cache_key_args = array($blog_id, $current_language, $default_language, $context, $name, $original_value);
  539. $cache_key = md5( json_encode( $cache_key_args ) );
  540. $cache_group = '_icl_t';
  541. $found = false;
  542. $to_return = wp_cache_get($cache_key, $cache_group, false, $found);
  543. if ($found) {
  544. if ($to_return == $original_value) {
  545. $has_translation = false;
  546. } else {
  547. $has_translation = true;
  548. }
  549. return $to_return;
  550. }
  551. if($current_language == $default_language && $original_value){
  552. $ret_val = $original_value;
  553. if(isset($has_translation)) $has_translation = false;
  554. }else{
  555. $result = icl_t_cache_lookup($context, $name);
  556. $is_string_change = _icl_is_string_change($result, $original_value);
  557. if (($result === false || $is_string_change) && !is_admin() && !$dont_auto_register && $context != 'Widgets') {
  558. static $string_registrations_per_request = 0;
  559. if($string_registrations_per_request < ICL_STRING_TRANSLATION_AUTO_REGISTER_THRESHOLD){
  560. // See if we should auto register the strings.
  561. if (isset($sitepress_settings['st']['icl_st_auto_reg'])) {
  562. $auto_reg = $sitepress_settings['st']['icl_st_auto_reg'];
  563. } else {
  564. $auto_reg = 'disable';
  565. }
  566. if($auto_reg == 'auto-always' || ($auto_reg == 'auto-admin' && current_user_can('manage_options'))){
  567. icl_register_string($context, $name, $original_value);
  568. $string_registrations_per_request++;
  569. }
  570. }
  571. }
  572. if($result === false || ( is_array($result) && ( !isset($result['value']) || ( isset($result['translated']) && !$result['translated'] && $original_value ) ) ) ){
  573. $ret_val = $original_value;
  574. if(isset($has_translation)) $has_translation = false;
  575. }else{
  576. $ret_val = $result['value'];
  577. if(isset($has_translation)) $has_translation = true;
  578. }
  579. }
  580. wp_cache_set($cache_key, $ret_val, $cache_group);
  581. return $ret_val;
  582. }
  583. /**
  584. * @param $name
  585. *
  586. * Checks whether a given string is to be translated in the Admin back-end.
  587. * Currently only tagline and title of a site are to be translated.
  588. * All other admin strings are to always be displayed in the user admin language.
  589. *
  590. * @return bool
  591. */
  592. function is_translated_admin_string( $name ) {
  593. $translated = false;
  594. $exclusions = array( 'Tagline', 'Blog Title' );
  595. if ( in_array( $name, $exclusions ) ) {
  596. $translated = true;
  597. }
  598. return $translated;
  599. }
  600. /**
  601. * @param $name
  602. * Returns the language the current string is to be translated into.
  603. *
  604. * @return string
  605. */
  606. function get_current_string_language( $name ) {
  607. global $sitepress;
  608. if ( defined( 'DOING_AJAX' ) ) {
  609. $current_language = $sitepress->get_language_cookie();
  610. } else {
  611. $current_language = $sitepress->get_current_language();
  612. }
  613. /*
  614. * The logic for this is a little different in the admin backend. Here we always use the user admin language if the admin backend is accessed.
  615. * We have to take care of two exceptions though.
  616. * 1. Plugins doing admin ajax calls in the frontend.
  617. * 2. Certain strings are to always be translated in the admin backend.
  618. * 3. We have to handle special exception when check_if_admin_action_from_referrer is not available yet (during upgrade)
  619. */
  620. if (version_compare(ICL_SITEPRESS_VERSION, '3.1.7.2', '>')) {
  621. if (defined('WP_ADMIN') && ( $sitepress->check_if_admin_action_from_referer() || !defined('DOING_AJAX') ) && !is_translated_admin_string($name)) {
  622. $current_user = $sitepress->get_current_user();
  623. if (isset($current_user->ID)) {
  624. $current_language = $sitepress->get_user_admin_language($current_user->ID);
  625. }
  626. }
  627. }
  628. return $current_language;
  629. }
  630. /**
  631. * Helper function for icl_t()
  632. * @param array $result
  633. * @param string $original_value
  634. * @return boolean
  635. */
  636. function _icl_is_string_change($result, $original_value) {
  637. if ($result == false) {
  638. return false;
  639. }
  640. if (!isset($result['value'])) {
  641. return false;
  642. }
  643. return (
  644. $result['translated'] && $result['original'] != $original_value ||
  645. !$result['translated'] && $result['value'] != $original_value
  646. );
  647. }
  648. add_filter('translate_string', 'icl_t', 10, 5);
  649. function icl_add_string_translation($string_id, $language, $value = null, $status = false, $translator_id = null){
  650. global $wpdb, $sitepress;
  651. $current_user = $sitepress->get_current_user();
  652. $res = $wpdb->get_row("SELECT id, value, status FROM {$wpdb->prefix}icl_string_translations WHERE string_id='".esc_sql($string_id)."' AND language='".esc_sql($language)."'");
  653. // the same string should not be sent two times to translation
  654. if(isset($res->status) && $res->status == ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR && is_null($value)){
  655. return false;
  656. }
  657. if($res){
  658. $st_id = $res->id;
  659. $st_update = array();
  660. if(!is_null($value) && $value != $res->value){ // null $value is for sending to translation. don't override existing.
  661. $st_update['value'] = $value;
  662. }
  663. if($status){
  664. $st_update['status'] = $status;
  665. }elseif($status === ICL_STRING_TRANSLATION_NOT_TRANSLATED){
  666. $st_update['status'] = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  667. }
  668. if(!empty($st_update)){
  669. if(!is_null($translator_id)){
  670. $st_update['translator_id'] = $current_user->ID;
  671. }
  672. $st_update['translation_date'] = current_time("mysql");
  673. $wpdb->update($wpdb->prefix.'icl_string_translations', $st_update, array('id'=>$st_id));
  674. }
  675. }else{
  676. if(!$status){
  677. $status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  678. }
  679. $st = array(
  680. 'string_id' => $string_id,
  681. 'language' => $language,
  682. 'status' => $status
  683. );
  684. if(!is_null($value)){
  685. $st['value'] = $value;
  686. }
  687. if(!is_null($translator_id)){
  688. $st_update['translator_id'] = $current_user->ID;
  689. }
  690. $wpdb->insert($wpdb->prefix.'icl_string_translations', $st);
  691. $st_id = $wpdb->insert_id;
  692. }
  693. if(isset($GLOBALS['ICL_Pro_Translation'])){
  694. $GLOBALS['ICL_Pro_Translation']->_content_fix_links_to_translated_content($st_id, $language, 'string');
  695. }
  696. icl_update_string_status($string_id);
  697. do_action('icl_st_add_string_translation', $st_id);
  698. return $st_id;
  699. }
  700. /**
  701. *
  702. * @global WPDB $wpdb
  703. * @global array $sitepress_settings
  704. * @param string $option_name
  705. * @param string $language
  706. * @param string $new_value
  707. * @param int|bool $status
  708. * @param int $translator_id
  709. * @param int $rec_level
  710. * @return boolean|mixed
  711. */
  712. function icl_update_string_translation($option_name, $language, $new_value = null, $status = false, $translator_id = null, $rec_level = 0) {
  713. global $wpdb, $sitepress_settings;
  714. if (!is_array($new_value)) {
  715. $new_value = (array) $new_value;
  716. }
  717. $updated = array();
  718. foreach ($new_value as $index => $value) {
  719. if (is_array($value)) {
  720. $name = "[". $option_name ."][" . $index . "]";
  721. $result = icl_update_string_translation($name, $language, $value, $status, $translator_id, $rec_level + 1);
  722. $updated[] = array_sum( explode(",", $result) );
  723. } else {
  724. if (is_string($index)) {
  725. if ($rec_level == 0) {
  726. $name = "[". $option_name ."]" . $index;
  727. } else {
  728. $name = $option_name . $index;
  729. }
  730. } else {
  731. $name = $option_name;
  732. }
  733. $select_original_string = "SELECT * FROM {$wpdb->prefix}icl_strings WHERE name = %s AND language = %s";
  734. $original_string = $wpdb->get_row($wpdb->prepare($select_original_string, $name, $sitepress_settings['st']['strings_language']));
  735. if (!$original_string || !isset($original_string->id) || !is_numeric($original_string->id)) {
  736. continue;
  737. }
  738. $updated[] = icl_add_string_translation($original_string->id, $language, $value, $status, $translator_id);
  739. }
  740. }
  741. if (array_sum($updated) > 0) {
  742. return join(",", $updated);
  743. } else {
  744. return false;
  745. }
  746. }
  747. function icl_get_string_id($string, $context){
  748. global $wpdb;
  749. $id = (int) $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}icl_strings WHERE value=%s AND context=%s", $string, $context));
  750. return $id;
  751. }
  752. function icl_get_string_translations($offset=0){
  753. global $wpdb, $sitepress, $sitepress_settings, $wp_query, $icl_st_string_translation_statuses;
  754. $string_translations = array();
  755. $current_user = $sitepress->get_current_user();
  756. $extra_cond = "";
  757. if(icl_st_is_translator() && isset($_GET['status']) && preg_match("#".ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR."-(.+)#", $_GET['status'], $matches)){
  758. $status_filter = ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR;
  759. $status_filter_lang = $matches[1];
  760. $lcode_alias = str_replace('-', '', $status_filter_lang);
  761. $extra_cond .= " AND str_{$lcode_alias}.language = '{$status_filter_lang}' ";
  762. }else{
  763. $status_filter = isset($_GET['status']) ? intval($_GET['status']) : false;
  764. }
  765. $search_filter = isset($_GET['search']) ? $_GET['search'] : false;
  766. $exact_match = isset($_GET['em']) ? $_GET['em'] == 1 : false;
  767. if($status_filter !== false){
  768. if($status_filter == ICL_STRING_TRANSLATION_COMPLETE){
  769. $extra_cond .= " AND s.status = " . ICL_STRING_TRANSLATION_COMPLETE;
  770. }elseif($status_filter == ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR){
  771. ; // do nothing
  772. }else{
  773. $extra_cond .= " AND status IN (" . ICL_STRING_TRANSLATION_PARTIAL . "," . ICL_STRING_TRANSLATION_NEEDS_UPDATE . "," . ICL_STRING_TRANSLATION_NOT_TRANSLATED . "," . ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR . ")";
  774. }
  775. }
  776. if($search_filter != false){
  777. if($exact_match){
  778. $extra_cond .= " AND s.value = '". esc_sql($search_filter)."' ";
  779. }else{
  780. $extra_cond .= " AND s.value LIKE '%". esc_sql($search_filter)."%' ";
  781. }
  782. }
  783. $context_filter = isset($_GET['context']) ? $_GET['context'] : false;
  784. if($context_filter !== false){
  785. $extra_cond .= " AND s.context = '" . esc_sql($context_filter) . "'";
  786. }
  787. if(isset($_GET['show_results']) && $_GET['show_results']=='all'){
  788. $limit = 9999;
  789. $offset = 0;
  790. }else{
  791. $limit = $sitepress_settings['st']['strings_per_page'];
  792. if(!isset($_GET['paged'])) $_GET['paged'] = 1;
  793. $offset = ($_GET['paged']-1)*$limit;
  794. }
  795. /* TRANSLATOR - START */
  796. if(icl_st_is_translator()){
  797. $user_lang_pairs = get_user_meta($current_user->ID, $wpdb->prefix.'language_pairs', true);
  798. if(!empty($status_filter_lang)){
  799. $_joins = $_sels = $_where = array();
  800. foreach($sitepress->get_active_languages() as $l){
  801. if($l['code'] == $sitepress_settings['st']['strings_language']) continue;
  802. $lcode_alias = str_replace('-', '', $l['code']);
  803. $_sels[] = "str_{$lcode_alias}.id AS id_{$lcode_alias},
  804. str_{$lcode_alias}.status AS status_{$lcode_alias},
  805. str_{$lcode_alias}.value AS value_{$lcode_alias},
  806. str_{$lcode_alias}.translator_id AS translator_{$lcode_alias},
  807. str_{$lcode_alias}.translation_date AS date_{$lcode_alias}
  808. ";
  809. $_joins[] = " LEFT JOIN {$wpdb->prefix}icl_string_translations str_{$lcode_alias} ON str_{$lcode_alias}.string_id = s.id AND str_{$lcode_alias}.language = '{$l['code']}'";
  810. }
  811. $sql = "
  812. SELECT SQL_CALC_FOUND_ROWS s.id AS string_id, s.language AS string_language, s.context, s.name, s.value, s.status,
  813. " . join(", ", $_sels) . "
  814. FROM {$wpdb->prefix}icl_strings s
  815. " . join("\n", $_joins) . "
  816. WHERE
  817. str_{$status_filter_lang}.status = %d AND
  818. (str_{$status_filter_lang}.translator_id IS NULL OR str_{$status_filter_lang}.translator_id = %d)
  819. {$extra_cond}
  820. ORDER BY string_id DESC
  821. LIMIT {$offset},{$limit}
  822. ";
  823. $sql_prepared = $wpdb->prepare($sql, array(ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR, $current_user->ID));
  824. $res = $wpdb->get_results($sql_prepared, ARRAY_A);
  825. }else{
  826. $_joins = $_sels = $_where = array();
  827. foreach($sitepress->get_active_languages() as $l){
  828. if($l['code'] == $sitepress_settings['st']['strings_language']
  829. || empty($user_lang_pairs[$sitepress_settings['st']['strings_language']][$l['code']])) continue;
  830. $lcode_alias = str_replace('-', '', $l['code']);
  831. $lcode_alias = str_replace('-', '', $l['code']);
  832. $_sels[] = "str_{$lcode_alias}.id AS id_{$lcode_alias},
  833. str_{$lcode_alias}.status AS status_{$lcode_alias},
  834. str_{$lcode_alias}.value AS value_{$lcode_alias},
  835. str_{$lcode_alias}.translator_id AS translator_{$lcode_alias},
  836. str_{$lcode_alias}.translation_date AS date_{$lcode_alias}
  837. ";
  838. $_joins[] = "LEFT JOIN {$wpdb->prefix}icl_string_translations str_{$lcode_alias} ON str_{$lcode_alias}.string_id = s.id AND str_{$lcode_alias}.language='{$l['code']}'";
  839. if($status_filter == ICL_STRING_TRANSLATION_COMPLETE){
  840. $_where[] .= " AND str_{$lcode_alias}.status = " . ICL_STRING_TRANSLATION_COMPLETE;
  841. }else{
  842. if(empty($_lwhere)){
  843. $_lwhere = ' AND (';
  844. foreach($sitepress->get_active_languages() as $l2){
  845. if($l2['code'] == $sitepress_settings['st']['strings_language'] || empty($user_lang_pairs[$sitepress_settings['st']['strings_language']][$l2['code']])) continue;
  846. $l2code_alias = str_replace('-', '', $l2['code']);
  847. $_lwheres[] = " str_{$l2code_alias}.status = " . ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR . " OR
  848. str_{$l2code_alias}.translator_id = " . $current_user->ID ;
  849. }
  850. $_lwhere .= join(' OR ', $_lwheres ) . ')';
  851. $_where[] = $_lwhere;
  852. }
  853. }
  854. }
  855. $sql = "
  856. SELECT SQL_CALC_FOUND_ROWS s.id AS string_id, s.language AS string_language, s.context, s.name, s.value, s.status, ".
  857. join(', ', $_sels) . "
  858. FROM {$wpdb->prefix}icl_strings s " . join("\n", $_joins) . "
  859. WHERE s.language = '{$sitepress_settings['st']['strings_language']}' ".join(' ', $_where) . "
  860. {$extra_cond}
  861. ORDER BY s.id DESC
  862. LIMIT {$offset},{$limit}
  863. ";
  864. $res = $wpdb->get_results($sql, ARRAY_A);
  865. }
  866. $wp_query->found_posts = $wpdb->get_var("SELECT FOUND_ROWS()");
  867. $wp_query->query_vars['posts_per_page'] = $limit;
  868. $wp_query->max_num_pages = ceil($wp_query->found_posts/$limit);
  869. if($res){
  870. if(!empty($status_filter_lang)){
  871. foreach($res as $row){
  872. $_translations = array();
  873. foreach($sitepress->get_active_languages() as $l){
  874. if($l['code'] == $sitepress_settings['st']['strings_language']) continue;
  875. $lcode_alias = str_replace('-', '', $l['code']);
  876. if($row['id_'. $lcode_alias]){
  877. $_translations[$l['code']] = array(
  878. 'id' => $row['id_'. $lcode_alias],
  879. 'status' => $row['status_'. $lcode_alias],
  880. 'language' => $l['code'],
  881. 'value' => $row['value_'. $lcode_alias],
  882. 'translator_id' => $row['translator_'. $lcode_alias],
  883. 'translation_date' => $row['date_'. $lcode_alias]
  884. );
  885. }
  886. }
  887. $string_translations[$row['string_id']] = array(
  888. 'string_id' => $row['string_id'],
  889. 'string_language' => $row['string_language'],
  890. 'context' => $row['context'],
  891. 'name' => $row['name'],
  892. 'value' => $row['value'],
  893. 'status' => ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR,
  894. 'translations' => $_translations
  895. );
  896. }
  897. }else{
  898. foreach($res as $row){
  899. $_translations = array();
  900. $_status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  901. $_statuses = array();
  902. foreach($sitepress->get_active_languages() as $l){
  903. if($l['code'] == $sitepress_settings['st']['strings_language'] || empty($user_lang_pairs[$sitepress_settings['st']['strings_language']][$l['code']])) continue;
  904. $lcode_alias = str_replace('-', '', $l['code']);
  905. if($row['id_'. $lcode_alias]){
  906. $_translations[$l['code']] = array(
  907. 'id' => $row['id_'. $lcode_alias],
  908. 'status' => $row['status_'. $lcode_alias],
  909. 'language' => $l['code'],
  910. 'value' => $row['value_'. $lcode_alias],
  911. 'translator_id' => $row['translator_'. $lcode_alias],
  912. 'translation_date' => $row['date_'. $lcode_alias]
  913. );
  914. }
  915. $_statuses[$l['code']] = @intval($row['status_'. $lcode_alias]);
  916. if($row['status_'. $lcode_alias] == ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR){
  917. $_status == ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR;
  918. }
  919. }
  920. $_statuses = array_values($_statuses);
  921. $_statuses = array_unique($_statuses);
  922. if($_statuses == array(ICL_STRING_TRANSLATION_NOT_TRANSLATED)){
  923. $_status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
  924. }elseif($_statuses == array(ICL_STRING_TRANSLATION_COMPLETE, ICL_STRING_TRANSLATION_NOT_TRANSLATED)){
  925. $_status = ICL_STRING_TRANSLATION_PARTIAL;
  926. }elseif($_statuses == array(ICL_STRING_TRANSLATION_COMPLETE)){
  927. $_status = ICL_STRING_TRANSLATION_COMPLETE;
  928. }elseif(in_array(ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR, $_statuses) || in_array(ICL_STRING_TRANSLATION_NEEDS_UPDATE, $_statuses)){
  929. $_status = ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR;
  930. }
  931. $string_translations[$row['string_id']] = array(
  932. 'string_id' => $row['string_id'],
  933. 'string_language' => $row['string_language'],
  934. 'context' => $row['context'],
  935. 'name' => $row['name'],
  936. 'value' => $row['value'],
  937. 'status' => $_status,
  938. 'translations' => $_translations
  939. );
  940. }
  941. }
  942. }
  943. /* TRANSLATOR - END */
  944. }else{
  945. // removed check for language = default lang
  946. if($status_filter != ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR){
  947. $res = $wpdb->get_results("
  948. SELECT SQL_CALC_FOUND_ROWS id AS string_id, language AS string_language, context, name, value, status
  949. FROM {$wpdb->prefix}icl_strings s
  950. WHERE
  951. 1
  952. {$extra_cond}
  953. ORDER BY string_id DESC
  954. LIMIT {$offset},{$limit}
  955. ", ARRAY_A);
  956. }else{
  957. $res = $wpdb->get_results("
  958. SELECT SQL_CALC_FOUND_ROWS s.id AS string_id, s.language AS string_language, s.context, s.name, s.value, " . ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR . " AS status
  959. FROM {$wpdb->prefix}icl_strings s
  960. JOIN {$wpdb->prefix}icl_string_translations str ON str.str

Large files files are truncated, but you can click here to view the full file