File: /home/dermova/www/india/wp-content/plugins/rit-core/inc/shortcode/parallax.php
<?php
/**
* RIT Core Plugin
* @package RIT Core
* @version 0.1
* @author CleverSoft
* @link http://cleversoft.co
* @copyright Copyright (c) 2015 CleverSoft
* @license GPL v2
*/
require_once( 'inc/otf_regen_thumbs.php' );
if ( ! class_exists( 'RIT_VCParallaxBackgrounds' ) ) {
class RIT_VCParallaxBackgrounds {
private static $parallaxID = 1;
const COMPATIBILITY_MODE = '_rit_vc_prlx_bg_compat_mode';
/**
* Constructor, checks for Visual Composer and defines hooks
*
* @return void
* @since 1.0
*/
function __construct() {
// Our translations
add_action( 'plugins_loaded', array( $this, 'loadTextDomain' ), 1 );
// Gambit links
add_filter( 'plugin_row_meta', array( $this, 'pluginLinks' ), 10, 2 );
add_action( 'after_setup_theme', array( $this, 'init' ), 1 );
add_filter( 'rit_add_parallax_div', array( __CLASS__, 'createParallaxDiv' ), 10, 3 );
add_action( 'admin_head', array( $this, 'printAdminScripts' ) );
// Activation instructions & CodeCanyon rating notices
$this->createNotices();
// Add plugin specific filters and actions here
add_action( 'wp_head', array( $this, 'ie9Detector' ) );
// Add a compatibility mode toggler
add_filter( 'plugin_row_meta', array( $this, 'addCompatibilityModeToggle' ), 11, 2 );
add_action( 'admin_init', array( $this, 'toggleCompatibilityMode' ) );
}
public function ie9Detector() {
echo "<!--[if IE 9]> <script>var _ritParallaxIE9 = true;</script> <![endif]-->";
}
/**
* Hook into Visual Composer
*
* @return void
* @since 2.3
*/
public function init() {
// Check if Visual Composer is installed
if ( ! defined( 'WPB_VC_VERSION' ) ) {
return;
}
if ( version_compare( WPB_VC_VERSION, '4.2', '<' ) ) {
add_action( 'init', array( $this, 'addParallaxParams' ), 100 );
} else {
// New feature in 3.1, compatibility mode. This is for themes that override
// the VC row element, mostly embedded copied of VC do this
$compatibilityMode = get_option( self::COMPATIBILITY_MODE );
if ( ! empty( $compatibilityMode ) ) {
add_action( 'admin_init', array( $this, 'addParallaxParams' ), 99999 );
} else {
// This is the normal method including the parallax parameters
add_action( 'vc_after_mapping', array( $this, 'addParallaxParams' ) );
}
}
}
/**
* There is a bug in Visual Composer where the dependencies do not refresh if the settings
* are inside a tab, this mini-script fixes this error
*
* @return void
* @since 2.0
*/
public function printAdminScripts() {
echo "<script>
jQuery(document).ready(function(\$) {
\$('body').on('click', '[role=tab]', function() { \$('[name=rit_parallax_bg_type]').trigger('change') });
});
</script>";
}
/**
* Loads the translations
*
* @return void
* @since 1.0
*/
public function loadTextDomain() {
load_plugin_textdomain( RIT_TEXT_DOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Creates the placeholder for the row with the parallax bg
*
* @param string $output An empty string
* @param array $atts The attributes of the vc_row shortcode
* @param string $content The contents of vc_row
* @return string The placeholder div
* @since 1.0
*/
public static function createParallaxDiv( $output, $atts, $content ) {
extract( shortcode_atts( array(
// Old parameter names, keep these for backward rendering compatibility
'parallax' => '',
'speed' => '',
'enable_mobile' => '',
'break_parents' => '',
// 'row_span' => '',
// BG type
'rit_parallax_bg_type' => '',
'gmbt_background_position' => '',
// Our new parameter names
'rit_parallax_parallax' => '',
'rit_parallax_speed' => '',
'rit_parallax_enable_mobile' => '',
'rit_parallax_break_parents' => '',
'gmbt_background_repeat' => '',
'rit_parallax_dont_scale_image' => '',
// 'rit_parallax_row_span' => '',
'rit_parallax_image' => '',
// Video options
'rit_parallax_video_youtube_mute' => '', // This is now also works with vimeo, but the name is still kept for backward compatibility
'rit_parallax_video_youtube_loop_trigger' => '0',
'rit_parallax_video' => '',
'rit_parallax_smooth_scrolling' => '',
'rit_parallax_video_aspect_ratio' => '',
// Deprecated
// FIXME: Probably a good idea to delete this after some version iterations (maybe on v3.2)
'rit_parallax_video_vimeo' => '', // Keep this for backward compatibility
'rit_parallax_video_youtube' => '', // Keep this for backward compatibility
), $atts ) );
/*
* We're using new param names now, support the old ones
*/
if ( empty( $rit_parallax_parallax ) ) {
$rit_parallax_parallax = $parallax;
}
if ( empty( $rit_parallax_speed ) ) {
$rit_parallax_speed = $speed;
}
if ( empty( $rit_parallax_enable_mobile ) ) {
$rit_parallax_enable_mobile = $enable_mobile;
}
if ( empty( $rit_parallax_break_parents ) ) {
$rit_parallax_break_parents = $break_parents;
}
$rit_parallax_dont_scale_image = "dont-scale";
/*
* Main parallax method
*/
$type = 'video';
if ( empty( $rit_parallax_bg_type ) || $rit_parallax_bg_type == 'parallax' ) {
$type = 'parallax';
}
// If there isn't any image in the CSS, or if there isn't any image attribute, skip it
$attachmentImage = self::getBackgroundAttachmentFromCSS( $atts, $rit_parallax_parallax, abs( (float) $rit_parallax_speed ), 'full' );
//if ( $type == 'parallax' && empty( $rit_parallax_image ) && ! $attachmentImage ) {
// return '';
//}
if ( empty( $rit_parallax_parallax ) ) {
return "";
}
/*
* Enqueue scripts
*/
$pluginData = get_plugin_data( __FILE__ );
// Our main script
wp_enqueue_script(
'vc-row-parallax',
plugins_url( 'js/min/script-min.js', __FILE__ ),
array( 'jquery' ),
RIT_VERSION,
true
);
// Smooth Scroller
if ( ! empty( $rit_parallax_smooth_scrolling ) ) {
wp_enqueue_script(
'rit-smooth-scroll',
plugins_url( 'js/min/rit-smoothscroll-min.js', __FILE__ ),
array( 'jquery' ),
RIT_VERSION,
true
);
}
// Parallax styles
wp_enqueue_style(
'vc-row-parallax-styles',
plugins_url( 'css/style.css', __FILE__ ),
array(),
RIT_VERSION
);
// rit-bg-parallax is just a fail-safe class because some themes might use bg-parallax
//$parallaxClass = ( $rit_parallax_parallax == "none" ) ? "" : "bg-parallax rit-bg-parallax";
//$parallaxClass = in_array( $rit_parallax_parallax, array( "none", "fixed", "up", "down", "left", "right", "bg-parallax" ) ) ? $parallaxClass : "";
$parallaxClass = in_array( $rit_parallax_parallax, array( "none", "fixed", "up", "down", "left", "right", "bg-parallax" ) ) ? "bg-parallax rit-bg-parallax" : "";
if ( $type == 'video' ) {
$parallaxClass = "bg-parallax rit-bg-parallax";
}
$parallaxClass .= " " . $type;
if ( ! $parallaxClass ) {
return '';
}
$videoDiv = "";
/*
* Form the video background
*/
// If this is empty, check the deprecated values, maybe those still have values
// FIXME: Probably a good idea to delete this after some version iterations (maybe on v3.2)
if ( empty( $rit_parallax_video ) ) {
$rit_parallax_video = $rit_parallax_video_youtube;
if ( ! empty( $rit_parallax_video_vimeo ) ) {
$rit_parallax_video = $rit_parallax_video_vimeo;
}
}
if ( $type == 'video' ) {
$rit_parallax_video = self::getVideoProvider( $rit_parallax_video );
if ( $rit_parallax_video['type'] == 'youtube' ) {
$videoDiv = "<div style='visibility: hidden' id='video-" . self::$parallaxID++ . "' data-youtube-video-id='" . $rit_parallax_video['id'] . "' data-mute='" . ( $rit_parallax_video_youtube_mute == 'mute' ? 'true' : 'false' ) . "' data-loop-adjustment='" . $rit_parallax_video_youtube_loop_trigger . "' data-video-aspect-ratio='" . $rit_parallax_video_aspect_ratio . "'><div id='video-" . self::$parallaxID++ . "-inner'></div></div>";
} else {
$videoDiv = '<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script><div id="video-' . self::$parallaxID . '" data-vimeo-video-id="' . $rit_parallax_video['id'] . '" data-mute="' . ( $rit_parallax_video_youtube_mute == 'mute' ? 'true' : 'false' ) . '" data-video-aspect-ratio="' . $rit_parallax_video_aspect_ratio . '"><iframe id="video-iframe-' . self::$parallaxID . '" src="//player.vimeo.com/video/' . $rit_parallax_video['id'] . '?api=1&player_id=video-iframe-' . self::$parallaxID++ . '&html5=1&autopause=0&autoplay=1&badge=0&byline=0&loop=1&title=0" frameborder="0"></iframe></div>';
}
}
// We can get the ID of the background image (then get the dimensions via VC's background styling)
/*
* Get the background image
*/
$bgImageWidth = '';
$bgImageHeight = '';
$bgImage = '';
if ( $type == 'parallax' ) {
// For normal "cover" parallax, use a special size
// For pattern / "repeat" parallax, use the full image size
$size = $gmbt_background_repeat == 'repeat' ? 'full' : 'cover';
// Compatibility mode: for older installed copies of the plugin, we used VC's background image, try and get the ID from that
$attachmentImage = self::getBackgroundAttachmentFromCSS( $atts, $rit_parallax_parallax, abs( (float) $rit_parallax_speed ), $size );
$bgImageWidth = $attachmentImage !== false ? $attachmentImage[1] : '';
$bgImageHeight = $attachmentImage !== false ? $attachmentImage[2] : '';
$bgImage = $attachmentImage[0];
// Else, try and use the new attribute
if ( ! empty( $rit_parallax_image ) ) {
$attachmentImage = self::getBackgroundAttachmentFromAttribute( $rit_parallax_image, $rit_parallax_parallax, abs( (float) $rit_parallax_speed ), $size );
$bgImageWidth = $attachmentImage !== false ? $attachmentImage[1] : '';
$bgImageHeight = $attachmentImage !== false ? $attachmentImage[2] : '';
$bgImage = $attachmentImage[0];
}
}
return "<div class='" . esc_attr( $parallaxClass ) . "' " .
"data-bg-align='" . esc_attr( $gmbt_background_position ) . "' " .
"data-direction='" . esc_attr( $rit_parallax_parallax ) . "' " .
"data-velocity='" . esc_attr( (float)$rit_parallax_speed * -1 ) . "' " .
"data-mobile-enabled='" . esc_attr( $rit_parallax_enable_mobile ) . "' " .
"data-break-parents='" . esc_attr( $rit_parallax_break_parents ) . "' " .
"data-bg-height='" . esc_attr( $bgImageHeight ) . "' " .
"data-bg-width='" . esc_attr( $bgImageWidth ) . "' " .
"data-bg-image='" . esc_attr( $bgImage ) . "' " .
"data-bg-size-adjust='" . esc_attr( $rit_parallax_dont_scale_image ) . "' " .
"data-bg-repeat='" . esc_attr( empty( $gmbt_background_repeat ) ? 'false' : 'true' ) . "'>" . $videoDiv . "</div>";
}
/**
* Gets the Video ID & Provider from a video URL or ID
*
* @param $videoString string The URL or ID of a video
* @return array container whether the video is a YouTube video or a Vimeo video along with the video ID
* @since 3.0
*/
protected static function getVideoProvider( $videoString ) {
$videoString = trim( $videoString );
/*
* Check for YouTube
*/
$videoID = false;
if ( preg_match( '/youtube\.com\/watch\?v=([^\&\?\/]+)/', $videoString, $id ) ) {
if ( count( $id > 1 ) ) {
$videoID = $id[1];
}
} else if ( preg_match( '/youtube\.com\/embed\/([^\&\?\/]+)/', $videoString, $id ) ) {
if ( count( $id > 1 ) ) {
$videoID = $id[1];
}
} else if ( preg_match( '/youtube\.com\/v\/([^\&\?\/]+)/', $videoString, $id ) ) {
if ( count( $id > 1 ) ) {
$videoID = $id[1];
}
} else if ( preg_match( '/youtu\.be\/([^\&\?\/]+)/', $videoString, $id ) ) {
if ( count( $id > 1 ) ) {
$videoID = $id[1];
}
}
if ( ! empty( $videoID ) ) {
return array(
'type' => 'youtube',
'id' => $videoID
);
}
/*
* Check for Vimeo
*/
if ( preg_match( '/vimeo\.com\/(\w*\/)*(\d+)/', $videoString, $id ) ) {
if ( count( $id > 1 ) ) {
$videoID = $id[ count( $id ) - 1 ];
}
}
if ( ! empty( $videoID ) ) {
return array(
'type' => 'vimeo',
'id' => $videoID
);
}
/*
* Non-URL form
*/
if ( preg_match( '/^\d+$/', $videoString ) ) {
return array(
'type' => 'vimeo',
'id' => $videoString
);
}
return array(
'type' => 'youtube',
'id' => $videoString
);
}
/**
* Finds the attachment object from the generated CSS by Visual Composer
*
* @return void
* @since 3.0
*/
protected static function getBackgroundAttachmentFromCSS( $atts, $direction, $velocity, $size = 'cover' ) {
if ( empty( $atts['css'] ) ) {
return false;
}
if ( preg_match( '/\?id=(\d+)/', $atts['css'], $id ) === false ) {
return false;
}
if ( count( $id ) < 2 ) {
return false;
}
$id = $id[1];
if ( $size == 'cover' && strtolower( $direction ) != 'none') {
if ( strtolower( $direction ) == 'up' || strtolower( $direction ) == 'down' ) {
$width = 1600;
$height = 1000 + 500 * $velocity;
} else {
$width = 1600 + 500 * $velocity;
$height = 1000;
}
$attachmentImage = wp_get_attachment_image_src( $id, array( (int)$width, (int)$height) );
} else {
$attachmentImage = wp_get_attachment_image_src( $id, $size );
}
return $attachmentImage;
}
/**
* Finds the attachment object from the generated CSS by Visual Composer
*
* @return void
* @since 3.0
*/
protected static function getBackgroundAttachmentFromAttribute( $attachmentID, $direction, $velocity, $size = 'cover' ) {
if ( $size != 'cover' ) {
return wp_get_attachment_image_src( $attachmentID, $size );
}
if ( strtolower( $direction ) != 'none' ) {
if ( strtolower( $direction ) == 'up' || strtolower( $direction ) == 'down' ) {
$width = 1600;
$height = 1000 + 500 * $velocity;
} else {
$width = 1600 + 500 * $velocity;
$height = 1000;
}
return wp_get_attachment_image_src( $attachmentID, array( $width, $height) );
}
return wp_get_attachment_image_src( $attachmentID, 'full' );
}
/**
* Adds the parameter fields to the VC row
*
* @return void
* @since 1.0
*/
public function addParallaxParams() {
$setting = array(
"type" => "dropdown",
"class" => "",
"heading" => __( "Background Type", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_bg_type",
"value" => array(
__( "Image Parallax", RIT_TEXT_DOMAIN ) => "parallax",
__( "Video", RIT_TEXT_DOMAIN ) => "video",
),
"description" => __( "No live previews are shown in the VC frontend edito due to the different structure of the editor. The normal background image is shown instead.", RIT_TEXT_DOMAIN ),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "dropdown",
"class" => "",
"heading" => __( "Breakout Row Background", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_break_parents",
"value" => array(
"Don't break out the row container" => "0",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 1, RIT_TEXT_DOMAIN ), 1 ) => "1",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 2, RIT_TEXT_DOMAIN ), 2 ) => "2",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 3, RIT_TEXT_DOMAIN ), 3 ) => "3",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 4, RIT_TEXT_DOMAIN ), 4 ) => "4",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 5, RIT_TEXT_DOMAIN ), 5 ) => "5",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 6, RIT_TEXT_DOMAIN ), 6 ) => "6",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 7, RIT_TEXT_DOMAIN ), 7 ) => "7",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 8, RIT_TEXT_DOMAIN ), 8 ) => "8",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 9, RIT_TEXT_DOMAIN ), 9 ) => "9",
sprintf( _n( "Break out of 1 container", "Break out of %d containers", 10, RIT_TEXT_DOMAIN ), 10 ) => "10",
__( "Break out of all containers (full page width)", RIT_TEXT_DOMAIN ) => "99",
),
"description" => __( "Your background images, background colors, image parallax and video backgrounds are contained inside a Visual Composer row, depending on your theme, this container may be too small for your needs. Adjust this option to let the backgruond stretch outside it's current container and occupy the parent container's width.", RIT_TEXT_DOMAIN ),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "checkbox",
"class" => "",
"heading" => __( "Enable Smooth Scrolling", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_smooth_scrolling",
"value" => array( __( "Check this to enable smooth scrolling for the whole page. If at least one row has this checked, your entire page will scroll smoothly.", RIT_TEXT_DOMAIN ) => "rit_parallax_enable_smooth_scroll" ),
"description" => __( "", RIT_TEXT_DOMAIN ),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "textfield",
"class" => "",
"heading" => __( "YouTube or Vimeo URL or Video ID", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_video",
"value" => "",
"description" => __( "Enter the URL to the video or the video ID of your YouTube or Vimeo video you want to use as your background. If your URL isn't showing a video, try inputting the video ID instead. <em>Ads will show up in the video if it has them.</em> No video will be shown if left blank. <strong>Tip: newly uploaded videos may not display right away and might show an error message</strong><br><br><strong>Videos will not show up in mobile devices because they handle videos differently. In those cases, please put in a background image the normal way (in the <em>Design Options</em> tab) and that will be shown instead.</strong>", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "video" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "checkbox",
"class" => "",
"heading" => __( "Mute Video", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_video_youtube_mute",
"value" => array( __( "Check this to mute your video.", RIT_TEXT_DOMAIN ) => "mute" ),
"description" => __( "", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "video" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "textfield",
"class" => "",
"heading" => __( "YouTube Loop Triggering Refinement", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_video_youtube_loop_trigger",
"value" => "0",
"description" => '<div class="dashicons dashicons-megaphone" style="color: #e74c3c"></div> ' . __( "<strong>Use this if you see a noticeable dark video frame before the video loops.</strong> Because YouTube performs it's video looping with a huge noticeable delay, we try our best to guess when the video exactly ends and trigger a loop when we <em>just</em> reach the end. If there's a dark frame, put in a time here in milliseconds that we can use to push back the looping trigger. Try values from 5-100 milliseconds.", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "video" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "textfield",
"class" => "",
"heading" => __( "Video Aspect Ratio", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_video_aspect_ratio",
"value" => '16:9',
"description" => __( "The video will be resized to maintain this aspect ratio, this is to prevent the video from showing any black bars. Enter an aspect ratio here such as: "16:9", "4:3" or "16:10". The default is "16:9"", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "video" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "dropdown",
"class" => "",
"heading" => __( "Background Image Parallax", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_parallax",
"value" => array(
"No Parallax" => "none",
"Fixed" => "fixed",
"Up" => "up",
"Down" => "down",
"Left" => "left",
"Right" => "right",
),
"description" => __( "You can select your background image to apply parallax to on the field below, or you can also head over to the <strong>Design Options</strong> tab and select an image there.</em></strong>", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "attach_image",
"class" => "",
"heading" => __( "Background Image", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_image",
"description" => __( "Select your background image. <strong>Make sure that your image is of high resolution, we will resize the image to make it fit and to optimize it to achieve the best performance</strong>. You can use this field to input your image or use the image uploader provided in the <strong>Design Options</strong> tab.", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
// $setting = array(
// "type" => "checkbox",
// "class" => "",
// "param_name" => "rit_parallax_dont_scale_image",
// "value" => array( __( "Do not scale the background image depending on the row size.", RIT_TEXT_DOMAIN ) => "dont-scale" ),
// "description" => __( "By default, the background is resized to fit the row size, small images get upsized and large images get downsized. Checking this will disable resizing.", RIT_TEXT_DOMAIN ),
// "dependency" => array(
// "element" => "rit_parallax_bg_type",
// "value" => array( "parallax" ),
// ),
// "group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
// );
// vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "dropdown",
"class" => "",
"heading" => __( "Background Style / Repeat", RIT_TEXT_DOMAIN ),
"param_name" => "gmbt_background_repeat",
"value" => array(
__( "Cover Whole Row (covers the whole row)", RIT_TEXT_DOMAIN ) => "",
__( "Repeating Image Pattern", RIT_TEXT_DOMAIN ) => "repeat",
),
"description" => __( "Select whether the background image above should cover the whole row, or whether the image is a background seamless pattern.", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "dropdown",
"class" => "",
"heading" => __( "Background Position / Alignment", RIT_TEXT_DOMAIN ),
"param_name" => "gmbt_background_position",
"value" => array(
__( "Centered", RIT_TEXT_DOMAIN ) => "",
__( "Left (only applies to up, down parallax or fixed)", RIT_TEXT_DOMAIN ) => "left",
__( "Right (only applies to up, down parallax or fixed)", RIT_TEXT_DOMAIN ) => "right",
__( "Top (only applies to left or right parallax)", RIT_TEXT_DOMAIN ) => "top",
__( "Bottom (only applies to left or right parallax)", RIT_TEXT_DOMAIN ) => "bottom",
),
"description" => __( "The alignment of the background / parallax image. Note that this most likely will only be noticeable in smaller screens, if the row is large enough, the image will most likely be fully visible. Use this if you want to ensure that a certain area will always be visible in your parallax in smaller screens.<br><br><strong>Not applicable to pattern backgrounds.</strong>", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "textfield",
"class" => "",
"heading" => __( "Parallax Speed", RIT_TEXT_DOMAIN ),
"param_name" => "rit_parallax_speed",
"value" => "0.3",
"description" => __( "The movement speed, value should be between 0.1 and 1.0. A lower number means slower scrolling speed.", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
$setting = array(
"type" => "checkbox",
"class" => "",
"param_name" => "rit_parallax_enable_mobile",
"value" => array( __( "Check this to enable the parallax effect in mobile devices", RIT_TEXT_DOMAIN ) => "parallax-enable-mobile" ),
"description" => __( "Parallax effects would most probably cause slowdowns when your site is viewed in mobile devices. If the device width is less than 980 pixels, then it is assumed that the site is being viewed in a mobile device.", RIT_TEXT_DOMAIN ),
"dependency" => array(
"element" => "rit_parallax_bg_type",
"value" => array( "parallax" ),
),
"group" => __( "Image Parallax / Video", RIT_TEXT_DOMAIN ),
);
vc_add_param( 'vc_row', $setting );
}
/**
* Adds plugin links
*
* @access public
* @param array $plugin_meta The current array of links
* @param string $plugin_file The plugin file
* @return array The current array of links together with our additions
* @since 2.6
**/
public function pluginLinks( $plugin_meta, $plugin_file ) {
if ( $plugin_file == plugin_basename( __FILE__ ) ) {
$pluginData = get_plugin_data( __FILE__ );
$plugin_meta[] = sprintf( "<a href='%s' target='_blank'>%s</a>",
"http://support.rit.ph?utm_source=" . urlencode( $pluginData['Name'] ) . "&utm_medium=plugin_link",
__( "Get Customer Support", RIT_TEXT_DOMAIN )
);
$plugin_meta[] = sprintf( "<a href='%s' target='_blank'>%s</a>",
"http://codecanyon.net/user/GambitTech/portfolio?utm_source=" . urlencode( $pluginData['Name'] ) . "&utm_medium=plugin_link",
__( "Get More Plugins", RIT_TEXT_DOMAIN )
);
}
return $plugin_meta;
}
/************************************************************************
* Activation instructions & CodeCanyon rating notices START
************************************************************************/
/**
* For theme developers who want to include our plugin, they will need
* to disable this section. This can be done by include this line
* in their theme:
*
* defined( 'rit_DISABLE_RATING_NOTICE' ) or define( 'rit_DISABLE_RATING_NOTICE', true );
*/
/**
* Adds the hooks for the notices
*
* @access protected
* @return void
* @since 2.6
**/
protected function createNotices() {
register_activation_hook( __FILE__, array( $this, 'justActivated' ) );
register_deactivation_hook( __FILE__, array( $this, 'justDeactivated' ) );
if ( defined( 'rit_DISABLE_RATING_NOTICE' ) ) {
return;
}
add_action( 'admin_notices', array( $this, 'remindSettingsAndSupport' ) );
add_action( 'admin_notices', array( $this, 'remindRating' ) );
add_action( 'wp_ajax_' . __CLASS__ . '-ask-rate', array( $this, 'ajaxRemindHandler' ) );
}
/**
* Creates the transients for triggering the notices when the plugin is activated
*
* @return void
* @since 2.6
**/
public function justActivated() {
delete_transient( __CLASS__ . '-activated' );
if ( defined( 'rit_DISABLE_RATING_NOTICE' ) ) {
return;
}
set_transient( __CLASS__ . '-activated', time(), MINUTE_IN_SECONDS * 3 );
delete_transient( __CLASS__ . '-ask-rate' );
set_transient( __CLASS__ . '-ask-rate', time(), DAY_IN_SECONDS * 4 );
update_option( __CLASS__ . '-ask-rate-placeholder', 1 );
}
/**
* Removes the transients & triggers when the plugin is deactivated
*
* @return void
* @since 2.6
**/
public function justDeactivated() {
delete_transient( __CLASS__ . '-activated' );
delete_transient( __CLASS__ . '-ask-rate' );
delete_option( __CLASS__ . '-ask-rate-placeholder' );
}
/**
* Ajax handler for when a button is clicked in the 'ask rating' notice
*
* @return void
* @since 2.6
**/
public function ajaxRemindHandler() {
check_ajax_referer( __CLASS__, '_nonce' );
if ( $_POST['type'] == 'remove' ) {
delete_option( __CLASS__ . '-ask-rate-placeholder' );
} else { // remind
set_transient( __CLASS__ . '-ask-rate', time(), DAY_IN_SECONDS );
}
die();
}
/**
* Displays the notice for reminding the user to rate our plugin
*
* @return void
* @since 2.6
**/
public function remindRating() {
if ( defined( 'rit_DISABLE_RATING_NOTICE' ) ) {
return;
}
if ( get_option( __CLASS__ . '-ask-rate-placeholder' ) === false ) {
return;
}
if ( get_transient( __CLASS__ . '-ask-rate' ) ) {
return;
}
$pluginData = get_plugin_data( __FILE__ );
$nonce = wp_create_nonce( __CLASS__ );
echo '<div class="updated rit-ask-rating" style="border-left-color: #3498db">
<p>
<img src="' . plugins_url( 'rit-logo.png', __FILE__ ) . '" style="display: block; margin-bottom: 10px"/>
<strong>' . sprintf( __( 'Enjoying %s?', RIT_TEXT_DOMAIN ), $pluginData['Name'] ) . '</strong><br>' .
__( 'Help us out by rating our plugin 5 stars in CodeCanyon! This will allow us to create more awesome products and provide top notch customer support.', RIT_TEXT_DOMAIN ) . '<br>' .
'<button data-href="http://codecanyon.net/downloads?utm_source=' . urlencode( $pluginData['Name'] ) . '&utm_medium=rate_notice#item-7049478" class="button button-primary" style="margin: 10px 10px 10px 0;">' . __( 'Rate us 5 stars in CodeCanyon :)', RIT_TEXT_DOMAIN ) . '</button>' .
'<button class="button button-secondary remind" style="margin: 10px 10px 10px 0;">' . __( 'Remind me tomorrow', RIT_TEXT_DOMAIN ) . '</button>' .
'<button class="button button-secondary nothanks" style="margin: 10px 0;">' . __( 'I've already rated!', RIT_TEXT_DOMAIN ) . '</button>' .
'<script>
jQuery(document).ready(function($) {
"use strict";
$(".rit-ask-rating button").click(function() {
if ( $(this).is(".button-primary") ) {
var $this = $(this);
var data = {
"_nonce": "' . $nonce . '",
"action": "' . __CLASS__ . '-ask-rate",
"type": "remove"
};
$.post(ajaxurl, data, function(response) {
$this.parents(".updated:eq(0)").fadeOut();
window.open($this.attr("data-href"), "_blank");
});
} else if ( $(this).is(".remind") ) {
var $this = $(this);
var data = {
"_nonce": "' . $nonce . '",
"action": "' . __CLASS__ . '-ask-rate",
"type": "remind"
};
$.post(ajaxurl, data, function(response) {
$this.parents(".updated:eq(0)").fadeOut();
});
} else if ( $(this).is(".nothanks") ) {
var $this = $(this);
var data = {
"_nonce": "' . $nonce . '",
"action": "' . __CLASS__ . '-ask-rate",
"type": "remove"
};
$.post(ajaxurl, data, function(response) {
$this.parents(".updated:eq(0)").fadeOut();
});
}
return false;
});
});
</script>
</p>
</div>';
}
/**
* Displays the notice that we have a support site and additional instructions
*
* @return void
* @since 2.6
**/
public function remindSettingsAndSupport() {
if ( defined( 'rit_DISABLE_RATING_NOTICE' ) ) {
return;
}
if ( ! get_transient( __CLASS__ . '-activated' ) ) {
return;
}
$pluginData = get_plugin_data( __FILE__ );
echo '<div class="updated" style="border-left-color: #3498db">
<p>
<img src="' . plugins_url( 'rit-logo.png', __FILE__ ) . '" style="display: block; margin-bottom: 10px"/>
<strong>' . sprintf( __( 'Thank you for activating %s!', RIT_TEXT_DOMAIN ), $pluginData['Name'] ) . '</strong><br>' .
__( 'Now just edit your <strong>row settings</strong> in Visual Composer, add a background picture in the <strong>Design Options</strong> tab, then head on to the <strong>Image Parallax / Video</strong> tab to adjust your parallax.', RIT_TEXT_DOMAIN ) . '<br>' .
__( 'If you need any support, you can leave us a ticket in our support site. The link to our support site is listed in the plugin details for future reference.', RIT_TEXT_DOMAIN ) . '<br>' .
'<a href="http://support.rit.ph?utm_source=' . urlencode( $pluginData['Name'] ) . '&utm_medium=activation_notice" class="rit_ask_rate button button-default" style="margin: 10px 0;" target="_blank">' . __( 'Visit our support site', RIT_TEXT_DOMAIN ) . '</a>' .
'<br>' .
'<em style="color: #999">' . __( 'This notice will go away in a moment', RIT_TEXT_DOMAIN ) . '</em><br>
</p>
</div>';
}
/************************************************************************
* Activation instructions & CodeCanyon rating notices END
************************************************************************/
/**
* Adds an enabled/disable link for toggling compatiblity mode. Compatibility mode changes the
* hook so that the plugin will work in impractical situations where VC is embedded into a theme
*
* @access public
* @param array $plugin_meta The current array of links
* @param string $plugin_file The plugin file
* @return array The current array of links together with our additions
* @since 3.1
**/
public function addCompatibilityModeToggle( $plugin_meta, $plugin_file ) {
if ( $plugin_file == plugin_basename( __FILE__ ) ) {
$pluginData = get_plugin_data( __FILE__ );
$compatibilityMode = get_option( self::COMPATIBILITY_MODE );
$nonce = wp_create_nonce( self::COMPATIBILITY_MODE );
if ( empty( $compatibilityMode ) ) {
$plugin_meta[] = sprintf( "<a href='%s' target='_self'>%s</a>",
admin_url( "plugins.php?" . self::COMPATIBILITY_MODE . "=1&nonce=" . $nonce ),
__( "Enable Compatibility Mode", RIT_TEXT_DOMAIN )
);
} else {
$plugin_meta[] = sprintf( "<a href='%s' target='_self'>%s</a>",
admin_url( "plugins.php?" . self::COMPATIBILITY_MODE . "=0&nonce=" . $nonce ),
__( "Disable Compatibility Mode", RIT_TEXT_DOMAIN )
);
}
}
return $plugin_meta;
}
public function toggleCompatibilityMode() {
if ( empty( $_REQUEST['nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_REQUEST['nonce'], self::COMPATIBILITY_MODE ) ) {
return;
}
if ( isset( $_REQUEST[ self::COMPATIBILITY_MODE ] ) ) {
if ( empty( $_REQUEST[ self::COMPATIBILITY_MODE ] ) ) {
delete_option( self::COMPATIBILITY_MODE );
} else {
update_option( self::COMPATIBILITY_MODE, '1' );
}
wp_redirect( admin_url( 'plugins.php' ) );
die();
}
}
}
new RIT_VCParallaxBackgrounds();
}
if ( ! function_exists( 'vc_theme_before_vc_row' ) ) {
/**
* Adds the placeholder div right before the vc_row is printed
*
* @param array $atts The attributes of the vc_row shortcode
* @param string $content The contents of vc_row
* @return string The placeholder div
* @since 1.0
*/
function vc_theme_before_vc_row($atts, $content = null) {
return apply_filters( 'rit_add_parallax_div', '', $atts, $content );
}
}