*/ class Adamrob_Parallax_Scroll_Shortcode { /** * The ID of this plugin. * * @since 3.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 3.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Holds the key for the shortcode * * @since 3.0.0 * @var string $shortcode_key */ private $shortcode_key; /** * The post type key * * @since 3.0.0 * @access private * @var string $post_type_key The post type key. */ private $post_type_key; /** * Shortcode CSS key * Holds the CSS that is common against all parallax methods * * @since 3.0.0 * @access private * @var string $shortcode_css_key */ private $shortcode_css_key; /** * Initialize the class and set its properties. * * @since 3.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. * @param string $shortcode_key The shortcode key for the plugin. * @param string $post_type_key The post type key for the plugin. */ public function __construct( $plugin_name, $version, $shortcode_key, $post_type_key ) { $this->plugin_name = $plugin_name; $this->version = $version; $this->shortcode_key = $shortcode_key; $this->post_type_key = $post_type_key; $this->shortcode_css_key = $this->plugin_name . '-sc-css'; } /** * Register the stylesheets for the shortcode. * * @since 3.0.0 */ public function register_styles() { wp_register_style( $this->shortcode_css_key, plugin_dir_url( __FILE__ ) . 'css/adamrob-parallax-scroll-shortcode.css', array(), $this->version, 'all' ); /** * @deprecated 3.5.0 To be replaced with newer and better version */ wp_register_style( 'parallax-CSS', plugin_dir_url( __FILE__ ) . 'css/adamrob-parallax-scroll-parallax-legacy.css', array(), $this->version, 'all' ); } /** * Register the scripts for the shortcode. * * @since 3.0.0 */ public function register_scripts() { wp_register_script( 'parallax-script-fullwidth', plugin_dir_url( __FILE__ ) . 'js/adamrob-parallax-scroll-fullwidth.js', array( 'jquery' ), $this->version, false ); /** * @deprecated 3.6.0 To be replaced with newer and better version */ wp_register_script( 'parallax-script-scroll', plugin_dir_url( __FILE__ ) . 'js/adamrob-parallax-scroll-scroll.js', array( 'jquery' ), $this->version, false ); /** * @deprecated 3.6.0 To be replaced with newer and better version */ wp_register_script( 'parallax-script', plugin_dir_url( __FILE__ ) . 'js/parallax/parallax.min.js', array( 'jquery' ), $this->version, false ); } /** * Returns the required markup for the shortcode * * @since 3.0.0 * @since 3.0.1 Fix. Wrong parameter used for mobile image size */ public function show_shortcode($atts){ /** @var integer Error code store */ $errorcode = 0; /** Extract the parameters passed in */ extract( shortcode_atts( array( 'id' => '0', ), $atts ) ); /** Sanatise the passed in shortcode parameters */ $postid = intval($id); if ($postid==0 || !is_int($postid)){ $errorcode=1; } /** enque the style sheet */ wp_enqueue_style($this->shortcode_css_key); /** Setup a WP query to retrieve the posts */ if ( $errorcode === 0){ /** Buffer the output */ ob_start(); /** Set up the arguments for query */ $args = array( 'page_id' => $postid, 'post_type' => array( $this->post_type_key ) ); //Look up the header $post = new WP_Query( $args ); /** Check a post exists and then loop through all */ if ( $post->have_posts() ) { while ( $post->have_posts() ) { /** set post object */ $post->the_post(); /** Make sure there is a thumbnail image */ if ( !has_post_thumbnail() ) { $errorcode = 2; break; } /** Retrieve the parameters */ $parameters = $this->get_meta_parameters($post); /** Check if its enabled */ if ($parameters['disableparallax'] && wp_is_mobile()){ break; } //*Create IDs for parralax and container divs $parallaxFWStyleClass='';//_'.$postid; $containerFWStyleClass='';//_'.$postid; /** enque the style sheet */ wp_enqueue_style('parallax-CSS'); //Check if full width is enabled if ($parameters['fullwidth']){ //include full width java script wp_enqueue_script( 'parallax-script-fullwidth' ); //Rename IDs $parallaxFWStyleClass='adamrob_parallax_fullwidth '; $containerFWStyleClass='adamrob_parallax_container_fullwidth '; //Send parameters to script wp_localize_script('parallax-script-fullwidth', 'parallax_script_options', array( 'parallaxdivid' => $parallaxFWStyleClass, 'parallaxcontainerid' => $containerFWStyleClass )); } //Check if Scroll Is Enabled $parallaxScrollingClass=''; if ($parameters['scrollspeed']>0 && $parameters['scrollspeed'] < 9 && $parameters['usejs']==false){ //include java script wp_enqueue_script( 'parallax-script-scroll' ); $parallaxScrollingClass='adamrob_parallax_scrolling '; //Send parameters to script wp_localize_script('parallax-script-scroll', 'parallax_script_scroll_options', array( 'parallaxcontainerid' => $parallaxScrollingClass )); } //Check if we should use parallax.js to achieve effect if ($parameters['usejs']==true){ //Attach script wp_enqueue_script( 'parallax-script' ); } //Build the style tag for the parallax container $parallaxStyle=''; if ($parameters['height']!==100){ //Use user defined height $parallaxStyle='height:'.$parameters['height'].'px;'; }elseif($parameters['height']!==100 && $parameters['content'] ==""){ //Define the minimum height if no post content. //If there is post content, use min height from css $parallaxStyle='height:100px;'; } //Enable parallax image? $ParallaxImgStyle=''; if (!$parameters['disableimg'] || wp_is_mobile()===FALSE){ //Only show parallax if not on mobile. //or on a mobile and user wants it $ParallaxImgStyle='background-image: url('.$parameters['thumb_url'].');'; } //build style tag for background size $ParallaxSizeStyle='background-size: cover;'; if (wp_is_mobile()==FALSE && $parameters['imgsize']>0){ //if user not on mobile and wants to change the size $ParallaxSizeStyle='background-size: '.$parameters['imgsize'].'px;'; }elseif(wp_is_mobile()&&isset($parameters['mobpsize'])&&$parameters['mobpsize']==0){ //User is on mobile and wants to auto size //$ParallaxSizeStyle='background-size: 100% 100%;'; $ParallaxSizeStyle='background-size: cover; background-attachment: scroll;'; }elseif(wp_is_mobile()&&isset($parameters['mobpsize'])&&$parameters['mobpsize']>0){ //User is on mobile and wants to use a different size $ParallaxSizeStyle='background-size: '.$parameters['mobpsize'].'px;background-repeat: no-repeat; background-attachment: scroll;'; } /** build the markup */ if ( ! $parameters['usejs'] ){ $result = include( 'partials/adamrob-parallax-scroll-public-parallax-css-legacy.php' ); //if ( $result ) $errorcode = 3; } if ( $parameters['usejs'] ){ $result = include( 'partials/adamrob-parallax-scroll-public-parallax-js-legacy.php' ); //if ( $result ) $errorcode = 4; } } } } /** Reset the query Data */ wp_reset_postdata(); /** get the buffered output */ $markup = ob_get_clean(); /** Shortcode Output */ if ( $errorcode !== 0){ return $this->display_error($errorcode); } /** All is good. Send the output */ return $markup; } /** ob_start(); ?>
Parallax Error! get_error_text($errorcode) ?>