/** * The form shown on the admins widget page. Here settings can be changed. * * @since 1.2.0 * @param mixed array $instance * @return string */ function form($instance) { // Defaults $defaults = array('title' => __(self::$widgetName, 'slideshow-plugin'), 'slideshowId' => -1); // Merge database settings with defaults $instance = wp_parse_args((array) $instance, $defaults); // Get slideshows $slideshows = get_posts(array('numberposts' => -1, 'offset' => 0, 'post_type' => SlideshowPluginPostType::$postType)); // Include form include SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/form.php'; }
/** * Loads the stylesheet with the parsed style name, then returns it. * * @since 2.2.8 * @param string $styleName * @return string $stylesheet */ public static function loadStylesheet($styleName) { // Get custom stylesheet, of the default stylesheet if the custom stylesheet does not exist $stylesheet = get_option($styleName, ''); if (strlen($stylesheet) <= 0) { $stylesheetFile = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin' . DIRECTORY_SEPARATOR . $styleName . '.css'; if (!file_exists($stylesheetFile)) { $stylesheetFile = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin' . DIRECTORY_SEPARATOR . 'style-light.css'; } // Get contents of stylesheet ob_start(); include $stylesheetFile; $stylesheet .= ob_get_clean(); } // Replace the '%plugin-url%' tag with the actual URL and add a unique identifier to separate stylesheets $stylesheet = str_replace('%plugin-url%', SlideshowPluginMain::getPluginUrl(), $stylesheet); $stylesheet = str_replace('.slideshow_container', '.slideshow_container_' . $styleName, $stylesheet); return $stylesheet; }
<?php // Path to the General Settings' views folder $generalSettingsViewsPath = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'SlideshowPluginGeneralSettings' . DIRECTORY_SEPARATOR; ?> <div class="wrap"> <form method="post" action="options.php"> <?php settings_fields(SlideshowPluginGeneralSettings::$settingsGroup); ?> <div class="icon32" style="background: url('<?php echo SlideshowPluginMain::getPluginUrl() . '/images/SlideshowPluginPostType/adminIcon32.png'; ?> ');"></div> <h2 class="nav-tab-wrapper"> <a href="#general-settings-tab" class="nav-tab nav-tab-active"><?php _e('General Settings', 'slideshow-plugin'); ?> </a> <a href="#default-slideshow-settings-tab" class="nav-tab"><?php _e('Default Slideshow Settings', 'slideshow-plugin'); ?> </a> <a href="#custom-styles-tab" class="nav-tab"><?php _e('Custom Styles', 'slideshow-plugin'); ?> </a> <?php
/** * Gets the stylesheet with the parsed style name, then returns it. * * @since 2.2.8 * @param string $styleName * @return string $stylesheet */ public static function getStylesheet($styleName) { // Check if $styleName is a custom stylesheet if (self::isCustomStylesheet($styleName)) { // Get custom stylesheet $stylesheet = get_option($styleName, ''); } else { $stylesheetFile = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin' . DIRECTORY_SEPARATOR . $styleName . '.css'; if (!file_exists($stylesheetFile)) { $stylesheetFile = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin' . DIRECTORY_SEPARATOR . 'style-light.css'; } // Get contents of stylesheet ob_start(); include $stylesheetFile; $stylesheet = ob_get_clean(); } // Replace the URL placeholders with actual URLs and add a unique identifier to separate stylesheets $stylesheet = str_replace('%plugin-url%', SlideshowPluginMain::getPluginUrl(), $stylesheet); $stylesheet = str_replace('%site-url%', get_bloginfo('url'), $stylesheet); $stylesheet = str_replace('%stylesheet-url%', get_stylesheet_directory_uri(), $stylesheet); $stylesheet = str_replace('%template-url%', get_template_directory_uri(), $stylesheet); $stylesheet = str_replace('.slideshow_container', '.slideshow_container_' . $styleName, $stylesheet); return $stylesheet; }
/** * Returns an array of stylesheets with its keys and respective names. * * Gets the version number for each stylesheet when $withVersion is set to true. * * When the $separateDefaultFromCustom boolean is set to true, the default stylesheets will be returned separately * from the custom stylesheets. * * The data returned with both parameters set to 'false' will look like the following: * * [$stylesheetKey => $stylesheetName] * * With both parameters set to 'true' the returned data will be formed like this: * * [ * default => [$stylesheetKey => [name => $stylesheetName, version => $versionNumber]], * custom => [$stylesheetKey => [name => $stylesheetName, version => $versionNumber]] * ] * * @since 2.1.23 * @param boolean $withVersion (optional, defaults to false) * @param boolean $separateDefaultFromCustom (optional, defaults to false) * @return array $stylesheets */ static function getStylesheets($withVersion = false, $separateDefaultFromCustom = false) { // Default styles $defaultStyles = array('style-light.css' => __('Light', 'slideshow-plugin'), 'style-dark.css' => __('Dark', 'slideshow-plugin')); // Loop through default stylesheets $stylesheetsFilePath = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin'; foreach ($defaultStyles as $fileName => $name) { // Check if stylesheet exists on server, don't offer it when it does not exist. if (!file_exists($stylesheetsFilePath . DIRECTORY_SEPARATOR . $fileName)) { unset($defaultStyles[$fileName]); continue; } // Add version if $withVersion is true if ($withVersion) { $defaultStyles[$fileName] = array('name' => $name, 'version' => SlideshowPluginMain::$version); } } // Get custom styles $customStyles = get_option(SlideshowPluginGeneralSettings::$customStyles, array()); // Add version to the custom styles if $withVersion is true if ($withVersion) { foreach ($customStyles as $customStylesKey => $customStylesName) { $customStylesVersion = get_option($customStylesKey . '_version', false); if (!$customStylesVersion) { $customStylesVersion = time(); } $customStyles[$customStylesKey] = array('name' => $customStylesName, 'version' => $customStylesVersion); } } // Return if ($separateDefaultFromCustom) { return array('default' => $defaultStyles, 'custom' => $customStyles); } return array_merge($defaultStyles, $customStyles); }
/** * Function prepare returns the required html and enqueues * the scripts and stylesheets necessary for displaying the slideshow * * Passing this function no parameter or passing it a negative one will * result in a random pick of slideshow * * @since 2.1.0 * @param int $postId * @return String $output */ static function prepare($postId = null) { $post = null; // Get post by its ID, if the ID is not a negative value if (is_numeric($postId) && $postId >= 0) { $post = get_post($postId); } // Get slideshow by slug when it's a non-empty string if ($post === null && is_string($postId) && !is_numeric($postId) && !empty($postId)) { $query = new WP_Query(array('post_type' => SlideshowPluginPostType::$postType, 'name' => $postId, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => true)); if ($query->have_posts()) { $post = $query->next_post(); } } // When no slideshow is found, get one at random if ($post === null) { $post = get_posts(array('numberposts' => 1, 'offset' => 0, 'orderby' => 'rand', 'post_type' => SlideshowPluginPostType::$postType, 'suppress_filters' => true)); if (is_array($post)) { $post = $post[0]; } } // Exit on error if ($post === null) { return '<!-- Wordpress Slideshow - No slideshows available -->'; } // Log slideshow's issues to be able to track them on the page. $log = array(); // Get views $views = SlideshowPluginSlideshowSettingsHandler::getViews($post->ID); if (!is_array($views) || count($views) <= 0) { $log[] = 'No views were found'; } // Get settings $settings = SlideshowPluginSlideshowSettingsHandler::getSettings($post->ID); $styleSettings = SlideshowPluginSlideshowSettingsHandler::getStyleSettings($post->ID); // The slideshow's session ID, allows JavaScript and CSS to distinguish between multiple slideshows $sessionID = self::$sessionCounter++; // Try to get a custom stylesheet if (isset($styleSettings['style'])) { // Try to get the custom style's version $customStyle = get_option($styleSettings['style'], false); $customStyleVersion = false; if ($customStyle) { $customStyleVersion = get_option($styleSettings['style'] . '_version', false); } // Style name and version if ($customStyle && $customStyleVersion) { $styleName = $styleSettings['style']; $styleVersion = $customStyleVersion; } else { $styleName = str_replace('.css', '', $styleSettings['style']); $styleVersion = SlideshowPluginMain::$version; } } else { $styleName = 'style-light'; $styleVersion = SlideshowPluginMain::$version; } // Register function stylesheet wp_enqueue_style('slideshow-jquery-image-gallery-stylesheet_functional', SlideshowPluginMain::getPluginUrl() . '/style/' . __CLASS__ . '/functional.css', array(), SlideshowPluginMain::$version); // Enqueue stylesheet wp_enqueue_style('slideshow-jquery-image-gallery-ajax-stylesheet_' . $styleName, admin_url('admin-ajax.php?action=slideshow_jquery_image_gallery_load_stylesheet&style=' . $styleName), array(), $styleVersion); // Include output file to store output in $output. $output = ''; ob_start(); include SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/slideshow.php'; $output .= ob_get_clean(); // Enqueue slideshow script wp_enqueue_script('slideshow-jquery-image-gallery-script', SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/slideshow.min.js', array('jquery'), SlideshowPluginMain::$version); // Set dimensionWidth and dimensionHeight if dimensions should be preserved if (isset($settings['preserveSlideshowDimensions']) && $settings['preserveSlideshowDimensions'] == 'true') { $aspectRatio = explode(':', $settings['aspectRatio']); // Width if (isset($aspectRatio[0]) && is_numeric($aspectRatio[0])) { $settings['dimensionWidth'] = $aspectRatio[0]; } else { $settings['dimensionWidth'] = 1; } // Height if (isset($aspectRatio[1]) && is_numeric($aspectRatio[1])) { $settings['dimensionHeight'] = $aspectRatio[1]; } else { $settings['dimensionHeight'] = 1; } } // Include slideshow settings by localizing them wp_localize_script('slideshow-jquery-image-gallery-script', 'SlideshowPluginSettings_' . $sessionID, $settings); // Return output return $output; }
<?php // Get default stylesheets $defaultStyles = array(); $defaultStylesheets = array('style-light.css' => __('Light', 'slideshow-plugin'), 'style-dark.css' => __('Dark', 'slideshow-plugin')); $stylesheetsFilePath = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin'; foreach ($defaultStylesheets as $fileName => $name) { if (file_exists($stylesheetsFilePath . DIRECTORY_SEPARATOR . $fileName)) { ob_start(); include $stylesheetsFilePath . DIRECTORY_SEPARATOR . $fileName; $defaultStyles[$fileName] = array('name' => $name, 'style' => ob_get_clean()); } } // Get custom styles $customStyleValues = array(); $customStyleKeys = get_option(SlideshowPluginGeneralSettings::$customStyles, array()); if (is_array($customStyleKeys)) { foreach ($customStyleKeys as $customStyleKey => $customStyleKeyName) { // Get custom style value from custom style key $customStyleValues[$customStyleKey] = get_option($customStyleKey); } } ?> <div class="custom-styles-tab feature-filter" style="float: left; display: none;"> <div class="styles-list"> <p> <b><?php _e('Default stylesheets', 'slideshow-plugin'); ?>
/** * Include popup, needs to be called in the footer * * @since 2.0.0 */ static function includePopup() { include SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/search-popup.php'; }
/** * Function prepare returns the required html and enqueues * the scripts and stylesheets necessary for displaying the slideshow * * Passing this function no parameter or passing it a negative one will * result in a random pick of slideshow * * @since 2.1.0 * @param int $postId * @return String $output */ static function prepare($postId = null) { $post = null; // Get post by its ID, if the ID is not a negative value if (is_numeric($postId) && $postId >= 0) { $post = get_post($postId); } // Get slideshow by slug when it's a non-empty string if ($post === null && is_string($postId) && !is_numeric($postId) && !empty($postId)) { $query = new WP_Query(array('post_type' => SlideshowPluginPostType::$postType, 'name' => $postId, 'orderby' => 'post_date', 'order' => 'DESC', 'suppress_filters' => true)); if ($query->have_posts()) { $post = $query->next_post(); } } // When no slideshow is found, get one at random if ($post === null) { $post = get_posts(array('numberposts' => 1, 'offset' => 0, 'orderby' => 'rand', 'post_type' => SlideshowPluginPostType::$postType, 'suppress_filters' => true)); if (is_array($post)) { $post = $post[0]; } } // Exit on error if ($post === null) { return '<!-- WordPress Slideshow - No slideshows available -->'; } // Log slideshow's issues to be able to track them on the page. $log = array(); // Get views $views = SlideshowPluginSlideshowSettingsHandler::getViews($post->ID); if (!is_array($views) || count($views) <= 0) { $log[] = 'No views were found'; } // Get settings $settings = SlideshowPluginSlideshowSettingsHandler::getSettings($post->ID); $styleSettings = SlideshowPluginSlideshowSettingsHandler::getStyleSettings($post->ID); // Only enqueue the functional stylesheet when the 'allStylesheetsRegistered' flag is false if (!SlideshowPluginSlideshowStylesheet::$allStylesheetsRegistered) { wp_enqueue_style('slideshow-jquery-image-gallery-stylesheet_functional', SlideshowPluginMain::getPluginUrl() . '/style/' . __CLASS__ . '/functional.css', array(), SlideshowPluginMain::$version); } // Check if requested style is available. If not, use the default list($styleName, $styleVersion) = SlideshowPluginSlideshowStylesheet::enqueueStylesheet($styleSettings['style']); // Include output file to store output in $output. $output = ''; ob_start(); include SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/slideshow.php'; $output .= ob_get_clean(); // Enqueue slideshow script wp_enqueue_script('slideshow-jquery-image-gallery-script', SlideshowPluginMain::getPluginUrl() . '/js/min/all.frontend.min.js', array('jquery'), SlideshowPluginMain::$version); // Set dimensionWidth and dimensionHeight if dimensions should be preserved if (isset($settings['preserveSlideshowDimensions']) && $settings['preserveSlideshowDimensions'] == 'true') { $aspectRatio = explode(':', $settings['aspectRatio']); // Width if (isset($aspectRatio[0]) && is_numeric($aspectRatio[0])) { $settings['dimensionWidth'] = $aspectRatio[0]; } else { $settings['dimensionWidth'] = 1; } // Height if (isset($aspectRatio[1]) && is_numeric($aspectRatio[1])) { $settings['dimensionHeight'] = $aspectRatio[1]; } else { $settings['dimensionHeight'] = 1; } } // Include slideshow settings by localizing them wp_localize_script('slideshow-jquery-image-gallery-script', 'SlideshowPluginSettings_' . $post->ID, $settings); // Include the location of the admin-ajax.php file wp_localize_script('slideshow-jquery-image-gallery-script', 'slideshow_jquery_image_gallery_script_adminURL', admin_url()); self::$sessionCounter++; // Return output return $output; }
/** * Build templates for back-end slides. * * Returns when $return is true, prints when $return is false. * * @since 2.2.0 * @param boolean $return (optional, defaults to true) * @return String $backEndTemplates */ static function getBackEndTemplates($return = true) { // Start output buffering if output needs to be returned if ($return) { ob_start(); } include SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . __CLASS__ . DIRECTORY_SEPARATOR . 'backend_templates.php'; // Return output if ($return) { return ob_get_clean(); } return ''; }
/** * Shows settings for particular slideshow * * @since 1.0.0 */ static function settingsMetaBox() { global $post; // Nonce wp_nonce_field(SlideshowPluginSlideshowSettingsHandler::$nonceAction, SlideshowPluginSlideshowSettingsHandler::$nonceName); // Get settings $settings = SlideshowPluginSlideshowSettingsHandler::getSettings($post->ID, true); // Include include SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/settings.php'; }
/** * Returns an array of stylesheets with its keys and respective names. * * When the $separateDefaultFromCustom boolean is set to true, the default stylesheets will be returned separately * from the custom stylesheets as: array('default' => array(), 'custom' => array()) respectively. * * @since 2.1.23 * @param boolean $separateDefaultFromCustom (optional, defaults to false) * @return array $stylesheets */ static function getStylesheets($separateDefaultFromCustom = false) { // Default styles $defaultStyles = array('style-light.css' => __('Light', 'slideshow-plugin'), 'style-dark.css' => __('Dark', 'slideshow-plugin')); // Loop through default stylesheets $stylesheetsFilePath = SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'style' . DIRECTORY_SEPARATOR . 'SlideshowPlugin'; foreach ($defaultStyles as $fileName => $name) { // Check if stylesheet exists on server, don't offer it when it does not exist. if (!file_exists($stylesheetsFilePath . DIRECTORY_SEPARATOR . $fileName)) { unset($defaultStyles[$fileName]); } } // Get custom styles $customStyles = get_option(SlideshowPluginGeneralSettings::$customStyles, array()); // Return if ($separateDefaultFromCustom) { return array('default' => $defaultStyles, 'custom' => $customStyles); } return array_merge($defaultStyles, $customStyles); }
/** * Hooked on the admin's 'media_buttons' hook, outputs the shortcode inserter media button * * @since 2.1.16 */ static function shortcodeInserter() { // Get slideshows $slideshows = new WP_Query(array('post_type' => SlideshowPluginPostType::$postType, 'orderby' => 'post_date', 'posts_per_page' => -1, 'order' => 'DESC')); include SlideshowPluginMain::getPluginPath() . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . __CLASS__ . DIRECTORY_SEPARATOR . 'shortcode-inserter.php'; }