Import legacy nurinda.co.id website
This commit is contained in:
1 parent
3f59bb9038
commit
6e21646ac4
13389 files changed
+3246690
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,140 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'wp_ajax_usof_ajax_mega_menu_save_settings', 'usof_ajax_mega_menu_save_settings' );
|
||||
function usof_ajax_mega_menu_save_settings() {
|
||||
$item_id = $_POST['item'];
|
||||
$settings = $_POST['settings'];
|
||||
|
||||
if ( ! check_ajax_referer( 'usof-mega-menu-save', 'security', FALSE ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $settings as $key => $val ) {
|
||||
if ( strip_tags( $val ) != $val ) {
|
||||
$settings[$key] = strip_tags( $val );
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $item_id, 'us_mega_menu_settings', $settings );
|
||||
|
||||
do_action( 'usof_ajax_mega_menu_save_settings' );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => us_translate( 'Changes saved.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_ajax_mega_menu', 'usof_ajax_mega_menu' );
|
||||
function usof_ajax_mega_menu() {
|
||||
$menu_id = $_GET['menu_id'];
|
||||
$item_id = $_GET['item_id'];
|
||||
|
||||
$menu_items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'any' ) );
|
||||
|
||||
$menu_label = '';
|
||||
if ( is_array( $menu_items ) AND count( $menu_items ) > 0 ) {
|
||||
foreach ( $menu_items as $menu_item ) {
|
||||
if ( $menu_item->ID == $item_id ) {
|
||||
$menu_label = $menu_item->title;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $menu_label == '' ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$settings_config = us_config( 'mega-menu', array() );
|
||||
|
||||
?>
|
||||
<div class="usof-header">
|
||||
<h2><?php echo $menu_label; ?><span> – <?php _e( 'Dropdown Settings', 'us' ) ?></span></h2>
|
||||
<div class="usof-control for_save status_clear">
|
||||
<button class="usof-button type_save" type="button">
|
||||
<span><?php echo us_translate( 'Save Changes' ) ?></span>
|
||||
<span class="usof-preloader"></span>
|
||||
</button>
|
||||
<div class="usof-control-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="us-mm-body">
|
||||
<div class="us-mm-settings" id="section_settings">
|
||||
<?php
|
||||
|
||||
$values = ( get_post_meta( $item_id, 'us_mega_menu_settings', TRUE ) ) ? get_post_meta( $item_id, 'us_mega_menu_settings', TRUE ) : array();
|
||||
foreach ( $settings_config as $field_id => $field ) {
|
||||
if ( ! isset( $values[$field_id] ) AND isset( $field['std'] ) ) {
|
||||
$values[$field_id] = $field['std'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $settings_config as $field_id => $field ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_id,
|
||||
'id' => 'usof_' . $field_id,
|
||||
'field' => $field,
|
||||
'values' => &$values,
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(function ($) {
|
||||
$('#TB_window').addClass('usof-container');
|
||||
var $USMMHeader = $('.usof-header'),
|
||||
$saveButton = $USMMHeader.find('.usof-control.for_save'),
|
||||
$saveMessage = $saveButton.find('.usof-control-message'),
|
||||
saveStateTimer = null;
|
||||
|
||||
"use strict";
|
||||
var USMMSave = function(){
|
||||
$saveButton.usMod('status', 'loading');
|
||||
$saveMessage.html('');
|
||||
$saveButton.off('click', USMMSave);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'usof_ajax_mega_menu_save_settings',
|
||||
menu: <?php echo $menu_id; ?>,
|
||||
item: <?php echo $item_id; ?>,
|
||||
settings: USMMSettings,
|
||||
security: '<?php echo wp_create_nonce( 'usof-mega-menu-save' ); ?>'
|
||||
},
|
||||
success: function(result){
|
||||
if ($saveButton.usMod('status') !== 'loading') return;
|
||||
$saveMessage.html(result.data.message);
|
||||
$saveButton.usMod('status', 'success');
|
||||
clearTimeout(saveStateTimer);
|
||||
saveStateTimer = setTimeout(function(){
|
||||
$saveMessage.html('');
|
||||
$saveButton.usMod('status', 'clear');
|
||||
}.bind(this), 4000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(document.body).trigger('usof_mm_load');
|
||||
|
||||
$(document.body).off('usof_mm_save').on('usof_mm_save', function(){
|
||||
clearTimeout(saveStateTimer);
|
||||
$saveButton.usMod('status', 'notsaved');
|
||||
$saveButton.off('click').on('click', USMMSave);
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
die();
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'wp_ajax_usof_save', 'usof_ajax_save' );
|
||||
function usof_ajax_save() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
do_action( 'usof_before_ajax_save' );
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
$config = us_config( 'theme-options', array(), TRUE );
|
||||
|
||||
// Logic do not seek here, young padawan. For WPML string translation compability such copying method is used.
|
||||
// If result of array_merge is put directly to $updated_options, the options will not save.
|
||||
$usof_options_fallback = array_merge( usof_defaults(), $usof_options );
|
||||
$updated_options = array();
|
||||
foreach ( $usof_options_fallback as $key => $val ) {
|
||||
$updated_options[ $key ] = $val;
|
||||
}
|
||||
|
||||
$post_options = us_maybe_get_post_json( 'usof_options' );
|
||||
|
||||
if ( empty( $post_options ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'There\'s no options to save', 'us' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $post_options as $key => $value ) {
|
||||
if ( isset( $updated_options[ $key ] ) ) {
|
||||
$updated_options[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
usof_save_options( $updated_options );
|
||||
|
||||
do_action( 'usof_after_ajax_save' );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => us_translate( 'Changes saved.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_reset', 'usof_ajax_reset' );
|
||||
function usof_ajax_reset() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$updated_options = usof_defaults();
|
||||
usof_save_options( $updated_options );
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __( 'Options were reset', 'us' ),
|
||||
'usof_options' => $updated_options,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_backup', 'usof_ajax_backup' );
|
||||
function usof_ajax_backup() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
$backup = array(
|
||||
'time' => current_time( 'mysql', TRUE ),
|
||||
'usof_options' => $usof_options,
|
||||
);
|
||||
$backup_time = strtotime( $backup['time'] ) + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
|
||||
|
||||
update_option( 'usof_backup_' . US_THEMENAME, $backup, FALSE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'status' => __( 'Last Backup', 'us' ) . ': <span>' . date_i18n( 'F j, Y - G:i T', $backup_time ) . '</span>',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_restore_backup', 'usof_ajax_restore_backup' );
|
||||
function usof_ajax_restore_backup() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
global $usof_options;
|
||||
|
||||
$backup = get_option( 'usof_backup_' . US_THEMENAME );
|
||||
if ( ! $backup OR ! is_array( $backup ) OR ! isset( $backup['usof_options'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => __( 'There\'s no backup to restore', 'us' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$usof_options = $backup['usof_options'];
|
||||
update_option( 'usof_options_' . US_THEMENAME, $usof_options, TRUE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __( 'Backup was restored', 'us' ),
|
||||
'usof_options' => $usof_options,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_save_style_scheme', 'usof_ajax_save_style_scheme' );
|
||||
function usof_ajax_save_style_scheme() {
|
||||
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
|
||||
$scheme = us_maybe_get_post_json( 'scheme' );
|
||||
if ( isset( $scheme['id'] ) ) {
|
||||
$scheme_id = $scheme['id'];
|
||||
} else {
|
||||
$max_index = 0;
|
||||
if ( count( $custom_color_schemes ) > 0 ) {
|
||||
$max_index = intval( max( array_keys( $custom_color_schemes ) ) );
|
||||
}
|
||||
$scheme_id = $max_index + 1;
|
||||
}
|
||||
|
||||
$custom_color_schemes[ $scheme_id ] = array( 'title' => $scheme['name'], 'values' => $scheme['colors'] );
|
||||
update_option( 'usof_style_schemes_' . US_THEMENAME, $custom_color_schemes, TRUE );
|
||||
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$output = '';
|
||||
|
||||
$custom_color_schemes_reversed = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
foreach ( $custom_color_schemes_reversed as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item type_custom" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
// Overwrite btn
|
||||
$output .= '<div class="usof-schemes-item-save" title="' . us_translate( 'Save' ) . '"></div>';
|
||||
// Delete btn
|
||||
$output .= '<div class="usof-schemes-item-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
foreach ( $color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
$output .= '</li>';
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'customSchemes' => $custom_color_schemes,
|
||||
'schemes' => $color_schemes,
|
||||
'schemesHtml' => $output,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_usof_delete_style_scheme', 'usof_ajax_delete_style_scheme' );
|
||||
function usof_ajax_delete_style_scheme() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$scheme = sanitize_text_field( $_POST['scheme'] );
|
||||
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
if ( isset( $custom_color_schemes[ $scheme ] ) ) {
|
||||
unset( $custom_color_schemes[ $scheme ] );
|
||||
}
|
||||
update_option( 'usof_style_schemes_' . US_THEMENAME, $custom_color_schemes, TRUE );
|
||||
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$output = '';
|
||||
|
||||
$custom_color_schemes_reversed = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
foreach ( $custom_color_schemes_reversed as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item type_custom" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
// Overwrite btn
|
||||
$output .= '<div class="usof-schemes-item-save" title="' . us_translate( 'Save' ) . '"></div>';
|
||||
// Delete btn
|
||||
$output .= '<div class="usof-schemes-item-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
foreach ( $color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
$output .= '</li>';
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'customSchemes' => $custom_color_schemes,
|
||||
'schemes' => $color_schemes,
|
||||
'schemesHtml' => $output,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Adding palette values for color picker
|
||||
add_action( 'wp_ajax_usof_color_palette', 'usof_ajax_color_palette' );
|
||||
function usof_ajax_color_palette() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
$paletteColors = get_option( 'usof_color_palette_' . US_THEMENAME );
|
||||
if ( ! is_array( $paletteColors ) ) {
|
||||
$paletteColors = array();
|
||||
}
|
||||
$paletteLength = count( $paletteColors );
|
||||
$color = us_maybe_get_post_json( 'color' );
|
||||
$output = '';
|
||||
if ( isset( $color['value'] ) AND $paletteLength < 8 ) {
|
||||
// Appending new color
|
||||
$paletteColors[] = $color['value'];
|
||||
update_option( 'usof_color_palette_' . US_THEMENAME, $paletteColors, TRUE );
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$output .= '<div class="usof_colpick_palette_value"><span style="background:' . $color . '" title="' . esc_attr( $color ) . '"></span><div class="usof_colpick_palette_delete" title="' . us_translate( 'Delete' ) . '"></div></div>';
|
||||
}
|
||||
$output .= '<div class="usof_colpick_palette_add" title="' . __( 'Add the current color to the palette', 'us' ) . '"></div>';
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'output' => $output,
|
||||
)
|
||||
);
|
||||
} elseif ( isset( $color['colorId'] ) ) {
|
||||
// Deleting current color
|
||||
unset( $paletteColors[ $color['colorId'] ] );
|
||||
$newPalette = array();
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$newPalette[] = $color;
|
||||
}
|
||||
update_option( 'usof_color_palette_' . US_THEMENAME, $newPalette, TRUE );
|
||||
foreach ( $paletteColors as $color ) {
|
||||
$output .= '<div class="usof_colpick_palette_value"><span style="background:' . $color . '" title="' . esc_attr( $color ) . '"></span><div class="usof_colpick_palette_delete" title="' . us_translate( 'Delete' ) . '"></div></div>';
|
||||
}
|
||||
$output .= '<div class="usof_colpick_palette_add" title="' . __( 'Add the current color to the palette', 'us' ) . '"></div>';
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'output' => $output,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Color Schemes
|
||||
add_action( 'wp_ajax_usof_get_style_schemes', 'usof_get_style_schemes' );
|
||||
function usof_get_style_schemes() {
|
||||
if ( ! check_admin_referer( 'usof-actions' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
|
||||
// Reverse Custom schemes order to make last added item first
|
||||
$custom_color_schemes = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'schemes' => $color_schemes,
|
||||
'custom_schemes' => $custom_color_schemes,
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'admin_menu', 'us_options_admin_menu', 9 );
|
||||
function us_options_admin_menu() {
|
||||
add_menu_page( __( 'Theme Options', 'us' ), US_THEMENAME, 'manage_options', 'us-theme-options', 'us_theme_options_page', NULL, '59.001' );
|
||||
$usof_page = add_submenu_page( 'us-theme-options', US_THEMENAME, __( 'Theme Options', 'us' ), 'edit_theme_options', 'us-theme-options', 'us_theme_options_page' );
|
||||
add_action( 'admin_print_scripts-' . $usof_page, 'usof_print_scripts' );
|
||||
add_action( 'admin_print_styles-' . $usof_page, 'usof_print_styles' );
|
||||
add_action( 'admin_print_styles-' . $usof_page, 'usof_print_fonts' );
|
||||
|
||||
add_action( 'admin_print_scripts-post-new.php', 'usof_print_scripts' );
|
||||
add_action( 'admin_print_scripts-post.php', 'usof_print_scripts' );
|
||||
|
||||
add_action( 'admin_print_scripts-nav-menus.php', 'usof_print_scripts' );
|
||||
|
||||
add_action( 'admin_notices', 'usof_hide_admin_notices_start', 1 );
|
||||
add_action( 'admin_notices', 'usof_hide_admin_notices_end', 1000 );
|
||||
}
|
||||
|
||||
function us_theme_options_page() {
|
||||
|
||||
// For notices
|
||||
echo '<div class="wrap"><h2 class="hidden"></h2>';
|
||||
|
||||
global $usof_options, $usof_img_sizes, $usof_enable_portfolio, $usof_sidebar_titlebar;
|
||||
usof_load_options_once();
|
||||
$usof_options = array_merge( usof_defaults(), $usof_options );
|
||||
|
||||
// Preserving values for hidden fields
|
||||
$hidden_fields_values = array();
|
||||
|
||||
$visited_new_sections = array();
|
||||
if ( isset( $_COOKIE ) AND isset( $_COOKIE['usof_visited_new_sections'] ) ) {
|
||||
$visited_new_sections = explode( ',', $_COOKIE['usof_visited_new_sections'] );
|
||||
}
|
||||
|
||||
$usof_img_sizes = us_image_sizes_select_values();
|
||||
$usof_enable_portfolio = us_get_option( 'enable_portfolio', 1 );
|
||||
$usof_sidebar_titlebar = us_get_option( 'enable_sidebar_titlebar', 0 );
|
||||
|
||||
$config = us_config( 'theme-options', array(), TRUE );
|
||||
echo '<div class="usof-container';
|
||||
echo apply_filters( 'usof_container_classes', '' );
|
||||
if ( get_option( 'us_license_activated', 0 ) OR ( defined( 'US_DEV' ) AND US_DEV ) ) {
|
||||
echo ' theme_activated';
|
||||
}
|
||||
echo '" data-ajaxurl="' . esc_attr( admin_url( 'admin-ajax.php' ) ) . '">';
|
||||
echo '<form class="usof-form" method="post" action="#" autocomplete="off">';
|
||||
// Output _nonce and _wp_http_referer hidden fields for ajax secuirity checks
|
||||
wp_nonce_field( 'usof-actions' );
|
||||
echo '<div class="usof-header">';
|
||||
echo '<div class="usof-header-logo">';
|
||||
echo US_THEMENAME . ' <span>' . US_THEMEVERSION . '</span></div>';
|
||||
echo '<div class="usof-header-title"><span>' . __( 'Theme Options', 'us' ) . ' — </span>';
|
||||
echo '<h2>' . us_translate_x( 'General', 'settings screen' ) . '</h2></div>';
|
||||
// Control for opening color schemes window
|
||||
echo '<div class="usof-control for_schemes hidden">';
|
||||
echo '<button class="usof-button" type="button">' . __( 'Color Schemes', 'us' ) . '</button>';
|
||||
echo '</div>';
|
||||
// Control for saving changes button
|
||||
echo '<div class="usof-control for_save status_clear">';
|
||||
echo '<button class="usof-button type_save" type="button"><span>' . us_translate( 'Save Changes' ) . '</span>';
|
||||
echo '<span class="usof-preloader"></span></button>';
|
||||
echo '<div class="usof-control-message"></div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
// Saving empty or outdated selects
|
||||
$empty_select_present = FALSE;
|
||||
|
||||
$usof_options_fallback = array_merge( usof_defaults(), $usof_options );
|
||||
$updated_options = array();
|
||||
foreach ( $usof_options_fallback as $key => $val ) {
|
||||
$updated_options[ $key ] = $val;
|
||||
}
|
||||
|
||||
foreach ( $config as $section_id => $section ) {
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
foreach ( $section['fields'] as $field_id => $field ) {
|
||||
if ( $field['type'] == 'select' ) {
|
||||
$field_values = array_keys( $field['options'] );
|
||||
if ( ! isset( $updated_options[ $field_id ] ) OR ! in_array( $updated_options[ $field_id ], $field_values ) ) {
|
||||
$empty_select_present = TRUE;
|
||||
$updated_options[ $field_id ] = array_shift( $field_values );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $empty_select_present ) {
|
||||
usof_save_options( $updated_options );
|
||||
}
|
||||
|
||||
// Sided Menu
|
||||
echo '<div class="usof-nav"><div class="usof-nav-bg"></div><ul class="usof-nav-list level_1">';
|
||||
foreach ( $config as $section_id => &$section ) {
|
||||
if ( isset( $section['place_if'] ) AND ! $section['place_if'] ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $active_section ) ) {
|
||||
$active_section = $section_id;
|
||||
}
|
||||
echo '<li class="usof-nav-item level_1 id_' . $section_id . ( ( $section_id == $active_section ) ? ' current' : '' ) . '"';
|
||||
echo ' data-id="' . $section_id . '">';
|
||||
echo '<a class="usof-nav-anchor level_1" href="#' . $section_id . '">';
|
||||
echo '<img class="usof-nav-icon" src="' . $section['icon'] . '.png" srcset="' . $section['icon'] . '-2x.png 2x" alt="icon">';
|
||||
echo '<span class="usof-nav-title">' . $section['title'] . '</span>';
|
||||
echo '<span class="usof-nav-arrow"></span>';
|
||||
echo '</a>';
|
||||
if ( isset( $section['new'] ) AND $section['new'] AND ! in_array( $section_id, $visited_new_sections ) ) {
|
||||
echo '<span class="usof-nav-popup">' . __( 'New', 'us' ) . '</span>';
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
echo '<ul></div>';
|
||||
|
||||
// Content
|
||||
echo '<div class="usof-content">';
|
||||
foreach ( $config as $section_id => &$section ) {
|
||||
if ( isset( $section['place_if'] ) AND ! $section['place_if'] ) {
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
$hidden_fields_values = array_merge( $hidden_fields_values, array_intersect_key( $usof_options, $section['fields'] ) );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
echo '<section class="usof-section ' . ( ( $section_id == $active_section ) ? 'current' : '' ) . '" data-id="' . $section_id . '">';
|
||||
echo '<div class="usof-section-header" data-id="' . $section_id . '">';
|
||||
echo '<h3>' . $section['title'] . '</h3><span class="usof-section-header-control"></span></div>';
|
||||
echo '<div class="usof-section-content" style="display: ' . ( ( $section_id == $active_section ) ? 'block' : 'none' ) . '">';
|
||||
if ( isset( $section['fields'] ) ) {
|
||||
foreach ( $section['fields'] as $field_name => &$field ) {
|
||||
if ( isset( $field['place_if'] ) AND ! $field['place_if'] ) {
|
||||
if ( isset( $usof_options[ $field_name ] ) ) {
|
||||
$hidden_fields_values[ $field_name ] = $usof_options[ $field_name ];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_name,
|
||||
'id' => 'usof_' . $field_name,
|
||||
'field' => $field,
|
||||
'values' => &$usof_options,
|
||||
)
|
||||
);
|
||||
unset( $hidden_fields_values[ $field_name ] );
|
||||
}
|
||||
}
|
||||
echo '</div></section>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
echo '<div class="usof-hidden-fields"' . us_pass_data_to_js( $hidden_fields_values ) . '></div>';
|
||||
}
|
||||
|
||||
function usof_print_scripts() {
|
||||
global $usof_directory_uri;
|
||||
if ( ! did_action( 'wp_enqueue_media' ) ) {
|
||||
wp_enqueue_media();
|
||||
}
|
||||
wp_enqueue_script( 'usof-colorpicker', $usof_directory_uri . '/js/usof-colpick.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
wp_enqueue_script( 'usof-select2', $usof_directory_uri . '/js/select2.min.js', array( 'jquery' ), '4.0.5', TRUE );
|
||||
wp_enqueue_script( 'usof-scripts', $usof_directory_uri . '/js/usof.js', array( 'jquery' ), US_THEMEVERSION, TRUE );
|
||||
do_action( 'usof_print_scripts' );
|
||||
}
|
||||
|
||||
function usof_print_styles() {
|
||||
global $usof_directory_uri, $us_template_directory_uri;
|
||||
wp_enqueue_style( 'usof-styles', $usof_directory_uri . '/css/usof.css', array(), US_THEMEVERSION );
|
||||
do_action( 'usof_print_styles' );
|
||||
}
|
||||
|
||||
function usof_print_fonts() {
|
||||
$prefixes = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'body' );
|
||||
$font_options = $fonts = array();
|
||||
|
||||
$uploaded_fonts = us_get_option( 'uploaded_fonts', array() );
|
||||
$uploaded_font_names = array();
|
||||
if ( is_array( $uploaded_fonts ) AND count( $uploaded_fonts ) > 0 ) {
|
||||
foreach ( $uploaded_fonts as $uploaded_font ) {
|
||||
$uploaded_font_names[] = esc_attr( strip_tags( $uploaded_font['name'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $prefixes as $prefix ) {
|
||||
$font_option = explode( '|', us_get_option( $prefix . '_font_family', 'none' ), 2 );
|
||||
if ( in_array( $font_option[0], $uploaded_font_names ) ) {
|
||||
continue;
|
||||
}
|
||||
$font_options[] = $font_option;
|
||||
}
|
||||
|
||||
$custom_fonts = us_get_option( 'custom_font', array() );
|
||||
if ( is_array( $custom_fonts ) AND count( $custom_fonts ) > 0 ) {
|
||||
foreach ( $custom_fonts as $custom_font ) {
|
||||
$font_options[] = explode( '|', $custom_font['font_family'], 2 );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $font_options as $font ) {
|
||||
if ( ! isset( $font[1] ) OR empty( $font[1] ) ) {
|
||||
// Fault tolerance for missing font-variants
|
||||
$font[1] = '400,700';
|
||||
}
|
||||
$selected_font_variants = explode( ',', $font[1] );
|
||||
// Empty font or web safe combination selected
|
||||
if ( $font[0] == 'none' OR strpos( $font[0], ',' ) !== FALSE ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$font[0] = str_replace( ' ', '+', $font[0] );
|
||||
if ( ! isset( $fonts[ $font[0] ] ) ) {
|
||||
$fonts[ $font[0] ] = array();
|
||||
}
|
||||
|
||||
foreach ( $selected_font_variants as $font_variant ) {
|
||||
$fonts[ $font[0] ][] = $font_variant;
|
||||
}
|
||||
}
|
||||
|
||||
$protocol = is_ssl() ? 'https' : 'http';
|
||||
$subset = '&subset=' . us_get_option( 'font_subset', 'latin' );
|
||||
$font_index = 1;
|
||||
foreach ( $fonts as $font_name => $font_variants ) {
|
||||
if ( count( $font_variants ) == 0 OR $font_name == 'get_h1' ) {
|
||||
continue;
|
||||
}
|
||||
$font_variants = array_unique( $font_variants );
|
||||
|
||||
// Google font url
|
||||
$font_url = $protocol . '://fonts.googleapis.com/css?family=' . $font_name . ':' . implode( ',', $font_variants ) . $subset;
|
||||
wp_enqueue_style( 'us-font-' . $font_index, $font_url );
|
||||
$font_index ++;
|
||||
}
|
||||
|
||||
// Generate font-face for Uploaded Fonts
|
||||
$uploaded_fonts = us_get_option( 'uploaded_fonts', array() );
|
||||
if ( is_array( $uploaded_fonts ) AND count( $uploaded_fonts ) > 0 ) {
|
||||
echo '<style>';
|
||||
foreach ( $uploaded_fonts as $uploaded_font ) {
|
||||
$files = explode( ',', $uploaded_font['files'] );
|
||||
$urls = array();
|
||||
foreach ( $files as $file ) {
|
||||
$url = wp_get_attachment_url( $file );
|
||||
if ( $url ) {
|
||||
$urls[] = 'url(' . esc_url( $url ) . ') format("' . pathinfo( $url, PATHINFO_EXTENSION ) . '")';
|
||||
}
|
||||
}
|
||||
if ( count( $urls ) ) {
|
||||
$src = implode( ', ', $urls );
|
||||
echo '@font-face {';
|
||||
echo 'font-display: swap;';
|
||||
echo 'font-style: normal;';
|
||||
echo 'font-family:"' . strip_tags( $uploaded_font['name'] ) . '";';
|
||||
echo 'font-weight:' . $uploaded_font['weight'] . ';';
|
||||
echo 'src:' . $src . ';';
|
||||
echo '}';
|
||||
}
|
||||
}
|
||||
echo '</style>';
|
||||
}
|
||||
}
|
||||
|
||||
function usof_hide_admin_notices_start() {
|
||||
?><div class="hidden"><?php
|
||||
}
|
||||
|
||||
function usof_hide_admin_notices_end() {
|
||||
?></div><?php
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'admin_init', 'usof_mega_menu_init' );
|
||||
function usof_mega_menu_init() {
|
||||
global $pagenow, $usof_version;
|
||||
if ( $pagenow == 'nav-menus.php') {
|
||||
global $us_template_directory_uri;
|
||||
|
||||
add_action('admin_footer', 'usof_mega_menu_admin_footer');
|
||||
|
||||
wp_enqueue_style( 'usof-styles', $us_template_directory_uri . '/framework/vendor/usof/css/usof.css', array(), $usof_version );
|
||||
add_thickbox();
|
||||
}
|
||||
}
|
||||
|
||||
function usof_mega_menu_admin_footer() {
|
||||
?>
|
||||
<script>
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
var menuId = $('input#menu').val();
|
||||
|
||||
$('#menu-to-edit li.menu-item.menu-item-depth-0').each(function() {
|
||||
var $menuItem = $(this),
|
||||
itemId = parseInt($menuItem.attr('id').match(/[0-9]+/)[0], 10),
|
||||
$nextMenuItem = $menuItem.next();
|
||||
|
||||
if ( $nextMenuItem.length == 0 || $nextMenuItem.is('li.menu-item.menu-item-depth-0') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $('<a href="<?php echo admin_url(); ?>admin-ajax.php?action=usof_ajax_mega_menu&menu_id='+menuId+'&item_id='+itemId+'">')
|
||||
.addClass("us-mm-btn thickbox")
|
||||
.html('<?php _e( 'Dropdown Settings', 'us' ); ?>');
|
||||
|
||||
$('.item-title', $menuItem).append($button);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_action( 'load-post.php', 'us_post_meta_boxes_setup' );
|
||||
add_action( 'load-post-new.php', 'us_post_meta_boxes_setup' );
|
||||
|
||||
function us_post_meta_boxes_setup() {
|
||||
|
||||
$config = us_config( 'meta-boxes', array() );
|
||||
|
||||
foreach ( $config as &$meta_box ) {
|
||||
new US_Meta_Box( $meta_box );
|
||||
}
|
||||
}
|
||||
|
||||
class US_Meta_Box {
|
||||
|
||||
public $meta_box;
|
||||
|
||||
public function __construct( $meta_box ) {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->meta_box = $meta_box;
|
||||
|
||||
// Add meta box
|
||||
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
|
||||
// Save meta box
|
||||
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
||||
add_action( 'save_post_' . $post_type, array( $this, 'save_meta_boxes' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function add_meta_boxes() {
|
||||
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
||||
add_meta_box(
|
||||
$this->meta_box['id'], $this->meta_box['title'], array(
|
||||
$this,
|
||||
'meta_box_body',
|
||||
), $post_type, $this->meta_box['context'], $this->meta_box['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function meta_box_body() {
|
||||
|
||||
echo '<div class="usof-metabox">';
|
||||
global $us_metabox_marker_placed;
|
||||
if ( empty( $us_metabox_marker_placed ) ) {
|
||||
echo '<input type="hidden" name="us_metabox_save" value="1">';
|
||||
$us_metabox_marker_placed = TRUE;
|
||||
}
|
||||
|
||||
$post = get_post();
|
||||
$post_id = isset( $post->ID ) ? $post->ID : 0;
|
||||
$values = array();
|
||||
|
||||
// Output "Used in" locations for Page Blocks metabox
|
||||
if ( 'us_post_info' == $this->meta_box['id'] ) {
|
||||
$this->meta_box['fields']['used_in_locations']['description'] = us_get_used_in_locations( $post->ID, TRUE );
|
||||
}
|
||||
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
if ( $post_id ) {
|
||||
if ( metadata_exists( 'post', $post_id, $field_id ) ) {
|
||||
$values[ $field_id ] = get_post_meta( $post_id, $field_id, TRUE );
|
||||
} elseif ( isset( $field['std'] ) ) {
|
||||
$values[ $field_id ] = $field['std'];
|
||||
} else {
|
||||
$values[ $field_id ] = '';
|
||||
}
|
||||
if ( $field['type'] == 'link' ) {
|
||||
$values[ $field_id ] = json_decode( $values[ $field_id ], TRUE );
|
||||
}
|
||||
}
|
||||
if ( isset( $field['options'] ) AND ( ! in_array( $field['type'], array( 'checkboxes' ) ) ) AND ( ! in_array( $values[ $field_id ], array_keys( $field['options'] ) ) ) ) {
|
||||
$values[ $field_id ] = ( isset( $field['std'] ) ) ? $field['std'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_id,
|
||||
'id' => 'usof_' . $field_id,
|
||||
'field' => $field,
|
||||
'values' => &$values,
|
||||
'is_metabox' => TRUE,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function save_meta_boxes( $post_id ) {
|
||||
if ( ! ( isset( $_POST['us_metabox_save'] ) AND $_POST['us_metabox_save'] == 1 ) ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $this->meta_box['fields'] as $field_id => $field ) {
|
||||
if ( $field['type'] == 'heading' ) {
|
||||
continue;
|
||||
}
|
||||
$new_value = isset( $_POST[ $field_id ] ) ? $_POST[ $field_id ] : NULL;
|
||||
|
||||
update_post_meta( $post_id, $field_id, $new_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
(function(){function o(n){var i=e;n&&(e[n]||(e[n]={}),i=e[n]);if(!i.define||!i.define.packaged)t.original=i.define,i.define=t,i.define.packaged=!0;if(!i.require||!i.require.packaged)r.original=i.require,i.require=r,i.require.packaged=!0}var ACE_NAMESPACE="",e=function(){return this}();!e&&typeof window!="undefined"&&(e=window);if(!ACE_NAMESPACE&&typeof requirejs!="undefined")return;var t=function(e,n,r){if(typeof e!="string"){t.original?t.original.apply(this,arguments):(console.error("dropping module because define wasn't a string."),console.trace());return}arguments.length==2&&(r=n),t.modules[e]||(t.payloads[e]=r,t.modules[e]=null)};t.modules={},t.payloads={};var n=function(e,t,n){if(typeof t=="string"){var i=s(e,t);if(i!=undefined)return n&&n(),i}else if(Object.prototype.toString.call(t)==="[object Array]"){var o=[];for(var u=0,a=t.length;u<a;++u){var f=s(e,t[u]);if(f==undefined&&r.original)return;o.push(f)}return n&&n.apply(null,o)||!0}},r=function(e,t){var i=n("",e,t);return i==undefined&&r.original?r.original.apply(this,arguments):i},i=function(e,t){if(t.indexOf("!")!==-1){var n=t.split("!");return i(e,n[0])+"!"+i(e,n[1])}if(t.charAt(0)=="."){var r=e.split("/").slice(0,-1).join("/");t=r+"/"+t;while(t.indexOf(".")!==-1&&s!=t){var s=t;t=t.replace(/\/\.\//,"/").replace(/[^\/]+\/\.\.\//,"")}}return t},s=function(e,r){r=i(e,r);var s=t.modules[r];if(!s){s=t.payloads[r];if(typeof s=="function"){var o={},u={id:r,uri:"",exports:o,packaged:!0},a=function(e,t){return n(r,e,t)},f=s(a,o,u);o=f||u.exports,t.modules[r]=o,delete t.payloads[r]}s=t.modules[r]=o||s}return s};o(ACE_NAMESPACE)})(),define("ace/lib/regexp",["require","exports","module"],function(e,t,n){"use strict";function o(e){return(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.extended?"x":"")+(e.sticky?"y":"")}function u(e,t,n){if(Array.prototype.indexOf)return e.indexOf(t,n);for(var r=n||0;r<e.length;r++)if(e[r]===t)return r;return-1}var r={exec:RegExp.prototype.exec,test:RegExp.prototype.test,match:String.prototype.match,replace:String.prototype.replace,split:String.prototype.split},i=r.exec.call(/()??/,"")[1]===undefined,s=function(){var e=/^/g;return r.test.call(e,""),!e.lastIndex}();if(s&&i)return;RegExp.prototype.exec=function(e){var t=r.exec.apply(this,arguments),n,a;if(typeof e=="string"&&t){!i&&t.length>1&&u(t,"")>-1&&(a=RegExp(this.source,r.replace.call(o(this),"g","")),r.replace.call(e.slice(t.index),a,function(){for(var e=1;e<arguments.length-2;e++)arguments[e]===undefined&&(t[e]=undefined)}));if(this._xregexp&&this._xregexp.captureNames)for(var f=1;f<t.length;f++)n=this._xregexp.captureNames[f-1],n&&(t[n]=t[f]);!s&&this.global&&!t[0].length&&this.lastIndex>t.index&&this.lastIndex--}return t},s||(RegExp.prototype.test=function(e){var t=r.exec.call(this,e);return t&&this.global&&!t[0].length&&this.lastIndex>t.index&&this.lastIndex--,!!t})}),define("ace/lib/es5-shim",["require","exports","module"],function(e,t,n){function r(){}function w(e){try{return Object.defineProperty(e,"sentinel",{}),"sentinel"in e}catch(t){}}function H(e){return e=+e,e!==e?e=0:e!==0&&e!==1/0&&e!==-1/0&&(e=(e>0||-1)*Math.floor(Math.abs(e))),e}function B(e){var t=typeof e;return e===null||t==="undefined"||t==="boolean"||t==="number"||t==="string"}function j(e){var t,n,r;if(B(e))return e;n=e.valueOf;if(typeof n=="function"){t=n.call(e);if(B(t))return t}r=e.toString;if(typeof r=="function"){t=r.call(e);if(B(t))return t}throw new TypeError}Function.prototype.bind||(Function.prototype.bind=function(t){var n=this;if(typeof n!="function")throw new TypeError("Function.prototype.bind called on incompatible "+n);var i=u.call(arguments,1),s=function(){if(this instanceof s){var e=n.apply(this,i.concat(u.call(arguments)));return Object(e)===e?e:this}return n.apply(t,i.concat(u.call(arguments)))};return n.prototype&&(r.prototype=n.prototype,s.prototype=new r,r.prototype=null),s});var i=Function.prototype.call,s=Array.prototype,o=Object.prototype,u=s.slice,a=i.bind(o.toString),f=i.bind(o.hasOwnProperty),l,c,h,p,d;if(d=f(o,"__defineGetter__"))l=i.bind(o.__defineGetter__),c=i.bind(o.__defineSetter__),h=i.bind(o.__lookupGetter__),p=i.bind(o.__lookupSetter__);if([1,2].splice(0).length!=2)if(!function(){function e(e){var t=new Array(e+2);return t[0]=t[1]=0,t}var t=[],n;t.splice.apply(t,e(20)),t.splice.apply(t,e(26)),n=t.length,t.splice(5,0,"XXX"),n+1==t.length;if(n+1==t.length)return!0}())Array.prototype.splice=function(e,t){var n=this.length;e>0?e>n&&(e=n):e==void 0?e=0:e<0&&(e=Math.max(n+e,0)),e+t<n||(t=n-e);var r=this.slice(e,e+t),i=u.call(arguments,2),s=i.length;if(e===n)s&&this.push.apply(this,i);else{var o=Math.min(t,n-e),a=e+o,f=a+s-o,l=n-a,c=n-o;if(f<a)for(var h=0;h<l;++h)this[f+h]=this[a+h];else if(f>a)for(h=l;h--;)this[f+h]=this[a+h];if(s&&e===c)this.length=c,this.push.apply(this,i);else{this.length=c+s;for(h=0;h<s;++h)this[e+h]=i[h]}}return r};else{var v=Array.prototype.splice;Array.prototype.splice=function(e,t){return arguments.length?v.apply(this,[e===void 0?Line truncated
|
||||
(function() {
|
||||
window.require(["ace/ace"], function(a) {
|
||||
if (a) {
|
||||
a.config.init(true);
|
||||
a.define = window.define;
|
||||
}
|
||||
if (!window.ace)
|
||||
window.ace = a;
|
||||
for (var key in a) if (a.hasOwnProperty(key))
|
||||
window.ace[key] = a[key];
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
define("ace/ext/searchbox",["require","exports","module","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/keyboard/hash_handler","ace/lib/keys"],function(e,t,n){"use strict";var r=e("../lib/dom"),i=e("../lib/lang"),s=e("../lib/event"),o=".ace_search {background-color: #ddd;border: 1px solid #cbcbcb;border-top: 0 none;max-width: 325px;overflow: hidden;margin: 0;padding: 4px;padding-right: 6px;padding-bottom: 0;position: absolute;top: 0px;z-index: 99;white-space: normal;}.ace_search.left {border-left: 0 none;border-radius: 0px 0px 5px 0px;left: 0;}.ace_search.right {border-radius: 0px 0px 0px 5px;border-right: 0 none;right: 0;}.ace_search_form, .ace_replace_form {border-radius: 3px;border: 1px solid #cbcbcb;float: left;margin-bottom: 4px;overflow: hidden;}.ace_search_form.ace_nomatch {outline: 1px solid red;}.ace_search_field {background-color: white;color: black;border-right: 1px solid #cbcbcb;border: 0 none;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;float: left;height: 22px;outline: 0;padding: 0 7px;width: 214px;margin: 0;}.ace_searchbtn,.ace_replacebtn {background: #fff;border: 0 none;border-left: 1px solid #dcdcdc;cursor: pointer;float: left;height: 22px;margin: 0;position: relative;}.ace_searchbtn:last-child,.ace_replacebtn:last-child {border-top-right-radius: 3px;border-bottom-right-radius: 3px;}.ace_searchbtn:disabled {background: none;cursor: default;}.ace_searchbtn {background-position: 50% 50%;background-repeat: no-repeat;width: 27px;}.ace_searchbtn.prev {background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADFJREFUeNpiSU1NZUAC/6E0I0yACYskCpsJiySKIiY0SUZk40FyTEgCjGgKwTRAgAEAQJUIPCE+qfkAAAAASUVORK5CYII=); }.ace_searchbtn.next {background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADRJREFUeNpiTE1NZQCC/0DMyIAKwGJMUAYDEo3M/s+EpvM/mkKwCQxYjIeLMaELoLMBAgwAU7UJObTKsvAAAAAASUVORK5CYII=); }.ace_searchbtn_close {background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAcCAYAAABRVo5BAAAAZ0lEQVR42u2SUQrAMAhDvazn8OjZBilCkYVVxiis8H4CT0VrAJb4WHT3C5xU2a2IQZXJjiQIRMdkEoJ5Q2yMqpfDIo+XY4k6h+YXOyKqTIj5REaxloNAd0xiKmAtsTHqW8sR2W5f7gCu5nWFUpVjZwAAAABJRU5ErkJggg==) no-repeat 50% 0;border-radius: 50%;border: 0 none;color: #656565;cursor: pointer;float: right;font: 16px/16px Arial;height: 14px;margin: 5px 1px 9px 5px;padding: 0;text-align: center;width: 14px;}.ace_searchbtn_close:hover {background-color: #656565;background-position: 50% 100%;color: white;}.ace_replacebtn.prev {width: 54px}.ace_replacebtn.next {width: 27px}.ace_button {margin-left: 2px;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-o-user-select: none;-ms-user-select: none;user-select: none;overflow: hidden;opacity: 0.7;border: 1px solid rgba(100,100,100,0.23);padding: 1px;-moz-box-sizing: border-box;box-sizing: border-box;color: black;}.ace_button:hover {background-color: #eee;opacity:1;}.ace_button:active {background-color: #ddd;}.ace_button.checked {border-color: #3399ff;opacity:1;}.ace_search_options{margin-bottom: 3px;text-align: right;-webkit-user-select: none;-moz-user-select: none;-o-user-select: none;-ms-user-select: none;user-select: none;}",u=e("../keyboard/hash_handler").HashHandler,a=e("../lib/keys");r.importCssString(o,"ace_searchbox");var f='<div class="ace_search right"> <button type="button" action="hide" class="ace_searchbtn_close"></button> <div class="ace_search_form"> <input class="ace_search_field" placeholder="Search for" spellcheck="false"></input> <button type="button" action="findNext" class="ace_searchbtn next"></button> <button type="button" action="findPrev" class="ace_searchbtn prev"></button> <button type="button" action="findAll" class="ace_searchbtn" title="Alt-Enter">All</button> </div> <div class="ace_replace_form"> <input class="ace_search_field" placeholder="Replace with" spellcheck="false"></input> <button type="button" action="replaceAndFindNext" class="ace_replacebtn">Replace</button> <button type="button" action="replaceAll" class="ace_replacebtn">All</button> </div> <div class="ace_search_options"> <span action="toggleRegexpMode" class="ace_button" title="RegExp Search">.*</span> <span action="toggleCaseSensitive" class="ace_button" title="CaseSensitive Search">Aa</span> <span action="toggleWholeWords" class="ace_button" title="Whole Word Search">\\b</span> </div></div>'.replace(/>\s+/g,">"),l=function(e,t,n){var i=r.createElement("div");i.innerHTML=f,this.element=i.firstChild,this.$init(),this.setEditor(e)};(function(){this.setEditor=function(e){e.searchBox=this,e.container.appendChild(this.element),this.editor=e},this.$initElements=function(e){this.searchBox=e.querySelector(".ace_search_form"),this.replaceBox=e.querySelector(".ace_replace_form"),this.searchOptions=e.querySelectLine truncated
|
||||
(function() {
|
||||
window.require(["ace/ext/searchbox"], function() {});
|
||||
})();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
define("ace/mode/css_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("../lib/lang"),s=e("./text_highlight_rules").TextHighlightRules,o=t.supportType="align-content|align-items|align-self|all|animation|animation-delay|animation-direction|animation-duration|animation-fill-mode|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|backface-visibility|background|background-attachment|background-blend-mode|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|border|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|bottom|box-shadow|box-sizing|caption-side|clear|clip|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|cursor|direction|display|empty-cells|filter|flex|flex-basis|flex-direction|flex-flow|flex-grow|flex-shrink|flex-wrap|float|font|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|hanging-punctuation|height|justify-content|left|letter-spacing|line-height|list-style|list-style-image|list-style-position|list-style-type|margin|margin-bottom|margin-left|margin-right|margin-top|max-height|max-width|min-height|min-width|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|order|outline|outline-color|outline-offset|outline-style|outline-width|overflow|overflow-x|overflow-y|padding|padding-bottom|padding-left|padding-right|padding-top|page-break-after|page-break-before|page-break-inside|perspective|perspective-origin|position|quotes|resize|right|tab-size|table-layout|text-align|text-align-last|text-decoration|text-decoration-color|text-decoration-line|text-decoration-style|text-indent|text-justify|text-overflow|text-shadow|text-transform|top|transform|transform-origin|transform-style|transition|transition-delay|transition-duration|transition-property|transition-timing-function|unicode-bidi|vertical-align|visibility|white-space|width|word-break|word-spacing|word-wrap|z-index",u=t.supportFunction="rgb|rgba|url|attr|counter|counters",a=t.supportConstant="absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero",f=t.supportConstantColor="aqua|black|blue|fuchsia|gray|green|lime|marooLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";var r=e("../lib/oop"),i=e("./text_highlight_rules").TextHighlightRules,s=function(){this.$rules={start:[{token:"comment.doc.tag",regex:"@[\\w\\d_]+"},s.getTagRule(),{defaultToken:"comment.doc",caseInsensitive:!0}]}};r.inherits(s,i),s.getTagRule=function(e){return{token:"comment.doc.tag.storage.type",regex:"\\b(?:TODO|FIXME|XXX|HACK)\\b"}},s.getStartRule=function(e){return{token:"comment.doc",regex:"\\/\\*(?=\\*)",next:e}},s.getEndRule=function(e){return{token:"comment.doc",regex:"\\*\\/",next:e}},t.DocCommentHighlightRules=s}),define("ace/mode/javascript_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"],function(e,t,n){"use strict";function a(){var e=o.replace("\\d","\\d\\-"),t={onMatch:function(e,t,n){var r=e.charAt(1)=="/"?2:1;if(r==1)t!=this.nextState?n.unshift(this.next,this.nextState,0):n.unshift(this.next),n[2]++;else if(r==2&&t==this.nextState){n[1]--;if(!n[1]||n[1]<0)n.shift(),n.shift()}return[{type:"meta.tag.punctuation."+(r==1?"":"end-")+"tag-open.xml",value:e.slice(0,r)},{type:"meta.tag.tag-name.xml",value:e.substr(r)}]},regex:"</?"+e+"",next:"jsxAttributes",nextState:"jsx"};this.$rules.start.unshift(t);var n={regex:"{",token:"paren.quasi.start",push:"start"};this.$rules.jsx=[n,t,{include:"reference"},{defaultToken:"string"}],this.$rules.jsxAttributes=[{token:"meta.tag.punctuation.tag-close.xml",regex:"/?>",onMatch:function(e,t,n){return t==n[0]&&n.shift(),e.length==2&&(n[0]==this.nextState&&n[1]--,(!n[1]||n[1]<0)&&n.splice(0,2)),this.next=n[0]||"start",[{type:this.token,value:e}]},nextState:"jsx"},n,f("jsxAttributes"),{token:"entity.other.attribute-name.xml",regex:e},{token:"keyword.operator.attribute-equals.xml",regex:"="},{token:"text.tag-whitespace.xml",regex:"\\s+"},{token:"string.attribute-value.xml",regex:"'",stateName:"jsx_attr_q",push:[{token:"string.attribute-value.xml",regex:"'",next:"pop"},{include:"reference"},{defaultToken:"string.attribute-value.xml"}]},{token:"string.attribute-value.xml",regex:'"',stateName:"jsx_attr_qq",push:[{token:"string.attribute-value.xml",regex:'"',next:"pop"},{include:"reference"},{defaultToken:"string.attribute-value.xml"}]},t],this.$rules.reference=[{token:"constant.language.escape.reference.xml",regex:"(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"}]}function f(e){return[{token:"comment",regex:/\/\*/,next:[i.getTagRule(),{token:"comment",regex:"\\*\\/",next:e||"pop"},{defaultToken:"comment",caseInsensitive:!0}]},{token:"comment",regex:"\\/\\/",next:[i.getTagRule(),{token:"comment",regex:"$|^",next:e||"pop"},{defaultToken:"comment",caseInsensitive:!0}]}]}var r=e("../lib/oop"),i=e("./doc_comment_highlight_rules").DocCommentHighlightRules,s=e("./text_highlight_rules").TextHighlightRules,o="[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*",u=function(e){var t=this.createKeywordMapper({"variable.language":"Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|Namespace|QName|XML|XMLList|ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|JSON|Math|this|arguments|prototype|window|document",keyword:"const|yield|import|get|set|async|await|break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|of|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|__parent__|__count__|escape|unescape|with|__proto__|class|enum|extends|super|export|implements|private|public|interface|package|protected|static","storage.type":"const|let|var|function","constant.language":"null|Infinity|NaN|undefined","support.function":"alert","constant.language.boolean":"true|false"},"identifier"),n="case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void",r="\\\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|u{[0-9a-fA-F]{1,6}}|[0-2][0-7]{0,2}|3[0-7][0-7]?|[4-7][0-7]?|.)";this.$rules={no_regex:[i.getStartRule("doc-start"),f("no_regex"),{token:"string",regex:"'(?=.)",next:"qstring"},{token:"string",regex:'"(?=.)',next:"qqstring"},{token:"constant.numeric",regex:/0(?:[xX][0-9a-fA-F]+|[bB][01]+)\b/},{token:"constant.numeric",regex:/[+-]?\d[\d_]*(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/},{token:["storage.type","punctuation.operator","support.function","punctuation.operator","entity.name.function","text","keyword.operator"],regex:"("+o+")(\\.)(prototype)(\\.)("+o+")(\\s*)(=)",next:"function_arguments"},{token:["storage.type","punctuation.operator","entity.name.function","text","keyword.operator","text","storage.type","text","paren.lparen"],regex:"("+o+")(\\.)("+o+")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",next:"function_arguments"},{toLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
ace.define("ace/theme/usof",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-dawn",t.cssText=".ace-dawn .ace_gutter {background: #f1f1f1;color: #999}.ace-dawn {background-color: #f8f8f8;color: #666}.ace-dawn .ace_cursor {color: #000000}.ace-dawn .ace_marker-layer .ace_selection {background: rgba(30, 30, 30, 0.15)}.ace-dawn .ace_marker-layer .ace_active-line {background: rgba(36, 99, 180, 0.08)}.ace-dawn .ace_gutter-active-line {background-color : #e2e2e2}.ace-dawn .ace_keyword,.ace-dawn .ace_meta {color: #6253ad}.ace-dawn .ace_constant,.ace-dawn .ace_constant.ace_character,.ace-dawn .ace_constant.ace_character.ace_escape,.ace-dawn .ace_constant.ace_other {color: #6253ad}.ace-dawn .ace_support,.ace-dawn .ace_entity {color: #5397db}.ace-dawn .ace_support.ace_constant {color: #6253ad}.ace-dawn .ace_list,.ace-dawn .ace_markup.ace_list,.ace-dawn .ace_support.ace_function {color: #6253ad}.ace-dawn .ace_string {color: #38425c}.ace-dawn .ace_string.ace_regexp {color: #5397db}.ace-dawn .ace_comment {color: #999}.ace-dawn .ace_variable,.ace-dawn .ace_string.ace_attribute-value {color: #009975}";var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
||||
@@ -0,0 +1 @@
|
||||
"no use strict";(function(e){function t(e,t){var n=e,r="";while(n){var i=t[n];if(typeof i=="string")return i+r;if(i)return i.location.replace(/\/*$/,"/")+(r||i.main||i.name);if(i===!1)return"";var s=n.lastIndexOf("/");if(s===-1)break;r=n.substr(s)+r,n=n.slice(0,s)}return e}if(typeof e.window!="undefined"&&e.document)return;if(e.require&&e.define)return;e.console||(e.console=function(){var e=Array.prototype.slice.call(arguments,0);postMessage({type:"log",data:e})},e.console.error=e.console.warn=e.console.log=e.console.trace=e.console),e.window=e,e.ace=e,e.onerror=function(e,t,n,r,i){postMessage({type:"error",data:{message:e,data:i.data,file:t,line:n,col:r,stack:i.stack}})},e.normalizeModule=function(t,n){if(n.indexOf("!")!==-1){var r=n.split("!");return e.normalizeModule(t,r[0])+"!"+e.normalizeModule(t,r[1])}if(n.charAt(0)=="."){var i=t.split("/").slice(0,-1).join("/");n=(i?i+"/":"")+n;while(n.indexOf(".")!==-1&&s!=n){var s=n;n=n.replace(/^\.\//,"").replace(/\/\.\//,"/").replace(/[^\/]+\/\.\.\//,"")}}return n},e.require=function(r,i){i||(i=r,r=null);if(!i.charAt)throw new Error("worker.js require() accepts only (parentId, id) as arguments");i=e.normalizeModule(r,i);var s=e.require.modules[i];if(s)return s.initialized||(s.initialized=!0,s.exports=s.factory().exports),s.exports;if(!e.require.tlns)return console.log("unable to load "+i);var o=t(i,e.require.tlns);return o.slice(-3)!=".js"&&(o+=".js"),e.require.id=i,e.require.modules[i]={},importScripts(o),e.require(r,i)},e.require.modules={},e.require.tlns={},e.define=function(t,n,r){arguments.length==2?(r=n,typeof t!="string"&&(n=t,t=e.require.id)):arguments.length==1&&(r=t,n=[],t=e.require.id);if(typeof r!="function"){e.require.modules[t]={exports:r,initialized:!0};return}n.length||(n=["require","exports","module"]);var i=function(n){return e.require(t,n)};e.require.modules[t]={exports:{},factory:function(){var e=this,t=r.apply(this,n.map(function(t){switch(t){case"require":return i;case"exports":return e.exports;case"module":return e;default:return i(t)}}));return t&&(e.exports=t),e}}},e.define.amd={},require.tlns={},e.initBaseUrls=function(t){for(var n in t)require.tlns[n]=t[n]},e.initSender=function(){var n=e.require("ace/lib/event_emitter").EventEmitter,r=e.require("ace/lib/oop"),i=function(){};return function(){r.implement(this,n),this.callback=function(e,t){postMessage({type:"call",id:t,data:e})},this.emit=function(e,t){postMessage({type:"event",name:e,data:t})}}.call(i.prototype),new i};var n=e.main=null,r=e.sender=null;e.onmessage=function(t){var i=t.data;if(i.event&&r)r._signal(i.event,i.data);else if(i.command)if(n[i.command])n[i.command].apply(n,i.args);else{if(!e[i.command])throw new Error("Unknown command:"+i.command);e[i.command].apply(e,i.args)}else if(i.init){e.initBaseUrls(i.tlns),require("ace/lib/es5-shim"),r=e.sender=e.initSender();var s=require(i.module)[i.classname];n=e.main=new s(r)}}})(this),define("ace/lib/oop",["require","exports","module"],function(e,t,n){"use strict";t.inherits=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},t.mixin=function(e,t){for(var n in t)e[n]=t[n];return e},t.implement=function(e,n){t.mixin(e,n)}}),define("ace/lib/lang",["require","exports","module"],function(e,t,n){"use strict";t.last=function(e){return e[e.length-1]},t.stringReverse=function(e){return e.split("").reverse().join("")},t.stringRepeat=function(e,t){var n="";while(t>0){t&1&&(n+=e);if(t>>=1)e+=e}return n};var r=/^\s\s*/,i=/\s\s*$/;t.stringTrimLeft=function(e){return e.replace(r,"")},t.stringTrimRight=function(e){return e.replace(i,"")},t.copyObject=function(e){var t={};for(var n in e)t[n]=e[n];return t},t.copyArray=function(e){var t=[];for(var n=0,r=e.length;n<r;n++)e[n]&&typeof e[n]=="object"?t[n]=this.copyObject(e[n]):t[n]=e[n];return t},t.deepCopy=function s(e){if(typeof e!="object"||!e)return e;var t;if(Array.isArray(e)){t=[];for(var n=0;n<e.length;n++)t[n]=s(e[n]);return t}if(Object.prototype.toString.call(e)!=="[object Object]")return e;t={};for(var n in e)t[n]=s(e[n]);return t},t.arrayToMap=function(e){var t={};for(var n=0;n<e.length;n++)t[e[n]]=1;return t},t.createMap=function(e){var t=Object.create(null);for(var n in e)t[n]=e[n];return t},t.arrayRemove=function(e,t){for(var n=0;n<=e.length;n++)t===e[n]&&e.splice(n,1)},t.escapeRegExp=function(e){return e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1")},t.escapeHTML=function(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<")},t.getMatchOffsets=function(e,t){var n=[];return e.replace(t,function(e){n.push({offset:arguments[arguments.length-2],length:e.length})}),n},t.deferredCall=function(e){var t=null,n=function(){t=null,e()},r=function(e){return r.cancel(),t=setTimeout(n,e||0),r};return r.schedule=r,r.call=function(){return this.cancel(),e(),r},r.cancel=function(){return clearTimeout(t),t=null,r},r.isPending=function(){return t},r},t.delayedCall=function(e,t){var n=Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
"no use strict";(function(e){function t(e,t){var n=e,r="";while(n){var i=t[n];if(typeof i=="string")return i+r;if(i)return i.location.replace(/\/*$/,"/")+(r||i.main||i.name);if(i===!1)return"";var s=n.lastIndexOf("/");if(s===-1)break;r=n.substr(s)+r,n=n.slice(0,s)}return e}if(typeof e.window!="undefined"&&e.document)return;if(e.require&&e.define)return;e.console||(e.console=function(){var e=Array.prototype.slice.call(arguments,0);postMessage({type:"log",data:e})},e.console.error=e.console.warn=e.console.log=e.console.trace=e.console),e.window=e,e.ace=e,e.onerror=function(e,t,n,r,i){postMessage({type:"error",data:{message:e,data:i.data,file:t,line:n,col:r,stack:i.stack}})},e.normalizeModule=function(t,n){if(n.indexOf("!")!==-1){var r=n.split("!");return e.normalizeModule(t,r[0])+"!"+e.normalizeModule(t,r[1])}if(n.charAt(0)=="."){var i=t.split("/").slice(0,-1).join("/");n=(i?i+"/":"")+n;while(n.indexOf(".")!==-1&&s!=n){var s=n;n=n.replace(/^\.\//,"").replace(/\/\.\//,"/").replace(/[^\/]+\/\.\.\//,"")}}return n},e.require=function(r,i){i||(i=r,r=null);if(!i.charAt)throw new Error("worker.js require() accepts only (parentId, id) as arguments");i=e.normalizeModule(r,i);var s=e.require.modules[i];if(s)return s.initialized||(s.initialized=!0,s.exports=s.factory().exports),s.exports;if(!e.require.tlns)return console.log("unable to load "+i);var o=t(i,e.require.tlns);return o.slice(-3)!=".js"&&(o+=".js"),e.require.id=i,e.require.modules[i]={},importScripts(o),e.require(r,i)},e.require.modules={},e.require.tlns={},e.define=function(t,n,r){arguments.length==2?(r=n,typeof t!="string"&&(n=t,t=e.require.id)):arguments.length==1&&(r=t,n=[],t=e.require.id);if(typeof r!="function"){e.require.modules[t]={exports:r,initialized:!0};return}n.length||(n=["require","exports","module"]);var i=function(n){return e.require(t,n)};e.require.modules[t]={exports:{},factory:function(){var e=this,t=r.apply(this,n.map(function(t){switch(t){case"require":return i;case"exports":return e.exports;case"module":return e;default:return i(t)}}));return t&&(e.exports=t),e}}},e.define.amd={},require.tlns={},e.initBaseUrls=function(t){for(var n in t)require.tlns[n]=t[n]},e.initSender=function(){var n=e.require("ace/lib/event_emitter").EventEmitter,r=e.require("ace/lib/oop"),i=function(){};return function(){r.implement(this,n),this.callback=function(e,t){postMessage({type:"call",id:t,data:e})},this.emit=function(e,t){postMessage({type:"event",name:e,data:t})}}.call(i.prototype),new i};var n=e.main=null,r=e.sender=null;e.onmessage=function(t){var i=t.data;if(i.event&&r)r._signal(i.event,i.data);else if(i.command)if(n[i.command])n[i.command].apply(n,i.args);else{if(!e[i.command])throw new Error("Unknown command:"+i.command);e[i.command].apply(e,i.args)}else if(i.init){e.initBaseUrls(i.tlns),require("ace/lib/es5-shim"),r=e.sender=e.initSender();var s=require(i.module)[i.classname];n=e.main=new s(r)}}})(this),define("ace/lib/oop",["require","exports","module"],function(e,t,n){"use strict";t.inherits=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},t.mixin=function(e,t){for(var n in t)e[n]=t[n];return e},t.implement=function(e,n){t.mixin(e,n)}}),define("ace/lib/lang",["require","exports","module"],function(e,t,n){"use strict";t.last=function(e){return e[e.length-1]},t.stringReverse=function(e){return e.split("").reverse().join("")},t.stringRepeat=function(e,t){var n="";while(t>0){t&1&&(n+=e);if(t>>=1)e+=e}return n};var r=/^\s\s*/,i=/\s\s*$/;t.stringTrimLeft=function(e){return e.replace(r,"")},t.stringTrimRight=function(e){return e.replace(i,"")},t.copyObject=function(e){var t={};for(var n in e)t[n]=e[n];return t},t.copyArray=function(e){var t=[];for(var n=0,r=e.length;n<r;n++)e[n]&&typeof e[n]=="object"?t[n]=this.copyObject(e[n]):t[n]=e[n];return t},t.deepCopy=function s(e){if(typeof e!="object"||!e)return e;var t;if(Array.isArray(e)){t=[];for(var n=0;n<e.length;n++)t[n]=s(e[n]);return t}if(Object.prototype.toString.call(e)!=="[object Object]")return e;t={};for(var n in e)t[n]=s(e[n]);return t},t.arrayToMap=function(e){var t={};for(var n=0;n<e.length;n++)t[e[n]]=1;return t},t.createMap=function(e){var t=Object.create(null);for(var n in e)t[n]=e[n];return t},t.arrayRemove=function(e,t){for(var n=0;n<=e.length;n++)t===e[n]&&e.splice(n,1)},t.escapeRegExp=function(e){return e.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1")},t.escapeHTML=function(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<")},t.getMatchOffsets=function(e,t){var n=[];return e.replace(t,function(e){n.push({offset:arguments[arguments.length-2],length:e.length})}),n},t.deferredCall=function(e){var t=null,n=function(){t=null,e()},r=function(e){return r.cancel(),t=setTimeout(n,e||0),r};return r.schedule=r,r.call=function(){return this.cancel(),e(),r},r.cancel=function(){return clearTimeout(t),t=null,r},r.isPending=function(){return t},r},t.delayedCall=function(e,t){var n=Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
/*! Select2 4.0.5 | https://github.com/select2/select2/blob/master/LICENSE.md */!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c),c}:a(jQuery)}(function(a){var b=function(){if(a&&a.fn&&a.fn.select2&&a.fn.select2.amd)var b=a.fn.select2.amd;var b;return function(){if(!b||!b.requirejs){b?c=b:b={};var a,c,d;!function(b){function e(a,b){return v.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=t.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,t.nodeIdCompat&&x.test(a[g])&&(a[g]=a[g].replace(x,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k<a.length;k++)if("."===(m=a[k]))a.splice(k,1),k-=1;else if(".."===m){if(0===k||1===k&&".."===a[2]||".."===a[k-1])continue;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if((e=p[o.slice(0,l).join("/")])&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(a,c){return function(){var d=w.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),o.apply(b,d.concat([a,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){r[a]=b}}function j(a){if(e(s,a)){var c=s[a];delete s[a],u[a]=!0,n.apply(b,c)}if(!e(r,a)&&!e(u,a))throw new Error("No "+a);return r[a]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return a?k(a):[]}function m(a){return function(){return t&&t.config&&t.config[a]||{}}}var n,o,p,q,r={},s={},t={},u={},v=Object.prototype.hasOwnProperty,w=[].slice,x=/\.js$/;p=function(a,b){var c,d=k(a),e=d[0],g=b[1];return a=d[1],e&&(e=f(e,g),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(g)):f(a,g):(a=f(a,g),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},q={require:function(a){return g(a)},exports:function(a){var b=r[a];return void 0!==b?b:r[a]={}},module:function(a){return{id:a,uri:"",exports:r[a],config:m(a)}}},n=function(a,c,d,f){var h,k,m,n,o,t,v,w=[],x=typeof d;if(f=f||a,t=l(f),"undefined"===x||"function"===x){for(c=!c.length&&d.length?["require","exports","module"]:c,o=0;o<c.length;o+=1)if(n=p(c[o],t),"require"===(k=n.f))w[o]=q.require(a);else if("exports"===k)w[o]=q.exports(a),v=!0;else if("module"===k)h=w[o]=q.module(a);else if(e(r,k)||e(s,k)||e(u,k))w[o]=j(k);else{if(!n.p)throw new Error(a+" missing "+k);n.p.load(n.n,g(f,!0),i(k),{}),w[o]=r[k]}m=d?d.apply(r[a],w):void 0,a&&(h&&h.exports!==b&&h.exports!==r[a]?r[a]=h.exports:m===b&&v||(r[a]=m))}else a&&(r[a]=d)},a=c=o=function(a,c,d,e,f){if("string"==typeof a)return q[a]?q[a](c):j(p(a,l(c)).f);if(!a.splice){if(t=a,t.deps&&o(t.deps,t.callback),!c)return;c.splice?(a=c,c=d,d=null):a=b}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?n(b,a,c,d):setTimeout(function(){n(b,a,c,d)},4),o},o.config=function(a){return o(a)},a._defined=r,d=function(a,b,c){if("string"!=typeof a)throw new Error("See almond README: incorrect module build, no module name");b.splice||(c=b,b=[]),e(r,a)||e(s,a)||(s[a]=[a,b,c])},d.amd={jQuery:!0}}(),b.requirejs=a,b.require=c,b.define=d}}(),b.define("almond",function(){}),b.define("jquery",[],function(){var b=a||$;return null==b&&console&&console.error&&console.error("Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page."),b}),b.define("select2/utils",["jquery"],function(a){function b(a){var b=a.prototype,c=[];for(var d in b){"function"==typeof b[d]&&("constructor"!==d&&c.push(d))}return c}var c={};c.Extend=function(a,b){function c(){this.constructor=a}var d={}.hasOwnProperty;for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},c.Decorate=function(a,c){function d(){var b=Array.prototype.unshift,d=c.prototype.constructor.length,e=a.prototype.constructor;d>0&&(b.call(arguments,a.prototype.constructor),e=c.prototype.constructor),e.apply(this,arguments)}function e(){this.constructor=d}var f=b(c),g=b(a);c.displayName=a.displayName,d.prototype=new e;for(var h=0;h<g.length;h++){var i=g[h];d.prototype[i]=a.prototype[i]}for(var j=(function(a){var b=function(){};a in d.prototype&&(b=d.prototype[a]);var e=c.prototype[a];return function(){return Array.prototype.unshift.call(arguments,b),e.apply(this,arguments)}}),k=0;k<f.length;k++){var l=f[k];d.prototype[l]=j(l)}return d};var d=function(){this.listeners={}};return d.prototype.on=function(a,b){this.listeners=this.listeners||{},a in this.listeners?this.listeners[a].push(b):this.listeners[a]=[b]},d.prototype.trigger=function(a){var b=Array.prototype.slice,c=b.call(arguments,1);this.listeners=this.listeners||{},null==c&&(c=[]),0===c.length&&c.push({}),c[0]Line truncated
|
||||
@@ -0,0 +1,789 @@
|
||||
/*
|
||||
* usof_colpick Color Picker
|
||||
* Copyright 2013 Jose Vargas. Licensed under GPL license.
|
||||
* Based on Stefan Petre's Color Picker www.eyecon.ro, dual licensed under the MIT and GPL licenses
|
||||
*/
|
||||
|
||||
( function( $ ) {
|
||||
var usof_colpick = function() {
|
||||
var
|
||||
tpl = '<div class="usof_colpick">' +
|
||||
'<div class="usof_colpick_color">' +
|
||||
'<div class="usof_colpick_color_overlay1"><div class="usof_colpick_color_overlay2">' +
|
||||
'<div class="usof_colpick_selector_outer"><div class="usof_colpick_selector_inner"></div></div>' +
|
||||
'</div></div>' +
|
||||
'</div>' +
|
||||
'<div class="usof_colpick_hue"><div class="usof_colpick_hue_arrs"></div></div>' +
|
||||
'<div class="usof_colpick_alpha"><div class="usof_colpick_alpha_arrs"></div></div>' +
|
||||
'<div class="usof_colpick_gradient"></div>' +
|
||||
'<div class="usof_colpick_hex_field"><div class="usof_colpick_field_letter">#</div><input type="text" maxlength="6" size="6" /></div>' +
|
||||
// Rgb
|
||||
'<div class="usof_colpick_rgb_r usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">R</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// rGb
|
||||
'<div class="usof_colpick_rgb_g usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">G</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// rgB
|
||||
'<div class="usof_colpick_rgb_b usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">B</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// Hsb
|
||||
'<div class="usof_colpick_hsb_h usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">H</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// hSb
|
||||
'<div class="usof_colpick_hsb_s usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">S</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// hsB
|
||||
'<div class="usof_colpick_hsb_b usof_colpick_field">' +
|
||||
'<div class="usof_colpick_field_letter">B</div><input type="text" maxlength="3" size="3" />' +
|
||||
'</div>' +
|
||||
// Alpha
|
||||
'<div class="usof_colpick_field"><input type="text" maxlength="3" size="3" /></div>' +
|
||||
'</div>',
|
||||
defaults = {
|
||||
showEvent: 'focus',
|
||||
onShow: function() {
|
||||
},
|
||||
onBeforeShow: function() {
|
||||
},
|
||||
onHide: function() {
|
||||
},
|
||||
onChange: function() {
|
||||
},
|
||||
onSubmit: function() {
|
||||
},
|
||||
colorScheme: 'light',
|
||||
livePreview: true,
|
||||
flat: false,
|
||||
layout: 'full',
|
||||
height: 156
|
||||
},
|
||||
transparentImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAMFJREFUeNrsVlsOhCAM7Jg9j97/GHChMTxcC9UPTNatif0AIxhmOlMqSMpIhBiG9k/y43gP+P8Bn/FPkIbiPZQhTRSafXDKoMDL4DNqWn7fNccMlAYF66ZE/8avBvu0qUG1sPvKLQOFlo0GigfvcVGI8cQbNr8plnlxehflPELlMbMhYDzu7zaluj1onM7GL0/sB+ic7pGBxcXu+QkuqhhrJasartXQ9iqPGtQKOO20lKscbtbAIAXk8J/HEYNVgAEAHShEyUuW684AAAAASUVORK5CYII=",
|
||||
//Fill the inputs of the plugin
|
||||
fillRGBAFields = function( hsba, cal ) {
|
||||
var rgb = hsbaToRgba( hsba );
|
||||
$( cal ).data( 'usof_colpick' ).fields
|
||||
.eq( 1 ).val( rgb.r ).end()
|
||||
.eq( 2 ).val( rgb.g ).end()
|
||||
.eq( 3 ).val( rgb.b ).end()
|
||||
.eq( 7 ).val( rgb.a ).end();
|
||||
},
|
||||
fillHSBAFields = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).fields
|
||||
.eq( 4 ).val( Math.round( hsba.h ) ).end()
|
||||
.eq( 5 ).val( Math.round( hsba.s ) ).end()
|
||||
.eq( 6 ).val( Math.round( hsba.b ) ).end()
|
||||
.eq( 7 ).val( hsba.a ).end();
|
||||
},
|
||||
fillHexFields = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).fields.eq( 0 ).val( hsbaToHex( hsba ) );
|
||||
},
|
||||
//Set the round selector position
|
||||
setSelector = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).selector.css( 'backgroundColor', hsbaToHex( {
|
||||
h: hsba.h,
|
||||
s: 100,
|
||||
b: 100
|
||||
} ) );
|
||||
$( cal ).data( 'usof_colpick' ).selectorIndic.css( {
|
||||
left: parseInt( $( cal ).data( 'usof_colpick' ).height * hsba.s / 100, 10 ),
|
||||
top: parseInt( $( cal ).data( 'usof_colpick' ).height * ( 100 - hsba.b ) / 100, 10 )
|
||||
} );
|
||||
},
|
||||
//Set the hue selector position
|
||||
setHue = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).hue.css( 'top', parseInt( $( cal ).data( 'usof_colpick' ).height - $( cal ).data( 'usof_colpick' ).height * hsba.h / 360, 10 ) );
|
||||
},
|
||||
// Set the alpha selector position
|
||||
setAlpha = function( hsba, cal ) {
|
||||
var usof_colpick = $( cal ).data( 'usof_colpick' ),
|
||||
rgba = hsbaToRgba( hsba );
|
||||
if ( hsba.a === undefined ) {
|
||||
hsba.a = 1.;
|
||||
}
|
||||
usof_colpick.alpha.css( 'top', parseInt( $( cal ).data( 'usof_colpick' ).height * ( 1. - hsba.a ) ) );
|
||||
var alphaStyle = 'background: linear-gradient(to bottom, rgb(' + rgba.r + ', ' + rgba.g + ', ' + rgba.b + ') 0%, ';
|
||||
alphaStyle += 'rgba(' + rgba.r + ', ' + rgba.g + ', ' + rgba.b + ', 0) 100%) repeat scroll 0% 0%, transparent url("';
|
||||
alphaStyle += transparentImage + '") repeat scroll 0% 0%/16px;';
|
||||
usof_colpick.alphaContainer.attr( 'style', alphaStyle )
|
||||
},
|
||||
//Set current and new colors
|
||||
setCurrentColor = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).currentColor.css( 'backgroundColor', hsbaToHex( hsba ) );
|
||||
},
|
||||
setNewColor = function( hsba, cal ) {
|
||||
$( cal ).data( 'usof_colpick' ).newColor.css( 'backgroundColor', hsbaToHex( hsba ) );
|
||||
},
|
||||
//Called when the new color is changed
|
||||
change = function( ev ) {
|
||||
var cal = $( this ).parent().parent(), col;
|
||||
if ( this.parentNode.className.indexOf( '_hex' ) > 0 ) {
|
||||
cal.data( 'usof_colpick' ).color = col = hexToHsba( fixHex( this.value ) );
|
||||
fillRGBAFields( col, cal.get( 0 ) );
|
||||
fillHSBAFields( col, cal.get( 0 ) );
|
||||
} else if ( this.parentNode.className.indexOf( '_hsb' ) > 0 ) {
|
||||
col = fixHSBA( {
|
||||
h: parseInt( cal.data( 'usof_colpick' ).fields.eq( 4 ).val(), 10 ),
|
||||
s: parseInt( cal.data( 'usof_colpick' ).fields.eq( 5 ).val(), 10 ),
|
||||
b: parseInt( cal.data( 'usof_colpick' ).fields.eq( 6 ).val(), 10 ),
|
||||
a: parseFloat( cal.data( 'usof_colpick' ).fields.eq( 7 ).val() )
|
||||
} );
|
||||
cal.data( 'usof_colpick' ).color = col;
|
||||
fillRGBAFields( col, cal.get( 0 ) );
|
||||
fillHexFields( col, cal.get( 0 ) );
|
||||
} else {
|
||||
cal.data( 'usof_colpick' ).color = col = rgbaToHsba( fixRGBA( {
|
||||
r: parseInt( cal.data( 'usof_colpick' ).fields.eq( 1 ).val(), 10 ),
|
||||
g: parseInt( cal.data( 'usof_colpick' ).fields.eq( 2 ).val(), 10 ),
|
||||
b: parseInt( cal.data( 'usof_colpick' ).fields.eq( 3 ).val(), 10 ),
|
||||
a: parseFloat( cal.data( 'usof_colpick' ).fields.eq( 7 ).val() )
|
||||
} ) );
|
||||
fillHexFields( col, cal.get( 0 ) );
|
||||
fillHSBAFields( col, cal.get( 0 ) );
|
||||
}
|
||||
setSelector( col, cal.get( 0 ) );
|
||||
setHue( col, cal.get( 0 ) );
|
||||
setAlpha( col, cal.get( 0 ) );
|
||||
setNewColor( col, cal.get( 0 ) );
|
||||
cal.data( 'usof_colpick' ).onChange.apply( cal.parent(), [
|
||||
col,
|
||||
hsbaToHex( col ),
|
||||
hsbaToRgba( col ),
|
||||
cal.data( 'usof_colpick' ).el,
|
||||
0
|
||||
] );
|
||||
},
|
||||
//Change style on blur and on focus of inputs
|
||||
blur = function( ev ) {
|
||||
$( this ).parent().removeClass( 'usof_colpick_focus' );
|
||||
},
|
||||
focus = function() {
|
||||
$( this ).parent().parent().data( 'usof_colpick' ).fields.parent().removeClass( 'usof_colpick_focus' );
|
||||
$( this ).parent().addClass( 'usof_colpick_focus' );
|
||||
},
|
||||
//Increment/decrement arrows functions
|
||||
moveIncrement = function( ev ) {
|
||||
ev.data.field.val( Math.max( 0, Math.min( ev.data.max, parseInt( ev.data.val - ev.pageY + ev.data.y, 10 ) ) ) );
|
||||
if ( ev.data.preview ) {
|
||||
change.apply( ev.data.field.get( 0 ), [ true ] );
|
||||
}
|
||||
return false;
|
||||
},
|
||||
upIncrement = function( ev ) {
|
||||
change.apply( ev.data.field.get( 0 ), [ true ] );
|
||||
ev.data.el.removeClass( 'usof_colpick_slider' ).find( 'input' ).focus();
|
||||
$( document ).off( 'mouseup', upIncrement );
|
||||
$( document ).off( 'mousemove', moveIncrement );
|
||||
return false;
|
||||
},
|
||||
//Hue slider functions
|
||||
downHue = function( ev ) {
|
||||
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
|
||||
var current = {
|
||||
cal: $( this ).parent(),
|
||||
y: $( this ).offset().top
|
||||
};
|
||||
$( document ).on( 'mouseup touchend', current, upHue );
|
||||
$( document ).on( 'mousemove touchmove', current, moveHue );
|
||||
|
||||
var pageY = ( ( ev.type == 'touchstart' ) ? ev.originalEvent.changedTouches[ 0 ].pageY : ev.pageY );
|
||||
change.apply(
|
||||
current.cal.data( 'usof_colpick' )
|
||||
.fields.eq( 4 ).val( parseInt( 360 * ( current.cal.data( 'usof_colpick' ).height - ( pageY - current.y ) ) / current.cal.data( 'usof_colpick' ).height, 10 ) )
|
||||
.get( 0 ),
|
||||
[ current.cal.data( 'usof_colpick' ).livePreview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
moveHue = function( ev ) {
|
||||
var pageY = ( ( ev.type == 'touchmove' ) ? ev.originalEvent.changedTouches[ 0 ].pageY : ev.pageY );
|
||||
change.apply(
|
||||
ev.data.cal.data( 'usof_colpick' )
|
||||
.fields.eq( 4 ).val( parseInt( 360 * ( ev.data.cal.data( 'usof_colpick' ).height - Math.max( 0, Math.min( ev.data.cal.data( 'usof_colpick' ).height, ( pageY - ev.data.y ) ) ) ) / ev.data.cal.data( 'usof_colpick' ).height, 10 ) )
|
||||
.get( 0 ),
|
||||
[ ev.data.preview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
upHue = function( ev ) {
|
||||
fillRGBAFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
fillHexFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
$( document ).off( 'mouseup touchend', upHue );
|
||||
$( document ).off( 'mousemove touchmove', moveHue );
|
||||
return false;
|
||||
},
|
||||
//Alpha slider function
|
||||
downAlpha = function( ev ) {
|
||||
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
|
||||
var current = {
|
||||
cal: $( this ).parent(),
|
||||
y: $( this ).offset().top
|
||||
};
|
||||
$( document ).on( 'mouseup touchend', current, upAlpha );
|
||||
$( document ).on( 'mousemove touchmove', current, moveAlpha );
|
||||
|
||||
var pageY = ( ( ev.type == 'touchstart' ) ? ev.originalEvent.changedTouches[ 0 ].pageY : ev.pageY );
|
||||
change.apply(
|
||||
current.cal.data( 'usof_colpick' )
|
||||
.fields.eq( 7 ).val( ( current.cal.data( 'usof_colpick' ).height - ( pageY - current.y ) ) / current.cal.data( 'usof_colpick' ).height )
|
||||
.get( 0 ),
|
||||
[ current.cal.data( 'usof_colpick' ).livePreview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
moveAlpha = function( ev ) {
|
||||
var pageY = ( ( ev.type == 'touchmove' ) ? ev.originalEvent.changedTouches[ 0 ].pageY : ev.pageY );
|
||||
change.apply(
|
||||
ev.data.cal.data( 'usof_colpick' )
|
||||
.fields.eq( 7 ).val( ( ev.data.cal.data( 'usof_colpick' ).height - ( pageY - ev.data.y ) ) / ev.data.cal.data( 'usof_colpick' ).height )
|
||||
.get( 0 ),
|
||||
[ ev.data.preview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
upAlpha = function( ev ) {
|
||||
fillRGBAFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
fillHexFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
$( document ).off( 'mouseup touchend', upAlpha );
|
||||
$( document ).off( 'mousemove touchmove', moveAlpha );
|
||||
return false;
|
||||
},
|
||||
//Color selector functions
|
||||
downSelector = function( ev ) {
|
||||
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
|
||||
var current = {
|
||||
cal: $( this ).parent(),
|
||||
pos: $( this ).offset()
|
||||
};
|
||||
current.preview = current.cal.data( 'usof_colpick' ).livePreview;
|
||||
|
||||
$( document ).on( 'mouseup touchend', current, upSelector );
|
||||
$( document ).on( 'mousemove touchmove', current, moveSelector );
|
||||
|
||||
var pageX, pageY;
|
||||
if ( ev.type == 'touchstart' ) {
|
||||
pageX = ev.originalEvent.changedTouches[ 0 ].pageX;
|
||||
pageY = ev.originalEvent.changedTouches[ 0 ].pageY;
|
||||
} else {
|
||||
pageX = ev.pageX;
|
||||
pageY = ev.pageY;
|
||||
}
|
||||
|
||||
change.apply(
|
||||
current.cal.data( 'usof_colpick' ).fields
|
||||
.eq( 6 ).val( parseInt( 100 * ( current.cal.data( 'usof_colpick' ).height - ( pageY - current.pos.top ) ) / current.cal.data( 'usof_colpick' ).height, 10 ) ).end()
|
||||
.eq( 5 ).val( parseInt( 100 * ( pageX - current.pos.left ) / current.cal.data( 'usof_colpick' ).height, 10 ) )
|
||||
.get( 0 ),
|
||||
[ current.preview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
moveSelector = function( ev ) {
|
||||
var pageX, pageY;
|
||||
if ( ev.type == 'touchmove' ) {
|
||||
pageX = ev.originalEvent.changedTouches[ 0 ].pageX;
|
||||
pageY = ev.originalEvent.changedTouches[ 0 ].pageY;
|
||||
} else {
|
||||
pageX = ev.pageX;
|
||||
pageY = ev.pageY;
|
||||
}
|
||||
|
||||
change.apply(
|
||||
ev.data.cal.data( 'usof_colpick' ).fields
|
||||
.eq( 6 ).val( parseInt( 100 * ( ev.data.cal.data( 'usof_colpick' ).height - Math.max( 0, Math.min( ev.data.cal.data( 'usof_colpick' ).height, ( pageY - ev.data.pos.top ) ) ) ) / ev.data.cal.data( 'usof_colpick' ).height, 10 ) ).end()
|
||||
.eq( 5 ).val( parseInt( 100 * ( Math.max( 0, Math.min( ev.data.cal.data( 'usof_colpick' ).height, ( pageX - ev.data.pos.left ) ) ) ) / ev.data.cal.data( 'usof_colpick' ).height, 10 ) )
|
||||
.get( 0 ),
|
||||
[ ev.data.preview ]
|
||||
);
|
||||
return false;
|
||||
},
|
||||
upSelector = function( ev ) {
|
||||
fillRGBAFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
fillHexFields( ev.data.cal.data( 'usof_colpick' ).color, ev.data.cal.get( 0 ) );
|
||||
$( document ).off( 'mouseup touchend', upSelector );
|
||||
$( document ).off( 'mousemove touchmove', moveSelector );
|
||||
return false;
|
||||
},
|
||||
//Submit button
|
||||
clickSubmit = function( ev ) {
|
||||
var cal = $( this ).parent();
|
||||
var col = cal.data( 'usof_colpick' ).color;
|
||||
cal.data( 'usof_colpick' ).origColor = col;
|
||||
setCurrentColor( col, cal.get( 0 ) );
|
||||
cal.data( 'usof_colpick' ).onSubmit( col, hsbaToHex( col ), hsbaToRgba( col ), cal.data( 'usof_colpick' ).el );
|
||||
},
|
||||
//Show/Hide the color picker
|
||||
show = function( ev ) {
|
||||
if ( ev ) {ev.stopPropagation();}
|
||||
var cal = $( '#' + $( this ).data( 'usof_colpickId' ) ),
|
||||
pos, top, bottomSpace, that = this,
|
||||
calWrap = $( this ).parent( '.usof-color' ).find( '.usof_colpick_wrap' )[ 0 ],
|
||||
calWrapH = $( calWrap ).height();
|
||||
cal.data( 'usof_colpick' ).onBeforeShow.apply( this, [ cal.get( 0 ) ] );
|
||||
pos = $( this ).offset();
|
||||
top = this.offsetHeight;
|
||||
bottomSpace = document.body.clientHeight - ( pos.top - window.pageYOffset );
|
||||
if ( bottomSpace < calWrapH ) {
|
||||
top = 0 - calWrapH;
|
||||
}
|
||||
$( calWrap ).css( { top: top + 'px' } );
|
||||
cal.data( 'usof_colpick' ).onShow.apply( this, [ cal.get( 0 ) ] );
|
||||
},
|
||||
hide = function( ev ) {
|
||||
if ( ev ) {ev.stopPropagation();}
|
||||
var cal = $( '#' + $( this ).data( 'usof_colpickId' ) );
|
||||
cal.data( 'usof_colpick' ).onHide.apply( this, [ cal.get( 0 ) ] );
|
||||
$( 'html' ).off( 'mousedown', hide );
|
||||
},
|
||||
//Fix the values if the user enters a negative or high value
|
||||
fixHSBA = function( hsba ) {
|
||||
if ( hsba.a === undefined ) {
|
||||
hsba.a = 1.;
|
||||
}
|
||||
return {
|
||||
h: Math.min( 360, Math.max( 0, hsba.h ) ),
|
||||
s: Math.min( 100, Math.max( 0, hsba.s ) ),
|
||||
b: Math.min( 100, Math.max( 0, hsba.b ) ),
|
||||
a: Math.min( 1., Math.max( 0., hsba.a ) )
|
||||
};
|
||||
},
|
||||
fixRGBA = function( rgba ) {
|
||||
if ( rgba.a === undefined ) {
|
||||
rgba.a = 1.;
|
||||
}
|
||||
return {
|
||||
r: Math.min( 255, Math.max( 0, rgba.r ) ),
|
||||
g: Math.min( 255, Math.max( 0, rgba.g ) ),
|
||||
b: Math.min( 255, Math.max( 0, rgba.b ) ),
|
||||
a: Math.min( 1., Math.max( 0., rgba.a ) )
|
||||
};
|
||||
},
|
||||
fixHex = function( hex ) {
|
||||
if ( hex.substr( 0, 5 ) == 'rgba(' ) {
|
||||
var parts = hex.substring( 5, s.length - 1 ).split( ',' ).map( parseFloat );
|
||||
if ( parts.length == 4 ) {
|
||||
return hex;
|
||||
}
|
||||
}
|
||||
var len = 6 - hex.length;
|
||||
if ( len > 0 ) {
|
||||
var o = [];
|
||||
for ( var i = 0; i < len; i ++ ) {
|
||||
o.push( '0' );
|
||||
}
|
||||
o.push( hex );
|
||||
hex = o.join( '' );
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
return {
|
||||
init: function( opt ) {
|
||||
opt = $.extend( {}, defaults, opt || {} );
|
||||
var gradient;
|
||||
//Set color
|
||||
if ( typeof opt.color == 'string' ) {
|
||||
if ( isGradient( opt.color ) ) {
|
||||
gradient = gradientParser( opt.color );
|
||||
opt.color = hexToHsba( gradient.hex );
|
||||
} else {
|
||||
opt.color = hexToHsba( opt.color );
|
||||
}
|
||||
} else if ( opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined ) {
|
||||
opt.color = rgbaToHsba( opt.color );
|
||||
} else if ( opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined ) {
|
||||
opt.color = fixHSBA( opt.color );
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
//For each selected DOM element
|
||||
return this.each( function() {
|
||||
//If the element does not have an ID
|
||||
if ( !$( this ).data( 'usof_colpickId' ) ) {
|
||||
var options = $.extend( {}, opt );
|
||||
options.origColor = opt.color;
|
||||
//Generate and assign a random ID
|
||||
var id = 'collorpicker_' + parseInt( Math.random() * 100000 );
|
||||
$( this ).data( 'usof_colpickId', id );
|
||||
//Set the tpl's ID and get the HTML
|
||||
var cal = $( tpl ).attr( 'id', id );
|
||||
//Add class according to layout
|
||||
cal.addClass( 'usof_colpick_' + options.layout + ( options.submit ? '' : ' usof_colpick_' + options.layout + '_ns' ) );
|
||||
//Add class if the color scheme is not default
|
||||
if ( options.colorScheme != 'light' ) {
|
||||
cal.addClass( 'usof_colpick_' + options.colorScheme );
|
||||
}
|
||||
//Setup submit button
|
||||
cal.find( 'div.usof_colpick_submit' ).html( options.submitText ).click( clickSubmit );
|
||||
//Setup input fields
|
||||
options.fields = cal.find( 'input' ).change( change ).blur( blur ).focus( focus );
|
||||
//Setup hue selector
|
||||
options.selector = cal.find( 'div.usof_colpick_color' ).on( 'mousedown touchstart', downSelector );
|
||||
options.selectorIndic = options.selector.find( 'div.usof_colpick_selector_outer' );
|
||||
//Store parts of the plugin
|
||||
options.el = this;
|
||||
options.hue = cal.find( 'div.usof_colpick_hue_arrs' );
|
||||
var huebar = options.hue.parent();
|
||||
options.alphaContainer = cal.find( 'div.usof_colpick_alpha' );
|
||||
options.alpha = cal.find( 'div.usof_colpick_alpha_arrs' );
|
||||
|
||||
//Paint the hue bar
|
||||
var UA = navigator.userAgent.toLowerCase();
|
||||
var isIE = navigator.appName === 'Microsoft Internet Explorer';
|
||||
var IEver = isIE ? parseFloat( UA.match( /msie ([0-9]{1,}[\.0-9]{0,})/ )[ 1 ] ) : 0;
|
||||
var ngIE = ( isIE && IEver < 10 );
|
||||
var stops = [
|
||||
'#ff0000',
|
||||
'#ff0080',
|
||||
'#ff00ff',
|
||||
'#8000ff',
|
||||
'#0000ff',
|
||||
'#0080ff',
|
||||
'#00ffff',
|
||||
'#00ff80',
|
||||
'#00ff00',
|
||||
'#80ff00',
|
||||
'#ffff00',
|
||||
'#ff8000',
|
||||
'#ff0000'
|
||||
];
|
||||
if ( ngIE ) {
|
||||
var i, div;
|
||||
for ( i = 0; i <= 11; i ++ ) {
|
||||
div = $( '<div></div>' ).attr( 'style', 'height:8.333333%; filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=' + stops[ i ] + ', endColorstr=' + stops[ i + 1 ] + '); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=' + stops[ i ] + ', endColorstr=' + stops[ i + 1 ] + ')";' );
|
||||
huebar.append( div );
|
||||
}
|
||||
} else {
|
||||
var stopList = stops.join( ',' );
|
||||
huebar.attr( 'style', 'background:linear-gradient(to bottom,' + stopList + '); ' );
|
||||
}
|
||||
cal.find( 'div.usof_colpick_hue' ).on( 'mousedown touchstart', downHue );
|
||||
cal.find( 'div.usof_colpick_alpha' ).on( 'mousedown touchstart', downAlpha );
|
||||
options.newColor = cal.find( 'div.usof_colpick_new_color' );
|
||||
options.currentColor = cal.find( 'div.usof_colpick_current_color' );
|
||||
//Store options and fill with default color
|
||||
cal.data( 'usof_colpick', options );
|
||||
fillRGBAFields( options.color, cal.get( 0 ) );
|
||||
fillHSBAFields( options.color, cal.get( 0 ) );
|
||||
fillHexFields( options.color, cal.get( 0 ) );
|
||||
setHue( options.color, cal.get( 0 ) );
|
||||
setAlpha( options.color, cal.get( 0 ) );
|
||||
setSelector( options.color, cal.get( 0 ) );
|
||||
setCurrentColor( options.color, cal.get( 0 ) );
|
||||
setNewColor( options.color, cal.get( 0 ) );
|
||||
//Append to body if flat=false, else show in place
|
||||
if ( options.flat ) {
|
||||
cal.appendTo( this ).show();
|
||||
cal.css( {
|
||||
position: 'relative',
|
||||
display: 'block'
|
||||
} );
|
||||
} else {
|
||||
cal.appendTo( $( this ).parent().children( '.usof_colpick_wrap' ) );
|
||||
if ( options.showEvent == 'focus' ) {
|
||||
$( this ).on( 'focus', function( ev ) {
|
||||
var $that = $( this );
|
||||
setTimeout( function() {
|
||||
$that.select();
|
||||
}, 5 );
|
||||
show.call( this, ev );
|
||||
} );
|
||||
|
||||
$( this ).on( 'blur', function( ev ) {
|
||||
hide.call( this, ev );
|
||||
} );
|
||||
} else {
|
||||
$( this ).on( options.showEvent, function( ev ) {
|
||||
show.call( this, ev, options.showEvent );
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
},
|
||||
showPicker: function() {
|
||||
return this.each( function() {
|
||||
if ( $( this ).data( 'usof_colpickId' ) ) {
|
||||
show.apply( this );
|
||||
}
|
||||
} );
|
||||
},
|
||||
hidePicker: function() {
|
||||
return this.each( function() {
|
||||
if ( $( this ).data( 'usof_colpickId' ) ) {
|
||||
hide.apply( this );
|
||||
}
|
||||
} );
|
||||
},
|
||||
//Sets a color as new and current (default)
|
||||
setColor: function( col, setCurrent ) {
|
||||
var gradient;
|
||||
setCurrent = ( typeof setCurrent === "undefined" ) ? 1 : setCurrent;
|
||||
if ( typeof col == 'string' ) {
|
||||
if ( isGradient( col ) ) {
|
||||
gradient = gradientParser( col );
|
||||
col = hexToHsba( gradient.hex );
|
||||
} else {
|
||||
col = hexToHsba( col );
|
||||
}
|
||||
} else if ( col.r != undefined && col.g != undefined && col.b != undefined ) {
|
||||
col = rgbaToHsba( col );
|
||||
} else if ( col.h != undefined && col.s != undefined && col.b != undefined ) {
|
||||
col = fixHSBA( col );
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
return this.each( function() {
|
||||
if ( $( this ).data( 'usof_colpickId' ) ) {
|
||||
var cal = $( '#' + $( this ).data( 'usof_colpickId' ) );
|
||||
cal.data( 'usof_colpick' ).color = col;
|
||||
cal.data( 'usof_colpick' ).origColor = col;
|
||||
fillRGBAFields( col, cal.get( 0 ) );
|
||||
fillHSBAFields( col, cal.get( 0 ) );
|
||||
fillHexFields( col, cal.get( 0 ) );
|
||||
setHue( col, cal.get( 0 ) );
|
||||
setAlpha( col, cal.get( 0 ) );
|
||||
setSelector( col, cal.get( 0 ) );
|
||||
|
||||
setNewColor( col, cal.get( 0 ) );
|
||||
cal.data( 'usof_colpick' ).onChange.apply( cal.parent(), [
|
||||
col,
|
||||
hsbaToHex( col ),
|
||||
hsbaToRgba( col ),
|
||||
cal.data( 'usof_colpick' ).el,
|
||||
1,
|
||||
gradient,
|
||||
] );
|
||||
if ( setCurrent ) {
|
||||
setCurrentColor( col, cal.get( 0 ) );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
//Color space convertions
|
||||
var hexToRgba = function( hex ) {
|
||||
if ( hex.substr( 0, 5 ) == 'rgba(' ) {
|
||||
var parts = hex.substring( 5, hex.length - 1 ).split( ',' ).map( parseFloat );
|
||||
if ( parts.length == 4 ) {
|
||||
return { r: parts[ 0 ], g: parts[ 1 ], b: parts[ 2 ], a: parts[ 3 ] };
|
||||
}
|
||||
}
|
||||
if ( hex.length == 3 ) {
|
||||
hex = hex.charAt( 0 ) + hex.charAt( 0 ) + hex.charAt( 1 ) + hex.charAt( 0 ) + hex.charAt( 2 ) + hex.charAt( 2 );
|
||||
}
|
||||
hex = parseInt( ( ( hex.indexOf( '#' ) > - 1 ) ? hex.substring( 1 ) : hex ), 16 );
|
||||
return { r: hex >> 16, g: ( hex & 0x00FF00 ) >> 8, b: ( hex & 0x0000FF ), a: 1. };
|
||||
};
|
||||
|
||||
var gradientParser = function( color ) {
|
||||
if ( m = /^linear-gradient\(([\D\d]+)\);?$/.exec( color ) ) {
|
||||
var gradient = m[ 1 ].split( ',' ),
|
||||
directions = [ 'to', 'top', 'right', 'bottom', 'left', 'turn', 'deg' ],
|
||||
index,
|
||||
colors = {
|
||||
colors: [],
|
||||
gradient: color,
|
||||
};
|
||||
|
||||
// Find gradient direction
|
||||
for ( var i = 0; i < directions.length; i ++ ) {
|
||||
index = gradient[ 0 ].indexOf( directions[ i ] );
|
||||
if ( index != - 1 ) {
|
||||
colors.direction = gradient[ 0 ];
|
||||
}
|
||||
}
|
||||
|
||||
// Find color values
|
||||
for ( var i = 0; i < gradient.length; i ++ ) {
|
||||
gradient[ i ] = gradient[ i ].trim();
|
||||
|
||||
// Look for hex values
|
||||
var hex = gradient[ i ].indexOf( '#' );
|
||||
if ( hex !== - 1 ) {
|
||||
var normalizedHex = normalizeHex( gradient[ i ].replace( '#', '' ) );
|
||||
colors.colors.push( normalizedHex );
|
||||
}
|
||||
|
||||
// Look for hex RGB
|
||||
var rgb = gradient[ i ].indexOf( 'rgb(' );
|
||||
if ( rgb !== - 1 ) {
|
||||
var rgbColor = {};
|
||||
|
||||
rgbColor.r = parseInt( gradient[ i ].replace( 'rgb(', '' ).trim() );
|
||||
rgbColor.g = parseInt( gradient[ i + 1 ].trim() );
|
||||
rgbColor.b = parseInt( gradient[ i + 2 ].replace( ')', '' ).trim() );
|
||||
colors.colors.push( rgbColor );
|
||||
}
|
||||
|
||||
// Look for hex RGBa
|
||||
var rgba = gradient[ i ].indexOf( 'rgba(' );
|
||||
if ( rgba !== - 1 ) {
|
||||
var rgbaColor = {};
|
||||
|
||||
rgbaColor.r = parseInt( gradient[ i ].replace( 'rgba(', '' ).trim() );
|
||||
rgbaColor.g = parseInt( gradient[ i + 1 ].trim() );
|
||||
rgbaColor.b = parseInt( gradient[ i + 2 ].trim() );
|
||||
rgbaColor.a = parseFloat( gradient[ i + 3 ].trim().replace( ')', '' ).trim() );
|
||||
colors.colors.push( rgbaColor );
|
||||
}
|
||||
}
|
||||
|
||||
if ( typeof colors.colors[ 0 ] == 'string' ) {
|
||||
colors.hex = colors.colors[ 0 ];
|
||||
} else {
|
||||
// Can be returned as rgba string if rgba object is passed
|
||||
colors.hex = rgbaToHex( colors.colors[ 0 ] );
|
||||
}
|
||||
|
||||
return colors;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Hex should come without leading "#"
|
||||
var normalizeHex = function( hex ) {
|
||||
var hashString;
|
||||
if ( hex.length === 3 ) {
|
||||
hex = '#' + hex[ 0 ] + hex[ 0 ] + hex[ 1 ] + hex[ 1 ] + hex[ 2 ] + hex[ 2 ];
|
||||
} else if ( hex.length <= 6 ) {
|
||||
hashString = hex.split( '' );
|
||||
while ( hashString.length < 6 ) {
|
||||
hashString.unshift( '0' );
|
||||
}
|
||||
hex = '#' + hashString.join( '' );
|
||||
}
|
||||
|
||||
return hex;
|
||||
};
|
||||
|
||||
var isGradient = function( color ) {
|
||||
if ( m = /^linear-gradient\(.+\)$/.exec( color ) ) {
|
||||
return true
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var hexToHsba = function( hex ) {
|
||||
return rgbaToHsba( hexToRgba( hex ) );
|
||||
};
|
||||
var rgbaToHsba = function( rgba ) {
|
||||
var hsba = { h: 0, s: 0, b: 0 };
|
||||
var min = Math.min( rgba.r, rgba.g, rgba.b );
|
||||
var max = Math.max( rgba.r, rgba.g, rgba.b );
|
||||
var delta = max - min;
|
||||
hsba.b = max;
|
||||
hsba.s = max != 0 ? 255 * delta / max : 0;
|
||||
if ( hsba.s != 0 ) {
|
||||
if ( rgba.r == max ) {
|
||||
hsba.h = ( rgba.g - rgba.b ) / delta;
|
||||
} else if ( rgba.g == max ) {
|
||||
hsba.h = 2 + ( rgba.b - rgba.r ) / delta;
|
||||
} else {
|
||||
hsba.h = 4 + ( rgba.r - rgba.g ) / delta;
|
||||
}
|
||||
} else {
|
||||
hsba.h = - 1;
|
||||
}
|
||||
hsba.h *= 60;
|
||||
if ( hsba.h < 0 ) {
|
||||
hsba.h += 360;
|
||||
}
|
||||
hsba.s *= 100 / 255;
|
||||
hsba.b *= 100 / 255;
|
||||
hsba.a = rgba.a;
|
||||
return hsba;
|
||||
};
|
||||
var hsbaToRgba = function( hsba ) {
|
||||
var rgb = {};
|
||||
var h = hsba.h;
|
||||
var s = hsba.s * 255 / 100;
|
||||
var v = hsba.b * 255 / 100;
|
||||
if ( s == 0 ) {
|
||||
rgb.r = rgb.g = rgb.b = v;
|
||||
} else {
|
||||
var t1 = v;
|
||||
var t2 = ( 255 - s ) * v / 255;
|
||||
var t3 = ( t1 - t2 ) * ( h % 60 ) / 60;
|
||||
if ( h == 360 ) {
|
||||
h = 0;
|
||||
}
|
||||
if ( h < 60 ) {
|
||||
rgb.r = t1;
|
||||
rgb.b = t2;
|
||||
rgb.g = t2 + t3
|
||||
} else if ( h < 120 ) {
|
||||
rgb.g = t1;
|
||||
rgb.b = t2;
|
||||
rgb.r = t1 - t3
|
||||
} else if ( h < 180 ) {
|
||||
rgb.g = t1;
|
||||
rgb.r = t2;
|
||||
rgb.b = t2 + t3
|
||||
} else if ( h < 240 ) {
|
||||
rgb.b = t1;
|
||||
rgb.r = t2;
|
||||
rgb.g = t1 - t3
|
||||
} else if ( h < 300 ) {
|
||||
rgb.b = t1;
|
||||
rgb.g = t2;
|
||||
rgb.r = t2 + t3
|
||||
} else if ( h < 360 ) {
|
||||
rgb.r = t1;
|
||||
rgb.g = t2;
|
||||
rgb.b = t1 - t3
|
||||
} else {
|
||||
rgb.r = 0;
|
||||
rgb.g = 0;
|
||||
rgb.b = 0
|
||||
}
|
||||
}
|
||||
return { r: Math.round( rgb.r ), g: Math.round( rgb.g ), b: Math.round( rgb.b ), a: hsba.a };
|
||||
};
|
||||
var rgbaToHex = function( rgba ) {
|
||||
if ( rgba.a !== undefined && rgba.a < 1. ) {
|
||||
return 'rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + Math.round( rgba.a * 100 ) / 100 + ')';
|
||||
}
|
||||
var hex = [
|
||||
rgba.r.toString( 16 ),
|
||||
rgba.g.toString( 16 ),
|
||||
rgba.b.toString( 16 )
|
||||
];
|
||||
$.each( hex, function( nr, val ) {
|
||||
if ( val.length == 1 ) {
|
||||
hex[ nr ] = '0' + val;
|
||||
}
|
||||
} );
|
||||
return '#' + hex.join( '' );
|
||||
};
|
||||
var hsbaToHex = function( hsba ) {
|
||||
return rgbaToHex( hsbaToRgba( hsba ) );
|
||||
};
|
||||
$.fn.extend( {
|
||||
usof_colpick: usof_colpick.init,
|
||||
usof_colpickSetColor: usof_colpick.setColor,
|
||||
usof_colpickShow: usof_colpick.showPicker,
|
||||
usof_colpickHide: usof_colpick.hidePicker
|
||||
} );
|
||||
$.extend( {
|
||||
usof_colpick: {
|
||||
normalizeHex: normalizeHex,
|
||||
rgbaToHex: rgbaToHex,
|
||||
rgbaToHsb: rgbaToHsba,
|
||||
hsbaToHex: hsbaToHex,
|
||||
hsbaToRgba: hsbaToRgba,
|
||||
hexToHsba: hexToHsba,
|
||||
hexToRgba: hexToRgba,
|
||||
gradientParser: gradientParser,
|
||||
isGradient: isGradient,
|
||||
}
|
||||
} );
|
||||
} )( jQuery );
|
||||
+2994
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,203 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Output single USOF Field
|
||||
*
|
||||
* Multiple selector
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
* @var $values array Set of values for the current and relevant fields
|
||||
*/
|
||||
|
||||
if ( isset( $field['place_if'] ) AND ! $field['place_if'] ) {
|
||||
return;
|
||||
}
|
||||
if ( ! isset( $field['type'] ) ) {
|
||||
if ( WP_DEBUG ) {
|
||||
wp_die( $name . ' has no defined type' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$show_field = ( ! isset( $field['show_if'] ) OR usof_execute_show_if( $field['show_if'], $values ) );
|
||||
|
||||
// Options Wrapper
|
||||
if ( $field['type'] == 'wrapper_start' ) {
|
||||
$row_classes = '';
|
||||
if ( isset( $field['classes'] ) AND ! empty( $field['classes'] ) ) {
|
||||
$row_classes .= ' ' . $field['classes'];
|
||||
}
|
||||
echo '<div class="usof-form-wrapper ' . $name . $row_classes . '" data-name="' . $name . '" data-id="' . $id . '" ';
|
||||
echo 'style="display: ' . ( $show_field ? 'block' : 'none' ) . '">';
|
||||
if ( isset( $field['title'] ) AND ! empty( $field['title'] ) ) {
|
||||
echo '<div class="usof-form-wrapper-title">' . $field['title'] . '</div>';
|
||||
}
|
||||
echo '<div class="usof-form-wrapper-content">';
|
||||
if ( isset( $field['show_if'] ) AND is_array( $field['show_if'] ) AND ! empty( $field['show_if'] ) ) {
|
||||
// Showing conditions
|
||||
echo '<div class="usof-form-wrapper-showif hidden"' . us_pass_data_to_js( $field['show_if'] ) . '></div>';
|
||||
}
|
||||
|
||||
return;
|
||||
} elseif ( $field['type'] == 'wrapper_end' ) {
|
||||
echo '</div></div>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$field['std'] = isset( $field['std'] ) ? $field['std'] : NULL;
|
||||
$value = isset( $values[ $name ] ) ? $values[ $name ] : $field['std'];
|
||||
|
||||
// Options Group
|
||||
if ( $field['type'] == 'group' ) {
|
||||
global $usof_options;
|
||||
|
||||
$group_classes = ( ! empty( $field['classes'] ) ) ? ' ' . $field['classes'] : '';
|
||||
if ( isset( $field['is_accordion'] ) AND $field['is_accordion'] ) {
|
||||
$group_classes .= ' type_accordion';
|
||||
} else {
|
||||
$group_classes .= ' type_simple';
|
||||
}
|
||||
if ( isset( $field['is_sortable'] ) AND $field['is_sortable'] ) {
|
||||
$group_classes .= ' sortable';
|
||||
}
|
||||
echo '<div class="usof-form-group' . $group_classes . '" data-name="' . $name . '"';
|
||||
if ( ! empty( $field['title'] ) ) {
|
||||
echo ' data-params_title="' . rawurlencode( $field['title'] ) . '"';
|
||||
}
|
||||
echo 'style="display: ' . ( $show_field ? 'block' : 'none' ) . '">';
|
||||
echo '<div class="usof-form-group-prototype hidden">';
|
||||
us_load_template(
|
||||
'vendor/usof/templates/fields/group_param', array(
|
||||
'params_values' => array(),
|
||||
'field' => $field,
|
||||
)
|
||||
);
|
||||
echo '</div>';
|
||||
|
||||
if ( is_array( $value ) AND count( $value ) > 0 ) {
|
||||
foreach ( $value as $index => $params_values ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/fields/group_param', array(
|
||||
'params_values' => $params_values,
|
||||
'field' => $field,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
echo '<span class="usof-form-group-add">';
|
||||
echo '<span class="usof-form-group-add-title">' . us_translate( 'Add' ) . '</span>';
|
||||
echo '<span class="usof-preloader"></span>';
|
||||
echo '</span>';
|
||||
$translations = array(
|
||||
'deleteConfirm' => __( 'Are you sure want to delete the element?', 'us' ),
|
||||
'style' => us_translate( 'Style' ),
|
||||
);
|
||||
echo '<span class="usof-form-group-translations hidden"' . us_pass_data_to_js( $translations ) . '></span>';
|
||||
if ( isset( $field['show_if'] ) AND is_array( $field['show_if'] ) AND ! empty( $field['show_if'] ) ) {
|
||||
// Showing conditions
|
||||
echo '<div class="usof-form-row-showif hidden"' . us_pass_data_to_js( $field['show_if'] ) . '></div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$row_classes = ' type_' . $field['type'];
|
||||
if ( ! in_array(
|
||||
$field['type'], array(
|
||||
'message',
|
||||
'heading',
|
||||
)
|
||||
) AND ( ! isset( $field['classes'] ) OR strpos( $field['classes'], 'desc_' ) === FALSE ) ) {
|
||||
$row_classes .= ' desc_1';
|
||||
}
|
||||
if ( isset( $field['cols'] ) ) {
|
||||
$row_classes .= ' cols_' . $field['cols'];
|
||||
}
|
||||
if ( isset( $field['classes'] ) AND ! empty( $field['classes'] ) ) {
|
||||
$row_classes .= ' ' . $field['classes'];
|
||||
}
|
||||
|
||||
// Output option row
|
||||
echo '<div class="usof-form-row' . $row_classes . '" data-name="' . $name . '" data-id="' . $id . '" ';
|
||||
echo 'style="display: ' . ( $show_field ? 'block' : 'none' ) . '">';
|
||||
if ( isset( $field['title'] ) AND ! empty( $field['title'] ) ) {
|
||||
echo '<div class="usof-form-row-title"><span>' . $field['title'] . '</span>';
|
||||
if ( isset( $field['description'] ) AND ! empty( $field['description'] ) AND ( ! empty( $field['classes'] ) AND strpos( $field['classes'], 'desc_4' ) !== FALSE ) ) {
|
||||
echo '<div class="usof-form-row-desc">';
|
||||
echo '<div class="usof-form-row-desc-icon"></div>';
|
||||
echo '<div class="usof-form-row-desc-text">' . $field['description'] . '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '<div class="usof-form-row-field"><div class="usof-form-row-control">';
|
||||
// Including the field control itself
|
||||
us_load_template(
|
||||
'vendor/usof/templates/fields/' . $field['type'], array(
|
||||
'name' => $name,
|
||||
'id' => $id,
|
||||
'field' => $field,
|
||||
'value' => $value,
|
||||
'is_metabox' => ( isset( $is_metabox ) ) ? $is_metabox : FALSE,
|
||||
)
|
||||
);
|
||||
echo '</div>';
|
||||
if ( isset( $field['description'] ) AND ! empty( $field['description'] ) AND ( empty( $field['classes'] ) OR strpos( $field['classes'], 'desc_4' ) === FALSE ) ) {
|
||||
echo '<div class="usof-form-row-desc">';
|
||||
echo '<div class="usof-form-row-desc-icon"></div>';
|
||||
echo '<div class="usof-form-row-desc-text">' . $field['description'] . '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ( isset( $field['hints_for'] ) ) {
|
||||
|
||||
// Check if post type exist
|
||||
$post_type_obj = get_post_type_object( $field['hints_for'] );
|
||||
|
||||
if ( $post_type_obj ) {
|
||||
|
||||
$hint_text = '';
|
||||
|
||||
// Get post labels for hints
|
||||
$hints = array(
|
||||
'edit_url' => '<a href="' . admin_url( 'post.php?post={{post_id}}&action=edit' ) . '" target="_blank">{{hint}}</a>',
|
||||
// for JS
|
||||
'add' => $post_type_obj->labels->add_new,
|
||||
'edit' => __( 'Edit selected', 'us' ),
|
||||
);
|
||||
|
||||
// Count published posts
|
||||
$count_posts = wp_count_posts( $field['hints_for'] );
|
||||
$published_posts = $count_posts->publish;
|
||||
if ( $published_posts ) {
|
||||
|
||||
$edit_link = get_edit_post_link( $value );
|
||||
|
||||
// Output "Edit" link if post exists and assigned
|
||||
if ( $edit_link AND $value ) {
|
||||
$hint_text = '<a href="' . $edit_link . '" target="_blank">' . $hints['edit'] . '</a>';
|
||||
}
|
||||
|
||||
// Output "Add New" link if there are no published posts
|
||||
} else {
|
||||
$hint_text = '<a href="' . admin_url( 'post-new.php?post_type=' . $field['hints_for'] ) . '" target="_blank">' . $hints['add'] . '</a>';
|
||||
$hints['no_posts'] = TRUE;
|
||||
}
|
||||
|
||||
unset( $hints['add'] );
|
||||
|
||||
echo '<div class="usof-form-row-hint-text">' . $hint_text . '</div>';
|
||||
echo '<div class="usof-form-row-hint-json hidden"' . us_pass_data_to_js( $hints ) . '></div>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</div>'; // .usof-form-row-field
|
||||
if ( isset( $field['show_if'] ) AND is_array( $field['show_if'] ) AND ! empty( $field['show_if'] ) ) {
|
||||
// Showing conditions
|
||||
echo '<div class="usof-form-row-showif"' . us_pass_data_to_js( $field['show_if'] ) . '></div>';
|
||||
}
|
||||
echo '</div>';
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Backup
|
||||
*
|
||||
* Store / restore options backup
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$backup = get_option( 'usof_backup_' . US_THEMENAME );
|
||||
|
||||
$output = '<div class="usof-backup">';
|
||||
$output .= '<div class="usof-backup-status">';
|
||||
if ( $backup AND is_array( $backup ) AND isset( $backup['time'] ) ) {
|
||||
$backup_time = strtotime( $backup['time'] ) + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
|
||||
$output .= __( 'Last Backup', 'us' ) . ': <span>' . date_i18n( 'F j, Y - G:i T', $backup_time ) . '</span>';
|
||||
} else {
|
||||
$output .= __( 'No backups yet', 'us' );
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="usof-button type_backup"><span>' . __( 'Backup Options', 'us' ) . '</span>';
|
||||
$output .= '<span class="usof-preloader"></span>';
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="usof-button type_restore"';
|
||||
if ( ! $backup OR ! is_array( $backup ) OR ! isset( $backup['usof_options'] ) ) {
|
||||
$output .= ' style="display: none"';
|
||||
}
|
||||
$output .= '><span class="usof-button-label">' . __( 'Restore Options', 'us' ) . '</span>';
|
||||
$output .= '<span class="usof-preloader"></span>';
|
||||
$output .= '</div>';
|
||||
$i18n = array(
|
||||
'restore_confirm' => __( 'Are you sure want to restore options from the backup?', 'us' ),
|
||||
);
|
||||
$output .= '<div class="usof-backup-i18n"' . us_pass_data_to_js( $i18n ) . '></div>';
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Check Table
|
||||
*
|
||||
* Multiple selector as table
|
||||
*
|
||||
* @var $id string Field ID
|
||||
* @var $name string Field name
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array List of key => title pairs
|
||||
*
|
||||
* @var $value array List of checked keys
|
||||
*/
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array();
|
||||
}
|
||||
if ( isset( $is_metabox ) AND $is_metabox ) {
|
||||
$name .= '[]';
|
||||
}
|
||||
|
||||
$output = '<ul class="usof-checkbox-list">';
|
||||
foreach ( $field['options'] as $key => $option ) {
|
||||
|
||||
if ( $option['group'] != NULL ) {
|
||||
$output .= '</ul><ul class="usof-checkbox-list"><li class="usof-checkbox-list-title">' . $option['group'] . '</li>';
|
||||
}
|
||||
if ( isset( $option['apply_if'] ) AND ! $option['apply_if'] ) {
|
||||
continue;
|
||||
}
|
||||
$output .= '<li class="usof-checkbox for_' . $key . '"><label>';
|
||||
$output .= '<input type="checkbox" name="' . $name . '" value="' . esc_attr( $key ) . '"';
|
||||
if ( in_array( $key, $value ) ) {
|
||||
$output .= ' checked';
|
||||
}
|
||||
$output .= '>';
|
||||
$output .= '<span class="usof-checkbox-icon"></span>';
|
||||
$output .= '<span class="usof-checkbox-text"><span>' . $option['title'] . '</span></span>';
|
||||
$output .= '<span class="usof-checkbox-size for_js">';
|
||||
if ( isset( $option['js_size'] ) AND $option['js_size'] ) {
|
||||
$output .= $option['js_size'];
|
||||
} else {
|
||||
$output .= '-';
|
||||
}
|
||||
$output .= '</span>';
|
||||
$output .= '<span class="usof-checkbox-size for_css">';
|
||||
if ( isset( $option['css_size'] ) AND $option['css_size'] ) {
|
||||
$output .= $option['css_size'];
|
||||
} else {
|
||||
$output .= '-';
|
||||
}
|
||||
$output .= '</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '<div class="usof-checkbox-description"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
$output .= '<div class="usof-checkbox-list-desc">' . __( 'All sizes in kilobytes', 'us' ) . '</div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Checkboxes
|
||||
*
|
||||
* Multiple selector
|
||||
*
|
||||
* @var $id string Field ID
|
||||
* @var $name string Field name
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array List of key => title pairs
|
||||
*
|
||||
* @var $value array List of checked keys
|
||||
*/
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array();
|
||||
}
|
||||
if ( isset( $is_metabox ) AND $is_metabox ) {
|
||||
$name .= '[]';
|
||||
}
|
||||
|
||||
$output = '<ul class="usof-checkbox-list">';
|
||||
foreach ( $field['options'] as $key => $option_title ) {
|
||||
$output .= '<li class="usof-checkbox"><label>';
|
||||
$output .= '<input type="checkbox" name="' . $name . '" value="' . esc_attr( $key ) . '"';
|
||||
if ( in_array( $key, $value ) ) {
|
||||
$output .= ' checked';
|
||||
}
|
||||
$output .= '><span class="usof-checkbox-icon"></span><span class="usof-checkbox-text">' . $option_title . '</span>';
|
||||
$output .= '</label></li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Color
|
||||
*
|
||||
* Simple color picker
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['text'] string Field additional text
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
if ( preg_match( '~^\#([\da-f])([\da-f])([\da-f])$~', $value, $matches ) ) {
|
||||
$value = '#' . $matches[1] . $matches[1] . $matches[2] . $matches[2] . $matches[3] . $matches[3];
|
||||
}
|
||||
|
||||
$palette = get_option( 'usof_color_palette_' . US_THEMENAME );
|
||||
if ( ! is_array( $palette ) ) {
|
||||
$palette = array();
|
||||
}
|
||||
|
||||
$gradient = strstr( $value, 'linear-gradient' ) ? ' with_gradient' : '';
|
||||
|
||||
$output = '<div class="usof-color' . $gradient . '">';
|
||||
$output .= '<div class="usof-color-preview" style="background: ' . $value . '"></div>';
|
||||
$output .= '<input class="usof-color-value" type="text" name="' . $name . '" value="' . esc_attr( $value ) . '" />';
|
||||
$output .= '<div class="usof-color-clear" title="' . us_translate( 'Clear' ) . '"></div>';
|
||||
|
||||
$output .= '<div class="usof_colpick_wrap">';
|
||||
$output .= '<div class="usof_colpick_palette">';
|
||||
|
||||
// Fill palette with default colors
|
||||
if ( empty( $palette ) ) {
|
||||
global $usof_options;
|
||||
|
||||
$options = $usof_options;
|
||||
$predefined_colors = array(
|
||||
$options['color_content_primary'],
|
||||
$options['color_content_secondary'],
|
||||
$options['color_content_heading'],
|
||||
$options['color_content_text'],
|
||||
$options['color_content_faded'],
|
||||
$options['color_content_border'],
|
||||
$options['color_content_bg_alt'],
|
||||
$options['color_content_bg'],
|
||||
);
|
||||
|
||||
update_option( 'usof_color_palette_' . US_THEMENAME, $predefined_colors );
|
||||
}
|
||||
|
||||
foreach ( $palette as $color ) {
|
||||
$output .= '<div class="usof_colpick_palette_value"><span style="background:' . $color . '" title="' . esc_attr( $color ) . '"></span><div class="usof_colpick_palette_delete" title="' . us_translate( 'Delete' ) . '"></div></div>';
|
||||
}
|
||||
$output .= '<div class="usof_colpick_palette_add" title="' . __( 'Add the current color to the palette', 'us' ) . '"></div>';
|
||||
$output .= '</div></div></div>';
|
||||
|
||||
if ( isset( $field['text'] ) AND ! empty( $field['text'] ) ) {
|
||||
$output .= '<div class="usof-color-text">' . $field['text'] . '</div>';
|
||||
}
|
||||
echo $output;
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Css
|
||||
*
|
||||
* Simple textarea field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
global $usof_directory_uri;
|
||||
|
||||
$output = '<div class="usof-form-row-control-ace"></div>';
|
||||
$output .= '<div class="usof-form-row-control-param"';
|
||||
$output .= us_pass_data_to_js(
|
||||
array(
|
||||
'ace_path' => $usof_directory_uri . '/js/ace/ace.js',
|
||||
'ace_ext_sarch_path' => $usof_directory_uri . '/js/ace/ext-searchbox.js',
|
||||
)
|
||||
);
|
||||
$output .= '></div>';
|
||||
$output .= '<textarea name="' . $name . '">' . esc_textarea( $value ) . '</textarea>';
|
||||
// $output .= '<div class="usof-form-row-resize"><div class="usof-form-row-resize-knob"><span></span></div></div>';
|
||||
|
||||
echo $output;
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: design_options
|
||||
*
|
||||
* Design options.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
* @var $field['states'] array Available states: array( 'default', 'mobiles', 'tablets' )
|
||||
* @var $field['with_position'] bool Show position controls
|
||||
*
|
||||
* @var $value array Current value
|
||||
*/
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array();
|
||||
}
|
||||
|
||||
$directions = array( 'top', 'right', 'bottom', 'left' );
|
||||
$states = ( isset( $field['states'] ) AND is_array( $field['states'] ) ) ? $field['states'] : array( 'default', 'tablets', 'mobiles' );
|
||||
$states_titles = array(
|
||||
'default' => us_translate( 'Default' ),
|
||||
'tablets' => __( 'Tablets', 'us' ),
|
||||
'mobiles' => __( 'Mobiles', 'us' ),
|
||||
);
|
||||
$with_position = ( isset( $field['with_position'] ) AND $field['with_position'] );
|
||||
|
||||
$output = '<div class="usof-design">';
|
||||
foreach ( $states as $state ) {
|
||||
$state_title = us_arr_path( $states_titles, $state, $state );
|
||||
$output .= '<div class="usof-design-control for_' . $state . '">';
|
||||
$output .= '<div class="usof-design-control-title">' . $state_title . '</div>';
|
||||
|
||||
if ( $with_position ) {
|
||||
// Checking if position is enabled
|
||||
$pos_enabled = FALSE;
|
||||
foreach ( $directions as $part ) {
|
||||
$subname = 'position_' . $part . '_' . $state;
|
||||
if ( isset( $value[ $subname ] ) AND $value[ $subname ] !== '' ) {
|
||||
$pos_enabled = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Positioning Switcher
|
||||
$output .= '<div class="usof-switcher">';
|
||||
$output .= '<input type="hidden" name="pos_abs_' . $state . '" value="0" />';
|
||||
$output .= '<input type="checkbox" id="' . $id . '_pos_abs_' . $state . '" name="pos_abs_' . $state . '" value="1"' . ( $pos_enabled ? ' checked="checked"' : '' ) . '>';
|
||||
$output .= '<label for="' . $id . '_pos_abs_' . $state . '">';
|
||||
$output .= '<span class="usof-switcher-box"><i></i></span>';
|
||||
$output .= '<span class="usof-switcher-text">' . __( 'Absolute Positioning', 'us' ) . '</span>';
|
||||
$output .= '</label></div>';
|
||||
|
||||
// Position
|
||||
$output .= '<div class="usof-design-position' . ( $pos_enabled ? '' : ' pos_off' ) . '">';
|
||||
$output .= '<div class="usof-design-attr">Position</div>';
|
||||
foreach ( $directions as $part ) {
|
||||
$subname = 'position_' . $part . '_' . $state;
|
||||
$subvalue = isset( $value[ $subname ] ) ? $value[ $subname ] : '';
|
||||
if ( preg_match( '~^\d+$~', $subvalue ) ) {
|
||||
$subvalue = $subvalue . 'px';
|
||||
}
|
||||
$output .= '<input class="' . $part . '" type="text" name="' . esc_attr( $subname ) . '" value="' . esc_attr( $subvalue ) . '">';
|
||||
}
|
||||
}
|
||||
|
||||
// Margin
|
||||
$output .= '<div class="usof-design-margin">';
|
||||
$output .= '<div class="usof-design-attr">Margin</div>';
|
||||
foreach ( $directions as $part ) {
|
||||
$subname = 'margin_' . $part . '_' . $state;
|
||||
$subvalue = isset( $value[ $subname ] ) ? $value[ $subname ] : '';
|
||||
if ( preg_match( '~^\d+$~', $subvalue ) ) {
|
||||
$subvalue = $subvalue . 'px';
|
||||
}
|
||||
$output .= '<input class="' . $part . '" type="text" name="' . esc_attr( $subname ) . '" value="' . esc_attr( $subvalue ) . '">';
|
||||
}
|
||||
|
||||
// Border
|
||||
$output .= '<div class="usof-design-border">';
|
||||
$output .= '<div class="usof-design-attr">Border</div>';
|
||||
foreach ( $directions as $part ) {
|
||||
$subname = 'border_' . $part . '_' . $state;
|
||||
$subvalue = isset( $value[ $subname ] ) ? $value[ $subname ] : '';
|
||||
if ( preg_match( '~^\d+$~', $subvalue ) ) {
|
||||
$subvalue = $subvalue . 'px';
|
||||
}
|
||||
$output .= '<input class="' . $part . '" type="text" name="' . esc_attr( $subname ) . '" value="' . esc_attr( $subvalue ) . '">';
|
||||
}
|
||||
|
||||
// Padding
|
||||
$output .= '<div class="usof-design-padding">';
|
||||
$output .= '<div class="usof-design-attr">Padding</div>';
|
||||
foreach ( $directions as $part ) {
|
||||
$subname = 'padding_' . $part . '_' . $state;
|
||||
$subvalue = isset( $value[ $subname ] ) ? $value[ $subname ] : '';
|
||||
if ( preg_match( '~^\d+$~', $subvalue ) ) {
|
||||
$subvalue = $subvalue . 'px';
|
||||
}
|
||||
$output .= '<input class="' . $part . '" type="text" name="' . esc_attr( $subname ) . '" value="' . esc_attr( $subvalue ) . '">';
|
||||
}
|
||||
$output .= '</div>';
|
||||
|
||||
// .usof-design-border
|
||||
$output .= '</div>';
|
||||
|
||||
// .usof-design-margin
|
||||
$output .= '</div>';
|
||||
|
||||
if ( $with_position ) {
|
||||
// .usof-design-position
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
// .usof-design-control
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Font
|
||||
*
|
||||
* Select font
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['only_google'] bool
|
||||
* @param $field ['preview'] array
|
||||
* @param $field ['preview']['text'] string Preview text
|
||||
* @param $field ['preview']['size'] string Font size in css format
|
||||
*
|
||||
* @var $value array List of checked keys
|
||||
*/
|
||||
|
||||
global $usof_options;
|
||||
|
||||
$output = $uploaded_fonts_output = '';
|
||||
$font_value = explode( '|', $value, 2 );
|
||||
if ( ! isset( $font_value[1] ) OR empty( $font_value[1] ) ) {
|
||||
$font_value[1] = '400,700';
|
||||
}
|
||||
$font_value[1] = explode( ',', $font_value[1] );
|
||||
|
||||
// Uploaded Fonts
|
||||
$uploaded_font_families = array();
|
||||
$uploaded_fonts = us_get_option( 'uploaded_fonts', array() );
|
||||
if ( is_array( $uploaded_fonts ) AND count( $uploaded_fonts ) > 0 ) {
|
||||
$uploaded_fonts_output .= '<optgroup label="' . __( 'Uploaded Fonts', 'us' ) . '">';
|
||||
foreach ( $uploaded_fonts as $uploaded_font ) {
|
||||
$uploaded_font_name = strip_tags( $uploaded_font['name'] );
|
||||
if ( $uploaded_font_name == '' OR in_array( $uploaded_font_name, $uploaded_font_families ) OR empty( $uploaded_font['files'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$uploaded_font_families[] = $uploaded_font_name;
|
||||
$uploaded_fonts_output .= "<option class='uploaded' value='" . esc_attr( $uploaded_font_name ) . "' " . selected( $font_value[0], $uploaded_font_name, FALSE ) . '>' . $uploaded_font_name . '</option>';
|
||||
}
|
||||
$uploaded_fonts_output .= '</optgroup>';
|
||||
}
|
||||
|
||||
if ( ! isset( $web_safe_fonts ) ) {
|
||||
$web_safe_fonts = us_config( 'web-safe-fonts' );
|
||||
}
|
||||
|
||||
if ( ! isset( $google_fonts ) ) {
|
||||
$google_fonts = us_config( 'google-fonts', array() );
|
||||
if ( ! isset( $usof_options['google_fonts_included'] ) ) {
|
||||
$usof_options['google_fonts_included'] = TRUE;
|
||||
$output .= '<div class="usof-fonts-json"' . us_pass_data_to_js( $google_fonts ) . '></div>';
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '<div class="usof-font">';
|
||||
|
||||
// Font preview
|
||||
$field['preview'] = isset( $field['preview'] ) ? $field['preview'] : array();
|
||||
$field['preview']['text'] = isset( $field['preview']['text'] ) ? $field['preview']['text'] : '0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
$output .= '<div class="usof-font-preview" style="background: ' . $usof_options['color_content_bg'] . ';';
|
||||
if ( isset( $field['preview']['for_heading'] ) AND $field['preview']['for_heading'] ) {
|
||||
if ( $usof_options[ $field['preview']['color_field'] ] ) {
|
||||
$output .= 'color: ' . $usof_options[ $field['preview']['color_field'] ] . ';';
|
||||
} else {
|
||||
$output .= 'color: ' . $usof_options['color_content_heading'] . ';';
|
||||
}
|
||||
} else {
|
||||
$output .= 'color: ' . $usof_options['color_content_text'] . ';';
|
||||
}
|
||||
if ( isset( $field['preview']['size_field'] ) AND ! empty( $usof_options[ $field['preview']['size_field'] ] ) ) {
|
||||
$output .= 'font-size: ' . $usof_options[ $field['preview']['size_field'] ] . ';';
|
||||
}
|
||||
if ( isset( $field['preview']['lineheight_field'] ) AND ! empty( $usof_options[ $field['preview']['lineheight_field'] ] ) ) {
|
||||
$output .= 'line-height: ' . $usof_options[ $field['preview']['lineheight_field'] ] . ';';
|
||||
}
|
||||
if ( isset( $field['preview']['letterspacing_field'] ) AND ! empty( $usof_options[ $field['preview']['letterspacing_field'] ] ) ) {
|
||||
$output .= 'letter-spacing: ' . $usof_options[ $field['preview']['letterspacing_field'] ] . ';';
|
||||
}
|
||||
if ( isset( $field['preview']['transform_field'] ) AND ! empty( $usof_options[ $field['preview']['transform_field'] ] ) ) {
|
||||
if ( in_array( 'uppercase', $usof_options[ $field['preview']['transform_field'] ] ) ) {
|
||||
$output .= 'text-transform: uppercase;';
|
||||
}
|
||||
if ( in_array( 'italic', $usof_options[ $field['preview']['transform_field'] ] ) ) {
|
||||
$output .= 'font-style: italic;';
|
||||
}
|
||||
}
|
||||
if ( isset( $field['preview']['weight_field'] ) AND ! empty( $usof_options[ $field['preview']['weight_field'] ] ) ) {
|
||||
$output .= 'font-weight: ' . $usof_options[ $field['preview']['weight_field'] ] . ';';
|
||||
} elseif ( count( $font_value[1] ) > 0 ) {
|
||||
$output .= 'font-weight: ' . intval( $font_value[1][0] ) . ';';
|
||||
}
|
||||
$output .= '"><div>' . $field['preview']['text'] . '</div></div>';
|
||||
|
||||
$output .= '<input type="hidden" name="' . $name . '" value="' . esc_attr( $value ) . '" />';
|
||||
$output .= '<select>';
|
||||
|
||||
// Output if 'only_google' param is not set
|
||||
if ( ! isset( $field['only_google'] ) OR ! $field['only_google'] ) {
|
||||
$output .= '<option value="none" ' . selected( $font_value[0], 'none', FALSE ) . '>' . __( 'No font specified', 'us' ) . '</option>';
|
||||
|
||||
if ( isset( $field['preview']['get_h1'] ) AND $field['preview']['get_h1'] ) {
|
||||
$output .= '<option value="get_h1" ' . selected( $font_value[0], 'get_h1', FALSE ) . '>' . __( 'As in Heading 1', 'us' ) . '</option>';
|
||||
}
|
||||
|
||||
// Uploaded Fonts
|
||||
$output .= $uploaded_fonts_output;
|
||||
|
||||
// Web safe fonts
|
||||
$output .= '<optgroup label="' . __( 'Web safe font combinations (do not need to be loaded)', 'us' ) . '">';
|
||||
foreach ( $web_safe_fonts as $font_name ) {
|
||||
$output .= '<option class="websafe" value="' . esc_attr( $font_name ) . '" ' . selected( $font_value[0], $font_name, FALSE ) . '>' . $font_name . '</option>';
|
||||
}
|
||||
$output .= '</optgroup>';
|
||||
}
|
||||
// Google Fonts
|
||||
$output .= '<optgroup label="' . __( 'Google Fonts (loaded from Google servers)', 'us' ) . '">';
|
||||
foreach ( $google_fonts as $font_name => &$tmp_font_value ) {
|
||||
if ( $font_name == '' OR in_array( $font_name, $uploaded_font_families ) ) {
|
||||
continue;
|
||||
}
|
||||
$output .= '<option value="' . esc_attr( $font_name ) . '"' . selected( $font_value[0], $font_name, FALSE ) . '>' . $font_name . '</option>';
|
||||
}
|
||||
$output .= '</optgroup>';
|
||||
|
||||
$output .= '</select>';
|
||||
|
||||
// Font weights
|
||||
if ( ! isset( $font_weights ) ) {
|
||||
$font_weights = array(
|
||||
'100' => '100 ' . __( 'thin', 'us' ),
|
||||
'100italic' => '100 ' . __( 'thin', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'200' => '200 ' . __( 'extra-light', 'us' ),
|
||||
'200italic' => '200 ' . __( 'extra-light', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'300' => '300 ' . __( 'light', 'us' ),
|
||||
'300italic' => '300 ' . __( 'light', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'400' => '400 ' . __( 'normal', 'us' ),
|
||||
'400italic' => '400 ' . __( 'normal', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'500' => '500 ' . __( 'medium', 'us' ),
|
||||
'500italic' => '500 ' . __( 'medium', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'600' => '600 ' . __( 'semi-bold', 'us' ),
|
||||
'600italic' => '600 ' . __( 'semi-bold', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'700' => '700 ' . __( 'bold', 'us' ),
|
||||
'700italic' => '700 ' . __( 'bold', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'800' => '800 ' . __( 'extra-bold', 'us' ),
|
||||
'800italic' => '800 ' . __( 'extra-bold', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
'900' => '900 ' . __( 'ultra-bold', 'us' ),
|
||||
'900italic' => '900 ' . __( 'ultra-bold', 'us' ) . ' <i>' . __( 'italic', 'us' ) . '</i>',
|
||||
);
|
||||
}
|
||||
$show_weights = (array) us_config( 'google-fonts.' . $font_value[0] . '.variants', array() );
|
||||
|
||||
$output .= '<ul class="usof-checkbox-list">';
|
||||
foreach ( $font_weights as $font_weight => $font_title ) {
|
||||
$output .= '<li class="usof-checkbox' . ( in_array( $font_weight, $show_weights ) ? '' : ' hidden' ) . '" data-value="' . $font_weight . '">';
|
||||
$output .= '<label class="' . ( in_array( $font_weight, $show_weights ) ? '' : 'hidden' ) . '">';
|
||||
$output .= '<input type="checkbox" value="' . $font_weight . '"';
|
||||
$output .= ( in_array( $font_weight, $font_value[1] ) ? ' checked' : '' );
|
||||
$output .= '>';
|
||||
$output .= '<span class="usof-checkbox-icon"></span><span class="usof-checkbox-text">';
|
||||
$output .= $font_title . '</span></label></li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
$font_style_fields_data = array();
|
||||
if ( isset( $field['preview']['color_field'] ) ) {
|
||||
$font_style_fields_data['colorField'] = $field['preview']['color_field'];
|
||||
}
|
||||
if ( isset( $field['preview']['size_field'] ) ) {
|
||||
$font_style_fields_data['sizeField'] = $field['preview']['size_field'];
|
||||
}
|
||||
if ( isset( $field['preview']['lineheight_field'] ) ) {
|
||||
$font_style_fields_data['lineheightField'] = $field['preview']['lineheight_field'];
|
||||
}
|
||||
if ( isset( $field['preview']['weight_field'] ) ) {
|
||||
$font_style_fields_data['weightField'] = $field['preview']['weight_field'];
|
||||
}
|
||||
if ( isset( $field['preview']['letterspacing_field'] ) ) {
|
||||
$font_style_fields_data['letterspacingField'] = $field['preview']['letterspacing_field'];
|
||||
}
|
||||
if ( isset( $field['preview']['transform_field'] ) ) {
|
||||
$font_style_fields_data['transformField'] = $field['preview']['transform_field'];
|
||||
}
|
||||
|
||||
$output .= '<div class="usof-font-style-fields-json"' . us_pass_data_to_js( $font_style_fields_data ) . '></div>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: grid_builder
|
||||
*
|
||||
* Advanced header builder.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @var $value array Current value
|
||||
*/
|
||||
global $usof_directory, $usof_directory_uri;
|
||||
|
||||
if ( ! empty( $value ) AND is_string( $value ) AND $value[0] === '{' ) {
|
||||
$value = json_decode( $value, TRUE );
|
||||
}
|
||||
$value = us_fix_grid_settings( $value );
|
||||
|
||||
$output = '<div class="us-bld" data-ajaxurl="' . esc_attr( admin_url( 'admin-ajax.php' ) ) . '">';
|
||||
|
||||
// States
|
||||
$output .= '<div class="us-bld-states" style="display: none;">';
|
||||
$output .= '<div class="us-bld-state for_default active">' . us_translate( 'Default' ) . '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
// Workspace
|
||||
$output .= '<div class="us-bld-workspace for_default">';
|
||||
|
||||
global $us_gb_post_date_types, $us_gb_product_field_types;
|
||||
$us_gb_post_date_types = array(
|
||||
'published' => __( 'Date of creation', 'us' ),
|
||||
'modified' => __( 'Date of update', 'us' ),
|
||||
);
|
||||
// Get the values of "type" param of "Product data" element
|
||||
$us_gb_product_field_types = us_config( 'elements/product_field.params.type.options', array() );
|
||||
|
||||
// Editor
|
||||
if ( ! function_exists( 'usgb_get_elms_placeholders' ) ) {
|
||||
/**
|
||||
* Prepare HTML for elements list for a certain elements area
|
||||
*
|
||||
* @param array $layout
|
||||
* @param array $data Elements data
|
||||
* @param string $place
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function usgb_get_elms_placeholders( &$layout, &$data, $place ) {
|
||||
$output = '';
|
||||
if ( ! isset( $layout[ $place ] ) OR ! is_array( $layout[ $place ] ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
foreach ( $layout[ $place ] as $elm ) {
|
||||
// Checking if the element has absolute position (= at least one design options position is not empty)
|
||||
$is_abs = FALSE;
|
||||
foreach ( array( 'left', 'top', 'right', 'bottom' ) as $direction ) {
|
||||
$direction_value = us_arr_path( $data, $elm . '.design_options.position_' . $direction . '_default', '' );
|
||||
if ( $direction_value !== '' ) {
|
||||
$is_abs = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( substr( $elm, 1, 7 ) == 'wrapper' ) {
|
||||
$output .= '<div class="us-bld-editor-wrapper type_' . ( ( $elm[0] == 'h' ) ? 'horizontal' : 'vertical' );
|
||||
$output .= $is_abs ? ' pos_abs' : '';
|
||||
if ( ! isset( $layout[ $elm ] ) OR empty( $layout[ $elm ] ) ) {
|
||||
$output .= ' empty';
|
||||
}
|
||||
$output .= '" data-id="' . esc_attr( $elm ) . '">';
|
||||
$output .= '<div class="us-bld-editor-wrapper-content">';
|
||||
$output .= usgb_get_elms_placeholders( $layout, $data, $elm );
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="us-bld-editor-wrapper-controls">';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_add" title="' . esc_attr( __( 'Add element into wrapper', 'us' ) ) . '"></a>';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_edit" title="' . esc_attr( __( 'Edit wrapper', 'us' ) ) . '"></a>';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_delete" title="' . esc_attr( __( 'Delete wrapper', 'us' ) ) . '"></a>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div><!-- .us-bld-editor-wrapper -->';
|
||||
} else {
|
||||
// Handling standard single element
|
||||
$type = strtok( $elm, ':' );
|
||||
$elm_title = us_config( 'elements/' . $type . '.title', $type );
|
||||
$values = isset( $data[ $elm ] ) ? $data[ $elm ] : array();
|
||||
|
||||
$output .= '<div class="us-bld-editor-elm type_' . $type;
|
||||
$output .= $is_abs ? ' pos_abs' : '';
|
||||
$output .= '" data-id="' . esc_attr( $elm ) . '">';
|
||||
$output .= '<div class="us-bld-editor-elm-content">';
|
||||
if ( ! empty( $values['icon'] ) ) {
|
||||
$output .= us_prepare_icon_tag( $values['icon'] );
|
||||
}
|
||||
if ( $type == 'text' AND isset( $values['text'] ) AND ( ! empty( $values['text'] ) OR ! empty( $values['icon'] ) ) ) {
|
||||
$output .= strip_tags( $values['text'] );
|
||||
} elseif ( $type == 'btn' ) {
|
||||
if ( ! empty( $values['icon'] ) ) {
|
||||
$output .= us_prepare_icon_tag( $values['icon'] );
|
||||
}
|
||||
if ( ! empty( $values['label'] ) ) {
|
||||
$output .= strip_tags( $values['label'] );
|
||||
} elseif ( empty( $values['icon'] ) ) {
|
||||
$output .= __( 'Button', 'us' );
|
||||
}
|
||||
} elseif ( $type == 'post_taxonomy' AND isset( $values['taxonomy_name'] ) ) {
|
||||
$taxonomies_options = us_get_taxonomies();
|
||||
$output .= us_arr_path( $taxonomies_options, $values['taxonomy_name'], $elm_title );
|
||||
} elseif ( $type == 'post_custom_field' AND isset( $values['key'] ) ) {
|
||||
$custom_fields_options = us_get_custom_fields();
|
||||
$output .= us_arr_path( $custom_fields_options, $values['key'], $elm_title );
|
||||
if ( $values['key'] === 'custom' ) {
|
||||
$output .= ': ' . strip_tags( us_arr_path( $values, 'custom_key', '' ) );
|
||||
}
|
||||
} elseif ( $type == 'post_date' AND isset( $values['type'] ) ) {
|
||||
global $us_gb_post_date_types;
|
||||
$output .= us_arr_path( $us_gb_post_date_types, $values['type'], $elm_title );
|
||||
} elseif ( $type == 'product_field' AND isset( $values['type'] ) ) {
|
||||
global $us_gb_product_field_types;
|
||||
$output .= us_arr_path( $us_gb_product_field_types, $values['type'], $elm_title );
|
||||
if ( $values['type'] == 'sale_badge' AND ! empty ( $values['sale_text'] ) ) {
|
||||
$output .= ': "' . strip_tags( $values['sale_text'] ) . '"';
|
||||
}
|
||||
} else {
|
||||
$output .= $elm_title;
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="us-bld-editor-elm-controls">';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_edit" title="' . esc_attr( __( 'Edit element', 'us' ) ) . '"></a>';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_clone" title="' . esc_attr( __( 'Duplicate element', 'us' ) ) . '"></a>';
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-control type_delete" title="' . esc_attr( __( 'Delete element', 'us' ) ) . '"></a>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
$output .= '<div class="us-bld-editor">';
|
||||
$output .= '<div class="us-bld-editor-row at_middle">';
|
||||
$output .= '<div class="us-bld-editor-row-h">';
|
||||
$output .= '<div class="us-bld-editor-cell at_center">';
|
||||
// Output inner widgets
|
||||
// keeping middle_center for compatibility
|
||||
$output .= usgb_get_elms_placeholders( $value['default']['layout'], $value['data'], 'middle_center' );
|
||||
$output .= '<a href="javascript:void(0)" class="us-bld-editor-add" title="' . esc_attr( __( 'Add element', 'us' ) ) . '"></a>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div><!-- .us-bld-editor -->';
|
||||
|
||||
// Options
|
||||
$output .= '<div class="us-bld-options">';
|
||||
$hb_options_sections = array(
|
||||
'global' => __( 'Grid Layout Settings', 'us' ),
|
||||
// 'hover' => __( 'On hover', 'us' ),
|
||||
);
|
||||
|
||||
$options_values = us_arr_path( $value, 'default.options', array() );
|
||||
// Setting starting state to properly handle show_if rules
|
||||
$options_values['state'] = 'default';
|
||||
foreach ( $hb_options_sections as $hb_section => $hb_section_title ) {
|
||||
$output .= '<div class="us-bld-options-section' . ( ( $hb_section == 'global' ) ? ' active' : '' ) . '" data-id="' . $hb_section . '">';
|
||||
$output .= '<div class="us-bld-options-section-title">' . $hb_section_title . '</div>';
|
||||
$output .= '<div class="us-bld-options-section-content" style="display: ' . ( ( $hb_section == 'global' ) ? 'block' : 'none' ) . ';">';
|
||||
foreach ( us_config( 'grid-settings.options.' . $hb_section, array() ) as $field_name => $fld ) {
|
||||
if ( ! isset( $fld['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$field_html = us_get_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $field_name,
|
||||
'id' => 'hb_opt_' . $field_name,
|
||||
'field' => $fld,
|
||||
'values' => $options_values,
|
||||
)
|
||||
);
|
||||
// Changing rows' classes to prevent auto-init of these rows as main fields
|
||||
$field_html = preg_replace( '~usof\-form\-(row|wrapper) ~', 'usof-subform-$1 ', $field_html );
|
||||
$output .= $field_html;
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= ' </div ><!-- .us-bld-options -->';
|
||||
|
||||
$output .= '<div class="us-bld-params hidden"';
|
||||
$output .= us_pass_data_to_js(
|
||||
array(
|
||||
'navMenus' => us_get_nav_menus(),
|
||||
)
|
||||
);
|
||||
$output .= '></div>';
|
||||
$output .= '<div class="us-bld-value hidden"' . us_pass_data_to_js( $value ) . '></div>';
|
||||
|
||||
// Elements' default values
|
||||
$elms_titles = array();
|
||||
$elms_defaults = array();
|
||||
|
||||
foreach ( us_config( 'grid-settings.elements', array() ) as $type ) {
|
||||
$elm = us_config( 'elements/' . $type );
|
||||
$elms_titles[ $type ] = isset( $elm['title'] ) ? $elm['title'] : $type;
|
||||
$elms_defaults[ $type ] = us_get_elm_defaults( $type, 'grid' );
|
||||
}
|
||||
$output .= '<div class="us-bld-defaults hidden"' . us_pass_data_to_js( $elms_defaults ) . '></div>';
|
||||
$translations = array(
|
||||
'template_replace_confirm' => __( 'Selected template will overwrite all your current elements and settings! Are you sure want to apply it?', 'us' ),
|
||||
'orientation_change_confirm' => __( 'Are you sure want to change the header orientation? Some of your elements\' positions may be changed', 'us' ),
|
||||
'element_delete_confirm' => __( 'Are you sure want to delete the element?', 'us' ),
|
||||
'add_element' => __( 'Add element into wrapper', 'us' ),
|
||||
'edit_element' => __( 'Edit element', 'us' ),
|
||||
'clone_element' => __( 'Duplicate element', 'us' ),
|
||||
'delete_element' => __( 'Delete element', 'us' ),
|
||||
'edit_wrapper' => __( 'Edit wrapper', 'us' ),
|
||||
'delete_wrapper' => __( 'Delete wrapper', 'us' ),
|
||||
'posts_taxonomies' => us_get_taxonomies(),
|
||||
'custom_fields_options' => us_get_custom_fields(),
|
||||
'post_date_types' => $us_gb_post_date_types,
|
||||
'product_field_types' => $us_gb_product_field_types,
|
||||
);
|
||||
|
||||
// Setting elements titles for translations
|
||||
$translations['elms_titles'] = array();
|
||||
foreach ( us_config( 'grid-settings.elements', array() ) as $elm ) {
|
||||
$elm_config = us_config( 'elements/' . $elm );
|
||||
$translations['elms_titles'][ $elm ] = us_arr_path( $elm_config, 'title', $elm );
|
||||
}
|
||||
|
||||
$output .= '<div class="us-bld-translations hidden"' . us_pass_data_to_js( $translations ) . '></div>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
// List of elements that can be added
|
||||
$output .= us_get_template(
|
||||
'templates/elist', array(
|
||||
'elements' => us_config( 'grid-settings.elements', array() ),
|
||||
)
|
||||
);
|
||||
|
||||
// Empty editor window for loading the elements afterwards
|
||||
$output .= us_get_template(
|
||||
'templates/ebuilder', array(
|
||||
'titles' => $elms_titles,
|
||||
'body' => '',
|
||||
)
|
||||
);
|
||||
|
||||
// Export & Import
|
||||
$output .= us_get_template(
|
||||
'templates/export_import', array(
|
||||
'title' => __( 'Export / Import', 'us' ),
|
||||
'text' => __( 'To import another Grid Layout replace the text in this field and click "Import" button.', 'us' ),
|
||||
'save_text' => __( 'Import Grid Layout', 'us' ),
|
||||
)
|
||||
);
|
||||
|
||||
// Empty grid layout templates window for loading the templates afterwards
|
||||
$output .= us_get_template(
|
||||
'templates/gtemplates', array(
|
||||
'body' => '',
|
||||
)
|
||||
);
|
||||
echo $output;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Grid Layout Select
|
||||
*
|
||||
* Drop-down selector field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
// Get Grid Layouts
|
||||
$templates_config = us_config( 'grid-templates', array(), TRUE );
|
||||
|
||||
$custom_layouts = array_flip( us_get_posts_titles_for( 'us_grid_layout' ) );
|
||||
|
||||
$output = '<div class="usof-grid-layout-select">';
|
||||
$output .= '<select name="' . $name . '">';
|
||||
$output .= '<optgroup label="' . __( 'Grid Layouts', 'us' ) . '">';
|
||||
foreach ( $custom_layouts as $title => $id ) {
|
||||
$output .= '<option value="' . $id . '"';
|
||||
if ( $value == $id ) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
$output .= ' data-edit-url="' . admin_url( '/post.php?post=' . $id . '&action=edit' ) . '">' . $title . '</option>';
|
||||
}
|
||||
$current_tmpl_group = '';
|
||||
foreach ( $templates_config as $template_name => $template ) {
|
||||
if ( ! empty( $template['group'] ) AND $current_tmpl_group != $template['group'] ) {
|
||||
$current_tmpl_group = $template['group'];
|
||||
$output .= '</optgroup>';
|
||||
$output .= '<optgroup label="' . $template['group'] . '">';
|
||||
}
|
||||
$output .= '<option value="' . $template_name . '"';
|
||||
if ( $value == $template_name ) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
$output .= '>' . $template['title'] . '</option>';
|
||||
}
|
||||
$output .= '</optgroup>';
|
||||
$output .= '</select>';
|
||||
$output .= '<div class="us-grid-layout-desc-edit">';
|
||||
$output .= sprintf( _x( '%sEdit selected%s or %screate a new one%s.', 'Grid Layout', 'us' ), '<a href="#" class="edit-link" target="_blank">', '</a>', '<a href="' . admin_url() . 'post-new.php?post_type=us_grid_layout" target="_blank">', '</a>' );
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="us-grid-layout-desc-add">';
|
||||
$output .= '<a href="' . admin_url() . 'post-new.php?post_type=us_grid_layout" target="_blank">' . __( 'Add Grid Layout', 'us' ) . '</a>.';
|
||||
$output .= '</div></div>';
|
||||
|
||||
echo $output;
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Group
|
||||
*
|
||||
* Grouped options
|
||||
*
|
||||
* @var $field array Group options
|
||||
* @var $params_values array Group values
|
||||
*
|
||||
*/
|
||||
|
||||
$param_content_styles = '';
|
||||
$output = '<div class="usof-form-group-item">';
|
||||
|
||||
// Output Title block when Accordion type is set
|
||||
if ( isset( $field[ 'is_accordion' ] ) AND $field[ 'is_accordion' ] ) {
|
||||
$param_title = ( ! empty( $field['title'] ) ) ? $field['title'] : '';
|
||||
foreach ( $field['params'] as $param_name => $param ) {
|
||||
if ( strpos( $param_title, '{{' . $param_name . '}}' ) !== FALSE ) {
|
||||
$param_value = isset( $params_values[$param_name] ) ? $params_values[$param_name] : $field['params'][$param_name]['std'];
|
||||
$param_value = esc_attr( trim( $param_value ) );
|
||||
$param_title = str_replace( '{{' . $param_name . '}}', $param_value, $param_title );
|
||||
}
|
||||
}
|
||||
$output .= '<div class="usof-form-group-item-title">';
|
||||
|
||||
// Output Button Preview when class "for_btns" is set
|
||||
if ( isset( $field['classes'] ) AND strpos( $field['classes'], 'for_btns' ) !== FALSE ) {
|
||||
$output .= '<div class="usof-btn-preview hov_fade">';
|
||||
$output .= '<div class="usof-btn">';
|
||||
$output .= '<div class="usof-btn-before"></div>';
|
||||
$output .= '<span class="usof-btn-label">' . $param_title . '</span>';
|
||||
$output .= '<div class="usof-btn-after"></div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= $param_title;
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
$param_content_styles = ' style="display:none;"';
|
||||
}
|
||||
|
||||
$output .= '<div class="usof-form-group-item-content"' . $param_content_styles . '>';
|
||||
ob_start();
|
||||
foreach ( $field['params'] as $param_name => $param ) {
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => $param_name,
|
||||
'id' => 'usof_' . $param_name,
|
||||
'field' => $param,
|
||||
'values' => $params_values,
|
||||
)
|
||||
);
|
||||
}
|
||||
$output .= ob_get_clean();
|
||||
$output .= '</div>';
|
||||
$output .= '<div class="usof-form-group-item-controls">';
|
||||
if ( isset( $field['is_sortable'] ) AND $field['is_sortable'] ) {
|
||||
$output .= '<div class="usof-control-move" title="' . us_translate( 'Move' ) . '"></div>';
|
||||
}
|
||||
$output .= '<div class="usof-control-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</div></div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Heading
|
||||
*
|
||||
* Simple heading.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Html
|
||||
*
|
||||
* Simple textarea field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['encoded'] bool Value is encoded
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
global $usof_directory_uri;
|
||||
|
||||
$data = array(
|
||||
'ace_path' => $usof_directory_uri . '/js/ace/ace.js',
|
||||
'ace_ext_sarch_path' => $usof_directory_uri . '/js/ace/ext-searchbox.js',
|
||||
);
|
||||
if ( isset( $field['encoded'] ) AND $field['encoded'] ) {
|
||||
$data['encoded'] = 1;
|
||||
}
|
||||
|
||||
$output = '<div class="usof-form-row-control-ace"></div>';
|
||||
$output .= '<div class="usof-form-row-control-param"';
|
||||
$output .= us_pass_data_to_js($data);
|
||||
$output .= '></div>';
|
||||
|
||||
$output .= '<textarea name="' . $name . '">' . esc_textarea( $value ) . '</textarea>';
|
||||
// $output .= '<div class="usof-form-row-resize"><div class="usof-form-row-resize-knob"><span></span></div></div>';
|
||||
|
||||
echo $output;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Icon
|
||||
*
|
||||
* Icon field with preview
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['text'] string Field additional text
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$icon_sets = us_config( 'icon-sets', array() );
|
||||
|
||||
reset( $icon_sets );
|
||||
$value = trim( $value );
|
||||
if ( ! preg_match( '/(fas|far|fal|fab|material)\|[a-z0-9-]/i', $value ) ) {
|
||||
$value = $field['std'];
|
||||
}
|
||||
$select_value = $input_value = '';
|
||||
$value_arr = explode('|', $value);
|
||||
if ( count( $value_arr ) == 2 ) {
|
||||
$select_value = $value_arr[0];
|
||||
$input_value = $value_arr[1];
|
||||
}
|
||||
if ( empty( $select_value ) ) {
|
||||
$select_value = key( $icon_sets );
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="us-icon">
|
||||
<input name="<?php echo esc_attr( $name ); ?>" class="us-icon-value" type="hidden" value="<?php echo esc_attr( $value ); ?>">
|
||||
<div class="usof-select">
|
||||
<select name="icon_set" class="us-icon-select">
|
||||
<?php foreach ( $icon_sets as $set_slug => $set_info ) { ?>
|
||||
<option value="<?php echo $set_slug ?>"<?php if ( $select_value == $set_slug ) echo ' selected="selected"'; ?> data-info-url="<?php echo $set_info['set_url'] ?>"><?php echo $set_info['set_name'] ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="us-icon-preview">
|
||||
<?php echo ( $icon_preview_html = us_prepare_icon_tag( $value ) ) ? $icon_preview_html : '<i class="material-icons"></i>'; ?>
|
||||
</div>
|
||||
<div class="us-icon-input">
|
||||
<input name="icon_name" class="us-icon-text" type="text" value="<?php echo $input_value; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="us-icon-desc">
|
||||
<?php echo '<a class="us-icon-set-link" href="' . $icon_sets[$select_value]['set_url'] . '" target="_blank">' . __( 'Enter icon name from the list', 'us' ) . '</a>. ' . __( 'Examples:', 'us' ) . ' <span class="usof-example">star</span>, <span class="usof-example">edit</span>, <span class="usof-example">code</span>' ?>
|
||||
</div>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Images
|
||||
*
|
||||
* Radiobutton-like toggler of images
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array Associative array of value => image
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
global $us_template_directory_uri;
|
||||
|
||||
$output = '<ul class="usof-imgradio">';
|
||||
foreach ( $field['options'] as $key => $img_url ) {
|
||||
$output .= '<li class="usof-imgradio-item">';
|
||||
$output .= '<input type="radio" id="' . $id . '_' . $key . '" name="' . $name . '"' . checked( $value, $key, FALSE ) . ' value="' . esc_attr( $key ) . '">';
|
||||
$output .= '<label for="' . $id . '_' . $key . '"><img src="' . trailingslashit( $us_template_directory_uri ) . $img_url . '.png" srcset="' . trailingslashit( $us_template_directory_uri ) . $img_url . '-2x.png 2x" alt="' . $key . '"></label>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Link
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['text'] string Field additional text
|
||||
*
|
||||
* @var $value string Current value
|
||||
*
|
||||
* @param $value ['url'] string Link URL
|
||||
* @param $value ['target'] string Link Target
|
||||
*/
|
||||
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array(
|
||||
'url' => is_string( $value ) ? $value : '',
|
||||
);
|
||||
}
|
||||
if ( ! isset( $value['url'] ) ) {
|
||||
$value['url'] = '';
|
||||
}
|
||||
if ( ! isset( $value['target'] ) ) {
|
||||
$value['target'] = '';
|
||||
}
|
||||
$output = '<input type="hidden" name="' . $name . '" value="' . esc_attr( json_encode( $value ) ) . '" />';
|
||||
$output .= '<input type="text" value="' . esc_attr( $value['url'] ) . '"';
|
||||
if ( isset( $field['placeholder'] ) AND ! empty( $field['placeholder'] ) ) {
|
||||
$output .= ' placeholder="' . esc_attr( $field['placeholder'] ) . '"';
|
||||
}
|
||||
$output .= ' />';
|
||||
|
||||
$output .= '<div class="usof-checkbox">';
|
||||
$output .= '<label>';
|
||||
$output .= '<input type="checkbox"';
|
||||
if ( $value['target'] == '_blank' ) {
|
||||
$output .= ' checked';
|
||||
}
|
||||
$output .= '>';
|
||||
$output .= '<span class="usof-checkbox-icon"></span><span class="usof-checkbox-text">' . us_translate( 'Open link in a new tab' ) . '</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Info
|
||||
*
|
||||
* Information message
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*/
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Radio
|
||||
*
|
||||
* Radio buttons selector
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array List of key => title pairs
|
||||
*
|
||||
* @var $value array List of checked keys
|
||||
*/
|
||||
|
||||
$output = '<ul class="usof-radio-list">';
|
||||
foreach ( $field['options'] as $key => $option_title ) {
|
||||
$output .= '<li class="usof-radio">';
|
||||
$output .= '<input type="radio" id="' . $id . '_' . $key . '" name="' . $name . '" value="' . esc_attr( $key ) . '"';
|
||||
$output .= checked( $value, $key, FALSE );
|
||||
$output .= '><label for="' . $id . '_' . $key . '">' . $option_title . '</label>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
echo $output;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Transfer
|
||||
*
|
||||
* Transfer theme options data
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$output = '<div class="usof-reset">';
|
||||
$output .= '<div class="usof-button type_reset"><span>' . __( 'Reset Options', 'us' ) . '</span>';
|
||||
$output .= '<span class="usof-preloader"></span></div>';
|
||||
$output .= '</div>';
|
||||
|
||||
$i18n = array(
|
||||
'reset_confirm' => __( 'Are you sure want to reset all the options to default values?', 'us' ),
|
||||
'reset_complete' => __( 'Options were reset', 'us' ),
|
||||
);
|
||||
$output .= '<div class="usof-form-row-control-i18n"' . us_pass_data_to_js( $i18n ) . '></div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Select
|
||||
*
|
||||
* Drop-down selector field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array List of value => title pairs
|
||||
* @param $field ['is_advanced'] bool apply select2 script
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$output = '<div class="usof-select';
|
||||
if ( isset( $field['is_advanced'] ) AND $field['is_advanced'] ) {
|
||||
$output .= ' type_advanced';
|
||||
}
|
||||
$output .= '">';
|
||||
|
||||
$output .= '<select name="' . $name . '"';
|
||||
if ( isset( $field['is_advanced'] ) AND $field['is_advanced'] ) {
|
||||
$output .= ' class="advanced"';
|
||||
}
|
||||
$output .= '>';
|
||||
|
||||
$is_first_optgroup = TRUE;
|
||||
foreach ( $field['options'] as $key => $option ) {
|
||||
if ( is_array( $option ) AND isset( $option['optgroup'] ) AND $option['optgroup'] ) {
|
||||
if ( ! $is_first_optgroup ) {
|
||||
$output .= '</optgroup>';
|
||||
}
|
||||
$output .= '<optgroup label="' . esc_attr( $option['title'] ) . '">';
|
||||
$is_first_optgroup = FALSE;
|
||||
|
||||
} else {
|
||||
$output .= '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, FALSE ) . '>' . $option . '</option>';
|
||||
}
|
||||
}
|
||||
if ( ! $is_first_optgroup ) {
|
||||
$output .= '</optgroup>';
|
||||
}
|
||||
|
||||
$output .= '</select>';
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Slider
|
||||
*
|
||||
* Slider-selector of the integer value within some range.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array with "min", "max", "step" values
|
||||
* @param $field ['std'] string Default value
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
// Set fallback values when "options" param is not set in config
|
||||
if ( ! isset( $field['options'] ) ) {
|
||||
$field['options'] = array(
|
||||
'px' => array(
|
||||
'min' => 0,
|
||||
'max' => 100,
|
||||
'step' => 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Get the first unit name from config
|
||||
$unit_keys = array_keys( $field['options'] );
|
||||
$first_unit = isset( $unit_keys[0] ) ? $unit_keys[0] : '';
|
||||
|
||||
$output = '<div class="usof-slider';
|
||||
if ( count( $field['options'] ) > 1 ) {
|
||||
$output .= ' with_units'; // add class when more then 1 units in config
|
||||
}
|
||||
$output .= '">';
|
||||
$output .= '<div class="usof-slider-selector">';
|
||||
|
||||
// Prepare value for regex
|
||||
$value = esc_attr( trim( $value ) );
|
||||
$value = str_replace( ',', '.', $value );
|
||||
|
||||
// Cut the string to get a unit
|
||||
$units_expression = implode( '|', array_map( 'preg_quote', $unit_keys ) );
|
||||
preg_match( '#^(-?\d+)(\.)?(\d+)?(' . $units_expression . ')?$#i', $value, $matches );
|
||||
|
||||
if ( isset( $matches[4] ) ) {
|
||||
$current_unit = $matches[4];
|
||||
$valueOutput = $value;
|
||||
} else {
|
||||
$current_unit = $first_unit;
|
||||
$valueOutput = $value . $first_unit;
|
||||
}
|
||||
|
||||
$output .= '<input type="text" name="' . $name . '" value="' . $valueOutput . '" />';
|
||||
|
||||
// Define current unit params
|
||||
$max = isset( $field['options'][ $current_unit ]['max'] ) ? $field['options'][ $current_unit ]['max'] : 100;
|
||||
$min = isset( $field['options'][ $current_unit ]['min'] ) ? $field['options'][ $current_unit ]['min'] : 0;
|
||||
$step = isset( $field['options'][ $current_unit ]['step'] ) ? $field['options'][ $current_unit ]['step'] : 1;
|
||||
|
||||
// Output units selection based on config
|
||||
$output .= '<div class="usof-slider-selector-units"';
|
||||
$output .= ' data-units_expression="' . $units_expression . '"';
|
||||
$output .= ' data-unit="' . $current_unit . '"';
|
||||
$output .= ' data-max="' . $max . '"';
|
||||
$output .= ' data-min="' . $min . '"';
|
||||
$output .= ' data-step="' . $step . '"';
|
||||
$output .= '>';
|
||||
foreach ( $field['options'] as $unit => $values ) {
|
||||
$data_atts = ' data-unit="' . $unit . '"';
|
||||
$data_atts .= ' data-max="' . ( isset( $values['max'] ) ? $values['max'] : 100 ) . '"';
|
||||
$data_atts .= ' data-min="' . ( isset( $values['min'] ) ? $values['min'] : 0 ) . '"';
|
||||
$data_atts .= ' data-step="' . ( isset( $values['step'] ) ? $values['step'] : 1 ) . '"';
|
||||
|
||||
$output .= '<div class="usof-slider-selector-unit"' . $data_atts . '>';
|
||||
if ( empty( $unit ) ) {
|
||||
$output .= '<i>' . __( 'No units', 'us' ) . '</i>'; // case for empty unit, like in "line-height" option
|
||||
} else {
|
||||
$output .= $unit;
|
||||
}
|
||||
$output .= '</div>';
|
||||
}
|
||||
$output .= '</div></div>';
|
||||
|
||||
// Calculate slider range offset in percents based on current "min" and "max" values
|
||||
$offset_direction = ( is_rtl() ) ? 'right' : 'left';
|
||||
$float_value = floatval( $value );
|
||||
|
||||
if ( $max <= $min ) {
|
||||
$offset = 100;
|
||||
} else {
|
||||
if ( $float_value < $min ) {
|
||||
$offset = 0;
|
||||
} elseif ( $float_value >= $max ) {
|
||||
$offset = 100;
|
||||
} else {
|
||||
$offset = ( min( $max, max( $min, $float_value ) ) - $min ) * 100 / ( $max - $min );
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '<div class="usof-slider-box"><div class="usof-slider-box-h">';
|
||||
$output .= '<div class="usof-slider-range" style="' . $offset_direction . ':' . $offset . '%;">';
|
||||
$output .= '<div class="usof-slider-runner" draggable="true"></div>';
|
||||
$output .= '</div></div></div>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Select Scheme
|
||||
*
|
||||
* Drop-down selector field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
// Could already be defined in parent function
|
||||
if ( ! isset( $color_schemes ) ) {
|
||||
$color_schemes = us_config( 'style-schemes' );
|
||||
}
|
||||
if ( ! isset( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = get_option( 'usof_style_schemes_' . US_THEMENAME );
|
||||
if ( ! is_array( $custom_color_schemes ) ) {
|
||||
$custom_color_schemes = array();
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse Custom schemes order to make last added item first
|
||||
$custom_color_schemes = array_reverse( $custom_color_schemes, TRUE );
|
||||
|
||||
// Window title and close control
|
||||
$output = '<div class="us-bld-window-title">' . __( 'Color Schemes', 'us' ) . '</div>';
|
||||
$output .= '<div class="us-bld-window-closer" title="' . us_translate( 'Close' ) . '"></div>';
|
||||
|
||||
$output .= '<div class="usof-schemes">';
|
||||
|
||||
// Save as new controls
|
||||
$output .= '<div class="usof-schemes-controls">';
|
||||
$output .= '<div class="usof-schemes-text">' . __( 'Save current colors as', 'us' ) . '</div>';
|
||||
$output .= '<input type="text" id="scheme_name" value="" placeholder="' . __( 'Color Scheme Name', 'us' ) . '"/>';
|
||||
$output .= '<button id="save_new_scheme" class="usof-button" disabled type="button">';
|
||||
$output .= '<span>' . _x( 'Save as new', 'color scheme', 'us' ) . '</span>';
|
||||
$output .= '<span class="usof-preloader"></span>';
|
||||
$output .= '</button>';
|
||||
$output .= '</div>';
|
||||
|
||||
// Schemes list
|
||||
$output .= '<ul class="usof-schemes-list">';
|
||||
|
||||
// Custom schemes
|
||||
foreach ( $custom_color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item type_custom" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
// Overwrite btn
|
||||
$output .= '<div class="usof-schemes-item-save" title="' . us_translate( 'Save' ) . '"></div>';
|
||||
// Delete btn
|
||||
$output .= '<div class="usof-schemes-item-delete" title="' . us_translate( 'Delete' ) . '"></div>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
// Predefined schemes
|
||||
foreach ( $color_schemes as $key => &$scheme ) {
|
||||
$output .= '<li class="usof-schemes-item" data-id="' . $key . '">';
|
||||
$output .= usof_color_scheme_preview( $scheme );
|
||||
$output .= '</li>';
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
$first_color_scheme = array_shift( $color_schemes );
|
||||
$color_scheme_colors = array_keys( $first_color_scheme['values'] );
|
||||
$output .= '<div class="usof-form-row-control-colors-json hidden"' . us_pass_data_to_js( $color_scheme_colors ) . '></div>';
|
||||
|
||||
$i18n = array(
|
||||
'delete_confirm' => __( 'Are you sure want to delete the element?', 'us' ),
|
||||
);
|
||||
$output .= '<div class="usof-form-row-control-i18n hidden"' . us_pass_data_to_js( $i18n ) . '></div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Switch
|
||||
*
|
||||
* On-off switcher
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['options'] array Array of two key => title pairs
|
||||
* @param $field ['text'] array Additional text to show right near the switcher
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
if ( ! isset( $field['options'] ) OR empty( $field['options'] ) ) {
|
||||
$field['options'] = array(
|
||||
TRUE => 'On',
|
||||
FALSE => 'Off',
|
||||
);
|
||||
}
|
||||
$field_keys = array_keys( $field['options'] );
|
||||
if ( count( $field_keys ) < 2 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '<div class="usof-switcher">';
|
||||
$output .= '<input type="hidden" name="' . $name . '" value="' . esc_attr( $field_keys[1] ) . '" />';
|
||||
$output .= '<input type="checkbox" id="' . $id . '" name="' . $name . '"' . checked( $value, $field_keys[0], FALSE ) . ' value="' . esc_attr( $field_keys[0] ) . '">';
|
||||
$output .= '<label for="' . $id . '">';
|
||||
$output .= '<span class="usof-switcher-box"><i></i></span>';
|
||||
if ( isset( $field['switch_text'] ) AND ! empty( $field['switch_text'] ) ) {
|
||||
$output .= '<span class="usof-switcher-text">' . $field['switch_text'] . '</span>';
|
||||
}
|
||||
$output .= '</label></div>';
|
||||
|
||||
echo $output;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Text
|
||||
*
|
||||
* Simple text field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['placeholder'] string Field placeholder
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$output = '<input type="text" name="' . $name . '" value="' . esc_attr( $value ) . '"';
|
||||
if ( isset( $field['placeholder'] ) AND ! empty( $field['placeholder'] ) ) {
|
||||
$output .= ' placeholder="' . esc_attr( $field['placeholder'] ) . '"';
|
||||
}
|
||||
$output .= ' />';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Textarea
|
||||
*
|
||||
* Simple textarea field.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['placeholder'] string Field placeholder
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$output = '<textarea name="' . $name . '"';
|
||||
if ( isset( $field['placeholder'] ) AND ! empty( $field['placeholder'] ) ) {
|
||||
$output .= ' placeholder="' . esc_attr( $field['placeholder'] ) . '"';
|
||||
}
|
||||
$output .= '>' . esc_textarea( $value ) . '</textarea>';
|
||||
|
||||
echo $output;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Transfer
|
||||
*
|
||||
* Transfer theme options data
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
*
|
||||
* @var $value string Current value
|
||||
*/
|
||||
|
||||
$output = '<div class="usof-transfer">';
|
||||
$output .= '<textarea></textarea>';
|
||||
$output .= '<div class="usof-button type_import"><span>' . _x( 'Import Options', 'verb', 'us' ) . '</span>';
|
||||
$output .= '<span class="usof-preloader"></span>';
|
||||
$output .= '</div>';
|
||||
$translations = array(
|
||||
'importError' => __( 'Wrong import data format', 'us' ),
|
||||
'importSuccess' => __( 'Options imported', 'us' ),
|
||||
);
|
||||
$output .= '<div class="usof-transfer-translations"' . us_pass_data_to_js( $translations ) . '></div>';
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme Options Field: Upload
|
||||
*
|
||||
* Upload some file with the specified settings.
|
||||
*
|
||||
* @var $name string Field name
|
||||
* @var $id string Field ID
|
||||
* @var $field array Field options
|
||||
*
|
||||
* @param $field ['title'] string Field title
|
||||
* @param $field ['description'] string Field title
|
||||
* @param $field ['button_label'] string Upload Button label
|
||||
* @param $field ['preview_type'] string 'image' / 'text'
|
||||
* @param $field ['is_multiple'] bool
|
||||
*
|
||||
* @var $value mixed Either full path to the file, or ID from WordPress media uploads
|
||||
*/
|
||||
|
||||
$field['preview_type'] = isset( $field['preview_type'] ) ? $field['preview_type'] : 'image';
|
||||
$field['is_multiple'] = isset( $field['is_multiple'] ) ? $field['is_multiple'] : FALSE;
|
||||
$field['button_label'] = isset( $field['button_label'] ) ? $field['button_label'] : us_translate( 'Set image' );
|
||||
|
||||
$upload_file = '';
|
||||
if ( $field['preview_type'] == 'image' ) {
|
||||
if ( ! empty( $value ) ) {
|
||||
$upload_file = usof_get_image_src( $value, 'medium' );
|
||||
}
|
||||
} elseif ( $field['preview_type'] == 'text' ) {
|
||||
$files = explode( ',', $value );
|
||||
$upload_file = array();
|
||||
foreach ( $files as $file ) {
|
||||
$url = wp_get_attachment_url( $file );
|
||||
if ( $url ) {
|
||||
$upload_file[] = $url;
|
||||
}
|
||||
}
|
||||
if ( count( $upload_file ) == 0 ) {
|
||||
$upload_file = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$control_buttons = '<div class="usof-upload-controls">';
|
||||
$control_buttons .= '<a class="usof-button type_change" href="javascript:void(0)"><span>' . us_translate( 'Change' ) . '</span></a>';
|
||||
$control_buttons .= '<a class="usof-button type_remove" href="javascript:void(0)"><span>' . us_translate( 'Remove' ) . '</span></a>';
|
||||
$control_buttons .= '</div>';
|
||||
|
||||
$output = '<div class="usof-upload preview_' . $field['preview_type'];
|
||||
if ( $field['is_multiple'] ) {
|
||||
$output .= ' is_multiple';
|
||||
}
|
||||
$output .= '">';
|
||||
$output .= '<input type="hidden" name="' . $name . '" value="' . $value . '">';
|
||||
|
||||
$output .= '<button class="usof-button type_upload" type="button"' . ( $upload_file ? ' style="display:none;"' : '' ) . '>';
|
||||
$output .= '<span class="usof-button-label">' . $field['button_label'] . '</span>';
|
||||
$output .= '</button>';
|
||||
|
||||
$output .= '<div class="usof-upload-preview"' . ( $upload_file ? '' : ' style="display:none;"' ) . '>';
|
||||
if ( $field['preview_type'] == 'image' ) {
|
||||
$output .= '<div class="usof-preloader"></div>';
|
||||
if ( $upload_file ) {
|
||||
$output .= '<img src="' . esc_attr( $upload_file[0] ) . '" alt="preview" />';
|
||||
} else {
|
||||
$output .= '<img src="" alt="preview" />';
|
||||
}
|
||||
$output .= $control_buttons;
|
||||
} elseif ( $field['preview_type'] == 'text' ) {
|
||||
$output .= '<div class="usof-upload-file">';
|
||||
if ( $upload_file ) {
|
||||
foreach ( $upload_file as $file ) {
|
||||
$output .= '<span>' . basename( $file ) . '</span>';
|
||||
}
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= $control_buttons;
|
||||
}
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
|
||||
unset( $upload_file );
|
||||
@@ -0,0 +1,347 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
global $usof_directory, $usof_directory_uri;
|
||||
if ( ! isset( $usof_directory ) ) {
|
||||
$usof_directory = get_template_directory() . '/framework/vendor/usof';
|
||||
}
|
||||
if ( ! isset( $usof_directory_uri ) ) {
|
||||
$usof_directory_uri = get_template_directory_uri() . '/framework/vendor/usof';
|
||||
}
|
||||
|
||||
if ( is_admin() ) {
|
||||
if ( ! defined( 'DOING_AJAX' ) OR ! DOING_AJAX ) {
|
||||
// Front-end interface
|
||||
require $usof_directory . '/functions/interface.php';
|
||||
require $usof_directory . '/functions/meta-box.php';
|
||||
require $usof_directory . '/functions/mega-menu.php';
|
||||
} elseif ( ( isset( $_POST['action'] ) AND substr( $_POST['action'], 0, 5 ) == 'usof_' ) OR ( isset( $_GET['action'] ) AND substr( $_GET['action'], 0, 5 ) == 'usof_' ) ) {
|
||||
// Ajax methods
|
||||
require $usof_directory . '/functions/ajax.php';
|
||||
require $usof_directory . '/functions/ajax-mega-menu.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme option or return default value
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default_value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function usof_get_option( $name, $default_value = NULL ) {
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
if ( $default_value === NULL ) {
|
||||
$default_value = usof_defaults( $name );
|
||||
}
|
||||
|
||||
$value = isset( $usof_options[ $name ] ) ? $usof_options[ $name ] : $default_value;
|
||||
|
||||
return apply_filters( 'usof_get_option_' . $name, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default value for a certain USOF field
|
||||
* @param array $field
|
||||
* @return mixed
|
||||
*/
|
||||
function usof_get_default( &$field ) {
|
||||
|
||||
$no_values_types = array(
|
||||
'backup',
|
||||
'heading',
|
||||
'message',
|
||||
'transfer',
|
||||
'wrapper_start',
|
||||
'wrapper_end',
|
||||
);
|
||||
|
||||
$selectable_types = array(
|
||||
'imgradio',
|
||||
'radio',
|
||||
'select',
|
||||
'style_scheme',
|
||||
);
|
||||
|
||||
if ( ! isset( $field['type'] ) OR in_array( $field['type'], $no_values_types ) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Using first value as standard for selectable types
|
||||
if ( ! isset( $field['std'] ) AND in_array( $field['type'], $selectable_types ) ) {
|
||||
if ( isset( $field['options'] ) AND is_array( $field['options'] ) AND ! empty( $field['options'] ) ) {
|
||||
$field['std'] = key( $field['options'] );
|
||||
reset( $field['options'] );
|
||||
}
|
||||
}
|
||||
|
||||
return isset( $field['std'] ) ? $field['std'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default values
|
||||
*
|
||||
* @param string $key If set, retreive only one default value
|
||||
*
|
||||
* @return mixed Array of values or a single value if the $key is specified
|
||||
*/
|
||||
function usof_defaults( $key = NULL ) {
|
||||
$config = us_config( 'theme-options' );
|
||||
|
||||
$values = array();
|
||||
foreach ( $config as &$section ) {
|
||||
if ( ! isset( $section['fields'] ) ) {
|
||||
continue;
|
||||
}
|
||||
foreach ( $section['fields'] as $field_id => &$field ) {
|
||||
if ( $key !== NULL AND $field_id != $key ) {
|
||||
continue;
|
||||
}
|
||||
if ( isset( $values[ $field_id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $field['type'] ) AND $field['type'] == 'style_scheme' ) {
|
||||
$options = array_keys( us_config( 'style-schemes' ) );
|
||||
if ( empty( $options ) ) {
|
||||
continue;
|
||||
}
|
||||
$field['std'] = isset( $field['std'] ) ? $field['std'] : $options[0];
|
||||
// If theme has default style scheme, it's values will be used as standard as well
|
||||
$values = array_merge( $values, us_config( 'style-schemes.' . $field['std'] . '.values' ) );
|
||||
}
|
||||
|
||||
$default_value = usof_get_default( $field );
|
||||
if ( $default_value !== NULL ) {
|
||||
$values[ $field_id ] = $default_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $key !== NULL ) {
|
||||
return isset( $values[ $key ] ) ? $values[ $key ] : NULL;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the options were not loaded, load them
|
||||
*/
|
||||
function usof_load_options_once() {
|
||||
global $usof_options;
|
||||
if ( isset( $usof_options ) ) {
|
||||
return;
|
||||
}
|
||||
$usof_options = get_option( 'usof_options_' . US_THEMENAME );
|
||||
if ( $usof_options === FALSE ) {
|
||||
// Trying to fetch the old good SMOF options
|
||||
$usof_options = get_option( US_THEMENAME . '_options' );
|
||||
if ( $usof_options !== FALSE ) {
|
||||
// Disabling the old options autoload
|
||||
update_option( US_THEMENAME . '_options', $usof_options, FALSE );
|
||||
} else {
|
||||
// Not defined yet, using default values
|
||||
$usof_options = usof_defaults();
|
||||
}
|
||||
update_option( 'usof_options_' . US_THEMENAME, $usof_options, TRUE );
|
||||
}
|
||||
|
||||
$usof_options = apply_filters( 'usof_load_options_once', $usof_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current usof options values from global $usof_options variable to database
|
||||
*
|
||||
* @param array $updated_options Array of the new options values
|
||||
*/
|
||||
function usof_save_options( $updated_options ) {
|
||||
|
||||
if ( ! is_array( $updated_options ) OR empty( $updated_options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $usof_options;
|
||||
usof_load_options_once();
|
||||
|
||||
do_action( 'usof_before_save', $updated_options );
|
||||
$usof_options = $updated_options;
|
||||
update_option( 'usof_options_' . US_THEMENAME, $usof_options, TRUE );
|
||||
|
||||
do_action( 'usof_after_save', $updated_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get uploaded image from USOF field value
|
||||
*
|
||||
* @param string $value Upload field value in "123|full" format
|
||||
*
|
||||
* @return array [url, width, height]
|
||||
*/
|
||||
function usof_get_image_src( $value, $size = NULL ) {
|
||||
if ( preg_match( '~^(\d+)(\|(.+))?$~', $value, $matches ) ) {
|
||||
// Image size
|
||||
if ( $size == NULL ) {
|
||||
$matches[3] = empty( $matches[3] ) ? 'full' : $matches[3];
|
||||
} else {
|
||||
$matches[3] = $size;
|
||||
}
|
||||
$result = wp_get_attachment_image_src( $matches[1], $matches[3] );
|
||||
if ( is_array( $result ) AND count( $result ) > 2 AND preg_match( '~\.svg$~', $result[0] ) ) {
|
||||
// SVG images have no specific dimensions
|
||||
$result[1] = $result[2] = '';
|
||||
}
|
||||
} else {
|
||||
$value = str_replace( '[site_url]', site_url(), $value );
|
||||
$result = array( $value, '', '' );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function usof_get_link_atts( $value ) {
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = array(
|
||||
'url' => is_string( $value ) ? $value : '',
|
||||
);
|
||||
}
|
||||
$atts = array();
|
||||
if ( isset( $value['url'] ) AND ! empty( $value['url'] ) ) {
|
||||
$atts['href'] = $value['url'];
|
||||
|
||||
if ( strpos( $atts['href'], '[lang]' ) !== FALSE ) {
|
||||
$atts['href'] = str_replace( '[lang]', usof_get_lang(), $atts['href'] );
|
||||
}
|
||||
|
||||
if ( isset( $value['target'] ) AND ! empty( $value['target'] ) ) {
|
||||
$atts['target'] = $value['target'];
|
||||
}
|
||||
}
|
||||
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the showing condition is true
|
||||
*
|
||||
* Note: at any possible syntax error we choose to show the field so it will be functional anyway.
|
||||
*
|
||||
* @param array $condition Showing condition
|
||||
* @param array $values Current values
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function usof_execute_show_if( $condition, &$values = NULL ) {
|
||||
if ( ! is_array( $condition ) OR count( $condition ) < 3 ) {
|
||||
// Wrong condition
|
||||
$result = TRUE;
|
||||
} elseif ( in_array( strtolower( $condition[1] ), array( 'and', 'or' ) ) ) {
|
||||
// Complex or / and statement
|
||||
$result = usof_execute_show_if( $condition[0], $values );
|
||||
$index = 2;
|
||||
while ( isset( $condition[ $index ] ) ) {
|
||||
$condition[ $index - 1 ] = strtolower( $condition[ $index - 1 ] );
|
||||
if ( $condition[ $index - 1 ] == 'and' ) {
|
||||
$result = ( $result AND usof_execute_show_if( $condition[ $index ], $values ) );
|
||||
} elseif ( $condition[ $index - 1 ] == 'or' ) {
|
||||
$result = ( $result OR usof_execute_show_if( $condition[ $index ], $values ) );
|
||||
}
|
||||
$index = $index + 2;
|
||||
}
|
||||
} else {
|
||||
if ( ! isset( $values[ $condition[0] ] ) ) {
|
||||
if ( $condition[1] == '=' AND ( ! in_array( $condition[2], array( 0, '', FALSE, NULL ) ) ) ) {
|
||||
return FALSE;
|
||||
} elseif ( $condition[1] == '!=' AND in_array( $condition[2], array( 0, '', FALSE, NULL ) ) ) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
$value = $values[ $condition[0] ];
|
||||
if ( $condition[1] == '=' ) {
|
||||
$result = ( $value == $condition[2] );
|
||||
} elseif ( $condition[1] == '!=' OR $condition[1] == '<>' ) {
|
||||
$result = ( $value != $condition[2] );
|
||||
} elseif ( $condition[1] == 'in' ) {
|
||||
$result = ( ! is_array( $condition[2] ) OR in_array( $value, $condition[2] ) );
|
||||
} elseif ( $condition[1] == 'not in' ) {
|
||||
$result = ( ! is_array( $condition[2] ) OR ! in_array( $value, $condition[2] ) );
|
||||
} elseif ( $condition[1] == 'has' ) {
|
||||
$result = ( ! is_array( $value ) OR in_array( $condition[2], $value ) );
|
||||
} elseif ( $condition[1] == '<=' ) {
|
||||
$result = ( $value <= $condition[2] );
|
||||
} elseif ( $condition[1] == '<' ) {
|
||||
$result = ( $value < $condition[2] );
|
||||
} elseif ( $condition[1] == '>' ) {
|
||||
$result = ( $value > $condition[2] );
|
||||
} elseif ( $condition[1] == '>=' ) {
|
||||
$result = ( $value >= $condition[2] );
|
||||
} else {
|
||||
$result = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function usof_get_lang() {
|
||||
if ( function_exists( 'wpml_get_current_language' ) ) {
|
||||
// WPML
|
||||
global $sitepress;
|
||||
$default_language = $sitepress->get_default_language();
|
||||
if ( $default_language != ICL_LANGUAGE_CODE ) {
|
||||
return wpml_get_current_language();
|
||||
}
|
||||
} elseif ( function_exists( 'pll_current_language' ) ) {
|
||||
// Polylang
|
||||
return pll_current_language();
|
||||
} elseif ( function_exists( 'qtrans_getLanguage' ) ) {
|
||||
// qTranslate
|
||||
return qtrans_getLanguage();
|
||||
}
|
||||
|
||||
// No supported translation plugins found
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output preview for color scheme used by ajax and style_scheme
|
||||
*
|
||||
* @param array $scheme
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function usof_color_scheme_preview( $scheme ) {
|
||||
if ( empty( $scheme ) ) {
|
||||
return '';
|
||||
}
|
||||
$preview = '<div class="usof-scheme-preview">';
|
||||
// Header
|
||||
$preview .= '<div class="preview_header" style="background:' . $scheme['values']['color_header_middle_bg'] . ';"></div>';
|
||||
// Content
|
||||
$preview .= '<div class="preview_content" style="background:' . $scheme['values']['color_content_bg'] . ';">';
|
||||
// Heading
|
||||
$preview .= '<div class="preview_heading" style="color:' . us_gradient2hex( $scheme['values']['color_content_heading'] ) . ';">' . trim( esc_html( $scheme['title'] ) ) . '</div>';
|
||||
// Text
|
||||
$preview .= '<div class="preview_text" style="color:' . us_gradient2hex( $scheme['values']['color_content_text'] ) . ';">';
|
||||
$preview .= 'Lorem ipsum dolor sit amet, <span style="color:' . us_gradient2hex( $scheme['values']['color_content_link'] ) . ';">consectetur</span> adipiscing elit. Maecenas arcu lectus, sollicitudin dictum dapibus sit amet.';
|
||||
$preview .= '</div>';
|
||||
// Primary
|
||||
$preview .= '<div class="preview_primary" style="background:' . $scheme['values']['color_content_primary'] . ';"></div>';
|
||||
// Secondary
|
||||
$preview .= '<div class="preview_secondary" style="background:' . $scheme['values']['color_content_secondary'] . ';"></div>';
|
||||
$preview .= '</div>';
|
||||
// Footer
|
||||
$preview .= '<div class="preview_footer" style="background:' . $scheme['values']['color_footer_bg'] . ';"></div>';
|
||||
$preview .= '</div>';
|
||||
|
||||
return $preview;
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* Import Functions
|
||||
*
|
||||
* @package Widget_Importer_Exporter
|
||||
* @subpackage Functions
|
||||
* @copyright Copyright (c) 2013 - 2015, DreamDolphin Media, LLC
|
||||
* @link https://github.com/stevengliebe/widget-importer-exporter
|
||||
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* @since 0.3
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process import file
|
||||
*
|
||||
* This parses a file and triggers importation of its widgets.
|
||||
*
|
||||
* @since 0.3
|
||||
*
|
||||
* @param string $file Path to .wie file uploaded
|
||||
*
|
||||
* @global string $wie_import_results
|
||||
*/
|
||||
function us_wie_process_import_file( $file ) {
|
||||
|
||||
global $wie_import_results;
|
||||
|
||||
// File exists?
|
||||
if ( ! file_exists( $file ) ) {
|
||||
wp_die(
|
||||
'Import file could not be found. Please try again.', '', array( 'back_link' => TRUE )
|
||||
);
|
||||
}
|
||||
|
||||
// Get file contents and decode
|
||||
$data = file_get_contents( $file );
|
||||
$data = json_decode( $data );
|
||||
|
||||
// Import the widget data
|
||||
// Make results available for display on import/export page
|
||||
$wie_import_results = us_wie_import_data( $data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Import widget JSON data
|
||||
*
|
||||
* @since 0.4
|
||||
* @global array $wp_registered_sidebars
|
||||
*
|
||||
* @param object $data JSON widget data from .wie file
|
||||
*
|
||||
* @return array Results array
|
||||
*/
|
||||
function us_wie_import_data( $data ) {
|
||||
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
// Have valid data?
|
||||
// If no data or could not decode
|
||||
if ( empty( $data ) || ! is_object( $data ) ) {
|
||||
wp_die(
|
||||
'Import data could not be read. Please try a different file.', '', array( 'back_link' => TRUE )
|
||||
);
|
||||
}
|
||||
|
||||
// Get all available widgets site supports
|
||||
$available_widgets = us_wie_available_widgets();
|
||||
|
||||
// Get all existing widget instances
|
||||
$widget_instances = array();
|
||||
foreach ( $available_widgets as $widget_data ) {
|
||||
$widget_instances[$widget_data['id_base']] = get_option( 'widget_' . $widget_data['id_base'] );
|
||||
}
|
||||
|
||||
// Begin results
|
||||
$results = array();
|
||||
|
||||
// Loop import data's sidebars
|
||||
foreach ( $data as $sidebar_id => $widgets ) {
|
||||
|
||||
// Skip inactive widgets
|
||||
// (should not be in export file)
|
||||
if ( 'wp_inactive_widgets' == $sidebar_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if sidebar is available on this site
|
||||
// Otherwise add widgets to inactive, and say so
|
||||
if ( isset( $wp_registered_sidebars[$sidebar_id] ) ) {
|
||||
$sidebar_available = TRUE;
|
||||
$use_sidebar_id = $sidebar_id;
|
||||
$sidebar_message_type = 'success';
|
||||
$sidebar_message = '';
|
||||
} else {
|
||||
$sidebar_available = FALSE;
|
||||
$use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme
|
||||
$sidebar_message_type = 'error';
|
||||
$sidebar_message = 'Sidebar does not exist in theme (using Inactive)';
|
||||
}
|
||||
|
||||
// Result for sidebar
|
||||
$results[$sidebar_id]['name'] = ! empty( $wp_registered_sidebars[$sidebar_id]['name'] ) ? $wp_registered_sidebars[$sidebar_id]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID
|
||||
$results[$sidebar_id]['message_type'] = $sidebar_message_type;
|
||||
$results[$sidebar_id]['message'] = $sidebar_message;
|
||||
$results[$sidebar_id]['widgets'] = array();
|
||||
|
||||
// Loop widgets
|
||||
foreach ( $widgets as $widget_instance_id => $widget ) {
|
||||
|
||||
$fail = FALSE;
|
||||
|
||||
// Get id_base (remove -# from end) and instance ID number
|
||||
$id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
|
||||
$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
|
||||
|
||||
// Does site support this widget?
|
||||
if ( ! $fail && ! isset( $available_widgets[$id_base] ) ) {
|
||||
$fail = TRUE;
|
||||
$widget_message_type = 'error';
|
||||
$widget_message = 'Site does not support widget'; // explain why widget not imported
|
||||
}
|
||||
|
||||
// Convert multidimensional objects to multidimensional arrays
|
||||
// Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
|
||||
// Without this, they are imported as objects and cause fatal error on Widgets page
|
||||
// If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
|
||||
// It is probably much more likely that arrays are used than objects, however
|
||||
$widget = json_decode( json_encode( $widget ), TRUE );
|
||||
|
||||
// Does widget with identical settings already exist in same sidebar?
|
||||
if ( ! $fail && isset( $widget_instances[$id_base] ) ) {
|
||||
|
||||
// Get existing widgets in this sidebar
|
||||
$sidebars_widgets = get_option( 'sidebars_widgets' );
|
||||
$sidebar_widgets = isset( $sidebars_widgets[$use_sidebar_id] ) ? $sidebars_widgets[$use_sidebar_id] : array(); // check Inactive if that's where will go
|
||||
|
||||
// Loop widgets with ID base
|
||||
$single_widget_instances = ! empty( $widget_instances[$id_base] ) ? $widget_instances[$id_base] : array();
|
||||
foreach ( $single_widget_instances as $check_id => $check_widget ) {
|
||||
|
||||
// Is widget in same sidebar and has identical settings?
|
||||
if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
|
||||
|
||||
$fail = TRUE;
|
||||
$widget_message_type = 'warning';
|
||||
$widget_message = 'Widget already exists'; // explain why widget not imported
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// No failure
|
||||
if ( ! $fail ) {
|
||||
|
||||
// Add widget instance
|
||||
$single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time
|
||||
$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // start fresh if have to
|
||||
$single_widget_instances[] = $widget; // add it
|
||||
|
||||
// Get the key it was given
|
||||
end( $single_widget_instances );
|
||||
$new_instance_id_number = key( $single_widget_instances );
|
||||
|
||||
// If key is 0, make it 1
|
||||
// When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it)
|
||||
if ( '0' === strval( $new_instance_id_number ) ) {
|
||||
$new_instance_id_number = 1;
|
||||
$single_widget_instances[$new_instance_id_number] = $single_widget_instances[0];
|
||||
unset( $single_widget_instances[0] );
|
||||
}
|
||||
|
||||
// Move _multiwidget to end of array for uniformity
|
||||
if ( isset( $single_widget_instances['_multiwidget'] ) ) {
|
||||
$multiwidget = $single_widget_instances['_multiwidget'];
|
||||
unset( $single_widget_instances['_multiwidget'] );
|
||||
$single_widget_instances['_multiwidget'] = $multiwidget;
|
||||
}
|
||||
|
||||
// Update option with new widget
|
||||
update_option( 'widget_' . $id_base, $single_widget_instances );
|
||||
|
||||
// Assign widget instance to sidebar
|
||||
$sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time
|
||||
$new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance
|
||||
$sidebars_widgets[$use_sidebar_id][] = $new_instance_id; // add new instance to sidebar
|
||||
update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data
|
||||
|
||||
// After widget import action
|
||||
$after_widget_import = array(
|
||||
'sidebar' => $use_sidebar_id,
|
||||
'sidebar_old' => $sidebar_id,
|
||||
'widget' => $widget,
|
||||
'widget_type' => $id_base,
|
||||
'widget_id' => $new_instance_id,
|
||||
'widget_id_old' => $widget_instance_id,
|
||||
'widget_id_num' => $new_instance_id_number,
|
||||
'widget_id_num_old' => $instance_id_number,
|
||||
);
|
||||
|
||||
// Success message
|
||||
if ( $sidebar_available ) {
|
||||
$widget_message_type = 'success';
|
||||
$widget_message = 'Imported';
|
||||
} else {
|
||||
$widget_message_type = 'warning';
|
||||
$widget_message = 'Imported to Inactive';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Result for widget instance
|
||||
$results[$sidebar_id]['widgets'][$widget_instance_id]['name'] = isset( $available_widgets[$id_base]['name'] ) ? $available_widgets[$id_base]['name'] : $id_base; // widget name or ID if name not available (not supported by site)
|
||||
$results[$sidebar_id]['widgets'][$widget_instance_id]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : 'No Title'; // show "No Title" if widget instance is untitled
|
||||
$results[$sidebar_id]['widgets'][$widget_instance_id]['message_type'] = $widget_message_type;
|
||||
$results[$sidebar_id]['widgets'][$widget_instance_id]['message'] = $widget_message;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Functions
|
||||
*
|
||||
* @package Widget_Importer_Exporter
|
||||
* @subpackage Functions
|
||||
* @copyright Copyright (c) 2013, DreamDolphin Media, LLC
|
||||
* @link https://github.com/stevengliebe/widget-importer-exporter
|
||||
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* @since 0.4
|
||||
*/
|
||||
|
||||
/**
|
||||
* Available widgets
|
||||
*
|
||||
* Gather site's widgets into array with ID base, name, etc.
|
||||
* Used by export and import functions.
|
||||
*
|
||||
* @since 0.4
|
||||
* @global array $wp_registered_widget_updates
|
||||
* @return array Widget information
|
||||
*/
|
||||
function us_wie_available_widgets() {
|
||||
|
||||
global $wp_registered_widget_controls;
|
||||
|
||||
$widget_controls = $wp_registered_widget_controls;
|
||||
|
||||
$available_widgets = array();
|
||||
|
||||
foreach ( $widget_controls as $widget ) {
|
||||
|
||||
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[$widget['id_base']] ) ) { // no dupes
|
||||
|
||||
$available_widgets[$widget['id_base']]['id_base'] = $widget['id_base'];
|
||||
$available_widgets[$widget['id_base']]['name'] = $widget['name'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $available_widgets;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,787 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress eXtended RSS file parser implementations
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Importer
|
||||
*/
|
||||
|
||||
/**
|
||||
* WordPress Importer class for managing parsing of WXR files.
|
||||
*/
|
||||
class WXR_Parser {
|
||||
function parse( $file ) {
|
||||
// Attempt to use proper XML parsers first
|
||||
if ( extension_loaded( 'simplexml' ) ) {
|
||||
$parser = new WXR_Parser_SimpleXML;
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
// If SimpleXML succeeds or this is an invalid WXR file then return the results
|
||||
if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) {
|
||||
return $result;
|
||||
}
|
||||
} else if ( extension_loaded( 'xml' ) ) {
|
||||
$parser = new WXR_Parser_XML;
|
||||
$result = $parser->parse( $file );
|
||||
|
||||
// If XMLParser succeeds or this is an invalid WXR file then return the results
|
||||
if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// We have a malformed XML file, so display the error and fallthrough to regex
|
||||
if ( isset( $result ) && defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
|
||||
echo '<pre>';
|
||||
if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
|
||||
foreach ( $result->get_error_data() as $error ) {
|
||||
echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
|
||||
}
|
||||
} else if ( 'XML_parse_error' == $result->get_error_code() ) {
|
||||
$error = $result->get_error_data();
|
||||
echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
|
||||
}
|
||||
echo '</pre>';
|
||||
echo '<p><strong>' . 'There was an error when reading this WXR file' . '</strong><br />';
|
||||
echo 'Details are shown above. The importer will now try again with a different parser...' . '</p>';
|
||||
}
|
||||
|
||||
// use regular expressions if nothing else available or this is bad XML
|
||||
$parser = new WXR_Parser_Regex;
|
||||
|
||||
return $parser->parse( $file );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WXR Parser that makes use of the SimpleXML PHP extension.
|
||||
*/
|
||||
class WXR_Parser_SimpleXML {
|
||||
function parse( $file ) {
|
||||
$authors = $posts = $categories = $tags = $terms = array();
|
||||
|
||||
$internal_errors = libxml_use_internal_errors( TRUE );
|
||||
|
||||
$dom = new DOMDocument;
|
||||
$old_value = NULL;
|
||||
if ( function_exists( 'libxml_disable_entity_loader' ) ) {
|
||||
$old_value = libxml_disable_entity_loader( TRUE );
|
||||
}
|
||||
$success = $dom->loadXML( file_get_contents( $file ) );
|
||||
if ( ! is_null( $old_value ) ) {
|
||||
libxml_disable_entity_loader( $old_value );
|
||||
}
|
||||
|
||||
if ( ! $success || isset( $dom->doctype ) ) {
|
||||
return new WP_Error( 'SimpleXML_parse_error', 'There was an error when reading this WXR file', libxml_get_errors() );
|
||||
}
|
||||
|
||||
$xml = simplexml_import_dom( $dom );
|
||||
unset( $dom );
|
||||
|
||||
// halt if loading produces an error
|
||||
if ( ! $xml ) {
|
||||
return new WP_Error( 'SimpleXML_parse_error', 'There was an error when reading this WXR file', libxml_get_errors() );
|
||||
}
|
||||
|
||||
$wxr_version = $xml->xpath( '/rss/channel/wp:wxr_version' );
|
||||
if ( ! $wxr_version ) {
|
||||
return new WP_Error( 'WXR_parse_error', 'This does not appear to be a WXR file, missing/invalid WXR version number' );
|
||||
}
|
||||
|
||||
$wxr_version = (string) trim( $wxr_version[0] );
|
||||
// confirm that we are dealing with the correct file format
|
||||
if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) {
|
||||
return new WP_Error( 'WXR_parse_error', 'This does not appear to be a WXR file, missing/invalid WXR version number' );
|
||||
}
|
||||
|
||||
$base_url = $xml->xpath( '/rss/channel/wp:base_site_url' );
|
||||
$base_url = (string) trim( $base_url[0] );
|
||||
|
||||
$namespaces = $xml->getDocNamespaces();
|
||||
if ( ! isset( $namespaces['wp'] ) ) {
|
||||
$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
|
||||
}
|
||||
if ( ! isset( $namespaces['excerpt'] ) ) {
|
||||
$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
|
||||
}
|
||||
|
||||
// grab authors
|
||||
foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) {
|
||||
$a = $author_arr->children( $namespaces['wp'] );
|
||||
$login = (string) $a->author_login;
|
||||
$authors[$login] = array(
|
||||
'author_id' => (int) $a->author_id,
|
||||
'author_login' => $login,
|
||||
'author_email' => (string) $a->author_email,
|
||||
'author_display_name' => (string) $a->author_display_name,
|
||||
'author_first_name' => (string) $a->author_first_name,
|
||||
'author_last_name' => (string) $a->author_last_name,
|
||||
);
|
||||
}
|
||||
|
||||
// grab cats, tags and terms
|
||||
foreach ( $xml->xpath( '/rss/channel/wp:category' ) as $term_arr ) {
|
||||
$t = $term_arr->children( $namespaces['wp'] );
|
||||
$category = array(
|
||||
'term_id' => (int) $t->term_id,
|
||||
'category_nicename' => (string) $t->category_nicename,
|
||||
'category_parent' => (string) $t->category_parent,
|
||||
'cat_name' => (string) $t->cat_name,
|
||||
'category_description' => (string) $t->category_description,
|
||||
);
|
||||
|
||||
foreach ( $t->termmeta as $meta ) {
|
||||
$category['termmeta'][] = array(
|
||||
'key' => (string) $meta->meta_key,
|
||||
'value' => (string) $meta->meta_value,
|
||||
);
|
||||
}
|
||||
|
||||
$categories[] = $category;
|
||||
}
|
||||
|
||||
foreach ( $xml->xpath( '/rss/channel/wp:tag' ) as $term_arr ) {
|
||||
$t = $term_arr->children( $namespaces['wp'] );
|
||||
$tag = array(
|
||||
'term_id' => (int) $t->term_id,
|
||||
'tag_slug' => (string) $t->tag_slug,
|
||||
'tag_name' => (string) $t->tag_name,
|
||||
'tag_description' => (string) $t->tag_description,
|
||||
);
|
||||
|
||||
foreach ( $t->termmeta as $meta ) {
|
||||
$tag['termmeta'][] = array(
|
||||
'key' => (string) $meta->meta_key,
|
||||
'value' => (string) $meta->meta_value,
|
||||
);
|
||||
}
|
||||
|
||||
$tags[] = $tag;
|
||||
}
|
||||
|
||||
foreach ( $xml->xpath( '/rss/channel/wp:term' ) as $term_arr ) {
|
||||
$t = $term_arr->children( $namespaces['wp'] );
|
||||
$term = array(
|
||||
'term_id' => (int) $t->term_id,
|
||||
'term_taxonomy' => (string) $t->term_taxonomy,
|
||||
'slug' => (string) $t->term_slug,
|
||||
'term_parent' => (string) $t->term_parent,
|
||||
'term_name' => (string) $t->term_name,
|
||||
'term_description' => (string) $t->term_description,
|
||||
);
|
||||
|
||||
foreach ( $t->termmeta as $meta ) {
|
||||
$term['termmeta'][] = array(
|
||||
'key' => (string) $meta->meta_key,
|
||||
'value' => (string) $meta->meta_value,
|
||||
);
|
||||
}
|
||||
|
||||
$terms[] = $term;
|
||||
}
|
||||
|
||||
// grab posts
|
||||
foreach ( $xml->channel->item as $item ) {
|
||||
$post = array(
|
||||
'post_title' => (string) $item->title,
|
||||
'guid' => (string) $item->guid,
|
||||
);
|
||||
|
||||
$dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
|
||||
$post['post_author'] = (string) $dc->creator;
|
||||
|
||||
$content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
|
||||
$excerpt = $item->children( $namespaces['excerpt'] );
|
||||
$post['post_content'] = (string) $content->encoded;
|
||||
$post['post_excerpt'] = (string) $excerpt->encoded;
|
||||
|
||||
$wp = $item->children( $namespaces['wp'] );
|
||||
$post['post_id'] = (int) $wp->post_id;
|
||||
$post['post_date'] = (string) $wp->post_date;
|
||||
$post['post_date_gmt'] = (string) $wp->post_date_gmt;
|
||||
$post['comment_status'] = (string) $wp->comment_status;
|
||||
$post['ping_status'] = (string) $wp->ping_status;
|
||||
$post['post_name'] = (string) $wp->post_name;
|
||||
$post['status'] = (string) $wp->status;
|
||||
$post['post_parent'] = (int) $wp->post_parent;
|
||||
$post['menu_order'] = (int) $wp->menu_order;
|
||||
$post['post_type'] = (string) $wp->post_type;
|
||||
$post['post_password'] = (string) $wp->post_password;
|
||||
$post['is_sticky'] = (int) $wp->is_sticky;
|
||||
|
||||
if ( isset( $wp->attachment_url ) ) {
|
||||
$post['attachment_url'] = (string) $wp->attachment_url;
|
||||
}
|
||||
|
||||
foreach ( $item->category as $c ) {
|
||||
$att = $c->attributes();
|
||||
if ( isset( $att['nicename'] ) ) {
|
||||
$post['terms'][] = array(
|
||||
'name' => (string) $c,
|
||||
'slug' => (string) $att['nicename'],
|
||||
'domain' => (string) $att['domain'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $wp->postmeta as $meta ) {
|
||||
$post['postmeta'][] = array(
|
||||
'key' => (string) $meta->meta_key,
|
||||
'value' => (string) $meta->meta_value,
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $wp->comment as $comment ) {
|
||||
$meta = array();
|
||||
if ( isset( $comment->commentmeta ) ) {
|
||||
foreach ( $comment->commentmeta as $m ) {
|
||||
$meta[] = array(
|
||||
'key' => (string) $m->meta_key,
|
||||
'value' => (string) $m->meta_value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$post['comments'][] = array(
|
||||
'comment_id' => (int) $comment->comment_id,
|
||||
'comment_author' => (string) $comment->comment_author,
|
||||
'comment_author_email' => (string) $comment->comment_author_email,
|
||||
'comment_author_IP' => (string) $comment->comment_author_IP,
|
||||
'comment_author_url' => (string) $comment->comment_author_url,
|
||||
'comment_date' => (string) $comment->comment_date,
|
||||
'comment_date_gmt' => (string) $comment->comment_date_gmt,
|
||||
'comment_content' => (string) $comment->comment_content,
|
||||
'comment_approved' => (string) $comment->comment_approved,
|
||||
'comment_type' => (string) $comment->comment_type,
|
||||
'comment_parent' => (string) $comment->comment_parent,
|
||||
'comment_user_id' => (int) $comment->comment_user_id,
|
||||
'commentmeta' => $meta,
|
||||
);
|
||||
}
|
||||
|
||||
$posts[] = $post;
|
||||
}
|
||||
|
||||
return array(
|
||||
'authors' => $authors,
|
||||
'posts' => $posts,
|
||||
'categories' => $categories,
|
||||
'tags' => $tags,
|
||||
'terms' => $terms,
|
||||
'base_url' => $base_url,
|
||||
'version' => $wxr_version,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WXR Parser that makes use of the XML Parser PHP extension.
|
||||
*/
|
||||
class WXR_Parser_XML {
|
||||
var $wp_tags = array(
|
||||
'wp:post_id',
|
||||
'wp:post_date',
|
||||
'wp:post_date_gmt',
|
||||
'wp:comment_status',
|
||||
'wp:ping_status',
|
||||
'wp:attachment_url',
|
||||
'wp:status',
|
||||
'wp:post_name',
|
||||
'wp:post_parent',
|
||||
'wp:menu_order',
|
||||
'wp:post_type',
|
||||
'wp:post_password',
|
||||
'wp:is_sticky',
|
||||
'wp:term_id',
|
||||
'wp:category_nicename',
|
||||
'wp:category_parent',
|
||||
'wp:cat_name',
|
||||
'wp:category_description',
|
||||
'wp:tag_slug',
|
||||
'wp:tag_name',
|
||||
'wp:tag_description',
|
||||
'wp:term_taxonomy',
|
||||
'wp:term_parent',
|
||||
'wp:term_name',
|
||||
'wp:term_description',
|
||||
'wp:author_id',
|
||||
'wp:author_login',
|
||||
'wp:author_email',
|
||||
'wp:author_display_name',
|
||||
'wp:author_first_name',
|
||||
'wp:author_last_name',
|
||||
);
|
||||
var $wp_sub_tags = array(
|
||||
'wp:comment_id',
|
||||
'wp:comment_author',
|
||||
'wp:comment_author_email',
|
||||
'wp:comment_author_url',
|
||||
'wp:comment_author_IP',
|
||||
'wp:comment_date',
|
||||
'wp:comment_date_gmt',
|
||||
'wp:comment_content',
|
||||
'wp:comment_approved',
|
||||
'wp:comment_type',
|
||||
'wp:comment_parent',
|
||||
'wp:comment_user_id',
|
||||
);
|
||||
|
||||
function parse( $file ) {
|
||||
$this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = FALSE;
|
||||
$this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
|
||||
|
||||
$xml = xml_parser_create( 'UTF-8' );
|
||||
xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
|
||||
xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
|
||||
xml_set_object( $xml, $this );
|
||||
xml_set_character_data_handler( $xml, 'cdata' );
|
||||
xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
|
||||
|
||||
if ( ! xml_parse( $xml, file_get_contents( $file ), TRUE ) ) {
|
||||
$current_line = xml_get_current_line_number( $xml );
|
||||
$current_column = xml_get_current_column_number( $xml );
|
||||
$error_code = xml_get_error_code( $xml );
|
||||
$error_string = xml_error_string( $error_code );
|
||||
|
||||
return new WP_Error(
|
||||
'XML_parse_error', 'There was an error when reading this WXR file', array(
|
||||
$current_line,
|
||||
$current_column,
|
||||
$error_string,
|
||||
)
|
||||
);
|
||||
}
|
||||
xml_parser_free( $xml );
|
||||
|
||||
if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) {
|
||||
return new WP_Error( 'WXR_parse_error', 'This does not appear to be a WXR file, missing/invalid WXR version number' );
|
||||
}
|
||||
|
||||
return array(
|
||||
'authors' => $this->authors,
|
||||
'posts' => $this->posts,
|
||||
'categories' => $this->category,
|
||||
'tags' => $this->tag,
|
||||
'terms' => $this->term,
|
||||
'base_url' => $this->base_url,
|
||||
'version' => $this->wxr_version,
|
||||
);
|
||||
}
|
||||
|
||||
function tag_open( $parse, $tag, $attr ) {
|
||||
if ( in_array( $tag, $this->wp_tags ) ) {
|
||||
$this->in_tag = substr( $tag, 3 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( in_array( $tag, $this->wp_sub_tags ) ) {
|
||||
$this->in_sub_tag = substr( $tag, 3 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( $tag ) {
|
||||
case 'category':
|
||||
if ( isset( $attr['domain'], $attr['nicename'] ) ) {
|
||||
$this->sub_data['domain'] = $attr['domain'];
|
||||
$this->sub_data['slug'] = $attr['nicename'];
|
||||
}
|
||||
break;
|
||||
case 'item':
|
||||
$this->in_post = TRUE;
|
||||
case 'title':
|
||||
if ( $this->in_post ) {
|
||||
$this->in_tag = 'post_title';
|
||||
}
|
||||
break;
|
||||
case 'guid':
|
||||
$this->in_tag = 'guid';
|
||||
break;
|
||||
case 'dc:creator':
|
||||
$this->in_tag = 'post_author';
|
||||
break;
|
||||
case 'content:encoded':
|
||||
$this->in_tag = 'post_content';
|
||||
break;
|
||||
case 'excerpt:encoded':
|
||||
$this->in_tag = 'post_excerpt';
|
||||
break;
|
||||
|
||||
case 'wp:term_slug':
|
||||
$this->in_tag = 'slug';
|
||||
break;
|
||||
case 'wp:meta_key':
|
||||
$this->in_sub_tag = 'key';
|
||||
break;
|
||||
case 'wp:meta_value':
|
||||
$this->in_sub_tag = 'value';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function cdata( $parser, $cdata ) {
|
||||
if ( ! trim( $cdata ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( FALSE !== $this->in_tag || FALSE !== $this->in_sub_tag ) {
|
||||
$this->cdata .= $cdata;
|
||||
} else {
|
||||
$this->cdata .= trim( $cdata );
|
||||
}
|
||||
}
|
||||
|
||||
function tag_close( $parser, $tag ) {
|
||||
switch ( $tag ) {
|
||||
case 'wp:comment':
|
||||
unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
|
||||
if ( ! empty( $this->sub_data ) ) {
|
||||
$this->data['comments'][] = $this->sub_data;
|
||||
}
|
||||
$this->sub_data = FALSE;
|
||||
break;
|
||||
case 'wp:commentmeta':
|
||||
$this->sub_data['commentmeta'][] = array(
|
||||
'key' => $this->sub_data['key'],
|
||||
'value' => $this->sub_data['value'],
|
||||
);
|
||||
break;
|
||||
case 'category':
|
||||
if ( ! empty( $this->sub_data ) ) {
|
||||
$this->sub_data['name'] = $this->cdata;
|
||||
$this->data['terms'][] = $this->sub_data;
|
||||
}
|
||||
$this->sub_data = FALSE;
|
||||
break;
|
||||
case 'wp:postmeta':
|
||||
if ( ! empty( $this->sub_data ) ) {
|
||||
$this->data['postmeta'][] = $this->sub_data;
|
||||
}
|
||||
$this->sub_data = FALSE;
|
||||
break;
|
||||
case 'item':
|
||||
$this->posts[] = $this->data;
|
||||
$this->data = FALSE;
|
||||
break;
|
||||
case 'wp:category':
|
||||
case 'wp:tag':
|
||||
case 'wp:term':
|
||||
$n = substr( $tag, 3 );
|
||||
array_push( $this->$n, $this->data );
|
||||
$this->data = FALSE;
|
||||
break;
|
||||
case 'wp:author':
|
||||
if ( ! empty( $this->data['author_login'] ) ) {
|
||||
$this->authors[$this->data['author_login']] = $this->data;
|
||||
}
|
||||
$this->data = FALSE;
|
||||
break;
|
||||
case 'wp:base_site_url':
|
||||
$this->base_url = $this->cdata;
|
||||
break;
|
||||
case 'wp:wxr_version':
|
||||
$this->wxr_version = $this->cdata;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( $this->in_sub_tag ) {
|
||||
$this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
|
||||
$this->in_sub_tag = FALSE;
|
||||
} else if ( $this->in_tag ) {
|
||||
$this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
|
||||
$this->in_tag = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$this->cdata = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
|
||||
*/
|
||||
class WXR_Parser_Regex {
|
||||
var $authors = array();
|
||||
var $posts = array();
|
||||
var $categories = array();
|
||||
var $tags = array();
|
||||
var $terms = array();
|
||||
var $base_url = '';
|
||||
|
||||
function __construct() {
|
||||
$this->has_gzip = is_callable( 'gzopen' );
|
||||
}
|
||||
|
||||
function parse( $file ) {
|
||||
$wxr_version = $in_post = FALSE;
|
||||
|
||||
$fp = $this->fopen( $file, 'r' );
|
||||
if ( $fp ) {
|
||||
while ( ! $this->feof( $fp ) ) {
|
||||
$importline = rtrim( $this->fgets( $fp ) );
|
||||
|
||||
if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) ) {
|
||||
$wxr_version = $version[1];
|
||||
}
|
||||
|
||||
if ( FALSE !== strpos( $importline, '<wp:base_site_url>' ) ) {
|
||||
preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
|
||||
$this->base_url = $url[1];
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '<wp:category>' ) ) {
|
||||
preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category );
|
||||
$this->categories[] = $this->process_category( $category[1] );
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '<wp:tag>' ) ) {
|
||||
preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag );
|
||||
$this->tags[] = $this->process_tag( $tag[1] );
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '<wp:term>' ) ) {
|
||||
preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term );
|
||||
$this->terms[] = $this->process_term( $term[1] );
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '<wp:author>' ) ) {
|
||||
preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
|
||||
$a = $this->process_author( $author[1] );
|
||||
$this->authors[$a['author_login']] = $a;
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '<item>' ) ) {
|
||||
$post = '';
|
||||
$in_post = TRUE;
|
||||
continue;
|
||||
}
|
||||
if ( FALSE !== strpos( $importline, '</item>' ) ) {
|
||||
$in_post = FALSE;
|
||||
$this->posts[] = $this->process_post( $post );
|
||||
continue;
|
||||
}
|
||||
if ( $in_post ) {
|
||||
$post .= $importline . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$this->fclose( $fp );
|
||||
}
|
||||
|
||||
if ( ! $wxr_version ) {
|
||||
return new WP_Error( 'WXR_parse_error', 'This does not appear to be a WXR file, missing/invalid WXR version number' );
|
||||
}
|
||||
|
||||
return array(
|
||||
'authors' => $this->authors,
|
||||
'posts' => $this->posts,
|
||||
'categories' => $this->categories,
|
||||
'tags' => $this->tags,
|
||||
'terms' => $this->terms,
|
||||
'base_url' => $this->base_url,
|
||||
'version' => $wxr_version,
|
||||
);
|
||||
}
|
||||
|
||||
function get_tag( $string, $tag ) {
|
||||
preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
|
||||
if ( isset( $return[1] ) ) {
|
||||
if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
|
||||
if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== FALSE ) {
|
||||
preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
|
||||
$return = '';
|
||||
foreach ( $matches[1] as $match ) {
|
||||
$return .= $match;
|
||||
}
|
||||
} else {
|
||||
$return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
|
||||
}
|
||||
} else {
|
||||
$return = $return[1];
|
||||
}
|
||||
} else {
|
||||
$return = '';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function process_category( $c ) {
|
||||
return array(
|
||||
'term_id' => $this->get_tag( $c, 'wp:term_id' ),
|
||||
'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
|
||||
'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
|
||||
'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
|
||||
'category_description' => $this->get_tag( $c, 'wp:category_description' ),
|
||||
);
|
||||
}
|
||||
|
||||
function process_tag( $t ) {
|
||||
return array(
|
||||
'term_id' => $this->get_tag( $t, 'wp:term_id' ),
|
||||
'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
|
||||
'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
|
||||
'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
|
||||
);
|
||||
}
|
||||
|
||||
function process_term( $t ) {
|
||||
return array(
|
||||
'term_id' => $this->get_tag( $t, 'wp:term_id' ),
|
||||
'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
|
||||
'slug' => $this->get_tag( $t, 'wp:term_slug' ),
|
||||
'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
|
||||
'term_name' => $this->get_tag( $t, 'wp:term_name' ),
|
||||
'term_description' => $this->get_tag( $t, 'wp:term_description' ),
|
||||
);
|
||||
}
|
||||
|
||||
function process_author( $a ) {
|
||||
return array(
|
||||
'author_id' => $this->get_tag( $a, 'wp:author_id' ),
|
||||
'author_login' => $this->get_tag( $a, 'wp:author_login' ),
|
||||
'author_email' => $this->get_tag( $a, 'wp:author_email' ),
|
||||
'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
|
||||
'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
|
||||
'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
|
||||
);
|
||||
}
|
||||
|
||||
function process_post( $post ) {
|
||||
$post_id = $this->get_tag( $post, 'wp:post_id' );
|
||||
$post_title = $this->get_tag( $post, 'title' );
|
||||
$post_date = $this->get_tag( $post, 'wp:post_date' );
|
||||
$post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
|
||||
$comment_status = $this->get_tag( $post, 'wp:comment_status' );
|
||||
$ping_status = $this->get_tag( $post, 'wp:ping_status' );
|
||||
$status = $this->get_tag( $post, 'wp:status' );
|
||||
$post_name = $this->get_tag( $post, 'wp:post_name' );
|
||||
$post_parent = $this->get_tag( $post, 'wp:post_parent' );
|
||||
$menu_order = $this->get_tag( $post, 'wp:menu_order' );
|
||||
$post_type = $this->get_tag( $post, 'wp:post_type' );
|
||||
$post_password = $this->get_tag( $post, 'wp:post_password' );
|
||||
$is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
|
||||
$guid = $this->get_tag( $post, 'guid' );
|
||||
$post_author = $this->get_tag( $post, 'dc:creator' );
|
||||
|
||||
$post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
|
||||
$post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
|
||||
$post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
|
||||
$post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
|
||||
|
||||
$post_content = $this->get_tag( $post, 'content:encoded' );
|
||||
$post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
|
||||
$post_content = str_replace( '<br>', '<br />', $post_content );
|
||||
$post_content = str_replace( '<hr>', '<hr />', $post_content );
|
||||
|
||||
$postdata = compact(
|
||||
'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password', 'is_sticky'
|
||||
);
|
||||
|
||||
$attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
|
||||
if ( $attachment_url ) {
|
||||
$postdata['attachment_url'] = $attachment_url;
|
||||
}
|
||||
|
||||
preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
|
||||
foreach ( $terms as $t ) {
|
||||
$post_terms[] = array(
|
||||
'slug' => $t[2],
|
||||
'domain' => $t[1],
|
||||
'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
|
||||
);
|
||||
}
|
||||
if ( ! empty( $post_terms ) ) {
|
||||
$postdata['terms'] = $post_terms;
|
||||
}
|
||||
|
||||
preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
|
||||
$comments = $comments[1];
|
||||
if ( $comments ) {
|
||||
foreach ( $comments as $comment ) {
|
||||
preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
|
||||
$commentmeta = $commentmeta[1];
|
||||
$c_meta = array();
|
||||
foreach ( $commentmeta as $m ) {
|
||||
$c_meta[] = array(
|
||||
'key' => $this->get_tag( $m, 'wp:meta_key' ),
|
||||
'value' => $this->get_tag( $m, 'wp:meta_value' ),
|
||||
);
|
||||
}
|
||||
|
||||
$post_comments[] = array(
|
||||
'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
|
||||
'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
|
||||
'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
|
||||
'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
|
||||
'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
|
||||
'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
|
||||
'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
|
||||
'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
|
||||
'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
|
||||
'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
|
||||
'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
|
||||
'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
|
||||
'commentmeta' => $c_meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( ! empty( $post_comments ) ) {
|
||||
$postdata['comments'] = $post_comments;
|
||||
}
|
||||
|
||||
preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
|
||||
$postmeta = $postmeta[1];
|
||||
if ( $postmeta ) {
|
||||
foreach ( $postmeta as $p ) {
|
||||
$post_postmeta[] = array(
|
||||
'key' => $this->get_tag( $p, 'wp:meta_key' ),
|
||||
'value' => $this->get_tag( $p, 'wp:meta_value' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( ! empty( $post_postmeta ) ) {
|
||||
$postdata['postmeta'] = $post_postmeta;
|
||||
}
|
||||
|
||||
return $postdata;
|
||||
}
|
||||
|
||||
function _normalize_tag( $matches ) {
|
||||
return '<' . strtolower( $matches[1] );
|
||||
}
|
||||
|
||||
function fopen( $filename, $mode = 'r' ) {
|
||||
if ( $this->has_gzip ) {
|
||||
return gzopen( $filename, $mode );
|
||||
}
|
||||
|
||||
return fopen( $filename, $mode );
|
||||
}
|
||||
|
||||
function feof( $fp ) {
|
||||
if ( $this->has_gzip ) {
|
||||
return gzeof( $fp );
|
||||
}
|
||||
|
||||
return feof( $fp );
|
||||
}
|
||||
|
||||
function fgets( $fp, $len = 8192 ) {
|
||||
if ( $this->has_gzip ) {
|
||||
return gzgets( $fp, $len );
|
||||
}
|
||||
|
||||
return fgets( $fp, $len );
|
||||
}
|
||||
|
||||
function fclose( $fp ) {
|
||||
if ( $this->has_gzip ) {
|
||||
return gzclose( $fp );
|
||||
}
|
||||
|
||||
return fclose( $fp );
|
||||
}
|
||||
}
|
||||
+1228
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user