PluginProbe
Slideshow SE / 2.5
Slideshow SE v2.5
2.7.2 2.7.1 trunk 2.5 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.18 2.5.19 2.5.2 2.5.20 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 All 26 releases
slideshow-se / classes / SlideshowSEPluginShortcode.php

SlideshowSEPluginShortcode.php in Slideshow SE 2.5, at classes/SlideshowSEPluginShortcode.php

151 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class SlideshowSEPluginShortcode provides the shortcode function, which is called
4 * on use of shortcode anywhere in the posts and pages. Also provides the shortcode
5 * inserter, so that it's made easier for non-programmers to insert the shortcode
6 * into a post or page.
7 *
8 * @since 1.2.0
9 * @author: Stefan Boonstra
10 */
11 class SlideshowSEPluginShortcode
12 {
13 /** @var string $shortCode */
14 public static $shortCode = 'slideshow_deploy';
15
16 /** @var string $bookmark */
17 public static $bookmark = '!slideshow_deploy!';
18
19 /** @var array $postIDs */
20 private static $postIds = array();
21
22 /**
23 * Initializes the shortcode, registering it and hooking the shortcode
24 * inserter media buttons.
25 *
26 * @since 2.1.16
27 */
28 static function init()
29 {
30 // Register shortcode
31 add_shortcode(self::$shortCode, array(__CLASS__, 'slideshowDeploy'));
32
33 // Admin
34 if (is_admin())
35 {
36 // Add shortcode inserter HTML
37 add_action('media_buttons', array(__CLASS__, 'shortcodeInserter'), 11);
38
39 // Enqueue shortcode inserter script
40 add_action('admin_enqueue_scripts', array(__CLASS__, 'localizeScript'), 11);
41 }
42 }
43
44 /**
45 * Function slideshowDeploy adds a bookmark to where ever a shortcode
46 * is found and adds the postId to an array, it then is loaded after
47 * WordPress has done its HTML checks.
48 *
49 * @since 1.2.0
50 * @param mixed $attributes
51 * @return String $output
52 */
53 static function slideshowDeploy($attributes)
54 {
55 $postId = '';
56
57 if (isset($attributes['id']))
58 {
59 $postId = $attributes['id'];
60 }
61
62 $settings = SlideshowSEPluginSlideshowSettingsHandler::getSettings($postId);
63
64 if ($settings['avoidFilter'] == 'true' &&
65 strlen(current_filter()) > 0)
66 {
67 // Avoid current filter, call function to replace the bookmark with the slideshow
68 add_filter(current_filter(), array(__CLASS__, 'insertSlideshow'), 999);
69
70 // Save post id
71 self::$postIds[] = $postId;
72
73 // Set output
74 $output = self::$bookmark;
75 }
76 else
77 {
78 // Just output the slideshow, without filtering
79 $output = SlideshowSEPlugin::prepare($postId);
80 }
81
82 // Return output
83 return $output;
84 }
85
86 /**
87 * Function insertSlideshow uses the prepare method of class SlideshowSEPlugin
88 * to insert the code for the slideshow on the location a bookmark was found.
89 *
90 * @since 2.1.8
91 * @param String $content
92 * @return String $content
93 */
94 static function insertSlideshow($content)
95 {
96 // Loop through post ids
97 if (is_array(self::$postIds) &&
98 count(self::$postIds) > 0)
99 {
100 foreach (self::$postIds as $postId)
101 {
102 $updatedContent = preg_replace("/" . self::$bookmark . "/", SlideshowSEPlugin::prepare($postId), $content, 1);
103
104 if (is_string($updatedContent))
105 {
106 $content = $updatedContent;
107 }
108 }
109 }
110
111 // Reset postIds, so a shortcode in a next post can be used
112 self::$postIds = array();
113
114 return $content;
115 }
116
117 /**
118 * Hooked on the admin's 'media_buttons' hook, outputs the shortcode inserter media button
119 *
120 * @since 2.1.16
121 */
122 static function shortcodeInserter()
123 {
124 $data = new stdClass();
125 $data->slideshows = new WP_Query(array(
126 'post_type' => SlideshowSEPluginPostType::$postType,
127 'orderby' => 'post_date',
128 'posts_per_page' => -1,
129 'order' => 'DESC'
130 ));
131
132 SlideshowSEPluginMain::outputView(__CLASS__ . DIRECTORY_SEPARATOR . 'shortcode-inserter.php', $data);
133 }
134
135 /**
136 * Enqueues the shortcode inserter script
137 *
138 * @since 2.1.16
139 */
140 static function localizeScript()
141 {
142 wp_localize_script(
143 'slideshow-jquery-image-gallery-backend-script',
144 'slideshow_jquery_image_gallery_backend_script_shortcode',
145 array(
146 'data' => array('shortcode' => SlideshowSEPluginShortcode::$shortCode),
147 'localization' => array('undefinedSlideshow' => __('No slideshow selected.', 'slideshow-se'))
148 )
149 );
150 }
151 }