-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzoetrope_viewer.module
858 lines (775 loc) · 27.9 KB
/
zoetrope_viewer.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
<?php
/**
* @file
* Zoetrope Ltd. 2014.
*
* Adds a UUID field type and field formatters to display zoetrope
* engage™ images in a drupal site.
*/
/**
* This constant is the zoetrope CDN url, there's a settings page to override it.
*/
define('ZOETROPE_VIEWER_CDN', '//d34tuy4jppw3dn.cloudfront.net');
/**
* Implements hook_permission().
*/
function zoetrope_viewer_permission() {
return array(
'administer zoetrope viewer' => array(
'title' => t('Administer Zoetrope Viewer Settings'),
'restrict access' => TRUE,
),
);
}
/**
* Implements hook_help().
*
* @todo Add more help.
*/
function zoetrope_viewer_help($path, $arg){
switch($path){
case 'admin/help#zoetrope_viewer':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Zoetrope Viewer module defines a Zoetrope field types for the Field module, as well as field display formatters to display Zoetrope 3D images in web pages. See the <a href="@field-help">Field module help page</a> for more information about fields.', array('@field-help' => url('admin/help/field'))) . '</p>';
return $output;
}
}
/**
* Implements hook_menu().
*/
function zoetrope_viewer_menu() {
$menu['admin/config/media/zoetrope_viewer'] = array(
'title' => 'Zoetrope Viewer Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('zoetrope_viewer_settings_form'),
'access arguments' => array('administer zoetrope viewer'),
'file' => 'zoetrope_viewer.admin.inc',
);
return $menu;
}
/**
* Validate zoetrope_viewer_settings_form submissions.
*/
function zoetrope_viewer_settings_form_validate($form, &$form_state) {
$values = $form_state['values'];
if ($values['zoetrope_viewer_cdn_enable']) {
if (!valid_url($values['zoetrope_viewer_cdn'])) {
form_set_error('zoetrope_viewer_cdn', t('The CDN url does not appear to be a valid url.'));
}
}
}
/**
* Implements hook_field_info().
*/
function zoetrope_viewer_field_info() {
return array(
// We name our field as the associative name of the array.
'zoetrope_uuid_field' => array(
'label' => t('Zoetrope ID'),
'description' => t('Add a Zoetrope Engage™ image to an entity'),
'default_widget' => 'zoetrope_uuid_field_text_widget',
'default_formatter' => 'zoetrope_engage_image',
'property_type' => 'zoetrope_uuid_field',
'property_callbacks' => array('zoetrope_viewer_uuid_field_property_info_callback'),
),
);
}
/**
* Callback to alter the property info of Zoetrope UUID fields.
*
* @see zoetrope_viewer_field_info()
*/
function zoetrope_viewer_uuid_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
$name = $field['field_name'];
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
$property['type'] = ($field['cardinality'] != 1) ? 'list<zoetrope_uuid_field>' : 'zoetrope_uuid_field';
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
$property['auto creation'] = 'zoetrope_viewer_uuid_field_field_data_auto_creation';
$property['property info'] = zoetrope_viewer_uuid_field_field_data_property_info();
unset($property['query callback']);
}
/**
* Create an empty field instance.
*
* Returns the default array structure for a Dimensions field for use when
* creating new data arrays through an entity metadata wrapper.
*
* @see zoetrope_viewer_uuid_field_property_info_callback()
*/
function zoetrope_viewer_uuid_field_field_data_auto_creation() {
return array(
'zoetrope_uuid' => '',
'start_position' => 0,
'gallery_image_positions' => array(),
);
}
/**
* Defines info for the properties of the Dimensions field data structure.
*
* @see zoetrope_viewer_uuid_field_property_info_callback()
*/
function zoetrope_viewer_uuid_field_field_data_property_info($name = NULL) {
return array(
// Real, stored data tokens.
'zoetrope_uuid' => array(
'label' => t('Zoetrope ID'),
'description' => t('The Zoetrope ID for the image.'),
'type' => 'text',
'getter callback' => 'entity_property_verbatim_get',
'setter callback ' => 'entity_property_verbatim_set',
),
'start_position' => array(
'label' => t('Starting Position'),
'description' => t('The index of the initial view.'),
'type' => 'integer',
'getter callback' => 'entity_property_verbatim_get',
'setter callback' => 'entity_property_verbatim_set',
),
'gallery_image_positions' => array(
'label' => t('Gallery Image Positions'),
'description' => t('Holds information about the positions and priorities of images to be used for 2D gallery scenarios.'),
'type' => 'list<struct>',
'getter callback' => 'entity_property_verbatim_get',
'setter callback' => 'entity_property_verbatim_set',
'property info' => array(
// These properties are not being correctly exposed as tokens.
'weight' => array(
'label' => t('Gallery image position weight'),
'description' => t('the priority/weight of this gallery image position'),
'type' => 'int',
'getter callback' => 'entity_property_verbatim_get',
'setter callback' => 'entity_property_verbatim_set',
),
'position' => array(
'label' => t('Gallery image position'),
'description' => t("the position of this gallery image, in the style of 'start_position'"),
'type' => 'int',
'getter callback' => 'entity_property_verbatim_get',
'setter callback' => 'entity_property_verbatim_set',
),
'gallery_preview_url' => array(
'label' => t('Preview Image URI'),
'description' => t('URI to preview image.'),
'type' => 'uri',
'getter callback' => 'entity_metadata_zoetrope_viewer_get_properties',
),
),
),
// Dynamic properties.
'preview_url' => array(
'label' => t('Preview Image URI'),
'description' => t('URI to preview image.'),
'type' => 'uri',
'getter callback' => 'zoetrope_viewer_entity_metadata_get_properties',
),
);
}
/**
* Callback to get entity dynamic entity properties.
*
* @todo Add gallery_preview_url tokens.
*
* @see zoetrope_viewer_uuid_field_field_data_property_info()
*/
function zoetrope_viewer_entity_metadata_get_properties($data, array $options, $name, $entity_type) {
if ($name == 'preview_url') {
return _zoetrope_viewer_image_url($data['zoetrope_uuid'], 1000, $data['start_position']);
}
}
/**
* Implements hook_field_presave().
*
* Gallery_image_positions needs to be serialized here.
*/
function zoetrope_viewer_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as & $item) {
if (isset($item['gallery_image_positions']) && is_array($item['gallery_image_positions'])) {
$item['gallery_image_positions'] = serialize($item['gallery_image_positions']);
}
}
}
/**
* Implements hook_field_load().
*/
function zoetrope_viewer_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
foreach ($items as & $entity) {
foreach ($entity as & $item) {
if (isset($item['gallery_image_positions']) && is_string($item['gallery_image_positions'])) {
$item['gallery_image_positions'] = unserialize($item['gallery_image_positions']);
}
}
}
}
/**
* Implements hook_field_validate().
*
* @todo Add validation of gallery_image_positions.
*/
function zoetrope_viewer_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['zoetrope_uuid'])) {
// Test for valid UUID (mongo ObjectID style UUID).
if (!preg_match('/^[0-9a-fA-F]{24}$/', $item['zoetrope_uuid'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'zoetrope_uuid_field_uuid_invalid',
'message' => t('Zoetrope ID field must be a valid UUID.'),
);
}
if (!empty($item['start_position'])) {
$value = $item['start_position'];
if (!is_numeric($value) || intval($value) != $value || (intval($value) < 0) || (intval($value) > 107)) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'zoetrope_uuid_field_start_position_invalid',
'message' => t('The starting position needs to be an integer between 0-107.'),
);
}
}
}
}
}
/**
* Implements hook_field_widget_info().
*
* Only widget is a text input box.
*/
function zoetrope_viewer_field_widget_info() {
return array(
'zoetrope_uuid_field_text_widget' => array(
'label' => t('Zoetrope text field'),
'field types' => array('zoetrope_uuid_field'),
),
);
}
/**
* Implements hook_field_widget_form().
*
* This implements our input box as defined in hook_field_widget_info().
*/
function zoetrope_viewer_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$uuid = isset($items[$delta]['zoetrope_uuid']) ? $items[$delta]['zoetrope_uuid'] : '';
$start_position = isset($items[$delta]['start_position']) ? $items[$delta]['start_position'] : '0';
$widget = &$element;
$widget['#delta'] = $delta;
switch ($instance['widget']['type']) {
case 'zoetrope_uuid_field_text_widget':
$widget += array(
'#type' => 'fieldset',
'#title' => t('Zoetrope Image'),
'#attached' => array(
'css' => array(drupal_get_path('module', 'zoetrope_viewer') . '/css/zoetrope_viewer_admin.css'),
),
);
$widget['zoetrope_uuid'] = array(
'#title' => t('Zoetrope ID'),
'#type' => 'textfield',
'#default_value' => $uuid,
'#size' => 40,
'#maxlength' => 40,
'#attributes' => array(
'class' => array('zoetrope-uuid-field-zoetrope-id'),
),
);
$widget['start_position'] = array(
'#title' => t('Start position'),
'#type' => 'textfield',
'#default_value' => $start_position,
'#size' => 3,
'#maxlength' => 3,
'#attributes' => array(
'class' => array('zoetrope-uuid-field-starting-position'),
),
);
break;
}
return $element;
}
/**
* Implements hook_field_widget_error().
*/
function zoetrope_viewer_field_widget_error($element, $error, $form, &$form_state) {
switch ($error['error']) {
case 'zoetrope_uuid_field_uuid_invalid':
form_error($element['zoetrope_uuid'], $error['message']);
break;
case 'zoetrope_uuid_field_start_position_invalid':
form_error($element['start_position'], $error['message']);
break;
}
}
/**
* Implements hook_field_is_empty().
*/
function zoetrope_viewer_field_is_empty($item, $field) {
return empty($item['zoetrope_uuid']);
}
/**
* Implements hook_field_formatter_info().
*/
function zoetrope_viewer_field_formatter_info() {
$info = array(
'zoetrope_engage_image' => array(
'label' => t('Zoetrope Reel viewer'),
'field types' => array('zoetrope_uuid_field', 'text'),
'description' => t('Embeds the zoetrope viewer.'),
'settings' => array(
'inline_image' => FALSE,
'force_mini' => FALSE,
'trigger_image' => '',
'2d_version' => FALSE,
'image_style' => '',
'loadspin' => FALSE,
'idle-animate' => FALSE,
'autoload' => FALSE,
'preload' => FALSE,
'show-cta' => TRUE,
'gallery' => FALSE,
),
),
'zoetrope_image_gallery' => array(
'label' => t('Image + Zoetrope Images'),
'field types' => array('image'),
'description' => t('Image formatter which includes zoetrope images.'),
'settings' => array(
'zoetrope_uuid_field_name' => '',
'position' => 'first',
'image_style' => '',
),
),
);
return $info;
}
/**
* Implements hook_field_formatter_settings_form().
*/
function zoetrope_viewer_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
switch ($instance['display'][$view_mode]['type']) {
case 'zoetrope_engage_image':
$states_non_2d = array(
'visible' => array(
':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][2d_version]"]' => array('checked' => FALSE),
),
);
$element['2d_version'] = array(
'#type' => 'checkbox',
'#title' => t('2D version'),
'#description' => t('Forces the viewer to just show a 2D image.'),
'#default_value' => $settings['2d_version'],
);
$element['inline_image'] = array(
'#type' => 'checkbox',
'#title' => t('Inline Engage image'),
'#description' => t('Inline images appear in the page content, whereas normal engage images open in a responsive lightbox overlay.'),
'#default_value' => $settings['inline_image'],
'#states' => $states_non_2d,
);
$element['force_mini'] = array(
'#type' => 'checkbox',
'#title' => t('Force Mini (Non inline only)'),
'#description' => t('Forces the viewer to display a mini zoetrope viewer, rather than the responsive one in the interest of bandwidth.'),
'#default_value' => $settings['force_mini'],
'#states' => $states_non_2d,
);
$element['loadspin'] = array(
'#type' => 'checkbox',
'#title' => t('Spin once on load'),
'#description' => t('Spins one time when loaded.'),
'#default_value' => $settings['loadspin'],
'#states' => $states_non_2d,
);
$element['idle-animate'] = array(
'#type' => 'checkbox',
'#title' => t('Spin when Idle'),
'#description' => t('Spins when not being dragged by the user.'),
'#default_value' => $settings['idle-animate'],
'#states' => $states_non_2d,
);
$element['show-cta'] = array(
'#type' => 'checkbox',
'#title' => t('Show call to action'),
'#description' => t('Hides the labels which indcate the viewer is interactive.'),
'#default_value' => $settings['show-cta'],
'#states' => $states_non_2d,
);
$element['preload'] = array(
'#type' => 'checkbox',
'#title' => t('Preload'),
'#description' => t('Preload for extra responsiveness at the cost of server bandwidth. If loadspin is selected also, the image will rotate on page load.'),
'#default_value' => $settings['preload'],
'#states' => $states_non_2d,
);
$element['gallery'] = array(
'#type' => 'checkbox',
'#title' => t('Show Gallery hotspots'),
'#description' => t('Show hotspots of selected views.'),
'#default_value' => $settings['gallery'],
'#states' => $states_non_2d,
);
$fields_info = field_info_instances($instance['entity_type'], $instance['bundle']);
$options = array();
foreach ($fields_info as $field_name => $field_instance) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'image') {
$options[$field_name] = $field_instance['label'];
}
}
$element['trigger_image'] = array(
'#title' => t('Trigger Image Override field'),
'#type' => 'select',
'#description' => t('Select an image field to use as the trigger image if present.'),
'#default_value' => $settings['trigger_image'],
'#options' => $options,
'#empty_option' => t('None, (Use initial Engage view).'),
);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
break;
case 'zoetrope_image_gallery':
$fields_info = field_info_instances($instance['entity_type'], $instance['bundle']);
$options = array('' => 'None');
foreach ($fields_info as $field_name => $field_instance) {
$field_info = field_info_field($field_name);
if ($field_info['type'] == 'zoetrope_uuid_field') {
$options[$field_name] = $field_instance['label'];
}
}
$element['zoetrope_uuid_field_name'] = array(
'#type' => 'select',
'#title' => t('Zoetrope ID field to combine'),
'#description' => t('The field on this entity to combine for display. You probably want to hide the zoetrope_uuid_field which you use here.'),
'#default_value' => $settings['zoetrope_uuid_field_name'],
'#options' => $options,
);
$element['position'] = array(
'#type' => 'select',
'#title' => t('Zoetrope positions'),
'#description' => t('Where should the zoetrope images be placed'),
'#default_value' => $settings['position'],
'#options' => array(
'start' => t('Start'),
'end' => t('End'),
),
);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
break;
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function zoetrope_viewer_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
switch ($display['type']) {
case 'zoetrope_engage_image':
$summary[] = $settings['inline_image'] ? t('Inline (no overlay)') : t('Show in Overlay');
$summary[] = $settings['force_mini'] ? t('Mini Viewer') : t('Responsive Viewer');
$summary[] = $settings['trigger_image'] ? t('Using field `@field` for the trigger image',
array('@field' => $settings['trigger_image'])
) : t('Zoetrope trigger image.');
$image_styles = image_style_options(FALSE, PASS_THROUGH);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
if (isset($image_styles[$settings['image_style']])) {
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
}
else {
$summary[] = t('Original image');
}
break;
case 'zoetrope_image_gallery':
$image_styles = image_style_options(FALSE, PASS_THROUGH);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
if (isset($image_styles[$settings['image_style']])) {
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
}
else {
$summary[] = t('Original image');
}
if (empty($settings['zoetrope_uuid_field_name'])) {
$summary[] = t('Engage Image configured');
}
else {
$summary[] = t('Using field `@name` at the @pos of list.',
array('@name' => $settings['zoetrope_uuid_field_name'], '@pos' => $settings['position'])
);
}
break;
}
return implode('<br />', $summary);
}
/**
* Implements hook_field_formatter_prepare_view().
*/
function zoetrope_viewer_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
foreach ($entities as $id => $entity) {
$display = $displays[$id];
// If it's a zoetrope_image_gallery display.
if ($display['type'] == 'zoetrope_image_gallery' && !empty($display['settings']['zoetrope_uuid_field_name'])) {
// Add the zoetrope engage images if we can.
if (isset($entity->{$display['settings']['zoetrope_uuid_field_name']})) {
$zoetrope_uuid_field = $entity->{$display['settings']['zoetrope_uuid_field_name']}[$langcode];
$e_items = &$items[$id];
foreach ($zoetrope_uuid_field as $value) {
if ($display['settings']['position'] == 'end') {
array_push($e_items, $value);
}
else {
array_unshift($e_items, $value);
}
}
}
}
elseif ($display['type'] == 'zoetrope_engage_image' && !empty($display['settings']['trigger_image'])) {
if (isset($entity->{$display['settings']['trigger_image']})) {
$image_field = $entity->{$display['settings']['trigger_image']}[$langcode];
$e_items = &$items[$id];
// Match up image field deltas with zoetrope image deltas.
foreach ($e_items as $delta => & $value) {
if (!empty($image_field[$delta])) {
$value['trigger_image'] = $image_field[$delta];
}
}
}
}
}
}
/**
* Implements hook_field_formatter_view().
*/
function zoetrope_viewer_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
foreach ($items as $delta => $item) {
switch ($display['type']) {
case 'zoetrope_engage_image':
$element[$delta] = _zoetrope_viewer_engage_image_field_view($item, $settings, $instance['id']);
break;
case 'zoetrope_image_gallery':
if (isset($item['zoetrope_uuid_field'])) {
$element[$delta] = _zoetrope_viewer_engage_image_field_view($item, $settings);
}
else {
$element[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $display['settings']['image_style'],
'#path' => '',
);
}
break;
}
}
return $element;
}
/**
* Helper to make a renderable array.
*
* @param array $item
* The item being rendered.
* @param array $settings
* The field settings.
* @param mixed $rel
* A grouping variable for multiple Zoetropes.
*
* @return array
* A renderable array.
*/
function _zoetrope_viewer_engage_image_field_view($item, $settings, $rel = FALSE) {
global $language;
$img_uuid = empty($item['zoetrope_uuid']) ? $item['value'] : $item['zoetrope_uuid'];
$start_position = isset($item['start_position']) ? $item['start_position'] : 0;
$gallery_images = array();
if(isset($item['gallery_image_positions'])){
foreach ($item['gallery_image_positions'] as $value) {
array_push($gallery_images, $value['position']);
}
}
$site_uuid = variable_get('zoetrope_viewer_site_uuid', '');
// Override sites default CDN (done by modules sometimes).
$cdn = !empty($settings['cdn']) ? $settings['cdn'] : FALSE;
$cdn = !empty($item['cdn']) ? $item['cdn'] : $cdn;
$preview_path = _zoetrope_viewer_image_url($img_uuid, 500, $start_position, $cdn);
$e = array(
'#theme' => 'image',
'#path' => $preview_path,
'#attributes' => array(
'data-zoe-image' => $img_uuid,
'data-zoe-site' => $site_uuid,
'data-zoe-rel' => $rel,
'data-zoe-start-position' => $start_position,
'data-zoe-lang' => $language->language,
'data-zoe-gallery-images' => drupal_json_encode($gallery_images),
),
);
// Force the size of the trigger image (depreciated).
if (isset($settings['trigger_size']) && intval($settings['trigger_size']) != 0) {
$e['#attributes']['width'] = $settings['trigger_size'];
$e['#attributes']['height'] = $settings['trigger_size'];
}
// Use the sizes from an image style for the trigger.
if (!empty($settings['image_style'])) {
$dimensions = array('width' => 500, 'height' => 500);
image_style_transform_dimensions($settings['image_style'], $dimensions);
$e['#attributes']['width'] = $dimensions['width'];
$e['#attributes']['height'] = $dimensions['height'];
}
if (!isset($settings['2d_version']) || $settings['2d_version'] == FALSE) {
$e['#attributes']['class'] = array('zoe-engage-image');
}
else {
// Keep the markup cleaner with attributes which wont be used.
return $e;
}
// Add the JS and CSS, always from the Zoetrope CDN.
$e['#attached'] = array(
'js' => array(
ZOETROPE_VIEWER_CDN . '/v3/js/zoetrope.jquery.js' => array(
'type' => 'external',
'group' => JS_THEME,
'weight' => 1000000,
)
),
'css' => array(
ZOETROPE_VIEWER_CDN . '/v3/css/zoetrope.jquery.min.css' => array(
'type' => 'external',
)
)
);
if ($cdn) {
$e['#attributes']['data-zoe-cdn'] = $cdn;
}
// Alternate trigger image.
if (isset($settings['trigger_image']) && !empty($item['trigger_image'])) {
$e['#path'] = $item['trigger_image'];
$e['#path'] = $item['trigger_image']['uri'];
if (!empty($settings['image_style'])) {
$e['#theme'] = 'image_style';
$e['#style_name'] = $settings['image_style'];
}
}
// Force the mini viewer.
if (isset($settings['force_mini']) && $settings['force_mini']) {
$e['#attributes']['class'][] = 'zoe-mini';
}
// Inline the viewer.
if (isset($settings['inline_image']) && !$settings['inline_image']) {
$e['#attributes']['data-zoe-inline'] = 'false';
}
// Spin once on load.
if (!empty($settings['loadspin']) && $settings['loadspin']) {
$e['#attributes']['data-zoe-loadspin'] = 'true';
}
// Animate.
if (!empty($settings['auto-animate']) && $settings['auto-animate']) {
$e['#attributes']['data-zoe-auto-animate'] = 'true';
}
// Hide CTA.
if (!empty($settings['show-cta']) && $settings['show-cta']) {
$e['#attributes']['data-zoe-show-cta'] = 'true';
}
// Preload.
if (isset($settings['preload']) && !$settings['preload']) {
$e['#attributes']['data-zoe-preload'] = 'false';
}
if (isset($settings['gallery']) && $settings['gallery']) {
$e['#attributes']['data-zoe-gallery'] = 'true';
}
return $e;
}
/**
* Returns a CDN base URL, in the right format
*
* @param string $cdn
* CDN override, defaults false to use global setting
* in `zoetrope_viewer_cdn`.
*
* @return string Base URL for the CDN.
*/
function _zoetrope_viewer_cdn_url($cdn = ""){
$mode = !empty($_SERVER['HTTPS']) ? 'https:' : 'http:';
$cdn_enable = variable_get('zoetrope_viewer_cdn_enable');
if ($cdn == "" && $cdn_enable) {
$cdn = variable_get('zoetrope_viewer_cdn', ZOETROPE_VIEWER_CDN);
}
else{
$cdn = ZOETROPE_VIEWER_CDN;
}
return $mode . $cdn;
}
/**
* Returns a preview image URL from the CDN.
*
* @param string $uuid
* The Zoetrope image UUID.
* @param int $size
* The image size, can be either 250,500,1000.
* @param int $position
* The position between 0-107.
* @param string $cdn
* The base CDN, if not using the site default CDN.
*
* @return string
* A fully formed image URL.
*/
function _zoetrope_viewer_image_url($uuid, $size = 500, $position = 0, $cdn = "") {
$cdn = _zoetrope_viewer_cdn_url($cdn);
if (!in_array($size, array(250, 500, 1000))) {
watchdog('Zoetrope Viewer', 'Invalid image size `@size` selected for preview, should have been 250,500 or 1000.',
array('@size' => $size), WATCHDOG_ERROR
);
}
return $cdn . '/' . $uuid . '/' . $size . '/' . $position . '.jpg';
}
/**
* Shortcut for `_zoetrope_viewer_image_url($uuid, 500, $start_position, $cdn)`.
*
* @param object $field
* The zoetrope field to retrieve an image for.
* @param string $cdn
* String CDN override.
*
* @return string
* A fully formed image URL.
*
* @see _zoetrope_viewer_image_url()
*/
function zoetrope_viewer_preview_image_url($field, $cdn = "") {
return _zoetrope_viewer_image_url($field['zoetrope_uuid'], 500, $field['start_position'], $cdn);
}
/**
* Shortcut for `_zoetrope_viewer_image_url($uuid, 1000, $start_position, $cdn)`.
*
* @param object $field
* The zoetrope field to retrieve an image for.
* @param string $cdn
* String CDN override.
*
* @return string
* A fully formed image URL.
*
* @see _zoetrope_viewer_image_url()
*/
function zoetrope_viewer_large_image_url($field, $cdn = "") {
return _zoetrope_viewer_image_url($field['zoetrope_uuid'], 1000, $field['start_position'], $cdn);
}