PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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

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