-
Notifications
You must be signed in to change notification settings - Fork 2
/
wpg2validate.inc
408 lines (359 loc) · 16.9 KB
/
wpg2validate.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<?php
/*
Author: WPG2 Team
Updated: 12:09 3/05/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.
*/
/*
* Performs a Series of Checks to Ensure WPG2 will function within the Wordpress/Gallery2 Environment
*
* @param NULL
* @return string $html The album tree HTML
*/
function wpg2_validate($wpg2_outputtype) {
global $wp_db_version;
//If we're setting options,
if ( isset($_POST['action']) ) {
$wpg2_option = get_option('wpg2_options');
// Option Saving Time
foreach ($_POST['wpg2_options'] as $key=>$value){
$wpg2_option[$key] = $value;
}
update_option('wpg2_options', $wpg2_option);
}
// Initialisation
$validate_err=0;
$validate_warning=0;
//Get Current Gallery2 Plug-in Options
$wpg2_option = get_option('wpg2_options');
$wpg2_g2path = get_option('wpg2_g2paths');
// Do We Have Paths?
if (empty($wpg2_g2path['g2_filepath']) || empty($wpg2_g2path['wpg2_relativepath']) ) {
$ret = wpg2_simple_find_paths();
if (!$ret) {
// Clean up Permalink Structure
wpg2_trimpermalinkrules();
// Verify WPG2 Internal g2_embeduri setting
wpg2_template_page();
$wpg2_g2path = get_option('wpg2_g2paths');
}
}
// Test Wordpress Version
$environment_html = '<strong>';
$environment_html .= __('1. Wordpress Compatible? - [' , 'wpg2');
if ($wp_db_version >=$wpg2_option['g2_wpversion_low']) {
$environment_html .= '<font color="green">' . __(' Success', 'wpg2') . '</font>';
} else {
define("WPVERSIONERR", "True");
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '</font>';
$validate_err=1;
}
$environment_html .= '] <br />';
// Test Gallery2 URL
if (!$validate_err) {
$environment_html .= __('2. URI to Gallery2 Ok? - [' , 'wpg2');
$ret = wpg2_validateuri($wpg2_g2path['g2_url'].'embed.php');
if (!$ret) {
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
} else {
define("G2EMBEDERR", "True");
$validate_warning=1;
$reterr = $ret;
$environment_html .= '<font color="orange">' . __('Warning', 'wpg2') . '</font>';
}
$environment_html .= '] <br />';
}
// Gallery Ok?
if (!$validate_err) {
$environment_html .= __('3. Gallery2 can be located in G2 File Path? - [', 'wpg2');
if (file_exists( $wpg2_g2path['g2_filepath'].'embed.php' ) )
$environment_html .= '<font color="green">' . __('Success', 'wpg2').'</font>';
else {
$environment_html .= '<font color="red">' . __('Failed', 'wpg2').'</font>';
define("G2PATHERR", "True");
$validate_err=1;
}
$environment_html .= '] <br />';
}
// Test Initialise G2
if (!$validate_err) {
$environment_html .= __('4. Gallery2 can be initialised? - [', 'wpg2');
if (!defined('G2INIT')) {
$ret = g2_init();
if (!$ret)
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
else {
define("G2INITERR", "True");
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '-><font>';
$validate_err=1;
}
} else {
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
}
$environment_html .= '] <br />';
}
// Test G2 Version
if (!$validate_err) {
$environment_html .= __('5. Gallery2 Version Compatible? - [' , 'wpg2');
list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core', true);
$g2version = $core->getInstalledVersions();
$g2version = substr($g2version['gallery'],0,3);
if ($wpg2_option['g2_version_low'] <= $g2version)
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
else {
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '</font>';
define("G2VERERR", "True");
$validate_err=1;
}
$environment_html .= '] <br />';
}
// ImageBlock Active?
if (!$validate_err) {
$environment_html .= __('6. Gallery2 Module: ImageBlock Active? - [' , 'wpg2');
$g2_image_block_active = 0;
$g2_moduleid = 'imageblock';
list ($ret, $g2_modulestatus ) = GalleryCoreApi::fetchPluginStatus('module');
if (!$ret) {
if (isset($g2_modulestatus[$g2_moduleid]) && !empty($g2_modulestatus[$g2_moduleid]['active']) && $g2_modulestatus[$g2_moduleid]['active'])
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
else {
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '</font>';
define("G2IMAGEBLOCKERR", "True");
$validate_err=1;
}
}
$environment_html .= '] <br />';
}
// Test ImageBlock Version
if (!$validate_err) {
$environment_html .= __('7. Gallery2 Module: ImageBlock Version Compatible? - [', 'wpg2');
GalleryCoreApi::requireOnce('modules/imageblock/module.inc');
GalleryCoreApi::requireOnce('modules/core/classes/GalleryRepositoryUtilities.class');
$plugin = new ImageBlockModule;
$version = $plugin->getVersion();
$version_comparison = GalleryRepositoryUtilities::compareRevisions($version,$wpg2_option['g2_imageblock_version_low']);
if ($version_comparison != 'older') {
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
} else {
define("G2IMAGEBLOCKVERSIONERR", "True");
$validate_warning=1;
$reterr = $ret;
$environment_html .= '<font color="orange">' . __('Warning', 'wpg2') . '</font>';
}
$environment_html .= '] <br />';
}
// ImageFrame Active?
if (!$validate_err) {
$environment_html .= __('8. Gallery2 Module: ImageFrame Active? - [' , 'wpg2');
$g2_image_block_active = 0;
$g2_moduleid = 'imageframe';
if (!$ret) {
if (isset($g2_modulestatus[$g2_moduleid]) && !empty($g2_modulestatus[$g2_moduleid]['active']) && $g2_modulestatus[$g2_moduleid]['active'])
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
else {
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '</font>';
define("G2IMAGEFRAMEERR", "True");
$validate_err=1;
}
}
$environment_html .= '] <br />';
}
// ImageFrame can be found in Relative Path?
if (!$validate_err) {
$environment_html .= __('9. Gallery2 to WPG2 Relative Path Validate? - [' , 'wpg2');
if (file_exists($wpg2_g2path['g2_filepath'].$wpg2_g2path['wpg2_relativepath'].DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.'wpg2imageblock.tpl' ) ) {
$environment_html .= '<font color="green">' . __('Success', 'wpg2') . '</font>';
} else {
$environment_html .= '<font color="red">' . __('Failed', 'wpg2') . '</font>';
define("G2RELPATHERR", "True");
$validate_err=1;
}
$environment_html .= '] <br /></strong></td></tr>';
}
// End Validation Checks
if (!$validate_err) {
$environment_html .= '<tr><td><font size="4">' . __('WPG2 Page Generation Rules: ', 'wpg2') . ' </font><a href="'.$wpg2_g2path['g2_embeduri'].'">'.'(View WPG2 Output Page »)</a><strong><br />';
// WPG2 Page Output Type?
$environment_html .= __('1. WPG2 Output Style? - [', 'wpg2');
if ( $wpg2_option['g2_embedpagetype'] == 'wordpress' ) {
$environment_html .= '<font color="green">' . __('Look like a Wordpress Page', 'wpg2'). '</font>';
} else {
$environment_html .= '<font color="green">' . __('Look like a Gallery2 Page', 'wpg2'). '</font>';
}
$environment_html .= '] <br />';
// WPG2 / Gallery Rewrites Active?
$environment_html .= __('2. WPG2 Gallery2 Rewrites Status? - [', 'wpg2');
if ($wpg2_option['g2_rewriteactive'] == 'active') {
$environment_html .= '<font color="green">' . __('On', 'wpg2'). '</font>';
} else {
if ($wpg2_option['g2_rewriteactive'] == 'safe')
$environment_html .= '<font color="green">' . __('Off [Safe]', 'wpg2'). '</font>';
else
$environment_html .= '<font color="green">' . __('Off', 'wpg2'). '</font>';
}
$environment_html .= '] <br />';
// Custom Header?
$environment_html .= __('3. Embedded Page is using what Header type? - [', 'wpg2');
if ( file_exists( TEMPLATEPATH . '/wpg2header.php') ) {
$environment_html .= '<font color="green">' . __('WPG2HEADER', 'wpg2'). '</font>';
$wpg2_option['g2_externalheader'] = "Yes";
} else {
if ($wpg2_option['g2_embedpagetype'] != 'gallery2' )
define('WPSIMPLEHEADER',"True");
$environment_html .= '<font color="green">' . __('Simple', 'wpg2'). '</font>';
$wpg2_option['g2_externalheader'] = "No";
}
$environment_html .= '] <br />';
// Custom Footer?
$environment_html .= __('4. Embedded Page is using what Footer type? - [', 'wpg2');
if ( file_exists( TEMPLATEPATH . '/wpg2footer.php') ) {
$environment_html .= '<font color="green">' . __('WPG2FOOTER', 'wpg2'). '</font>';
$wpg2_option['g2_externalfooter'] = "Yes";
} else {
$environment_html .= '<font color="green">' . __('Simple', 'wpg2'). '</font>';
$wpg2_option['g2_externalfooter'] = "No";
}
$environment_html .= '] <br />';
// External WPG2 CSS
$environment_html .= __('5. Using Which WPG2 Stylesheet? - [', 'wpg2');
if ( file_exists( TEMPLATEPATH . '/wpg2.css') ) {
$environment_html .= '<font color="green">' . __('External', 'wpg2'). '</font>';
$wpg2_option['g2_externalcss'] = "Yes";
} else {
$environment_html .= '<font color="green">' . __('Internal', 'wpg2'). '</font>';
$wpg2_option['g2_externalcss'] = "";
}
$environment_html .= '] </strong></td></tr>';
}
$environment_html .= '</table>';
if ($validate_err)
$wpg2_option['g2_validated'] = "No";
else {
if (!$wpg2_option['g2_rewriteactive'] == 'active') {
$g2_moduleid = 'rewrite';
list ($ret, $g2_modulestatus ) = GalleryCoreApi::fetchPluginStatus('module');
if (!$ret && isset($g2_modulestatus[$g2_moduleid]) && !empty($g2_modulestatus[$g2_moduleid]['active']) && $g2_modulestatus[$g2_moduleid]['active']) {
// Deactivate Rewrite Module as Wordpress Permalink Array will be wrong.
list ($ret, $ignored) = GalleryCoreApi::deactivatePlugin('module', 'rewrite');
if (!$ret)
define("G2REWRITEDEACTIVATED", "True");
}
}
$wpg2_option['g2_validated'] = "Yes";
// Close Gallery Connection
GalleryEmbed::done();
}
// Update the Options
update_option('wpg2_options', $wpg2_option);
// Add BTEV Event Message
if (function_exists('btev_trigger_error')) {
btev_trigger_error('WPG2 VALIDATION ('.$wpg2_option['g2_validated'].') ', E_USER_NOTICE, __FILE__);
}
//Output Status
if ($wpg2_outputtype != "silent") {
echo '<div class="wrap">';
echo '<h2>'. __('WPG2 Dashboard').'</font><font size="2"> <a href="http://codex.gallery2.org/Integration:WPG2_Options_-_Validation" rel="external">'. __('(Help)', 'wpg2').'</a></font></h2>';
?>
<form name="g2options" method="post" action="">
<table cellspacing="1" cellpadding="5" class="form-table">
<input type="hidden" name="action" value="update" />
<tr valign="top">
<td><strong><?php _e('Should Gallery2 Page(s) look like a Wordpress Page?', 'wpg2') ?>
<?php _e('Yes', 'wpg2') ?>
<input name="wpg2_options[g2_embedpagetype]" type="radio" value="wordpress" <?php if ($wpg2_option['g2_embedpagetype'] == 'wordpress'){echo "checked ";}?> />
<?php _e(' No', 'wpg2') ?>
<input name="wpg2_options[g2_embedpagetype]" type="radio" value="gallery2" <?php if ($wpg2_option['g2_embedpagetype'] == 'gallery2'){echo "checked ";}?> />
</strong>  
<input type="submit" name="Submit" value="<?php _e('Change', 'wpg2') ?>" />
</td></tr>
</table>
</form>
<?php
echo "<table cellpadding=1 cellspacing=0 class='form-table'>";
if ($validate_err){
echo '<tr><td><font size="4">' . __('WPG2 Validation Check: ', 'wpg2') . '<font color="red">' . __('Failed', 'wpg2') . '</font> <a href="http://codex.gallery2.org/Integration:WPG2_Options_-_Validation" rel="external">'. __('(Help)', 'wpg2').'</a></font><br />';
echo $environment_html;
} else {
echo '<tr><td><font size="4">' . __('WPG2 Validation Check: ', 'wpg2') . '<font color="green">' . __('Valid', 'wpg2') . '</font> <a href="http://codex.gallery2.org/Integration:WPG2_Options_-_Validation" rel="external">'. __('(Help)', 'wpg2').'</a></font><br />';
echo $environment_html;
}
if (defined('WPVERSIONERR')) {
echo '<div id = "wpversion_form">';
echo '<br /><h2>' . __('Error: Wordpress Build is NOT Compatible', 'wpg2').'</h2>'. __(' WPG2 ','wpg2').$wpg2_option['g2_wpg2version'];
_e(' requires a minimum Wordpress build of ', 'wpg2');
echo $wpg2_option['g2_wpversion_low'];
_e (' and has detected your Wordpress build ', 'wpg2');
echo $wp_db_version;
_e (' does not meet the minimum build requirement.', 'wpg2');
echo '<br /><br /></div>';
}
if (defined('G2EMBEDERR')) {
echo '<div id = "g2embed_form">';
echo '<br /><h3>'. __('Warning: Possible invalid URL to Gallery2', 'wpg2').'</h3>'. __('Possible Validation Problem of Gallery2 URL. The error returned reads: "', 'wpg2').$reterr.'"<br /><br />';
echo '</div>';
}
if (defined('G2PATHERR')) {
echo '<div id = "g2path_form">';
echo '<br /><h2>'. __('Error: embed.php cannot be located in the specified File Path.', 'wpg2').'</h2>';
_e('WPG2 plugin cannot locate the Gallery2 installation.<br /><br />Upon activation, WPG2 automatically looks for your Gallery2 installation in (Domain URL)/gallery2/, (Domain URL)/gallery/, (Domain URL)/photos/, (WordPress URL)/gallery2/, (WordPress URL)/gallery/, and (WordPress URL)/photos/. If your Gallery2 installation is in another directory, please go to the "WPG2 Paths" tab and enter your Gallery2 URL. ', 'wpg2');
echo ($wpg2_g2path['g2_filepath']). __('embed.php', 'wpg2').'<br /><br />';
echo '</div>';
}
if (defined('G2INITERR')) {
echo '<div id = "g2init_form">';
echo '<br /><h2>'. __('Error: Gallery2 cannot be initialised', 'wpg2').'</h2>'. __('Check to ensure Gallery2 is correctly working and revalidate.', 'wpg2').'<br />';
echo $ret.'<br /><br />';
echo '</div>';
}
if (defined('G2VERERR')) {
echo '<div id = "g2version_form">';
echo '<br /><h2>'. __('Error: Gallery2 version is incompatible','wpg2').'</h2>'. __('WPG2 plugin requires at least Gallery2 version ', 'wpg2');
echo $wpg2_option['g2_version_low']. __(', Gallery2 reports you are running version ','wpg2');
echo $g2version.'<br /><br />';
echo '</div>';
}
if (defined('G2IMAGEBLOCKERR')) {
echo '<div id = "g2imageblock_form">';
echo '<br /><h2>'. __('Error: Gallery2 Imageblock plugin is not activated','wpg2').'</h2>'. __('Ensure the Gallery2 ImageBlock is installed / activated via the Gallery2 Site Admin -> Plugin Panel.', 'wpg2').'<br /><br />';
echo $ret;
echo '</div>';
}
if (defined('G2IMAGEBLOCKVERSIONERR')) {
echo '<div id = "g2imageblock_form">';
echo '<br /><h3>'. __('Warning: Gallery2 Imageblock plugin is an old version.','wpg2').'</h3>'. __('Please update to the most recent version from your Gallery2 page: Site Admin -> Plugins.<br />If you do not upgrade the ImageBlock plugin, you will not be able to use the size option with WPG2 tags.', 'wpg2').'<br /><br />';
echo $ret;
echo '</div>';
}
if (defined('G2IMAGEFRAMEERR')) {
echo '<div id = "g2imageframe_form">';
echo '<br /><h2>'. __('Error: Gallery2 Imageframe plugin is not activated','wpg2').'</h2>'. __('Ensure the Gallery2 ImageFrame is installed / activated via the Gallery2 Site Admin -> Plugin Panel.', 'wpg2').'<br /><br />';
echo $ret;
echo '</div>';
}
if (defined('G2RELPATHERR')) {
echo '<div id = "g2path_form">';
echo '<br /><h2>'. __('Error: Gallery2 to WPG2 relative Path cannot be validated','wpg2').'</h2>'. __('The file wpg2imageblock.tpl must be within this path ', 'wpg2');
echo $wpg2_g2path['g2_filepath'].$wpg2_g2path['wpg2_relativepath'].DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.'wpg2imageblock.tpl'.__(' as specified in the <strong>Gallery2 to WPG2 Relative Path</strong> in WPG2 Paths Tab','wpg2').'<br /><br />';
echo '</div>';
}
if (defined('G2REWRITEDEACTIVATED')) {
echo '<div id = "simpleheader_form">';
echo '<br /><h3>'. __('Warning: Gallery2 Rewrite Plugin was deactived','wpg2').'</h3>'. __('WPG2 has automatically deactivated the Gallery2 Rewrite Plugin, to reactive, enable Gallery2 Rewrites in the WPG2 Gallery2 Rewrites Tab.','wpg2').'<br /><br />';
echo '</div>';
}
if (defined('WPSIMPLEHEADER')) {
echo '<div id = "simpleheader_form">';
echo '<h3>'. __('Warning: Using the Simple Header','wpg2').'</h3>'. __('WPG2 will generate your Wordpress header using the CSS Elements specified in the WPG2 Output options. For some Wordpress themes this will incorrectly distort the output from Gallery2 and instead you may need to create your own WPG2 Header.','wpg2').'<br /><br />';
echo '</div>';
}
echo '</div></div>';
}
}
?>