Example #1
0
function themerex_save_data_page($post_id)
{
    global $THEMEREX_meta_box_page, $THEMEREX_theme_options;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // verify nonce
    if (!isset($_POST['meta_box_page_nonce']) || !wp_verify_nonce($_POST['meta_box_page_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    $custom_options = array();
    $need_save = false;
    foreach ($THEMEREX_meta_box_page['fields'] as $field) {
        if (!isset($field['id'])) {
            continue;
        }
        if (!isset($_POST[$field['id']])) {
            continue;
        }
        $need_save = true;
        $new = isset($_POST[$field['id']]) ? $_POST[$field['id']] : '';
        $custom_options[$field['id']] = $new ? $new : 'default';
    }
    foreach ($THEMEREX_theme_options as $option) {
        if (!isset($option['override']) || !in_array('page', explode(',', $option['override']))) {
            continue;
        }
        if (!isset($option['id'])) {
            continue;
        }
        $id = get_option_name($option['id']);
        if (!isset($_POST[$id])) {
            continue;
        }
        $need_save = true;
        $new = isset($_POST[$id]) ? $_POST[$id] : '';
        $custom_options[$id] = $new ? $new : 'default';
    }
    if ($need_save) {
        update_post_meta($post_id, 'post_custom_options', $custom_options);
    }
}
Example #2
0
function category_custom_fields_save($term_id = 0)
{
    global $THEMEREX_theme_options;
    $term_meta = category_custom_fields_get($term_id);
    $need_save = false;
    foreach ($THEMEREX_theme_options as $option) {
        if (!isset($option['override']) || !in_array('category', explode(',', $option['override']))) {
            continue;
        }
        if (!isset($option['id'])) {
            continue;
        }
        $id = get_option_name($option['id']);
        if (!isset($_POST[$id])) {
            continue;
        }
        $need_save = true;
        $multiple = isset($option['multiple']) && $option['multiple'];
        if ($multiple && is_array($_POST[$id])) {
            sort($_POST[$id]);
        }
        $inc = isset($option['increment']) && $option['increment'] || $option['type'] == 'socials';
        if ($inc && is_array($_POST[$id])) {
            foreach ($_POST[$id] as $k => $v) {
                $_POST[$id][$k] .= '|' . $_POST[$id . '_numbers'][$k] . ($option['type'] == 'socials' ? '|' . $_POST[$id . '_icons'][$k] : '');
            }
        }
        $new = isset($_POST[$id]) ? ($multiple || $inc) && is_array($_POST[$id]) ? implode(',', $_POST[$id]) : stripslashes($_POST[$id]) : ($option['type'] == 'checkbox' ? 'false' : '');
        if (isset($option['enable'])) {
            $new = $new . '|' . (isset($_POST[$id . '_enable']) ? 1 : 0);
        }
        $term_meta[$id] = $new ? $new : 'default';
    }
    //save the option array
    if ($need_save) {
        category_custom_fields_set($term_id, $term_meta);
    }
}
Example #3
0
function theme_options_show_field($field, $value = null, &$flags)
{
    if ($value !== null) {
        $field['val'] = $value;
    }
    if (!isset($field['val']) || $field['val'] == '') {
        $field['val'] = 'default';
    }
    if ($flags['inherit'] && isset($field['options']) && is_array($field['options'])) {
        $field['options'] = themerex_array_merge(array('default' => 'Inherit'), $field['options']);
    }
    if (isset($flags['radio_as_select']) && $flags['radio_as_select'] && $field['type'] == 'radio') {
        $field['type'] = 'select';
    }
    if (isset($flags['clear_shortname']) && $flags['clear_shortname'] && isset($field['id'])) {
        $field['id'] = get_option_name($field['id']);
    }
    $menu = '';
    $output = '';
    $name_hook = str_replace(" ", "-", preg_replace("[^A-Za-z0-9]", "", themerex_strtolower($field['name'])));
    if (isset($flags['heading_as_tabs']) && $flags['heading_as_tabs'] && $field['type'] == 'heading') {
        $field['type'] = 'group';
        $field['tab'] = $name_hook;
        $field['tabs'] = array($name_hook => $field['name']);
    }
    if (in_array($field['type'], array('group', 'groupend', 'heading')) && $flags['group_opened']) {
        $output .= '</div>';
        if (!$flags['tabs_opened']) {
            $output .= '</div>';
        } else {
            if (in_array($field['type'], array('groupend', 'heading'))) {
                $output .= '</div>';
                $flags['tabs_opened'] = false;
            }
        }
        $flags['group_opened'] = false;
    }
    if ($field['type'] == 'group') {
        $flags['group_opened'] = true;
        if (isset($field['tabs'])) {
            if (!isset($flags['heading_as_tabs']) || !$flags['heading_as_tabs']) {
                $output .= '<div class="opt_tabs"' . (isset($field['std']) ? ' id="' . $field['std'] . '"' : '') . '><ul>';
            }
            foreach ($field['tabs'] as $id => $title) {
                if (!isset($flags['heading_as_tabs']) || !$flags['heading_as_tabs']) {
                    $output .= '<li id="tab_' . $id . '"><a href="#content_' . $id . '">' . $title . '</a></li>';
                } else {
                    $menu .= '<li id="tab_' . $id . '"><a href="#content_' . $id . '">' . $title . '</a></li>';
                }
            }
            if (!isset($flags['heading_as_tabs']) || !$flags['heading_as_tabs']) {
                $output .= '</ul>';
            }
            $flags['tabs_opened'] = true;
        }
        if (isset($field['tab'])) {
            $output .= '<div class="opt_group opt_content" id="content_' . $field['tab'] . '">';
        } else {
            $output .= '<div class="opt_group' . (isset($field['tabs']) ? ' opt_tabs' : '') . '"' . (isset($field['std']) ? ' id="' . $field['std'] . '"' : '') . '>';
            $output .= '<h3 class="toggle">' . $field['name'] . '</h3><div class="opt_content' . (isset($field['closed']) && $field['closed'] ? ' closed' : '') . '">';
        }
    }
    if (!in_array($field['type'], array("heading", "hidden", "group", "groupend"))) {
        $class = '';
        if (isset($field['class'])) {
            $class = $field['class'];
        }
        $output .= '<div class="section section-' . str_replace(array('list', 'range'), array('select', 'select'), $field['type']) . ' ' . $class . '">' . "\n";
        $output .= '<h3 class="heading">' . $field['name'] . '</h3>' . "\n";
        $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
    }
    if (isset($field['enable'])) {
        $tmp = explode('|', $field['val']);
        $field['val'] = $tmp[0];
        if (isset($tmp[1])) {
            $field['enable'] = $tmp[1];
        }
    }
    switch ($field['type']) {
        case 'hidden':
            $output .= '<input class="of-input" name="' . $field['id'] . '" id="' . $field['id'] . '" type="' . $field['type'] . '" value="' . htmlspecialchars($field['val'] == 'default' ? '' : $field['val']) . '" />';
            break;
        case 'text':
            $inc = isset($field['increment']) && $field['increment'];
            if ($inc) {
                $arr = explode(',', $field['val']);
                $output .= '<div class="of-increment-area">';
            } else {
                $arr = array($field['val']);
            }
            for ($i = 0; $i < count($arr); $i++) {
                $sb = explode('|', $arr[$i]);
                if (count($sb) == 1) {
                    $sb[1] = $i + 1;
                }
                $output .= ($inc ? '<div class="of-increment-item"><input type="hidden" name="' . $field['id'] . '_numbers[]" value="' . $sb[1] . '" />' : '') . '<input class="of-input' . ($inc ? ' of-incremented' : '') . '" name="' . $field['id'] . ($inc ? '[]' : '') . '" id="' . $field['id'] . '" type="' . $field['type'] . '" value="' . htmlspecialchars($sb[0] == 'default' ? '' : $sb[0]) . '" />' . ($inc ? '<a href="#" class="of-increment-button of-increment-del">-</a></div>' : '');
            }
            if ($inc) {
                $output .= '</div><a href="#" class="of-increment-button of-increment-add">' . __('+ Add item', 'themerex') . '</a>';
            }
            break;
        case 'textarea':
            $cols = isset($field['cols']) && $field['cols'] > 10 ? $field['cols'] : '40';
            $rows = isset($field['rows']) && $field['rows'] > 1 ? $field['rows'] : '8';
            $output .= '<textarea class="of-input" name="' . $field['id'] . '" id="' . $field['id'] . '" cols="' . $cols . '" rows="' . $rows . '">' . htmlspecialchars($field['val'] == 'default' ? '' : $field['val']) . '</textarea>';
            break;
        case 'select':
            $multiple = isset($field['multiple']) && $field['multiple'];
            $output .= '<select class="of-input" name="' . $field['id'] . ($multiple ? '[]' : '') . '" id="' . $field['id'] . '"' . (isset($field['size']) ? ' size="' . $field['size'] . '"' : '') . ($multiple ? ' multiple="multiple"' : '') . '>';
            foreach ($field['options'] as $k => $option) {
                if (is_array($option)) {
                    $title = isset($option['name']) ? $option['name'] : (isset($option['title']) ? $option['title'] : $k);
                } else {
                    $title = $option;
                }
                $output .= '<option' . ($multiple ? in_array($k, explode(',', $field['val'])) : $field['val'] == $k ? ' selected="selected"' : '') . ' value="' . $k . '">' . htmlspecialchars($title) . '</option>';
            }
            $output .= '</select>';
            break;
        case 'checklist':
            $multiple = isset($field['multiple']) && $field['multiple'];
            $i = 0;
            $id = $field['id'];
            $output .= '<ul class="checklist">';
            foreach ($field['options'] as $k => $val) {
                $i++;
                $output .= '<li>';
                $output .= '<input type="' . ($multiple ? 'checkbox' : 'radio') . '" value="' . $k . '" name="' . $id . ($multiple ? '[]' : '') . '" id="' . $id . $i . '"' . (in_array($k, explode(',', $field['val'])) ? ' checked="checked"' : '') . '><label for="' . $id . $i . '">' . $val . '</label>';
                $output .= '</li>';
            }
            $output .= '</ul>';
            break;
        case 'list':
            $output .= '<select class="of-input" name="' . $field['id'] . '" id="' . $field['id'] . '">';
            foreach ($field['options'] as $option) {
                $output .= '<option' . ($field['val'] == $option ? ' selected="selected"' : '') . ' value="' . $option . '">' . htmlspecialchars($option) . '</option>';
            }
            $output .= '</select>';
            break;
        case 'range':
            $output .= '<select class="of-input" name="' . $field['id'] . '" id="' . $field['id'] . '">';
            $output .= '<option value="default">Inherit</option>';
            for ($i = $field['from']; $i <= $field['to']; $i++) {
                $output .= '<option value="' . $i . '" ' . ($field['val'] == $i ? ' selected="selected"' : '') . '>' . $i . '</option>';
            }
            $output .= '</select>';
            break;
        case 'fontsize':
            $output .= '<select class="of-typography of-typography-size" name="' . $field['id'] . '" id="' . $field['id'] . '_size">';
            for ($i = 9; $i < 71; $i++) {
                $output .= '<option value="' . $i . '" ' . ($field['val'] == $i ? ' selected="selected"' : '') . '>' . $i . 'px</option>';
            }
            $output .= '</select>';
            break;
        case "radio":
            foreach ($field['options'] as $key => $option) {
                $output .= '<input class="of-input of-radio" type="radio" name="' . $field['id'] . '" value="' . $key . '" ' . ($field['val'] == $key ? ' checked="checked"' : '') . ' id="' . $field['id'] . '_' . $key . '" /><label for="' . $field['id'] . '_' . $key . '">' . $option . '</label>' . (isset($field['style']) && $field['style'] == 'vertical' ? '<br />' : '');
            }
            break;
        case "checkbox":
            $output .= '<input type="checkbox" class="checkbox of-input" name="' . $field['id'] . '" id="' . $field['id'] . '" value="true" ' . ($field['val'] == 'true' ? ' checked="checked"' : '') . ' /><label for="' . $field['id'] . '">' . $field['name'] . '</label>';
            break;
        case "upload":
        case "upload_min":
        case "mediamanager":
            $upload = $field['val'] == 'default' ? '' : $field['val'];
            if (!empty($upload)) {
                $hide = '';
            } else {
                $hide = 'hide';
            }
            $output .= '<input class="of-input" name="' . $field['id'] . '" id="' . $field['id'] . '_upload" value="' . $upload . '" type="' . ($field['type'] == 'upload_min' ? 'hidden' : 'text') . '" />' . '<div class="upload_button_div">' . '<span class="button image_' . ($field['type'] == 'mediamanager' ? 'media' : 'upload') . '_button" id="' . $field['id'] . '"' . ($field['type'] == 'mediamanager' ? ' data-choose="' . (isset($field['multiple']) && $field['multiple'] ? __('Choose Images', 'themerex') : __('Choose Image', 'themerex')) . '"' . ' data-update="' . (isset($field['multiple']) && $field['multiple'] ? __('Add to Gallery', 'themerex') : __('Choose Image', 'themerex')) . '"' . '	data-multiple="' . (isset($field['multiple']) && $field['multiple'] ? 'true' : 'false') . '"' . ' data-linked-field="' . $field['id'] . '_upload"' : '') . '>' . __('Upload Image', 'themerex') . '</span>' . '<span class="button image_reset_button ' . $hide . '" id="reset_' . $field['id'] . '"' . (empty($upload) ? ' style="display:none;"' : '') . '>' . __('Remove', 'themerex') . '</span>' . '</div>' . "\n";
            //			. '<div class="clear"></div>' . "\n";
            if (!empty($upload)) {
                $output .= '<a class="of-uploaded-image" target="_blank" href="' . $upload . '">';
                $ext = pathinfo($upload, PATHINFO_EXTENSION);
                if (in_array(themerex_strtolower($ext), array('jpg', 'png', 'gif'))) {
                    $output .= '<img class="of-option-image" id="image_' . $field['id'] . '" src="' . $upload . '" alt="" />';
                } else {
                    $fname = pathinfo($upload, PATHINFO_BASENAME);
                    $output .= '<span id="image_' . $field['id'] . '">' . $fname . '</span>';
                }
                $output .= '</a>';
                $output .= '<div class="clear"></div>' . "\n";
            }
            break;
        case "color":
            $output .= '<input class="of-color colorSelector" name="' . $field['id'] . '" id="' . $field['id'] . '" type="text" value="' . ($field['val'] == 'default' ? '' : $field['val']) . '" />';
            break;
        case "images":
            $output .= '<input type="hidden" value="' . $field['val'] . '" name="' . $field['id'] . '" />';
            $i = 0;
            foreach ($field['options'] as $key => $option) {
                $i++;
                $selected = '';
                if ($field['val'] == $key || $i == 1 && $field['val'] == '') {
                    $selected = 'of-radio-img-selected';
                }
                $output .= '<span>';
                if ($key == 'default') {
                    $option = get_template_directory_uri() . '/images/spacer.png';
                }
                $output .= '<img src="' . $option . '" data-icon="' . $key . '" alt="" class="of-radio-img-img ' . $selected . '" />';
                $output .= '</span>';
            }
            break;
        case "icons":
            $i = 0;
            if (isset($field['css']) && $field['css'] != '' && file_exists($field['css'])) {
                $field['options'] = parseIconsClasses($field['css']);
            }
            $output .= '</div>';
            $output .= '<input type="hidden" value="' . $field['val'] . '" name="' . $field['id'] . '" />';
            foreach ($field['options'] as $option) {
                $i++;
                $selected = '';
                if ($field['val'] == $option || $i == 1 && $field['val'] == '') {
                    $selected = 'of-radio-icon-selected';
                }
                $output .= '<span>';
                $output .= '<span class="of-radio-icon-icon ' . $option . ' ' . $selected . '" data-icon="' . $option . '"></span>';
                $output .= '</span>';
            }
            $output .= '<div>';
            break;
        case 'socials':
            $arr = explode(',', $field['val']);
            $output .= '<div class="of-increment-area of-socials-area">';
            for ($i = 0; $i < count($arr); $i++) {
                $sb = explode('|', $arr[$i]);
                if (count($sb) == 1) {
                    $sb[1] = $i + 1;
                }
                if (count($sb) == 2) {
                    $sb[2] = '';
                }
                $j = 0;
                $icons = '';
                $button = '';
                foreach ($field['options'] as $k => $option) {
                    $j++;
                    $selected = '';
                    if ($sb[2] == $k || $j == 1 && $sb[2] == '') {
                        $selected = 'of-radio-img-selected';
                        $button = $option;
                    }
                    $icons .= '<span>';
                    //$output .= '<span class="of-radio-icon-icon '. $option . ' ' . $selected .'" onClick="document.getElementById(\'of-radio-icon-'. $field['id'] . $j.'\').checked = true;"></span>';
                    $icons .= '<img src="' . $option . '" data-icon="' . $k . '" alt="" class="of-radio-img-img ' . $selected . '" />';
                    $icons .= '</span>';
                }
                $output .= '<div class="of-increment-item"><input type="hidden" name="' . $field['id'] . '_numbers[]" value="' . $sb[1] . '" />' . '<input class="of-input of-incremented" name="' . $field['id'] . '[]" id="' . $field['id'] . '" type="text" value="' . htmlspecialchars($sb[0] == 'default' ? '' : $sb[0]) . '" />' . '<a href="#" class="of-socials-button"><img src="' . $button . '" alt="" /></a>' . '<a href="#" class="of-increment-button of-increment-del">-</a>' . '<div class="of-socials-icons">' . '<input type="hidden" value="' . $sb[2] . '" name="' . $field['id'] . '_icons[]" />' . $icons . '</div></div>';
            }
            $output .= '</div><a href="#" class="of-increment-button of-increment-add">' . __('+ Add item', 'themerex') . '</a>';
            break;
        case "info":
            $default = $field['std'];
            $output .= '<div class="info">' . $default . '</div>';
            break;
        case "heading":
            if ($flags['heading_opened']) {
                $output .= '</div>' . "\n";
            }
            $jquery_click_hook = "of-option-" . $name_hook;
            $menu .= '<li><a title="' . $field['name'] . '" href="#' . $jquery_click_hook . '">' . $field['name'] . '</a></li>';
            $output .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . $field['name'] . '</h2>' . "\n";
            $flags['heading_opened'] = true;
            break;
        default:
            if (function_exists('show_custom_field')) {
                $output .= show_custom_field($field, $field['val']);
            }
    }
    if (!in_array($field['type'], array("heading", "hidden", "group", "groupend"))) {
        //$output .= $field['type']!='checklist' ? '<br/>' : '';
        if (!isset($field['desc'])) {
            $descr = '';
        } else {
            $descr = $field['desc'];
        }
        if (isset($field['enable'])) {
            $output .= '<input type="checkbox" class="checkbox of-enable of-input" name="' . $field['id'] . '_enable" id="' . $field['id'] . '_enable" value="1" ' . ($field['enable'] == '1' ? ' checked="checked"' : '') . ' />';
        }
        $output .= '</div><div class="explain">' . $descr . '</div>' . "\n";
        $output .= '<div class="clear"> </div></div></div>' . "\n";
    }
    return array($output, $menu);
}