コード例 #1
0
ファイル: functions.php プロジェクト: edgarter/wecare
function icl_st_init()
{
    global $sitepress_settings, $sitepress, $wpdb, $icl_st_err_str;
    if ($GLOBALS['pagenow'] === 'site-new.php' && isset($_REQUEST['action']) && 'add-site' === $_REQUEST['action']) {
        return;
    }
    add_action('icl_update_active_languages', 'icl_update_string_status_all');
    add_action('update_option_blogname', 'icl_st_update_blogname_actions', 5, 2);
    add_action('update_option_blogdescription', 'icl_st_update_blogdescription_actions', 5, 2);
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_page') {
        icl_st_string_in_page($_GET['string_id']);
        exit;
    }
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_source') {
        icl_st_string_in_source($_GET['string_id']);
        exit;
    }
    if (get_magic_quotes_gpc() && isset($_GET['page']) && $_GET['page'] === WPML_ST_FOLDER . '/menu/string-translation.php') {
        $_POST = stripslashes_deep($_POST);
    }
    if (!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']) {
        return;
    }
    if (!isset($sitepress_settings['st']['sw'])) {
        $sitepress_settings['st']['sw'] = array();
        //no settings for now
        $sitepress->save_settings($sitepress_settings);
        $init_all = true;
    }
    if (!isset($sitepress_settings['st']['strings_per_page'])) {
        $sitepress_settings['st']['strings_per_page'] = 10;
        $sitepress->save_settings($sitepress_settings);
    } elseif (isset($_GET['strings_per_page']) && $_GET['strings_per_page'] > 0) {
        $sitepress_settings['st']['strings_per_page'] = $_GET['strings_per_page'];
        $sitepress->save_settings($sitepress_settings);
    }
    if (!isset($sitepress_settings['st']['icl_st_auto_reg'])) {
        $sitepress_settings['st']['icl_st_auto_reg'] = 'disable';
        $sitepress->save_settings($sitepress_settings);
    }
    if (empty($sitepress_settings['st']['strings_language'])) {
        $iclsettings['st']['strings_language'] = $sitepress_settings['st']['strings_language'] = 'en';
        $sitepress->save_settings($iclsettings);
    }
    if (!isset($sitepress_settings['st']['translated-users'])) {
        $sitepress_settings['st']['translated-users'] = array();
    }
    if (isset($_POST['iclt_st_sw_save']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_sw_form') || isset($init_all)) {
        if (isset($init_all)) {
            icl_register_string('WP', __('Blog Title', 'wpml-string-translation'), get_option('blogname'));
            icl_register_string('WP', __('Tagline', 'wpml-string-translation'), get_option('blogdescription'));
            __icl_st_init_register_widget_titles();
            // create a list of active widgets
            $active_text_widgets = array();
            $widgets = (array) get_option('sidebars_widgets');
            foreach ($widgets as $k => $w) {
                if ('wp_inactive_widgets' != $k && $k != 'array_version') {
                    if (is_array($widgets[$k])) {
                        foreach ($widgets[$k] as $v) {
                            if (preg_match('#text-([0-9]+)#i', $v, $matches)) {
                                $active_text_widgets[] = $matches[1];
                            }
                        }
                    }
                }
            }
            $widget_text = get_option('widget_text');
            if (is_array($widget_text)) {
                foreach ($widget_text as $k => $w) {
                    if (!empty($w) && isset($w['title']) && in_array($k, $active_text_widgets)) {
                        icl_register_string('Widgets', 'widget body - ' . md5($w['text']), $w['text']);
                    }
                }
            }
        }
        if (isset($_POST['iclt_st_sw_save'])) {
            $updat_string_statuses = false;
            $sitepress_settings['st']['sw'] = $_POST['icl_st_sw'];
            if ($sitepress_settings['st']['strings_language'] != $_POST['icl_st_sw']['strings_language']) {
                $updat_string_statuses = true;
            }
            $sitepress_settings['st']['strings_language'] = $_POST['icl_st_sw']['strings_language'];
            $sitepress->save_settings($sitepress_settings);
            $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_strings SET language=%s WHERE language <> %s", $sitepress_settings['st']['strings_language'], $sitepress_settings['st']['strings_language']));
            if ($updat_string_statuses) {
                icl_update_string_status_all();
            }
            //register author strings
            if (!empty($sitepress_settings['st']['translated-users'])) {
                icl_st_register_user_strings_all();
            }
            wp_redirect(admin_url('admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&updated=true'));
        }
    }
    // handle po file upload
    if (isset($_POST['icl_po_upload']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_form')) {
        global $icl_st_po_strings;
        if ($_FILES['icl_po_file']['size'] == 0) {
            $icl_st_err_str = __('File upload error', 'wpml-string-translation');
        } else {
            $lines = file($_FILES['icl_po_file']['tmp_name']);
            $icl_st_po_strings = array();
            $fuzzy = 0;
            for ($k = 0; $k < count($lines); $k++) {
                $date_time_flag = false;
                if (0 === strpos($lines[$k], '#, fuzzy')) {
                    $fuzzy = 1;
                    $k++;
                }
                $name = false;
                if (0 === strpos($lines[$k], '# wpml-name: ')) {
                    $name = preg_replace("/^# wpml-name: /i", '', trim($lines[$k]));
                    $k++;
                }
                if (preg_match('/msgctxt/', $lines[$k])) {
                    //we look for the line that poedit needs for unique identification of the string
                    if (preg_match('/wpmldatei18/', $lines[$k])) {
                        //if it contains the date_time setting we add the flag to escape the control structures in the date time placeholder string
                        $date_time_flag = true;
                    }
                    $k++;
                }
                $int = preg_match('#msgid "(.+)"#im', trim($lines[$k]), $matches);
                if ($int) {
                    $string = str_replace('\\"', '"', $matches[1]);
                    $int = preg_match('#msgstr "(.+)"#im', trim($lines[$k + 1]), $matches);
                    if ($int) {
                        $translation = str_replace('\\"', '"', $matches[1]);
                    } else {
                        $translation = "";
                    }
                    if ($name === false) {
                        $name = md5($string);
                    }
                    $string_exists = $wpdb->get_var("\r\n                        SELECT id FROM {$wpdb->prefix}icl_strings \r\n                        WHERE context='" . esc_sql($_POST['icl_st_i_context_new'] ? $_POST['icl_st_i_context_new'] : $_POST['icl_st_i_context']) . "'\r\n                        AND name='" . $name . "'");
                    if ($date_time_flag) {
                        $string = str_replace("\\\\", "\\", $string);
                        $translation = str_replace("\\\\", "\\", $translation);
                        $name = str_replace("\\\\", "\\", $name);
                    }
                    $icl_st_po_strings[] = array('string' => $string, 'translation' => $translation, 'name' => $name, 'fuzzy' => $fuzzy, 'exists' => $string_exists);
                    $k++;
                }
                if (!trim($lines[$k])) {
                    $fuzzy = 0;
                }
            }
            if (empty($icl_st_po_strings)) {
                $icl_st_err_str = __('No string found', 'wpml-string-translation');
            }
        }
    } elseif (isset($_POST['action']) && 'icl_st_save_strings' == $_POST['action']) {
        $arr = array_intersect_key($_POST['icl_strings'], array_flip($_POST['icl_strings_selected']));
        //$arr = array_map('html_entity_decode', $arr);
        if (isset($_POST['icl_st_po_language'])) {
            $arr_t = array_intersect_key($_POST['icl_translations'], array_flip($_POST['icl_strings_selected']));
            $arr_f = array_intersect_key($_POST['icl_fuzzy'], array_flip($_POST['icl_strings_selected']));
            //$arr_t = array_map('html_entity_decode', $arr_t);
        }
        foreach ($arr as $k => $string) {
            $name = isset($_POST['icl_name'][$k]) && $_POST['icl_name'][$k] ? $_POST['icl_name'][$k] : md5($string);
            $string_id = icl_register_string($_POST['icl_st_domain_name'], $name, $string);
            if ($string_id && isset($_POST['icl_st_po_language'])) {
                if ($arr_t[$k] != "") {
                    if ($arr_f[$k]) {
                        $_status = ICL_TM_NOT_TRANSLATED;
                    } else {
                        $_status = ICL_TM_COMPLETE;
                    }
                    icl_add_string_translation($string_id, $_POST['icl_st_po_language'], $arr_t[$k], $_status);
                    icl_update_string_status($string_id);
                }
            }
        }
    }
    //handle po export
    if (isset($_POST['icl_st_pie_e']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_export')) {
        //force some filters
        if (isset($_GET['status'])) {
            unset($_GET['status']);
        }
        $_GET['show_results'] = 'all';
        if ($_POST['icl_st_e_context']) {
            $_GET['context'] = $_POST['icl_st_e_context'];
        }
        $_GET['translation_language'] = $_POST['icl_st_e_language'];
        $strings = icl_get_string_translations();
        if (!empty($strings)) {
            $po = icl_st_generate_po_file($strings, !isset($_POST['icl_st_pe_translations']));
        } else {
            $po = "";
        }
        if (!isset($_POST['icl_st_pe_translations'])) {
            $popot = 'pot';
            $poname = $_POST['icl_st_e_context'] ? urlencode($_POST['icl_st_e_context']) : 'all_context';
        } else {
            $popot = 'po';
            $poname = $_GET['context'] . '-' . $_GET['translation_language'];
        }
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=" . $poname . '.' . $popot . ";");
        header("Content-Length: " . strlen($po));
        echo $po;
        exit(0);
    } elseif (isset($_POST['icl_st_action']) && $_POST['icl_st_action'] == 'send_strings') {
        add_action('init', 'icl_send_strings_action');
    }
    // hook into blog title and tag line
    add_filter('option_blogname', 'icl_sw_filters_blogname');
    add_filter('option_blogdescription', 'icl_sw_filters_blogdescription');
    add_filter('widget_title', 'icl_sw_filters_widget_title', 0);
    //highest priority
    add_filter('widget_text', 'icl_sw_filters_widget_text', 0);
    //highest priority
    $setup_complete = apply_filters('WPML_get_setting', false, 'setup_complete');
    $theme_localization_type = apply_filters('WPML_get_setting', false, 'theme_localization_type');
    if ($setup_complete && $theme_localization_type == 1) {
        add_filter('gettext', 'icl_sw_filters_gettext', 9, 3);
        add_filter('gettext_with_context', 'icl_sw_filters_gettext_with_context', 1, 4);
        add_filter('ngettext', 'icl_sw_filters_ngettext', 9, 5);
        add_filter('ngettext_with_context', 'icl_sw_filters_nxgettext', 9, 6);
    }
    $widget_groups = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%'");
    foreach ($widget_groups as $w) {
        add_action('update_option_' . $w->option_name, 'icl_st_update_widget_title_actions', 5, 2);
    }
    add_action('update_option_widget_text', 'icl_st_update_text_widgets_actions', 5, 2);
    add_action('update_option_sidebars_widgets', '__icl_st_init_register_widget_titles');
    if ($icl_st_err_str) {
        add_action('admin_notices', 'icl_st_admin_notices');
    }
    if (isset($_REQUEST['string-translated']) && $_REQUEST['string-translated'] == true) {
        add_action('admin_notices', 'icl_st_admin_notices_string_updated');
    }
    add_filter('get_the_author_first_name', 'icl_st_author_first_name_filter', 10, 2);
    add_filter('get_the_author_last_name', 'icl_st_author_last_name_filter', 10, 2);
    add_filter('get_the_author_nickname', 'icl_st_author_nickname_filter', 10, 2);
    add_filter('get_the_author_description', 'icl_st_author_description_filter', 10, 2);
    add_filter('the_author', 'icl_st_author_displayname_filter', 10);
}
コード例 #2
0
function icl_st_init()
{
    global $sitepress_settings, $sitepress, $wpdb, $icl_st_err_str;
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_page') {
        icl_st_string_in_page($_GET['string_id']);
        exit;
    }
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_source') {
        icl_st_string_in_source($_GET['string_id']);
        exit;
    }
    if (get_magic_quotes_gpc() && isset($_GET['page']) && $_GET['page'] == WPML_ST_FOLDER . '/menu/string-translation.php') {
        $_POST = stripslashes_deep($_POST);
    }
    if (!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']) {
        return;
    }
    if (!isset($sitepress_settings['st']['sw'])) {
        $sitepress_settings['st']['sw'] = array();
        //no settings for now
        $sitepress->save_settings($sitepress_settings);
        $init_all = true;
    }
    if (!isset($sitepress_settings['st']['strings_per_page'])) {
        $sitepress_settings['st']['strings_per_page'] = 10;
        $sitepress->save_settings($sitepress_settings);
    } elseif (isset($_GET['strings_per_page']) && $_GET['strings_per_page'] > 0) {
        $sitepress_settings['st']['strings_per_page'] = $_GET['strings_per_page'];
        $sitepress->save_settings($sitepress_settings);
    }
    if (!isset($sitepress_settings['st']['translated-users'])) {
        $sitepress_settings['st']['translated-users'] = array();
    }
    if (isset($_POST['iclt_st_sw_save']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_sw_form') || isset($init_all)) {
        if (isset($init_all)) {
            icl_register_string('WP', __('Blog Title', 'wpml-string-translation'), get_option('blogname'));
            icl_register_string('WP', __('Tagline', 'wpml-string-translation'), get_option('blogdescription'));
            __icl_st_init_register_widget_titles();
            // create a list of active widgets
            $active_text_widgets = array();
            $widgets = (array) get_option('sidebars_widgets');
            foreach ($widgets as $k => $w) {
                if ('wp_inactive_widgets' != $k && $k != 'array_version') {
                    foreach ($widgets[$k] as $v) {
                        if (preg_match('#text-([0-9]+)#i', $v, $matches)) {
                            $active_text_widgets[] = $matches[1];
                        }
                    }
                }
            }
            $widget_text = get_option('widget_text');
            if (is_array($widget_text)) {
                foreach ($widget_text as $k => $w) {
                    if (!empty($w) && isset($w['title']) && in_array($k, $active_text_widgets)) {
                        icl_register_string('Widgets', 'widget body - ' . md5(apply_filters('widget_text', $w['text'])), apply_filters('widget_text', $w['text']));
                    }
                }
            }
        }
        if (isset($_POST['iclt_st_sw_save'])) {
            $updat_string_statuses = false;
            $sitepress_settings['st']['sw'] = $_POST['icl_st_sw'];
            if ($sitepress_settings['st']['strings_language'] != $_POST['icl_st_sw']['strings_language']) {
                $updat_string_statuses = true;
            }
            $sitepress_settings['st']['strings_language'] = $_POST['icl_st_sw']['strings_language'];
            $sitepress->save_settings($sitepress_settings);
            if ($updat_string_statuses) {
                icl_update_string_status_all();
            }
            //register author strings
            if (!empty($sitepress_settings['st']['translated-users'])) {
                icl_st_register_user_strings_all();
            }
            wp_redirect($_SERVER['REQUEST_URI'] . '&updated=true');
        }
    }
    // handle po file upload
    if (isset($_POST['icl_po_upload']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_form')) {
        global $icl_st_po_strings;
        if ($_FILES['icl_po_file']['size'] == 0) {
            $icl_st_err_str = __('File upload error', 'wpml-string-translation');
        } else {
            $lines = file($_FILES['icl_po_file']['tmp_name']);
            $icl_st_po_strings = array();
            $fuzzy = 0;
            for ($k = 0; $k < count($lines); $k++) {
                if (0 === strpos($lines[$k], '#, fuzzy')) {
                    $fuzzy = 1;
                    $k++;
                }
                $int = preg_match('#msgid "(.+)"#im', trim($lines[$k]), $matches);
                if ($int) {
                    $string = str_replace('\\"', '"', $matches[1]);
                    $int = preg_match('#msgstr "(.+)"#im', trim($lines[$k + 1]), $matches);
                    if ($int) {
                        $translation = str_replace('\\"', '"', $matches[1]);
                    } else {
                        $translation = "";
                    }
                    $string_exists = $wpdb->get_var("\n                        SELECT id FROM {$wpdb->prefix}icl_strings \n                        WHERE context='" . $wpdb->escape($_POST['icl_st_i_context_new'] ? $_POST['icl_st_i_context_new'] : $_POST['icl_st_i_context']) . "' \n                        AND name='" . md5($string) . "'");
                    $icl_st_po_strings[] = array('string' => $string, 'translation' => $translation, 'fuzzy' => $fuzzy, 'exists' => $string_exists);
                    $k++;
                }
                if (!trim($lines[$k])) {
                    $fuzzy = 0;
                }
            }
            if (empty($icl_st_po_strings)) {
                $icl_st_err_str = __('No string found', 'wpml-string-translation');
            }
        }
    } elseif (isset($_POST['icl_st_save_strings'])) {
        $arr = array_intersect_key($_POST['icl_strings'], array_flip($_POST['icl_strings_selected']));
        //$arr = array_map('html_entity_decode', $arr);
        if (isset($_POST['icl_st_po_language'])) {
            $arr_t = array_intersect_key($_POST['icl_translations'], array_flip($_POST['icl_strings_selected']));
            $arr_f = array_intersect_key($_POST['icl_fuzzy'], array_flip($_POST['icl_strings_selected']));
            //$arr_t = array_map('html_entity_decode', $arr_t);
        }
        // see if the strings are already registered and have names
        // case of adding translation
        $res = $wpdb->get_results("                                                                                              \n            SELECT value, name \n            FROM {$wpdb->prefix}icl_strings \n            WHERE context = '" . $wpdb->escape($_POST['icl_st_domain_name']) . "' AND value IN ('" . join("','", array_map('mysql_real_escape_string', $arr)) . "')  \n        ");
        if (!empty($res)) {
            foreach ($res as $r) {
                $map[$r->value] = $r->name;
            }
        }
        foreach ($arr as $k => $string) {
            if (isset($map[$string])) {
                $name = $map[$string];
            } else {
                $name = md5($string);
            }
            $string_id = icl_register_string($_POST['icl_st_domain_name'], $name, $string);
            if ($string_id && isset($_POST['icl_st_po_language'])) {
                if ($arr_t[$k] != "") {
                    if ($arr_f[$k]) {
                        $_status = ICL_STRING_TRANSLATION_NOT_TRANSLATED;
                    } else {
                        $_status = ICL_STRING_TRANSLATION_COMPLETE;
                    }
                    icl_add_string_translation($string_id, $_POST['icl_st_po_language'], $arr_t[$k], $_status);
                    icl_update_string_status($string_id);
                }
            }
        }
    }
    //handle po export
    if (isset($_POST['icl_st_pie_e']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_export')) {
        //force some filters
        if (isset($_GET['status'])) {
            unset($_GET['status']);
        }
        $_GET['show_results'] = 'all';
        if ($_POST['icl_st_e_context']) {
            $_GET['context'] = $_POST['icl_st_e_context'];
        }
        $_GET['translation_language'] = $_POST['icl_st_e_language'];
        $strings = icl_get_string_translations();
        if (!empty($strings)) {
            $po = icl_st_generate_po_file($strings, !isset($_POST['icl_st_pe_translations']));
        } else {
            $po = "";
        }
        if (!isset($_POST['icl_st_pe_translations'])) {
            $popot = 'pot';
            $poname = $_POST['icl_st_e_context'] ? urlencode($_POST['icl_st_e_context']) : 'all_context';
        } else {
            $popot = 'po';
            $poname = $_GET['translation_language'];
        }
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=" . $poname . '.' . $popot . ";");
        header("Content-Length: " . strlen($po));
        echo $po;
        exit(0);
    } elseif (isset($_POST['icl_st_action']) && $_POST['icl_st_action'] == 'send_strings') {
        if ($_POST['iclnonce'] == wp_create_nonce('icl-string-translation')) {
            $_POST = stripslashes_deep($_POST);
            $services = $_POST['service'];
            $string_ids = explode(',', $_POST['strings']);
            $translate_to = array();
            foreach ($_POST['translate_to'] as $lang_to => $one) {
                if (isset($services[$lang_to])) {
                    $translate_to[$lang_to] = $services[$lang_to];
                }
            }
            if (!empty($translate_to)) {
                icl_translation_send_strings($string_ids, $translate_to);
            }
        }
    }
    // hook into blog title and tag line
    add_filter('option_blogname', 'icl_sw_filters_blogname');
    add_filter('option_blogdescription', 'icl_sw_filters_blogdescription');
    add_filter('widget_title', 'icl_sw_filters_widget_title');
    add_filter('widget_text', 'icl_sw_filters_widget_text');
    if (isset($sitepress_settings['theme_localization_type']) && $sitepress_settings['theme_localization_type'] == 1) {
        add_filter('gettext', 'icl_sw_filters_gettext', 9, 3);
        add_filter('gettext_with_context', 'icl_sw_filters_gettext_with_context', 9, 4);
        add_filter('ngettext', 'icl_sw_filters_ngettext', 9, 5);
        add_filter('ngettext_with_context', 'icl_sw_filters_nxgettext', 9, 6);
    }
    $widget_groups = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%'");
    foreach ($widget_groups as $w) {
        add_action('update_option_' . $w->option_name, 'icl_st_update_widget_title_actions', 5, 2);
    }
    add_action('update_option_widget_text', 'icl_st_update_text_widgets_actions', 5, 2);
    add_action('update_option_sidebars_widgets', '__icl_st_init_register_widget_titles');
    if ($icl_st_err_str) {
        add_action('admin_notices', 'icl_st_admin_notices');
    }
    add_filter('get_the_author_first_name', 'icl_st_author_first_name_filter', 10, 2);
    add_filter('get_the_author_last_name', 'icl_st_author_last_name_filter', 10, 2);
    add_filter('get_the_author_nickname', 'icl_st_author_nickname_filter', 10, 2);
    add_filter('get_the_author_description', 'icl_st_author_description_filter', 10, 2);
    add_filter('the_author', 'icl_st_author_displayname_filter', 10);
}
コード例 #3
0
} elseif (filter_input(INPUT_GET, 'download_mo')) {
    include dirname(__FILE__) . '/auto-download-mo.php';
    return;
}
$status_filter_text = filter_input(INPUT_GET, 'status');
if (preg_match("#" . ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR . "-(.+)#", $status_filter_text, $matches)) {
    $status_filter = ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR;
    $status_filter_lang = $matches[1];
} else {
    $status_filter = filter_input(INPUT_GET, 'status', FILTER_SANITIZE_NUMBER_INT);
}
$status_filter = $status_filter !== null ? (int) $status_filter : null;
$context_filter = filter_input(INPUT_GET, 'context');
$search_filter = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$exact_match = filter_input(INPUT_GET, 'em', FILTER_VALIDATE_BOOLEAN);
$icl_string_translations = icl_get_string_translations();
if (!empty($icl_string_translations)) {
    $icl_strings_in_page = icl_get_strings_tracked_in_pages($icl_string_translations);
}
$active_languages = $sitepress->get_active_languages();
$icl_contexts = icl_st_get_contexts($status_filter);
$icl_st_translation_enabled = $sitepress->icl_account_configured() && $sitepress->get_icl_translation_enabled();
$available_contexts = array();
if (!empty($icl_contexts)) {
    foreach ($icl_contexts as $c) {
        if ($c) {
            $available_contexts[] = $c->context;
        }
    }
}
if (!empty($sitepress_settings['st']['theme_localization_domains']) && is_array($sitepress_settings['st']['theme_localization_domains'])) {
コード例 #4
0
ファイル: functions.php プロジェクト: crazyyy/octagram
function icl_st_init()
{
    global $sitepress_settings, $sitepress, $wpdb, $icl_st_err_str;
    if ($GLOBALS['pagenow'] === 'site-new.php' && isset($_REQUEST['action']) && 'add-site' === $_REQUEST['action']) {
        return;
    }
    add_action('icl_update_active_languages', 'icl_update_string_status_all');
    add_action('update_option_blogname', 'icl_st_update_blogname_actions', 5, 2);
    add_action('update_option_blogdescription', 'icl_st_update_blogdescription_actions', 5, 2);
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_page') {
        icl_st_string_in_page($_GET['string_id']);
        exit;
    }
    if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'view_string_in_source') {
        icl_st_string_in_source($_GET['string_id']);
        exit;
    }
    if (get_magic_quotes_gpc() && isset($_GET['page']) && $_GET['page'] === WPML_ST_FOLDER . '/menu/string-translation.php') {
        $_POST = stripslashes_deep($_POST);
    }
    if (!isset($sitepress_settings['existing_content_language_verified']) || !$sitepress_settings['existing_content_language_verified']) {
        return;
    }
    if (!isset($sitepress_settings['st']['sw'])) {
        $sitepress_settings['st']['sw'] = array();
        //no settings for now
        $sitepress->save_settings($sitepress_settings);
        $init_all = true;
    }
    if (!isset($sitepress_settings['st']['strings_per_page'])) {
        $sitepress_settings['st']['strings_per_page'] = 10;
        $sitepress->save_settings($sitepress_settings);
    } elseif (isset($_GET['strings_per_page']) && $_GET['strings_per_page'] > 0) {
        $sitepress_settings['st']['strings_per_page'] = $_GET['strings_per_page'];
        $sitepress->save_settings($sitepress_settings);
    }
    if (!isset($sitepress_settings['st']['icl_st_auto_reg'])) {
        $sitepress_settings['st']['icl_st_auto_reg'] = 'disable';
        $sitepress->save_settings($sitepress_settings);
    }
    if (empty($sitepress_settings['st']['strings_language'])) {
        $iclsettings['st']['strings_language'] = $sitepress_settings['st']['strings_language'] = 'en';
        $sitepress->save_settings($iclsettings);
    }
    if (!isset($sitepress_settings['st']['translated-users'])) {
        $sitepress_settings['st']['translated-users'] = array();
    }
    if (isset($_POST['iclt_st_sw_save']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_sw_form') || isset($init_all)) {
        if (isset($init_all)) {
            global $WPML_String_Translation;
            $WPML_String_Translation->initialize_wp_and_widget_strings();
        }
        if (isset($_POST['iclt_st_sw_save'])) {
            $updat_string_statuses = false;
            $sitepress_settings['st']['sw'] = $_POST['icl_st_sw'];
            if ($sitepress_settings['st']['strings_language'] != $_POST['icl_st_sw']['strings_language']) {
                $updat_string_statuses = true;
            }
            $sitepress_settings['st']['strings_language'] = $_POST['icl_st_sw']['strings_language'];
            $sitepress->save_settings($sitepress_settings);
            $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_strings SET language=%s WHERE language <> %s", $sitepress_settings['st']['strings_language'], $sitepress_settings['st']['strings_language']));
            if ($updat_string_statuses) {
                icl_update_string_status_all();
            }
            //register author strings
            if (!empty($sitepress_settings['st']['translated-users'])) {
                icl_st_register_user_strings_all();
            }
            wp_redirect(admin_url('admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&updated=true'));
        }
    }
    // handle po file upload
    if (isset($_POST['icl_po_upload']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_form')) {
        if ($_FILES['icl_po_file']['size'] == 0) {
            $icl_st_err_str = __('File upload error', 'wpml-string-translation');
        } else {
            global $po_importer;
            require_once WPML_ST_PATH . '/inc/gettext/wpml-po-import.class.php';
            $po_importer = new WPML_PO_Import($_FILES['icl_po_file']['tmp_name']);
            $icl_st_err_str = $po_importer->get_errors();
        }
    } elseif (isset($_POST['action']) && 'icl_st_save_strings' == $_POST['action']) {
        $arr = array_intersect_key($_POST['icl_strings'], array_flip($_POST['icl_strings_selected']));
        //$arr = array_map('html_entity_decode', $arr);
        if (isset($_POST['icl_st_po_language'])) {
            $arr_t = array_intersect_key($_POST['icl_translations'], array_flip($_POST['icl_strings_selected']));
            $arr_f = array_intersect_key($_POST['icl_fuzzy'], array_flip($_POST['icl_strings_selected']));
            //$arr_t = array_map('html_entity_decode', $arr_t);
        }
        $arr_c = array_intersect_key($_POST['icl_context'], array_flip($_POST['icl_strings_selected']));
        foreach ($arr as $k => $string) {
            $string = str_replace('\\n', "\n", $string);
            $name = isset($_POST['icl_name'][$k]) && $_POST['icl_name'][$k] ? $_POST['icl_name'][$k] : md5($string);
            $string_id = icl_register_string(array('domain' => $_POST['icl_st_domain_name'], 'context' => $arr_c[$k]), $name, $string);
            if ($string_id && isset($_POST['icl_st_po_language'])) {
                if ($arr_t[$k] != "") {
                    if ($arr_f[$k]) {
                        $_status = ICL_TM_NOT_TRANSLATED;
                    } else {
                        $_status = ICL_TM_COMPLETE;
                    }
                    $translation = str_replace('\\n', "\n", $arr_t[$k]);
                    icl_add_string_translation($string_id, $_POST['icl_st_po_language'], $translation, $_status);
                    icl_update_string_status($string_id);
                }
            }
        }
    }
    //handle po export
    if (isset($_POST['icl_st_pie_e']) && wp_verify_nonce($_POST['_wpnonce'], 'icl_po_export')) {
        //force some filters
        if (isset($_GET['status'])) {
            unset($_GET['status']);
        }
        $_GET['show_results'] = 'all';
        if ($_POST['icl_st_e_context']) {
            $_GET['context'] = $_POST['icl_st_e_context'];
        }
        $_GET['translation_language'] = $_POST['icl_st_e_language'];
        $strings = icl_get_string_translations();
        if (!empty($strings)) {
            $po = icl_st_generate_po_file($strings, !isset($_POST['icl_st_pe_translations']));
        } else {
            $po = "";
        }
        if (!isset($_POST['icl_st_pe_translations'])) {
            $popot = 'pot';
            $poname = $_POST['icl_st_e_context'] ? urlencode($_POST['icl_st_e_context']) : 'all_context';
        } else {
            $popot = 'po';
            $poname = $_GET['context'] . '-' . $_GET['translation_language'];
        }
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=" . $poname . '.' . $popot . ";");
        header("Content-Length: " . strlen($po));
        echo $po;
        exit(0);
    } elseif (isset($_POST['icl_st_action']) && $_POST['icl_st_action'] == 'send_strings') {
        add_action('init', 'icl_send_strings_action');
    }
    // hook into blog title and tag line
    add_filter('option_blogname', 'icl_sw_filters_blogname');
    add_filter('option_blogdescription', 'icl_sw_filters_blogdescription');
    add_filter('widget_title', 'icl_sw_filters_widget_title', 0);
    //highest priority
    add_filter('widget_text', 'icl_sw_filters_widget_text', 0);
    //highest priority
    $setup_complete = apply_filters('WPML_get_setting', false, 'setup_complete');
    $theme_localization_type = apply_filters('WPML_get_setting', false, 'theme_localization_type');
    if ($setup_complete && $theme_localization_type == 1) {
        add_filter('gettext', 'icl_sw_filters_gettext', 9, 3);
        add_filter('gettext_with_context', 'icl_sw_filters_gettext_with_context', 1, 4);
        add_filter('ngettext', 'icl_sw_filters_ngettext', 9, 5);
        add_filter('ngettext_with_context', 'icl_sw_filters_nxgettext', 9, 6);
    }
    $widget_groups = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget\\_%'");
    foreach ($widget_groups as $w) {
        add_action('update_option_' . $w->option_name, 'icl_st_update_widget_title_actions', 5, 2);
    }
    add_action('update_option_widget_text', 'icl_st_update_text_widgets_actions', 5, 2);
    add_action('update_option_sidebars_widgets', '__icl_st_init_register_widget_titles');
    if ($icl_st_err_str) {
        add_action('admin_notices', 'icl_st_admin_notices');
    }
    if (isset($_REQUEST['string-translated']) && $_REQUEST['string-translated'] == true) {
        add_action('admin_notices', 'icl_st_admin_notices_string_updated');
    }
    add_filter('get_the_author_first_name', 'icl_st_author_first_name_filter', 10, 2);
    add_filter('get_the_author_last_name', 'icl_st_author_last_name_filter', 10, 2);
    add_filter('get_the_author_nickname', 'icl_st_author_nickname_filter', 10, 2);
    add_filter('get_the_author_description', 'icl_st_author_description_filter', 10, 2);
    add_filter('the_author', 'icl_st_author_displayname_filter', 10);
}