-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshort_code.php
69 lines (55 loc) · 1.71 KB
/
short_code.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
<?php
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('foto_album', plugin_dir_url(__FILE__) . 'foto_album.css');
wp_enqueue_script('foto_album', plugin_dir_url(__FILE__) . 'slideshow.js', ['jquery']);
});
// album_id om unieke DOM id's te genereren zodat er meerdere albums op 1 pagina kunnen staan
$albumId = 1;
function foto_album_shortcode($atts) {
$options['link'] = isset($options['link']) ? $options['link'] : "";
$args = shortcode_atts(array(
'link' => $options['link'],
), $atts);
$album = $args['link'];
return displayAlbum($album);
}
function displayAlbum($album) {
static $albumId = 0;
ob_start(); ?>
<div class="bss-slides" id="foto_album_<?php echo ++$albumId ?>">
<i class="fas fa-spinner fa-spin" style="font-size: 4em; margin:1em;"></i>
</div>
<script>
jQuery(document).ready(function($) {
loadAlbum($, <?php echo "'{$album}', 'foto_album_{$albumId}'" ?>);
});
</script>
<?php
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function get_remote_contents($url) {
$response = wp_remote_get($url);
if (!is_wp_error($response)) {
return wp_remote_retrieve_body($response);
}
return NULL;
}
// function parse_photos($contents) {
// $m = NULL;
// preg_match_all('~\"(http[^"]+)"\,[0-9^,]+\,[0-9^,]+~i', $contents, $m);
// return array_unique($m[1]);
// }
$ajax = function () {
try {
if ($contents = get_remote_contents($_GET['link'])) {
echo $contents;
}
} catch (Exception $e) {
header('', true, 500);
wp_send_json_error($e->getMessage());
}
};
add_action('wp_ajax_foto_album', $ajax);
add_action('wp_ajax_nopriv_foto_album', $ajax);