示例#1
0
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0)
{
    if (!defined('ICL_SITEPRESS_VERSION') || ICL_PLUGIN_INACTIVE) {
        return $option_value;
    }
    // determine option name
    if (!$name && $rec_level == 0) {
        $ob = debug_backtrace();
        if (is_scalar($ob[2 + $rec_level]['args'][0])) {
            $name = preg_replace('@^option_@', '', $ob[2 + $rec_level]['args'][0]);
        }
    }
    // cache - phase 1 - check/get
    static $__icl_st_cache;
    if ($rec_level == 0) {
        if (isset($__icl_st_cache[$name]) && apply_filters('icl_st_admin_string_return_cached', true, $name)) {
            //echo "FROM CACHE $name<br />";
            return $__icl_st_cache[$name];
        }
    }
    // case of double-serialized options (See Arras theme)
    $serialized = false;
    if (is_serialized($option_value)) {
        $option_value = @unserialize($option_value);
        $serialized = true;
    }
    //if(is_object($option_value)){
    //$option_value = (array)$option_value;
    //}
    if (is_array($option_value) || is_object($option_value)) {
        foreach ($option_value as $k => $value) {
            $val = icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1);
            if (is_object($option_value)) {
                $option_value->{$k} = $val;
            } else {
                $option_value[$k] = $val;
            }
        }
    } else {
        static $option_names;
        if (empty($option_names)) {
            $option_names = get_option('_icl_admin_option_names');
        }
        // determine theme/plugin name
        if (!empty($option_names['theme']) && !empty($option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)])) {
            if (isset($option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)])) {
                foreach ((array) $option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)] as $ops => $val) {
                    if (!empty($key)) {
                        $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                        if ($int) {
                            $opname = $matches[1][0];
                        }
                    } else {
                        $opname = $name;
                    }
                    if ($ops == $opname) {
                        $key_suff = 'theme_' . basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY);
                        break;
                    }
                }
            }
            if (ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY != ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY) {
                if (isset($option_names['theme'][basename(ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY)])) {
                    foreach ((array) $option_names['theme'][basename(ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY)] as $ops => $val) {
                        if (!empty($key)) {
                            $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                            if ($int) {
                                $opname = $matches[1][0];
                            }
                        } else {
                            $opname = $name;
                        }
                        if ($ops == $opname) {
                            $key_suff = 'theme_' . ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY;
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($option_names['plugin'])) {
            foreach ((array) $option_names['plugin'] as $plugin => $options) {
                foreach ($options as $kops => $ops) {
                    if (is_array($ops)) {
                        $arrkey = explode('][', trim($key, '[]'));
                        $_val = $options;
                        for ($i = 0; $i < count($arrkey); $i++) {
                            if (isset($_val[$arrkey[$i]])) {
                                $_val = $_val[$arrkey[$i]];
                            } else {
                                break;
                            }
                        }
                        if (in_array($name, $_val)) {
                            // seems not work since WPML 3.1, added next elseif which works
                            $key_suff = 'plugin_' . $plugin;
                            break;
                        } elseif (in_array($name, array_keys($_val))) {
                            $key_suff = 'plugin_' . $plugin;
                            break;
                        }
                    } elseif ($ops == $name) {
                        // seems not work since WPML 3.1, added next elseif which works
                        $key_suff = 'plugin_' . $plugin;
                        break;
                    } elseif ($kops == $name) {
                        $key_suff = 'plugin_' . $plugin;
                        break;
                    }
                }
            }
        }
        if (!empty($key_suff)) {
            $tr = icl_t('admin_texts_' . $key_suff, $key . $name, $option_value, $hast, true);
        }
        if (isset($tr)) {
            $option_value = $tr;
        }
    }
    // case of double-serialized options (See Arras theme)
    if ($serialized) {
        $option_value = serialize($option_value);
    }
    // cache - phase 2 - set
    if ($rec_level == 0) {
        $__icl_st_cache[$name] = $option_value;
    }
    /*
     * if sticky links plugin is enabled and set to change links into sticky 
     * in strings, change those links back into permalinks when displayed
     */
    if (is_string($option_value) and class_exists("WPML_Sticky_links")) {
        global $WPML_Sticky_Links;
        if (isset($WPML_Sticky_Links)) {
            if ($WPML_Sticky_Links->settings['sticky_links_strings']) {
                $option_value = $WPML_Sticky_Links->show_permalinks($option_value);
            }
        }
    }
    return $option_value;
}
示例#2
0
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0)
{
    // determine option name
    if (!$name) {
        $ob = debug_backtrace();
        if (is_scalar($ob[2 + $rec_level]['args'][0])) {
            $name = preg_replace('@^option_@', '', $ob[2 + $rec_level]['args'][0]);
        }
    }
    // cache - phase 1 - check/get
    static $__icl_st_cache;
    if ($rec_level == 0) {
        if (isset($__icl_st_cache[$name])) {
            //echo "FROM CACHE $name<br />";
            return $__icl_st_cache[$name];
        }
    }
    // case of double-serialized options (See Arras theme)
    $serialized = false;
    if (is_serialized($option_value)) {
        $option_value = @unserialize($option_value);
        $serialized = true;
    }
    //if(is_object($option_value)){
    //$option_value = (array)$option_value;
    //}
    if (is_array($option_value) || is_object($option_value)) {
        foreach ($option_value as $k => $value) {
            $val = icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1);
            if (is_object($option_value)) {
                $option_value->{$k} = $val;
            } else {
                $option_value[$k] = $val;
            }
        }
    } else {
        static $option_names;
        if (empty($option_names)) {
            $option_names = get_option('_icl_admin_option_names');
        }
        // determine theme/plugin name
        if (!empty($option_names['theme']) && !empty($option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)])) {
            if (isset($option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)])) {
                foreach ((array) $option_names['theme'][basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY)] as $ops => $val) {
                    if (!empty($key)) {
                        $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                        if ($int) {
                            $opname = $matches[1][0];
                        }
                    } else {
                        $opname = $name;
                    }
                    if ($ops == $opname) {
                        $key_suff = 'theme_' . basename(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY);
                        break;
                    }
                }
            }
            if (ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY != ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY) {
                if (isset($option_names['theme'][basename(ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY)])) {
                    foreach ((array) $option_names['theme'][basename(ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY)] as $ops => $val) {
                        if (!empty($key)) {
                            $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                            if ($int) {
                                $opname = $matches[1][0];
                            }
                        } else {
                            $opname = $name;
                        }
                        if ($ops == $opname) {
                            $key_suff = 'theme_' . ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY;
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($option_names['plugin'])) {
            foreach ((array) $option_names['plugin'] as $plugin => $options) {
                foreach ($options as $kops => $ops) {
                    if (is_array($ops)) {
                        $arrkey = explode('][', trim($key, '[]'));
                        $_val = $options;
                        for ($i = 0; $i < count($arrkey); $i++) {
                            if (isset($_val[$arrkey[$i]])) {
                                $_val = $_val[$arrkey[$i]];
                            } else {
                                break;
                            }
                        }
                        if (in_array($name, $_val)) {
                            $key_suff = 'plugin_' . $plugin;
                            break;
                        }
                    } elseif ($ops == $name) {
                        $key_suff = 'plugin_' . $plugin;
                        break;
                    }
                }
            }
        }
        if (!empty($key_suff)) {
            $tr = icl_t('admin_texts_' . $key_suff, $key . $name, $option_value, $hast, true);
        }
        if (isset($tr)) {
            $option_value = $tr;
        }
    }
    // case of double-serialized options (See Arras theme)
    if ($serialized) {
        $option_value = serialize($option_value);
    }
    // cache - phase 2 - set
    if ($rec_level == 0) {
        $__icl_st_cache[$name] = $option_value;
    }
    return $option_value;
}
function icl_st_translate_admin_string($option_value, $key = "", $name = "", $rec_level = 0)
{
    // case of double-serialized options (See Arras theme)
    $serialized = false;
    if (is_serialized($option_value)) {
        $option_value = @unserialize($option_value);
        $serialized = true;
    }
    //if(is_object($option_value)){
    //$option_value = (array)$option_value;
    //}
    if (is_array($option_value) || is_object($option_value)) {
        if (!$name) {
            $ob = debug_backtrace();
            if (is_scalar($ob[3]['args'][0])) {
                $name = preg_replace('@^option_@', '', $ob[3 + $rec_level]['args'][0]);
            }
        }
        foreach ($option_value as $k => $value) {
            $val = icl_st_translate_admin_string($value, $key . '[' . $name . ']', $k, $rec_level + 1);
            if (is_object($option_value)) {
                $option_value->{$k} = $val;
            } else {
                $option_value[$k] = $val;
            }
        }
    } else {
        if (!$name) {
            $ob = debug_backtrace();
            if (is_scalar($ob[2 + $rec_level]['args'][0])) {
                $name = preg_replace('@^option_@', '', $ob[2 + $rec_level]['args'][0]);
            }
        }
        $option_names = get_option('_icl_admin_option_names');
        // determine theme/plugin name
        if (!empty($option_names['theme'])) {
            foreach ((array) $option_names['theme'][basename(get_template_directory())] as $ops => $val) {
                if (!empty($key)) {
                    $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                    if ($int) {
                        $opname = $matches[1][0];
                    }
                } else {
                    $opname = $name;
                }
                if ($ops == $opname) {
                    $key_suff = 'theme_' . basename(get_template_directory());
                    break;
                }
            }
            if (get_template_directory() != get_stylesheet_directory()) {
                foreach ((array) $option_names['theme'][basename(get_stylesheet_directory())] as $ops => $val) {
                    if (!empty($key)) {
                        $int = preg_match_all('#\\[([^\\]]+)\\]#', $key, $matches);
                        if ($int) {
                            $opname = $matches[1][0];
                        }
                    } else {
                        $opname = $name;
                    }
                    if ($ops == $opname) {
                        $key_suff = 'theme_' . get_stylesheet_directory();
                        break;
                    }
                }
            }
        }
        if (!empty($option_names['plugin'])) {
            foreach ((array) $option_names['plugin'] as $plugin => $options) {
                foreach ($options as $kops => $ops) {
                    if (is_array($ops)) {
                        $arrkey = explode('][', trim($key, '[]'));
                        $_val = $options;
                        for ($i = 0; $i < count($arrkey); $i++) {
                            if (isset($_val[$arrkey[$i]])) {
                                $_val = $_val[$arrkey[$i]];
                            } else {
                                break;
                            }
                        }
                        if (in_array($name, $_val)) {
                            $key_suff = 'plugin_' . $plugin;
                            break;
                        }
                    } elseif ($ops == $name) {
                        $key_suff = 'plugin_' . $plugin;
                        break;
                    }
                }
            }
        }
        if (!empty($key_suff)) {
            $tr = icl_t('admin_texts_' . $key_suff, $key . $name, $option_value, $hast, true);
        }
        if (!is_null($tr)) {
            $option_value = $tr;
        }
    }
    // case of double-serialized options (See Arras theme)
    if ($serialized) {
        $option_value = serialize($option_value);
    }
    return $option_value;
}