예제 #1
0
/**
 * Generates admin form
 */
function get_admin_form($menu_slug = null)
{
    $options = get_admin_options();
    $form = '';
    if ($_REQUEST['saved']) {
        $form .= '<div class="updated settings-error" id="setting-error-settings_updated">';
        $form .= '<p><strong>Settings saved.</strong></p>';
        $form .= '</div>';
    }
    // If menu_slug is empty return empty form
    if (!$menu_slug) {
        return 'Empty form';
    }
    // Start the form
    $form .= '<form method="post" action="?page=' . $_GET['page'] . '&slug=' . $menu_slug . '">';
    // Open table
    $form .= '<div class="theme-admin">';
    if (!is_array($options[$menu_slug])) {
        return;
    }
    //echo "<pre>" . print_r($options) . "</pre>";
    // Cycle over the all form options
    foreach ($options[$menu_slug] as $key => $value) {
        $opt = get_option($key, "OptionWasNotSet");
        if ($opt != "OptionWasNotSet") {
            $option_value = stripslashes(get_option($key));
        } elseif (!empty($value['default'])) {
            $option_value = $value['default'];
        } else {
            $option_value = '';
        }
        switch ($value['type']) {
            case 'box_start':
                $form .= '<div class="theme-admin-box">';
                $form .= '<div class="theme-admin-head">';
                $form .= '<div class="expander"><div class="expander-wrap">Open</div></div>';
                $form .= '<h3>' . $value['name'] . '</h3>';
                // Submit form
                $form .= '<p class="submit">';
                $form .= '<input type="hidden" name="action" value="save" />';
                $form .= '<input name="save" type="submit" value="Save changes" class="button-primary"/>';
                $form .= '</p>';
                if ($value['show_weight']) {
                    $form .= '<p class="weight">Order: <input type="text" id="' . $key . '" name="' . $key . '" value="' . $option_value . '"></p>';
                }
                $form .= '</div>';
                $form .= '<div class="theme-admin-content">';
                $has_box = true;
                break;
            case 'box_end':
                $form .= '</div>';
                $form .= '</div>';
                break;
            case 'header':
                $form .= '<h4>' . $value['name'] . '</h4>';
                break;
                // Description
            // Description
            case 'description':
                $form .= '<div class="theme-admin-row theme-admin-description clearfix">';
                $form .= '    <div class="theme-admin-row-input">' . $value['name'] . '</div>';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Textfield
            // Textfield
            case 'textfield':
                $form .= '<div class="theme-admin-row theme-admin-textfield clearfix">';
                $form .= '    <div class="theme-admin-row-title"><label for="' . $key . '">' . $value['name'] . '</label></div>';
                $form .= '    <div class="theme-admin-row-input">';
                $form .= '        <input type="text" class="regular-text ' . $value['class'] . '" value="' . htmlspecialchars($option_value, ENT_QUOTES, 'UTF-8') . '" id="' . $key . '" name="' . $key . '" />';
                $form .= '        <span class="description">&nbsp;&nbsp;' . $value['desc'] . '</span>';
                $form .= '    </div><!-- /.theme-admin-row-input -->';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Image URL
            // Image URL
            case 'image_url':
                $form .= '<div class="theme-admin-row theme-admin-textfield clearfix">';
                $form .= '    <div class="theme-admin-row-title"><label for="' . $key . '">' . $value['name'] . '</label></div>';
                $form .= '    <div class="theme-admin-row-input">';
                $form .= '        <input type="text" class="regular-image ' . $value['class'] . '" value="' . htmlspecialchars($option_value, ENT_QUOTES, 'UTF-8') . '" id="' . $key . '" name="' . $key . '" />';
                $form .= '        <input type="button" value="Select Image" class="media-select" id="' . $key . '_selectMedia" name="' . $key . '_button" />';
                $form .= '        <span class="description">&nbsp;&nbsp;' . $value['desc'] . '</span>';
                $form .= '    </div><!-- /.theme-admin-row-input -->';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Textarea
            // Textarea
            case 'textarea':
                $form .= '<div class="theme-admin-row theme-admin-textarea clearfix">';
                $form .= '    <div class="theme-admin-row-title"><label for="' . $key . '">' . $value['name'] . '</label></div>';
                $form .= '    <div class="theme-admin-row-input">';
                $form .= '        <textarea cols="40" rows="4" class="large-text ' . $value['class'] . '" id="' . $key . '" name="' . $key . '">' . $option_value . '</textarea>';
                $form .= '        <span class="description">' . $value['desc'] . '</span>';
                $form .= '    </div><!-- /.theme-admin-row-input -->';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Checkbox
            // Checkbox
            case 'checkbox':
                $form .= '<div class="theme-admin-row theme-admin-checkbox clearfix">';
                $form .= '    <div class="theme-admin-row-title">' . $value['name'] . '</div>';
                $form .= '    <div class="theme-admin-row-input"><fieldset><label for="' . $key . '">';
                if ($option_value == '1') {
                    $form .= '<input type="checkbox" name="' . $key . '" id="' . $key . '" value="1" checked="checked" />';
                } else {
                    $form .= '<input type="checkbox" name="' . $key . '" id="' . $key . '" value="1" />';
                }
                unset($option_value);
                $form .= '<span class="description">' . $value['desc'] . '</span>';
                $form .= '</label></fieldset></div>';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Select
            // Select
            case 'select':
                $form .= '<div class="theme-admin-row clearfix">';
                $form .= '    <div class="theme-admin-row-title"><label for="' . $key . '">' . $value['name'] . '</label></div>';
                $form .= '    <div class="theme-admin-row-input">';
                $form .= '        <select name="' . $key . '">';
                foreach ($value['options'] as $option_key => $name) {
                    if ($option_value == $option_key) {
                        $form .= '<option value="' . $option_key . '" selected="selected">' . $name . '</option>';
                    } else {
                        $form .= '<option value="' . $option_key . '">' . $name . '</option>';
                    }
                }
                $form .= '</select>';
                $form .= '<span class="description">' . $value['desc'] . '</span>';
                $form .= '    </div><!-- /.theme-admin-row-input -->';
                $form .= '</div><!-- /.theme-admin-row -->';
                break;
                // Clone footer picture
            // Clone footer picture
            case 'clone_picture':
                $form .= '		<!-- sheepIt Form Pictures -->';
                $form .= '		<div id="sheepItFormPictures">';
                $form .= '			<input type="hidden" id="' . $key . '" name="' . $key . '" value="" />';
                $form .= '			<div id="inputJSON" style="display:none;"><!--' . $option_value . '--></div>';
                $form .= '			<script type="text/template" class="inputJSON">' . $option_value . '</script>';
                // default values
                $defValues = get_option('footer_gallery_default_values', 'yes');
                $form .= '			<script type="text/template" class="initValues">' . $defValues . '</script>';
                $form .= '			<!-- Form template-->';
                $form .= '			<div id="sheepItFormPictures_template" class="sheepItFormPictures_template">';
                $form .= '				<input type="hidden" id="index_number" name="index_number" value="#index#" />';
                $form .= '				<h4>Image</h4>';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Image Source URL</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-image ' . $value['class'] . '" value="" id="image_src_#index#" name="image_src_#index#" />';
                $form .= '        				<input type="button" value="Select Image" class="media-select" id="image_src_#index#_selectMedia" name="image_src_#index#_selectMedia" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Link</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-text ' . $value['class'] . '" value="" id="image_link_#index#" name="image_link_#index#" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Description</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-text ' . $value['class'] . '" value="" id="image_desc_#index#" name="image_desc_#index#" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '			  </div><!-- /Form template-->';
                $form .= '			  <div id="sheepItFormPictures_noforms_template" class="theme-admin-row clearfix">No panels</div>';
                $form .= '			<div class="theme-admin-row clearfix">';
                $form .= '				<!-- Controls -->';
                $form .= '			  	<div id="sheepItFormPictures_controls">';
                $form .= '					<div id="sheepItFormPictures_add" ><span><a class="button-primary">Add picture</a></span></div>';
                $form .= '					<div id="sheepItFormPictures_remove_last"><span><a class="button-primary">Remove picture</a></span></div>';
                $form .= '			  	</div><!-- /Controls -->';
                $form .= '			</div><!-- /admin-row clearfix -->';
                $form .= '		</div><!-- /sheepIt Form -->';
                break;
                // Clone slider home page
            // Clone slider home page
            case 'clone_home_slider':
                $form .= '		<!-- sheepIt Form Home Slider -->';
                $form .= '		<div id="sheepItFormHomeSlider">';
                $form .= '			<input type="hidden" id="' . $key . '" name="' . $key . '" value="" />';
                $form .= '			<div id="inputJSON" style="display:none;"><!--' . $option_value . '--></div>';
                $form .= '			<script type="text/template" class="inputJSON">' . $option_value . '</script>';
                // default values
                $defValues = get_option('home_slider_default_values', 'yes');
                $form .= '			<script type="text/template" class="initValues">' . $defValues . '</script>';
                $form .= '			<!-- Form template-->';
                $form .= '			<div id="sheepItFormHomeSlider_template" class="sheepItFormHomeSlider_template">';
                $form .= '				<input type="hidden" id="index_number_home_slider" name="index_number_home_slider" value="#index#" />';
                $form .= '				<h4>Image</h4>';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Center image URL</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-image ' . $value['class'] . '" value="" id="img_src_#index#" name="img_src_#index#" />';
                $form .= '        				<input type="button" value="Select Image" class="media-select" id="img_src_#index#_selectMedia" name="img_src_#index#_selectMedia" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Background image URL</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-image ' . $value['class'] . '" value="" id="img_background_#index#" name="img_background_#index#" />';
                $form .= '        				<input type="button" value="Select Image" class="media-select" id="img_background_#index#_selectMedia" name="img_background_#index#_selectMedia" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Link (center image)</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-text ' . $value['class'] . '" value="" id="img_link_#index#" name="img_link_#index#" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '				<div class="theme-admin-row clearfix">';
                $form .= '					<div class="theme-admin-row-title">Description</div>';
                $form .= '					<div class="theme-admin-row-input">';
                $form .= '        				<input type="text" class="regular-text ' . $value['class'] . '" value="" id="img_desc_#index#" name="img_desc_#index#" />';
                $form .= '					</div><!-- /theme-admin-row-input -->';
                $form .= '				</div><!-- /admin-row clearfix -->';
                $form .= '			  </div><!-- /Form template-->';
                $form .= '			  <div id="sheepItFormHomeSlider_noforms_template" class="theme-admin-row clearfix">No panels</div>';
                $form .= '			<div class="theme-admin-row clearfix">';
                $form .= '				<!-- Controls -->';
                $form .= '			  	<div id="sheepItFormHomeSlider_controls">';
                $form .= '					<div id="sheepItFormHomeSlider_add" ><span><a class="button-primary">Add picture</a></span></div>';
                $form .= '					<div id="sheepItFormHomeSlider_remove_last"><span><a class="button-primary">Remove picture</a></span></div>';
                $form .= '			  	</div><!-- /Controls -->';
                $form .= '			</div><!-- /admin-row clearfix -->';
                $form .= '		</div><!-- /sheepIt Form -->';
                break;
        }
    }
    // Close table
    $form .= '</div><!-- /.theme-admin -->';
    // Submit form
    if (!$has_box) {
        $form .= '<p class="submit">';
        $form .= '<input type="hidden" name="action" value="save" />';
        $form .= '<input name="save" type="submit" value="Save changes" class="button-primary"/>';
        $form .= '</p>';
    }
    // Close the form
    $form .= '</form>';
    return $form;
}
예제 #2
0
function theme_admin_menu()
{
    $options = get_admin_options();
    if ($_GET['page'] == "Fullscreen") {
        if ('save' == $_REQUEST['action']) {
            foreach ($options[$_REQUEST['slug']] as $key => $value) {
                if ($key == "home_page_slider_images") {
                    // templates numbers from hidden input
                    $numbers = $_REQUEST[$key];
                    $numArray = explode(",", $numbers);
                    $images = array();
                    for ($i = 0; $i < count($numArray); $i++) {
                        $inputSrc = "img_src_" . $numArray[$i];
                        $inputLink = "img_link_" . $numArray[$i];
                        $inputDesc = "img_desc_" . $numArray[$i];
                        $inputBackgroundSrc = "img_background_" . $numArray[$i];
                        $images[$i] = array($_REQUEST[$inputSrc], $_REQUEST[$inputLink], $_REQUEST[$inputDesc], $_REQUEST[$inputBackgroundSrc]);
                    }
                    update_option($key, json_encode($images));
                    // disable default values
                    update_option('home_slider_default_values', 'no');
                } elseif ($key == "footer_clone_picture") {
                    // templates numbers from hidden input
                    $numbers = $_REQUEST[$key];
                    $numArray = explode(",", $numbers);
                    $images = array();
                    for ($i = 0; $i < count($numArray); $i++) {
                        $inputSrc = "image_src_" . $numArray[$i];
                        $inputLink = "image_link_" . $numArray[$i];
                        $inputDesc = "image_desc_" . $numArray[$i];
                        $images[$i] = array($_REQUEST[$inputSrc], $_REQUEST[$inputLink], $_REQUEST[$inputDesc]);
                    }
                    update_option($key, json_encode($images));
                    // disable default values
                    update_option('footer_gallery_default_values', 'no');
                } elseif (isset($_REQUEST[$key])) {
                    update_option($key, $_REQUEST[$key]);
                } else {
                    delete_option($key);
                }
            }
            header("Location: admin.php?page=" . $_GET['page'] . "&saved=true");
            die;
        }
    }
    add_object_page(FULL_NAME, SHORT_NAME, 'administrator', SHORT_NAME, 'theme_admin');
}
예제 #3
0
                }
            }
        }
    } elseif (is_string($meta_name)) {
        $metas = get_post_meta($post_id, '_post_metas_' . $meta_name, true);
    }
    return $metas;
}
/*
 * 前台后台都载入的钩子
 * 注意:钩子中全部使用class来实现,以防止和其他函数冲突
 */
global $admin_options;
// 因为是在action/filter等钩子中使用,所以必须要声明为global,一旦声明为global,在主题中也可以使用。这个地方也有个技巧,要在主题文件functions.php中早点载入admin-options.php,这样就可以在主题中全局使用$admin_options了。
global $admin_options_config;
$admin_options = get_admin_options();
include dirname(__FILE__) . "/controller.php";
include dirname(__FILE__) . "/hook.php";
// 设定初始值
if (isset($admin_options_config['defaults']) && !empty($admin_options_config['defaults'])) {
    foreach ($admin_options_config['defaults'] as $key => $value) {
        if (!isset($admin_options[$key])) {
            $admin_options[$key] = $value;
        }
        // 不能在为空的时候也这样设定,因为有可能站长故意设置为空
    }
}
/*
 * 后台视图
 */
class AdminOptionsView