-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickrblendr.php
246 lines (205 loc) · 8.13 KB
/
flickrblendr.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
<?php
/*
* Plugin Name: flickrblendr
* Description: custom post a flickr slideshow two photos at a time blended
* Version: 0.1.1
* Author: John Johnston
* Author URI: http://johnjohnston.info
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function add_flickrblendr_scripts_basic()
{
// wp_register_script Registers a script file in WordPress to be linked to a page later using the wp_enqueue_script() function, which safely handles the script dependencies.
wp_register_script('flickrblendr', plugins_url('assets/flickrblendr.js', __FILE__), array('json2', 'jquery'), false, true);
wp_register_style('flickrblendr', plugins_url('assets/flickrblendr.css', __FILE__));
}
add_action('init', 'add_flickrblendr_scripts_basic');
/* Settings */
add_action('admin_init', 'flickrblendr_plugin_settings');
function flickrblendr_plugin_settings()
{
register_setting('flickrblendr-settings-group', 'flickrblendr_apikey');
register_setting('flickrblendr-settings-group', 'flickrblendr_showmode');
}
function flickrblendr_plugin_menu()
{
add_options_page('FlickrBlendr Options', 'FlickrBlendr', 'manage_options', __FILE__, 'flickrblendr_plugin_options');
}
function flickrblendr_plugin_options()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
?>
<div class="wrap">
<h2>FlickrBlendr Settings</h2>
<p>You can create/find your api key at <a href="https://www.flickr.com/services/api/keys/">Flickr API Keys</a>. You will need to sign in.</p>
<form method="post" action="options.php">
<?php settings_fields('flickrblendr-settings-group');
?>
<?php do_settings_sections('flickrblendr-settings-group');
?>
<table class="form-table">
<tr valign="top">
<th scope="row">Flickr API Key</th>
<td>
<input type="text" name="flickrblendr_apikey" value="<?php echo esc_attr(get_option('flickrblendr_apikey'));
?>" />
</td>
</tr>
<tr>
<td>Use mode popup: <input name="flickrblendr_showmode" type="checkbox" value="1" <?php checked('1', get_option('flickrblendr_showmode'));
?> />
<em>This dosen't work yet, the popup is always there.</em>
</td></tr>
</table>
<?php submit_button();
?>
</form>
</div>
<?php
echo '</div>';
}
add_action('admin_menu', 'flickrblendr_plugin_menu');
/*
Custom post type
*/
function my_custom_post_flickrblendr()
{
$labels = array(
'name' => _x('FlickrBlendr', 'post type general name'),
'singular_name' => _x('FlickrBlendr', 'post type singular name'),
'add_new' => _x('Add New', 'FlickrBlendr'),
'add_new_item' => __('Add New FlickrBlendr'),
'edit_item' => __('Edit FlickrBlendr'),
'new_item' => __('New FlickrBlendr'),
'all_items' => __('All FlickrBlendrs'),
'view_item' => __('View FlickrBlendr'),
'search_items' => __('Search FlickrBlendr'),
'not_found' => __('No FlickrBlendrs found'),
'not_found_in_trash' => __('No FlickrBlendrs found in the Trash'),
'parent_item_colon' => '',
'menu_name' => 'FlickrBlendrs',
);
$args = array(
'labels' => $labels,
'description' => 'Holds FlickrBlendrs and show specific data',
'public' => true,
'menu_position' => 5,
'hierarchical' => true,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
'has_archive' => false,
);
register_post_type('flickrblendr', $args);
}
add_action('init', 'my_custom_post_flickrblendr');
/*
Metaboxes
*/
add_action('add_meta_boxes', 'flickrblendr_meta_box_add');
function flickrblendr_meta_box_add()
{
add_meta_box('flickrblendr_meta_box_search', 'Flickr Search String', 'flickrblendr_meta_box_cb', 'flickrblendr', 'normal', 'high');
}
function flickrblendr_meta_box_cb()
{
global $post;
$values = get_post_custom($post->ID);
$text = isset($values['flickrblendr_search']) ? $values['flickrblendr_search'] : '';
wp_nonce_field('flickrblendr_search_nonce', 'flickrblendr_search_nonce');
?>
<p>
<label for="flickrblendr_search">Flickr Search</label>
<input type="text" name="flickrblendr_search" id="flickrblendr_search" value="<?php echo $text;
?>" /> Leave empty if you don't want to search particular images.
</p>
<?php
}
add_action('save_post', 'flickrblendr_meta_box_save');
function flickrblendr_meta_box_save($post_id)
{
global $meta_box;
// Bail if we're doing an auto save
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// if our nonce isn't there, or we can't verify it, bail
if (!isset($_POST['flickrblendr_search_nonce']) || !wp_verify_nonce($_POST['flickrblendr_search_nonce'], 'flickrblendr_search_nonce')) {
return;
}
// if our current user can't edit this post, bail
if (!current_user_can('edit_post')) {
return;
}
if (isset($_POST['my_meta_box_text'])) {
update_post_meta($post_id, 'flickrblendr_search', $_POST['flickrblendr_search']);
}
}
/*
end metaboxes
*/
add_filter('the_content', 'flickrblendr_before_content');
function flickrblendr_before_content($content)
{
if (is_singular('flickrblendr')) {
$flickrblendr = flickrblendr_content();
$content = $flickrblendr.$content;
}
return $content;
}
function flickrblendrpage_enqueue_scripts()
{
if (is_singular('flickrblendr')) {
//enqueue here so only add script & styles when needed
//echo esc_attr( get_option('flickrblendr_apikey') )
$flickrapikey = get_option('flickrblendr_apikey');
$flickrfeed = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key='.$flickrapikey.'&license=7%2C8%2C2%2C4%2C5&sort=interestingness-desc&extras=url_c%2Clicense%2Cowner_name&per_page=500&format=json';
wp_enqueue_script('flickrblendr');
wp_enqueue_script('flickrfeed', $flickrfeed, array('json2', 'jquery', 'flickrblendr'), false, true);
wp_enqueue_style('flickrblendr');
}
}
add_action('wp_enqueue_scripts', 'flickrblendrpage_enqueue_scripts');
function flickrblendr_content()
{
$flickrblendrsearch = 'calm';
$flickrblendrurl = plugin_dir_url(__FILE__);
$r = '<div id="flickrblendrholder">
<div id="flickrblendr"><div id="controlwrap"><div id="info">i</div><div id="controls">
<div id="expand" onclick="fullscreen();">
<img src="'.$flickrblendrurl.'assets/fullscreen.png"></div>
Blend Mode: <select name="mode" id="mode" onchange="swapmode();return true;" size="1">
<option value="multiply" >multiply</option>
<option value="screen">screen</option>
<option value="overlay">overlay</option>
<option value="darken">darken</option>
<option value="lighten">lighten</option>
<option value="color-dodge">color-dodge</option>
<option value="color-burn">color-burn</option>
<option value="hard-light">hard-light</option>
<option value="soft-light">soft-light</option>
<option value="difference">difference</option>
<option value="exclusion" selected>exclusion</option>
<option value="hue">hue</option>
<option value="saturation">saturation</option>
<option value="color">color</option>
<option value="luminosity">luminosity</option>
</select> </div></div>
<div id="pic" data-flickrblendr="'.$flickrblendrsearch.'" class="flickrblendrfeed" ><p id="licenses" class="info"></p><img src="'.$flickrblendrurl.'assets/Ajax-loader.gif" id="flickrblenderloader""></div>
</div></div>';
return $r;
}
function flickrblendr_activate()
{
// register taxonomies/post types here
my_custom_post_flickrblendr();
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'flickrblendr_activate');
function flickrblendr_deactivate()
{
flush_rewrite_rules();
}
register_deactivation_hook(__FILE__, 'flickrblendr_deactivate');
?>