/** * 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; }
/** * Enqueues scripts for when the admin page is a slideshow edit page. * * @since 2.1.11 */ static function enqueueAdminScripts() { // Return if function doesn't exist if (!function_exists('get_current_screen')) { return; } // Return when not on a slideshow edit page. $currentScreen = get_current_screen(); if ($currentScreen->post_type != self::$postType) { return; } // Enqueue associating script wp_enqueue_script('post-type-handler', SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/post-type-handler.js', array('jquery'), SlideshowPluginMain::$version); // TODO: These scripts have been moved here from the footer. They need to be always printed in the header // TODO: a solution for this needs to be found. // Enqueue scripts required for sorting the slides list wp_enqueue_script('jquery-ui-sortable'); // Enqueue JSColor wp_enqueue_script('jscolor-colorpicker', SlideshowPluginMain::getPluginUrl() . '/js/SlideshowPluginPostType/jscolor/jscolor.js', null, SlideshowPluginMain::$version); // Enqueue slide insert script and style SlideshowPluginSlideInserter::enqueueFiles(); }
<a href="#TB_inline?width=450&inlineId=insertSlideshowShortcode" class="button thickbox" title="<?php _e('Insert a Slideshow', 'slideshow-jquery-image-gallery'); ?> " style="padding-left: .4em;" > <img src="<?php echo SlideshowPluginMain::getPluginUrl() . '/images/SlideshowPluginPostType/adminIcon.png'; ?> " alt="<?php _e('Insert a Slideshow', 'slideshow-jquery-image-gallery'); ?> " style="vertical-align: text-top;" /> <?php _e('Insert Slideshow', 'slideshow-jquery-image-gallery'); ?> </a> <div id="insertSlideshowShortcode" style="display: none;"> <h3 style="padding: 10px 0; color: #5a5a5a;"> <?php _e('Insert a Slideshow', 'slideshow-jquery-image-gallery'); ?>
/** * 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; }
/** * Registers new post type slideshow * * @since 1.0.0 */ static function registerSlideshowPostType() { global $wp_version; register_post_type(self::$postType, array('labels' => array('name' => __('Slideshows', 'slideshow-jquery-image-gallery'), 'singular_name' => __('Slideshow', 'slideshow-jquery-image-gallery'), 'add_new_item' => __('Add New Slideshow', 'slideshow-jquery-image-gallery'), 'edit_item' => __('Edit slideshow', 'slideshow-jquery-image-gallery'), 'new_item' => __('New slideshow', 'slideshow-jquery-image-gallery'), 'view_item' => __('View slideshow', 'slideshow-jquery-image-gallery'), 'search_items' => __('Search slideshows', 'slideshow-jquery-image-gallery'), 'not_found' => __('No slideshows found', 'slideshow-jquery-image-gallery'), 'not_found_in_trash' => __('No slideshows found', 'slideshow-jquery-image-gallery')), 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'capabilities' => array('edit_post' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows'], 'read_post' => SlideshowPluginGeneralSettings::$capabilities['addSlideshows'], 'delete_post' => SlideshowPluginGeneralSettings::$capabilities['deleteSlideshows'], 'edit_posts' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows'], 'edit_others_posts' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows'], 'publish_posts' => SlideshowPluginGeneralSettings::$capabilities['addSlideshows'], 'read_private_posts' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows'], 'read' => SlideshowPluginGeneralSettings::$capabilities['addSlideshows'], 'delete_posts' => SlideshowPluginGeneralSettings::$capabilities['deleteSlideshows'], 'delete_private_posts' => SlideshowPluginGeneralSettings::$capabilities['deleteSlideshows'], 'delete_published_posts' => SlideshowPluginGeneralSettings::$capabilities['deleteSlideshows'], 'delete_others_posts' => SlideshowPluginGeneralSettings::$capabilities['deleteSlideshows'], 'edit_private_posts' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows'], 'edit_published_posts' => SlideshowPluginGeneralSettings::$capabilities['editSlideshows']), 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => version_compare($wp_version, '3.8', '<') ? SlideshowPluginMain::getPluginUrl() . '/images/' . __CLASS__ . '/adminIcon.png' : 'dashicons-format-gallery', 'supports' => array('title'), 'register_meta_box_cb' => array(__CLASS__, 'registerMetaBoxes'))); }
/** * 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; }
/** * Enqueues styles and scripts necessary for the media upload button. * * @since 2.0.0 */ static function enqueueFiles() { // Return if function doesn't exist if (!function_exists('get_current_screen')) { return; } // Return when not on a slideshow edit page, or files have already been included. $currentScreen = get_current_screen(); if ($currentScreen->post_type != SlideshowPluginPostType::$postType || self::$enqueuedFiles) { return; } // Enqueue style wp_enqueue_style('slideshow-slide-inserter', SlideshowPluginMain::getPluginUrl() . '/style/' . __CLASS__ . '/slide-inserter.css', null, SlideshowPluginMain::$version); // Enqueue insert button script wp_enqueue_script('slideshow-slide-inserter', SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/slide-inserter.js', array('jquery'), SlideshowPluginMain::$version); wp_localize_script('slideshow-slide-inserter', 'SlideInserterTranslations', array('confirmMessage' => __('Are you sure you want to delete this slide?', 'slideshow-plugin'))); // Set enqueued to true self::$enqueuedFiles = true; }
/** * 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; }
/** * This function is registered in the SlideshowPluginAjax class * and prints the results from the search query. * * @since 2.0.0 */ static function printSearchResults() { global $wpdb; // Numberposts and offset $numberPosts = 10; $offset = 0; if (isset($_POST['offset']) && is_numeric($_POST['offset'])) { $offset = $_POST['offset']; } $attachmentIDs = array(); if (isset($_POST['attachmentIDs'])) { $attachmentIDs = array_filter($_POST['attachmentIDs'], 'ctype_digit'); } // Get attachments with a title alike the search string, needs to be filtered add_filter('posts_where', array(__CLASS__, 'printSearchResultsWhereFilter')); $query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'offset' => $offset, 'posts_per_page' => $numberPosts + 1, 'orderby' => 'date', 'order' => 'DESC')); $attachments = $query->get_posts(); remove_filter('posts_where', array(__CLASS__, 'printSearchResultsWhereFilter')); // Look for images by their file's name when not enough matching results were found if (count($attachments) < $numberPosts) { $searchString = esc_sql($_POST['search']); // Add results found with the previous query to the $attachmentIDs array to exclude them as well foreach ($attachments as $attachment) { $attachmentIDs[] = $attachment->ID; } // Search by file name $fileNameQuery = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => $numberPosts - count($attachments), 'post__not_in' => $attachmentIDs, 'meta_query' => array(array('key' => '_wp_attached_file', 'value' => $searchString, 'compare' => 'LIKE')))); // Put found results in attachments array $fileNameQueryAttachments = $fileNameQuery->get_posts(); if (is_array($fileNameQueryAttachments) && count($fileNameQueryAttachments) > 0) { foreach ($fileNameQueryAttachments as $fileNameQueryAttachment) { $attachments[] = $fileNameQueryAttachment; } } } // Check if there are enough attachments to print a 'Load more images' button $loadMoreResults = false; if (count($attachments) > $numberPosts) { array_pop($attachments); $loadMoreResults = true; } // Print results to the screen if (count($attachments) > 0) { if ($offset > 0) { echo '<tr valign="top"> <td colspan="3" style="text-align: center;"> <b>' . count($attachments) . ' ' . __('More results loaded', 'slideshow-plugin') . '<b> </td> </tr>'; } foreach ($attachments as $attachment) { $image = wp_get_attachment_image_src($attachment->ID); if (!is_array($image) || !$image) { if (!empty($attachment->guid)) { $imageSrc = $attachment->guid; } else { continue; } } else { $imageSrc = $image[0]; } if (!$imageSrc || empty($imageSrc)) { $imageSrc = SlideshowPluginMain::getPluginUrl() . '/images/SlideshowPluginPostType/no-img.png'; } echo '<tr valign="top" data-attachment-Id="' . $attachment->ID . '" class="result-table-row"> <td class="image"> <img width="60" height="60" src="' . $imageSrc . '" class="attachment" alt="' . $attachment->post_title . '" title="' . $attachment->post_title . '"> </td> <td class="column-title"> <strong class="title">' . $attachment->post_title . '</strong> <p class="description">' . $attachment->post_content . '</p> </td> <td class="insert-button"> <input type="button" class="insert-attachment button-secondary" value="' . __('Insert', 'slideshow-plugin') . '" /> </td> </tr>'; } if ($loadMoreResults) { echo '<tr> <td colspan="3" style="text-align: center;"> <button class="button-secondary load-more-results" data-offset="' . ($offset + $numberPosts) . '"> ' . __('Load more results', 'slideshow-plugin') . ' </button> </td> </tr>'; } } else { echo '<tr> <td colspan="3" style="text-align: center;"> <a href="' . admin_url() . 'media-new.php" target="_blank"> ' . __('No images were found, click here to upload some.', 'slideshow-plugin') . ' </a> </td> </tr>'; } die; }
} // Prepare image $image = wp_get_attachment_image_src($attachment->ID); $imageSrc = ''; $displaySlide = true; if (!is_array($image) || !$image) { if (!empty($attachment->guid)) { $imageSrc = $attachment->guid; } else { $displaySlide = false; } } else { $imageSrc = $image[0]; } if (!$imageSrc || empty($imageSrc)) { $imageSrc = SlideshowPluginMain::getPluginUrl() . '/images/' . __CLASS__ . '/no-img.png'; } $editUrl = admin_url() . '/media.php?attachment_id=' . $attachment->ID . '&action=edit'; if ($displaySlide) { ?> <li class="widefat sortable-slides-list-item"> <h3 class="hndle"> <span> <?php _e('Image slide', 'slideshow-plugin'); ?> </span>
/** * Enqueue scripts and stylesheets. Needs to be called on the 'admin_enqueue_scripts' hook. * * @since 2.1.22 */ static function enqueue() { // Return if function doesn't exist if (!function_exists('get_current_screen')) { return; } // Return when not on a slideshow edit page, or files have already been included. $currentScreen = get_current_screen(); if ($currentScreen->post_type != SlideshowPluginPostType::$postType) { return; } // Enqueue general settings stylesheet wp_enqueue_style('slideshow-jquery-image-gallery-general-settings', SlideshowPluginMain::getPluginUrl() . '/style/' . __CLASS__ . '/general-settings.css', array(), SlideshowPluginMain::$version); // Enqueue general settings script wp_enqueue_script('slideshow-jquery-image-gallery-general-settings', SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/general-settings.js', array('jquery'), SlideshowPluginMain::$version); // Localize general settings script wp_localize_script('slideshow-jquery-image-gallery-general-settings', 'GeneralSettingsVariables', array('customStylesKey' => self::$customStyles, 'newCustomizationPrefix' => __('New', 'slideshow-plugin'), 'confirmDeleteMessage' => __('Are you sure you want to delete this custom style?', 'slideshow-plugin'))); }
/** * Enqueues the shortcode inserter script * * @since 2.1.16 */ static function shortcodeInserterScript() { wp_enqueue_script('slideshow-shortcode-inserter', SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/shortcode-inserter.js', array('jquery'), SlideshowPluginMain::$version); wp_localize_script('slideshow-shortcode-inserter', 'SlideshowShortcodeInserter', array('undefinedSlideshowMessage' => __('No slideshow selected.', 'slideshow-plugin'), 'shortcode' => SlideshowPluginShortcode::$shortCode)); }