The slider was removed } elseif( (int)$slider['flag_deleted'] ) { $error = self::generateErrorMarkup( __('Removed slider', 'LayerSlider'), sprintf(__('The slider you’ve inserted here was removed in the meantime, thus it won’t be displayed to your visitors. This slider is still recoverable on the admin interface. You can enable listing removed sliders with the Screen Options -> Removed sliders option, then choose the Restore option for the corresponding item to reinstate this slider, or just click %shere%s.', 'LayerSlider'), '', ''), 'dashicons-trash' ); // ERROR: Scheduled sliders } else { $tz = date_default_timezone_get(); $siteTz = get_option('timezone_string', 'UTC'); $siteTz = $siteTz ? $siteTz : 'UTC'; date_default_timezone_set( $siteTz ); if( ! empty($slider['schedule_start']) && (int) $slider['schedule_start'] > time() ) { $error = self::generateErrorMarkup( sprintf(__('This slider is scheduled to display on %s', 'LayerSlider'), date_i18n(get_option('date_format').' @ '.get_option('time_format'), (int) $slider['schedule_start']) ), '', 'dashicons-calendar-alt', 'scheduled' ); } elseif( ! empty($slider['schedule_end']) && (int) $slider['schedule_end'] < time() ) { $error = self::generateErrorMarkup( sprintf(__('This slider was scheduled to hide on %s ','LayerSlider'), date_i18n(get_option('date_format').' @ '.get_option('time_format'), (int) $slider['schedule_end']) ), sprintf(__('Due to scheduling, this slider is no longer visible to your visitors. If you wish to reinstate this slider, just remove the schedule in %sSlider Settings -> Publish%s.', 'LayerSlider'), '', ''), 'dashicons-no-alt', 'dead' ); } date_default_timezone_set( $tz ); } // ERROR: No slider ID was provided } else { $error = self::generateErrorMarkup(); } return array( 'error' => $error, 'data' => $slider ); } public static function cacheForSlider( $sliderID ) { // Exclude administrators to avoid serving a copy // where notifications and other items may not be present. if( current_user_can( get_option('layerslider_custom_capability', 'manage_options') ) ) { return false; } // Attempt to retrieve the pre-generated markup // set via the Transients API if caching is enabled. if( get_option('ls_use_cache', true) ) { if( $slider = get_transient('ls-slider-data-'.$sliderID) ) { $slider['id'] = $sliderID; $slider['_cached'] = true; return $slider; } } return false; } public static function processShortcode( $slider, $embed = array() ) { // Slider ID $sID = 'layerslider_'.$slider['id']; // Include init code in the footer? $condsc = get_option('ls_conditional_script_loading', false) ? true : false; $footer = get_option('ls_include_at_footer', false) ? true : false; $footer = $condsc ? true : $footer; // Check for the '_cached' key in data, // indicating that it's a pre-generated // slider markup retrieved via Transients if( ! empty( $slider['_cached'] ) ) { $output = $slider; // No cached copy, generate new markup. // Make sure to include some database related // data, since we rely on those to display // notifications for admins. } else { $output = self::generateSliderMarkup( $slider, $embed ); $output['id'] = $slider['id']; $output['schedule_start'] = $slider['schedule_start']; $output['schedule_end'] = $slider['schedule_end']; $output['flag_hidden'] = $slider['flag_hidden']; $output['flag_deleted'] = $slider['flag_deleted']; // Save generated markup if caching is enabled, except for // administrators to avoid serving a copy where notifications // and other items may be present. $capability = get_option('layerslider_custom_capability', 'manage_options'); $permission = current_user_can( $capability ); if( get_option('ls_use_cache', true) && ! $permission ) { set_transient('ls-slider-data-'.$slider['id'], $output, HOUR_IN_SECONDS * 6); } } // Replace slider ID to avoid issues with enabled caching when // adding the same slider to a page in multiple times if(array_key_exists($slider['id'], self::$slidersOnPage)) { $sliderCount = ++self::$slidersOnPage[ $slider['id'] ]; $output['init'] = str_replace($sID, $sID.'_'.$sliderCount, $output['init']); $output['container'] = str_replace($sID, $sID.'_'.$sliderCount, $output['container']); $sID = $sID.'_'.$sliderCount; } else { // Add current slider ID to identify duplicates later on // and give them a unique slider ID to avoid issues with caching. self::$slidersOnPage[ $slider['id'] ] = 1; } // Override firstSlide if it is specified in embed params if( ! empty( $embed['firstslide'] ) ) { $output['init'] = str_replace('[firstSlide]', $embed['firstslide'], $output['init']); } // Filter to override the printed JavaScript init code if( has_filter('layerslider_slider_init') ) { $output['init'] = apply_filters('layerslider_slider_init', $output['init'], $slider, $sID ); } // Unify the whole markup after any potential string replacement $output['markup'] = $output['container'].$output['markup']; // Filter to override the printed HTML markup if( has_filter('layerslider_slider_markup') ) { $output['markup'] = apply_filters('layerslider_slider_markup', $output['markup'], $slider, $sID); } // Plugins if( ! empty( $output['plugins'] ) ) { $GLOBALS['lsLoadPlugins'] = array_merge($GLOBALS['lsLoadPlugins'], $output['plugins']); } // Fonts if( ! empty( $output['fonts'] ) ) { $GLOBALS['lsLoadFonts'] = array_merge($GLOBALS['lsLoadFonts'], $output['fonts']); } if( $footer ) { $GLOBALS['lsSliderInit'][] = $output['init']; return $output['markup']; } else { $output['init'] = ''; return $output['init'].$output['markup']; } } public static function generateSliderMarkup( $slider = null, $embed = array() ) { // Bail out early if no params received or using Popup on unactivated sites if( ! $slider || ( (int)$slider['flag_popup'] && ! LS_Config::isActivatedSite() ) ) { return array('init' => '', 'container' => '', 'markup' => ''); } // Slider and markup data $id = $slider['id']; $sliderID = 'layerslider_'.$id; $slides = $slider['data']; // Store generated output $lsInit = array(); $lsContainer = array(); $lsMarkup = array(); $lsPlugins = array(); $lsFonts = array(); // Include slider file if(is_array($slides)) { // Get phpQuery if( ! defined('LS_phpQuery') ) { libxml_use_internal_errors(true); include LS_ROOT_PATH.'/helpers/phpQuery.php'; } $GLOBALS['lsPremiumNotice'] = array(); include LS_ROOT_PATH.'/config/defaults.php'; include LS_ROOT_PATH.'/includes/slider_markup_setup.php'; include LS_ROOT_PATH.'/includes/slider_markup_html.php'; include LS_ROOT_PATH.'/includes/slider_markup_init.php'; // Admin notice when using premium features on non-activated sites if( ! empty( $GLOBALS['lsPremiumNotice'] ) ) { array_unshift($lsContainer, self::generateErrorMarkup( __('Premium features is available for preview purposes only.', 'LayerSlider'), sprintf(__('We’ve detected that you’re using premium features in this slider, but you have not yet activated your copy of LayerSlider. Premium features in your sliders will not be available for your visitors without activation. %sClick here to learn more%s. Detected features: %s', 'LayerSlider'), '', '', implode(', ', $GLOBALS['lsPremiumNotice'])), 'dashicons-star-filled', 'info' )); } $lsInit = implode('', $lsInit); $lsContainer = implode('', $lsContainer); $lsMarkup = implode('', $lsMarkup); } // Concatenate output if( get_option('ls_concatenate_output', false) ) { $lsInit = trim(preg_replace('/\s+/u', ' ', $lsInit)); $lsContainer = trim(preg_replace('/\s+/u', ' ', $lsContainer)); $lsMarkup = trim(preg_replace('/\s+/u', ' ', $lsMarkup)); } // Bug fix in v5.4.0: Use self closing tag for $lsMarkup = str_replace('>', ' />', $lsMarkup); // Return formatted data return array( 'init' => $lsInit, 'container' => $lsContainer, 'markup' => $lsMarkup, 'plugins' => array_unique( $lsPlugins ), 'fonts' => array_unique( $lsFonts ) ); } public static function generateErrorMarkup( $title = null, $description = null, $logo = 'dashicons-warning', $customClass = '' ) { if( ! $title ) { $title = __('LayerSlider encountered a problem while it tried to show your slider.', 'LayerSlider'); } if( is_null($description) ) { $description = __('Please make sure that you’ve used the right shortcode or method to insert the slider, and check if the corresponding slider exists and it wasn’t deleted previously.', 'LayerSlider'); } if( $description ) { $description .= '

'; } $logo = $logo ? '' : ''; $notice = __('Only you and other administrators can see this to take appropriate actions if necessary.', 'LayerSlider'); $classes = array('error', 'info', 'scheduled', 'dead'); if( ! empty($customClass) && ! in_array($customClass, $classes) ) { $customClass = ''; } return '
'.$logo.' '.$title.' '.$description.' '.$notice.'
'; } }