diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/slideshow-jquery-image-gallery/classes/SlideshowPluginSlideInserter.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/slideshow-jquery-image-gallery/classes/SlideshowPluginSlideInserter.php Mon Nov 19 18:26:13 2012 +0100 @@ -0,0 +1,225 @@ + 0){ + foreach($settings as $key => $setting) + if(strtolower(substr($key, 0, strlen($search))) == strtolower($search)) + unset($settings[$key]); + } + update_post_meta($_POST['postId'], 'settings', $settings); + + die; + } + + /** + * This function is registered in the SlideshowPluginAjax class + * and prints the results from the search query + */ + static function printSearchResults(){ + // Numberposts and offset + $numberPosts = 10; + $offset = 0; + if(isset($_POST['offset'])) + $offset = $_POST['offset']; + + // Get attachments with a title alike the search string, needs to be filtered + add_filter('posts_where', array(__CLASS__, 'printSearchResultsWhereFilter')); + $attachments = get_posts(array( + 'numberposts' => $numberPosts + 1, + 'offset' => $offset, + 'orderby' => 'post_date', + 'order' => 'DESC', + 'post_type' => 'attachment', + 'suppress_filters' => false + )); + remove_filter('posts_where', array(__CLASS__, 'printSearchResultsWhereFilter')); + + // 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){ + foreach($attachments as $attachment){ + $image = wp_get_attachment_image_src($attachment->ID); + if(!$image[3]) $image[0] = SlideshowPluginMain::getPluginUrl() . '/images/SlideshowPluginPostType/no-img.png'; + echo ' + + ' . $attachment->post_title . ' + + + + ' . $attachment->post_title . ' + +

' . $attachment->post_content . '

+ + + + + '; + } + if($loadMoreResults){ + echo ' + + + + '; + } + } else { + echo ' + + + ' . __('No images were found, click here to upload some.', 'slideshow-plugin') . ' + + + '; + } + + die; + } + + /** + * Applies a where clause on the get_posts call from self::printSearchResults() + * + * @param string $where + * @return string $where + */ + static function printSearchResultsWhereFilter($where){ + global $wpdb; + + if(isset($_POST['search'])) + $where .= $wpdb->prepare( + " AND (post_title LIKE '%%%s%%' OR ID LIKE '%%%s%%') ", + $_POST['search'], + $_POST['search'] + ); + + return $where; + } + + /** + * Include popup, needs to be called in the footer + */ + static function includePopup(){ + include(SlideshowPluginMain::getPluginPath() . '/views/' . __CLASS__ . '/search-popup.php'); + } + + /** + * Enqueues styles and scripts necessary for the media upload button. + */ + static function enqueueFiles(){ + // Check if already enqueued + if(self::$enqueuedFiles) + return; + + // Enqueue style + wp_enqueue_style( + 'slideshow-slide-inserter', + SlideshowPluginMain::getPluginUrl() . '/style/' . __CLASS__ . '/slide-inserter.css' + ); + + // Enqueue insert button script + wp_enqueue_script( + 'slideshow-slide-inserter', + SlideshowPluginMain::getPluginUrl() . '/js/' . __CLASS__ . '/slide-inserter.js', + array('jquery') + ); + + 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; + } +} \ No newline at end of file