|
1 <?php |
|
2 /* |
|
3 Plugin Name: Slideshow |
|
4 Plugin URI: http://wordpress.org/extend/plugins/slideshow-jquery-image-gallery/ |
|
5 Description: This plugin offers a slideshow that is easily deployable in your website. Add any image that has already been uploaded to add to your slideshow. Options and styles are customizable for every single slideshow on your website. |
|
6 Version: 2.1.17 |
|
7 Requires at least: 3.3 |
|
8 Author: StefanBoonstra |
|
9 Author URI: http://stefanboonstra.com |
|
10 License: GPL |
|
11 */ |
|
12 |
|
13 /** |
|
14 * Class SlideshowPluginMain fires up the application on plugin load and provides some |
|
15 * methods for the other classes to use like the auto-includer and the |
|
16 * base path/url returning method. |
|
17 * |
|
18 * @author Stefan Boonstra |
|
19 * @version 13-10-12 |
|
20 */ |
|
21 class SlideshowPluginMain { |
|
22 |
|
23 /** Variables */ |
|
24 static $version = '2.1.17'; |
|
25 |
|
26 /** |
|
27 * Bootstraps the application by assigning the right functions to |
|
28 * the right action hooks. |
|
29 */ |
|
30 static function bootStrap(){ |
|
31 self::autoInclude(); |
|
32 |
|
33 // Initialize localization on init |
|
34 add_action('init', array(__CLASS__, 'localize')); |
|
35 |
|
36 // For ajax requests |
|
37 SlideshowPluginAjax::init(); |
|
38 |
|
39 // Deploy slideshow on do_action('slideshow_deploy'); hook. |
|
40 add_action('slideshow_deploy', array('SlideshowPlugin', 'deploy')); |
|
41 |
|
42 // Initialize shortcode |
|
43 SlideshowPluginShortcode::init(); |
|
44 |
|
45 // Register widget |
|
46 add_action('widgets_init', array('SlideshowPluginWidget', 'registerWidget')); |
|
47 |
|
48 // Register slideshow post type |
|
49 SlideshowPluginPostType::initialize(); |
|
50 |
|
51 // Transfers v1.x.x slides to the new slide format |
|
52 register_activation_hook(__FILE__, array(__CLASS__, 'transferV1toV2')); |
|
53 } |
|
54 |
|
55 /** |
|
56 * Transfers v1.x.x slides to the new slide format |
|
57 */ |
|
58 static function transferV1toV2(){ |
|
59 // Check if this has already been done |
|
60 if(get_option('slideshow-plugin-updated-from-v1-x-x-to-v2-0-1') !== false) |
|
61 return; |
|
62 |
|
63 // Get posts |
|
64 $posts = get_posts(array( |
|
65 'numberposts' => -1, |
|
66 'offset' => 0, |
|
67 'post_type' => SlideshowPluginPostType::$postType |
|
68 )); |
|
69 |
|
70 // Loop through posts |
|
71 if(is_array($posts) && count($posts) > 0){ |
|
72 foreach($posts as $post){ |
|
73 |
|
74 // Stores highest slide id. |
|
75 $highestSlideId = -1; |
|
76 |
|
77 // Get stored slide settings and convert them to array([slide-key] => array([setting-name] => [value])); |
|
78 $slidesPreOrder = array(); |
|
79 $settings = SlideshowPluginPostType::getSettings($post->ID, SlideshowPluginPostType::$prefixes['slide-list'], true); |
|
80 if(is_array($settings) && count($settings) > 0) |
|
81 foreach($settings as $key => $value){ |
|
82 $key = explode('_', $key); |
|
83 if(is_numeric($key[1])) |
|
84 $slidesPreOrder[$key[1]][$key[2]] = $value; |
|
85 } |
|
86 |
|
87 // Save slide keys from the $slidePreOrder array in the array itself for later use |
|
88 if(count($slidesPreOrder) > 0) |
|
89 foreach($slidesPreOrder as $key => $value){ |
|
90 // Save highest slide id |
|
91 if($key > $highestSlideId) |
|
92 $highestSlideId = $key; |
|
93 } |
|
94 |
|
95 // Get defaults |
|
96 $defaultData = SlideshowPluginPostType::getDefaultData(false); |
|
97 |
|
98 // Get old data |
|
99 $oldData = get_post_meta($post->ID, SlideshowPluginPostType::$settingsMetaKey, true); |
|
100 if(!is_array(($oldData))) |
|
101 $oldData = array(); |
|
102 |
|
103 // Get attachments |
|
104 $attachments = get_posts(array( |
|
105 'numberposts' => -1, |
|
106 'offset' => 0, |
|
107 'post_type' => 'attachment', |
|
108 'post_parent' => $post->ID |
|
109 )); |
|
110 |
|
111 // Get data from attachments |
|
112 $newData = array(); |
|
113 if(is_array($attachments) && count($attachments) > 0) |
|
114 foreach($attachments as $attachment){ |
|
115 $highestSlideId++; |
|
116 $newData['slide_' . $highestSlideId . '_postId'] = $attachment->ID; |
|
117 $newData['slide_' . $highestSlideId . '_type'] = 'attachment'; |
|
118 } |
|
119 |
|
120 // Save settings |
|
121 update_post_meta( |
|
122 $post->ID, |
|
123 SlideshowPluginPostType::$settingsMetaKey, |
|
124 array_merge( |
|
125 $defaultData, |
|
126 $oldData, |
|
127 $newData |
|
128 )); |
|
129 } |
|
130 } |
|
131 |
|
132 update_option('slideshow-plugin-updated-from-v1-x-x-to-v2-0-1', 'updated'); |
|
133 } |
|
134 |
|
135 /** |
|
136 * Translates the plugin |
|
137 */ |
|
138 static function localize(){ |
|
139 load_plugin_textdomain( |
|
140 'slideshow-plugin', |
|
141 false, |
|
142 dirname(plugin_basename(__FILE__)) . '/languages/' |
|
143 ); |
|
144 } |
|
145 |
|
146 /** |
|
147 * Returns url to the base directory of this plugin. |
|
148 * |
|
149 * @return string pluginUrl |
|
150 */ |
|
151 static function getPluginUrl(){ |
|
152 return plugins_url('', __FILE__); |
|
153 } |
|
154 |
|
155 /** |
|
156 * Returns path to the base directory of this plugin |
|
157 * |
|
158 * @return string pluginPath |
|
159 */ |
|
160 static function getPluginPath(){ |
|
161 return dirname(__FILE__); |
|
162 } |
|
163 |
|
164 /** |
|
165 * This function will load classes automatically on-call. |
|
166 */ |
|
167 function autoInclude(){ |
|
168 if(!function_exists('spl_autoload_register')) |
|
169 return; |
|
170 |
|
171 function slideshowFileAutoloader($name) { |
|
172 $name = str_replace('\\', DIRECTORY_SEPARATOR, $name); |
|
173 $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $name . '.php'; |
|
174 |
|
175 if(is_file($file)) |
|
176 require_once $file; |
|
177 } |
|
178 |
|
179 spl_autoload_register('slideshowFileAutoloader'); |
|
180 } |
|
181 } |
|
182 |
|
183 /** |
|
184 * Activate plugin |
|
185 */ |
|
186 SlideShowPluginMain::bootStrap(); |