-
Notifications
You must be signed in to change notification settings - Fork 0
/
nivo_slider.module
executable file
·337 lines (305 loc) · 10.7 KB
/
nivo_slider.module
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
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* @file
* Primarily Backdrop hooks.
*/
// Include the slider functions
include_once('includes/nivo_slider_slider.inc');
/**
* Implements hook_library_info().
*/
function nivo_slider_library_info() {
$module_path = backdrop_get_path('module', 'nivo_slider');
$libraries['nivo-slider'] = array(
'title' => 'Nivo Slider',
'website' => 'http://nivo.dev7studios.com/pricing',
'version' => '3.1',
'js' => array(
'libraries/nivo-slider/jquery.nivo.slider.js' => array(),
),
'css' => array(
'libraries/nivo-slider/nivo-slider.css' => array(
'type' => 'file',
'media' => 'screen',
),
), );
return $libraries;
}
/**
* Implements hook_config_info().
*/
function nivo_slider_config_info() {
$prefixes['nivo_slider.settings'] = array(
'label' => t('Nivo Slider settings'),
'group' => t('Configuration'),
);
return $prefixes;
}
/**
* Implements hook_requirements().
*/
function nivo_slider_requirements($phase) {
// Create an array to hold Nivo Slider requirements
$requirements = array();
// Check requirements during the runtime phase
if ($phase == 'runtime') {
// Check if the Nivo Slider jQuery plugin library is installed
if (($library = backdrop_get_library('nivo-slider', 'nivo-slider'))) {
$requirements['nivo_slider_library'] = array(
'title' => t('Nivo Slider jQuery plugin'),
'value' => t('Installed'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['nivo_slider_library'] = array(
'title' => t('Nivo Slider jQuery plugin'),
'value' => t('Not installed'),
'description' => $library['error message'],
'severity' => REQUIREMENT_ERROR,
);
}
// Check if the site is running >= jQuery 1.7
if (($library = backdrop_get_library('system', 'jquery')) && $library['version'] >= 1.7) {
$requirements['nivo_slider_jquery'] = array(
'title' => t('Nivo Slider jQuery version'),
'value' => t('jQuery @version', array('@version' => $library['version'])),
'severity' => REQUIREMENT_OK,
);
}
else {
$destination = backdrop_get_destination();
$requirements['nivo_slider_jquery'] = array(
'title' => t('Nivo Slider jQuery version'),
'value' => t('jQuery @version', array('@version' => $library['version'])),
'description' => t('Nivo Slider requires jQuery 1.7 or greater. Configure <a href="@jquery_update">jQuery Update</a>.', array('@jquery_update' => url('admin/config/development/jquery_update', array('query' => $destination)))),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Implements hook_permission().
*/
function nivo_slider_permission() {
return array(
'administer nivo slider' => array(
'title' => t('Administer Nivo Slider'),
'description' => t('Allows a user to configure Nivo Slider.'),
),
);
}
/**
* Implements hook_menu().
*/
function nivo_slider_menu() {
$items['admin/structure/nivo-slider'] = array(
'title' => 'Nivo Slider',
'description' => 'Configure slider content and options.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('nivo_slider_slide_configuration_form'),
'access arguments' => array('administer nivo slider'),
'file' => 'nivo_slider_slides.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/structure/nivo-slider/slides'] = array(
'title' => 'Slides',
'description' => 'Configure slider content.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('nivo_slider_slide_configuration_form'),
'access arguments' => array('administer nivo slider'),
'file' => 'nivo_slider_slides.admin.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['admin/structure/nivo-slider/options'] = array(
'title' => 'Options',
'description' => 'Configure slider options.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('nivo_slider_option_configuration_form'),
'access arguments' => array('administer nivo slider'),
'file' => 'nivo_slider_options.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
/**
* Implements hook_contextual_links_view_alter().
*/
function nivo_slider_contextual_links_view_alter(&$element, &$items) {
if (isset($element['#element']['#block']) && $element['#element']['#block']->delta == 'nivo_slider') {
$element['#links']['slides'] = array(
'title' => t('Configure slider slides'),
'href' => 'admin/structure/nivo-slider/slides',
);
$element['#links']['options'] = array(
'title' => t('Configure slider options'),
'href' => 'admin/structure/nivo-slider/options',
);
}
}
/**
* Implements hook_i18n_string_info()
*/
function nivo_slider_i18n_string_info() {
$groups['nivo_slider'] = array(
'title' => t('Nivo Slider'),
'description' => t('Slide titles and descriptions.'),
'format' => TRUE,
'list' => FALSE,
'refresh callback' => 'nivo_slider_locale_refresh',
);
return $groups;
}
/**
* Update / create translation source for user defined slide strings.
*
* @param $slides
* An array of slider slides.
*/
function nivo_slider_locale_refresh($slides = NULL) {
if (!isset($slides)) {
$slides = config_get('nivo_slider.settings', 'nivo_slider_banner_settings');
}
foreach ($slides as $slide => $settings) {
foreach ($settings as $setting => $value) {
switch ($setting) {
case 'title':
i18n_string_update('nivo_slider:slide:' . $slide . ':title', $value);
break;
case 'description':
i18n_string_update('nivo_slider:slide:' . $slide . ':description', $value['value'], array('format' => $value['format']));
break;
}
}
}
}
/**
* Translates a user defined slide string.
*
* @param $name
* Location glued with ':'.
* @param $string
* String in default language. Default language may or may not be English.
* @param $langcode
* The language code if it is different from the page request one.
* @param $textgroup
* Textgroup.
*
* @return $string
* Translated string, $string if not found.
*/
function nivo_slider_translate($name, $string, $langcode = NULL, $textgroup = 'nivo_slider') {
return function_exists('i18n_string') ? i18n_string($textgroup . ':' . $name, $string, array('langcode' => $langcode)) : $string;
}
/**
* Implements hook_theme().
*/
function nivo_slider_theme($existing, $type, $theme, $path) {
return array(
'nivo_slider_slide_configuration_form' => array(
'render element' => 'form',
'file' => 'nivo_slider.theme.inc',
'path' => $path . '/themes',
),
'nivo_slider_wrapper' => array(
'variables' => array(
'theme' => NULL,
'banners' => NULL,
),
'file' => 'nivo_slider.theme.inc',
'path' => $path . '/themes',
'template' => 'nivo-slider-wrapper',
),
);
}
/**
* Implements hook_hook_info().
*/
function nivo_slider_hook_info() {
$hooks['nivo_slider_theme_info'] = array(
'group' => 'nivo_slider',
);
$hooks['nivo_slider_theme_info_alter'] = array(
'group' => 'nivo_slider',
);
return $hooks;
}
/**
* Implements hook_block_info().
*/
function nivo_slider_block_info() {
$blocks['nivo_slider'] = array(
'info' => t('Nivo Slider'),
'cache' => BACKDROP_CACHE_PER_PAGE,
'status' => 1,
'region' => 'featured',
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function nivo_slider_block_view($delta = '') {
switch ($delta) {
case 'nivo_slider':
$block['content'] = array(
'#type' => 'markup',
'#theme' => 'nivo_slider_wrapper',
'#attached' => array(
'library' => array(
array('nivo_slider', 'nivo-slider'),
),
'js' => array(
array(
'data' => backdrop_get_path('module', 'nivo_slider') . '/js/nivo_slider.js',
'type' => 'file',
),
array(
'data' => array(
'nivo_slider' => array(
'effect' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_effect')),
'slices' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_slices')),
'boxCols' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_box_columns')),
'boxRows' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_box_rows')),
'animSpeed' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_animation_speed')),
'pauseTime' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_pause_time')),
'startSlide' => (int) check_plain(config_get('nivo_slider.settings', 'nivo_slider_start_slide')),
'directionNav' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_directional_navigation')) == 1 ? TRUE : FALSE,
'controlNav' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_control_navigation')) == 1 ? TRUE : FALSE,
'controlNavThumbs' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_control_nav_thumbs')) == 1 ? TRUE : FALSE,
'pauseOnHover' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_pause_on_hover')) == 1 ? TRUE : FALSE,
'manualAdvance' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_manual_advance')) == 1 ? TRUE : FALSE,
'prevText' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_previous_text')),
'nextText' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_next_text')),
'randomStart' => check_plain(config_get('nivo_slider.settings', 'nivo_slider_random_start')) == 1 ? TRUE : FALSE,
),
),
'type' => 'setting',
),
),
'css' => array(),
),
);
// Collect all themes
$themes = module_invoke_all('nivo_slider_theme_info');
// Allow theme information to be altered
backdrop_alter('nivo_slider_theme_info', $themes);
// Find the currently selected theme
$current_theme = config_get('nivo_slider.settings', 'nivo_slider_theme');
// Get the current theme's settings
$theme = $themes[$current_theme];
// Add the theme's resources
foreach (array('js', 'css') as $type) {
if (!empty($theme['resources'][$type])) {
foreach ($theme['resources'][$type] as $file_path) {
$block['content']['#attached'][$type][] = $file_path;
}
}
}
break;
}
return $block;
}