コード例 #1
0
 function reset_language_data()
 {
     global $wpdb, $sitepress;
     $active = $wpdb->get_col("SELECT code FROM {$wpdb->prefix}icl_languages WHERE active = 1");
     $wpdb->query("TRUNCATE TABLE `{$wpdb->prefix}icl_languages`");
     SitePress_Setup::fill_languages();
     $wpdb->query("TRUNCATE TABLE `{$wpdb->prefix}icl_languages_translations`");
     SitePress_Setup::fill_languages_translations();
     $wpdb->query("TRUNCATE TABLE `{$wpdb->prefix}icl_flags`");
     SitePress_Setup::fill_flags();
     //restore active
     $wpdb->query("UPDATE {$wpdb->prefix}icl_languages SET active=1 WHERE code IN(" . wpml_prepare_in($active) . ")");
     $wpdb->update($wpdb->prefix . 'icl_flags', array('from_template' => 0), null);
     $codes = $wpdb->get_col("SELECT code FROM {$wpdb->prefix}icl_languages");
     foreach ($codes as $code) {
         if (!$code || $wpdb->get_var($wpdb->prepare("SELECT lang_code FROM {$wpdb->prefix}icl_flags WHERE lang_code = %s", $code))) {
             continue;
         }
         if (!file_exists(ICL_PLUGIN_PATH . '/res/flags/' . $code . '.png')) {
             $file = 'nil.png';
         } else {
             $file = $code . '.png';
         }
         $wpdb->insert($wpdb->prefix . 'icl_flags', array('lang_code' => $code, 'flag' => $file, 'from_template' => 0));
     }
     $last_default_language = $sitepress !== null ? $sitepress->get_default_language() : 'en';
     if (!in_array($last_default_language, $codes)) {
         $last_active_languages = $sitepress->get_active_languages();
         foreach ($last_active_languages as $code => $last_active_language) {
             if (in_array($code, $codes)) {
                 $sitepress->set_default_language($code);
                 break;
             }
         }
     }
     icl_cache_clear();
 }
コード例 #2
0
ファイル: troubleshooting.php プロジェクト: edgarter/wecare
 *
 * @return callable
 */
function get_term_taxonomy_id_from_term_object($term_object)
{
    return $term_object->term_taxonomy_id;
}
$action = filter_input(INPUT_GET, 'debug_action', FILTER_SANITIZE_STRING);
$nonce = filter_input(INPUT_GET, 'nonce', FILTER_SANITIZE_STRING);
if (isset($action) && wp_verify_nonce($nonce, $action)) {
    ob_end_clean();
    global $wpdb;
    switch ($action) {
        case 'fix_languages':
            SitePress_Setup::fill_languages();
            SitePress_Setup::fill_languages_translations();
            icl_cache_clear();
            exit;
        case 'icl_fix_collation':
            repair_el_type_collate();
            exit;
        case 'reset_pro_translation_configuration':
            $sitepress_settings = get_option('icl_sitepress_settings');
            $sitepress_settings['content_translation_languages_setup'] = false;
            $sitepress_settings['content_translation_setup_complete'] = false;
            unset($sitepress_settings['content_translation_setup_wizard_step']);
            unset($sitepress_settings['site_id']);
            unset($sitepress_settings['access_key']);
            unset($sitepress_settings['translator_choice']);
            unset($sitepress_settings['icl_lang_status']);
            unset($sitepress_settings['icl_balance']);
コード例 #3
0
ファイル: sitepress-schema.php プロジェクト: edgarter/wecare
function icl_sitepress_activate()
{
    global $wpdb;
    $charset_collate = '';
    if (method_exists($wpdb, 'has_cap') && $wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    try {
        SitePress_Setup::fill_languages();
        SitePress_Setup::fill_languages_translations();
        SitePress_Setup::fill_flags();
        // translations
        $table_name = $wpdb->prefix . 'icl_translations';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n             CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                `translation_id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\n                `element_type` VARCHAR( 36 ) NOT NULL DEFAULT 'post_post',\r\n                `element_id` BIGINT NULL DEFAULT NULL ,\r\n                `trid` BIGINT NOT NULL ,\r\n                `language_code` VARCHAR( 7 ) NOT NULL,\r\n                `source_language_code` VARCHAR( 7 ),\r\n                UNIQUE KEY `el_type_id` (`element_type`,`element_id`),\r\n                UNIQUE KEY `trid_lang` (`trid`,`language_code`),\r\n                KEY `trid` (`trid`),\r\n                KEY `id_type_language` (`element_id`, `element_type`, `language_code`)\r\n            ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // translation_status table
        $table_name = $wpdb->prefix . 'icl_translation_status';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                 `rid` bigint(20) NOT NULL AUTO_INCREMENT,\r\n                 `translation_id` bigint(20) NOT NULL,\r\n                 `status` tinyint(4) NOT NULL,\r\n                 `translator_id` bigint(20) NOT NULL,\r\n                 `needs_update` tinyint(4) NOT NULL,\r\n                 `md5` varchar(32) NOT NULL,\r\n                 `translation_service` varchar(16) NOT NULL,\r\n                 `batch_id` int DEFAULT 0 NOT NULL,\r\n                 `translation_package` text NOT NULL,\r\n                 `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n                 `links_fixed` tinyint(4) NOT NULL DEFAULT 0,\r\n                 `_prevstate` longtext,\r\n                 PRIMARY KEY (`rid`),\r\n                 UNIQUE KEY `translation_id` (`translation_id`)\r\n                ) {$charset_collate}    \r\n            ";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // translation jobs
        $table_name = $wpdb->prefix . 'icl_translate_job';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                `job_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\n                `rid` BIGINT UNSIGNED NOT NULL ,\r\n                `translator_id` INT UNSIGNED NOT NULL ,\r\n                `translated` TINYINT UNSIGNED NOT NULL DEFAULT 0,\r\n                `manager_id` INT UNSIGNED NOT NULL ,\r\n                `revision` INT UNSIGNED NULL,\r\n                INDEX ( `rid` , `translator_id` )\r\n                ) {$charset_collate}    \r\n            ";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // translate table
        $table_name = $wpdb->prefix . 'icl_translate';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                `tid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\n                `job_id` BIGINT UNSIGNED NOT NULL ,\r\n                `content_id` BIGINT UNSIGNED NOT NULL ,\r\n                `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,\r\n                `field_type` VARCHAR( 160 ) NOT NULL ,\r\n                `field_format` VARCHAR( 16 ) NOT NULL ,\r\n                `field_translate` TINYINT NOT NULL ,\r\n                `field_data` longtext NOT NULL ,\r\n                `field_data_translated` longtext NOT NULL ,\r\n                `field_finished` TINYINT NOT NULL DEFAULT 0,\r\n                INDEX ( `job_id` )\r\n                ) {$charset_collate}\r\n            ";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // batches table
        $table_name = $wpdb->prefix . 'icl_translation_batches';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS {$wpdb->prefix}icl_translation_batches (\r\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n                  `batch_name` text NOT NULL,\r\n                  `tp_id` int NULL,\r\n                  `ts_url` text NULL,\r\n                  `last_update` DATETIME NULL,\r\n                  PRIMARY KEY (`id`)\r\n                ) {$charset_collate}\r\n            ";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // languages locale file names
        $table_name = $wpdb->prefix . 'icl_locale_map';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                    `code` VARCHAR( 7 ) NOT NULL ,\r\n                    `locale` VARCHAR( 8 ) NOT NULL ,\r\n                    UNIQUE (`code` ,`locale`)\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        /* general string translation */
        $table_name = $wpdb->prefix . 'icl_strings';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                  `id` bigint(20) unsigned NOT NULL auto_increment,\r\n                  `language` varchar(7) NOT NULL,\r\n                  `context` varchar(" . WPML_STRING_TABLE_NAME_CONTEXT_LENGTH . ") CHARACTER SET UTF8 NOT NULL,\r\n                  `name` varchar(" . WPML_STRING_TABLE_NAME_CONTEXT_LENGTH . ") CHARACTER SET UTF8 NOT NULL,\r\n                  `value` text NOT NULL,\r\n                  `string_package_id` BIGINT unsigned NULL,\r\n                  `type` VARCHAR(40) NOT NULL DEFAULT 'LINE',\r\n                  `title` VARCHAR(160) NULL,\r\n                  `status` TINYINT NOT NULL,\r\n                  PRIMARY KEY  (`id`),\r\n                  UNIQUE KEY `context_name` (`context`,`name`),\r\n                  KEY `language_context` (`language`, `context`)\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        $table_name = $wpdb->prefix . 'icl_string_translations';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                 CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                  `id` bigint(20) unsigned NOT NULL auto_increment,\r\n                  `string_id` bigint(20) unsigned NOT NULL,\r\n                  `language` varchar(10) NOT NULL,\r\n                  `status` tinyint(4) NOT NULL,\r\n                  `value` text NULL DEFAULT NULL,              \r\n                  `translator_id` bigint(20) unsigned DEFAULT NULL, \r\n                  `translation_service` varchar(16) DEFAULT '' NOT NULL,\r\n                  `batch_id` int DEFAULT 0 NOT NULL,\r\n                  `translation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\r\n                  PRIMARY KEY  (`id`),\r\n                  UNIQUE KEY `string_language` (`string_id`,`language`)\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        $table_name = $wpdb->prefix . 'icl_string_status';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                  CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\n                `rid` BIGINT NOT NULL ,\r\n                `string_translation_id` BIGINT NOT NULL ,\r\n                `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,\r\n                `md5` VARCHAR( 32 ) NOT NULL,\r\n                INDEX ( `string_translation_id` )\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        $table_name = $wpdb->prefix . 'icl_string_positions';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                  CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\r\n                `string_id` BIGINT NOT NULL ,\r\n                `kind` TINYINT,\r\n                `position_in_page` VARCHAR( 255 ) NOT NULL,\r\n                INDEX ( `string_id` )\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        // message status table
        $table_name = $wpdb->prefix . 'icl_message_status';
        if (0 !== strcasecmp($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'"), $table_name)) {
            $sql = "\r\n                  CREATE TABLE IF NOT EXISTS `{$table_name}` (\r\n                      `id` bigint(20) unsigned NOT NULL auto_increment,\r\n                      `rid` bigint(20) unsigned NOT NULL,\r\n                      `object_id` bigint(20) unsigned NOT NULL,\r\n                      `from_language` varchar(10) NOT NULL,\r\n                      `to_language` varchar(10) NOT NULL,\r\n                      `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,\r\n                      `md5` varchar(32) NOT NULL,\r\n                      `object_type` varchar(64) NOT NULL,\r\n                      `status` smallint(6) NOT NULL,\r\n                      PRIMARY KEY  (`id`),\r\n                      UNIQUE KEY `rid` (`rid`),\r\n                      KEY `object_id` (`object_id`)\r\n                ) {$charset_collate}";
            if ($wpdb->query($sql) === false) {
                throw new Exception($wpdb->last_error);
            }
        }
        /* string translation - start */
        $icl_translation_sql = "\r\n             CREATE TABLE IF NOT EXISTS {$wpdb->prefix}icl_core_status (\r\n            `id` BIGINT NOT NULL auto_increment,\r\n            `rid` BIGINT NOT NULL,\r\n            `module` VARCHAR( 16 ) NOT NULL ,\r\n            `origin` VARCHAR( 64 ) NOT NULL ,\r\n            `target` VARCHAR( 64 ) NOT NULL ,\r\n            `status` SMALLINT NOT NULL,\r\n            PRIMARY KEY ( `id` ) ,\r\n            INDEX ( `rid` )\r\n            ) {$charset_collate}\r\n      ";
        if ($wpdb->query($icl_translation_sql) === false) {
            throw new Exception($wpdb->last_error);
        }
        $icl_translation_sql = "\r\n            CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_content_status` (\r\n            `rid` BIGINT NOT NULL ,\r\n            `nid` BIGINT NOT NULL ,\r\n            `timestamp` DATETIME NOT NULL ,\r\n            `md5` VARCHAR( 32 ) NOT NULL ,\r\n            PRIMARY KEY ( `rid` ) ,\r\n            INDEX ( `nid` )\r\n            ) {$charset_collate} \r\n      ";
        if ($wpdb->query($icl_translation_sql) === false) {
            throw new Exception($wpdb->last_error);
        }
        $icl_translation_sql = "\r\n            CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_node` (\r\n            `nid` BIGINT NOT NULL ,\r\n            `md5` VARCHAR( 32 ) NOT NULL ,\r\n            `links_fixed` TINYINT NOT NULL DEFAULT 0,\r\n            PRIMARY KEY ( `nid` )\r\n            ) {$charset_collate}  \r\n      ";
        if ($wpdb->query($icl_translation_sql) === false) {
            throw new Exception($wpdb->last_error);
        }
        $icl_translation_sql = "\r\n            CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}icl_reminders` (\r\n            `id` BIGINT NOT NULL ,\r\n            `message` TEXT NOT NULL ,\r\n            `url`  TEXT NOT NULL ,\r\n            `can_delete` TINYINT NOT NULL ,\r\n            `show` TINYINT NOT NULL ,\r\n            PRIMARY KEY ( `id` )\r\n            ) {$charset_collate}  \r\n      ";
        if ($wpdb->query($icl_translation_sql) === false) {
            throw new Exception($wpdb->last_error);
        }
    } catch (Exception $e) {
        trigger_error($e->getMessage(), E_USER_ERROR);
        exit;
    }
    // don't set the new version if a multi-step upgrade is in progress
    if (!defined('ICL_MULTI_STEP_UPGRADE')) {
        delete_option('icl_sitepress_version');
        add_option('icl_sitepress_version', ICL_SITEPRESS_VERSION, '', true);
    }
    $iclsettings = get_option('icl_sitepress_settings');
    if ($iclsettings === false) {
        $short_v = implode('.', array_slice(explode('.', ICL_SITEPRESS_VERSION), 0, 3));
        $settings = array('hide_upgrade_notice' => $short_v);
        add_option('icl_sitepress_settings', $settings, '', true);
    } else {
        // reset ajx_health_flag
        $iclsettings['ajx_health_checked'] = 0;
        $iclsettings['just_reactivated'] = 1;
        update_option('icl_sitepress_settings', $iclsettings);
    }
    //Set new caps for all administrator role
    icl_enable_capabilities();
    //Set cron job to update WPML config index file from CDN
    wp_schedule_event(time(), 'daily', 'update_wpml_config_index');
    do_action('wpml_activated');
}