-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-booklet.php
69 lines (62 loc) · 1.81 KB
/
wp-booklet.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
/*
Plugin Name: WP Booklet
Plugin URI: https://github.com/schneidr/wp-booklet
Description: Adds jQuery Booklet as a shortcode to WordPress
Author: Gerald Schneider
Version: 0.1.1
Author URI: http://schneidr.de/
*/
function wp_booklet_load_scripts() {
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-easing',
plugins_url( 'jquery.easing.1.3.js', __FILE__ ),
array( 'jquery-ui-core', 'jquery-ui-draggable' )
);
wp_enqueue_script( 'jquery-booklet',
plugins_url( 'jquery.booklet.1.4.2.min.js', __FILE__ ),
array( 'jquery-easing' )
);
wp_register_style( 'booklet-style', plugins_url('jquery.booklet.1.4.2.css', __FILE__) );
wp_enqueue_style( 'booklet-style' );
}
add_action( 'wp_enqueue_scripts', 'wp_booklet_load_scripts' );
function wp_booklet_shortcode( $atts, $content = null ) {
global $wp_booklet_settings;
$wp_booklet_settings = shortcode_atts( array(
'id' => 'booklet',
'dir' => null,
'closed' => false
) , $atts );
extract( $wp_booklet_settings );
$return = "<div id=\"${id}\">";
if ( $dir !== null ) {
$basedir = realpath( ABSPATH . '/' . $dir );
$baseurl = get_bloginfo('wpurl') . '/' . $dir;
$files = glob("$basedir/*.jpg");
sort($files);
foreach ($files as $file) {
$return .= "<div>";
$return .= "<img src=\"".$baseurl."/".basename($file)."\" />";
$return .= "</div>";
}
}
else if ( $content !== null ) {
$return .= strip_tags( $content, "<img><div>" );
}
$return .= "</div>";
add_action('wp_footer', 'wp_booklet_footer');
return $return;
}
add_shortcode( 'booklet', 'wp_booklet_shortcode' );
function wp_booklet_footer() {
global $wp_booklet_settings;
echo "<script type=\"text/javascript\">
jQuery(function() {
jQuery('#${wp_booklet_settings['id']}').booklet({
closed: ${wp_booklet_settings['closed']}
});
});
</script>";
}
?>