This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
faf-wall.php
207 lines (176 loc) · 6.28 KB
/
faf-wall.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
<?php
/*
Plugin Name: FAF Wall
Plugin URI: https://github.com/fafiebig/faf-wall
Description: Show image walls of your WordPress images.
Version: 1.0
Author: F.A. Fiebig
Author URI: http://fafworx.com
License: GNU GENERAL PUBLIC LICENSE
*/
defined('ABSPATH') or die('No direct script access allowed!');
/**
* load translation domain
*/
function fafWallLoadTextdomain()
{
load_plugin_textdomain('faf-wall', false, dirname(plugin_basename(__FILE__)) . '/languages/');
}
add_action('plugins_loaded', 'fafWallLoadTextdomain');
/**
* add scripts and styles to admin
*/
function fafWallEnqueueAdminScriptsStyles()
{
wp_enqueue_script('faf-wall-editor-js', plugins_url('editor/editor.js', __FILE__), array('jquery'), '1.0', true);
}
add_action('admin_enqueue_scripts', 'fafWallEnqueueAdminScriptsStyles');
/**
* add scripts and styles to frontend
*/
function fafWallEnqueueScriptsStyles()
{
/* load freewall scripts and styles */
wp_enqueue_style('freewall-css', plugins_url('freewall/css/freewall.min.css', __FILE__), array(), '1.0', 'all');
wp_enqueue_script('freewall-js', plugins_url('freewall/js/freewall.min.js', __FILE__), array(), '1.0', true);
/* load slb scripts and styles */
wp_enqueue_style('simplelightbox-css', plugins_url('simplelightbox/css/simplelightbox.min.css', __FILE__), array(), '1.0', 'all');
wp_enqueue_script('simplelightbox-js', plugins_url('simplelightbox/js/simplelightbox.min.js', __FILE__), array(), '1.0', true);
/* load faf trigger script */
wp_enqueue_script('faf-wall-js', plugins_url('faf-wall.js', __FILE__), array('freewall-js', 'simplelightbox-js'), '1.0', true);
}
add_action('wp_enqueue_scripts', 'fafWallEnqueueScriptsStyles');
/**
* add the media button to editor
*/
function fafWallAddEditorButton()
{
echo '<a href="#" id="faf-wall-short" class="button">' . __('FAF Image Wall', 'faf-wall') . '</a>';
}
add_action('media_buttons', 'fafWallAddEditorButton', 100);
/**
* @param $atts
* @return string
*/
function fafWallGalleryShort($atts) {
global $post;
if ( ! empty( $atts['ids'] ) ) {
// 'ids' is explicitly ordered, unless you specify otherwise.
//if ( empty( $atts['orderby'] ) )
//$atts['orderby'] = 'post__in';
$atts['include'] = $atts['ids'];
}
extract(shortcode_atts(array(
'orderby' => 'menu_order ASC, ID ASC',
'include' => '',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'medium',
'link' => 'file'
), $atts));
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image',
'orderby' => $orderby
);
if ( !empty($include) )
$args['include'] = $include;
else {
$args['post_parent'] = $id;
$args['numberposts'] = -1;
}
$images = get_posts($args);
$height = ($atts['size'])?$atts['size']:200;
$id = uniqid('wall');
$html = '<div id="'.$id.'" class="free-wall">';
shuffle($images);
foreach ( $images as $image ) {
//$title = $image->post_title;
//$caption = $image->post_excerpt;
//$description = $image->post_content;
//$image_alt = get_post_meta($image->ID,'_wp_attachment_image_alt', true);
$width = $height * random_int(1,3);
$imgTitle = get_the_title($image->ID);
$imgMeta = wp_get_attachment_metadata($image->ID, true);
$imgLarge = wp_get_attachment_image_url($image->ID, 'large');
$imgMedium = wp_get_attachment_image_url($image->ID, 'medium');
$imgFull = wp_get_attachment_image_url($image->ID, 'full');
//$imgSet = wp_get_attachment_image_srcset($image->ID, 'medium');
//$imgSizes = wp_get_attachment_image_sizes($image->ID, 'medium');
$exif = mapExif(exif_read_data($imgFull));
//$exif = mapMeta($imgMeta['image_meta']);
$meta = implode(", ", $exif);
$html .= '<a class="free-wall-link" rel="lightbox" href="'.esc_url($imgLarge).'" title="'.esc_attr($imgTitle).' | '.$meta.'">';
$html .= '<div class="cell" style="width:'.$width.'px; height: '.$height.'px; background-image: url('.esc_url($imgMedium).')"></div>';
$html .= '</a>';
}
$html .= '</div>';
$html .= '<script>
var wallId = "#'.$id.'";
var wallHeight = '.$height.';
</script>';
return $html;
}
remove_shortcode('gallery');
add_shortcode('gallery', 'fafWallGalleryShort');
function mapMeta($meta)
{
$retval = array();
foreach ($meta AS $key => $val) {
switch ($key) {
case 'aperture':
$retval[] = 'f'.$val;
break;
case 'camera':
$retval[] = $val;
break;
case 'focal_length':
$retval[] = $val.'mm';
break;
case 'iso':
$retval[] = 'ISO'.$val;
break;
case 'shutter_speed':
$retval[] = round($val,2).'sek';
break;
}
}
return $retval;
}
function mapExif($exif)
{
$retval = array();
foreach ($exif AS $key => $val) {
switch ($key) {
case 'Make':
case 'Model':
case 'UndefinedTag:0xA434':
$retval[] = $val;
break;
case 'ExposureTime':
$retval[] = $val.'sec';
break;
case 'ISOSpeedRatings':
$retval[] = 'ISO'.$val;
break;
case 'FNumber':
@list($a, $v) = explode('/', $val);
$retval[] = 'F'.($a/$v);
break;
case 'FocalLength':
@list($a, $v) = explode('/', $val);
$retval[] = ($a/$v).'mm';
break;
case 'Flash':
if ($val != 16) {
$retval[] = 'Flash';
}
break;
}
}
return $retval;
}