Esempio n. 1
0
function weaverii_filter_textarea($text)
{
    // virtually all option text input from Weaver II can be code, and thus must not be
    // content filtered. Treat like code for now....
    return weaverii_filter_code($text);
}
Esempio n. 2
0
function weaverii_validate_all_options($in)
{
    /* validation for all options  */
    $err_msg = '';
    // no error message yet
    if (empty($in)) {
        wp_die(__('You attempted to save options, but something has gone wrong. Please be sure you are logged in and your host is correctly configured. See the "Weaver II Doesn\'t Save Settings" FAQ on weavertheme.com.', 'weaver-ii'));
    }
    if (!current_user_can('edit_theme_options')) {
        wp_die(__('You do not have sufficient permissions to manage options for this site.', 'weaver-ii'));
    }
    $wvr_last = '';
    foreach ($in as $key => $value) {
        switch ($key) {
            /* -------- integer -------- */
            case 'wii_excerpt_length':
                if (!empty($value) && (!is_numeric($value) || !is_int((int) $value))) {
                    $opt_id = str_replace('wii_', '', $key);
                    $opt_id = str_replace('_', ' ', $opt_id);
                    $err_msg .= weaverii_t_('Option must be an integer value: ') . '"' . $opt_id . '" = "' . $value . '".' . weaverii_t_(' Value has been cleared to blank value') . '<br />';
                    $in[$key] = '';
                }
                break;
            case 'wii_style_version':
                // auto-bumb whenever save options
                $vers = $value ? $value + 1 : 1;
                // bump or init
                $in[$key] = $vers;
                break;
                /* ---------- text ----------- */
            /* ---------- text ----------- */
            case 'wii_excerpt_more_msg':
            case 'wii_header_maxwidth':
                if (!empty($value)) {
                    $in[$key] = weaverii_filter_textarea($value);
                }
                break;
            case 'wii_themename':
                // can't be empty!
                if (empty($value)) {
                    $in[$key] = 'please-give-this-a-name';
                } else {
                    $in[$key] = weaverii_filter_textarea($value);
                }
                break;
                /* code */
            /* code */
            case '_wii_metainfo':
                // meta info for header
            // meta info for header
            case 'wii_theme_head_opts':
                // Predefined Theme CSS Rules
            // Predefined Theme CSS Rules
            case 'wii_menu_addhtml-left':
                // add html to left menu
            // add html to left menu
            case 'wii_menu_addhtml':
            case '_wii_copyright':
                // Alternate copyright
            // Alternate copyright
            case '_wii_css_rows':
            case 'ftp_hostname':
            case 'ftp_username':
            case '_wii_search_button_url':
                if (!empty($value)) {
                    $in[$key] = weaverii_filter_code($value);
                }
                break;
            case 'ftp_password':
                // special handling for password
                if (!empty($value)) {
                    $c_t = weaverii_encrypt(trim($value));
                    $in[$key] = $c_t;
                }
                break;
            case 'wii_perpagewidgets':
                // Add widget areas for per page - names must be lower case
                if (!empty($value)) {
                    $in[$key] = strtolower(str_ireplace(' ', '', weaverii_filter_code($value)));
                }
                break;
                /* must not have <style .... </style> */
            /* must not have <style .... </style> */
            case 'wii_add_css':
                // Add CSS Rules to Weaver II's style rules
                if (!empty($value)) {
                    $val = weaverii_filter_code($value);
                    $in[$key] = $val;
                    if (stripos($val, '<style') !== false || stripos($val, '</style') !== false) {
                        $err_msg .= weaverii_t_('"Add CSS Rules" option must not contain &lt;style&gt; tags!') . weaverii_t_(' Please correct your entry.') . '<br />';
                    }
                }
                break;
            case 'wii_last_option':
                // check for wii_last_option...
                if (!empty($value)) {
                    $wvr_last = $value;
                }
                break;
            case 'hide_advanced_btn':
                if (stripos($value, 'hide') === false) {
                    $in['hide_advanced'] = 'show';
                } else {
                    $in['hide_advanced'] = 'hide';
                }
                break;
            case 'hide_advanced':
                $val = $value;
                if (isset($in['hide_advanced_btn'])) {
                    if (stripos($in['hide_advanced_btn'], 'hide') === false) {
                        $val = 'show';
                    } else {
                        $val = 'hide';
                    }
                }
                $in[$key] = $val;
                break;
            case '_phpactions':
                if (!empty($value)) {
                    $in[$key] = stripslashes(wp_check_invalid_utf8(addslashes($value)));
                }
                break;
            default:
                /* to here, then colors, _css, or checkbox/selectors */
                $keylen = strlen($key);
                if (strrpos($key, '_css') == $keylen - 4) {
                    // all _css settings
                    if (!empty($value)) {
                        $val = weaverii_filter_code($value);
                        $in[$key] = $val;
                        if (strpos($val, '{') === false || strpos($val, '}') === false) {
                            $opt_id = str_replace('_css', '', $key);
                            // kill _css
                            $opt_id = str_replace('wii_', '', $opt_id);
                            $opt_id = str_replace('_', ' ', $opt_id);
                            $err_msg .= weaverii_t_('CSS options must be enclosed in {}\'s: ') . '"' . $opt_id . '" = "' . $value . '".' . weaverii_t_(' Please correct your entry.') . '<br />';
                        }
                    }
                    break;
                }
                // _css
                if (strrpos($key, '_insert') == $keylen - 7) {
                    // all _insert settings
                    if (!empty($value)) {
                        $val = weaverii_filter_code($value);
                        $in[$key] = $val;
                    }
                    break;
                }
                // _insert
                if (strrpos($key, '_url') == $keylen - 4) {
                    // all _url settings
                    if (!empty($value)) {
                        $val = weaverii_filter_code($value);
                        // can't use esc_url because that forces a leading html{background-image: url(%template_directory%images/addon_themes.png);}
                        $in[$key] = $val;
                    }
                    break;
                }
                // _insert
                if (strrpos($key, '_dec') == $keylen - 4) {
                    if (!empty($value) && !is_numeric($value)) {
                        $opt_id = str_replace('wii_', '', $key);
                        $opt_id = str_replace('_dec', '', $opt_id);
                        $opt_id = str_replace('_', ' ', $opt_id);
                        $err_msg .= weaverii_t_('Option must be a numeric value: ') . '"' . $opt_id . '" = "' . $value . '".' . weaverii_t_(' Value has been cleared to blank value.') . '<br />';
                        $in[$key] = '';
                    }
                    break;
                }
                if (strrpos($key, '_int') == $keylen - 4 || strrpos($key, '_X') == $keylen - 2 || strrpos($key, '_Y') == $keylen - 2 || strrpos($key, '_L') == $keylen - 2 || strrpos($key, '_R') == $keylen - 2 || strrpos($key, '_T') == $keylen - 2 || strrpos($key, '_B') == $keylen - 2) {
                    if (!empty($value) && (!is_numeric($value) || !is_int((int) $value))) {
                        $opt_id = str_replace('wii_', '', $key);
                        $opt_id = str_replace('_int', '', $opt_id);
                        $opt_id = str_replace('_', ' ', $opt_id);
                        $err_msg .= weaverii_t_('Option must be a numeric value: ') . '"' . $opt_id . '" = "' . $value . '".' . weaverii_t_(' Value has been cleared to blank value.') . '<br />';
                        $in[$key] = '';
                    }
                    break;
                }
                if (strrpos($key, 'color') == $keylen - 5) {
                    // _bgcolor and _color (order here important - after _css, etc.)
                    if (!empty($value)) {
                        $val = weaverii_filter_code($value);
                        if (preg_match('/^#?+[0-9a-f]{3}(?:[0-9a-f]{3})?$/i', $val)) {
                            // hex value
                            $val = strtoupper($val);
                            // force hex values to upper case, just to be tidy
                            if ($val[0] != '#') {
                                $val = '#' . $val;
                            }
                            $in[$key] = $val;
                        } else {
                            if (preg_match("/^([a-zA-Z])+\$/i", $val)) {
                                // name - all letters
                                $in[$key] = $val;
                            } else {
                                // only legal things left are rgb and rgba
                                $isrgb = strpos($val, 'rgb');
                                if ($isrgb === false || $isrgb != 0) {
                                    $in[$key] = '';
                                    $err_msg .= 'Color must be a valid # hex value, rgb value, or color name (a-z): ' . '"' . $key . '" = "' . $value . '".' . ' Value has been cleared to blank value.' . '<br />';
                                } else {
                                    $in[$key] = $val;
                                }
                            }
                        }
                    }
                    break;
                }
                if (!empty($value) && is_string($value) && !is_numeric($value)) {
                    $in[$key] = weaverii_filter_textarea($value);
                }
                break;
        }
    }
    /* if ($wvr_last != 'Weaver II') {
    		$err_msg .= 'Warning - your host may be configured to limit how many input var options you are allowed to pass via PHP.' .
    		' Unfortunately, this means your settings may not be saved correctly. See the "Weaver II Doesn\'t Save Settings" FAQ on weavertheme.com.<br />';
    
    	} */
    if (!empty($err_msg)) {
        add_settings_error('weaverii_settings', 'settings_error', $err_msg, 'error');
    } else {
        add_settings_error('weaverii_settings', 'settings_updated', weaverii_t_('Weaver II  Settings Saved.'), 'updated');
    }
    // $GLOBALS['wvrNoSettings'] = false;  // we've saved now
    return $in;
}
function weaveriip_save_totalcss()
{
    global $weaveriip_totalcss_checkbox_opts, $weaveriip_totalcss_text_opts, $weaveriip_totalcss_bg_opts;
    /* Save options from plus header: wvrx_plus_save_posts */
    if (!weaverii_pro_isset('wvp_css')) {
        weaveriip_totalcss_init();
    }
    if (isset($_POST['css_edit_lines'])) {
        $value = weaverii_filter_code($_POST['css_edit_lines']);
        if (!empty($value) && (!is_numeric($value) || !is_int((int) $value))) {
            $value = 1;
        }
        if ($value < 1 || $value > 25) {
            $value = 1;
        }
        weaverii_pro_setopt('css_edit_lines', $value);
    }
    global $weaveriip_css;
    foreach ($weaveriip_css as $option => $val) {
        if (isset($_POST[$val['id']]) && $_POST[$val['id']] != '' && $_POST[$val['id']] != '{}') {
            $css = weaverii_filter_code($_POST[$val['id']]);
            $css = weaveriip_bracket($css, '{', '}');
            weaverii_pro_setopt($val['id'], $css);
        } else {
            weaverii_pro_setopt($val['id'], false);
        }
    }
    weaverii_pro_update_options('save_totalcss');
    /* and let the user know something happened */
    echo '<div id="message" class="updated fade"><p><strong>Weaver II Pro More Options Saved</strong></p></div>';
}