This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoembed.php
800 lines (685 loc) · 24.4 KB
/
oembed.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
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
<?php
/**
* An oEmbed API for <b>netPhotoGraphics</b>.
*
* <i>oEmbed</i> recognizes modified versions of the standard <b>netPhotoGraphics</b> URL links.
* It intercepts the link processing and returns an object embedded result to
* insert into the requesting document
*
* If <i>mod_rewrite</i> is enabled the URLs start with the embed request:
*
* <dl>
* <dt>For an iFrame version of the page</dt><dd>example.com/embed/albumb/image.html</dd>
* <dt>For a json response</dt><dd>example.com/embed-json/albumb/image.html<\dd>
* </dl>
*
* Otherwise use a query parameter appended to the link:
*
* <dl>
* <dt>For an iFrame</dt><dd>example.com/albumb/image.html?embed=iFrame</dd>
* <dt>For a json response</dt><dd>example.com/albumb/image.html?embed=json</dd>
* </dl>
*
* Simple iFrame output (height and width) can be customized via the plugin page.
*
* Full iFrame output can be customized by providing theme based source files for the <i>icon</i>,
* the <i>iFrame CSS</i>, and/or the <i>iFrame HTML</i>.
*
* Create an <i>oembed</i> folder in your theme folder. If you wish to replace the
* plugin's icon, name your icon replacement <var>icon.png</var> and place it that folder.
*
* To customize the layout copy the <i>iFrame.css</i> and <i>iFrame.html</i> files from
* the plugin to your theme's <i>oembed</i> folder. Modify these files to achieve the
* results you desire.
* <b>Note:</b> there are meta-tokens in the <i>iFrame.html</i> file that will be
* dynamically replaced in the actual iFrame output by the specifics of the object you are
* linking. These meta-tokens are capitalized text enclosed in percent signs.
* e.g. <var>%GALLERYTITLE%</var>
*
* Forked from {@link https://github.com/deanmoses/zenphoto-json-rest-api}
*
* Original author Dean Moses (deanmoses)
*
* @author Mika Epstein (ipstenu), Stephen Billard (sbillard), Dean Moses (deanmoses)
* @copyright 2021 by Mika Epstein for use in {@link https://%GITHUB% netPhotoGraphics} and derivatives
* @package plugins/oEmbed
* @pluginCategory theme
* @license GPLv2 (or later)
* @repository {@link https://github.com/JorjaFox/embed-npg}
*
*/
// Plugin Headers
$plugin_is_filter = 995 | CLASS_PLUGIN; // must be high priority so fall thru rewrite rules come first
if (defined('SETUP_PLUGIN')) {
$plugin_description = gettext('oEmbed API');
$plugin_version = '0.0.3';
}
// Options
$option_interface = 'FLF_NGP_OEmbed';
// rewrite rules for cleaner URLs
$_conf_vars['special_pages'][] = array('rewrite' => '^embed/*$',
'rule' => '%REWRITE% index.php?embed=iFrame [NC]');
$_conf_vars['special_pages'][] = array('rewrite' => '^embed-json/*$',
'rule' => '%REWRITE% index.php?embed=json [NC]');
$_conf_vars['special_pages'][] = array('rewrite' => '^embed/(.*)/*$',
'rule' => '%REWRITE% $1?embed=iFrame [NC]');
$_conf_vars['special_pages'][] = array('rewrite' => '^embed-json/(.*)/*$',
'rule' => '%REWRITE% $1?embed=json [NC]');
/* Handle REST API calls during theme script loading (after rwrite rules are processed)
This is necessary because it sets response headers that are different. */
npgFilters::register('load_theme_script', 'FLF_NGP_OEmbed::execute', 9999);
// Register oEmbed Discovery so WordPress and Drupal can run with this.
npgFilters::register('theme_head', 'FLF_NGP_OEmbed::get_json_oembed');
class FLF_NGP_OEmbed {
function __construct() {
setOptionDefault('oEmbed_height', 338);
setOptionDefault('oEmbed_width', 600);
setOptionDefault('oEmbed_show_images', false);
}
function getOptionsSupported() {
$options = array(
gettext('iFrame Height') => array(
'key' => 'oEmbed_height',
'type' => OPTION_TYPE_NUMBER,
'order' => 1,
'desc' => gettext('The height for the oEmbed iFrame.')
),
gettext('iFrame Width') => array(
'key' => 'oEmbed_width',
'type' => OPTION_TYPE_NUMBER,
'order' => 1.5,
'desc' => gettext('The width for the oEmbed iFrame.')
),
gettext('Show Images and Albums') => array(
'key' => 'oEmbed_show_images',
'type' => OPTION_TYPE_CHECKBOX,
'order' => 1.75,
'desc' => gettext('Display images along side subalbums. This may cause your iframes to overflow.')
),
);
return $options;
}
function handleOptionSave($option, $currentValue) {
$iframe_height = (int) getOption('oEmbed_height');
if (!empty($iframe_height) && is_numeric($iframe_height)) {
setOption('oEmbed_height', $iframe_height);
}
$iframe_width = (int) getOption('oEmbed_width');
if (!empty($iframe_width) && is_numeric($iframe_width)) {
setOption('oEmbed_width', $iframe_width);
}
$show_images = getOption('oEmbed_show_images');
if (!empty($show_images) && $show_images) {
setOption('oEmbed_show_images', true);
} else {
setOption('oEmbed_show_images', false);
}
}
/**
* Execute header output for JSON calls.
*
* @return n/a
*/
protected static function execute_headers() {
header('Content-type: application/json; charset=UTF-8');
// If the request is coming from a subdomain, send the headers
// that allow cross domain AJAX. This is important when the web
// front end is being served from sub.domain.com but its AJAX
// requests are hitting an installation on domain.com
// Browsers send the Origin header only when making an AJAX request
// to a different domain than the page was served from. Format:
// protocol://hostname that the web app was served from. In most
// cases it'll be a subdomain like http://cdn.domain.com
if (isset($_SERVER['HTTP_ORIGIN'])) {
// The Host header is the hostname the browser thinks it's
// sending the AJAX request to. In most casts it'll be the root
// domain like domain.com
// If the Host is a substring within Origin, Origin is most likely a subdomain
// Todo: implement a proper 'ends_with'
if (strpos($_SERVER['HTTP_ORIGIN'], $_SERVER['HTTP_HOST']) !== false) {
// Allow CORS requests from the subdomain the ajax request is coming from
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
// Allow credentials to be sent in CORS requests.
// Really only needed on requests requiring authentication
header('Access-Control-Allow-Credentials: true');
}
}
// Add a Vary header so that browsers and CDNs know they need to cache different
// copies of the response when browsers send different Origin headers.
// This allows us to have clients on foo.domain.com and bar.domain.com,
// and the CDN will cache different copies of the response for each of them,
// with the appropriate Access-Control-Allow-Origin header set.
/* Allow for multiple Vary headers because other things could be adding a Vary as well. */
header('Vary: Origin', false);
}
/**
* This is the function that recognizes and executes an embed request
*/
public static function execute() {
if (isset($_GET['embed'])) {
switch (strtolower($_GET['embed'])) {
default:
case 'iframe':
// returns the iFrame
self::execute_iframe();
break;
case 'json':
// Returns the oEmbed JSON data.
self::execute_json();
break;
}
}
}
/**
* changes link to an oEmbed link
*
* @param type $link object link
* @param type $type iFrame for an iFrame link, json for a json formed oembed link
* @return string
*/
protected static function oEmbedLink($link, $type) {
switch ($type) {
case 'iFrame':
$rewrite = 'embed';
$plain = 'embed=iFrame';
break;
case 'json':
$rewrite = 'embed-json';
$plain = 'embed=json';
break;
}
if (MOD_REWRITE) {
$path = str_replace(WEBPATH . '/', WEBPATH . '/' . $rewrite . '/', $link);
} else {
if (strpos($link, '?')) {
$path = $link . '&' . $plain;
} else {
$path = $link . '?' . $plain;
}
}
return $path;
}
/**
* Respond to the request an iframe friendly version of the page.
*
* This does not return; it exits.
*/
protected static function execute_iframe() {
global $_gallery_page, $_current_album, $_current_image;
// If the whole thing isn't public, we're stopping.
if (GALLERY_SECURITY === 'public') {
switch ($_gallery_page) {
case 'index.php':
$ret = self::get_gallery_iframe();
break;
case 'album.php':
$ret = self::get_album_iframe($_current_album);
break;
case 'image.php':
$ret = self::get_image_iframe($_current_image);
break;
default:
// page not supported
$ret = self::get_error_iframe(405, gettext('Method not allowed.'));
break;
}
} else {
$ret = self::get_error_iframe(403, gettext('Access forbidden.'));
}
// Return the results to the client in JSON format
print($ret);
exit();
}
/**
* Respond to the request with the JSON code
*
* This does not return; it exits.
*/
protected static function execute_json() {
global $_gallery_page, $_current_album, $_current_image;
// Execute the headers
self::execute_headers();
// the data structure we will return via JSON
if (GALLERY_SECURITY === 'public') {
switch ($_gallery_page) {
case 'index.php':
$ret = self::get_gallery_data();
break;
case 'album.php':
$ret = self::get_album_data($_current_album);
break;
case 'image.php':
$ret = self::get_image_data($_current_image);
break;
default:
// page not supported
$ret = self::get_error_data(405, gettext('Method not allowed.'));
break;
}
} else {
$ret = self::get_error_data(403, gettext('Access forbidden.'));
}
// Return the results to the client in JSON format
print( json_encode($ret));
exit();
}
/**
* Allow auto discovery
* @return html header for posts.
*/
public static function get_json_oembed() {
global $_gallery_page, $_current_album, $_current_image;
switch ($_gallery_page) {
case 'index.php':
$canonicalurl = getGalleryIndexURL();
break;
case 'album.php':
$canonicalurl = $_current_album->getLink();
break;
case 'image.php':
$canonicalurl = $_current_image->getLink();
break;
}
if (isset($canonicalurl)) {
$meta = '<link rel="alternate" type="application/json+oembed" href="' . FULLHOSTPATH . self::oEmbedLink($canonicalurl, 'json') . '" />' . "\n";
echo $meta;
}
}
/**
* Returns an iFrame for the gallery
*
* @global type $_gallery
* @global type $_current_image
* @global type $_current_page
* @return type
*/
protected static function get_gallery_iframe() {
global $_gallery;
// If the album's private, we bail.
if (!checkAccess()) {
return self::get_error_iframe(403, gettext('Access forbidden.'));
}
// Album URL
$gallery_url = FULLHOSTPATH . getGalleryIndexURL();
// Default description
$description = '<p>' . "\n" . shortenContent($_gallery->getDesc(), 300, '...') . "\n" . '</p>';
if ($_gallery->getNumAlbums()) {
// build an array of album thumgs
$thumbs = array();
// Get all the albums sorted by last change date
$_gallery->setSortType('lastchange', 'album');
$_gallery->setSortDirection(1, 'album');
$get_albums = array_slice($_gallery->getAlbums(), 0, 5);
foreach ($get_albums as $filename) {
// Create Image Object and get thumb:
$albumObj = newAlbum($filename);
$thumbs[] = array(
'thumb' => $albumObj->getThumb(),
'url' => $albumObj->getLink(),
'title' => $albumObj->getTitle()
);
}
if ($thumbs) {
// Start the build...
$description .= '<div class="npg-embed-row">' . "\n" .
gettext('Albums:') . "\n" .
'<div class="npg-embed-column">' . "\n";
// for each image, we want to craft the output.
foreach ($thumbs as $one_thumb) {
$description .= '<a href="' . FULLHOSTPATH . $one_thumb['url'] . '" target="_top" title="' . html_encode($one_thumb['title']) . '" >' . "\n" .
'<img class="npg-embed-image" src="' . FULLHOSTPATH . html_encode($one_thumb['thumb']) . "\n" .
'" />' . "\n" .
"</a>\n";
}
$description .= '</div>' . "\n" . '</div>';
}
}
// Build the count of images and subalbums ...
if ($_gallery->getNumAlbums() || $_gallery->getNumImages()) {
$counts = ' (';
if ($c = $_gallery->getNumAlbums()) {
$counts .= sprintf(ngettext('%1$s album', '%1$s albums', $c), $c);
}
if ($_gallery->getNumAlbums() && $_gallery->getNumImages()) {
$counts .= ' and ';
}
if ($c = $_gallery->getNumImages()) {
$counts .= sprintf(ngettext('%1$s image', '%1$s images', $c), $c);
}
$counts .= ')';
} else {
$counts = '';
}
// Array with the data we need:
$ret = array(
'url_thumb' => $_gallery->getSiteLogo(),
'url' => $gallery_url,
'url_title' => gettext('Visit the gallery'),
'thumb_size' => [78, 282],
'share_code' => '', // output to share via html or URL
'title' => $_gallery->getTitle() . $counts,
'content' => $description
);
$iframe = self::use_default_iframe($ret);
return $iframe;
}
/**
* Returns an iFrame for an album
*
* @global type $_gallery
* @global type $_current_image
* @global type $_current_page
* @param type $album
* @return type
*/
protected static function get_album_iframe($album) {
global $_gallery, $_current_image, $_current_page;
// If the album's private, we bail.
if (!$album->checkAccess()) {
return self::get_error_iframe(403, gettext('Access forbidden.'));
}
// Default description
$description = '<p>' . "\n" . shortenContent($album->getDesc(), 250, '...') . "\n" . '</p>';
// Featured thumbnail...
$thumb_image = $album->getAlbumThumbImage();
$thumbnail_url = $thumb_image->getThumb();
// Album URL
$album_url = FULLHOSTPATH . $album->getLink();
// Defaults
$subalbums = false;
$subimages = getOption('oEmbed_show_images');
if ($album->getNumAlbums()) {
// build an array of album thumbs
$thumbs = array();
// Get all the albums sorted by last change date
$album->setSortType('lastchange', 'album');
$album->setSortDirection(1, 'album');
$get_albums = array_slice($album->getAlbums(), 0, 5);
foreach ($get_albums as $filename) {
// Create Image Object and get thumb:
$albumObj = newAlbum($filename);
$thumbs[] = array(
'thumb' => $albumObj->getThumb(),
'url' => $albumObj->getLink(),
'title' => $albumObj->getTitle()
);
}
if ($thumbs) {
// Start the build...
$description .= '<div class="npg-embed-row">' . "\n" . gettext('Subalbums:') . "\n" . '<div class="npg-embed-column">' . "\n";
// for each subalbum, we want to craft the output.
foreach ($thumbs as $one_thumb) {
$description .= '<a href="' . FULLHOSTPATH . $one_thumb['url'] . '" target="_top" title="' . html_encode($one_thumb['title']) . '" >' . "\n" .
'<img class="npg-embed-image" src="' . FULLHOSTPATH . html_encode($one_thumb['thumb']) . '" />' . "\n" .
"</a>\n";
}
$description .= '</div>' . "\n" . '</div>' . "\n";
// There are subalbums to show
$subalbums = true;
}
}
// If there are images, we will only show them IF:
// (There are NO subalbums) OR (there are subalbums AND we said to show images too)
if ($album->getNumImages() && (!$subalbums || ($subalbums && $subimages))) {
// We have images, so we show something different.
// The description is an image grid!
// Build an array of images
$images = array();
// Get all the images sorted by last change date
$album->setSortType('lastchange', 'album');
$album->setSortDirection(1, 'album');
$get_images = array_slice($album->getImages(), 0, 5);
foreach ($get_images as $filename) {
// Create Image Object and get thumb:
$image = newImage($album, $filename);
$images[] = array(
'thumb' => $image->getThumb(),
'url' => $image->getLink(),
'title' => $image->getTitle()
);
}
if ($images) {
// Start the build...
$description .= '<div class="npg-embed-row">' . "\n" . gettext('Images:') . "\n" . '<div class="npg-embed-column">' . "\n";
// for each image, we want to craft the output.
foreach ($images as $one_image) {
$description .= '<a href="' . FULLHOSTPATH . $one_image['url'] . '" target="_top" title="' . html_encode($one_image['title']) . '">' . "\n" .
'<img class="npg-embed-image" src="' . FULLHOSTPATH . html_encode($one_image['thumb']) . '" />' . "\n" .
"</a>\n";
}
$description .= '</div>' . "\n" . '</div>';
}
}
// Build the count of images and subalbums ...
if ($album->getNumAlbums() || $album->getNumImages()) {
$counts = ' (';
if ($c = $album->getNumAlbums()) {
$counts .= sprintf(ngettext('%1$s sub-album', '%1$s sub-albums', $c), $c);
}
if ($album->getNumAlbums() && $album->getNumImages()) {
$counts .= ' and ';
}
if ($c = $album->getNumImages()) {
$counts .= sprintf(ngettext('%1$s image', '%1$s images', $c), $c);
}
$counts .= ')';
} else {
$counts = '';
}
// Array with the data we need:
$ret = array(
'url_thumb' => $thumbnail_url,
'url' => $album_url,
'url_title' => gettext('Visit the album page'),
'thumb_size' => getSizeDefaultThumb(),
'width' => (int) getOption('image_size'),
'height' => floor(( getOption('image_size') * 24 ) / 36),
'share_code' => '', // output to share via html or URL
'title' => $album->getTitle() . $counts,
'content' => $description
);
$iframe = self::use_default_iframe($ret);
return $iframe;
}
/**
* Returns an iFrame for an image
*
* @global type $_gallery
* @param type $image
* @return type
*/
protected static function get_image_iframe($image) {
global $_gallery;
if (!$image->checkAccess()) {
return self::get_error_data(403, gettext('Access forbidden.'));
}
// Base description.
$description = '<p>' . "\n" . shortenContent($image->getDesc(), 250, '...') . "\n" . '</p>';
// Array with the data we need:
$ret = array(
'url_thumb' => FULLHOSTPATH . $image->getThumb(),
'url' => FULLHOSTPATH . $image->getLink(),
'url_title' => gettext('Visit the image page'),
'thumb_size' => getSizeDefaultThumb(),
'width' => (int) $image->getWidth(),
'height' => (int) $image->getHeight(),
'share_code' => '', // output to share via html or URL
'title' => $image->getTitle(),
'content' => $description
);
$iframe = self::use_default_iframe($ret);
return $iframe;
}
/**
* Return array containing info about the gallery.
*
* @return JSON-ready array
*/
protected static function get_gallery_data() {
global $_gallery;
if (!checkAccess()) {
return self::get_error_data(403, gettext('Access forbidden.'));
}
$iframe_height = (int) getOption('oEmbed_height');
$iframe_width = (int) getOption('oEmbed_width');
$html = '<iframe src="' . FULLHOSTPATH . self::oEmbedLink(getGalleryIndexURL(), 'iFrame') . '" width="' . $iframe_width . '" height="' . $iframe_height . '" title="' . html_encode($_gallery->getTitle()) . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="npg-embedded-content"></iframe>';
// the data structure we will be returning
$ret = array(
'version' => '1.0',
'provider_name' => $_gallery->getTitle() . ' - ' . getGalleryTitle(),
'provider_url' => FULLHOSTPATH . getGalleryIndexURL(),
'title' => $_gallery->getTitle(),
'type' => 'rich',
'width' => $iframe_width,
'height' => $iframe_height,
'html' => $html,
'thumbnail_url' => FULLHOSTPATH . $_gallery->getSiteLogo(),
'thumbnail_width' => 282,
'thumbnail_height' => 78,
'content' => html_encode($_gallery->getDesc()),
);
return $ret;
}
/**
* Return array containing info about an album.
*
* @param obj $album Album object
* @return JSON-ready array
*/
protected static function get_album_data($album) {
global $_current_image;
if (!$album->checkAccess()) {
return self::get_error_data(403, gettext('Access forbidden.'));
}
$iframe_height = (int) getOption('oEmbed_height');
$iframe_width = (int) getOption('oEmbed_width');
$html = '<iframe src="' . FULLHOSTPATH . self::oEmbedLink($album->getLink(), 'iFrame') . '" width="' . $iframe_width . '" height="' . $iframe_height . '" title="' . html_encode($album->getTitle()) . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="npg-embedded-content"></iframe>';
// Get image size
$image_size = (int) getOption('image_size');
$thumb_size = getSizeDefaultThumb();
// Featured thumbnail...
$thumb_image = $album->getAlbumThumbImage();
$thumbnail_url = $thumb_image->getThumb();
// the data structure we will be returning
$ret = array(
'version' => '1.0',
'provider_name' => $album->getTitle() . ' - ' . getGalleryTitle(),
'provider_url' => FULLHOSTPATH . getGalleryIndexURL(),
'title' => $album->getTitle(),
'type' => 'rich',
'html' => $html,
'thumbnail_url' => FULLHOSTPATH . $thumbnail_url,
'thumbnail_width' => $thumb_size[0],
'thumbnail_height' => $thumb_size[1],
'content' => html_encode($album->getDesc()),
);
return $ret;
}
/**
* Return array containing info about an image.
*
* @param obj $image Image object
* @param boolean $verbose true: return a larger set of the image's information
* @return JSON-ready array
*/
protected static function get_image_data($image) {
if (!$image->checkAccess()) {
return self::get_error_data(403, gettext('Access forbidden.'));
}
// Get image size
$sizes = getSizeDefaultThumb();
$iframe_height = (int) getOption('oEmbed_height');
$iframe_width = (int) getOption('oEmbed_width');
$html = '<iframe src="' . FULLHOSTPATH . self::oEmbedLink($image->getLink(), 'iFrame') . '" width="' . $iframe_width . '" height="' . $iframe_height . '" title="' . html_encode($image->getTitle()) . '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="npg-embedded-content"></iframe>';
// the data structure we will be returning
$ret = array(
'version' => '1.0',
'provider_name' => $image->getTitle() . ' - ' . getGalleryTitle(),
'provider_url' => FULLHOSTPATH . getGalleryIndexURL(),
'title' => $image->getTitle(),
'type' => 'rich',
'html' => $html,
'thumbnail_url' => FULLHOSTPATH . $image->getThumb(),
'thumbnail_width' => '" ' . $sizes[0] . ' "',
'thumbnail_height' => $sizes[1],
'content' => html_encode($image->getDesc()),
);
return $ret;
}
/**
* Return array with error information
*
* @param int $error_code numeric HTTP error code like 404
* @param string $error_message message to return to the client
* @return JSON-ready array
*/
protected static function get_error_data($error_code, $error_message) {
http_response_code($error_code);
$ret = array(
'error' => true,
'status' => $error_code,
'message' => $error_message
);
return $ret;
}
/**
* Returns an iFrame with an error information
*
* @param type $error_code numeric HTTP error code like 404
* @param type $error_message message to display
* @return string iFrame
*
*/
protected static function get_error_iframe($error_code, $error_message) {
// Array with the data we need:
$ret = array(
'url_thumb' => FULLHOSTPATH . '/' . CORE_FOLDER . '/images/err-broken-page.png',
'url' => '',
'url_title' => '',
'thumb_size' => [100, 100],
'share_code' => '', // output to share via html or URL
'title' => $error_code,
'content' => $error_message
);
$iframe = self::use_default_iframe($ret);
return $iframe;
}
/**
* Default iFrame
* @return html
*/
protected static function use_default_iframe($ret) {
global $_gallery;
// Default icon
$gallery_icon = getPlugin('oembed/icon.png', TRUE, FULLWEBPATH);
// Featured Image and description
if ($ret['url_thumb']) {
$featured_image = '<div class="npg-embed-featured-image square">
<a href="' . $ret['url'] . '" target="_top">
<img width="' . $ret['thumb_size'][0] . '" height="' . $ret['thumb_size'][1] . '" src="' . $ret['url_thumb'] . '" title="' . $ret['url_title'] . '" />
</a>
</div>';
} else {
$featured_image = '';
}
// Get CSS
ob_start();
scriptLoader(getPlugin('oembed/iFrame.css', TRUE));
$iFrame_css = rtrim(ob_get_clean(), "\n");
// Build the iframe.
$inserts = array(
'%GALLERYTITLE%' => getBareGalleryTitle(),
'%GALLERYINDEXURL%' => FULLHOSTPATH . html_encode(getGalleryIndexURL()),
'%GALLERY_URL_TITLE%' => gettext('Visit the gallery'),
'%GALLERYICON%' => $gallery_icon,
'%TITLE%' => $ret['title'],
'%IFRAMECSS%' => $iFrame_css,
'%FEATURED_IMAGE%' => $featured_image,
'%OBJECT_URL%' => $ret['url'],
'%CONTENT%' => $ret['content'],
'%BUTTONTEXT%' => html_encodeTagged($ret['share_code'])
);
$iFrame = file_get_contents(getPlugin('oembed/iFrame.html', TRUE));
return strtr($iFrame, $inserts);
}
}