Exemple #1
0
function icl_st_scan_options_strings()
{
    global $wpdb;
    $options = array();
    // scan theme php file for update_option(), add_option()
    $options_names = _icl_st_get_options_writes(ICL_STRING_TRANSLATION_TEMPLATE_DIRECTORY);
    $options_names = array_merge($options_names, _icl_st_get_options_writes(ICL_STRING_TRANSLATION_STYLESHEET_DIRECTORY));
    $options_names = array_unique($options_names);
    $options_names = array_map('mysql_real_escape_string', $options_names);
    if (!empty($options_names)) {
        $res = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name IN ('" . join("','", $options_names) . "')");
        foreach ($res as $row) {
            $options[$row->option_name] = maybe_unserialize($row->option_value);
            // try unserializing twice - just in case (see Arras Theme)
            $options[$row->option_name] = maybe_unserialize($options[$row->option_name]);
        }
    }
    $_icl_admin_option_names = get_option('_icl_admin_option_names', array());
    $_icl_admin_option_names = @array_merge_recursive($_icl_admin_option_names, $options_names);
    $_icl_admin_option_names = __array_unique_recursive($_icl_admin_option_names);
    update_option('_icl_admin_option_names', $_icl_admin_option_names);
    return $options;
}
Exemple #2
0
function _icl_st_get_options_writes($path)
{
    static $found_writes = array();
    if (is_dir($path)) {
        $dh = opendir($path);
        while ($file = readdir($dh)) {
            if ($file == "." || $file == "..") {
                continue;
            }
            if (is_dir($path . '/' . $file)) {
                _icl_st_get_options_writes($path . '/' . $file);
            } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) {
                $content = file_get_contents($path . '/' . $file);
                $int = preg_match_all('#(add|update)_option\\(([^,]+),([^)]+)\\)#im', $content, $matches);
                if ($int) {
                    foreach ($matches[2] as $m) {
                        $option_name = trim($m);
                        if (0 === strpos($option_name, '"') || 0 === strpos($option_name, "'")) {
                            $option_name = trim($option_name, "\"'");
                        } elseif (false === strpos($option_name, '$')) {
                            if (false !== strpos($option_name, '::')) {
                                $cexp = explode('::', $option_name);
                                if (class_exists($cexp[0])) {
                                    if (defined($cexp[0] . '::' . $cexp[1])) {
                                        $option_name = constant($cexp[0] . '::' . $cexp[1]);
                                    }
                                }
                            } else {
                                if (defined($option_name)) {
                                    $option_name = constant($option_name);
                                }
                            }
                        } else {
                            $option_name = false;
                        }
                        if ($option_name) {
                            $found_writes[] = $option_name;
                        }
                    }
                }
            }
        }
    }
    return $found_writes;
}
function icl_st_scan_options_strings()
{
    global $wpdb;
    $options = array();
    // scan theme php file for update_option(), add_option()
    $options_names = _icl_st_get_options_writes(get_template_directory());
    $options_names = array_merge($options_names, _icl_st_get_options_writes(get_stylesheet_directory()));
    $options_names = array_unique($options_names);
    if (!empty($options_names)) {
        $res = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name IN ('" . join("','", $options_names) . "')");
        foreach ($res as $row) {
            $options[$row->option_name] = maybe_unserialize($row->option_value);
            // try unserializing twice - just in case (see Arras Theme)
            $options[$row->option_name] = maybe_unserialize($options[$row->option_name]);
        }
    }
    update_option('_icl_admin_option_names', $options_names);
    return $options;
}