This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotator.php
executable file
·325 lines (255 loc) · 10.6 KB
/
rotator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
/*
Plugin Name: Simple Image Rotator
Plugin URI: https://om4.com.au/plugins/
Description: Allows you to one or more sets of images and add them to your website so they display in rotation - like a mini slide show.
Version: 1.6.4
Author: OM4
Author URI: https://om4.com.au/plugins/
Text Domain: om4-simplerotator
Git URI: https://github.com/OM4/simple-image-rotator
Git Branch: release
License: GPLv2
*/
/* Copyright 2009-2016 OM4 (email: [email protected] web: https://om4.com.au/plugins/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class OM4_Simple_Rotator {
var $version = '1.6.4';
var $dbVersion = 1;
var $installedVersion;
var $dirname;
var $url;
static $number = 1;
var $script_suffix = '';
var $style_suffix = '';
/**
* Constructor
*
*/
public function __construct() {
// Uncomment to prevent browsers caching the JS file while debugging.
//$this->version .= time();
// Store the name of the directory that this plugin is installed in
$this->dirname = str_replace('/rotator.php', '', plugin_basename(__FILE__));
$this->url = plugins_url($this->dirname . '/');
register_activation_hook(__FILE__, array($this, 'Activate'));
add_action('init', array($this, 'LoadDomain'));
add_action('init', array($this, 'CheckVersion'));
add_action('init', array($this, 'RegisterShortcode'));
add_action('wp_enqueue_scripts', array($this, 'RegisterScripts'));
$this->installedVersion = intval(get_option('om4_simple_rotator_db_version'));
}
/**
* Intialise I18n
*
*/
function LoadDomain() {
load_plugin_textdomain( 'om4-simplerotator', false, dirname( plugin_basename( __FILE__ ) ) );
}
/**
* Plugin Activation Tasks
*
*/
function Activate() {
// There aren't really any installation tasks at the moment
if (!$this->installedVersion) {
$this->installedVersion = $this->dbVersion;
$this->SaveInstalledVersion();
}
}
/**
* Performs any upgrade tasks if required
*
*/
function CheckVersion() {
if ($this->installedVersion != $this->dbVersion) {
// Upgrade tasks
if ($this->installedVersion == 0) {
$this->installedVersion++;
}
$this->SaveInstalledVersion();
}
}
function RegisterShortcode() {
add_shortcode('simplerotator', array($this, 'ShortcodeHandler'));
}
/**
* Register the required JS/CSS so it is included in the page's <head> section
*/
function RegisterScripts() {
// Load the minified js and CSS files, unless these constants are set
$this->script_suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
$this->style_suffix = defined('STYLE_DEBUG') && STYLE_DEBUG ? '.dev' : '';
wp_enqueue_script('simple_rotator_js', "{$this->url}rotator{$this->script_suffix}.js", array('jquery'), $this->version);
wp_enqueue_style('simple_rotator', "{$this->url}rotator{$this->style_suffix}.css", array(), $this->version, 'screen');
}
/**
* Handler for the [simplerotator] shortcode
*/
function ShortcodeHandler($atts, $content = null) {
// List of supported shortcode attributes and their default values
$defaults = array(
'id' => '', // unique ID. If none specified, then it defaults to simplerotaor_x (where x is a unique number)
'interval' => '5', // seconds
'transition' => '2', // seconds
'align' => 'none', // none|left|center|right
'href' => '',
'cycles' => 0, // 0=infinite loop, 1 = 1 cycle, 2 = 2 cycles etc
'startdelay' => 0, // seconds
'order' => 'normal', // normal|random
'fullscreen' => false, // true|false
'width' => 0, // Image width (in pixels). Helps with page rendering. Do not use with a fullscreen rotator
'height' => 0, // Image height (in pixels). Helps with page rendering. Do not use with a fullscreen rotator
'shownavigation' => false, // false|true|onhover
// Control the next/previous image navigation feature
// false: no navigation buttons are shown (ie how it is now)
// true: always show next/prev navigation buttons (like the simple gallery plugin does)
// onhover: only show the next/prev buttons while hovering over the image rotator
'stoponnavigationclick' => true, // true|false
// Only applicable if shownavigation is true|onhover.
// true: when the next/previous navigation buttons are clicked, stop the image rotator from automatically rotating
// false: don't stop the image rotator after using the navigation buttons
'hidenavigationduringtransition' => false, // true|false
// Only applicable if shownavigation is true|onhover.
// Whether or not to show/hide the next/previous buttons while the rotator is transitioning between images.
// Particularly relevant when the transition="" parameter is set to high number (ie slow transitions)
// true: hide the next/previous navigation buttons during the image transitions
// false: don't hide the next/previous navigation buttons during the image transitions. If they are clicked during this period, the request will be ignored.
// BEGIN FULL SCREEN ROTATOR PARAMETERS
'topoffset' => 0, // # of pixels of padding/spacing from the top of the screen
'rightoffset' => 0, // # of pixels of padding/spacing from the right of the screen
'bottomoffset' => 0, // # of pixels of padding/spacing from the bottom of the screen
'leftoffset' => 0, // # of pixels of padding/spacing from the left of the screen
'losingside' => 'bottom', // bottom|right
// In instances where the image ratio does not match the visitor's screen ratio, one side of the image may be chopped off.
// By default the bottom of the image may be chopped, but this parameter can be used chop off the right hand side instead
'ensurefullscreen' => true // true|false
// true: If whitespace is detected between the losingside of the image and the losingside of the browser,
// increase the image size, potentially chopping off the other side of the image
// false: Don't try and detect whitspace. This maens that the losingside of the image may not take up the full browser dimension
// END FULL SCREEN ROTATOR PARAMETERS
);
$atts = shortcode_atts( $defaults, $atts);
foreach ($atts as $key => $value) {
$atts[$key] = esc_attr($value);
}
if (!strlen($content)) return;
if (!empty($href)) {
$href = esc_url($href, array('http', 'https'));
}
$images = explode(',', $content);
$totalnumimages = count($images);
if ($totalnumimages == 0) return;
extract( $atts, EXTR_SKIP );
$interval = absint($interval * 1000);
$transition = absint($transition * 1000);
$cycles = absint($cycles);
$startdelay = absint($startdelay * 1000);
$topoffset = intval($topoffset);
$rightoffset = intval($rightoffset);
$bottomoffset = intval($bottomoffset);
$leftoffset = intval($leftoffset);
$width = intval($width);
$height = intval($height);
// Can be onhover, true, or false
if ($shownavigation != 'onhover') {
$shownavigation = ($shownavigation == 'true' || $shownavigation == '1') ? 'true' : 'false';
}
$stoponnavigationclick = ($stoponnavigationclick == 'true' || $stoponnavigationclick == '1') ? 1 : 0;
$hidenavigationduringtransition = ($hidenavigationduringtransition == 'true' || $hidenavigationduringtransition == '1') ? 1 : 0;
$fullscreen = ($fullscreen == 'true' || $fullscreen == '1') ? 1 : 0;
$ensurefullscreen = ($ensurefullscreen == 'true' || $ensurefullscreen == '1') ? 1 : 0;
$additionalCssClasses = '';
$divStyle = '';
$imgDimensions = '';
$dimensions = 0;
if (in_array($align, array('left', 'center', 'right'))) {
$additionalCssClasses .= " align{$align}";
}
if (!in_array($losingside, array('bottom', 'right'))) {
$losingside = $defaults['losingside'];
}
if ($fullscreen) {
$additionalCssClasses .= ' fullscreen';
}
if (empty($id)) {
$id = 'simplerotator_' . self::$number;
}
if ($order == 'random') {
shuffle($images);
}
// If this isn't a fullscreen rotator and image width/height has been specified, then hard code them into the HTML <div> and <img> tag instead of calculating it dynamically using JavaScript
if ( !$fullscreen && $width > 0 && $height > 0 ) {
$imgDimensions = " width=\"$width\" height=\"$height\"";
$divStyle = " style=\"width: {$width}px; height: {$height}px;\" ";
$dimensions = 1;
}
// Print out the settings for this rotator
$html = <<<EOD
<script type="text/javascript">
if (typeof rotatorSettings === 'undefined') {
var rotatorSettings = []; // Define the empty settings array
}
EOD;
$html .= <<<EOD
rotatorSettings['$id'] = {
interval : $interval,
transition : $transition,
cycles : $cycles,
startdelay : $startdelay,
shownavigation : '$shownavigation',
stoponnavigationclick : $stoponnavigationclick,
hidenavigationduringtransition : $hidenavigationduringtransition,
fullscreen : $fullscreen,
topoffset : $topoffset,
rightoffset : $rightoffset,
bottomoffset : $bottomoffset,
leftoffset : $leftoffset,
losingside : '$losingside',
ensurefullscreen : $ensurefullscreen,
dimensions : $dimensions,
totalnumimages : $totalnumimages
}
</script>
EOD;
$html .= '<div class="simplerotator' . $additionalCssClasses . '" id="' . $id . '"' . $divStyle . ">\n";
if (!empty($href)) {
$html .= '<a href="' . $href . '">';
}
$class = ' class="hidden active first"';
foreach ($images as $image) {
$image = trim($image);
$html .= ' <img src="' . $image . '" alt=""' . $class . $imgDimensions . " />\n";
$class = ' class="hidden"';
}
if (!empty($href)) {
$html .= '</a>';
}
if ($shownavigation == 'onhover' || $shownavigation == 'true') {
$html .= '<div class="navigation"></div>';
}
$html .="</div>\n";
self::$number ++;
return $html;
}
function SaveInstalledVersion() {
update_option('om4_simple_rotator_db_version', $this->installedVersion);
}
}
if(defined('ABSPATH') && defined('WPINC')) {
if (!isset($GLOBALS["om4_Simple_Rotator"])) {
$GLOBALS["om4_Simple_Rotator"] = new OM4_Simple_Rotator();
}
}
?>