-
Notifications
You must be signed in to change notification settings - Fork 2
/
g2imageplugin.inc
362 lines (318 loc) · 17.5 KB
/
g2imageplugin.inc
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
<?php
/*
Author: WPG2 Team
Updated: 116:25 23/03/2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*
********************************************************************************************************
WORDPRESS FUNCTIONS
********************************************************************************************************
*/
/**
* Adds g2image Options to WPG2 Options Sub Menu
*
* @param None
* @return None
*/
function g2imageoptions() {
//If we're setting options,
if ( isset($_POST['action']) ) {
$g2_image = get_option('wpg2_g2ic');
// Option Saving Time
foreach ($_POST['g2_image'] as $key=>$value){
$g2_image[$key] = $value;
}
update_option('wpg2_g2ic', $g2_image);
?><div id="message" class="updated fade"><p><strong><?php _e('G2Image Page options saved.', 'wpg2') ?></strong></p></div><?php
}
// Get Gallery2 Option Settings
$g2_image = get_option('wpg2_g2ic');
$g2_option = get_option('wpg2_options');
if ( $g2_option['g2_validated'] == "Yes" ) {
?>
<div class="wrap">
<h2><?php _e('G2Image Popup Options', 'wpg2') ?></h2>
<form name="g2imageoptions" method="post" action="">
<input type="hidden" name="action" value="update" />
<table cellspacing="2" cellpadding="5" class="form-table">
<tr>
<th valign="top" scope="row"><?php _e('Thumbnails per Page:', 'wpg2') ?> </th>
<td>
<input name="g2_image[g2ic_images_per_page]" id="g2ic_images_per_page" value="<?php if(isset($g2_image['g2ic_images_per_page'])){echo $g2_image['g2ic_images_per_page'];} else{echo "15";} ?>" size="10" / ><br />
</td></tr>
<tr>
<th valign="top" scope="row"><?php _e('Default Image Sort Order:', 'wpg2') ?></th>
<td>
<select name="g2_image[g2ic_sortby]">
<option value="title_asc"<?php if ($g2_image['g2ic_sortby']=="title_asc" ){ echo " selected";} ?>><?php _e('Gallery2 Title (A-z)', 'wpg2') ?></option>
<option value="title_desc"<?php if ($g2_image['g2ic_sortby']=="title_desc" ){ echo " selected";} ?>><?php _e('Gallery2 Title (z-A)', 'wpg2') ?></option>
<option value="orig_time_desc"<?php if ($g2_image['g2ic_sortby']=="orig_time_desc" ){ echo " selected";} ?>><?php _e('Origination Time (newest first)', 'wpg2') ?></option>
<option value="orig_time_asc"<?php if ($g2_image['g2ic_sortby']=="orig_time_asc" ){ echo " selected";} ?>><?php _e('Origination Time (oldest first)', 'wpg2') ?></option>
<option value="mtime_desc"<?php if ($g2_image['g2ic_sortby']=="mtime_desc" ){ echo " selected";} ?>><?php _e('Last Modification (newest first)', 'wpg2') ?></option>
<option value="mtime_asc"<?php if ($g2_image['g2ic_sortby']=="mtime_asc" ){ echo " selected";} ?>><?php _e('Last Modification (oldest first)', 'wpg2') ?></option>
</select> <br />
</td>
</tr>
<tr>
<th valign="top" scope="row"><?php _e('Default Display', 'wpg2') ?> </th>
<td>
<input name="g2_image[g2ic_display_filenames]" type="radio" id="g2ic_display_filenames_false" value="no" <?php if(!isset($g2_image['g2ic_display_filenames'])){echo "checked ";} elseif ($g2_image['g2ic_display_filenames']=="no"){echo "checked ";}?> /><?php _e('Thumbnails Only', 'wpg2')?>;
<input name="g2_image[g2ic_display_filenames]" type="radio" id="g2ic_display_filenames_true" value="yes" <?php if ($g2_image['g2ic_display_filenames']=="yes"){echo "checked ";}?> /><?php _e('Thumbnails with Titles and Filenames', 'wpg2') ?>
</td>
</tr>
<tr>
<th valign="top" scope="row"><?php _e('Default Action:', 'wpg2') ?></th>
<td>
<?php _e('Choose the default "How to Insert" option.', 'wpg2') ?><br />
<select name="g2_image[g2ic_default_action]">
<option value="wpg2_image"<?php if ($g2_image['g2ic_default_action']=="wpg2_image" ){ echo " selected";} ?>><?php _e('WPG2 Tag', 'wpg2') ?></option>
<option value="thumbnail_image"<?php if ($g2_image['g2ic_default_action']=="thumbnail_image" ){ echo " selected";} ?>><?php _e('Thumbnail with link to image', 'wpg2') ?></option>
<option value="thumbnail_album"<?php if ($g2_image['g2ic_default_action']=="thumbnail_album" ){ echo " selected";} ?>><?php _e('Thumbnail with link to parent album', 'wpg2') ?></option>
<option value="thumbnail_lightbox"<?php if ($g2_image['g2ic_default_action']=="thumbnail_lightbox" ){ echo " selected";} ?>><?php _e('Thumbnail with LightBox link to Fullsized Image', 'wpg2') ?></option>
<option value="thumbnail_custom_url"<?php if ($g2_image['g2ic_default_action']=="thumbnail_custom_url" ){ echo " selected";} ?>><?php _e('Thumbnail with link to custom URL', 'wpg2') ?></option>
<option value="thumbnail_only"<?php if ($g2_image['g2ic_default_action']=="thumbnail_only" ){ echo " selected";} ?>><?php _e('Thumbnail only - no link', 'wpg2') ?></option>
<option value="fullsize_image"<?php if ($g2_image['g2ic_default_action']=="fullsize_image" ){ echo " selected";} ?>><?php _e('Fullsized image with link to Gallery page for image', 'wpg2') ?></option>
<option value="fullsize_album"<?php if ($g2_image['g2ic_default_action']=="fullsize_album" ){ echo " selected";} ?>><?php _e('Fullsized image with link to parent album', 'wpg2') ?></option>
<option value="fullsize_custom_url"<?php if ($g2_image['g2ic_default_action']=="fullsize_custom_url" ){ echo " selected";} ?>><?php _e('Fullsized image with link to custom URL', 'wpg2') ?></option>
<option value="fullsize_only"<?php if ($g2_image['g2ic_default_action']=="fullsize_only" ){ echo " selected";} ?>><?php _e('Fullsized image only - no link', 'wpg2') ?></option>
<option value="link_image"<?php if ($g2_image['g2ic_default_action']=="link_image" ){ echo " selected";} ?>><?php _e('Text link to image', 'wpg2') ?></option>
<option value="link_album"<?php if ($g2_image['g2ic_default_action']=="link_album" ){ echo " selected";} ?>><?php _e('Text link to parent album', 'wpg2') ?></option>
</select> <br />
</td>
</tr>
<tr>
<th valign="top" scope="row"><?php _e('Default Custom URL:', 'wpg2') ?> </th>
<td>
<input name="g2_image[g2ic_custom_url]" id="g2ic_custom_url" value="<?php if(isset($g2_image['g2ic_custom_url'])){echo $g2_image['g2ic_custom_url'];} else{echo "http://";} ?>" size="50" / ><br />
</td>
<tr>
<th valign="top" scope="row"><?php _e('Default Image Class:', 'wpg2') ?></th>
<td>
<select name="g2_image[g2ic_default_alignment]">
<option value="none"<?php if ($g2_image['g2ic_default_alignment']=="none" ){ echo " selected";} ?>><?php _e('None', 'wpg2') ?></option>
<option value="g2image_normal"<?php if ($g2_image['g2ic_default_alignment']=="g2image_normal" ){ echo " selected";} ?>><?php _e('Normal', 'wpg2') ?></option>
<option value="g2image_float_left"<?php if ($g2_image['g2ic_default_alignment']=="g2image_float_left" ){ echo " selected";} ?>><?php _e('Float Left', 'wpg2') ?></option>
<option value="g2image_float_right"<?php if ($g2_image['g2ic_default_alignment']=="g2image_float_right" ){ echo " selected";} ?>><?php _e('Float Right', 'wpg2') ?></option>
<option value="g2image_centered"<?php if ($g2_image['g2ic_default_alignment']=="g2image_centered" ){ echo " selected";} ?>><?php _e('Centered', 'wpg2') ?></option>
<?php if(isset($g2_image['g2ic_custom_class_1'])&&($g2_image['g2ic_custom_class_1']!='not_used')){ ?>
<option value="<?php echo $g2_image['g2ic_custom_class_1']; ?>"<?php if ($g2_image['g2ic_default_alignment']==$g2_image['g2ic_custom_class_1']){ echo " selected";} ?>><?php echo $g2_image['g2ic_custom_class_1']; ?></option>
<?php } ?>
<?php if(isset($g2_image['g2ic_custom_class_2'])&&($g2_image['g2ic_custom_class_2']!='not_used')){ ?>
<option value="<?php echo $g2_image['g2ic_custom_class_2']; ?>"<?php if ($g2_image['g2ic_default_alignment']==$g2_image['g2ic_custom_class_2']){ echo " selected";} ?>><?php echo $g2_image['g2ic_custom_class_2']; ?></option>
<?php } ?>
<?php if(isset($g2_image['g2ic_custom_class_3'])&&($g2_image['g2ic_custom_class_3']!='not_used')){ ?>
<option value="<?php echo $g2_image['g2ic_custom_class_3']; ?>"<?php if ($g2_image['g2ic_default_alignment']==$g2_image['g2ic_custom_class_3']){ echo " selected";} ?>><?php echo $g2_image['g2ic_custom_class_3']; ?></option>
<?php } ?>
<?php if(isset($g2_image['g2ic_custom_class_4'])&&($g2_image['g2ic_custom_class_4']!='not_used')){ ?>
<option value="<?php echo $g2_image['g2ic_custom_class_4']; ?>"<?php if ($g2_image['g2ic_default_alignment']==$g2_image['g2ic_custom_class_4']){ echo " selected";} ?>><?php echo $g2_image['g2ic_custom_class_4']; ?></option>
<?php } ?>
</select> <br />
<?php _e('This is the default CSS class applied to WPG2 tags and HTML thumbnails inserted using the G2Image popup window.', 'wpg2') ?><br />
<?php _e('Custom classes will be available as options after entering them below and hitting the "Update Options" button.', 'wpg2') ?><br />
</td>
</tr>
<tr>
<th valign="top" scope="row"><?php _e('Default Class Mode', 'wpg2') ?> </th>
<td>
<input name="g2_image[g2ic_class_mode]" type="radio" id="g2ic_class_mode_img" value="img" <?php if(!isset($g2_image['g2ic_class_mode'])){echo "checked ";} elseif ($g2_image['g2ic_class_mode']=="img"){echo "checked ";}?> /><?php _e('Class in the img tag - < img class=... /> (Recommended)', 'wpg2') ?><br />
<input name="g2_image[g2ic_class_mode]" type="radio" id="g2ic_class_mode_div" value="div" <?php if ($g2_image['g2ic_class_mode']=="div"){echo "checked ";}?> /><?php _e('Class in a div tag wrapper - < div class=...>< img ... />< /div>', 'wpg2') ?>
<?php _e('<br />NOTE: This setting only applies to images inserted as <img> tags, as WPG2 tag will always be wrapped with a div tag.', 'wpg2') ?><br />
</td>
</tr>
<tr>
<th valign="top" scope="row"><?php _e('Custom Classes:', 'wpg2') ?> </th>
<td>
<?php _e('Custom Classes (a valid class in your CSS or "not_used")', 'wpg2') ?>
<table><tr><td colspan=2>
<?php _e('1. ', 'wpg2') ?><input name="g2_image[g2ic_custom_class_1]" id="g2ic_custom_class_1" value="<?php if(isset($g2_image['g2ic_custom_class_1'])){echo $g2_image['g2ic_custom_class_1'];} else{echo "not_used";} ?>" size="30" / ><br />
</td><td>
<?php _e('3. ', 'wpg2') ?><input name="g2_image[g2ic_custom_class_3]" id="g2ic_custom_class_3" value="<?php if(isset($g2_image['g2ic_custom_class_3'])){echo $g2_image['g2ic_custom_class_3'];} else{echo "not_used";} ?>" size="30" / ><br />
</td></tr>
<tr><td colspan=2>
<?php _e('2. ', 'wpg2') ?><input name="g2_image[g2ic_custom_class_2]" id="g2ic_custom_class_2" value="<?php if(isset($g2_image['g2ic_custom_class_2'])){echo $g2_image['g2ic_custom_class_2'];} else{echo "not_used";} ?>" size="30" / ><br />
</td><td>
<?php _e('4. ', 'wpg2') ?><input name="g2_image[g2ic_custom_class_4]" id="g2ic_custom_class_4" value="<?php if(isset($g2_image['g2ic_custom_class_4'])){echo $g2_image['g2ic_custom_class_4'];} else{echo "not_used";} ?>" size="30" / ><br />
</td></tr></table></td></tr></table>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes', 'wpg2') ?>" />
</p>
</form>
</div>
<?php
} else {
?><div id="message" class="error"><p><strong><?php _e('Options not available until WPG2 Plugin is Validated.', 'wpg2') ?></strong></p></div>
<?php
}
}
/**
* Sets g2image Defaults
*
* @param None
* @return None
*/
function g2image_setdefaults() {
$g2_image['g2ic_images_per_page'] = 15;
$g2_image['g2ic_display_filenames'] = "no";
$g2_image['g2ic_default_alignment'] = 'none';
$g2_image['g2ic_custom_class_1'] = 'not_used';
$g2_image['g2ic_custom_class_2'] = 'not_used';
$g2_image['g2ic_custom_class_3'] = 'not_used';
$g2_image['g2ic_custom_class_4'] = 'not_used';
$g2_image['g2ic_custom_url'] = 'http://';
$g2_image['g2ic_class_mode'] = 'img';
$g2_image['g2ic_click_mode'] = 'one_click_insert';
$g2_image['g2ic_click_mode_variable'] = "yes";
$g2_image['g2ic_wpg2id_tags'] = 'yes';
$g2_image['g2ic_default_action'] = 'wpg2_image';
$g2_image['g2ic_sortby'] = 'title_asc';
// Get WPG2 Archive IF Exists and repopulate
$g2ic_archive = get_option('wpg2_g2ic_30_archive');
if (!empty($g2ic_archive)) {
foreach ($g2ic_archive as $key=>$value){
$g2_image[$key] = $value;
}
// delete_option('wpg2_g2ic_30_archive');
}
update_option('wpg2_g2ic', $g2_image);
}
/**
* Stores G2IC Defaults on Deactivation
*
* @param None
* @return None
*/
function g2image_deactivation() {
// Get Gallery2 IC Option Settings
$g2_image = get_option('wpg2_g2ic');
$g2ic_archive['g2ic_images_per_page'] = $g2_image['g2ic_images_per_page'];
$g2ic_archive['g2ic_display_filenames'] = $g2_image['g2ic_display_filenames'];
$g2ic_archive['g2ic_default_alignment'] = $g2_image['g2ic_default_alignment'];
$g2ic_archive['g2ic_custom_class_1'] = $g2_image['g2ic_custom_class_1'];
$g2ic_archive['g2ic_custom_class_2'] = $g2_image['g2ic_custom_class_2'];
$g2ic_archive['g2ic_custom_class_3'] = $g2_image['g2ic_custom_class_3'];
$g2ic_archive['g2ic_custom_class_4'] = $g2_image['g2ic_custom_class_4'];
$g2ic_archive['g2ic_custom_url'] = $g2_image['g2ic_custom_url'];
$g2ic_archive['g2ic_class_mode'] = $g2_image['g2ic_class_mode'];
$g2ic_archive['g2ic_click_mode'] = $g2_image['g2ic_click_mode'];
$g2ic_archive['g2ic_click_mode_variable'] = $g2_image['g2ic_click_mode_variable'];
$g2ic_archive['g2ic_wpg2id_tags'] = $g2_image['g2ic_wpg2id_tags'];
$g2ic_archive['g2ic_default_action'] = $g2_image['g2ic_default_action'];
$g2ic_archive['g2ic_sortby'] = $g2_image['g2ic_sortby'];
// Save the WPG2 Options into WPG2 Archive
update_option('wpg2_g2ic_30_archive', $g2ic_archive);
// Delete GIC Option
delete_option('wpg2_g2ic');
}
/*
********************************************************************************************************
TINYMCE
********************************************************************************************************
*/
/**
* Adds g2image to the TinyMCE button bar
*
* @param string $buttons the buttons string from the WP filter
* @return string the appended buttons string
*/
function g2image_wp_extended_editor_mce_buttons($buttons) {
array_push($buttons, 'separator', 'g2image');
return $buttons;
}
/**
* Adds g2image to the TinyMCE button Toolbar
*
* @param null
* @return null
*/
function g2image_addbuttons() {
// Don't bother doing this stuff if the current user lacks permissions
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
return;
// Add only in Rich Editor mode
if ( get_user_option('rich_editing') == 'true') {
add_filter("mce_external_plugins", "g2image_plugin");
add_filter('mce_buttons', 'g2image_wp_extended_editor_mce_buttons');
}
}
/**
* Adds g2image to the TinyMCE plugins list
*
* @param string $plugins the buttons string from the WP filter
* @return string the appended plugins string
*/
function g2image_plugin($plugin_array) {
$plugin_array['g2image'] = get_bloginfo('wpurl').'/wp-content/plugins/wpg2/g2image/editor_plugin.js';
return $plugin_array;
}
/**
* Adds Additional WPG2 Specific Elements to the TinyMCE valid elements list
*
* @param string $valid_elements the valid elements string from the WP filter
* @return string the appended valid elements string
*/
function g2image_wp_extended_editor_mce_valid_elements($valid_elements) {
$valid_elements .= 'wpg2,wpg2id,div[class]';
return $valid_elements;
}
/**
* Adds WPG2 Button to Wordpress Selected (Typically Write) Screens
*
* Javascript appended to the bottom of the "Write Post" or "Write Page" admin pages for the WPG2 quicktag.
*/
function g2image_callback() {
$g2image_url = get_bloginfo('wpurl').'/wp-content/plugins/wpg2/g2image/';
// Only add the javascript to post.php, post-new.php, page.php, page-new.php, or bookmarklet.php pages
if (strpos($_SERVER['REQUEST_URI'], 'post.php') ||
strpos($_SERVER['REQUEST_URI'], 'post-new.php') ||
strpos($_SERVER['REQUEST_URI'], 'page.php') ||
strpos($_SERVER['REQUEST_URI'], 'page-new.php') ||
strpos($_SERVER['REQUEST_URI'], 'bookmarklet.php')) {
?>
<script language="JavaScript" type="text/javascript"><!--
var g2_toolbar = document.getElementById("ed_toolbar");
<?php
g2image_edit_insert_button(__('WPG2', 'wpg2'), 'g2_open', __('Gallery2 Image Chooser', 'g2image'));
?>
function g2_open() {
var form = 'post';
var field = 'content';
var url = '<?php echo $g2image_url; ?>g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var name = 'g2image';
var w = 800;
var h = 600;
var valLeft = (screen.width) ? (screen.width-w)/2 : 0;
var valTop = (screen.height) ? (screen.height-h)/2 : 0;
var features = 'width='+w+',height='+h+',left='+valLeft+',top='+valTop+',resizable=1,scrollbars=1';
var g2imageWindow = window.open(url, name, features);
g2imageWindow.focus();
}
//--></script>
<?php
}
}
if(!function_exists('g2image_edit_insert_button')) {
//edit_insert_button: Inserts a button into the editor
function g2image_edit_insert_button($caption, $js_onclick, $title = '') {
?>
if(g2_toolbar){
var theButton = document.createElement('input');
theButton.type = 'button';
theButton.value = '<?php echo $caption; ?>';
theButton.onclick = <?php echo $js_onclick; ?>;
theButton.className = 'ed_button';
theButton.title = "<?php echo $title; ?>";
theButton.id = "<?php echo "ed_{$caption}"; ?>";
g2_toolbar.appendChild(theButton);
}
<?php
}
}
?>