init(); } public function init () { add_action( 'media_buttons', array( $this, 'add_rslider_button'), 100 ); add_action( 'admin_footer', array( $this, 'rslider_generator_popup') ); add_shortcode( 'a3_responsive_slider', array( $this, 'parse_shortcode_a3_responsive_slider') ); // Make track a3_responsive_slider shortcode used in content when save post add_action( 'save_post', array( $this, 'track_shortcode_is_used' ), 11, 3 ); } public function track_shortcode_is_used( $post_ID, $post, $update ) { $is_post_edit_page = in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ); if ( ! $is_post_edit_page ) return; if ( empty( $post_ID ) || empty( $post ) || empty( $_POST ) ) return; if ( is_int( wp_is_post_revision( $post ) ) ) return; if ( ! current_user_can( 'edit_post', $post_ID ) ) return; $post_type = get_post_type( $post_ID ); $have_shortcode = false; $our_shortcode = 'a3_responsive_slider'; // Remove old data for this post ID delete_post_meta( $post_ID, '_a3_slider_is_used' ); delete_post_meta( $post_ID, '_a3_slider_is_used_' . $post_type ); // Check if a3_responsive_slider shortcode is in the content if ( has_shortcode( $post->post_content, $our_shortcode ) ) { preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ); if ( ! empty( $matches ) && is_array( $matches ) && count( $matches ) > 0 ) { foreach ( $matches as $shortcode ) { if ( $our_shortcode === $shortcode[2] ) { $attr = shortcode_parse_atts( $shortcode[3] ); $my_attr = shortcode_atts( array( 'id' => 0 ), $attr ); $slider_id = $my_attr['id']; if ( $slider_id > 0 ) { $have_shortcode = true; $a3_slider_is_used = get_post_meta( $post_ID, '_a3_slider_is_used', false ); if ( is_array( $a3_slider_is_used ) && in_array( $slider_id, $a3_slider_is_used ) ) continue; add_post_meta( $post_ID, '_a3_slider_is_used', $slider_id ); add_post_meta( $post_ID, '_a3_slider_is_used_' . $post_type , $slider_id ); } } } } } } public function add_rslider_button() { $is_post_edit_page = in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ); if ( ! $is_post_edit_page ) return; echo ''.__( 'Sliders', 'a3-responsive-slider' ).''; } public function rslider_generator_popup() { $is_post_edit_page = in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ); if ( ! $is_post_edit_page ) return; $list_sliders = get_posts( array( 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'a3_slider', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_a3_slider_id', 'value' => 1, 'compare' => '>=', 'type' => 'NUMERIC', ) ), )); ?> '', 'inline_post' => false, 'description' => '', 'align' => 'none', 'width' => 300, 'width_type' => 'px', 'tall_type' => 'fixed', 'height' => 250, 'margin_top' => 10, 'margin_bottom' => 10, 'margin_left' => 10, 'margin_right' => 10, 'desc_margin_top' => 10, 'desc_margin_bottom'=> 10, 'desc_margin_left' => 10, 'desc_margin_right' => 10, ), $attributes) ); $slider_id = $id; $slider_data = get_post( $slider_id ); if ( $slider_data == NULL ) return ''; $have_slider_id = get_post_meta( $slider_id, '_a3_slider_id' , true ); if ( $have_slider_id < 1 ) return ''; $slider_settings = get_post_meta( $slider_id, '_a3_slider_settings', true ); $slide_items = A3_Responsive_Slider_Data::get_all_images_from_slider_client( $id ); global $a3_rslider_template1_global_settings; $templateid = 'template1'; $slider_template = 'template-1'; global ${'a3_rslider_'.$templateid.'_dimensions_settings'}; $dimensions_settings = ${'a3_rslider_'.$templateid.'_dimensions_settings'}; $output = ''; $rslider_custom_style = ''; $rslider_inline_style = ''; $rslider_desc_container_style = ''; $description_html = ''; $rslider_shortcode_wrap = false; if ( $inline_post ) { if ( $align == 'center' ) $rslider_custom_style .= 'float:none;margin:auto;display:block;'; elseif ( $align == 'left-wrap' ) $rslider_custom_style .= 'float:left;'; elseif ( $align == 'right-wrap' ) $rslider_custom_style .= 'float:right;'; else $rslider_custom_style .= 'float:'. $align .';'; if( $align == 'left-wrap' || $align == 'right-wrap' ) $rslider_shortcode_wrap = true; if ( $width > 0 ) $rslider_custom_style .= 'width:' . $width . $width_type . ' !important;'; if ( $tall_type == 'fixed' ) $rslider_inline_style .= 'height:'.$height.'px !important;'; else $rslider_inline_style .= 'height:auto;'; // override dimension from current template if ( $width > 0 ) { if ( $width_type == 'px' ) { $dimensions_settings['is_slider_responsive'] = 0; $dimensions_settings['slider_width'] = $width; } else { $dimensions_settings['is_slider_responsive'] = 1; $dimensions_settings['slider_wide_responsive'] = $width; } } if ( $tall_type == 'fixed' ) { $dimensions_settings['is_slider_tall_dynamic'] = 0; $dimensions_settings['slider_height_fixed'] = $height; } else { $dimensions_settings['is_slider_tall_dynamic'] = 1; } if ( $margin_top >= 0 ) $rslider_inline_style .= 'margin-top:'.$margin_top.'px;'; if ( $margin_bottom >= 0 ) $rslider_inline_style .= 'margin-bottom:'.$margin_bottom.'px;'; if ( $margin_left >= 0 ) $rslider_inline_style .= 'margin-left:'.$margin_left.'px;'; if ( $margin_right >= 0 ) $rslider_inline_style .= 'margin-right:'.$margin_right.'px;'; if ( $desc_margin_top >= 0 ) $rslider_desc_container_style .= 'margin-top:'.$desc_margin_top.'px;'; if ( $desc_margin_bottom >= 0 ) $rslider_desc_container_style .= 'margin-bottom:'.$desc_margin_bottom.'px;'; if ( $desc_margin_left >= 0 ) $rslider_desc_container_style .= 'margin-left:'.$desc_margin_left.'px;'; if ( $desc_margin_right >= 0 ) $rslider_desc_container_style .= 'margin-right:'.$desc_margin_right.'px;'; if ( trim( $description ) != '' ) $description_html = '
'.stripslashes( $description ).'
'; } require_once A3_RESPONSIVE_SLIDER_DIR . '/includes/mobile_detect.php'; $device_detect = new A3_RSlider_Mobile_Detect(); if ( $device_detect->isMobile() ) { $rslider_custom_style = ''; $rslider_inline_style = ''; $rslider_desc_container_style = ''; $rslider_shortcode_wrap = false; $dimensions_settings['is_slider_responsive'] = 1; $dimensions_settings['slider_wide_responsive'] = 100; $rslider_custom_style .= 'width:100% !important;'; if ( $inline_post ) { if ( $tall_type == 'fixed' ) $rslider_inline_style .= 'height:'.$height.'px !important;'; else $rslider_inline_style .= 'height:auto;'; if ( $tall_type == 'fixed' ) { $dimensions_settings['is_slider_tall_dynamic'] = 0; $dimensions_settings['slider_height_fixed'] = $height; } else { $dimensions_settings['is_slider_tall_dynamic'] = 1; } if ( $margin_top >= 0 ) $rslider_inline_style .= 'margin-top:'.$margin_top.'px;'; if ( $margin_bottom >= 0 ) $rslider_inline_style .= 'margin-bottom:'.$margin_bottom.'px;'; if ( $desc_margin_top >= 0 ) $rslider_desc_container_style .= 'margin-top:'.$desc_margin_top.'px;'; if ( $desc_margin_bottom >= 0 ) $rslider_desc_container_style .= 'margin-bottom:'.$desc_margin_bottom.'px;'; if ( trim( $description ) != '' ) $description_html = '
'.stripslashes( $description ).'
'; } } if ( ! $rslider_shortcode_wrap ) $output .= '
'; $output .= A3_Responsive_Slider_Display::dispay_slider( $slide_items, $slider_template, $dimensions_settings, $slider_settings, $rslider_custom_style, $rslider_inline_style, $description_html ); if ( ! $rslider_shortcode_wrap ) $output .= '
'; return $output; } public function get_all_posts_use_shortcode_slider( $slider_id, $post_type = '' ) { global $wpdb; if ( trim( $post_type ) != '' ) $meta_key_search = '_a3_slider_is_used_'.$post_type; else $meta_key_search = '_a3_slider_is_used'; $all_posts = $wpdb->get_results("SELECT * FROM ".$wpdb->postmeta." WHERE meta_key='".$meta_key_search."' AND meta_value='".$slider_id."' "); if ( $all_posts ) return $all_posts; else return false; } public function get_post_count_use_shortcode_slide( $slider_id, $post_type = '' ) { global $wpdb; if ( trim( $post_type ) != '' ) $meta_key_search = '_a3_slider_is_used_'.$post_type; else $meta_key_search = '_a3_slider_is_used'; $post_count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->postmeta." WHERE meta_key='".$meta_key_search."' AND meta_value='".$slider_id."' "); return $post_count; } public function show_all_posts_use_shortcode_slider( $slider_id ) { $post_types = get_post_types( array( 'public' => true, '_builtin' => true ) , 'objects' ); $custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ) , 'objects' ); $all_post_types = array_merge( $post_types, $custom_post_types ); if ( is_array( $all_post_types ) && count( $all_post_types ) > 0 ) { foreach ( $all_post_types as $post_type => $post_type_data ) { // Don't show for some post type if ( in_array( $post_type, array( 'attachment', 'revision', 'nav_menu_item', 'a3_slider' ) ) ) continue; $all_posts = $this->get_all_posts_use_shortcode_slider( $slider_id, $post_type ); if ( $all_posts && is_array( $all_posts ) && count( $all_posts ) > 0 ) { ?>

labels->name; ?>

post_id ); // Debug /*preg_match_all( '/' . get_shortcode_regex() . '/s', $my_post->post_content, $matches, PREG_SET_ORDER ); echo '
';
								var_dump($matches);
								echo '
';*/ if ( $my_post ) { ?>
[] post_title; ?>