Cyclone Slider - Version 2.9.5

Version Description

  • 2015-01-03 =
  • Fix. Thumbnail template thumb images now working.
  • New. Added support for custom image sizes.
  • Change. Removed cyclone_slide_image_url function from Thumbnail template and used $slide['image_thumbnails']['40_40_crop'] instead.
  • Change. Refactored Data and ImageResizer class.
  • Fix. Wrong class name Image_Resizer changed to CycloneSlider_ImageResizer.
Download this release

Release Info

Developer kosinix
Plugin Icon 128x128 Cyclone Slider
Version 2.9.5
Comparing to
See all releases

Code changes from version 2.9.4 to 2.9.5

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.codefleet.net/donate/
4
  Tags: slider, slideshow, drag-and-drop, wordpress-slider, wordpress-slideshow, cycle 2, jquery, responsive, translation-ready, custom-post, cyclone-slider
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
- Stable tag: 2.9.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -103,6 +103,13 @@ Inside `wp-content` create a folder named "cycloneslider". Add your templates in
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
106
  = 2.9.4 - 2015-01-02 =
107
  * Fix. Improved safety checks for POST data when saving sliders.
108
  * Fix. Deleting a single slide now works. This was a regression bug due to previous POST data safety check code.
@@ -344,6 +351,13 @@ Inside `wp-content` create a folder named "cycloneslider". Add your templates in
344
 
345
  == Upgrade Notice ==
346
 
 
 
 
 
 
 
 
347
  = 2.9.4 - 2015-01-02 =
348
  * Fix. Improved safety checks for POST data when saving sliders.
349
  * Fix. Deleting a single slide now works. This was a regression bug due to previous POST data safety check code.
4
  Tags: slider, slideshow, drag-and-drop, wordpress-slider, wordpress-slideshow, cycle 2, jquery, responsive, translation-ready, custom-post, cyclone-slider
5
  Requires at least: 3.5
6
  Tested up to: 4.1
7
+ Stable tag: 2.9.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 2.9.5 - 2015-01-03 =
107
+ * Fix. Thumbnail template thumb images now working.
108
+ * New. Added support for custom image sizes.
109
+ * Change. Removed cyclone_slide_image_url function from Thumbnail template and used $slide['image_thumbnails']['40_40_crop'] instead.
110
+ * Change. Refactored Data and ImageResizer class.
111
+ * Fix. Wrong class name Image_Resizer changed to CycloneSlider_ImageResizer.
112
+
113
  = 2.9.4 - 2015-01-02 =
114
  * Fix. Improved safety checks for POST data when saving sliders.
115
  * Fix. Deleting a single slide now works. This was a regression bug due to previous POST data safety check code.
351
 
352
  == Upgrade Notice ==
353
 
354
+ = 2.9.5 - 2015-01-03 =
355
+ * Fix. Thumbnail template thumb images now working.
356
+ * New. Added support for custom image sizes.
357
+ * Change. Removed cyclone_slide_image_url function from Thumbnail template and used $slide['image_thumbnails']['40_40_crop'] instead.
358
+ * Change. Refactored Data and ImageResizer class.
359
+ * Fix. Wrong class name Image_Resizer changed to CycloneSlider_ImageResizer.
360
+
361
  = 2.9.4 - 2015-01-02 =
362
  * Fix. Improved safety checks for POST data when saving sliders.
363
  * Fix. Deleting a single slide now works. This was a regression bug due to previous POST data safety check code.
cyclone-slider.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Cyclone Slider 2
4
  Plugin URI: http://www.codefleet.net/cyclone-slider-2/
5
  Description: Create and manage sliders with ease. Built for both casual users and developers.
6
- Version: 2.9.4
7
  Author: Nico Amarilla
8
  Author URI: http://www.codefleet.net/
9
  License:
@@ -49,7 +49,7 @@ function cycloneslider_init() {
49
  $plugin['url'] = plugin_dir_url(__FILE__);
50
 
51
  $plugin['debug'] = false;
52
- $plugin['version'] = '2.9.4';
53
  $plugin['textdomain'] = 'cycloneslider';
54
  $plugin['slug'] = 'cyclone-slider-2/cyclone-slider.php';
55
  $plugin['nonce_name'] = 'cyclone_slider_builder_nonce';
@@ -62,7 +62,15 @@ function cycloneslider_init() {
62
 
63
  $plugin['image_resizer'] = new CycloneSlider_ImageResizer();
64
  $plugin['image_editor'] = 'CycloneSlider_ImageEditor';
65
-
 
 
 
 
 
 
 
 
66
  $plugin['data'] = new CycloneSlider_Data();
67
 
68
  $plugin['nextgen_integration'] = new CycloneSlider_NextgenIntegration();
3
  Plugin Name: Cyclone Slider 2
4
  Plugin URI: http://www.codefleet.net/cyclone-slider-2/
5
  Description: Create and manage sliders with ease. Built for both casual users and developers.
6
+ Version: 2.9.5
7
  Author: Nico Amarilla
8
  Author URI: http://www.codefleet.net/
9
  License:
49
  $plugin['url'] = plugin_dir_url(__FILE__);
50
 
51
  $plugin['debug'] = false;
52
+ $plugin['version'] = '2.9.5';
53
  $plugin['textdomain'] = 'cycloneslider';
54
  $plugin['slug'] = 'cyclone-slider-2/cyclone-slider.php';
55
  $plugin['nonce_name'] = 'cyclone_slider_builder_nonce';
62
 
63
  $plugin['image_resizer'] = new CycloneSlider_ImageResizer();
64
  $plugin['image_editor'] = 'CycloneSlider_ImageEditor';
65
+ $plugin['image_sizes'] = array(
66
+ '40_40_crop' => array( // Used by thumbnail template
67
+ 'width' => 40,
68
+ 'height' => 40,
69
+ 'resize_option' => 'crop'
70
+ )
71
+ );
72
+ $plugin['image_sizes'] = apply_filters('cycloneslider_image_sizes', $plugin['image_sizes']);
73
+
74
  $plugin['data'] = new CycloneSlider_Data();
75
 
76
  $plugin['nextgen_integration'] = new CycloneSlider_NextgenIntegration();
src/CycloneSlider/Data.php CHANGED
@@ -44,20 +44,18 @@ class CycloneSlider_Data {
44
  return $post_id;
45
  }
46
 
47
- // Resize images if needed
48
- if(isset($_POST['cycloneslider_settings']) and isset($_POST['cycloneslider_metas'])){
49
- if($_POST['cycloneslider_settings']['resize'] == 1){
50
- $this->plugin['image_resizer']->resize_images( $_POST['cycloneslider_settings'], $_POST['cycloneslider_metas'] );
51
- }
52
- }
53
 
54
  // Save slides
55
- $slides = isset($_POST['cycloneslider_metas']) ? $_POST['cycloneslider_metas'] : array();
56
  $this->add_slider_slides( $post_id, $slides );
57
 
58
  // Save slider settings
59
- $slider_settings = isset($_POST['cycloneslider_settings']) ? $_POST['cycloneslider_settings'] : array();
60
- $this->add_slider_settings( $post_id, $_POST['cycloneslider_settings']);
61
 
62
  // Marked as done
63
  $cyclone_slider_saved_done = true;
@@ -334,7 +332,7 @@ class CycloneSlider_Data {
334
  }
335
 
336
  /**
337
- * Get Slide Image URL
338
  */
339
  public function get_slide_image_url( $slide_image_id, $slider_settings ){
340
  $width = $slider_settings['width'];
@@ -371,6 +369,42 @@ class CycloneSlider_Data {
371
  return $thumb_url;
372
  }
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  /**
375
  * Get View File
376
  *
44
  return $post_id;
45
  }
46
 
47
+ // Assign POST data with array key checks
48
+ $slides = isset($_POST['cycloneslider_metas']) ? $_POST['cycloneslider_metas'] : array();
49
+ $slider_settings = isset($_POST['cycloneslider_settings']) ? $_POST['cycloneslider_settings'] : array();
50
+
51
+ // Resize images
52
+ $this->plugin['image_resizer']->resize_images( $slider_settings, $slides );
53
 
54
  // Save slides
 
55
  $this->add_slider_slides( $post_id, $slides );
56
 
57
  // Save slider settings
58
+ $this->add_slider_settings( $post_id, $slider_settings);
 
59
 
60
  // Marked as done
61
  $cyclone_slider_saved_done = true;
332
  }
333
 
334
  /**
335
+ * Get Slide Image URL.
336
  */
337
  public function get_slide_image_url( $slide_image_id, $slider_settings ){
338
  $width = $slider_settings['width'];
369
  return $thumb_url;
370
  }
371
 
372
+ /**
373
+ * Get Slide Thumbnail URL.
374
+ */
375
+ public function get_slide_thumbnail_url( $slide_image_id, $width, $height, $resize){
376
+
377
+ // Get url to full image, its width and height
378
+ $image_dimensions = wp_get_attachment_image_src($slide_image_id, 'full');
379
+ if(!$image_dimensions){
380
+ return false;
381
+ }
382
+
383
+ // Assign variables
384
+ list($image_url, $orig_width, $orig_height) = $image_dimensions;
385
+
386
+ // If orig image width and height is the same as slideshow width and height, do not resize and return url
387
+ if($orig_width == $width and $orig_height == $height){
388
+ return $image_url;
389
+ }
390
+
391
+ //If resize is no, return url
392
+ if( true == $resize ){
393
+ return $image_url;
394
+ }
395
+
396
+ // Get full path to the slide image
397
+ $image_file = get_attached_file($slide_image_id);
398
+ if(empty($image_file)){
399
+ return false;
400
+ }
401
+
402
+ $thumb_name = $this->get_thumb_name( $image_file, $width, $height );
403
+ $thumb_url = dirname($image_url).'/'.$thumb_name; // URL to thumbnail
404
+
405
+ return $thumb_url;
406
+ }
407
+
408
  /**
409
  * Get View File
410
  *
src/CycloneSlider/Frontend.php CHANGED
@@ -97,6 +97,11 @@ class CycloneSlider_Frontend extends CycloneSlider_Base {
97
  $slides[$i]['full_image_url'] = $full_image_url;
98
  $slides[$i]['image_url'] = $this->plugin['data']->get_slide_image_url( $slide['id'], $slider_settings );
99
 
 
 
 
 
 
100
  $image_count++;
101
  } else if($slides[$i]['type']=='video'){
102
  $video_count++;
97
  $slides[$i]['full_image_url'] = $full_image_url;
98
  $slides[$i]['image_url'] = $this->plugin['data']->get_slide_image_url( $slide['id'], $slider_settings );
99
 
100
+ $slides[$i]['image_thumbnails'] = array();
101
+ foreach($this->plugin['image_sizes'] as $key=>$size){
102
+ $slides[$i]['image_thumbnails'][$key] = $this->plugin['data']->get_slide_thumbnail_url( $slide['id'], $slider_settings['width'], $slider_settings['height'], $slider_settings['resize'] );
103
+ }
104
+
105
  $image_count++;
106
  } else if($slides[$i]['type']=='video'){
107
  $video_count++;
src/CycloneSlider/ImageResizer.php CHANGED
@@ -27,6 +27,7 @@ class CycloneSlider_ImageResizer extends CycloneSlider_Base {
27
  if( is_array($slides) ){
28
 
29
  foreach($slides as $slide){
 
30
  // Get full path to the slide image
31
  $image_file = get_attached_file( $slide['id'] );
32
 
@@ -40,28 +41,50 @@ class CycloneSlider_ImageResizer extends CycloneSlider_Base {
40
  // Save image to this file
41
  $image_file_dest = "{$dirname}/{$thumb_name}";
42
 
43
- if( ! is_file( $image_file_dest ) ) { // Destination file does not exist
44
- $this->resize( $image_file, $image_file_dest, $width, $height, $slider_settings );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- } else if( is_file( $image_file_dest ) and $slider_settings['force_resize'] ) { // Exist but force resize so we resave it
47
- $this->resize( $image_file, $image_file_dest, $width, $height, $slider_settings );
48
 
 
 
 
 
 
49
  }
50
  }
51
  }
52
  }
53
 
54
  /**
55
- * Resize Image
56
  *
57
- * @param string $image_file
58
- * @param string $image_file_dest
59
- * @param int $width
60
- * @param int $height
61
- * @param array $slider_settings
 
62
  * @return boolean True or false
63
  */
64
- private function resize($image_file, $image_file_dest, $width, $height, $slider_settings){
65
  // Create
66
  $image = new $this->plugin['image_editor']( $image_file );
67
 
@@ -69,8 +92,8 @@ class CycloneSlider_ImageResizer extends CycloneSlider_Base {
69
  if( $image->load() ){
70
 
71
  // Do resize
72
- $image->resize( $width, $height, $slider_settings['resize_option'] );
73
- $image->save( $image_file_dest, $slider_settings['resize_quality']);
74
 
75
  return true;
76
  }
27
  if( is_array($slides) ){
28
 
29
  foreach($slides as $slide){
30
+
31
  // Get full path to the slide image
32
  $image_file = get_attached_file( $slide['id'] );
33
 
41
  // Save image to this file
42
  $image_file_dest = "{$dirname}/{$thumb_name}";
43
 
44
+ // Main slide image
45
+ if( isset($slider_settings['resize']) ){
46
+ if( 1 == $slider_settings['resize'] ){
47
+
48
+ // Resize if destination file does not exist OR if it exists but force resize is set to true
49
+ if( ( false === is_file($image_file_dest) ) or ( is_file($image_file_dest) and $slider_settings['force_resize'] ) ){
50
+
51
+ $this->resize_slide_image( $image_file, $image_file_dest, $width, $height, $slider_settings['resize_option'], $slider_settings['resize_quality'] );
52
+
53
+ }
54
+ }
55
+ }
56
+
57
+ // Additional slide images. Used mainly by templates. Eg. Thumbnail template's thumbnails
58
+ foreach($this->plugin['image_sizes'] as $size){
59
+
60
+ // Create thumb filename-{width}x{height}.jpg
61
+ $thumb_name = $this->generate_thumb_name( $image_file, $size['width'], $size['height'] );
62
 
63
+ // Save image to this file
64
+ $image_file_dest = "{$dirname}/{$thumb_name}";
65
 
66
+ if( ( false === is_file($image_file_dest) ) or ( is_file($image_file_dest) and $slider_settings['force_resize'] ) ){
67
+
68
+ $this->resize_slide_image( $image_file, $image_file_dest, $size['width'], $size['height'], $size['resize_option'], $slider_settings['resize_quality'] );
69
+
70
+ }
71
  }
72
  }
73
  }
74
  }
75
 
76
  /**
77
+ * Resize Slide Image
78
  *
79
+ * @param string $image_file Full path to image file
80
+ * @param string $image_file_dest Full path to destination image
81
+ * @param int $width Image width in pixels
82
+ * @param int $height Image height in pixels
83
+ * @param string $resize_option
84
+ * @param int $resize_quality Quality of image. 0-100 where 0 is worst and 100 is best
85
  * @return boolean True or false
86
  */
87
+ private function resize_slide_image( $image_file, $image_file_dest, $width, $height, $resize_option, $resize_quality){
88
  // Create
89
  $image = new $this->plugin['image_editor']( $image_file );
90
 
92
  if( $image->load() ){
93
 
94
  // Do resize
95
+ $image->resize( $width, $height, $resize_option );
96
+ $image->save( $image_file_dest, $resize_quality );
97
 
98
  return true;
99
  }
src/functions.php CHANGED
@@ -211,7 +211,7 @@ function cycloneslider_thumb( $original_attachment_id, $width, $height, $refresh
211
  return dirname($image_url).'/'.$thumb; //We used dirname() since we need the URL format not the path
212
  }
213
 
214
- $resizeObj = new Image_Resizer($image_path);
215
  $resizeObj -> resizeImage($width, $height, $option);
216
  $resizeObj -> saveImage($dirname.'/'.$thumb, 90);
217
 
211
  return dirname($image_url).'/'.$thumb; //We used dirname() since we need the URL format not the path
212
  }
213
 
214
+ $resizeObj = new CycloneSlider_ImageResizer($image_path);
215
  $resizeObj -> resizeImage($width, $height, $option);
216
  $resizeObj -> saveImage($dirname.'/'.$thumb, 90);
217
 
templates/thumbnails/slider.php CHANGED
@@ -90,7 +90,7 @@
90
  <?php foreach($slides as $i=>$slide): ?>
91
  <?php if ( 'image' == $slide['type'] ) : ?>
92
  <li>
93
- <img src="<?php echo cyclone_slide_image_url($slide['id'], 40, 40, array('current_slide_settings'=>$slide, 'slideshow_settings'=>$slider_settings, 'resize_option'=>'crop') ); ?>" width="40" height="40" alt="<?php echo $slide['img_alt'];?>" title="<?php echo $slide['img_title'];?>" />
94
  </li>
95
  <?php elseif ( 'youtube' == $slide['type'] ) : ?>
96
  <li>
90
  <?php foreach($slides as $i=>$slide): ?>
91
  <?php if ( 'image' == $slide['type'] ) : ?>
92
  <li>
93
+ <img src="<?php echo $slide['image_thumbnails']['40_40_crop']; ?>" width="40" height="40" alt="<?php echo $slide['img_alt'];?>" title="<?php echo $slide['img_title'];?>" />
94
  </li>
95
  <?php elseif ( 'youtube' == $slide['type'] ) : ?>
96
  <li>