从gitee代码库中初始化项目。

This commit is contained in:
2022-01-07 11:15:42 +08:00
parent b46e3d988f
commit a826b26bee
184 changed files with 30423 additions and 2 deletions
+109
View File
@@ -0,0 +1,109 @@
<?php
/**
* Options Framework
*
* @package Options Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*
* @wordpress-plugin
* Plugin Name: Options Framework
* Plugin URI: http://wptheming.com
* Description: A framework for building theme options.
* Version: 1.9.1
* Author: Devin Price
* Author URI: http://wptheming.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: optionsframework
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Don't load if optionsframework_init is already defined
if (is_admin() && !function_exists('optionsframework_init')):
function optionsframework_init()
{
// If user can't edit theme options, exit
if (!current_user_can('edit_theme_options')) {
return;
}
require get_template_directory() . '/inc/theme-options.php';
// Loads the required Options Framework classes.
require plugin_dir_path(__FILE__) . 'includes/class-options-framework.php';
require plugin_dir_path(__FILE__) . 'includes/class-options-framework-admin.php';
require plugin_dir_path(__FILE__) . 'includes/class-options-interface.php';
require plugin_dir_path(__FILE__) . 'includes/class-options-media-uploader.php';
require plugin_dir_path(__FILE__) . 'includes/class-options-sanitization.php';
// Instantiate the options page.
$options_framework_admin = new Options_Framework_Admin;
$options_framework_admin->init();
// Instantiate the media uploader class
$options_framework_media_uploader = new Options_Framework_Media_Uploader;
$options_framework_media_uploader->init();
}
add_action('init', 'optionsframework_init', 20);
endif;
/**
* Helper function to return the theme option value.
* If no value has been saved, it returns $default.
* Needed because options are saved as serialized strings.
*
* Not in a class to support backwards compatibility in themes.
*/
if (!function_exists('kratos_option')):
function kratos_option($name, $default = false)
{
$option_name = 'kratos';
// Get option settings from database
$options = get_option($option_name);
// Return specific option
if (isset($options[$name])) {
return $options[$name];
}
return $default;
}
endif;
add_action('admin_init', 'optionscheck_change_santiziation', 100);
function optionscheck_change_santiziation()
{
remove_filter('of_sanitize_textarea', 'of_sanitize_textarea');
add_filter('of_sanitize_textarea', 'custom_sanitize_textarea');
}
function custom_sanitize_textarea($input)
{
global $allowedposttags;
$custom_allowedtags["embed"] = array(
"src" => array(),
"type" => array(),
"allowfullscreen" => array(),
"allowscriptaccess" => array(),
"height" => array(),
"width" => array(),
);
$custom_allowedtags["script"] = array("type" => array(), "src" => array());
$custom_allowedtags = array_merge($custom_allowedtags, $allowedposttags);
$output = wp_kses($input, $custom_allowedtags);
return $output;
}
@@ -0,0 +1,310 @@
#optionsframework {
max-width: 855px;
background: #fff;
}
#optionsframework h3 {
margin: 0;
padding: 12px 10px;
border-bottom: 1px solid #ddd;
background-color: #f1f1f1;
cursor: default;
}
#optionsframework p {
margin-bottom: 0;
padding-bottom: 10px;
}
#optionsframework .section {
padding: 10px 10px 0;
}
#optionsframework .group {
padding-bottom: 40px;
}
#optionsframework .section .controls {
float: left;
padding-right: 2%;
width: 54%;
min-width: 350px;
}
#optionsframework .section .explain {
float: left;
max-width: 38%;
color: #777;
font-size: 12px;
line-height: 16px;
}
#optionsframework .section-checkbox .controls {
width: 98%;
}
#optionsframework .section-checkbox .explain {
max-width: 94%;
}
#optionsframework .controls input[type="text"],
#optionsframework .controls input[type="password"] {
width: 100%;
}
#optionsframework .controls input[type="text"].wp-color-picker {
width: 65px;
}
#optionsframework .controls select,
#optionsframework .controls textarea {
margin-bottom: 10px;
width: 100%;
}
#optionsframework .section-radio label,
#optionsframework .section-multicheck label {
float: left;
margin-bottom: 5px;
max-width: 90%;
line-height: 16px;
}
#optionsframework input.checkbox,
#optionsframework input.of-radio {
float: left;
clear: both;
margin: 0 10px 5px 0;
}
#optionsframework .section-typography .controls {
float: none;
width: auto;
}
#optionsframework .section-typography .explain {
float: none;
width: auto;
}
#optionsframework .controls .of-typography-size {
float: left;
width: 80px;
}
#optionsframework .controls .of-typography-unit {
float: left;
margin-left: 5px;
width: 50px;
}
#optionsframework .controls .of-typography-face {
float: left;
margin-left: 5px;
width: 100px;
}
#optionsframework .controls .of-typography-style {
float: left;
margin-right: 5px;
margin-left: 5px;
width: 80px;
}
#optionsframework .section-typography .wp-picker-container {
margin-top: 2px;
}
#optionsframework .of-background-properties {
clear: both;
margin-top: 18px;
}
#optionsframework .controls .of-background-repeat {
float: left;
margin-right: 5px;
width: 125px;
}
#optionsframework .controls .of-background-position {
float: left;
margin-right: 5px;
width: 125px;
}
#optionsframework .controls .of-background-attachment {
float: left;
margin-right: 5px;
width: 125px;
}
#optionsframework .section-background .wp-picker-container {
margin-bottom: 10px;
}
#optionsframework .controls .of-radio-img-img {
float: left;
display: none;
margin: 0 5px 10px 0;
border: 3px solid #f9f9f9;
cursor: pointer;
}
#optionsframework .controls .of-radio-img-selected {
border: 3px solid #ccc;
}
#optionsframework .controls .of-radio-img-img:hover {
opacity: 0.8;
}
#optionsframework .controls .of-border-width {
float: left;
width: 80px;
}
#optionsframework .controls .of-border-style {
float: left;
width: 120px;
}
#optionsframework .hide {
display: none;
}
#optionsframework .of-option-image {
margin: 3px 0 18px 0;
max-width: 340px;
}
#optionsframework .mini .controls select,
#optionsframework .section .mini .controls {
width: 140px;
}
#optionsframework .mini .controls input,
#optionsframework .mini .controls {
width: 140px;
min-width: 140px;
}
#optionsframework .mini .explain {
max-width: 74%;
}
#optionsframework .section-info {
padding-bottom: 7px;
}
#optionsframework .controls input.upload {
width: 80%;
}
#optionsframework .screenshot {
position: relative;
float: left;
margin-top: 3px;
margin-left: 1px;
width: 344px;
}
#optionsframework .screenshot img {
float: left;
margin-bottom: 10px;
padding: 4px;
max-width: 334px;
border-color: #ccc #eee #eee #ccc;
border-style: solid;
border-width: 1px;
background: #fafafa;
}
#optionsframework .screenshot .remove-image {
position: absolute;
bottom: 4px;
left: -4px;
float: left;
display: block;
padding: 0;
width: 16px;
height: 16px;
border: medium none;
background: url("../images/ico-delete.png") no-repeat;
text-indent: -9999px;
}
#optionsframework .screenshot .no_image .file_link {
margin-left: 20px;
}
#optionsframework .screenshot .no_image .remove-button {
bottom: 0px;
}
#optionsframework .reset-button {
float: left;
cursor: pointer;
}
#optionsframework-submit {
padding: 7px 10px;
border-top: 1px solid #ddd;
background-color: #f1f1f1;
}
#optionsframework .button-primary {
float: right;
}
#optionsframework .section:after {
display: table;
content: "";
}
#optionsframework .section:after {
clear: both;
}
#optionsframework .about-content {
padding: 10px 20px;
}
#optionsframework .about-content img {
width: 100%;
height: auto;
}
#optionsframework .about-content h4 {
margin-top: 20px;
margin-bottom: 16px;
padding-bottom: 0.3em;
border-bottom: 1px solid #eaecef;
font-weight: 600;
font-size: 18px;
line-height: 1.25;
}
#optionsframework .about-content ul {
padding-left: 0;
list-style: none;
font-size: 15px;
}
#optionsframework .about-content ul li {
line-height: 25px;
}
#optionsframework .about-content .notices {
color: #727777;
font-size: 14px;
}
#optionsframework .about-content .tips {
color: #333333;
text-align: center;
font-size: 16px;
}
#optionsframework .about-content .tips b {
margin-left: 3px;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

@@ -0,0 +1,308 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Admin {
/**
* Page hook for the options screen
*
* @since 1.7.0
* @type string
*/
protected $options_screen = null;
/**
* Hook in the scripts and styles
*
* @since 1.7.0
*/
public function init() {
// Gets options to load
$options = & Options_Framework::_optionsframework_options();
// Checks if options are available
if ( $options ) {
// Add the options page and menu item.
add_action('admin_menu', array($this, 'add_top_options_page'));
add_action('admin_menu', array($this, 'add_sub_options_page'));
// Add the required scripts and styles
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Settings need to be registered after admin_init
add_action( 'admin_init', array( $this, 'settings_init' ) );
}
}
/**
* Registers the settings
*
* @since 1.7.0
*/
function settings_init() {
// Get the option name
$options_framework = new Options_Framework;
$name = $options_framework->get_option_name();
// Registers the settings fields and callback
register_setting( 'optionsframework', $name, array ( $this, 'validate_options' ) );
// Displays notice after options save
add_action( 'optionsframework_after_validate', array( $this, 'save_options_notice' ) );
add_action( 'optionsframework_after_sendmail', array( $this, 'send_mail_notice' ) );
}
public function add_top_options_page()
{
add_menu_page(
__('主题设置', 'kratos'),
__('主题设置', 'kratos'),
'manage_options',
'kratos_options',
'',
'dashicons-admin-generic',
99
);
}
public static function menu_settings()
{
$menu = array(
'parent_slug' => 'kratos_options',
'page_title' => __('主题设置', 'kratos'),
'menu_title' => __('主题设置', 'kratos'),
'capability' => 'manage_options',
'menu_slug' => 'kratos_options',
);
return $menu;
}
public function add_sub_options_page()
{
$menu = $this->menu_settings();
$this->options_screen = add_submenu_page(
$menu['parent_slug'],
$menu['page_title'],
$menu['menu_title'],
$menu['capability'],
$menu['menu_slug'],
array($this, 'options_page')
);
}
/**
* Loads the required stylesheets
*
* @since 1.7.0
*/
function enqueue_admin_styles( $hook ) {
if ( $this->options_screen != $hook )
return;
wp_enqueue_style( 'optionsframework', get_stylesheet_directory_uri() . '/inc/options-framework/css/optionsframework.css', array(), Options_Framework::VERSION );
wp_enqueue_style( 'wp-color-picker' );
}
/**
* Loads the required javascript
*
* @since 1.7.0
*/
function enqueue_admin_scripts( $hook ) {
if ( $this->options_screen != $hook )
return;
// Enqueue custom option panel JS
wp_enqueue_script(
'options-custom',
get_stylesheet_directory_uri() . '/inc/options-framework/js/options-custom.js',
array( 'jquery','wp-color-picker' ),
Options_Framework::VERSION
);
// Inline scripts from options-interface.php
add_action( 'admin_head', array( $this, 'of_admin_head' ) );
}
function of_admin_head() {
// Hook to add custom scripts
do_action( 'optionsframework_custom_scripts' );
}
/**
* Builds out the options panel.
*
* If we were using the Settings API as it was intended we would use
* do_settings_sections here. But as we don't want the settings wrapped in a table,
* we'll call our own custom optionsframework_fields. See options-interface.php
* for specifics on how each individual field is generated.
*
* Nonces are provided using the settings_fields()
*
* @since 1.7.0
*/
function options_page() { ?>
<div id="optionsframework-wrap" class="wrap">
<?php $menu = $this->menu_settings(); ?>
<h2><?php echo esc_html( $menu['page_title'] ); ?></h2>
<h2 class="nav-tab-wrapper">
<?php echo Options_Framework_Interface::optionsframework_tabs(); ?>
</h2>
<?php settings_errors( 'options-framework' ); ?>
<div id="optionsframework-metabox" class="metabox-holder">
<div id="optionsframework" class="postbox">
<form action="options.php" method="post">
<?php settings_fields( 'optionsframework' ); ?>
<?php Options_Framework_Interface::optionsframework_fields(); /* Settings */ ?>
<div id="optionsframework-submit">
<input type="submit" class="button-primary" name="update" value="<?php esc_attr_e( '保存配置', 'kratos' ); ?>" />
<input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e( '恢复默认', 'kratos' ); ?>" onclick="return confirm( '<?php print esc_js( __( '单击「确定」进行恢复,但所有的配置都将丢失!', 'kratos' ) ); ?>' );" />
<div class="clear"></div>
</div>
</form>
</div> <!-- / #container -->
</div>
<?php do_action( 'optionsframework_after' ); ?>
</div> <!-- / .wrap -->
<?php
}
/**
* Validate Options.
*
* This runs after the submit/reset button has been clicked and
* validates the inputs.
*
* @uses $_POST['reset'] to restore default options
*/
function validate_options( $input ) {
/*
* Restore Defaults.
*
* In the event that the user clicked the "Restore Defaults"
* button, the options defined in the theme's options.php
* file will be added to the option for the active theme.
*/
if ( isset( $_POST['reset'] ) ) {
add_settings_error( 'options-framework', 'restore_defaults', __( '恢复完成', 'kratos' ), 'updated fade' );
return $this->get_default_values();
}
/*
* Update Settings
*
* This used to check for $_POST['update'], but has been updated
* to be compatible with the theme customizer introduced in WordPress 3.4
*/
$clean = array();
$options = & Options_Framework::_optionsframework_options();
foreach ( $options as $option ) {
if ( ! isset( $option['id'] ) ) {
continue;
}
if ( ! isset( $option['type'] ) ) {
continue;
}
$id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) );
// Set checkbox to false if it wasn't sent in the $_POST
if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) {
$input[$id] = false;
}
// Set each item in the multicheck to false if it wasn't sent in the $_POST
if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) {
foreach ( $option['options'] as $key => $value ) {
$input[$id][$key] = false;
}
}
// For a value to be submitted to database it must pass through a sanitization filter
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
$clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option );
}
}
if ( isset( $_POST['sendmail'] ) ) {
wp_mail( get_bloginfo( 'admin_email' ) ,__('[测试]邮件服务配置成功', 'kratos'),__('恭喜您 SMTP 邮件服务配置成功!', 'kratos'));
do_action( 'optionsframework_after_sendmail', $clean );
return $clean;
} else {
do_action( 'optionsframework_after_validate', $clean );
return $clean;
}
}
/**
* Display message when options have been saved
*/
function save_options_notice() {
add_settings_error( 'options-framework', 'save_options', __( '保存成功', 'kratos' ), 'updated fade' );
}
function send_mail_notice() {
add_settings_error( 'options-framework', 'send_mail', __( '发送完成,请留意邮箱:' . get_bloginfo( 'admin_email' ), 'kratos' ), 'updated fade' );
}
/**
* Get the default values for all the theme options
*
* Get an array of all default values as set in
* options.php. The 'id','std' and 'type' keys need
* to be defined in the configuration array. In the
* event that these keys are not present the option
* will not be included in this function's output.
*
* @return array Re-keyed options configuration array.
*
*/
function get_default_values() {
$output = array();
$config = & Options_Framework::_optionsframework_options();
foreach ( (array) $config as $option ) {
if ( ! isset( $option['id'] ) ) {
continue;
}
if ( ! isset( $option['std'] ) ) {
continue;
}
if ( ! isset( $option['type'] ) ) {
continue;
}
if ( has_filter( 'of_sanitize_' . $option['type'] ) ) {
$output[$option['id']] = apply_filters( 'of_sanitize_' . $option['type'], $option['std'], $option );
}
}
return $output;
}
}
@@ -0,0 +1,75 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.7.0
* @type string
*/
const VERSION = '1.9.1';
/**
* Gets option name
*
* @since 1.9.0
*/
function get_option_name() {
$name = 'kratos';
return apply_filters( 'options_framework_option_name', $name );
}
/**
* Wrapper for optionsframework_options()
*
* Allows for manipulating or setting options via 'of_options' filter
* For example:
*
* <code>
* add_filter( 'of_options', function( $options ) {
* $options[] = array(
* 'name' => 'Input Text Mini',
* 'desc' => 'A mini text input field.',
* 'id' => 'example_text_mini',
* 'std' => 'Default',
* 'class' => 'mini',
* 'type' => 'text'
* );
*
* return $options;
* });
* </code>
*
* Also allows for setting options via a return statement in the
* options.php file. For example (in options.php):
*
* <code>
* return array(...);
* </code>
*
* @return array (by reference)
*/
static function &_optionsframework_options() {
static $options = null;
if ( !$options ) {
// Load options from options.php file (if it exists)
$location = apply_filters( 'options_framework_location', array( 'theme-options.php' ) );
$options = kratos_options();
}
return $options;
}
}
@@ -0,0 +1,259 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Interface
{
/**
* Generates the tabs that are used in the options menu
*/
public static function optionsframework_tabs()
{
$counter = 0;
$options = &Options_Framework::_optionsframework_options();
$menu = '';
foreach ($options as $value) {
// Heading for Navigation
if ($value['type'] == "heading") {
$counter++;
$class = '';
$class = !empty($value['id']) ? $value['id'] : $value['name'];
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class)) . '-tab';
$menu .= '<a id="options-group-' . $counter . '-tab" class="nav-tab ' . $class . '" title="' . esc_attr($value['name']) . '" href="' . esc_attr('#options-group-' . $counter) . '">' . esc_html($value['name']) . '</a>';
}
}
return $menu;
}
/**
* Generates the options fields that are used in the form.
*/
public static function optionsframework_fields()
{
global $allowedtags;
$options_framework = new Options_Framework;
$option_name = $options_framework->get_option_name();
$settings = get_option($option_name);
$options = &Options_Framework::_optionsframework_options();
$counter = 0;
$menu = '';
foreach ($options as $value) {
$val = '';
$select_value = '';
$output = '';
// Wrap all options
if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) {
// Keep all ids lowercase with no spaces
$value['id'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($value['id']));
$id = 'section-' . $value['id'];
$class = 'section';
if (isset($value['type'])) {
$class .= ' section-' . $value['type'];
}
if (isset($value['class'])) {
$class .= ' ' . $value['class'];
}
$output .= '<div id="' . esc_attr($id) . '" class="' . esc_attr($class) . '">' . "\n";
if (isset($value['name'])) {
$output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
}
if ($value['type'] != 'editor') {
$output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
} else {
$output .= '<div class="option">' . "\n" . '<div>' . "\n";
}
}
// Set default value to $val
if (isset($value['std'])) {
$val = $value['std'];
}
// If the option is already saved, override $val
if (($value['type'] != 'heading') && ($value['type'] != 'info') && ($value['type'] != "about")) {
if (isset($settings[($value['id'])])) {
$val = $settings[($value['id'])];
// Striping slashes of non-array options
if (!is_array($val)) {
$val = stripslashes($val);
}
}
}
// If there is a description save it for labels
$explain_value = '';
if (isset($value['desc'])) {
$explain_value = $value['desc'];
}
// Set the placeholder if one exists
$placeholder = '';
if (isset($value['placeholder'])) {
$placeholder = ' placeholder="' . esc_attr($value['placeholder']) . '"';
}
if (has_filter('optionsframework_' . $value['type'])) {
$output .= apply_filters('optionsframework_' . $value['type'], $option_name, $value, $val);
}
switch ($value['type']) {
// Basic text input
case 'text':
$output .= '<input id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="text" value="' . esc_attr($val) . '"' . $placeholder . ' />';
break;
// Password input
case 'password':
$output .= '<input id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="password" value="' . esc_attr($val) . '" />';
break;
// Textarea
case 'textarea':
$rows = '8';
if (isset($value['settings']['rows'])) {
$custom_rows = $value['settings']['rows'];
if (is_numeric($custom_rows)) {
$rows = $custom_rows;
}
}
$val = stripslashes($val);
$output .= '<textarea id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" rows="' . $rows . '"' . $placeholder . '>' . esc_textarea($val) . '</textarea>';
break;
// Select Box
case 'select':
$output .= '<select class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '">';
foreach ($value['options'] as $key => $option) {
$output .= '<option' . selected($val, $key, false) . ' value="' . esc_attr($key) . '">' . esc_html($option) . '</option>';
}
$output .= '</select>';
break;
// Radio Box
case "radio":
$name = $option_name . '[' . $value['id'] . ']';
foreach ($value['options'] as $key => $option) {
$id = $option_name . '-' . $value['id'] . '-' . $key;
$output .= '<input class="of-input of-radio" type="radio" name="' . esc_attr($name) . '" id="' . esc_attr($id) . '" value="' . esc_attr($key) . '" ' . checked($val, $key, false) . ' /><label for="' . esc_attr($id) . '">' . esc_html($option) . '</label>';
}
break;
// Image Selectors
case "images":
$name = $option_name . '[' . $value['id'] . ']';
foreach ($value['options'] as $key => $option) {
$selected = '';
if ($val != '' && ($val == $key)) {
$selected = ' of-radio-img-selected';
}
$output .= '<input type="radio" id="' . esc_attr($value['id'] . '_' . $key) . '" class="of-radio-img-radio" value="' . esc_attr($key) . '" name="' . esc_attr($name) . '" ' . checked($val, $key, false) . ' />';
$output .= '<div class="of-radio-img-label">' . esc_html($key) . '</div>';
$output .= '<img src="' . esc_url($option) . '" alt="' . $option . '" class="of-radio-img-img' . $selected . '" onclick="document.getElementById(\'' . esc_attr($value['id'] . '_' . $key) . '\').checked=true;" />';
}
break;
// Checkbox
case "checkbox":
$output .= '<input id="' . esc_attr($value['id']) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" ' . checked($val, 1, false) . ' />';
$output .= '<label class="explain" for="' . esc_attr($value['id']) . '">' . wp_kses($explain_value, $allowedtags) . '</label>';
break;
// Color picker
case "color":
$default_color = '';
if (isset($value['std'])) {
if ($val != $value['std']) {
$default_color = ' data-default-color="' . $value['std'] . '" ';
}
}
$output .= '<input name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '" class="of-color" type="text" value="' . esc_attr($val) . '"' . $default_color . ' />';
break;
// Uploader
case "upload":
$output .= Options_Framework_Media_Uploader::optionsframework_uploader($value['id'], $val, null);
break;
case "info":
$id = '';
$class = 'section';
if (isset($value['id'])) {
$id = 'id="' . esc_attr($value['id']) . '" ';
}
if (isset($value['type'])) {
$class .= ' section-' . $value['type'];
}
if (isset($value['class'])) {
$class .= ' ' . $value['class'];
}
$output .= '<div ' . $id . 'class="' . esc_attr($class) . '">' . "\n";
if (isset($value['name'])) {
$output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
}
if (isset($value['desc'])) {
$output .= $value['desc'] . "\n";
}
$output .= '</div>' . "\n";
break;
case "sendmail":
$output .= '<input type="submit" name="sendmail" class="button-secondary" value="' . __('测试邮件', 'kratos') . '">';
break;
// Heading for Navigation
case "heading":
$counter++;
if ($counter >= 2) {
$output .= '</div>' . "\n";
}
$class = '';
$class = !empty($value['id']) ? $value['id'] : $value['name'];
$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class));
$output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">';
$output .= '<h3>' . esc_html($value['name']) . '</h3>' . "\n";
break;
}
if (($value['type'] != "heading") && ($value['type'] != "info") && ($value['type'] != "about")) {
$output .= '</div>';
if (($value['type'] != "checkbox") && ($value['type'] != "editor")) {
$output .= '<div class="explain">' . wp_kses($explain_value, $allowedtags) . '</div>' . "\n";
}
$output .= '</div></div>' . "\n";
}
echo $output;
}
// Outputs closing div if there tabs
if (Options_Framework_Interface::optionsframework_tabs() != '') {
echo '</div>';
}
}
}
@@ -0,0 +1,122 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
class Options_Framework_Media_Uploader {
/**
* Initialize the media uploader class
*
* @since 1.7.0
*/
public function init() {
add_action( 'admin_enqueue_scripts', array( $this, 'optionsframework_media_scripts' ) );
}
/**
* Media Uploader Using the WordPress Media Library.
*
* Parameters:
*
* string $_id - A token to identify this field (the name).
* string $_value - The value of the field, if present.
* string $_desc - An optional description of the field.
*
*/
static function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) {
// Gets the unique option id
$options_framework = new Options_Framework;
$option_name = $options_framework->get_option_name();
$output = '';
$id = '';
$class = '';
$int = '';
$value = '';
$name = '';
$id = strip_tags( strtolower( $_id ) );
// If a value is passed and we don't have a stored value, use the value that's passed through.
if ( $_value != '' && $value == '' ) {
$value = $_value;
}
if ($_name != '') {
$name = $_name;
}
else {
$name = $option_name.'['.$id.']';
}
if ( $value ) {
$class = ' has-file';
}
$output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('没有选择任何文件', 'kratos') .'" />' . "\n";
if ( function_exists( 'wp_enqueue_media' ) ) {
if ( ( $value == '' ) ) {
$output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( '上传', 'kratos' ) . '" />' . "\n";
} else {
$output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( '删除', 'kratos' ) . '" />' . "\n";
}
} else {
$output .= '<p><i>' . __( '升级 WordPress 版本获得完整的媒体支持', 'kratos' ) . '</i></p>';
}
if ( $_desc != '' ) {
$output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n";
}
$output .= '<div class="screenshot" id="' . $id . '-image">' . "\n";
if ( $value != '' ) {
$remove = '<a class="remove-image">删除</a>';
$image = preg_match( '/(^.*\.jpg|jpeg|png|gif|svg|ico*)/i', $value );
if ( $image ) {
$output .= '<img src="' . $value . '" alt="" />' . $remove;
} else {
$parts = explode( "/", $value );
for( $i = 0; $i < sizeof( $parts ); ++$i ) {
$title = $parts[$i];
}
// No output preview if it's not an image.
$output .= '';
// Standard generic output if it's not an image.
$title = __( '浏览文件', 'kratos' );
$output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>';
}
}
$output .= '</div>' . "\n";
return $output;
}
/**
* Enqueue scripts for file uploader
*/
function optionsframework_media_scripts( $hook ) {
$menu = Options_Framework_Admin::menu_settings();
if ( substr( $hook, -strlen( $menu['menu_slug'] ) ) !== $menu['menu_slug'] )
return;
if ( function_exists( 'wp_enqueue_media' ) )
wp_enqueue_media();
wp_register_script( 'of-media-uploader', get_stylesheet_directory_uri() . '/inc/options-framework/js/media-uploader.js', array( 'jquery' ), Options_Framework::VERSION );
wp_enqueue_script( 'of-media-uploader' );
wp_localize_script( 'of-media-uploader', 'optionsframework_l10n', array(
'upload' => __( '上传', 'kratos' ),
'remove' => __( '删除', 'kratos' )
) );
}
}
@@ -0,0 +1,195 @@
<?php
/**
* @package Options_Framework
* @author Devin Price <devin@wptheming.com>
* @license GPL-2.0+
* @link http://wptheming.com
* @copyright 2010-2014 WP Theming
*/
/**
* Sanitization for text input
*
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
*/
add_filter( 'of_sanitize_text', 'sanitize_text_field' );
/**
* Sanitization for password input
*
* @link http://developer.wordpress.org/reference/functions/sanitize_text_field/
*/
add_filter( 'of_sanitize_password', 'sanitize_text_field' );
/**
* Sanitization for select input
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_select', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for radio input
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_radio', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for image selector
*
* Validates that the selected option is a valid option.
*/
add_filter( 'of_sanitize_images', 'of_sanitize_enum', 10, 2 );
/**
* Sanitization for textarea field
*
* @param $input string
* @return $output sanitized string
*/
function of_sanitize_textarea( $input ) {
global $allowedposttags;
$output = wp_kses( $input, $allowedposttags );
return $output;
}
add_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
/**
* Sanitization for checkbox input
*
* @param $input string (1 or empty) checkbox state
* @return $output '1' or false
*/
function of_sanitize_checkbox( $input ) {
if ( $input ) {
$output = '1';
} else {
$output = false;
}
return $output;
}
add_filter( 'of_sanitize_checkbox', 'of_sanitize_checkbox' );
/**
* File upload sanitization.
*
* Returns a sanitized filepath if it has a valid extension.
*
* @param string $input filepath
* @returns string $output filepath
*/
function of_sanitize_upload( $input ) {
$output = '';
$filetype = wp_check_filetype( $input );
if ( $filetype["ext"] ) {
$output = esc_url( $input );
}
return $output;
}
add_filter( 'of_sanitize_upload', 'of_sanitize_upload' );
/**
* Sanitization of input with allowed tags and wpautotop.
*
* Allows allowed tags in html input and ensures tags close properly.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_allowedtags( $input ) {
global $allowedtags;
$output = wpautop( wp_kses( $input, $allowedtags ) );
return $output;
}
/**
* Sanitization of input with allowed post tags and wpautotop.
*
* Allows allowed post tags in html input and ensures tags close properly.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_allowedposttags( $input ) {
global $allowedposttags;
$output = wpautop( wp_kses( $input, $allowedposttags) );
return $output;
}
/**
* Validates that the $input is one of the avilable choices
* for that specific option.
*
* @param string $input
* @returns string $output
*/
function of_sanitize_enum( $input, $option ) {
$output = '';
if ( array_key_exists( $input, $option['options'] ) ) {
$output = $input;
}
return $output;
}
/**
* Sanitization for background option.
*
* @returns array $output
*/
function of_sanitize_background( $input ) {
$output = wp_parse_args( $input, array(
'color' => '',
'image' => '',
'repeat' => 'repeat',
'position' => 'top center',
'attachment' => 'scroll'
) );
$output['color'] = apply_filters( 'of_sanitize_hex', $input['color'] );
$output['image'] = apply_filters( 'of_sanitize_upload', $input['image'] );
return $output;
}
add_filter( 'of_sanitize_background', 'of_sanitize_background' );
/**
* Sanitize a color represented in hexidecimal notation.
*
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
* @param string The value that this function should return if it cannot be recognized as a color.
* @return string
*/
function of_sanitize_hex( $hex, $default = '' ) {
if ( of_validate_hex( $hex ) ) {
return $hex;
}
return $default;
}
add_filter( 'of_sanitize_color', 'of_sanitize_hex' );
/**
* Is a given string a color formatted in hexidecimal notation?
*
* @param string Color in hexidecimal notation. "#" may or may not be prepended to the string.
* @return bool
*/
function of_validate_hex( $hex ) {
$hex = trim( $hex );
/* Strip recognized prefixes. */
if ( 0 === strpos( $hex, '#' ) ) {
$hex = substr( $hex, 1 );
}
elseif ( 0 === strpos( $hex, '%23' ) ) {
$hex = substr( $hex, 3 );
}
/* Regex match. */
if ( 0 === preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) {
return false;
}
else {
return true;
}
}
@@ -0,0 +1,79 @@
jQuery(document).ready(function($){
var optionsframework_upload;
var optionsframework_selector;
function optionsframework_add_file(event, selector) {
var upload = $(".uploaded-file"), frame;
var $el = $(this);
optionsframework_selector = selector;
event.preventDefault();
// If the media frame already exists, reopen it.
if ( optionsframework_upload ) {
optionsframework_upload.open();
} else {
// Create the media frame.
optionsframework_upload = wp.media.frames.optionsframework_upload = wp.media({
// Set the title of the modal.
title: $el.data('choose'),
// Customize the submit button.
button: {
// Set the text of the button.
text: $el.data('update'),
// Tell the button not to close the modal, since we're
// going to refresh the page when the image is selected.
close: false
}
});
// When an image is selected, run a callback.
optionsframework_upload.on( 'select', function() {
// Grab the selected attachment.
var attachment = optionsframework_upload.state().get('selection').first();
optionsframework_upload.close();
optionsframework_selector.find('.upload').val(attachment.attributes.url);
if ( attachment.attributes.type == 'image' ) {
optionsframework_selector.find('.screenshot').empty().hide().append('<img src="' + attachment.attributes.url + '"><a class="remove-image">Remove</a>').slideDown('fast');
}
optionsframework_selector.find('.upload-button').unbind().addClass('remove-file').removeClass('upload-button').val(optionsframework_l10n.remove);
optionsframework_selector.find('.of-background-properties').slideDown();
optionsframework_selector.find('.remove-image, .remove-file').on('click', function() {
optionsframework_remove_file( $(this).parents('.section') );
});
});
}
// Finally, open the modal.
optionsframework_upload.open();
}
function optionsframework_remove_file(selector) {
selector.find('.remove-image').hide();
selector.find('.upload').val('');
selector.find('.of-background-properties').hide();
selector.find('.screenshot').slideUp();
selector.find('.remove-file').unbind().addClass('upload-button').removeClass('remove-file').val(optionsframework_l10n.upload);
// We don't display the upload button if .upload-notice is present
// This means the user doesn't have the WordPress 3.5 Media Library Support
if ( $('.section-upload .upload-notice').length > 0 ) {
$('.upload-button').remove();
}
selector.find('.upload-button').on('click', function(event) {
optionsframework_add_file(event, $(this).parents('.section'));
});
}
$('.remove-image, .remove-file').on('click', function() {
optionsframework_remove_file( $(this).parents('.section') );
});
$('.upload-button').click( function( event ) {
optionsframework_add_file(event, $(this).parents('.section'));
});
});
+166
View File
@@ -0,0 +1,166 @@
/**
* Custom scripts needed for the colorpicker, image button selectors,
* and navigation tabs.
*/
jQuery(document).ready(function ($) {
$('input[id^="s_"]').click(function () {
jQuery('#section-' + this.id + '_url').fadeToggle(400)
jQuery('#section-' + this.id + '_links').fadeToggle(400)
})
for (i = 0; i < $('input[id^="s_"]' + ':checked').length; i++) {
let id = $('input[id^="s_"]' + ':checked')[i].id
$('#section-' + id + '_url').show()
$('#section-' + id + '_links').show()
}
jQuery('#g_cos').click(function () {
jQuery('#section-g_cos_bucketname').fadeToggle(400)
jQuery('#section-g_cos_url').fadeToggle(400)
jQuery('#section-g_cos_accesskey').fadeToggle(400)
jQuery('#section-g_cos_secretkey').fadeToggle(400)
})
if (jQuery('#g_cos:checked').val() !== undefined) {
jQuery('#section-g_cos_bucketname').show()
jQuery('#section-g_cos_url').show()
jQuery('#section-g_cos_accesskey').show()
jQuery('#section-g_cos_secretkey').show()
}
jQuery('#g_cc_switch').click(function () {
jQuery('#section-g_cc').fadeToggle(400)
})
if (jQuery('#g_cc_switch:checked').val() !== undefined) {
jQuery('#section-g_cc').show()
}
jQuery('#g_donate').click(function () {
jQuery('#section-g_donate_alipay').fadeToggle(400)
jQuery('#section-g_donate_wechat').fadeToggle(400)
})
if (jQuery('#g_donate:checked').val() !== undefined) {
jQuery('#section-g_donate_alipay').show()
jQuery('#section-g_donate_wechat').show()
}
jQuery('#m_smtp').click(function () {
jQuery('#section-m_host').fadeToggle(400)
jQuery('#section-m_sec').fadeToggle(400)
jQuery('#section-m_port').fadeToggle(400)
jQuery('#section-m_username').fadeToggle(400)
jQuery('#section-m_passwd').fadeToggle(400)
jQuery('#section-m_sendmail').fadeToggle(400)
})
if (jQuery('#m_smtp:checked').val() !== undefined) {
jQuery('#section-m_host').show()
jQuery('#section-m_sec').show()
jQuery('#section-m_port').show()
jQuery('#section-m_username').show()
jQuery('#section-m_passwd').show()
jQuery('#section-m_sendmail').show()
}
jQuery('#g_thumbnail').click(function () {
jQuery('#section-g_postthumbnail').fadeToggle(400)
})
if (jQuery('#g_thumbnail:checked').val() !== undefined) {
jQuery('#section-g_postthumbnail').show()
}
jQuery('#top_select').change(function () {
if (jQuery("#top_select").val() == 'color') {
jQuery('#section-top_color').fadeIn(400)
jQuery('#section-top_img').fadeOut(400)
jQuery('#section-top_title').fadeOut(400)
jQuery('#section-top_describe').fadeOut(400)
} else {
jQuery('#section-top_color').fadeOut(400)
jQuery('#section-top_img').fadeIn(400)
jQuery('#section-top_title').fadeIn(400)
jQuery('#section-top_describe').fadeIn(400)
}
})
if (jQuery('#top_select').val() == 'color') {
jQuery('#section-top_color').show()
jQuery('#section-top_img').hide()
jQuery('#section-top_title').hide()
jQuery('#section-top_describe').hide()
} else {
jQuery('#section-top_color').hide()
jQuery('#section-top_img').show()
jQuery('#section-top_title').show()
jQuery('#section-top_describe').show()
}
// Loads the color pickers
$('.of-color').wpColorPicker()
// Image Options
$('.of-radio-img-img').click(function () {
$(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected')
$(this).addClass('of-radio-img-selected')
})
$('.of-radio-img-label').hide()
$('.of-radio-img-img').show()
$('.of-radio-img-radio').hide()
// Loads tabbed sections if they exist
if ($('.nav-tab-wrapper').length > 0) {
options_framework_tabs()
}
function options_framework_tabs () {
var $group = $('.group'),
$navtabs = $('.nav-tab-wrapper a'),
active_tab = ''
// Hides all the .group sections to start
$group.hide()
// Find if a selected tab is saved in localStorage
if (typeof (localStorage) != 'undefined') {
active_tab = localStorage.getItem('active_tab')
}
// If active tab is saved and exists, load it's .group
if (active_tab != '' && $(active_tab).length) {
$(active_tab).fadeIn()
$(active_tab + '-tab').addClass('nav-tab-active')
} else {
$('.group:first').fadeIn()
$('.nav-tab-wrapper a:first').addClass('nav-tab-active')
}
// Bind tabs clicks
$navtabs.click(function (e) {
e.preventDefault()
// Remove active class from all tabs
$navtabs.removeClass('nav-tab-active')
$(this).addClass('nav-tab-active').blur()
if (typeof (localStorage) != 'undefined') {
localStorage.setItem('active_tab', $(this).attr('href'))
}
var selected = $(this).attr('href')
$group.hide()
$(selected).fadeIn()
})
}
})