PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/sitepress-multilingual-cms/menu/troubleshooting.php

https://bitbucket.org/dkrzos/phc
PHP | 810 lines | 644 code | 89 blank | 77 comment | 68 complexity | de047f7dc707693fdfd24c120c28b01f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. include_once ICL_PLUGIN_PATH . '/inc/functions-troubleshooting.php';
  3. /* DEBUG ACTION */
  4. if(isset($_GET['debug_action']) && $_GET['nonce']==wp_create_nonce($_GET['debug_action'])){
  5. ob_end_clean();
  6. switch($_GET['debug_action']){
  7. case 'reset_pro_translation_configuration':
  8. $sitepress_settings = get_option('icl_sitepress_settings');
  9. $sitepress_settings['content_translation_languages_setup'] = false;
  10. $sitepress_settings['content_translation_setup_complete'] = false;
  11. unset($sitepress_settings['content_translation_setup_wizard_step']);
  12. unset($sitepress_settings['site_id']);
  13. unset($sitepress_settings['access_key']);
  14. unset($sitepress_settings['translator_choice']);
  15. unset($sitepress_settings['icl_lang_status']);
  16. unset($sitepress_settings['icl_balance']);
  17. unset($sitepress_settings['icl_support_ticket_id']);
  18. unset($sitepress_settings['icl_current_session']);
  19. unset($sitepress_settings['last_get_translator_status_call']);
  20. unset($sitepress_settings['last_icl_reminder_fetch']);
  21. unset($sitepress_settings['icl_account_email']);
  22. unset($sitepress_settings['translators_management_info']);
  23. update_option('icl_sitepress_settings', $sitepress_settings);
  24. mysql_query("TRUNCATE TABLE {$wpdb->prefix}icl_core_status");
  25. mysql_query("TRUNCATE TABLE {$wpdb->prefix}icl_content_status");
  26. mysql_query("TRUNCATE TABLE {$wpdb->prefix}icl_string_status");
  27. mysql_query("TRUNCATE TABLE {$wpdb->prefix}icl_node");
  28. mysql_query("TRUNCATE TABLE {$wpdb->prefix}icl_reminders");
  29. echo "<script type=\"text/javascript\">location.href='admin.php?page=".
  30. basename(ICL_PLUGIN_PATH).'/menu/troubleshooting.php&message=' . __('PRO translation was reset.', 'sitepress')."'</script>";
  31. exit;
  32. case 'ghost_clean':
  33. // clean the icl_translations table
  34. $orphans = $wpdb->get_col("
  35. SELECT t.translation_id
  36. FROM {$wpdb->prefix}icl_translations t
  37. LEFT JOIN {$wpdb->posts} p ON t.element_id = p.ID
  38. WHERE t.element_id IS NOT NULL AND t.element_type LIKE 'post\\_%' AND p.ID IS NULL
  39. ");
  40. if(!empty($orphans)){
  41. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id IN (".join(',',$orphans).")");
  42. }
  43. $orphans = $wpdb->get_col("
  44. SELECT t.translation_id
  45. FROM {$wpdb->prefix}icl_translations t
  46. LEFT JOIN {$wpdb->comments} c ON t.element_id = c.comment_ID
  47. WHERE t.element_type = 'comment' AND c.comment_ID IS NULL ");
  48. echo mysql_error();
  49. if(!empty($orphans)){
  50. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id IN (".join(',',$orphans).")");
  51. }
  52. $orphans = $wpdb->get_col("
  53. SELECT t.translation_id
  54. FROM {$wpdb->prefix}icl_translations t
  55. LEFT JOIN {$wpdb->term_taxonomy} p ON t.element_id = p.term_taxonomy_id
  56. WHERE t.element_id IS NOT NULL AND t.element_type LIKE 'tax\\_%' AND p.term_taxonomy_id IS NULL");
  57. if(!empty($orphans)){
  58. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id IN (".join(',',$orphans).")");
  59. }
  60. global $wp_taxonomies;
  61. if (is_array($wp_taxonomies)) {
  62. foreach ($wp_taxonomies as $t => $v) {
  63. $orphans = $wpdb->get_col("
  64. SELECT t.translation_id
  65. FROM {$wpdb->prefix}icl_translations t
  66. LEFT JOIN {$wpdb->term_taxonomy} p
  67. ON t.element_id = p.term_taxonomy_id
  68. WHERE t.element_type = 'tax_{$t}'
  69. AND p.taxonomy <> '{$t}'
  70. ");
  71. if (!empty($orphans)) {
  72. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id IN (".join(',',$orphans).")");
  73. }
  74. }
  75. }
  76. // remove ghost translations
  77. // get unlinked rids
  78. $rids = $wpdb->get_col("SELECT rid FROM {$wpdb->prefix}icl_translation_status WHERE translation_id NOT IN (SELECT translation_id FROM {$wpdb->prefix}icl_translations)");
  79. $jids = $wpdb->get_col("SELECT job_id FROM {$wpdb->prefix}icl_translate_job WHERE rid IN (".join(',', $rids).")");
  80. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translate WHERE job_id IN (".join(',', $jids).")");
  81. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translate_job WHERE job_id IN (".join(',', $jids).")");
  82. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translation_status WHERE rid IN (".join(',', $rids).")");
  83. // remove any duplicates in icl_translations
  84. $trs = $wpdb->get_results("SELECT element_id, GROUP_CONCAT(translation_id) AS tids FROM {$wpdb->prefix}icl_translations
  85. WHERE element_id > 0 AND element_type LIKE 'post\\_%' GROUP BY element_id");
  86. foreach($trs as $r){
  87. $exp = explode(',', $r->tids);
  88. if(count($exp) > 1){
  89. $maxtid = max($exp);
  90. foreach($exp as $e){
  91. if($e != $maxtid){
  92. $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $e));
  93. }
  94. }
  95. }
  96. }
  97. exit;
  98. break;
  99. case 'icl_sync_jobs':
  100. $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
  101. $requests = $iclq->cms_requests_all();
  102. if(!empty($requests))
  103. foreach($requests as $request){
  104. $source_language = ICL_Pro_Translation::server_languages_map($request['language_name'], true);
  105. $target_language = ICL_Pro_Translation::server_languages_map($request['target']['language_name'], true);
  106. $source_language = $wpdb->get_var($wpdb->prepare("SELECT code FROM {$wpdb->prefix}icl_languages WHERE english_name=%s", $source_language));
  107. $target_language = $wpdb->get_var($wpdb->prepare("SELECT code FROM {$wpdb->prefix}icl_languages WHERE english_name=%s", $target_language));
  108. // only handle old-style cms_id values
  109. if(!is_numeric($request['cms_id'])) continue;
  110. $tr = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", $request['cms_id']));
  111. if(empty($tr)){
  112. $trs = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translation_status WHERE translation_id=%d", $request['cms_id']));
  113. if(!empty($trs)){
  114. $tpack = unserialize($trs->translation_package);
  115. $original_id = $tpack['contents']['original_id']['data'];
  116. list($trid, $element_type) = $wpdb->get_row("
  117. SELECT trid, element_type
  118. FROM {$wpdb->prefix}icl_translations
  119. WHERE element_id={$original_id}
  120. AND element_type LIKE 'post\\_%'
  121. ", ARRAY_N);
  122. if($trid){
  123. $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translations WHERE trid={$trid} AND language_code='{$target_language}'");
  124. $recover = array(
  125. 'translation_id' => $request['cms_id'],
  126. 'element_type' => $element_type,
  127. //'element_id' => this is NULL
  128. 'trid' => $trid,
  129. 'language_code' => $target_language,
  130. 'source_language_code' => $source_language
  131. );
  132. $wpdb->insert($wpdb->prefix . 'icl_translations', $recover);
  133. }
  134. }
  135. }
  136. }
  137. // Do a check to see if the icl_translation_status is consistant.
  138. // There was a problem with the cancel logic leaving it in a status where
  139. // Translations couldn't be sent.
  140. global $iclTranslationManagement;
  141. $res = $wpdb->get_results($wpdb->prepare("
  142. SELECT rid, status, needs_update, md5, translation_package
  143. FROM {$wpdb->prefix}icl_translation_status"
  144. ));
  145. foreach($res as $row){
  146. if ($row->status == ICL_TM_NOT_TRANSLATED || $row->needs_update == 1) {
  147. $tpack = unserialize($row->translation_package);
  148. $original_id = $tpack['contents']['original_id']['data'];
  149. $post_md5 = $iclTranslationManagement->post_md5($original_id);
  150. if ($post_md5 == $row->md5) {
  151. // The md5 shouldn't be the same if it's not translated or needs update.
  152. // Add a dummy md5 and mark it as needs_update.
  153. $data = array('needs_update' => 1, 'md5' => 'XXXX');
  154. $wpdb->update($wpdb->prefix.'icl_translation_status', $data, array('rid'=>$row->rid));
  155. }
  156. }
  157. }
  158. exit;
  159. //break;
  160. case 'icl_cms_id_fix':
  161. $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
  162. $p = $wpdb->get_row("SELECT t.* FROM {$wpdb->prefix}icl_translations t JOIN {$wpdb->prefix}icl_translation_status s ON t.translation_id=s.translation_id
  163. WHERE t.element_type LIKE 'post\\_%' AND t.source_language_code IS NOT NULL AND s.translation_service='icanlocalize' LIMIT {$_REQUEST['offset']}, 1");
  164. if(!empty($p)){
  165. $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND source_language_code IS NULL", $p->trid));
  166. if($p->element_type=='post_page'){
  167. $permalink = get_option('home') . '?page_id=' . $original_id;
  168. }else{
  169. $permalink = get_option('home') . '?p=' . $original_id;
  170. }
  171. $_lang_details = $sitepress->get_language_details($p->source_language_code);
  172. $from_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']);
  173. $_lang_details = $sitepress->get_language_details($p->language_code);
  174. $to_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']);
  175. $cms_id = sprintf('%s_%d_%s_%s', preg_replace('#^post_#','',$p->element_type), $original_id, $p->source_language_code, $p->language_code);
  176. $ret = $iclq->update_cms_id(compact('permalink', 'from_language', 'to_language', 'cms_id'));
  177. if($ret != $cms_id && $iclq->error()){
  178. echo json_encode(array('errors'=>1, 'message'=>$iclq->error(), 'cont'=>0));
  179. }else{
  180. echo json_encode(array('errors'=>0, 'message'=>'OK', 'cont'=>1));
  181. }
  182. }else{
  183. echo json_encode(array('errors'=>0, 'message'=>__('Done', 'sitepress'), 'cont'=>0));
  184. }
  185. exit;
  186. //break;
  187. case 'icl_cleanup':
  188. global $sitepress, $wpdb, $wp_post_types;
  189. $post_types = array_keys($wp_post_types);
  190. foreach($post_types as $pt){
  191. $types[] = 'post_' . $pt;
  192. }
  193. /*
  194. * Messed up on 2.0 upgrade
  195. */
  196. // fix source_language_code
  197. // all source documents must have null
  198. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translations SET source_language_code = NULL
  199. WHERE element_type IN('".join("','", $types)."') AND source_language_code = '' AND language_code='%s'", $sitepress->get_default_language()));
  200. // get translated documents with missing source language
  201. $res = $wpdb->get_results($wpdb->prepare("
  202. SELECT translation_id, trid, language_code
  203. FROM {$wpdb->prefix}icl_translations
  204. WHERE (source_language_code = '' OR source_language_code IS NULL)
  205. AND element_type IN('".join("','", $types)."')
  206. AND language_code <> %s
  207. ", $sitepress->get_default_language()
  208. ));
  209. foreach($res as $row){
  210. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translations SET source_language_code = '%s' WHERE translation_id=%d", $sitepress->get_default_language(), $row->translation_id));
  211. }
  212. break;
  213. case 'sync_cancelled':
  214. $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']);
  215. $requests = $iclq->cms_requests_all();
  216. if($requests === false) {
  217. echo json_encode(array('errors'=>1, 'message'=>'Failed fetching jobs list from the server.'));
  218. exit;
  219. }
  220. $cms_ids = array();
  221. if(!empty($requests))
  222. foreach($requests as $request){
  223. $cms_ids[] = $request['cms_id'];
  224. }
  225. // get jobs that are in progress
  226. $translations = $wpdb->get_results("
  227. SELECT t.element_id, t.element_type, t.language_code, t.source_language_code, t.trid,
  228. s.rid, s._prevstate, s.translation_id
  229. FROM {$wpdb->prefix}icl_translation_status s
  230. JOIN {$wpdb->prefix}icl_translations t
  231. ON t.translation_id = s.translation_id
  232. WHERE s.translation_service='icanlocalize'
  233. AND s.status = ".ICL_TM_IN_PROGRESS."
  234. ");
  235. $job2delete = $rids2cancel = array();
  236. foreach($translations as $t){
  237. $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations
  238. WHERE trid=%d AND source_language_code IS NULL", $t->trid));
  239. $cms_id = sprintf('%s_%d_%s_%s', preg_replace('#^post_#','', $t->element_type), $original_id, $t->source_language_code, $t->language_code);
  240. if(!in_array($cms_id, $cms_ids)){
  241. $_lang_details = $sitepress->get_language_details($t->source_language_code);
  242. $lang_from = $_lang_details['english_name'];
  243. $_lang_details = $sitepress->get_language_details($t->language_code);
  244. $lang_to = $_lang_details['english_name'];
  245. $jobs2delete[] = '<a href="'.get_permalink($original_id).'">'.get_the_title($original_id).'</a>' . sprintf(' - from %s to %s',
  246. $lang_from, $lang_to);
  247. $translations2cancel[] = $t;
  248. }
  249. }
  250. if(!empty($jobs2delete)){
  251. echo json_encode(array('errors'=>0,
  252. 'message'=> '<div class="error" style="padding-top:5px;font-size:11px;">About to cancel these jobs:<br />
  253. <ul style="margin-left:10px;"><li>' . join('</li><li>', $jobs2delete) . '</li></ul><br />
  254. <a id="icl_ts_cancel_ok" href="#" class="button-secondary">OK</a>&nbsp;
  255. <a id="icl_ts_cancel_cancel" href="#" class="button-secondary">Cancel</a><br clear="all" /><br />
  256. </div>',
  257. 'data' => array('t2c'=>serialize($translations2cancel))
  258. )
  259. );
  260. }else{
  261. echo json_encode(array('errors'=>0, 'message'=> 'Nothing to cancel.'));
  262. }
  263. exit;
  264. case 'sync_cancelled_do_delete':
  265. $translations = unserialize(stripslashes($_POST['t2c']));
  266. if(is_array($translations)) foreach($translations as $t){
  267. $job_id = $wpdb->get_var($wpdb->prepare("SELECT job_id FROM {$wpdb->prefix}icl_translate_job WHERE rid=%d AND revision IS NULL", $t->rid));
  268. if($job_id){
  269. $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_translate_job WHERE job_id=%d", $job_id));
  270. $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_translate WHERE job_id=%d", $job_id));
  271. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translate_job SET revision = NULL WHERE rid=%d ORDER BY job_id DESC LIMIT 1", $t->rid));
  272. }
  273. if(!empty($t->_prevstate)){
  274. $_prevstate = unserialize($t->_prevstate);
  275. $wpdb->update($wpdb->prefix . 'icl_translation_status',
  276. array(
  277. 'status' => $_prevstate['status'],
  278. 'translator_id' => $_prevstate['translator_id'],
  279. 'status' => $_prevstate['status'],
  280. 'needs_update' => $_prevstate['needs_update'],
  281. 'md5' => $_prevstate['md5'],
  282. 'translation_service' => $_prevstate['translation_service'],
  283. 'translation_package' => $_prevstate['translation_package'],
  284. 'timestamp' => $_prevstate['timestamp'],
  285. 'links_fixed' => $_prevstate['links_fixed']
  286. ),
  287. array('translation_id'=>$t->translation_id)
  288. );
  289. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translation_status SET _prevstate = NULL WHERE translation_id=%d",$t->translation_id));
  290. }else{
  291. $wpdb->update($wpdb->prefix . 'icl_translation_status', array('status'=>ICL_TM_NOT_TRANSLATED, 'needs_update'=>0), array('translation_id'=>$t->translation_id));
  292. }
  293. }
  294. echo json_encode(array('errors'=>0, 'message'=> 'OK'));
  295. exit;
  296. case 'icl_ts_add_missing_language':
  297. $ptypes = array_keys($sitepress->get_translatable_documents());
  298. $posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_type IN ('".join("','", $ptypes)."')");
  299. foreach($posts as $p){
  300. $tid = $wpdb->get_var($wpdb->prepare("
  301. SELECT translation_id FROM {$wpdb->prefix}icl_translations
  302. WHERE element_type=%s AND element_id=%d
  303. ", 'post_' . $p->post_type, $p->ID));
  304. if(!$tid){
  305. $sitepress->set_element_language_details($p->ID, 'post_' . $p->post_type, null, $sitepress->get_default_language());
  306. }
  307. }
  308. $ttypes = array();
  309. foreach($ptypes as $ptype){
  310. $ttypes = array_merge($sitepress->get_translatable_taxonomies(true, $ptype), $ttypes);
  311. }
  312. $ttypes = array_unique($ttypes);
  313. $taxs = $wpdb->get_results("SELECT * FROM {$wpdb->term_taxonomy} WHERE taxonomy IN ('".join("','", $ttypes)."')");
  314. foreach($taxs as $t){
  315. $tid = $wpdb->get_var($wpdb->prepare("
  316. SELECT translation_id FROM {$wpdb->prefix}icl_translations
  317. WHERE element_type=%s AND element_id=%d
  318. ", 'tax_' . $t->taxonomy, $t->term_taxonomy_id));
  319. if(!$tid){
  320. $sitepress->set_element_language_details($t->term_taxonomy_id,
  321. 'tax_' . $t->taxonomy, null, $sitepress->get_default_language());
  322. }
  323. }
  324. $cids = $wpdb->get_col("SELECT c.comment_ID FROM {$wpdb->comments} c LEFT JOIN {$wpdb->prefix}icl_translations t ON t.element_id = c.comment_id AND t.element_type='comment' WHERE t.element_id IS NULL");
  325. foreach($cids as $cid){
  326. $sitepress->set_element_language_details($cid, 'comment', null, $sitepress->get_default_language());
  327. }
  328. exit;
  329. }
  330. }
  331. /* DEBUG ACTION */
  332. $icl_tables = array(
  333. $wpdb->prefix . 'icl_languages',
  334. $wpdb->prefix . 'icl_languages_translations',
  335. $wpdb->prefix . 'icl_translations',
  336. $wpdb->prefix . 'icl_translation_status',
  337. $wpdb->prefix . 'icl_translate_job',
  338. $wpdb->prefix . 'icl_translate',
  339. $wpdb->prefix . 'icl_locale_map',
  340. $wpdb->prefix . 'icl_flags',
  341. $wpdb->prefix . 'icl_content_status',
  342. $wpdb->prefix . 'icl_core_status',
  343. $wpdb->prefix . 'icl_node',
  344. $wpdb->prefix . 'icl_strings',
  345. $wpdb->prefix . 'icl_string_translations',
  346. $wpdb->prefix . 'icl_string_status',
  347. $wpdb->prefix . 'icl_string_positions',
  348. $wpdb->prefix . 'icl_message_status',
  349. $wpdb->prefix . 'icl_reminders',
  350. );
  351. if( (isset($_POST['icl_reset_allnonce']) && $_POST['icl_reset_allnonce']==wp_create_nonce('icl_reset_all'))){
  352. if($_POST['icl-reset-all']=='on'){
  353. icl_reset_wpml();
  354. echo '<script type="text/javascript">location.href=\''.admin_url('plugins.php?deactivate=true').'\'</script>';
  355. }
  356. }
  357. ?>
  358. <div class="wrap">
  359. <div id="icon-wpml" class="icon32"><br /></div>
  360. <h2><?php echo __('Troubleshooting', 'sitepress') ?></h2>
  361. <?php if(isset($_GET['message'])):?>
  362. <div class="updated message fade"><p>
  363. <?php echo esc_html($_GET['message']);?>
  364. </p></div>
  365. <?php endif?>
  366. <?php
  367. /*
  368. foreach($icl_tables as $icl_table){
  369. echo '<a href="#'.$icl_table.'_anch">'.$icl_table.'</a> | ';
  370. }
  371. */
  372. echo '<a href="#wpml-settings">'.__('WPML Settings', 'sitepress').'</a>';
  373. /*
  374. foreach($icl_tables as $icl_table){
  375. echo '<h3 id="'.$icl_table.'_anch" onclick="jQuery(\'#'.$icl_table.'\').toggle(); jQuery(\'#'.$icl_table.'_arrow_up\').toggle(); jQuery(\'#'.$icl_table.'_arrow_dn\').toggle();" style="cursor:pointer">'.$icl_table.'&nbsp;&nbsp;<span id="'.$icl_table.'_arrow_up" style="display:none">&uarr;</span><span id="'.$icl_table.'_arrow_dn">&darr;</span></h3>';
  376. if(strtolower($wpdb->get_var("SHOW TABLES LIKE '{$icl_table}'")) != strtolower($icl_table)){
  377. echo '<p class="error">'.__('Not found!', 'sitepress').'</p>';
  378. }else{
  379. $results = $wpdb->get_results("DESCRIBE {$icl_table}", ARRAY_A);
  380. $keys = array_keys($results[0]);
  381. ?>
  382. <table class="widefat">
  383. <thead>
  384. <tr>
  385. <?php foreach($keys as $k): ?><th width="<?php echo floor(100/count($keys)) ?>%"><?php echo $k ?></th><?php endforeach; ?>
  386. </tr>
  387. </thead>
  388. <tbody>
  389. <?php foreach($results as $r):?>
  390. <tr>
  391. <?php foreach($keys as $k): ?><td><?php echo $r[$k] ?></td><?php endforeach; ?>
  392. </tr>
  393. <?php endforeach; ?>
  394. </tbody>
  395. <tbody>
  396. </table>
  397. <?php
  398. echo '<span id="'.$icl_table.'" style="display:none">';
  399. $results = $wpdb->get_results("SELECT * FROM {$icl_table}", ARRAY_A);
  400. echo '<textarea style="font-size:10px;width:100%" wrap="off" rows="8" readonly="readonly">';
  401. $inc = 0;
  402. foreach((array)$results as $res){
  403. if($inc==0){
  404. $columns = array_keys($res);
  405. $columns = array_map('__custom_csv_escape', $columns);
  406. echo implode(",", $columns) . PHP_EOL;;
  407. }
  408. $inc++;
  409. $res = array_map('__custom_csv_escape', $res);
  410. echo implode(",", $res) . PHP_EOL;
  411. }
  412. echo '</textarea>';
  413. echo '</span>';
  414. }
  415. }
  416. function __custom_csv_escape($s){
  417. $s = "&#34;". str_replace('"','&#34;',addslashes($s)) . "&#34;";
  418. return $s;
  419. }
  420. */
  421. echo '<br /><hr /><h3 id="wpml-settings"> ' . __('WPML settings', 'sitepress') . '</h3>';
  422. echo '<textarea style="font-size:10px;width:100%" wrap="off" rows="16" readonly="readonly">';
  423. ob_start();
  424. print_r($sitepress->get_settings());
  425. $ob = ob_get_contents();
  426. ob_end_clean();
  427. echo htmlspecialchars($ob);
  428. echo '</textarea>';
  429. ?>
  430. <script type="text/javascript">
  431. jQuery(document).ready(function(){
  432. jQuery('#icl_torubleshooting_more_options').submit(iclSaveForm);
  433. })
  434. </script>
  435. <br clear="all" /><br />
  436. <?php if(!defined('ICL_DONT_PROMOTE') || !ICL_DONT_PROMOTE):?>
  437. <div class="icl_cyan_box" >
  438. <h3><?php _e('More options', 'sitepress')?></h3>
  439. <form name="icl_torubleshooting_more_options" id="icl_torubleshooting_more_options" action="">
  440. <?php wp_nonce_field('icl_torubleshooting_more_options_nonce', '_icl_nonce'); ?>
  441. <label><input type="checkbox" name="troubleshooting_options[raise_mysql_errors]" value="1" <?php
  442. if(!empty($sitepress_settings['troubleshooting_options']['raise_mysql_errors'])): ?>checked="checked"<?php endif; ?>/>&nbsp;<?php
  443. _e('Raise mysql errors on XML-RPC calls', 'sitepress')?></label>
  444. <br />
  445. <label><input type="checkbox" name="troubleshooting_options[http_communication]" value="1" <?php
  446. if($sitepress_settings['troubleshooting_options']['http_communication']): ?>checked="checked"<?php endif; ?>/>&nbsp;<?php
  447. _e('Communicate with ICanLocalize using HTTP instead of HTTPS', 'sitepress')?></label>
  448. <p>
  449. <input class="button" name="save" value="<?php echo __('Apply','sitepress') ?>" type="submit" />
  450. <span class="icl_ajx_response" id="icl_ajx_response"></span>
  451. </p>
  452. </form>
  453. </div>
  454. <br clear="all" />
  455. <?php endif; ?>
  456. <br />
  457. <script type="text/javascript">
  458. jQuery(document).ready(function(){
  459. jQuery('#icl_remove_ghost').click(function(){
  460. jQuery(this).attr('disabled', 'disabled');
  461. jQuery(this).after(icl_ajxloaderimg);
  462. jQuery.post(location.href + '&debug_action=ghost_clean&nonce=<?php echo wp_create_nonce('ghost_clean'); ?>', function(){
  463. jQuery('#icl_remove_ghost').removeAttr('disabled');
  464. alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
  465. jQuery('#icl_remove_ghost').next().fadeOut();
  466. });
  467. })
  468. jQuery('#icl_sync_jobs').click(function(){
  469. jQuery(this).attr('disabled', 'disabled');
  470. jQuery(this).after(icl_ajxloaderimg);
  471. jQuery.post(location.href + '&debug_action=icl_sync_jobs&nonce=<?php echo wp_create_nonce('icl_sync_jobs'); ?>', function(){
  472. jQuery('#icl_sync_jobs').removeAttr('disabled');
  473. alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
  474. jQuery('#icl_sync_jobs').next().fadeOut();
  475. });
  476. })
  477. jQuery('#icl_cleanup').click(function(){
  478. jQuery(this).attr('disabled', 'disabled');
  479. jQuery(this).after(icl_ajxloaderimg);
  480. jQuery.post(location.href + '&debug_action=icl_cleanup&nonce=<?php echo wp_create_nonce('icl_cleanup'); ?>', function(){
  481. jQuery('#icl_cleanup').removeAttr('disabled');
  482. alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
  483. jQuery('#icl_cleanup').next().fadeOut();
  484. });
  485. })
  486. function _icl_sync_cms_id(offset){
  487. jQuery('#icl_cms_id_fix_prgs_cnt').html(offset+1);
  488. jQuery.ajax({
  489. type: "POST",
  490. url: location.href + '&debug_action=icl_cms_id_fix&nonce=<?php echo wp_create_nonce('icl_cms_id_fix'); ?>&offset='+offset,
  491. data: 'debug_action=icl_cms_id_fix&nonce=<?php echo wp_create_nonce('icl_cms_id_fix'); ?>&offset='+offset,
  492. dataType: 'json',
  493. success: function(msg){
  494. if(msg.errors > 0){
  495. alert(msg.message);
  496. jQuery('#icl_cms_id_fix').removeAttr('disabled');
  497. jQuery('#icl_cms_id_fix').next().fadeOut();
  498. jQuery('#icl_cms_id_fix_prgs').fadeOut();
  499. }else{
  500. offset++;
  501. if(msg.cont){
  502. _icl_sync_cms_id(offset);
  503. }else{
  504. alert(msg.message);
  505. jQuery('#icl_cms_id_fix').removeAttr('disabled');
  506. jQuery('#icl_cms_id_fix').next().fadeOut();
  507. jQuery('#icl_cms_id_fix_prgs').fadeOut();
  508. }
  509. }
  510. }
  511. });
  512. }
  513. jQuery('#icl_cms_id_fix').click(function(){
  514. jQuery(this).attr('disabled', 'disabled');
  515. jQuery(this).after(icl_ajxloaderimg);
  516. jQuery('#icl_cms_id_fix_prgs').fadeIn();
  517. _icl_sync_cms_id(0);
  518. })
  519. jQuery('#icl_sync_cancelled').click(function(){
  520. jQuery(this).attr('disabled', 'disabled');
  521. jQuery(this).after(icl_ajxloaderimg);
  522. jQuery('#icl_sync_cancelled_resp').html('');
  523. jQuery.ajax({
  524. type: "POST",
  525. url: location.href.replace(/#/,'') + '&debug_action=sync_cancelled&nonce=<?php echo wp_create_nonce('sync_cancelled'); ?>',
  526. data: 'debug_action=sync_cancelled&nonce=<?php echo wp_create_nonce('sync_cancelled'); ?>',
  527. dataType: 'json',
  528. success: function(msg){
  529. if(msg.errors > 0){
  530. jQuery('#icl_sync_cancelled_resp').html(msg.message);
  531. }else{
  532. jQuery('#icl_sync_cancelled_resp').html(msg.message);
  533. if(msg.data){
  534. jQuery('#icl_ts_t2c').val(msg.data.t2c);
  535. }
  536. }
  537. jQuery('#icl_sync_cancelled').removeAttr('disabled');
  538. jQuery('#icl_sync_cancelled').next().fadeOut();
  539. }
  540. });
  541. });
  542. jQuery('#icl_ts_cancel_cancel').live('click', function(){
  543. jQuery('#icl_sync_cancelled_resp').html('');
  544. return false;
  545. });
  546. jQuery('#icl_ts_cancel_ok').live('click', function(){
  547. jQuery(this).attr('disabled', 'disabled');
  548. jQuery(this).after(icl_ajxloaderimg);
  549. jQuery.ajax({
  550. type: "POST",
  551. url: location.href.replace(/#/,'') + '&debug_action=sync_cancelled_do_delete&nonce=<?php echo wp_create_nonce('sync_cancelled_do_delete'); ?>',
  552. data: 'debug_action=sync_cancelled_do_delete&nonce=<?php echo wp_create_nonce('sync_cancelled_do_delete'); ?>&t2c='+jQuery('#icl_ts_t2c').val(),
  553. dataType: 'json',
  554. success: function(msg){
  555. if(msg.errors > 0){
  556. jQuery('#icl_sync_cancelled_resp').html(msg.message);
  557. }else{
  558. alert('Done');
  559. jQuery('#icl_sync_cancelled_resp').html('');
  560. }
  561. jQuery('#icl_ts_cancel_ok').removeAttr('disabled');
  562. jQuery('#icl_ts_cancel_ok').next().fadeOut();
  563. }
  564. });
  565. return false;
  566. });
  567. jQuery('#icl_add_missing_lang').click(function(){
  568. jQuery(this).attr('disabled', 'disabled');
  569. jQuery(this).after(icl_ajxloaderimg);
  570. jQuery.post(location.href + '&debug_action=icl_ts_add_missing_language&nonce=<?php
  571. echo wp_create_nonce('icl_ts_add_missing_language'); ?>', function(){
  572. jQuery('#icl_add_missing_lang').removeAttr('disabled');
  573. alert('<?php echo esc_js(__('Done', 'sitepress')) ?>');
  574. jQuery('#icl_add_missing_lang').next().fadeOut();
  575. });
  576. })
  577. })
  578. </script>
  579. <div class="icl_cyan_box" >
  580. <h3><?php _e('Clean up', 'sitepress')?></h3>
  581. <p class="error" style="padding:6px;"><?php _e('Please make backup of your database before using this.', 'sitepress') ?></p>
  582. <p>
  583. <input id="icl_remove_ghost" type="button" class="button-secondary" value="<?php _e('Remove ghost entries from the translation tables', 'sitepress')?>" /><br />
  584. <small style="margin-left:10px;">Removes entries from the WPML tables that are not linked properly. Cleans the table off entries left over upgrades, bug fixes or undetermined factors.</small>
  585. </p>
  586. <?php if(!empty($sitepress_settings['site_id']) && !empty($sitepress_settings['access_key'])):?>
  587. <p>
  588. <input id="icl_sync_jobs" type="button" class="button-secondary" value="<?php _e('Synchronize translation jobs with ICanLocalize', 'sitepress')?>" /><br />
  589. <small style="margin-left:10px;">Fixes links between translation entries in the database and ICanLocalize.</small>
  590. </p>
  591. <p>
  592. <input id="icl_cms_id_fix" type="button" class="button-secondary" value="<?php _e('CMS ID fix', 'sitepress')?>" />
  593. <span id="icl_cms_id_fix_prgs" style="display: none;"><?php printf('fixing %s/%d', '<span id="icl_cms_id_fix_prgs_cnt">0</span>', $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}icl_translations t JOIN {$wpdb->prefix}icl_translation_status s ON t.translation_id=s.translation_id WHERE t.element_type LIKE 'post\\_%' AND t.source_language_code IS NOT NULL AND s.translation_service='icanlocalize'")) ?></span><br />
  594. <small style="margin-left:10px;">Updates translation in progress with new style identifiers for documents. The new identifiers depend on the document being translated and the languages so it's not possible to get out of sync when translations are being deleted locally.</small>
  595. </p>
  596. <?php endif; ?>
  597. <p>
  598. <input id="icl_cleanup" type="button" class="button-secondary" value="<?php _e('General clean up', 'sitepress')?>" /><br />
  599. <small style="margin-left:10px;">Sets source language to NULL in the icl_translations table. </small>
  600. </p>
  601. <?php if(!defined('ICL_DONT_PROMOTE') || !ICL_DONT_PROMOTE):?>
  602. <p>
  603. <input id="icl_sync_cancelled" type="button" class="button-secondary" value="<?php _e('Check cancelled jobs on ICanLocalize', 'sitepress')?>" /><br />
  604. <small style="margin-left:10px;">When using the translation pickup mode cancelled jobs on ICanLocalize need to be synced manually.</small>
  605. </p>
  606. <span id="icl_sync_cancelled_resp"></span>
  607. <input type="hidden" id="icl_ts_t2c" value="" />
  608. <?php endif; ?>
  609. <p>
  610. <input id="icl_add_missing_lang" type="button" class="button-secondary" value="<?php _e('Set language information', 'sitepress')?>" /><br />
  611. <small style="margin-left:10px;">Adds language information to posts and taxonomies that are missing this information.</small>
  612. </p>
  613. </div>
  614. <br clear="all" />
  615. <?php if(!defined('ICL_DONT_PROMOTE') || !ICL_DONT_PROMOTE):?>
  616. <br />
  617. <div class="icl_cyan_box" >
  618. <h3><?php _e('Reset PRO translation configuration', 'sitepress')?></h3>
  619. <div class="icl_form_errors"><?php _e("Resetting your ICanLocalize account will interrupt any translation jobs that you have in progress. Only use this function if your ICanLocalize account doesn't include any jobs, or if the account was deleted.", 'sitepress'); ?></div>
  620. <p style="padding:6px;"><label><input onchange="if(jQuery(this).attr('checked')) jQuery('#icl_reset_pro_but').removeClass('button-primary-disabled'); else jQuery('#icl_reset_pro_but').addClass('button-primary-disabled');" id="icl_reset_pro_check" type="checkbox" value="1" />&nbsp;<?php echo _e('I am about to reset the ICanLocalize project setting.', 'sitepress'); ?></label></p>
  621. <a id="icl_reset_pro_but" onclick="if(!jQuery('#icl_reset_pro_check').attr('checked') || !confirm('<?php echo esc_js(__('Are you sure you want to reset the PRO translation configuration?', 'sitepress')) ?>')) return false;" href="admin.php?page=<?php echo basename(ICL_PLUGIN_PATH)?>/menu/troubleshooting.php&amp;debug_action=reset_pro_translation_configuration&amp;nonce=<?php echo wp_create_nonce('reset_pro_translation_configuration')?>" class="button-primary button-primary-disabled"><?php _e('Reset PRO translation configuration', 'sitepress');?></a>
  622. </div>
  623. <br clear="all" />
  624. <?php endif; ?>
  625. <br />
  626. <div class="icl_cyan_box" >
  627. <h3><?php _e('Database dump', 'sitepress')?></h3>
  628. <a class="button" href="admin.php?page=<?php echo ICL_PLUGIN_FOLDER ?>/menu/troubleshooting.php&amp;icl_action=dbdump&amp;nonce=<?php echo wp_create_nonce('dbdump') ?>"><?php _e('Download', 'sitepress') ?></a>
  629. </div>
  630. <br clear="all" />
  631. <?php if(!defined('ICL_DONT_PROMOTE') || !ICL_DONT_PROMOTE):?>
  632. <br />
  633. <div class="icl_cyan_box" >
  634. <a name="icl-connection-test"></a>
  635. <h3><?php _e('ICanLocalize connection test', 'sitepress')?></h3>
  636. <?php if(isset($_GET['icl_action']) && $_GET['icl_action']=='icl-connection-test'): ?>
  637. <?php
  638. $icl_query = new ICanLocalizeQuery();
  639. if(isset($_GET['data'])){
  640. $user = unserialize(base64_decode($_GET['data']));
  641. }else{
  642. $user['create_account'] = 1;
  643. $user['anon'] = 1;
  644. $user['platform_kind'] = 2;
  645. $user['cms_kind'] = 1;
  646. $user['blogid'] = $wpdb->blogid?$wpdb->blogid:1;
  647. $user['url'] = get_option('siteurl');
  648. $user['title'] = get_option('blogname');
  649. $user['description'] = isset($sitepress_settings['icl_site_description']) ? $sitepress_settings['icl_site_description'] : '';
  650. $user['is_verified'] = 1;
  651. if(defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')){
  652. $user['affiliate_id'] = ICL_AFFILIATE_ID;
  653. $user['affiliate_key'] = ICL_AFFILIATE_KEY;
  654. }
  655. $user['interview_translators'] = $sitepress_settings['interview_translators'];
  656. $user['project_kind'] = 2;
  657. $user['pickup_type'] = intval($sitepress_settings['translation_pickup_method']);
  658. $notifications = 0;
  659. if ( !empty($sitepress_settings['icl_notify_complete'])){
  660. $notifications += 1;
  661. }
  662. if ( $sitepress_settings['alert_delay']){
  663. $notifications += 2;
  664. }
  665. $user['notifications'] = $notifications;
  666. $user['ignore_languages'] = 0;
  667. $user['from_language1'] = isset($_GET['lang_from']) ? $_GET['lang_from'] : 'English';
  668. $user['to_language1'] = isset($_GET['lang_to']) ? $_GET['lang_to'] : 'French';
  669. }
  670. define('ICL_DEB_SHOW_ICL_RAW_RESPONSE', true);
  671. $resp = $icl_query->createAccount($user);
  672. echo '<textarea style="width:100%;height:400px;font-size:9px;">';
  673. if (defined('ICL_API_ENDPOINT')) {
  674. echo ICL_API_ENDPOINT . "\r\n\r\n";
  675. }
  676. echo __('Data', 'sitepress') . "\n----------------------------------------\n" .
  677. print_r($user, 1) .
  678. __('Response', 'sitepress') . "\n----------------------------------------\n" .
  679. print_r($resp, 1) .
  680. '</textarea>';
  681. ?>
  682. <?php endif; ?>
  683. <a class="button" href="admin.php?page=<?php echo ICL_PLUGIN_FOLDER ?>/menu/troubleshooting.php&ts=<?php echo time()?>&icl_action=icl-connection-test#icl-connection-test"><?php _e('Connect', 'sitepress') ?></a>
  684. </div>
  685. <br clear="all" />
  686. <?php endif; ?>
  687. <br />
  688. <div class="icl_cyan_box" >
  689. <?php
  690. echo '<h3 id="wpml-settings"> ' . __('Reset', 'sitepress') . '</h3>';
  691. ?>
  692. <?php if ( function_exists('is_multisite') && is_multisite() ): ?>
  693. <p><?php _e('This function is available through the Network Admin section.', 'sitepress'); ?></p>
  694. <?php if(current_user_can('manage_sites')): ?>
  695. <a href="<?php echo esc_url(network_admin_url('admin.php?page='.ICL_PLUGIN_FOLDER.'/menu/network.php'))?>"><?php _e('Go to WPML Network settings.', 'sitepress')?></a>
  696. <?php else: ?>
  697. <i><?php _e('You are not allowed to manage the WPML Network settings.', 'sitepress')?></i>
  698. <?php endif;?>
  699. <?php else: ?>
  700. <?php
  701. echo '<form method="post" onsubmit="return confirm(\''.__('Are you sure you want to reset all languages data? This operation cannot be reversed.', 'sitepress').'\')">';
  702. wp_nonce_field('icl_reset_all','icl_reset_allnonce');
  703. echo '<p class="error" style="padding:6px;">' . __("All translations you have sent to ICanLocalize will be lost if you reset WPML's data. They cannot be recovered later.", 'sitepress')
  704. . '</p>';
  705. echo '<label><input type="checkbox" name="icl-reset-all" ';
  706. if(!function_exists('is_super_admin') || is_super_admin()){
  707. echo 'onchange="if(this.checked) jQuery(\'#reset-all-but\').removeAttr(\'disabled\'); else jQuery(\'#reset-all-but\').attr(\'disabled\',\'disabled\');"';
  708. }
  709. echo ' /> ' . __('I am about to reset all language data.', 'sitepress') . '</label><br /><br />';
  710. echo '<input id="reset-all-but" type="submit" disabled="disabled" class="button-primary" value="'.__('Reset all language data and deactivate WPML', 'sitepress').'" />';
  711. echo '</form>';
  712. ?>
  713. <?php endif; ?>
  714. </div>
  715. <?php do_action('icl_menu_footer'); ?>
  716. </div>