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

/htdocs/wp-content/plugins/sitepress-multilingual-cms/inc/sitepress-schema.php

https://bitbucket.org/dkrzos/phc
PHP | 433 lines | 351 code | 35 blank | 47 comment | 65 complexity | aef2780f54664f864799073fd2a12aeb MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. function icl_sitepress_activate(){
  3. //if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'error_scrape'){
  4. // return;
  5. //}
  6. global $wpdb;
  7. global $EZSQL_ERROR;
  8. require_once(ICL_PLUGIN_PATH . '/inc/lang-data.php');
  9. //defines $langs_names
  10. $charset_collate = '';
  11. if ( method_exists($wpdb, 'has_cap') && $wpdb->has_cap( 'collation' ) ) {
  12. if ( ! empty($wpdb->charset) )
  13. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  14. if ( ! empty($wpdb->collate) )
  15. $charset_collate .= " COLLATE $wpdb->collate";
  16. }
  17. try{
  18. // languages table
  19. $table_name = $wpdb->prefix.'icl_languages';
  20. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  21. $sql = "
  22. CREATE TABLE `{$table_name}` (
  23. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  24. `code` VARCHAR( 7 ) NOT NULL ,
  25. `english_name` VARCHAR( 128 ) NOT NULL ,
  26. `major` TINYINT NOT NULL DEFAULT '0',
  27. `active` TINYINT NOT NULL ,
  28. `default_locale` VARCHAR( 8 ),
  29. `encode_url` TINYINT( 1 ) NOT NULL DEFAULT 0,
  30. UNIQUE KEY `code` (`code`),
  31. UNIQUE KEY `english_name` (`english_name`)
  32. ) ENGINE=MyISAM {$charset_collate}";
  33. $wpdb->query($sql);
  34. if($e = mysql_error()) throw new Exception($e);
  35. //$langs_names is defined in ICL_PLUGIN_PATH . '/inc/lang-data.php'
  36. foreach($langs_names as $key=>$val){
  37. if(strpos($key,'Norwegian Bokm')===0){ $key = 'Norwegian Bokmål'; $lang_codes[$key] = 'nb';} // exception for norwegian
  38. $default_locale = isset($lang_locales[$lang_codes[$key]]) ? $lang_locales[$lang_codes[$key]] : '';
  39. @$wpdb->insert($wpdb->prefix . 'icl_languages', array('english_name'=>$key, 'code'=>$lang_codes[$key], 'major'=>$val['major'], 'active'=>0, 'default_locale'=>$default_locale));
  40. }
  41. }
  42. // languages translations table
  43. $add_languages_translations = false;
  44. $table_name = $wpdb->prefix.'icl_languages_translations';
  45. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  46. $sql = "
  47. CREATE TABLE `{$table_name}` (
  48. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  49. `language_code` VARCHAR( 7 ) NOT NULL ,
  50. `display_language_code` VARCHAR( 7 ) NOT NULL ,
  51. `name` VARCHAR( 255 ) CHARACTER SET utf8 NOT NULL,
  52. UNIQUE(`language_code`, `display_language_code`)
  53. ) ENGINE=MyISAM {$charset_collate}";
  54. $wpdb->query($sql);
  55. if($e = mysql_error()) throw new Exception($e);
  56. $add_languages_translations = true;
  57. }
  58. //else{
  59. // this table will not be trucated on upgrade starting with WPML 1.7.3
  60. // $add_languages_translations sticks to false;
  61. //if(!defined('ICL_PRESERVE_LANGUAGES_TRANSLATIONS') || !ICL_PRESERVE_LANGUAGES_TRANSLATIONS){
  62. // mysql_query("TRUNCATE TABLE `{$table_name}`");
  63. // $add_languages_translations = true;
  64. //}
  65. //}
  66. if($add_languages_translations){
  67. foreach($langs_names as $lang=>$val){
  68. if(strpos($lang,'Norwegian Bokm')===0){ $lang = 'Norwegian Bokmål'; $lang_codes[$lang] = 'nb';}
  69. foreach($val['tr'] as $k=>$display){
  70. if(strpos($k,'Norwegian Bokm')===0){ $k = 'Norwegian Bokmål';}
  71. if(!trim($display)){
  72. $display = $lang;
  73. }
  74. if(!($wpdb->get_var("SELECT id FROM {$table_name} WHERE language_code='{$lang_codes[$lang]}' AND display_language_code='{$lang_codes[$k]}'"))){
  75. $wpdb->insert($wpdb->prefix . 'icl_languages_translations', array('language_code'=>$lang_codes[$lang], 'display_language_code'=>$lang_codes[$k], 'name'=>$display));
  76. }
  77. }
  78. }
  79. }
  80. // translations
  81. $table_name = $wpdb->prefix.'icl_translations';
  82. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  83. $sql = "
  84. CREATE TABLE `{$table_name}` (
  85. `translation_id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  86. `element_type` VARCHAR( 36 ) NOT NULL DEFAULT 'post_post',
  87. `element_id` BIGINT NULL DEFAULT NULL ,
  88. `trid` BIGINT NOT NULL ,
  89. `language_code` VARCHAR( 7 ) NOT NULL,
  90. `source_language_code` VARCHAR( 7 ),
  91. UNIQUE KEY `el_type_id` (`element_type`,`element_id`),
  92. UNIQUE KEY `trid_lang` (`trid`,`language_code`)
  93. ) ENGINE=MyISAM {$charset_collate}";
  94. $wpdb->query($sql);
  95. if($e = mysql_error()) throw new Exception($e);
  96. }
  97. // translation_status table
  98. $table_name = $wpdb->prefix.'icl_translation_status';
  99. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  100. $sql = "
  101. CREATE TABLE `{$table_name}` (
  102. `rid` bigint(20) NOT NULL AUTO_INCREMENT,
  103. `translation_id` bigint(20) NOT NULL,
  104. `status` tinyint(4) NOT NULL,
  105. `translator_id` bigint(20) NOT NULL,
  106. `needs_update` tinyint(4) NOT NULL,
  107. `md5` varchar(32) NOT NULL,
  108. `translation_service` varchar(16) NOT NULL,
  109. `translation_package` text NOT NULL,
  110. `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  111. `links_fixed` tinyint(4) NOT NULL DEFAULT 0,
  112. `_prevstate` longtext,
  113. PRIMARY KEY (`rid`),
  114. UNIQUE KEY `translation_id` (`translation_id`)
  115. ) ENGINE=MyISAM {$charset_collate}
  116. ";
  117. $wpdb->query($sql);
  118. if($e = mysql_error()) throw new Exception($e);
  119. }
  120. // translation jobs
  121. $table_name = $wpdb->prefix.'icl_translate_job';
  122. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  123. $sql = "
  124. CREATE TABLE `{$table_name}` (
  125. `job_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  126. `rid` BIGINT UNSIGNED NOT NULL ,
  127. `translator_id` INT UNSIGNED NOT NULL ,
  128. `translated` TINYINT UNSIGNED NOT NULL DEFAULT 0,
  129. `manager_id` INT UNSIGNED NOT NULL ,
  130. `revision` INT UNSIGNED NULL,
  131. INDEX ( `rid` , `translator_id` )
  132. ) ENGINE = MYISAM {$charset_collate}
  133. ";
  134. $wpdb->query($sql);
  135. if($e = mysql_error()) throw new Exception($e);
  136. }
  137. // translate table
  138. $table_name = $wpdb->prefix.'icl_translate';
  139. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  140. $sql = "
  141. CREATE TABLE `{$table_name}` (
  142. `tid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  143. `job_id` BIGINT UNSIGNED NOT NULL ,
  144. `content_id` BIGINT UNSIGNED NOT NULL ,
  145. `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  146. `field_type` VARCHAR( 128 ) NOT NULL ,
  147. `field_format` VARCHAR( 16 ) NOT NULL ,
  148. `field_translate` TINYINT NOT NULL ,
  149. `field_data` TEXT NOT NULL ,
  150. `field_data_translated` TEXT NOT NULL ,
  151. `field_finished` TINYINT NOT NULL DEFAULT 0,
  152. INDEX ( `job_id` )
  153. ) ENGINE = MYISAM {$charset_collate}
  154. ";
  155. $wpdb->query($sql);
  156. if($e = mysql_error()) throw new Exception($e);
  157. }
  158. // languages locale file names
  159. $table_name = $wpdb->prefix.'icl_locale_map';
  160. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  161. $sql = "
  162. CREATE TABLE `{$table_name}` (
  163. `code` VARCHAR( 8 ) NOT NULL ,
  164. `locale` VARCHAR( 8 ) NOT NULL ,
  165. UNIQUE (`code` ,`locale`)
  166. ) ENGINE=MyISAM {$charset_collate}";
  167. $wpdb->query($sql);
  168. if($e = mysql_error()) throw new Exception($e);
  169. }
  170. // flags table
  171. $table_name = $wpdb->prefix.'icl_flags';
  172. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  173. $sql = "
  174. CREATE TABLE `{$table_name}` (
  175. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  176. `lang_code` VARCHAR( 10 ) NOT NULL ,
  177. `flag` VARCHAR( 32 ) NOT NULL ,
  178. `from_template` TINYINT NOT NULL DEFAULT '0',
  179. UNIQUE (`lang_code`)
  180. ) ENGINE=MyISAM {$charset_collate}";
  181. $wpdb->query($sql);
  182. if($e = mysql_error()) throw new Exception($e);
  183. $codes = $wpdb->get_col("SELECT code FROM {$wpdb->prefix}icl_languages");
  184. foreach($codes as $code){
  185. if(!$code || $wpdb->get_var("SELECT lang_code FROM {$wpdb->prefix}icl_flags WHERE lang_code='{$code}'")) continue;
  186. if(!file_exists(ICL_PLUGIN_PATH.'/res/flags/'.$code.'.png')){
  187. $file = 'nil.png';
  188. }else{
  189. $file = $code.'.png';
  190. }
  191. $wpdb->insert($wpdb->prefix.'icl_flags', array('lang_code'=>$code, 'flag'=>$file, 'from_template'=>0));
  192. }
  193. }
  194. /* general string translation */
  195. $table_name = $wpdb->prefix.'icl_strings';
  196. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  197. $sql = "
  198. CREATE TABLE `{$table_name}` (
  199. `id` bigint(20) unsigned NOT NULL auto_increment,
  200. `language` varchar(10) NOT NULL,
  201. `context` varchar(160) NOT NULL,
  202. `name` varchar(160) NOT NULL,
  203. `value` text NOT NULL,
  204. `status` TINYINT NOT NULL,
  205. PRIMARY KEY (`id`),
  206. UNIQUE KEY `context_name` (`context`,`name`)
  207. ) ENGINE=MyISAM {$charset_collate}";
  208. $wpdb->query($sql);
  209. if($e = mysql_error()) throw new Exception($e);
  210. }
  211. $table_name = $wpdb->prefix.'icl_string_translations';
  212. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  213. $sql = "
  214. CREATE TABLE `{$table_name}` (
  215. `id` bigint(20) unsigned NOT NULL auto_increment,
  216. `string_id` bigint(20) unsigned NOT NULL,
  217. `language` varchar(10) NOT NULL,
  218. `status` tinyint(4) NOT NULL,
  219. `value` text NULL DEFAULT NULL,
  220. `translator_id` bigint(20) unsigned DEFAULT NULL,
  221. `translation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  222. PRIMARY KEY (`id`),
  223. UNIQUE KEY `string_language` (`string_id`,`language`)
  224. ) ENGINE=MyISAM {$charset_collate}";
  225. $wpdb->query($sql);
  226. if($e = mysql_error()) throw new Exception($e);
  227. }
  228. $table_name = $wpdb->prefix.'icl_string_status';
  229. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  230. $sql = "
  231. CREATE TABLE `{$table_name}` (
  232. `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  233. `rid` BIGINT NOT NULL ,
  234. `string_translation_id` BIGINT NOT NULL ,
  235. `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  236. `md5` VARCHAR( 32 ) NOT NULL,
  237. INDEX ( `string_translation_id` )
  238. ) ENGINE=MyISAM {$charset_collate}";
  239. $wpdb->query($sql);
  240. if($e = mysql_error()) throw new Exception($e);
  241. }
  242. $table_name = $wpdb->prefix.'icl_string_positions';
  243. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  244. $sql = "
  245. CREATE TABLE `{$table_name}` (
  246. `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  247. `string_id` BIGINT NOT NULL ,
  248. `kind` TINYINT,
  249. `position_in_page` VARCHAR( 255 ) NOT NULL,
  250. INDEX ( `string_id` )
  251. ) ENGINE=MyISAM {$charset_collate}";
  252. $wpdb->query($sql);
  253. if($e = mysql_error()) throw new Exception($e);
  254. }
  255. // message status table
  256. $table_name = $wpdb->prefix.'icl_message_status';
  257. if($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name){
  258. $sql = "
  259. CREATE TABLE `{$table_name}` (
  260. `id` bigint(20) unsigned NOT NULL auto_increment,
  261. `rid` bigint(20) unsigned NOT NULL,
  262. `object_id` bigint(20) unsigned NOT NULL,
  263. `from_language` varchar(10) NOT NULL,
  264. `to_language` varchar(10) NOT NULL,
  265. `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  266. `md5` varchar(32) NOT NULL,
  267. `object_type` varchar(64) NOT NULL,
  268. `status` smallint(6) NOT NULL,
  269. PRIMARY KEY (`id`),
  270. UNIQUE KEY `rid` (`rid`),
  271. KEY `object_id` (`object_id`)
  272. ) ENGINE=MyISAM {$charset_collate}";
  273. $wpdb->query($sql);
  274. if($e = mysql_error()) throw new Exception($e);
  275. }
  276. /* string translation - start */
  277. $icl_translation_sql = "
  278. CREATE TABLE IF NOT EXISTS {$wpdb->prefix}icl_core_status (
  279. `id` BIGINT NOT NULL auto_increment,
  280. `rid` BIGINT NOT NULL,
  281. `module` VARCHAR( 16 ) NOT NULL ,
  282. `origin` VARCHAR( 64 ) NOT NULL ,
  283. `target` VARCHAR( 64 ) NOT NULL ,
  284. `status` SMALLINT NOT NULL,
  285. PRIMARY KEY ( `id` ) ,
  286. INDEX ( `rid` )
  287. ) ENGINE=MyISAM {$charset_collate}
  288. ";
  289. $wpdb->query($icl_translation_sql);
  290. if($e = mysql_error()) throw new Exception($e);
  291. $icl_translation_sql = "
  292. CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_content_status` (
  293. `rid` BIGINT NOT NULL ,
  294. `nid` BIGINT NOT NULL ,
  295. `timestamp` DATETIME NOT NULL ,
  296. `md5` VARCHAR( 32 ) NOT NULL ,
  297. PRIMARY KEY ( `rid` ) ,
  298. INDEX ( `nid` )
  299. ) ENGINE=MyISAM {$charset_collate}
  300. ";
  301. mysql_query($icl_translation_sql);
  302. $wpdb->query($icl_translation_sql);
  303. if($e = mysql_error()) throw new Exception($e);
  304. $icl_translation_sql = "
  305. CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_node` (
  306. `nid` BIGINT NOT NULL ,
  307. `md5` VARCHAR( 32 ) NOT NULL ,
  308. `links_fixed` TINYINT NOT NULL DEFAULT 0,
  309. PRIMARY KEY ( `nid` )
  310. ) ENGINE=MyISAM {$charset_collate}
  311. ";
  312. $wpdb->query($icl_translation_sql);
  313. if($e = mysql_error()) throw new Exception($e);
  314. $icl_translation_sql = "
  315. CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_reminders` (
  316. `id` BIGINT NOT NULL ,
  317. `message` TEXT NOT NULL ,
  318. `url` TEXT NOT NULL ,
  319. `can_delete` TINYINT NOT NULL ,
  320. `show` TINYINT NOT NULL ,
  321. PRIMARY KEY ( `id` )
  322. ) ENGINE=MyISAM {$charset_collate}
  323. ";
  324. $wpdb->query($icl_translation_sql);
  325. if($e = mysql_error()) throw new Exception($e);
  326. } catch(Exception $e) {
  327. trigger_error($e->getMessage(), E_USER_ERROR);
  328. exit;
  329. }
  330. if(get_option('icl_sitepress_version')){
  331. icl_plugin_upgrade();
  332. }
  333. // don't set the new version if a multi-step upgrade is in progress
  334. if(!defined('ICL_MULTI_STEP_UPGRADE')){
  335. delete_option('icl_sitepress_version');
  336. add_option('icl_sitepress_version', ICL_SITEPRESS_VERSION, '', true);
  337. }
  338. $iclsettings = get_option('icl_sitepress_settings');
  339. if($iclsettings === false ){
  340. $short_v = implode('.', array_slice(explode('.', ICL_SITEPRESS_VERSION), 0, 3));
  341. $settings = array(
  342. 'hide_upgrade_notice' => $short_v
  343. );
  344. add_option('icl_sitepress_settings', $settings, '', true);
  345. }else{
  346. // reset ajx_health_flag
  347. $iclsettings['ajx_health_checked'] = 0;
  348. update_option('icl_sitepress_settings',$iclsettings);
  349. }
  350. }
  351. function icl_sitepress_deactivate(){
  352. }
  353. // Changed to use lowercased wpdb prefix. Some users have table name in uppercase.
  354. // http://bugs.mysql.com/bug.php?id=39894
  355. if(isset($_GET['activate'])){
  356. if(!isset($wpdb)) global $wpdb;
  357. $table_name = $wpdb->prefix.'icl_languages';
  358. if(strtolower($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'")) != strtolower($table_name)){
  359. add_action('admin_notices', 'icl_cant_create_table');
  360. function icl_cant_create_table(){
  361. echo '<div class="error"><ul><li><strong>';
  362. echo __('WPML cannot create the database tables! Make sure that your mysql user has the CREATE privilege', 'sitepress');
  363. echo '</strong></li></ul></div>';
  364. $active_plugins = get_option('active_plugins');
  365. $icl_sitepress_idx = array_search(ICL_PLUGIN_FOLDER . '/sitepress.php', $active_plugins);
  366. if(false !== $icl_sitepress_idx){
  367. unset($active_plugins[$icl_sitepress_idx]);
  368. update_option('active_plugins', $active_plugins);
  369. unset($_GET['activate']);
  370. $recently_activated = get_option('recently_activated');
  371. if(!isset($recently_activated[ICL_PLUGIN_FOLDER.'/sitepress.php'])){
  372. $recently_activated[ICL_PLUGIN_FOLDER.'/sitepress.php'] = time();
  373. update_option('recently_activated', $recently_activated);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. /*
  380. function icl_cant_be_activated(){
  381. echo '<div class="error"><ul><li><strong>';
  382. echo sprintf(__('WPML cannot be acctivated because: %s', 'sitepress'), $GLOBALS['_icl_activation_error']);
  383. echo '</strong></li></ul></div>';
  384. $active_plugins = get_option('active_plugins');
  385. $icl_sitepress_idx = array_search(ICL_PLUGIN_FOLDER . '/sitepress.php', $active_plugins);
  386. if(false !== $icl_sitepress_idx){
  387. unset($active_plugins[$icl_sitepress_idx]);
  388. update_option('active_plugins', $active_plugins);
  389. unset($_GET['activate']);
  390. $recently_activated = get_option('recently_activated');
  391. if(!isset($recently_activated[ICL_PLUGIN_FOLDER.'/sitepress.php'])){
  392. $recently_activated[ICL_PLUGIN_FOLDER.'/sitepress.php'] = time();
  393. update_option('recently_activated', $recently_activated);
  394. }
  395. }
  396. }
  397. */
  398. ?>