/** * Get preview data form post in admin area * * @since 1.5.0 */ public function post_slider_preview() { header("Content-Type: application/json"); // verify nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], "msp_panel")) { echo json_encode(array('success' => false, 'message' => __("Authorization failed!", MSWP_TEXT_DOMAIN))); exit; } $PS = msp_get_post_slider_class(); $posts_result = $PS->parse_and_get_posts_result(); $template_tags = $PS->get_first_post_template_tags_value(); if (empty($posts_result)) { $template_tags = null; } echo json_encode(array('success' => true, 'type' => 'preview', 'message' => '', 'preview_results' => $posts_result, 'template_tags' => $template_tags)); exit; // IMPORTANT }
/** * Generates shortcode code base of posts for post slider * * @return string Post slider shortcode */ public function get_post_slider_ms_slides_shortcode() { if (!isset($this->parsed_slider_data['slides'])) { return ''; } $slides = $this->parsed_slider_data['slides']; $query = array(); $query['image_from'] = $this->parsed_slider_data['setting']['ps_image_from']; $query['excerpt_length'] = $this->parsed_slider_data['setting']['ps_excerpt_len']; $exclude_posts_no_img = $this->parsed_slider_data['setting']['ps_exclude_no_img']; if (!empty($this->parsed_slider_data['setting']['ps_post_type'])) { $query['post_type'] = $this->parsed_slider_data['setting']['ps_post_type']; } $query['orderby'] = $this->parsed_slider_data['setting']['ps_orderby']; $query['order'] = $this->parsed_slider_data['setting']['ps_order']; $query['posts_per_page'] = $this->parsed_slider_data['setting']['ps_post_count']; if (!empty($this->parsed_slider_data['setting']['ps_posts_not_in'])) { $posts_not_in = explode(',', $this->parsed_slider_data['setting']['ps_posts_not_in']); $query['post__not_in'] = array_filter($posts_not_in); } if (!empty($this->parsed_slider_data['setting']['ps_posts_in'])) { $posts_in = explode(',', $this->parsed_slider_data['setting']['ps_posts_in']); $query['post__in'] = array_filter($posts_in); } $query['offset'] = $this->parsed_slider_data['setting']['ps_offset']; $taxs_data = array(); if (!empty($this->parsed_slider_data['setting']['ps_tax_term_ids'])) { $taxs_data = explode(',', $this->parsed_slider_data['setting']['ps_tax_term_ids']); } $tax_query = array(); $PS = msp_get_post_slider_class(); $query['tax_query'] = $PS->get_tax_query($taxs_data); $query['image_size'] = 'full'; $query = apply_filters('msp_post_slider_query_args', $query, $this->parsed_slider_data); $this->post_slider_args = $query; $slides_shortcode = ''; $th_wp_query = $PS->get_query_results($query); if ($th_wp_query->have_posts()) { while ($th_wp_query->have_posts()) { $th_wp_query->the_post(); $slide_content = ''; $attrs = ''; $this->post_id = $th_wp_query->post->ID; // get slide image if (empty($this->parsed_slider_data['setting']['ps_slide_bg'])) { $the_media = msp_get_auto_post_thumbnail_url($th_wp_query->post, $query['image_from'], $query['image_size']); } else { $the_media = $this->parsed_slider_data['setting']['ps_slide_bg']; } // skip this post if it does not have image and $exclude_posts_no_img is enabled if (empty($the_media) && 'true' == $exclude_posts_no_img) { continue; } $attrs .= sprintf('%s="%s" ', 'src', esc_attr($the_media)); // generate slide_info shortcode if slideinfo control is added if (isset($this->parsed_slider_data['setting']['slideinfo']) && 'true' == $this->parsed_slider_data['setting']['slideinfo']) { if (!empty($slides['0']['info'])) { $slide_info = preg_replace_callback('/{{[\\w-]+}}/', array($this, 'do_template_tag'), $slides['0']['info']); } else { $slide_info = " "; } $slide_content .= $this->get_ms_slide_info_shortcode($slide_info); } if ($this->parsed_slider_data['setting']['ps_link_slide']) { $attrs .= sprintf('%s="%s" ', 'link', get_the_permalink($th_wp_query->post->ID)); } $attrs .= sprintf('%s="%s" ', 'title', $this->escape_square_brackets(get_the_title($th_wp_query->post->ID))); $attrs .= sprintf('%s="%s" ', 'alt', $this->escape_square_brackets(get_the_title($th_wp_query->post->ID))); $attrs .= sprintf('%s="%s" ', 'target', $this->parsed_slider_data['setting']['ps_link_target']); $attrs .= sprintf('%s="%s" ', 'delay', $slides['0']['delay']); $attrs .= sprintf('%s="%s" ', 'css_class', $slides['0']['css_class'] . ' ms-slide-post-' . $th_wp_query->post->ID); // bg color and align for slides $attrs .= sprintf('%s="%s" ', 'bgalign', $slides['0']['bgalign']); $attrs .= sprintf('%s="%s" ', 'bgcolor', $slides['0']['bgcolor']); if ('true' == $this->parsed_slider_data['setting']['thumbs']) { if ('thumbs' == $this->parsed_slider_data['setting']['thumbs_type']) { if (!empty($the_media)) { // set custom thumb size if slider template is gallery if ('image-gallery' == $this->parsed_slider_data['setting']['template']) { $thumb = msp_get_the_resized_image_src($the_media, 175, 140, true); } else { $thumb = msp_get_the_resized_image_src($the_media, $this->parsed_slider_data['setting']['thumbs_width'], $this->parsed_slider_data['setting']['thumbs_height'], true); } $thumb = msp_get_the_relative_media_url($thumb); $attrs .= sprintf('%s="%s" ', 'thumb', $thumb); } else { $tab = '<div class="ms-thumb-alt">' . get_the_title($th_wp_query->post->ID) . '</div>'; $attrs .= sprintf('%s="%s" ', 'tab', $tab); } } elseif ('tabs' == $this->parsed_slider_data['setting']['thumbs_type']) { // if "insert thumb" option was enabled generate and add the thumbnail if ('true' == $this->parsed_slider_data['setting']['thumbs_in_tab']) { $thumb_height = $this->parsed_slider_data['setting']['thumbs_height']; $tab_thumb = msp_get_auto_post_thumbnail_url($th_wp_query->post, 'featured', array($thumb_height, $thumb_height), true); $attrs .= sprintf('%s="%s" ', 'tab_thumb', $tab_thumb); } if (!empty($slides['0']['info'])) { $tab_context = preg_replace_callback('/{{[\\w-]+}}/', array($this, 'do_template_tag'), $slides['0']['info']); } else { $tab_context = get_the_title($th_wp_query->post->ID); } $attrs .= sprintf('%s="%s" ', 'tab', $this->escape_special($tab_context)); } } // if( 'true' != $slide['is_overlay_layers'] ){ // $shortcodes .= $this->get_ms_slide_shortcode( $slide ); // } else { // $shortcodes .= $this->get_ms_overlay_slide_shortcode( $slide ); // } $slide_content .= $this->get_ms_layers_shortcode($slides['0']['layers']); $slides_shortcode .= sprintf('[%1$s %2$s]%4$s%3$s[/%1$s]%4$s', 'ms_slide', $attrs, $slide_content, "\n"); } } // Restore original Post Data wp_reset_postdata(); return $slides_shortcode; }
/** * Print required variable for master slider panel */ public function add_panel_variables() { wp_localize_script('jquery', '__MSP_SKINS', msp_get_skins()); global $mspdb; $slider_alias = ''; // get and print slider id if (isset($_REQUEST['slider_id'])) { $slider_id = $_REQUEST['slider_id']; } else { $slider_id = 0; if (isset($_REQUEST['action']) && 'add' == $_REQUEST['action']) { $slider_id = $mspdb->add_slider(array('status' => 'draft')); wp_localize_script('jquery', '__MSP_SLIDER_ID', (string) $slider_id); $slider_alias = $mspdb->generate_slider_alias($slider_id); wp_localize_script('jquery', '__MSP_SLIDER_ALIAS', $slider_alias); } } // Get and print panel data if ($slider_id) { $slider_data = $mspdb->get_slider($slider_id); $slider_type = isset($slider_data['type']) ? $slider_data['type'] : 'custom'; $slider_type = empty($slider_type) ? 'custom' : $slider_type; $msp_data = isset($slider_data['params']) ? $slider_data['params'] : NULL; $msp_data = empty($slider_data['params']) ? NULL : $slider_data['params']; $msp_preset_style = msp_get_option('preset_style', NULL); $msp_preset_effect = msp_get_option('preset_effect', NULL); $msp_buttons_style = msp_get_option('buttons_style', NULL); $msp_preset_style = empty($msp_preset_style) ? NULL : $msp_preset_style; $msp_preset_effect = empty($msp_preset_effect) ? NULL : $msp_preset_effect; $msp_buttons_style = empty($msp_buttons_style) ? NULL : $msp_buttons_style; if (empty($slider_alias)) { $slider_alias = isset($slider_data['alias']) && !empty($slider_data['alias']) ? $slider_data['alias'] : $mspdb->generate_slider_alias($slider_id); wp_localize_script('jquery', '__MSP_SLIDER_ALIAS', $slider_alias); } wp_localize_script('jquery', '__MSP_DATA', $msp_data); wp_localize_script('jquery', '__MSP_PRESET_STYLE', $msp_preset_style); wp_localize_script('jquery', '__MSP_PRESET_EFFECT', $msp_preset_effect); wp_localize_script('jquery', '__MSP_TYPE', $slider_type); wp_localize_script('jquery', '__MSP_PRESET_BUTTON', $msp_buttons_style); } // print essential variables (types, taxs, terms, template tags) for post slider in admin panel // since version 1.7 if (isset($slider_type) && 'post' == $slider_type) { $defined_tags = msp_get_general_post_template_tags(); $tags = array(); foreach ($defined_tags as $defined_tag) { $tag_type = '_general' == $defined_tag['type'] ? 'general' : $defined_tag['type']; $tags[$tag_type][] = array('name' => $defined_tag['name'], 'label' => $defined_tag['label']); } // -- get post types, taxes and terms -- $PS = msp_get_post_slider_class(); $terms = $PS->get_tax_term_dictionary(); // ------------------------------------- // $js_data = array('types_taxs_terms' => $terms, 'content_tags' => $tags); wp_localize_script('jquery', '__MSP_POST', apply_filters('masterslider_post_slider_init_data', $js_data)); } // print essential variables (types, taxs, terms, template tags) for woocommerce sliders in admin panel // since version 1.8 if (isset($slider_type) && 'wc-product' == $slider_type) { // if woocommerce is installed and actived if (msp_is_plugin_active('woocommerce/woocommerce.php')) { // -- template tags -------------------- $defined_tags = msp_get_general_post_template_tags(); $woocomm_tags = msp_get_woocommerce_template_tags(); $defined_tags = array_merge($defined_tags, $woocomm_tags); $tags = array(); foreach ($defined_tags as $defined_tag) { $tag_type = '_general' == $defined_tag['type'] ? 'general' : $defined_tag['type']; $tags[$tag_type][] = array('name' => $defined_tag['name'], 'label' => $defined_tag['label']); } // -- get post types, taxes and terms -- $WCS = msp_get_wc_slider_class(); $terms = $WCS->get_tax_term_dictionary(); // ------------------------------------- $js_data = array('types_taxs_terms' => $terms, 'content_tags' => $tags); // if woocommerce is not activated } else { $js_data = null; $wc_installation_url = admin_url('plugin-install.php?tab=plugin-information&plugin=woocommerce&TB_iframe=true&width=600&height=550'); wp_localize_script('jquery', '__WC_INSTALL_URL', $wc_installation_url); } wp_localize_script('jquery', '__MSP_POST', apply_filters('masterslider_wc_product_slider_init_data', $js_data)); } // define panel directory path wp_localize_script('jquery', '__MSP_PATH', MSWP_AVERTA_ADMIN_URL . '/views/slider-panel/'); $slider_panel_default_setting = array('width' => 1000, 'height' => 500, 'autoCrop' => false, 'autoplay' => false, 'layout' => 'boxed', 'autoHeight' => false, 'transition' => 'basic', 'speed' => 20, 'className' => '', 'start' => 1, 'space' => 0, 'grabCursor' => true, 'swipe' => true, 'wheel' => false, 'mouse' => true, 'loop' => false, 'shuffle' => false, 'preload' => '-1', 'overPause' => true, 'endPause' => false, 'hideLayers' => false, 'dir' => 'h', 'parallaxMode' => 'swipe', 'centerControls' => true, 'instantShowLayers' => false, 'skin' => 'ms-skin-default', 'duration' => 3, 'slideFillMode' => 'fill', 'sliderVideoFillMode' => 'fill', 'slideVideoLoop' => true, 'slideVideoMute' => true, 'slideVideoAutopause' => false, 'layerContent' => 'Lorem Ipsum'); wp_localize_script('jquery', '__MSP_DEF_OPTIONS', apply_filters('masterslider_panel_default_setting', $slider_panel_default_setting)); do_action('masterslider_admin_add_panel_variables', $slider_type); }
public function get_post_slider_ms_slides_shortcode() { if (!isset($this->parsed_slider_data['slides'])) { return ''; } $slides = $this->parsed_slider_data['slides']; $query = array(); $query['image_from'] = $this->parsed_slider_data['setting']['ps_image_from']; $query['excerpt_length'] = $this->parsed_slider_data['setting']['ps_excerpt_len']; if (!empty($this->parsed_slider_data['setting']['ps_post_type'])) { $query['post_type'] = $this->parsed_slider_data['setting']['ps_post_type']; } $query['orderby'] = $this->parsed_slider_data['setting']['ps_orderby']; $query['order'] = $this->parsed_slider_data['setting']['ps_order']; $query['posts_per_page'] = $this->parsed_slider_data['setting']['ps_post_count']; if (!empty($this->parsed_slider_data['setting']['ps_posts_not_in'])) { $posts_not_in = explode(',', $this->parsed_slider_data['setting']['ps_posts_not_in']); $query['post__not_in'] = array_filter($posts_not_in); } $query['offset'] = $this->parsed_slider_data['setting']['ps_offset']; $taxs_data = array(); if (!empty($this->parsed_slider_data['setting']['ps_tax_term_ids'])) { $taxs_data = explode(',', $this->parsed_slider_data['setting']['ps_tax_term_ids']); } $tax_query = array(); $PS = msp_get_post_slider_class(); $query['tax_query'] = $PS->get_tax_query($taxs_data); $this->post_slider_args = $query; $slides_shortcode = ''; $th_wp_query = $PS->get_query_results($query); if ($th_wp_query->have_posts()) { while ($th_wp_query->have_posts()) { $th_wp_query->the_post(); $slide_content = ''; $attrs = ''; $this->post_id = $th_wp_query->post->ID; // generate slide_info shortcode if slideinfo control is added if (isset($this->parsed_slider_data['setting']['slideinfo']) && 'true' == $this->parsed_slider_data['setting']['slideinfo']) { if (!empty($slides['0']['info'])) { $slide_info = preg_replace_callback('/{{[\\w-]+}}/', array($this, 'do_template_tag'), $slides['0']['info']); } else { $slide_info = " "; } $slide_content .= $this->get_ms_slide_info_shortcode($slide_info); } if (empty($this->parsed_slider_data['setting']['ps_slide_bg'])) { $the_media = msp_get_auto_post_thumbnail_src($th_wp_query->post, $query['image_from']); } else { $the_media = $this->parsed_slider_data['setting']['ps_slide_bg']; } $attrs .= sprintf('%s="%s" ', 'src', esc_attr($the_media)); if ($this->parsed_slider_data['setting']['ps_link_slide']) { $attrs .= sprintf('%s="%s" ', 'link', get_the_permalink($th_wp_query->post->ID)); } $attrs .= sprintf('%s="%s" ', 'title', get_the_title($th_wp_query->post->ID)); $attrs .= sprintf('%s="%s" ', 'alt', get_the_title($th_wp_query->post->ID)); $attrs .= sprintf('%s="%s" ', 'target', $this->parsed_slider_data['setting']['ps_link_target']); $attrs .= sprintf('%s="%s" ', 'delay', $slides['0']['delay']); if ('true' == $this->parsed_slider_data['setting']['thumbs']) { if ('thumbs' == $this->parsed_slider_data['setting']['thumbs_type']) { if (!empty($the_media)) { // set custom thumb size if slider template is gallery if ('image-gallery' == $this->parsed_slider_data['setting']['template']) { $thumb = msp_get_the_resized_image_src($the_media, 175, 140, true); } else { $thumb = msp_get_the_resized_image_src($the_media, $this->parsed_slider_data['setting']['thumbs_width'], $this->parsed_slider_data['setting']['thumbs_height'], true); } $thumb = msp_get_the_relative_media_url($thumb); $attrs .= sprintf('%s="%s" ', 'thumb', $thumb); } else { $tab = '<div class="ms-thumb-alt">' . get_the_title($th_wp_query->post->ID) . '</div>'; $attrs .= sprintf('%s="%s" ', 'tab', $tab); } } elseif ('tabs' == $this->parsed_slider_data['setting']['thumbs_type']) { $tab = get_the_title($th_wp_query->post->ID); $attrs .= sprintf('%s="%s" ', 'tab', $tab); } } $slide_content .= $this->get_ms_layers_shortcode($slides['0']['layers']); $slides_shortcode .= sprintf('[%1$s %2$s]%4$s%3$s[/%1$s]%4$s', 'ms_slide', $attrs, $slide_content, "\n"); } } // Restore original Post Data wp_reset_postdata(); return $slides_shortcode; }