admin_includes();
add_action( 'init', array( $this, 'init_scripts' ) );
add_action( 'init', array( $this, 'init_styles' ) );
// AJAX hide yellow message dontshow
add_action( 'wp_ajax_'.$this->plugin_name.'_a3_admin_ui_event', array( $this, 'a3_admin_ui_event' ) );
add_action( 'wp_ajax_nopriv_'.$this->plugin_name.'_a3_admin_ui_event', array( $this, 'a3_admin_ui_event' ) );
}
/*-----------------------------------------------------------------------------------*/
/* Init scripts */
/*-----------------------------------------------------------------------------------*/
public function init_scripts() {
$admin_pages = $this->admin_pages();
if ( is_admin() && isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $admin_pages ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_script_load' ) );
do_action( $this->plugin_name . '_init_scripts' );
add_action( 'admin_print_scripts', array( $this, 'admin_localize_printed_scripts' ), 5 );
add_action( 'admin_print_footer_scripts', array( $this, 'admin_localize_printed_scripts' ), 5 );
}
}
/*-----------------------------------------------------------------------------------*/
/* Init styles */
/*-----------------------------------------------------------------------------------*/
public function init_styles() {
$admin_pages = $this->admin_pages();
if ( is_admin() && isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $admin_pages ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'register_fontawesome_style' ), 0 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_css_load' ) );
do_action( $this->plugin_name . '_init_styles' );
}
}
public function register_fontawesome_style() {
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_register_style( 'font-awesome-styles', $this->admin_plugin_url() . '/assets/css/font-awesome' . $suffix . '.css', array(), '4.5.0', 'all' );
}
/*-----------------------------------------------------------------------------------*/
/* admin_script_load */
/*-----------------------------------------------------------------------------------*/
public function admin_script_load() {
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
$rtl = is_rtl() ? '.rtl' : '';
wp_register_script( 'chosen', $this->admin_plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), true, false );
wp_register_script( 'a3rev-chosen-new', $this->admin_plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), true, false );
wp_register_script( 'a3rev-style-checkboxes', $this->admin_plugin_url() . '/assets/js/iphone-style-checkboxes' . $rtl . '.js', array('jquery'), true, false );
wp_register_script( 'jquery-ui-slider-rtl', $this->admin_plugin_url() . '/assets/js/ui-slider/jquery.ui.slider.rtl' . $suffix . '.js', array('jquery'), true, true );
wp_register_script( 'a3rev-admin-ui-script', $this->admin_plugin_url() . '/assets/js/admin-ui-script.js', array('jquery'), true, true );
wp_register_script( 'a3rev-typography-preview', $this->admin_plugin_url() . '/assets/js/a3rev-typography-preview.js', array('jquery'), false, true );
wp_register_script( 'a3rev-settings-preview', $this->admin_plugin_url() . '/assets/js/a3rev-settings-preview.js', array('jquery'), false, true );
wp_register_script( 'jquery-tiptip', $this->admin_plugin_url() . '/assets/js/tipTip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), true, true );
wp_register_script( 'a3rev-metabox-ui', $this->admin_plugin_url() . '/assets/js/data-meta-boxes.js', array( 'jquery' ), true, true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'wp-color-picker' );
if ( is_rtl() ) {
wp_enqueue_script( 'jquery-ui-slider-rtl' );
} else {
wp_enqueue_script( 'jquery-ui-slider' );
}
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'a3rev-chosen-new' );
wp_enqueue_script( 'a3rev-style-checkboxes' );
wp_enqueue_script( 'a3rev-admin-ui-script' );
wp_enqueue_script( 'a3rev-typography-preview' );
wp_enqueue_script( 'a3rev-settings-preview' );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'a3rev-metabox-ui' );
} // End admin_script_load()
/*-----------------------------------------------------------------------------------*/
/* admin_localize_printed_scripts: Localize scripts only when enqueued */
/*-----------------------------------------------------------------------------------*/
public function admin_localize_printed_scripts() {
$rtl = is_rtl() ? 1 : 0;
if ( wp_script_is( 'a3rev-admin-ui-script' ) ) {
wp_localize_script( 'a3rev-admin-ui-script', 'a3_admin_ui_script_params', apply_filters( 'a3_admin_ui_script_params', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'plugin' => $this->plugin_name,
'security' => wp_create_nonce( $this->plugin_name . '_a3_admin_ui_event' ),
'rtl' => $rtl,
) ) );
}
} // End admin_localize_printed_scripts()
public function a3_admin_ui_event() {
check_ajax_referer( $this->plugin_name. '_a3_admin_ui_event', 'security' );
if ( isset( $_REQUEST['type'] ) ) {
switch ( trim( $_REQUEST['type'] ) ) {
case 'open_close_panel_box':
$form_key = $_REQUEST['form_key'];
$box_id = $_REQUEST['box_id'];
$is_open = $_REQUEST['is_open'];
$user_id = get_current_user_id();
$opened_box = get_user_meta( $user_id, $this->plugin_name . '-' . trim( $form_key ), true );
if ( empty( $opened_box ) || ! is_array( $opened_box ) ) {
$opened_box = array();
}
if ( 1 == $is_open && ! in_array( $box_id, $opened_box ) ) {
$opened_box[] = $box_id;
} elseif ( 0 == $is_open && in_array( $box_id, $opened_box ) ) {
$opened_box = array_diff( $opened_box, array( $box_id ) );
}
update_user_meta( $user_id, $this->plugin_name . '-' . trim( $form_key ), $opened_box );
break;
case 'check_new_version':
$transient_name = $_REQUEST['transient_name'];
delete_transient( $transient_name );
$new_version = '';
if ( class_exists( 'A3_Portfolio_Upgrade' ) ) {
$new_version = A3_Portfolio_Upgrade::get_version_info();
}
$version_message = $this->get_version_message();
$has_new_version = 1;
if ( '' == trim( $version_message ) ) {
$version_message = __( 'Great! You have the latest version installed.', 'a3_portfolios' );
$has_new_version = 0;
} else {
delete_option('a3_portfolios_clean_on_deletion');
if ( is_array( $new_version ) && 'valid' == $new_version['is_valid_key'] ) {
$current_update_plugins = get_site_transient( 'update_plugins' );
if ( isset( $current_update_plugins->response ) ) {
$plugin_name = A3_PORTFOLIO_NAME;
if ( empty( $current_update_plugins->response[$plugin_name] ) ) {
$current_update_plugins->response[$plugin_name] = new stdClass();
}
$current_update_plugins->response[$plugin_name]->url = "http://www.a3rev.com";
$current_update_plugins->response[$plugin_name]->slug = get_option( $this->plugin_option_key );
$current_update_plugins->response[$plugin_name]->package = $new_version["url"];
$current_update_plugins->response[$plugin_name]->new_version = $new_version['version'];
$current_update_plugins->response[$plugin_name]->upgrade_notice = $new_version['upgrade_notice'];
$current_update_plugins->response[$plugin_name]->id = "0";
set_site_transient( 'update_plugins', $current_update_plugins );
}
}
}
$response_data = array(
'has_new_version' => $has_new_version,
'version_message' => $version_message,
);
echo json_encode( $response_data );
break;
}
}
die();
}
/*-----------------------------------------------------------------------------------*/
/* admin_css_load */
/*-----------------------------------------------------------------------------------*/
public function admin_css_load () {
global $wp_version;
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'a3rev-admin-ui-style', $this->admin_plugin_url() . '/assets/css/admin-ui-style' . $suffix . '.css' );
if ( version_compare( $wp_version, '3.8', '>=' ) ) {
wp_enqueue_style( 'a3rev-admin-flat-ui-style', $this->admin_plugin_url() . '/assets/css/admin-flat-ui-style' . $suffix . '.css' );
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'a3rev-chosen-new-style', $this->admin_plugin_url() . '/assets/js/chosen/chosen' . $suffix . '.css' );
wp_enqueue_style( 'a3rev-tiptip-style', $this->admin_plugin_url() . '/assets/js/tipTip/tipTip.css' );
wp_enqueue_style( 'a3rev-metabox-ui-style', $this->admin_plugin_url() . '/assets/css/a3_admin_metabox.css' );
if ( is_rtl() ) {
wp_enqueue_style( 'a3rev-admin-ui-style-rtl', $this->admin_plugin_url() . '/assets/css/admin-ui-style.rtl' . $suffix . '.css' );
wp_enqueue_style( 'a3rev-metabox-ui-style-rtl', $this->admin_plugin_url() . '/assets/css/a3_admin_metabox.rtl' . $suffix . '.css' );
}
} // End admin_css_load()
/*-----------------------------------------------------------------------------------*/
/* get_success_message */
/*-----------------------------------------------------------------------------------*/
public function get_success_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Settings successfully saved.' , 'a3_portfolios' );
return '
';
}
/*-----------------------------------------------------------------------------------*/
/* get_error_message */
/*-----------------------------------------------------------------------------------*/
public function get_error_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Error: Settings can not save.' , 'a3_portfolios' );
return '';
}
/*-----------------------------------------------------------------------------------*/
/* get_reset_message */
/*-----------------------------------------------------------------------------------*/
public function get_reset_message( $message = '' ) {
if ( trim( $message ) == '' ) $message = __( 'Settings successfully reseted.' , 'a3_portfolios' );
return '';
}
/*-----------------------------------------------------------------------------------*/
/* admin_includes */
/* Include required core files used in admin UI.
/*-----------------------------------------------------------------------------------*/
public function admin_includes() {
// Includes Font Face Lib
include_once( 'includes/fonts_face.php' );
// Includes Uploader Lib
include_once( 'includes/uploader/class-uploader.php' );
}
/*-----------------------------------------------------------------------------------*/
/* Get Font Weights */
/*-----------------------------------------------------------------------------------*/
public function get_font_weights() {
$font_weights = array (
'300' => __( 'Thin', 'a3_portfolios' ),
'300 italic' => __( 'Thin/Italic', 'a3_portfolios' ),
'normal' => __( 'Normal', 'a3_portfolios' ),
'italic' => __( 'Italic', 'a3_portfolios' ),
'bold' => __( 'Bold', 'a3_portfolios' ),
'bold italic' => __( 'Bold/Italic', 'a3_portfolios' ),
);
return apply_filters( $this->plugin_name . '_font_weights', $font_weights );
}
/*-----------------------------------------------------------------------------------*/
/* Get Border Styles */
/*-----------------------------------------------------------------------------------*/
public function get_border_styles() {
$border_styles = array (
'solid' => __( 'Solid', 'a3_portfolios' ),
'double' => __( 'Double', 'a3_portfolios' ),
'dashed' => __( 'Dashed', 'a3_portfolios' ),
'dotted' => __( 'Dotted', 'a3_portfolios' ),
'groove' => __( 'Groove', 'a3_portfolios' ),
'ridge' => __( 'Ridge', 'a3_portfolios' ),
'inset' => __( 'Inset', 'a3_portfolios' ),
'outset' => __( 'Outset', 'a3_portfolios' ),
);
return apply_filters( $this->plugin_name . '_border_styles', $border_styles );
}
/*-----------------------------------------------------------------------------------*/
/* Get Settings Default Function - get_settings_default */
/* Just called for when option values is an array and it's in single option name for all settings
/*-----------------------------------------------------------------------------------*/
public function get_settings_default( $options, $option_name = '' ) {
$default_settings = array();
if ( !is_array( $options ) || count( $options ) < 1 ) return $default_settings;
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
// Do not include when it's separate option
if ( isset( $text_field['separate_option'] ) && $text_field['separate_option'] != false ) continue;
// Remove [, ] characters from id argument
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
$default_settings[$id_attribute] = $text_field['default'];
}
break;
default :
// Do not include when it's separate option
if ( isset( $value['separate_option'] ) && $value['separate_option'] != false ) continue;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
$default_settings[$id_attribute] = $value['default'];
break;
}
}
if ( trim( $option_name ) != '' ) $default_settings = apply_filters( $this->plugin_name . '_' . $option_name . '_default_settings' , $default_settings );
if ( ! is_array( $default_settings ) ) $default_settings = array();
return $default_settings;
}
/*-----------------------------------------------------------------------------------*/
/* Get Settings Function - get_settings */
/*-----------------------------------------------------------------------------------*/
public function get_settings( $options, $option_name = '' ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
$new_settings = array(); $new_single_setting = ''; // :)
// Get settings for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
global ${$option_name};
$default_settings = $this->get_settings_default( $options, $option_name );
$current_settings = get_option( $option_name );
if ( ! is_array( $current_settings ) ) $current_settings = array();
$current_settings = array_merge( $default_settings, $current_settings );
$current_settings = array_map( array( $this, 'admin_stripslashes' ), $current_settings );
$current_settings = apply_filters( $this->plugin_name . '_' . $option_name . '_get_settings' , $current_settings );
$$option_name = $current_settings;
}
// Get settings for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
global ${$id_attribute};
$current_setting = get_option( $id_attribute, $value['default'] );
switch ( $value['type'] ) {
// Array textfields
case 'wp_editor' :
if ( is_array( $current_setting ) )
$current_setting = array_map( array( $this, 'stripslashes' ), $current_setting );
elseif ( ! is_null( $current_setting ) )
$current_setting = stripslashes( $current_setting );
break;
default:
if ( is_array( $current_setting ) )
$current_setting = array_map( array( $this, 'admin_stripslashes' ), $current_setting );
elseif ( ! is_null( $current_setting ) )
$current_setting = esc_attr( stripslashes( $current_setting ) );
break;
}
$current_setting = apply_filters( $this->plugin_name . '_' . $id_attribute . '_get_setting' , $current_setting );
$$id_attribute = $current_setting;
}
}
// :)
if ( ! isset( $this->is_free_plugin ) || ! $this->is_free_plugin ) {
$fs = array( 0 => 'c', 1 => 'p', 2 => 'h', 3 => 'i', 4 => 'e', 5 => 'n', 6 => 'k', 7 => '_' );
$cs = array( 0 => 'U', 1 => 'g', 2 => 'p', 3 => 'r', 4 => 'd', 5 => 'a', 6 => 'e', 7 => '_' );
$check_settings_save = true;
if ( isset( $this->class_name ) && ! class_exists( $this->class_name . $cs[7] . $cs[0] . $cs[2] . $cs[1] . $cs[3] . $cs[5] . $cs[4] . $cs[6] ) ) {
$check_settings_save = false;
}
if ( ! function_exists( $this->plugin_name . $fs[7] . $fs[0] . $fs[2] . $fs[4] . $fs[0] . $fs[6] . $fs[7] . $fs[1] . $fs[3] . $fs[5] ) ) {
$check_settings_save = false;
}
if ( ! $check_settings_save ) {
if ( trim( $option_name ) != '' ) {
update_option( $option_name, $new_settings );
$$option_name = $new_settings;
}
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
update_option( $id_attribute, $new_single_setting );
$$id_attribute = $new_single_setting;
}
}
}
}
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Save Settings Function - save_settings */
/*-----------------------------------------------------------------------------------*/
public function save_settings( $options, $option_name = '' ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
if ( empty( $_POST ) ) return false;
$update_options = array();
$update_separate_options = array();
//var_dump($_POST);
// Get settings for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
// Save for global settings of plugin framework
switch ( $value['type'] ) {
// Toggle Box Open
case 'onoff_toggle_box' :
if ( isset( $_POST[ $this->toggle_box_open_option ] ) ) {
$option_value = 1;
} else {
$option_value = 0;
}
update_option( $this->toggle_box_open_option, $option_value );
break;
}
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $value['id'] );
}
// Get the option name
$option_value = null;
switch ( $value['type'] ) {
// Checkbox type
case 'checkbox' :
case 'onoff_checkbox' :
case 'switcher_checkbox' :
if ( ! isset( $value['checked_value'] ) ) $value['checked_value'] = 1;
if ( ! isset( $value['unchecked_value'] ) ) $value['unchecked_value'] = 0;
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $value['checked_value'];
} else {
$option_value = $value['unchecked_value'];
}
}
}
break;
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
// Get the option name
$option_value = null;
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $_POST[ $id_attribute ];
} else {
$option_value = '';
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ];
} else {
$option_value = '';
}
}
}
if ( strstr( $text_field['id'], '[' ) ) {
// Set keys and value
$key = key( $option_array[ $id_attribute ] );
$update_options[ $id_attribute ][ $key ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ][ $key ] = $option_value;
}
} else {
$update_options[ $id_attribute ] = $option_value;
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ] = $option_value;
}
}
}
break;
// Other types
default :
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $key != false ) {
if ( isset( $_POST[ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $id_attribute ] ) ) {
$option_value = $_POST[ $id_attribute ];
} else {
$option_value = '';
}
}
} else {
if ( $key != false ) {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ][ $key ];
} else {
$option_value = '';
}
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ] ) ) {
$option_value = $_POST[ $option_name ][ $id_attribute ];
} else {
$option_value = '';
}
}
}
// Just for Color type
if ( 'color' == $value['type'] && '' == trim( $option_value ) ) {
$option_value = 'transparent';
}
// Just for Background Color type
elseif ( 'bg_color' == $value['type'] && '' == trim( $option_value['color'] ) ) {
$option_value['color'] = 'transparent';
} elseif ( 'upload' == $value['type'] ) {
// Uploader: Set key and value for attachment id of upload type
if ( strstr( $value['id'], '[' ) ) {
$key = key( $option_array[ $id_attribute ] );
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
if ( isset( $_POST[ $id_attribute ][ $key . '_attachment_id' ] ) ) {
$attachment_id = $_POST[ $id_attribute ][ $key . '_attachment_id' ];
} else {
$attachment_id = 0;
}
$update_separate_options[ $id_attribute ][ $key . '_attachment_id' ] = $attachment_id;
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute ][ $key . '_attachment_id' ] ) ) {
$attachment_id = $_POST[ $option_name ][ $id_attribute ][ $key . '_attachment_id' ];
} else {
$attachment_id = 0;
}
$update_options[ $id_attribute ][ $key . '_attachment_id' ] = $attachment_id;
}
} else {
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
if ( isset( $_POST[ $id_attribute . '_attachment_id' ] ) ) {
$attachment_id = $_POST[ $id_attribute . '_attachment_id' ];
} else {
$attachment_id = 0;
}
$update_separate_options[ $id_attribute . '_attachment_id' ] = $attachment_id;
} else {
if ( isset( $_POST[ $option_name ][ $id_attribute . '_attachment_id' ] ) ) {
$attachment_id = $_POST[ $option_name ][ $id_attribute . '_attachment_id' ];
} else {
$attachment_id = 0;
}
$update_options[ $id_attribute . '_attachment_id' ] = $attachment_id;
}
}
}
break;
}
if ( !in_array( $value['type'], array( 'array_textfields' ) ) ) {
if ( strstr( $value['id'], '[' ) ) {
// Set keys and value
$key = key( $option_array[ $id_attribute ] );
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ][ $key ] = $option_value;
} else {
$update_options[ $id_attribute ][ $key ] = $option_value;
}
} else {
if ( trim( $option_name ) != '' && $value['separate_option'] != false ) {
$update_separate_options[ $id_attribute ] = $option_value;
} else {
$update_options[ $id_attribute ] = $option_value;
}
}
}
}
// Save settings for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
update_option( $option_name, $update_options );
}
// Save options if each option save in a row
if ( count( $update_options ) > 0 && trim( $option_name ) == '' ) {
foreach ( $update_options as $name => $value ) {
update_option( $name, $value );
}
}
// Save separate options
if ( count( $update_separate_options ) > 0 ) {
foreach ( $update_separate_options as $name => $value ) {
update_option( $name, $value );
}
}
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Reset Function - reset_settings */
/*-----------------------------------------------------------------------------------*/
public function reset_settings( $options, $option_name = '', $reset = false, $free_version = false ) {
if ( !is_array( $options ) || count( $options ) < 1 ) return;
// Update settings default for option values is an array and it's in single option name for all settings
if ( trim( $option_name ) != '' ) {
$default_settings = $this->get_settings_default( $options, $option_name );
$current_settings = get_option( $option_name );
if ( ! is_array( $current_settings ) ) $current_settings = array();
$current_settings = array_merge( $default_settings, $current_settings );
if ( $reset && !$free_version ) {
update_option( $option_name, $default_settings );
} else {
if ( $free_version ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
if ( ! isset( $text_field['free_version'] ) ) {
if ( ! isset( $value['free_version'] ) )
$text_field['free_version'] = false;
else
$text_field['free_version'] = $value['free_version'];
}
if ( $text_field['free_version'] ) unset( $default_settings[ $text_field['id']] );
}
break;
default :
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
if ( $value['free_version'] ) unset( $default_settings[ $value['id']] );
break;
}
}
$current_settings = array_merge( $current_settings, $default_settings );
update_option( $option_name, $current_settings );
} else {
update_option( $option_name, $current_settings );
}
}
}
// Update settings default for option value is stored as a record or it's spearate option
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( in_array( $value['type'], array( 'heading' ) ) ) continue;
if ( ! isset( $value['id'] ) || trim( $value['id'] ) == '' ) continue;
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['free_version'] ) ) $value['free_version'] = false;
// For way it has an option name
if ( ! isset( $value['separate_option'] ) ) $value['separate_option'] = false;
switch ( $value['type'] ) {
// Array textfields
case 'array_textfields' :
if ( !isset( $value['ids'] ) || !is_array( $value['ids'] ) || count( $value['ids'] ) < 1 ) break;
foreach ( $value['ids'] as $text_field ) {
if ( ! isset( $text_field['id'] ) || trim( $text_field['id'] ) == '' ) continue;
if ( ! isset( $text_field['default'] ) ) $text_field['default'] = '';
if ( ! isset( $text_field['free_version'] ) ) {
if ( ! isset( $value['free_version'] ) )
$text_field['free_version'] = false;
else
$text_field['free_version'] = $value['free_version'];
}
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $text_field['id'], '[' ) ) {
parse_str( esc_attr( $text_field['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $text_field['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $reset && $text_field['free_version'] && !$free_version ) {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
$current_settings[$key] = $text_field['default'];
update_option( $id_attribute, $current_settings );
} else {
update_option( $id_attribute, $text_field['default'] );
}
} elseif ( $reset && !$text_field['free_version'] ) {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
$current_settings[$key] = $text_field['default'];
update_option( $id_attribute, $current_settings );
} else {
update_option( $id_attribute, $text_field['default'] );
}
} else {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
if ( ! isset( $current_settings[$key] ) ) {
$current_settings[$key] = $text_field['default'];
update_option( $id_attribute, $current_settings );
}
} else {
add_option( $id_attribute, $text_field['default'] );
}
}
}
}
break;
default :
// Remove [, ] characters from id argument
$key = false;
if ( strstr( $value['id'], '[' ) ) {
parse_str( esc_attr( $value['id'] ), $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$first_key = current( $option_keys );
$id_attribute = $first_key;
$key = key( $option_array[ $id_attribute ] );
} else {
$id_attribute = esc_attr( $value['id'] );
}
if ( trim( $option_name ) == '' || $value['separate_option'] != false ) {
if ( $reset && $value['free_version'] && !$free_version ) {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
$current_settings[$key] = $value['default'];
update_option( $id_attribute, $current_settings );
} else {
update_option( $id_attribute, $value['default'] );
}
} elseif ( $reset && !$value['free_version'] ) {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
$current_settings[$key] = $value['default'];
update_option( $id_attribute, $current_settings );
} else {
update_option( $id_attribute, $value['default'] );
}
} else {
if ( $key != false ) {
$current_settings = get_option( $id_attribute, array() );
if ( ! is_array( $current_settings) ) {
$current_settings = array();
}
if ( ! isset( $current_settings[$key] ) ) {
$current_settings[$key] = $value['default'];
update_option( $id_attribute, $current_settings );
}
} else {
add_option( $id_attribute, $value['default'] );
}
}
}
break;
}
}
}
/*-----------------------------------------------------------------------------------*/
/* Get Option Value Function - settings_get_option */
/* Just called for when each option has an option value for settings
/*-----------------------------------------------------------------------------------*/
public function settings_get_option( $option_name, $default = '' ) {
// Array value
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key
$option_keys = array_keys( $option_array );
$option_name = current( $option_keys );
// Get value
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) )
$option_value = $option_values[ $key ];
else
$option_value = null;
// Single value
} else {
$option_value = get_option( $option_name, null );
}
if ( is_array( $option_value ) )
$option_value = array_map( 'stripslashes', $option_value );
elseif ( ! is_null( $option_value ) )
$option_value = stripslashes( $option_value );
return $option_value === null ? $default : $option_value;
}
/**
* Output admin fields.
*
*
* @access public
* @param array $options : Opens array to output
* @param text $form_key : It's unique key for form to get correct save and reset action for this form
* @param text $option_name : Save all settings as array into database for a single option name
* @param array $form_messages : { 'success_message' => '', 'error_message' => '', 'reset_message' => '' }
* @return void
* ========================================================================
* Option Array Structure :
* type => heading | google_api_key | onoff_toggle_box | text | email | number | password | color | bg_color | textarea | select | multiselect | radio | onoff_radio | checkbox | onoff_checkbox
* | switcher_checkbox | image_size | single_select_page | typography | border | border_styles | border_corner | box_shadow
* | slider | upload | wp_editor | array_textfields |
*
* id => text
* name => text
* free_version => true | false : if Yes then when save settings with $free_version = true, it does reset this option
* class => text
* css => text
* default => text : apply for other types
* array( 'enable' => 1, 'color' => '#515151' ) : apply bg_color only
* array( 'width' => '125', 'height' => '125', 'crop' => 1 ) : apply image_size only
* array( 'size' => '9px', 'face' => 'Arial', 'style' => 'normal', 'color' => '#515151' ) : apply for typography only
* array( 'width' => '1px', 'style' => 'normal', 'color' => '#515151', 'corner' => 'rounded' | 'square' , 'top_left_corner' => 3,
* 'top_right_corner' => 3, 'bottom_left_corner' => 3, 'bottom_right_corner' => 3 ) : apply for border only
* array( 'width' => '1px', 'style' => 'normal', 'color' => '#515151' ) : apply for border_styles only
* array( 'corner' => 'rounded' | 'square' , 'top_left_corner' => 3, 'top_right_corner' => 3, 'bottom_left_corner' => 3,
* 'bottom_right_corner' => 3 ) : apply for border_corner only
* array( 'enable' => 1|0, 'h_shadow' => '5px' , 'v_shadow' => '5px', 'blur' => '2px' , 'spread' => '2px', 'color' => '#515151',
* 'inset' => '' | 'insert' ) : apply for box_shadow only
*
* desc => text
* desc_tip => text
* separate_option => true | false
* custom_attributes => array
* view_doc => allowed html code : apply for heading only
* placeholder => text : apply for input, email, number, password, textarea, select, multiselect and single_select_page
* hide_if_checked => true | false : apply for checkbox only
* show_if_checked => true | false : apply for checkbox only
* checkboxgroup => start | end : apply for checkbox only
* checked_value => text : apply for checkbox, onoff_checkbox, switcher_checkbox only ( it's value set to database when checkbox is checked )
* unchecked_value => text : apply for checkbox, onoff_checkbox, switcher_checkbox only ( it's value set to database when checkbox is unchecked )
* checked_label => text : apply for onoff_checkbox, switcher_checkbox only ( set it to show the text instead ON word default )
* unchecked_label => text : apply for onoff_checkbox, switcher_checkbox only ( set it to show the text instead OFF word default )
* options => array : apply for select, multiselect, radio types
*
* onoff_options => array : apply for onoff_radio only
* ---------------- example ---------------------
* array(
* array( 'val' => 1,
* 'text' => 'Top',
* 'checked_label' => 'ON',
* 'unchecked_value' => 'OFF' ),
*
* array( 'val' => 2,
* 'text' => 'Bottom',
* 'checked_label' => 'ON',
* 'unchecked_value' => 'OFF' ),
* )
* ---------------------------------------------
*
* args => array : apply for single_select_page only
* min => number : apply for slider, border, border_corner types only
* max => number : apply for slider, border, border_corner types only
* increment => number : apply for slider, border, border_corner types only
* textarea_rows => number : apply for wp_editor type only
*
* ids => array : apply for array_textfields only
* ---------------- example ---------------------
* array(
* array( 'id' => 'box_margin_top',
* 'name' => 'Top',
* 'class' => '',
* 'css' => 'width:40px;',
* 'default' => '10px' ),
*
* array( 'id' => 'box_margin_top',
* 'name' => 'Top',
* 'class' => '',
* 'css' => 'width:40px;',
* 'default' => '10px' ),
* )
* ---------------------------------------------
*
* strip_methods => true | false : apply for upload type only
*
*/
public function admin_forms( $options, $form_key, $option_name = '', $form_messages = array() ) {
global $a3_portfolio_fonts_face, $a3_portfolio_uploader, $current_subtab;
$new_settings = array(); $new_single_setting = ''; // :)
$admin_message = '';
if ( isset( $_POST['form_name_action'] ) && $_POST['form_name_action'] == $form_key ) {
do_action( $this->plugin_name . '_before_settings_save_reset' );
do_action( $this->plugin_name . '-' . trim( $form_key ) . '_before_settings_save' );
// Save settings action
if ( isset( $_POST['bt_save_settings'] ) ) {
$this->save_settings( $options, $option_name );
$admin_message = $this->get_success_message( ( isset( $form_messages['success_message'] ) ) ? $form_messages['success_message'] : '' );
}
// Reset settings action
elseif ( isset( $_POST['bt_reset_settings'] ) ) {
$this->reset_settings( $options, $option_name, true );
$admin_message = $this->get_success_message( ( isset( $form_messages['reset_message'] ) ) ? $form_messages['reset_message'] : '' );
}
do_action( $this->plugin_name . '-' . trim( $form_key ) . '_after_settings_save' );
do_action( $this->plugin_name . '_after_settings_save_reset' );
}
do_action( $this->plugin_name . '-' . trim( $form_key ) . '_settings_init' );
do_action( $this->plugin_name . '_settings_init' );
$option_values = array();
if ( trim( $option_name ) != '' ) {
$option_values = get_option( $option_name, array() );
if ( is_array( $option_values ) )
$option_values = array_map( array( $this, 'admin_stripslashes' ), $option_values );
else
$option_values = array();
$default_settings = $this->get_settings_default( $options, $option_name );
$option_values = array_merge($default_settings, $option_values);
}
if ( !is_array( $options ) || count( $options ) < 1 ) return '';
?>
' . "\n\n";
if ( trim( $end_heading_id ) != '' ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $end_heading_id ) . '_after' );
}
if ( ! empty( $value['id'] ) )
$end_heading_id = $value['id'];
else
$end_heading_id = '';
if ( $header_sub_box_opening ) {
$header_sub_box_opening = false;
// close box inside
echo '' . "\n\n";
// close panel box
echo '' . "\n\n";
}
if ( $is_box && $header_box_opening && ! $is_sub ) {
$header_box_opening = false;
// close box inside
echo '' . "\n\n";
// close panel box
echo '' . "\n\n";
}
$view_doc = ( isset( $value['view_doc'] ) ) ? $value['view_doc'] : '';
if ( ! empty( $value['id'] ) ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $value['id'] ) . '_before' );
if ( $is_box ) {
$heading_box_id = $count_heading;
if ( ! empty( $value['id'] ) ) {
$heading_box_id = $value['id'];
}
$toggle_box_class = 'enable_toggle_box_save';
$opened_class = '';
if ( in_array( $heading_box_id, $opened_box ) && 1 == $toggle_box_open ) {
$opened_class = 'box_open';
}
if ( isset( $_POST['bt_save_settings']) && in_array( $heading_box_id, $opened_box ) ) {
$opened_class = 'box_open';
}
// Change to open box for the heading set alway_open = true
if ( isset( $value['alway_open'] ) && true == $value['alway_open'] ) {
$opened_class = 'box_open';
}
// Change to close box for the heading set alway_close = true
if ( isset( $value['alway_close'] ) && true == $value['alway_close'] ) {
$opened_class = '';
}
// Make the box open on first load with this argument first_open = true
if ( isset( $value['first_open'] ) && true == $value['first_open'] ) {
$this_box_is_opened = get_user_meta( $user_id, $this->plugin_name . '-' . trim( $heading_box_id ) . '-' . 'opened', true );
if ( empty( $this_box_is_opened ) ) {
$opened_class = 'box_open';
add_user_meta( $user_id, $this->plugin_name . '-' . trim( $heading_box_id ) . '-' . 'opened', 1 );
}
}
// open panel box
echo '' . "\n\n";
// open box handle
echo '
' . "\n\n";
echo ( ! empty( $value['name'] ) ) ? '
'. esc_html( $value['name'] ) .' '. $view_doc .' ' : '';
if ( stristr( $value['class'], 'pro_feature_fields' ) !== false && ! empty( $value['id'] ) ) $this->upgrade_top_message( true, sanitize_title( $value['id'] ) );
elseif ( stristr( $value['class'], 'pro_feature_fields' ) !== false ) $this->upgrade_top_message( true );
// close box handle
echo '' . "\n\n";
// open box inside
echo '
' . "\n\n";
echo '
' . "\n\n";
if ( $is_sub ) {
// Mark this heading as a sub box is openning to check for close it on next header box
$header_sub_box_opening = true;
} else {
// Mark this heading as a box is openning to check for close it on next header box
$header_box_opening = true;
}
} else {
echo '
' . "\n\n";
if ( stristr( $value['class'], 'pro_feature_fields' ) !== false && ! empty( $value['id'] ) ) $this->upgrade_top_message( true, sanitize_title( $value['id'] ) );
elseif ( stristr( $value['class'], 'pro_feature_fields' ) !== false ) $this->upgrade_top_message( true );
echo ( ! empty( $value['name'] ) ) ? '
'. esc_html( $value['name'] ) .' '. $view_doc .' ' : '';
}
if ( ! empty( $value['desc'] ) ) {
echo '
' . "\n\n";
echo wpautop( wptexturize( $value['desc'] ) );
echo '
' . "\n\n";
}
echo '
' . "\n\n";
echo '
' . "\n\n";
if ( trim( $end_heading_id ) != '' ) do_action( $this->plugin_name . '_settings_' . sanitize_title( $end_heading_id ) . '_after' );
}
if ( $header_sub_box_opening ) {
$header_sub_box_opening = false;
// close box inside
echo '
' . "\n\n";
// close panel box
echo '
' . "\n\n";
}
if ( $header_box_opening ) {
$header_box_opening = false;
// close box inside
echo '
' . "\n\n";
// close panel box
echo '' . "\n\n";
}
?>
plugin_name . '-' . trim( $form_key ) . '_settings_end' ); ?>
plugin_name . '-custom-boxes' , true );
if ( empty( $opened_box ) || ! is_array( $opened_box ) ) {
$opened_box = array();
}
$toggle_box_open = $this->settings_get_option( $this->toggle_box_open_option, 0 );
$toggle_box_class = '';
if ( 1 == $toggle_box_open ) {
$toggle_box_class = 'enable_toggle_box_save';
}
$opened_class = '';
if ( in_array( $heading_box_id, $opened_box ) && 1 == $toggle_box_open ) {
$opened_class = 'box_open';
}
// Change to open box for the heading set alway_open = true
if ( isset( $options['alway_open'] ) && true == $options['alway_open'] ) {
$opened_class = 'box_open';
}
// Change to close box for the heading set alway_close = true
if ( isset( $options['alway_close'] ) && true == $options['alway_close'] ) {
$opened_class = '';
}
// Make the box open on first load with this argument first_open = true
if ( isset( $options['first_open'] ) && true == $options['first_open'] ) {
$this_box_is_opened = get_user_meta( $user_id, $this->plugin_name . '-' . trim( $heading_box_id ) . '-' . 'opened', true );
if ( empty( $this_box_is_opened ) ) {
$opened_class = 'box_open';
add_user_meta( $user_id, $this->plugin_name . '-' . trim( $heading_box_id ) . '-' . 'opened', 1 );
}
}
} else {
$toggle_box_class = '';
$opened_class = '';
}
// open panel box
echo '' . "\n\n";
// open box handle
echo '
' . "\n\n";
echo ( ! empty( $options['name'] ) ) ? '
'. esc_html( $options['name'] ) .' '. $view_doc .' ' : '';
if ( stristr( $options['class'], 'pro_feature_fields' ) !== false && ! empty( $options['id'] ) ) $this->upgrade_top_message( true, sanitize_title( $options['id'] ) );
elseif ( stristr( $options['class'], 'pro_feature_fields' ) !== false ) $this->upgrade_top_message( true );
// close box handle
echo '' . "\n\n";
// open box inside
echo '
' . "\n\n";
echo '
' . "\n\n";
} else {
echo '
' . "\n\n";
if ( stristr( $options['class'], 'pro_feature_fields' ) !== false && ! empty( $options['id'] ) ) $this->upgrade_top_message( true, sanitize_title( $options['id'] ) );
elseif ( stristr( $options['class'], 'pro_feature_fields' ) !== false ) $this->upgrade_top_message( true );
echo ( ! empty( $options['name'] ) ) ? '
'. esc_html( $options['name'] ) .' '. $view_doc .' ' : '';
}
if ( ! empty( $options['desc'] ) ) {
echo '
' . "\n\n";
echo wpautop( wptexturize( $options['desc'] ) );
echo '
' . "\n\n";
}
echo $settings_html;
echo '
';
if ( $is_box ) {
// close box inside
echo '
' . "\n\n";
// close panel box
echo '
' . "\n\n";
}
}
/*-----------------------------------------------------------------------------------*/
/* Custom Stripslashed for array in array - admin_stripslashes() */
/*-----------------------------------------------------------------------------------*/
public function admin_stripslashes( $values ) {
if ( is_array( $values ) ) {
$values = array_map( array( $this, 'admin_stripslashes' ), $values );
} else {
$values = esc_attr( stripslashes( $values ) );
}
return $values;
}
/*-----------------------------------------------------------------------------------*/
/* hextorgb() */
/* Convert Hex to RGB for color */
/*-----------------------------------------------------------------------------------*/
public function hextorgb( $color = '', $text = true ) {
$color = trim( $color );
if ( '' == $color || 'transparent' == $color ) {
return false;
}
if ( '#' == $color[0] ) {
$color = substr( $color, 1 );
}
if ( 6 == strlen( $color ) ) {
list( $r, $g, $b ) = array( $color[0].$color[1], $color[2].$color[3], $color[4].$color[5] );
} elseif ( 3 == strlen( $color ) ) {
list( $r, $g, $b ) = array( $color[0].$color[0], $color[1].$color[1], $color[2].$color[2] );
} else {
return false;
}
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
if ( $text ) {
return $r.','.$g.','.$b;
} else {
return array( $r, $g, $b );
}
}
/*-----------------------------------------------------------------------------------*/
/* generate_border_css() */
/* Generate Border CSS on frontend */
/*-----------------------------------------------------------------------------------*/
public function generate_border_css( $option ) {
$border_css = '';
$border_css .= 'border: ' . esc_attr( $option['width'] ) . ' ' . esc_attr( $option['style'] ) . ' ' . esc_attr( $option['color'] ) .' !important;';
if ( isset( $option['corner'] ) && esc_attr( $option['corner'] ) == 'rounded' ) {
if ( ! isset( $option['rounded_value'] ) ) $option['rounded_value'] = 0;
if ( ! isset( $option['top_left_corner'] ) ) $option['top_left_corner'] = $option['rounded_value'];
if ( ! isset( $option['top_right_corner'] ) ) $option['top_right_corner'] = $option['rounded_value'];
if ( ! isset( $option['bottom_left_corner'] ) ) $option['bottom_left_corner'] = $option['rounded_value'];
if ( ! isset( $option['bottom_right_corner'] ) ) $option['bottom_right_corner'] = $option['rounded_value'];
$border_css .= 'border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
$border_css .= '-moz-border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
$border_css .= '-webkit-border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
} else {
$border_css .= 'border-radius: 0px !important;';
$border_css .= '-moz-border-radius: 0px !important;';
$border_css .= '-webkit-border-radius: 0px !important;';
}
return $border_css;
}
/*-----------------------------------------------------------------------------------*/
/* generate_border_style_css() */
/* Generate Border Style CSS on frontend */
/*-----------------------------------------------------------------------------------*/
public function generate_border_style_css( $option ) {
$border_style_css = '';
$border_style_css .= 'border: ' . esc_attr( $option['width'] ) . ' ' . esc_attr( $option['style'] ) . ' ' . esc_attr( $option['color'] ) .' !important;';
return $border_style_css;
}
/*-----------------------------------------------------------------------------------*/
/* generate_border_corner_css() */
/* Generate Border Corner CSS on frontend */
/*-----------------------------------------------------------------------------------*/
public function generate_border_corner_css( $option ) {
$border_corner_css = '';
if ( isset( $option['corner'] ) && esc_attr( $option['corner'] ) == 'rounded' ) {
if ( ! isset( $option['rounded_value'] ) ) $option['rounded_value'] = 0;
if ( ! isset( $option['top_left_corner'] ) ) $option['top_left_corner'] = $option['rounded_value'];
if ( ! isset( $option['top_right_corner'] ) ) $option['top_right_corner'] = $option['rounded_value'];
if ( ! isset( $option['bottom_left_corner'] ) ) $option['bottom_left_corner'] = $option['rounded_value'];
if ( ! isset( $option['bottom_right_corner'] ) ) $option['bottom_right_corner'] = $option['rounded_value'];
$border_corner_css .= 'border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
$border_corner_css .= '-moz-border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
$border_corner_css .= '-webkit-border-radius: ' . $option['top_left_corner'] . 'px ' . $option['top_right_corner'] . 'px ' . $option['bottom_right_corner'] . 'px ' . $option['bottom_left_corner'] . 'px !important;';
} else {
$border_corner_css .= 'border-radius: 0px !important;';
$border_corner_css .= '-moz-border-radius: 0px !important;';
$border_corner_css .= '-webkit-border-radius: 0px !important;';
}
return $border_corner_css;
}
/*-----------------------------------------------------------------------------------*/
/* generate_shadow_css() */
/* Generate Shadow CSS on frontend */
/*-----------------------------------------------------------------------------------*/
public function generate_shadow_css( $option ) {
$shadow_css = '';
if ( ! isset( $option['inset'] ) ) $option['inset'] = '';
if ( isset( $option['enable'] ) && $option['enable'] == 1 ) {
$shadow_css .= 'box-shadow: ' . $option['h_shadow'] . ' ' . $option['v_shadow'] . ' ' . $option['blur'] . ' ' . $option['spread'] . ' ' . $option['color'] . ' ' . $option['inset'] . ' !important;';
$shadow_css .= '-moz-box-shadow: ' . $option['h_shadow'] . ' ' . $option['v_shadow'] . ' ' . $option['blur'] . ' ' . $option['spread'] . ' ' . $option['color'] . ' ' . $option['inset'] . ' !important;';
$shadow_css .= '-webkit-box-shadow: ' . $option['h_shadow'] . ' ' . $option['v_shadow'] . ' ' . $option['blur'] . ' ' . $option['spread'] . ' ' . $option['color'] . ' ' . $option['inset'] . ' !important;';
} else {
$shadow_css .= 'box-shadow: none !important ;';
$shadow_css .= '-moz-box-shadow: none !important ;';
$shadow_css .= '-webkit-box-shadow: none !important ;';
}
return $shadow_css;
}
/*-----------------------------------------------------------------------------------*/
/* generate_background_css() */
/* Generate Background Color CSS on frontend */
/*-----------------------------------------------------------------------------------*/
public function generate_background_color_css( $option, $transparency = 100 ) {
$return_css = '';
if ( isset( $option['enable'] ) && $option['enable'] == 1 ) {
$color = $option['color'];
if ( 100 != $transparency ) {
$color = $this->hextorgb( $color );
$transparency = (int) $transparency / 100;
if ( $color !== false ) {
$return_css .= 'background-color: rgba( ' . $color . ', ' . $transparency . ' ) !important;';
} else {
$return_css .= 'background-color: transparent !important ;';
}
} else {
$return_css .= 'background-color: ' . $color . ' !important ;';
}
} else {
$return_css .= 'background-color: transparent !important ;';
}
return $return_css;
}
}
global $a3_portfolio_admin_interface;
$a3_portfolio_admin_interface = new A3_Portfolio_Admin_Interface();
?>