base = DFlip::get_instance();
$this->fields = $this->base->defaults;
// Load metabox assets.
add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_styles_scripts' ) );
// Load the metabox hooks and filters.
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 100 );
// Add action to save metabox config options.
add_action( 'save_post', array( $this, 'save_meta_boxes' ), 10, 2 );
}
/**
* Loads styles and scripts for our metaboxes.
*
* @since 1.0.0
*
* @return null Bail out if not on the proper screen.
*/
public function meta_box_styles_scripts()
{
global $id, $post;
if ( isset( get_current_screen()->base ) && 'post' !== get_current_screen()->base ) {
return;
}
if ( isset( get_current_screen()->post_type )
&& $this->base->plugin_slug !== get_current_screen()->post_type
) {
return;
}
// echo $this->base->file;
// Set the post_id for localization.
$post_id = isset( $post->ID ) ? $post->ID : (int) $id;
// Load necessary metabox styles.
wp_register_style( $this->base->plugin_slug . '-metabox-style', plugins_url( 'assets/css/metaboxes.css', $this->base->file ), array(), $this->base->version );
wp_enqueue_style( $this->base->plugin_slug . '-metabox-style' );
// Load necessary metabox scripts.
wp_register_script( $this->base->plugin_slug . '-metabox-script', plugins_url( 'assets/js/metaboxes.js', $this->base->file ),
array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-resizable' ), $this->base->version );
wp_enqueue_script( $this->base->plugin_slug . '-metabox-script' );
wp_enqueue_media( array( 'post' => $post_id ) );
}
/**
* Adds metaboxes for handling settings
*
* @since 1.0.0
*/
public function add_meta_boxes()
{
add_meta_box( 'dflip_post_meta_box_limit', __( 'dFlip-Lite Demo Limits', 'DFLIP' ), array( $this, 'create_meta_boxes_limit' ), 'dflip', 'normal', 'high' );
add_meta_box( 'dflip_post_meta_box', __( 'dFlip Settings', 'DFLIP' ), array( $this, 'create_meta_boxes' ), 'dflip', 'normal', 'high' );
add_meta_box( 'dflip_post_meta_box_shortcode', __( 'Shortcode', 'DFLIP' ), array( $this, 'create_meta_boxes_shortcode' ), 'dflip', 'side', 'high' );
add_meta_box( 'dflip_post_meta_box_video', __( 'Video Tutorial', 'DFLIP' ), array( $this, 'create_meta_boxes_video' ), 'dflip', 'side', 'low' );
}
/**
* Creates metaboxes for shortcode display
*
* @since 1.2.4
*
* @param object $post The current post object.
*/
public function create_meta_boxes_limit( $post )
{
?>
- Demo Flipbooks will be limited to 30 pages,
- Premium and Global settings are disabled,
- Lightboxes for Button and custom type are disabled,
- Hotspots and PDF links are disabled
Buy Full Version
ID;
$tabs = array(
'normal' => __( 'Normal', 'DFLIP' ),
'thumb' => __( 'Thumbnail', 'DFLIP' ),
'button' => __( 'Button', 'DFLIP' )
);
if ( $current_screen->post_type == 'dflip' ) {
if ( $current_screen->action == 'add' ) {
echo "Save Post to generate shortcode.";
} else {
?>
$title ) {
?>
">
[dflip id=""][/dflip]
post_type == 'dflip' ) {
?>
base->plugin_slug, $this->base->plugin_slug );
$tabs = array(
'source' => __( 'Source', 'DFLIP' ),
'layout' => __( 'Layout', 'DFLIP' ),
'outline' => __( 'Outline', 'DFLIP' )
);
if ( $error = get_transient( "my_save_post_errors_{$post->ID}" ) ) { ?>
ID}");
}
//create tabs and content
?>
create_normal_setting( 'source_type', $post );
$this->create_normal_setting( 'pdf_source', $post );
$this->create_normal_setting( 'pdf_thumb', $post );
?>
base->create_setting( $key, null, $this->get_config( $key, $post, $global_key ), $global_key, $this->global_config( $key ) );
}
private function create_normal_setting( $key, $post )
{
$this->base->create_setting( $key, null, $this->get_config( $key, $post ) );
}
/**
* Creates the UI for layout tab
*
* @since 1.0.0
*
* @param object $post The current post object.
*/
public function layout_tab( $post )
{
$this->create_global_setting( 'webgl', $post, 'global' );
$this->create_global_setting( 'hard', $post, 'global' );
$this->create_global_setting( 'bg_color', $post, '' );
$this->create_global_setting( 'bg_image', $post, '' );
$this->create_global_setting( 'duration', $post, '' );
$this->create_global_setting( 'height', $post, '' );
$this->create_global_setting( 'texture_size', $post, 'global' );
$this->create_global_setting( 'auto_sound', $post, 'global' );
$this->create_global_setting( 'enable_download', $post, 'global' );
$this->create_normal_setting( 'page_mode', $post );
$this->create_global_setting( 'single_page_mode', $post, 'global' );
$this->create_global_setting( 'controls_position', $post, 'global' );
$this->create_normal_setting( 'direction', $post );
$this->create_normal_setting( 'force_fit', $post );
$this->create_global_setting( 'autoplay', $post, 'global' );
$this->create_global_setting( 'autoplay_duration', $post, '' );
$this->create_global_setting( 'autoplay_start', $post, 'global' );
?>
create_normal_setting( 'auto_outline', $post );
$this->create_normal_setting( 'auto_thumbnail', $post );
$this->create_normal_setting( 'overwrite_outline', $post );
?>
%s', 'DFLIP' ),
' Outline Name : (destination as blank or link to url or page number)' ); ?>
ID, '_dflip_data', true );
$value = isset( $values[ $key ] ) ? $values[ $key ] : '';
$default = $_default === null ? isset( $this->fields[ $key ] ) ? is_array( $this->fields[ $key ] ) ? isset( $this->fields[ $key ]['std'] ) ? $this->fields[ $key ]['std'] : ''
: $this->fields[ $key ] : '' : $_default;
/* set standard value */
if ( $default !== null ) {
$value = $this->filter_std_value( $value, $default );
}
return $value;
}
/**
* Helper function to filter standard option values.
*
* @param mixed $value Saved string or array value
* @param mixed $std Standard string or array value
*
* @return mixed String or array
*
* @access public
* @since 1.0.0
*/
public function filter_std_value( $value = '', $std = '' )
{
$std = maybe_unserialize( $std );
if ( is_array( $value ) && is_array( $std ) ) {
foreach ( $value as $k => $v ) {
if ( '' === $value[ $k ] && isset( $std[ $k ] ) ) {
$value[ $k ] = $std[ $k ];
}
}
} else {
if ( '' === $value && $std !== null ) {
$value = $std;
}
}
return $value;
}
/**
* Saves values from dFlip metaboxes.
*
* @since 1.0.0
*
* @param int $post_id The current post ID.
* @param object $post The current post object.
*/
public function save_meta_boxes( $post_id, $post )
{
// Bail out if we fail a security check.
if ( !isset( $_POST['dflip'] )
|| !wp_verify_nonce( $_POST['dflip'], 'dflip' )
|| !isset( $_POST['_dflip'] )
) {
set_transient("my_save_post_errors_{$post_id}", "Security Check Failed", 10);
return;
}
// Bail out if running an autosave, ajax, cron or revision.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
set_transient("my_save_post_errors_{$post_id}", "Autosave", 10);
return;
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
set_transient("my_save_post_errors_{$post_id}", "Ajax", 10);
return;
}
/* if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
set_transient("my_save_post_errors_{$post_id}", "Cron", 10);
return;
}*/
if ( wp_is_post_revision( $post_id ) ) {
set_transient("my_save_post_errors_{$post_id}", "revision", 10);
return;
}
// Bail if this is not the correct post type.
if ( isset( $post->post_type )
&& $this->base->plugin_slug !== $post->post_type
) {
set_transient("my_save_post_errors_{$post_id}", "Incorrect Post Type", 10);
return;
}
// Bail out if user is not authorized
if ( !current_user_can( 'edit_post', $post_id ) ) {
set_transient("my_save_post_errors_{$post_id}", "UnAuthorized User", 10);
return;
}
// Sanitize all user inputs.
$settings = get_post_meta( $post_id, '_dflip_data', true );
if ( empty( $settings ) ) {
$settings = array();
}
$data = $_POST['_dflip'];
$settings = array_merge( $settings, $data );
/*SANITIZE DATA*/
//Check the urls
$settings['pdf_source'] = esc_url_raw( $settings['pdf_source'] );
$settings['pdf_thumb'] = esc_url_raw( $settings['pdf_thumb'] );
$settings['bg_image'] = esc_url_raw( $settings['bg_image'] );
//Check the text inputs
$settings['bg_color'] = sanitize_text_field( $settings['bg_color'] );
$settings['outline'] = isset( $settings['outline'] ) ? $this->array_val( $settings['outline'], 'items' ) : array();
if ( isset( $post->post_type ) && 'dflip' == $post->post_type ) {
if ( empty( $settings['title'] ) ) {
$settings['title'] = trim( strip_tags( $post->post_title ) );
}
if ( empty( $settings['slug'] ) ) {
$settings['slug'] = sanitize_text_field( $post->post_name );
}
}
// Get publish/draft status from Post
$settings['status'] = $post->post_status;
// Update the post meta.
update_post_meta( $post_id, '_dflip_data', $settings );
}
/**
* Removes index of array and returns only values array
*
* @since 1.0.0
*
* @param array Array to be sanitized
* @param string $scan key index that needs to be re-sanitized
*
* @return array sanitized array
*/
private function array_val( $arr = array(), $scan = '' )
{
if ( is_null( $arr ) ) {
return array();
}
$_arr = array_values( $arr );
if ( $_arr != null && $scan !== '' ) {
foreach ( $_arr as &$val ) {
if ( is_array( $val ) ) {
if ( isset( $val[ $scan ] ) ) {
$val[ $scan ] = $this->array_val( $val[ $scan ], $scan );
}
}
}
}
return $_arr;
}
/**
* Helper method for retrieving global check values.
*
* @since 1.0.0
*
* @param string $key The config key to retrieve.
* @param object $post The current post object.
*
* @return string Key value on success, empty string on failure.
*/
public function global_config( $key )
{
$global_value = $this->base->get_config( $key );
$value = isset( $this->fields[ $key ] ) ? is_array( $this->fields[ $key ] ) ? isset( $this->fields[ $key ]['choices'][ $global_value ] ) ? $this->fields[ $key ]['choices'][ $global_value ]
: $global_value : $global_value : $global_value;
return $value;
}
/**
* Returns the singleton instance of the class.
*
* @since 1.0.0
*
* @return object dFlip_PostType object.
*/
public static function get_instance()
{
if ( !isset( self::$instance )
&& !( self::$instance instanceof DFlip_Meta_Boxes )
) {
self::$instance = new DFlip_Meta_Boxes();
}
return self::$instance;
}
}
// Load the DFlip_Metaboxes class.
$dflip_meta_boxes = DFlip_Meta_Boxes::get_instance();