コード例 #1
0
function qtranxf_slug_multilingual($name)
{
    global $q_config;
    $results = qtranxf_slug_get_translations($name);
    if (empty($results)) {
        return $name;
    }
    $slugs = array();
    foreach ($results as $row) {
        $slugs[$row->lang] = $row->slug;
    }
    foreach ($q_config['enabled_languages'] as $lang) {
        if (isset($slugs[$lang])) {
            continue;
        }
        $slugs[$lang] = $name;
    }
    return qtranxf_join_b($slugs);
}
コード例 #2
0
/**
 * @param (string) $name - rawurlencoded post name or other slug (not permastruct).
 * @return string - multilingual urldecoded value for post name or other slug.
 */
function qtranxf_slug_multilingual($name)
{
    global $q_config;
    $name = urldecode($name);
    $slugs = qtranxf_slug_get_translations(qtranxf_slug_encode($name));
    if (empty($slugs)) {
        return $name;
    }
    foreach ($q_config['enabled_languages'] as $lang) {
        if (isset($slugs[$lang])) {
            //$slugs[$lang] = urldecode($slugs[$lang]);
        } else {
            $slugs[$lang] = $name;
        }
    }
    return urldecode(qtranxf_join_b($slugs));
}
コード例 #3
0
ファイル: qtx_slug.php プロジェクト: vinnygats/qtranslate-x
/**
 * @param (string) $name - rawurlencoded post name or other slug.
 * @param (string) $lang - two-letter language code.
 * @return string - rawurlencoded slug for language $lang.
*/
function qtranxf_slug_translate_name($name, $lang)
{
    $slugs = qtranxf_slug_get_translations($name);
    //qtranxf_dbg_log('qtranxf_slug_translate_name('.$name.', '.$lang.'): slugs: ', $slugs);
    if (isset($slugs[$lang])) {
        return $slugs[$lang];
    }
    return null;
}
コード例 #4
0
function qtranxf_slug_update_translations_of($group, $group_name, $default_lang, &$wp_group)
{
    foreach ($_POST['qtranslate-slugs'][$group] as $name_old => &$qfields) {
        //$name_old = $qfields['qtranslate-original-value'];
        $name = sanitize_key($qfields[$default_lang]);
        //qtranxf_dbg_log('qtranxf_slug_update_translations_of: new: $wp_group['.$name.']: ', $wp_group[$name]);
        //qtranxf_dbg_log('qtranxf_slug_update_translations_of: old: $wp_group['.$name_old.']: ', $wp_group[$name_old]);
        if ($name != $name_old) {
            if (isset($wp_group[$name_old])) {
                qtranxf_add_warning(sprintf(__('The slug for %s "%s" for default language cannot be changed to "%s" on this page, because it is not known here which tool created it and for what purpose. Please, update this slug on the page where it is originated from. It may be required then to come back here to update the translations, unless the other plugin or theme is %sintegrated%s with %s.', 'qtranslate'), $group_name, $name_old, $name, '<a href="https://qtranslatexteam.wordpress.com/integration/" target="_blank">', '</a>', 'qTranslate&#8209;X'));
                $qfields[$default_lang] = $name = $name_old;
            } else {
                $slugs_old = qtranxf_slug_get_translations($name_old);
                //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $slugs_old: ', $slugs_old);
                if (!empty($slugs_old)) {
                    qtranxf_slug_del_translations($name_old);
                }
            }
        }
        if (isset($wp_group[$name])) {
            qtranxf_slug_update_translations($name, $qfields, $default_lang);
        } else {
            qtranxf_add_error(sprintf(__('Translations cannot be updated for unknown %s "%s".', 'qtranslate'), $group_name, $name));
        }
    }
    qtranxf_slug_clean_request($group);
}
コード例 #5
0
function qtranxf_slug_rewrite_rules_array($rules_orig)
{
    //qtranxf_dbg_log('qtranxf_slug_rewrite_rules_array: $rules_orig: ', $rules_orig);
    $rules = array();
    //need to preserve order of items
    foreach ($rules_orig as $k => $v) {
        //if(qtranxf_isMultilingual($k)){}
        $blocks = preg_split('/([^a-z0-9_\\-]+)/', $k, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $rx = '';
        foreach ($blocks as $b) {
            if (!preg_match('/[^a-z0-9_\\-]+/', $b)) {
                $slugs = qtranxf_slug_get_translations($b);
                if (!empty($slugs)) {
                    $b = '(?i:' . $b;
                    foreach ($slugs as $s) {
                        $b .= '|' . $s;
                    }
                    $b .= ')';
                    $changed = true;
                }
            }
            $rx .= $b;
        }
        //qtranxf_dbg_log('qtranxf_slug_rewrite_rules_array: $k="'.$k.'"; $blocks: ', $blocks);
        $rules[$rx] = $v;
    }
    //qtranxf_dbg_log('qtranxf_slug_rewrite_rules_array: $rules: ', $rules);
    return $rules;
}