예제 #1
0
function qtranxf_slug_update_translations_for($name, &$qfields, $default_lang)
{
    if (isset($qfields['qtranslate-original-value'])) {
        qtranxf_slug_update_translations($name, $qfields, $default_lang);
    } else {
        foreach ($qfields as $nm => &$vals) {
            qtranxf_slug_update_translations_for($nm, $vals, $default_lang);
            // recursive call
        }
    }
}
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);
}
예제 #3
0
function qtranxf_slug_edited_term($term_id, $tt_id, $taxonomy)
{
    global $q_config;
    if (!isset($_POST['qtranslate-slugs']['slug'])) {
        return;
    }
    $qfields = $_POST['qtranslate-slugs']['slug'];
    $default_lang = $q_config['default_language'];
    $term = get_term($term_id, $taxonomy);
    //qtranxf_dbg_log('qtranxf_slug_edited_term: $term: ', $term);
    //qtranxf_dbg_log('qtranxf_slug_edited_term: $qfields: ', $qfields);
    $name = $term->slug;
    qtranxf_slug_update_translations($name, $qfields, $default_lang);
    qtranxf_slug_clean_request('slug');
}
function qtranxf_slug_update_translations_of($group, $group_name, $default_lang, &$wp_group)
{
    global $q_config;
    foreach ($_POST['qtranslate-slugs'][$group] as $key => &$qfields) {
        if (!isset($wp_group[$key])) {
            qtranxf_add_error(sprintf(__('Translations of "%s" cannot be updated for unknown term "%s".', 'qtranslate'), $group_name, $key));
            continue;
        }
        $is_permastruct;
        $value_new = qtranxf_slug_sanitize($qfields[$default_lang], $is_permastruct);
        //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $value_new: ', $value_new);
        if (isset($qfields['qtranslate-original-value'])) {
            $value_org = $qfields['qtranslate-original-value'];
            if ($value_org != $value_new) {
                //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $value_org: ', $value_org);
                if (!isset($q_config['slugs_opt']['mv'])) {
                    $q_config['slugs_opt']['mv'] = array();
                }
                if (!isset($q_config['slugs_opt']['mv']['terms'])) {
                    $q_config['slugs_opt']['mv']['terms'] = array();
                }
                if (!isset($q_config['slugs_opt']['mv']['terms'][$group])) {
                    $q_config['slugs_opt']['mv']['terms'][$group] = array('group_name' => $group_name, 'values' => array());
                }
                if (!isset($q_config['slugs_opt']['mv']['terms'][$group]['values'][$key])) {
                    $q_config['slugs_opt']['mv']['terms'][$group]['values'][$key] = array();
                    $q_config['slugs_opt']['mv']['terms'][$group]['values'][$key]['value_org'] = $value_org;
                }
                $q_config['slugs_opt']['mv']['terms'][$group]['values'][$key]['value_new'] = $value_new;
            }
            qtranxf_slug_del_translations_permastruct($value_org);
            $qfields = qtranxf_slug_replace($value_org, $value_new, $qfields);
        }
        $info_def = qtranxf_slug_split_permastruct($value_new);
        //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $info_def: ', $info_def);
        $cnt = count($info_def['slugs']);
        //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $cnt: ', $cnt);
        if ($is_permastruct) {
            $names = array();
            foreach ($info_def['slugs'] as $name) {
                $names[$name] = array();
            }
            foreach ($qfields as $lng => $val) {
                if (empty($val)) {
                    continue;
                }
                //default will be used
                $info_lng = qtranxf_slug_split_permastruct($val);
                if (count($info_lng['slugs']) != $cnt) {
                    qtranxf_add_error(sprintf(__('Translation of term "%s" for language code "%s", "%s" -> "%s", is inconsistent. Translation has to have matching structire. Please, correct it and try saving the configuration again.', 'qtranslate'), $group_name, $lng, $value_new, $val));
                    continue;
                }
                foreach ($info_lng['slugs'] as $k => $s) {
                    $name = $info_def['slugs'][$k];
                    $names[$name][$lng] = $s;
                }
            }
            //qtranxf_dbg_log('qtranxf_slug_update_translations_of: $names: ', $names);
            foreach ($names as $name => $slugs) {
                qtranxf_slug_update_translations($name, $slugs, $default_lang);
            }
        } else {
            //qtranxf_dbg_log('qtranxf_slug_update_translations_of: ok $value_new: ', $value_new);
            qtranxf_slug_update_translations($value_new, $qfields, $default_lang);
        }
    }
    /*
    	if(!empty($q_config['slugs_opt']['mv']['terms'][$group]['values'])){
    		$msg = '<br/>'.PHP_EOL;
    		foreach($q_config['slugs_opt']['mv']['terms'][$group]['values'] as $key => $info){
    			$name_org = $info['value_org'];
    			$name_new = $info['value_new'];
    			$msg .= '"'.$name_org.'" -> "'.$name_new.'"<br/>'.PHP_EOL;
    		}
    		qtranxf_add_warning(sprintf(__('The following default language slugs for custom %s have been renamed: %s Those custom types are created by the theme or by some 3rd-party plugins, which have not yet been fully %sintegrated%s with %s. Thefore you have to change the default language slug of those types using their custom tools. Make sure to change them to the same value as shown above, otherwise you will need to re-enter the translations of those strings again on this configuration page.', 'qtranslate'), $group_name, $msg, '<a href="https://qtranslatexteam.wordpress.com/integration/" target="_blank">', '</a>', 'qTranslate&#8209;X'));
    	}
    	//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'));
    */
    qtranxf_slug_clean_request($group);
}