Slideshow - Version 1.2.0

Version Description

  • Slideshows can now be placed in posts as well, using shortcode [slideshow id=SlideshowPostId].
  • Added a widget that can be loaded with an existing slideshow of choice.
  • Tested up to version 3.4
Download this release

Release Info

Developer stefanboonstra
Plugin Icon 128x128 Slideshow
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

classes/Slideshow.php CHANGED
@@ -4,7 +4,7 @@
4
  * Responsible for outputting the slideshow's HTML, CSS and Javascript.
5
  *
6
  * @author: Stefan Boonstra
7
- * @version: 25-5-12
8
  */
9
  class Slideshow {
10
 
@@ -15,11 +15,27 @@ class Slideshow {
15
  private static $htmlfile = 'slideshow.html';
16
 
17
  /**
18
- * Function initialize prints out the required html and enqueues
 
 
 
 
 
 
 
 
 
19
  * the scripts and stylesheets necessary for displaying the slideshow
 
 
 
 
 
 
20
  */
21
- static function initialize($postId = ''){
22
- if(empty($postId) || !is_numeric($postId)){
 
23
  $post = get_posts(array(
24
  'numberposts' => 1,
25
  'orderby' => 'rand',
@@ -31,11 +47,15 @@ class Slideshow {
31
  }else
32
  $post = wp_get_single_post($postId);
33
 
 
34
  if(empty($post))
35
  return;
36
 
 
 
 
37
  // Output basic html
38
- echo file_get_contents(SlideshowMain::getPluginUrl() . '/views/' . __CLASS__ . '/' . self::$htmlfile);
39
 
40
  // Get settings
41
  $settings = SlideshowPostType::$defaults;
@@ -64,7 +84,7 @@ class Slideshow {
64
  }
65
 
66
  // Output settings and images
67
- echo '
68
  <script type="text/javascript">
69
  var slideshow_images = ' . json_encode($images) . ';
70
  var slideshow_settings = ' . json_encode($settings) . ';
@@ -94,5 +114,8 @@ class Slideshow {
94
  'slideshow_style',
95
  SlideshowMain::getPluginUrl() . self::$stylesheet
96
  );
 
 
 
97
  }
98
  }
4
  * Responsible for outputting the slideshow's HTML, CSS and Javascript.
5
  *
6
  * @author: Stefan Boonstra
7
+ * @version: 15-06-12
8
  */
9
  class Slideshow {
10
 
15
  private static $htmlfile = 'slideshow.html';
16
 
17
  /**
18
+ * Function deploy prints out the prepared html
19
+ *
20
+ * @param int $postId
21
+ */
22
+ static function deploy($postId = ''){
23
+ echo self::prepare($postId);
24
+ }
25
+
26
+ /**
27
+ * Function prepare returns the required html and enqueues
28
  * the scripts and stylesheets necessary for displaying the slideshow
29
+ *
30
+ * Passing this function no parameter or passing it a negative one will
31
+ * result in a random pick of slideshow
32
+ *
33
+ * @param int $postId
34
+ * @return String $output
35
  */
36
+ static function prepare($postId = ''){
37
+ // Check if defined which Slideshow to use
38
+ if(empty($postId) || !is_numeric($postId) || $postId < 0){
39
  $post = get_posts(array(
40
  'numberposts' => 1,
41
  'orderby' => 'rand',
47
  }else
48
  $post = wp_get_single_post($postId);
49
 
50
+ // Exit function on error
51
  if(empty($post))
52
  return;
53
 
54
+ // Store output for return
55
+ $output = '';
56
+
57
  // Output basic html
58
+ $output .= file_get_contents(SlideshowMain::getPluginUrl() . '/views/' . __CLASS__ . '/' . self::$htmlfile);
59
 
60
  // Get settings
61
  $settings = SlideshowPostType::$defaults;
84
  }
85
 
86
  // Output settings and images
87
+ $output .= '
88
  <script type="text/javascript">
89
  var slideshow_images = ' . json_encode($images) . ';
90
  var slideshow_settings = ' . json_encode($settings) . ';
114
  'slideshow_style',
115
  SlideshowMain::getPluginUrl() . self::$stylesheet
116
  );
117
+
118
+ // Return output
119
+ return $output;
120
  }
121
  }
classes/SlideshowPostType.php CHANGED
@@ -4,14 +4,14 @@
4
  * slideshows and their individual settings
5
  *
6
  * @author: Stefan Boonstra
7
- * @version: 04-06-12
8
  */
9
  class SlideshowPostType {
10
 
11
  /** Variables */
12
  private static $adminIcon = 'images/adminIcon.png';
13
- public static $postType = 'slideshow';
14
- public static $defaults = array(
15
  'slideSpeed' => 1,
16
  'descriptionSpeed' => 0.3,
17
  'intervalSpeed' => 5,
@@ -97,6 +97,7 @@ class SlideshowPostType {
97
  global $post;
98
 
99
  $snippet = htmlentities(sprintf('<?php do_action(\'slideshow_deploy\', \'%s\'); ?>', $post->ID));
 
100
 
101
  include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/information.php');
102
  }
@@ -107,6 +108,7 @@ class SlideshowPostType {
107
  static function slidesMetaBox(){
108
  global $post;
109
 
 
110
  $attachments = get_posts(array(
111
  'post_type' => 'attachment',
112
  'numberposts' => null,
@@ -114,6 +116,10 @@ class SlideshowPostType {
114
  'post_parent' => $post->ID
115
  ));
116
 
 
 
 
 
117
  include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/slides.php');
118
  }
119
 
4
  * slideshows and their individual settings
5
  *
6
  * @author: Stefan Boonstra
7
+ * @version: 15-06-12
8
  */
9
  class SlideshowPostType {
10
 
11
  /** Variables */
12
  private static $adminIcon = 'images/adminIcon.png';
13
+ static $postType = 'slideshow';
14
+ static $defaults = array(
15
  'slideSpeed' => 1,
16
  'descriptionSpeed' => 0.3,
17
  'intervalSpeed' => 5,
97
  global $post;
98
 
99
  $snippet = htmlentities(sprintf('<?php do_action(\'slideshow_deploy\', \'%s\'); ?>', $post->ID));
100
+ $shortCode = htmlentities(sprintf('[' . SlideshowShortcode::$shortCode . ' id=%s]', $post->ID));
101
 
102
  include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/information.php');
103
  }
108
  static function slidesMetaBox(){
109
  global $post;
110
 
111
+ // Get slideshow attachments
112
  $attachments = get_posts(array(
113
  'post_type' => 'attachment',
114
  'numberposts' => null,
116
  'post_parent' => $post->ID
117
  ));
118
 
119
+ // Set url from which a substitute icon can be fetched
120
+ $noPreviewIcon = SlideshowMain::getPluginUrl() . '/images/no-img2.png';
121
+
122
+ // Include slides preview file
123
  include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/slides.php');
124
  }
125
 
classes/SlideshowShortcode.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class SlideshowShortcode is called on use of shortcode anywhere on the website.
4
+ *
5
+ * @author: Stefan Boonstra
6
+ * @version: 15-06-12
7
+ */
8
+ class SlideshowShortcode {
9
+
10
+ /** Variables */
11
+ static $shortCode = 'slideshow_deploy';
12
+
13
+ /**
14
+ * Function slideshowDeploy uses the prepare method of class Slideshow
15
+ * to deploy the slideshow on location of the [slideshow] shortcode.
16
+ *
17
+ * @param mixed $atts
18
+ * @return String $output
19
+ */
20
+ static function slideshowDeploy($atts){
21
+ $postId = '';
22
+ if(isset($atts['id']))
23
+ $postId = $atts['id'];
24
+
25
+ return Slideshow::prepare($postId);
26
+ }
27
+ }
classes/SlideshowWidget.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class SlideshowWidget allows showing one of your slideshows in your widget area.
4
+ *
5
+ * @author: Stefan Boonstra
6
+ * @version: 15-06-12
7
+ */
8
+ class SlideshowWidget extends WP_Widget {
9
+
10
+ /** Variables */
11
+ static $widgetName = 'Slideshow Widget';
12
+
13
+ /**
14
+ * Initializes the widget
15
+ */
16
+ function SlideshowWidget(){
17
+ // Settings
18
+ $options = array(
19
+ 'classname' => 'SlideshowWidget',
20
+ 'description' => __('Enables you to show your slideshows in the widget area of your website.', 'slideshow-plugin')
21
+ );
22
+
23
+ // Create the widget.
24
+ $this->WP_Widget(
25
+ 'slideshowWidget',
26
+ __('Slideshow Widget', 'slideshow-plugin'),
27
+ $options
28
+ );
29
+ }
30
+
31
+ /**
32
+ * The widget as shown to the user.
33
+ *
34
+ * @param mixed array $args
35
+ * @param mixed array $instance
36
+ */
37
+ function widget($args, $instance){
38
+ // Get slideshowId
39
+ $slideshowId = '';
40
+ if(isset($instance['slideshowId']))
41
+ $slideshowId = $instance['slideshowId'];
42
+ echo $slideshowId;
43
+ // Get title
44
+ $title = self::$widgetName;
45
+ if(isset($instance['title']))
46
+ $title = $instance['title'];
47
+
48
+ // Prepare slideshow for output to website.
49
+ $output = Slideshow::prepare($slideshowId);
50
+
51
+ // Include widget html
52
+ include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/widget.php');
53
+ }
54
+
55
+ /**
56
+ * The form shown on the admins widget page. Here settings can be changed.
57
+ *
58
+ * @param mixed array $instance
59
+ */
60
+ function form($instance){
61
+ // Defaults
62
+ $defaults = array(
63
+ 'title' => __(self::$widgetName, 'slideshow-plugin'),
64
+ 'slideshowId' => -1
65
+ );
66
+
67
+ // Merge database settings with defaults
68
+ $instance = wp_parse_args((array) $instance, $defaults);
69
+
70
+ // Get slideshows
71
+ $slideshows = get_posts(array(
72
+ 'numberposts' => null,
73
+ 'post_type' => SlideshowPostType::$postType
74
+ ));
75
+
76
+ // Include form
77
+ include(SlideshowMain::getPluginPath() . '/views/' . __CLASS__ . '/form.php');
78
+ }
79
+
80
+ /**
81
+ * Updates widget's settings.
82
+ *
83
+ * @param mixed array $newInstance
84
+ * @param mixed array $instance
85
+ */
86
+ function update($newInstance, $instance){
87
+ // Update title
88
+ if(isset($newInstance['title']) && !empty($newInstance['title']))
89
+ $instance['title'] = $newInstance['title'];
90
+
91
+ // Update slideshowId
92
+ if(isset($newInstance['slideshowId']) && !empty($newInstance['slideshowId']))
93
+ $instance['slideshowId'] = $newInstance['slideshowId'];
94
+
95
+ // Save
96
+ return $instance;
97
+ }
98
+
99
+ /**
100
+ * Registers this widget (should be called upon widget_init action hook)
101
+ */
102
+ static function registerWidget(){
103
+ register_widget(__CLASS__);
104
+ }
105
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@
3
  Contributors: stefanboonstra
4
  Tags: slideshow, slider, slide, images, image, photo, gallery, galleries
5
  Requires at least: 3.0
6
- Tested up to: 3.2.2
7
- Stable tag: 1.1.0
8
  License: GPLv2
9
 
10
  Integrate a fancy slideshow in just five steps. - Rainbows. Rainbows everywhere.
@@ -31,34 +31,39 @@ different images and settings for each one of them.
31
 
32
  3. Attach images from the media page to your newly created slideshow.
33
 
34
- 4. Use the code snippet visible in your slideshow admin panel to deploy your slideshow anywhere on your website.
35
 
36
  5. Feel like a sir.
37
 
38
 
39
  == Screenshots ==
40
 
41
- 1. Create a new slideshow. A code snippet of how to call it is already visible.
42
 
43
  2. Attach images to the slideshow for the media menu.
44
 
45
  3. The attached images are now visible in your newly created slideshow.
46
 
47
- 4. Using the code snippet the slideshow shows you, you can enjoy your slides in style.
48
 
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
52
  = 1.1.0 =
53
- * Added jQuery library as Wordpress websites don't seem to load them by default
54
- * Slideshow script now depends on by the plugin enqueued jQuery script
55
 
56
  = 1.0.1 =
57
- * Added documentary comments
58
  * Fixed error with directory paths causing Slideshows post type page to generate warnings.
59
 
60
  = 1.0.0 =
61
- * Initial release
62
 
63
 
64
  == Links ==
3
  Contributors: stefanboonstra
4
  Tags: slideshow, slider, slide, images, image, photo, gallery, galleries
5
  Requires at least: 3.0
6
+ Tested up to: 3.4
7
+ Stable tag: 1.2.0
8
  License: GPLv2
9
 
10
  Integrate a fancy slideshow in just five steps. - Rainbows. Rainbows everywhere.
31
 
32
  3. Attach images from the media page to your newly created slideshow.
33
 
34
+ 4. Use the shortcode or code snippet visible in your slideshow admin panel to deploy your slideshow anywhere on your website.
35
 
36
  5. Feel like a sir.
37
 
38
 
39
  == Screenshots ==
40
 
41
+ 1. Create a new slideshow. A shortcode and a code snippet of how to call it is already visible.
42
 
43
  2. Attach images to the slideshow for the media menu.
44
 
45
  3. The attached images are now visible in your newly created slideshow.
46
 
47
+ 4. Using the shortcode or code snippet the slideshow shows you, you can enjoy your slides in style.
48
 
49
 
50
  == Changelog ==
51
 
52
+ = 1.2.0 =
53
+ * Slideshows can now be placed in posts as well, using shortcode [slideshow id=*SlideshowPostId*].
54
+ * Added a widget that can be loaded with an existing slideshow of choice.
55
+ * Tested up to version 3.4
56
+
57
  = 1.1.0 =
58
+ * Added jQuery library as Wordpress websites don't seem to load them by default.
59
+ * Slideshow script now depends on by the plugin enqueued jQuery script.
60
 
61
  = 1.0.1 =
62
+ * Added documentary comments.
63
  * Fixed error with directory paths causing Slideshows post type page to generate warnings.
64
 
65
  = 1.0.0 =
66
+ * Initial release.
67
 
68
 
69
  == Links ==
slideshow.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Slideshow
4
  Plugin URI: http://stefanboonstra.com
5
  Description: This plugin offers a slideshow that is easily deployable in your website. Images can be assigned through the media page. Options are customizable for every single slideshow on your website.
6
- Version: 1.1.0
7
  Requires at least: 3.0
8
  Author: StefanBoonstra
9
  Author URI: http://stefanboonstra.com
@@ -16,7 +16,7 @@
16
  * base path/url returning method.
17
  *
18
  * @author Stefan Boonstra
19
- * @version 04-06-12
20
  */
21
  class SlideshowMain {
22
 
@@ -31,7 +31,13 @@ class SlideshowMain {
31
  add_action('init', array(__CLASS__, 'translator'));
32
 
33
  // Deploy slide show on do_action('slideshow_deploy'); hook.
34
- add_action('slideshow_deploy', array('Slideshow', 'initialize'));
 
 
 
 
 
 
35
 
36
  // Register slideshow post type
37
  add_action('init', array('SlideshowPostType', 'registerSlideshowPostType'));
3
  Plugin Name: Slideshow
4
  Plugin URI: http://stefanboonstra.com
5
  Description: This plugin offers a slideshow that is easily deployable in your website. Images can be assigned through the media page. Options are customizable for every single slideshow on your website.
6
+ Version: 1.2.0
7
  Requires at least: 3.0
8
  Author: StefanBoonstra
9
  Author URI: http://stefanboonstra.com
16
  * base path/url returning method.
17
  *
18
  * @author Stefan Boonstra
19
+ * @version 15-06-12
20
  */
21
  class SlideshowMain {
22
 
31
  add_action('init', array(__CLASS__, 'translator'));
32
 
33
  // Deploy slide show on do_action('slideshow_deploy'); hook.
34
+ add_action('slideshow_deploy', array('Slideshow', 'deploy'));
35
+
36
+ // Add shortcode
37
+ add_shortcode(SlideshowShortcode::$shortCode, array('SlideshowShortcode', 'slideshowDeploy'));
38
+
39
+ // Register widget
40
+ add_action('widgets_init', array('SlideshowWidget', 'registerWidget'));
41
 
42
  // Register slideshow post type
43
  add_action('init', array('SlideshowPostType', 'registerSlideshowPostType'));
views/SlideshowPostType/information.php CHANGED
@@ -1,3 +1,10 @@
1
  <p>
2
- <? _e(sprintf('To use this slideshow in your website add this piece of code: <i>"%s"</i> to where ever in your theme you want to place the slideshow.', $snippet), 'slideshow-plugin'); ?>
 
 
 
 
 
 
 
3
  </p>
1
  <p>
2
+ <? _e(sprintf(
3
+ '<p>To use this slideshow in your website either add this piece of shortcode to your posts or pages:</p>
4
+ <p><i>%s<i></p>
5
+ <p>Or add this piece of code to where ever in your website you want to place the slideshow.:</p>
6
+ <p><i>%s</i></p>',
7
+ $shortCode,
8
+ $snippet),
9
+ 'slideshow-plugin'); ?>
10
  </p>
views/SlideshowPostType/slides.php CHANGED
@@ -1,38 +1,43 @@
1
- <table class="wp-list-table widefat fixed media" cellspacing="0">
2
- <tbody id="the-list">
3
-
4
- <? foreach($attachments as $attachment): ?>
5
- <? $editUrl = admin_url() . '/media.php?attachment_id=' . $attachment->ID . '&amp;action=edit'; ?>
6
- <? $image = wp_get_attachment_image_src($attachment->ID); ?>
7
- <? if(!$image[3]) continue; ?>
8
-
9
- <tr id="post-<? echo $attachment->ID; ?>" class="alternate author-self status-inherit" valign="top">
10
-
11
- <td class="column-icon media-icon">
12
- <a href="<? echo $editUrl; ?>" title="Edit &#34;<? echo $attachment->post_title; ?>&#34;">
13
- <img
14
- width="80"
15
- height="60"
16
- src="<? echo $image[0]; ?>"
17
- class="attachment-80x60"
18
- alt="<? echo $attachment->post_title; ?>"
19
- title="<? echo $attachment->post_title; ?>"
20
- />
21
- </a>
22
- </td>
23
-
24
- <td class="title column-title">
25
- <strong>
26
- <a href="<? echo $editUrl; ?>" title="Edit &#34;<? echo $attachment->post_title; ?>&#34;"><? echo $attachment->post_title; ?></a>
27
- </strong>
28
-
29
- <p>
30
- <? echo $attachment->post_content; ?>
31
- </p>
32
- </td>
33
- </tr>
34
-
35
- <? endforeach; ?>
36
-
37
- </tbody>
38
- </table>
 
 
 
 
 
1
+ <? if(count($attachments) <= 0):
2
+ _e('Add slides to this slideshow by attaching images to it from the media page.', 'slideshow-plugin'); ?>
3
+
4
+ <? else: ?>
5
+ <table class="wp-list-table widefat fixed media" cellspacing="0">
6
+ <tbody id="the-list">
7
+
8
+ <? foreach($attachments as $attachment):?>
9
+ <? $editUrl = admin_url() . '/media.php?attachment_id=' . $attachment->ID . '&amp;action=edit'; ?>
10
+ <? $image = wp_get_attachment_image_src($attachment->ID); ?>
11
+ <? if(!$image[3]) $image[0] = $noPreviewIcon; ?>
12
+
13
+ <tr id="post-<? echo $attachment->ID; ?>" class="alternate author-self status-inherit" valign="top">
14
+
15
+ <td class="column-icon media-icon">
16
+ <a href="<? echo $editUrl; ?>" title="Edit &#34;<? echo $attachment->post_title; ?>&#34;">
17
+ <img
18
+ width="80"
19
+ height="60"
20
+ src="<? echo $image[0]; ?>"
21
+ class="attachment-80x60"
22
+ alt="<? echo $attachment->post_title; ?>"
23
+ title="<? echo $attachment->post_title; ?>"
24
+ />
25
+ </a>
26
+ </td>
27
+
28
+ <td class="title column-title">
29
+ <strong>
30
+ <a href="<? echo $editUrl; ?>" title="Edit &#34;<? echo $attachment->post_title; ?>&#34;"><? echo $attachment->post_title; ?></a>
31
+ </strong>
32
+
33
+ <p>
34
+ <? echo $attachment->post_content; ?>
35
+ </p>
36
+ </td>
37
+ </tr>
38
+
39
+ <? endforeach; ?>
40
+
41
+ </tbody>
42
+ </table>
43
+ <? endif; ?>
views/SlideshowWidget/form.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p>
2
+ <label for="<? echo $this->get_field_id('title'); ?>"><? _e('Title', 'slideshow-plugin'); ?></label>
3
+ <input class="widefat" id="<? echo $this->get_field_id('title'); ?>" name="<? echo $this->get_field_name('title'); ?>" value="<? echo $instance['title']; ?>" style="width:100%" />
4
+ </p>
5
+
6
+ <p>
7
+ <label for="<? echo $this->get_field_id('slideshowId'); ?>"><? _e('Slideshow', 'slideshow-plugin'); ?></label>
8
+ <select class="widefat" id="<? echo $this->get_field_id('slideshowId'); ?>" name="<? echo $this->get_field_name('slideshowId'); ?>" value="<? echo $instance['slideshowId']; ?>" style="width:100%">
9
+ <option value="-1" <? selected($instance['slideshowId'], -1); ?>><? _e('Random Slideshow', 'slideshow-plugin'); ?></option>
10
+ <? foreach($slideshows as $slideshow): ?>
11
+ <option value="<? echo $slideshow->ID ?>" <? selected($instance['slideshowId'], $slideshow->ID); ?>><? echo $slideshow->post_title ?></option>
12
+ <? endforeach; ?>
13
+ </select>
14
+ </p>
views/SlideshowWidget/widget.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <h3 class="widget-title"><? echo $title; ?></h3>
2
+ <? echo $output; ?>