1 | <?php |
---|
2 | |
---|
3 | function url_shorten ($url) { |
---|
4 | $short_url = str_replace('http://', '', stripslashes($url)); |
---|
5 | $short_url = str_replace('www.', '', $short_url); |
---|
6 | if ('/' == substr($short_url, -1)) |
---|
7 | $short_url = substr($short_url, 0, -1); |
---|
8 | if (strlen($short_url) > 35) |
---|
9 | $short_url = substr($short_url, 0, 32).'...'; |
---|
10 | return $short_url; |
---|
11 | } |
---|
12 | |
---|
13 | function selected($selected, $current) { |
---|
14 | if ($selected == $current) echo ' selected="selected"'; |
---|
15 | } |
---|
16 | |
---|
17 | function checked($checked, $current) { |
---|
18 | if ($checked == $current) echo ' checked="checked"'; |
---|
19 | } |
---|
20 | |
---|
21 | function return_categories_list( $parent = 0, $sortbyname = FALSE ) |
---|
22 | { |
---|
23 | /* |
---|
24 | * This function returns an list of all categories |
---|
25 | * that have $parent as their parent |
---|
26 | * if no parent is specified we will assume top level caegories |
---|
27 | * are required. |
---|
28 | */ |
---|
29 | global $wpdb; |
---|
30 | |
---|
31 | // select sort order |
---|
32 | $sort = "cat_id"; |
---|
33 | if( TRUE == $sortbyname ) |
---|
34 | { |
---|
35 | $sort = "cat_name"; |
---|
36 | } |
---|
37 | |
---|
38 | // First query the database |
---|
39 | $cats_tmp = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY $sort"); |
---|
40 | |
---|
41 | // Now strip this down to a simple array of IDs |
---|
42 | $cats = array(); |
---|
43 | if( count($cats_tmp) > 0 ) |
---|
44 | { |
---|
45 | foreach( $cats_tmp as $cat ) |
---|
46 | { |
---|
47 | $cats[] = $cat->cat_ID; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | // Return the list of categories |
---|
52 | return $cats; |
---|
53 | } |
---|
54 | |
---|
55 | function get_nested_categories($default = 0, $parent = 0) { |
---|
56 | global $post_ID, $mode, $wpdb; |
---|
57 | |
---|
58 | if ($post_ID) { |
---|
59 | $checked_categories = $wpdb->get_col(" |
---|
60 | SELECT category_id |
---|
61 | FROM $wpdb->categories, $wpdb->post2cat |
---|
62 | WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' |
---|
63 | "); |
---|
64 | |
---|
65 | if(count($checked_categories) == 0) |
---|
66 | { |
---|
67 | // No selected categories, strange |
---|
68 | $checked_categories[] = $default; |
---|
69 | } |
---|
70 | |
---|
71 | } else { |
---|
72 | $checked_categories[] = $default; |
---|
73 | } |
---|
74 | |
---|
75 | $cats = return_categories_list($parent, TRUE); |
---|
76 | $result = array(); |
---|
77 | |
---|
78 | foreach($cats as $cat) |
---|
79 | { |
---|
80 | $result[$cat]['children'] = get_nested_categories($default, $cat); |
---|
81 | $result[$cat]['cat_ID'] = $cat; |
---|
82 | $result[$cat]['checked'] = in_array($cat, $checked_categories); |
---|
83 | $result[$cat]['cat_name'] = get_the_category_by_ID($cat); |
---|
84 | } |
---|
85 | |
---|
86 | return $result; |
---|
87 | } |
---|
88 | |
---|
89 | function write_nested_categories($categories) { |
---|
90 | foreach($categories as $category) { |
---|
91 | echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], |
---|
92 | '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', |
---|
93 | ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n"; |
---|
94 | |
---|
95 | if(isset($category['children'])) { |
---|
96 | echo "\n<span class='cat-nest'>\n"; |
---|
97 | write_nested_categories($category['children']); |
---|
98 | echo "</span>\n"; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | function dropdown_categories($default = 0) { |
---|
104 | write_nested_categories(get_nested_categories($default)); |
---|
105 | } |
---|
106 | |
---|
107 | // Dandy new recursive multiple category stuff. |
---|
108 | function cat_rows($parent = 0, $level = 0, $categories = 0) { |
---|
109 | global $wpdb, $class, $user_level; |
---|
110 | if (!$categories) |
---|
111 | $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name"); |
---|
112 | |
---|
113 | if ($categories) { |
---|
114 | foreach ($categories as $category) { |
---|
115 | if ($category->category_parent == $parent) { |
---|
116 | $category->cat_name = wp_specialchars($category->cat_name); |
---|
117 | $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); |
---|
118 | $pad = str_repeat('— ', $level); |
---|
119 | if ( $user_level > 3 ) |
---|
120 | $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=delete&cat_ID=$category->cat_ID' onclick=\"return confirm('". sprintf(__("You are about to delete the category \'%s\'. All of its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop."), addslashes($category->cat_name)) . "')\" class='delete'>" . __('Delete') . "</a>"; |
---|
121 | else |
---|
122 | $edit = ''; |
---|
123 | |
---|
124 | $class = ('alternate' == $class) ? '' : 'alternate'; |
---|
125 | echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td> |
---|
126 | <td>$category->category_description</td> |
---|
127 | <td>$count</td> |
---|
128 | <td>$edit</td> |
---|
129 | </tr>"; |
---|
130 | cat_rows($category->cat_ID, $level + 1, $categories); |
---|
131 | } |
---|
132 | } |
---|
133 | } else { |
---|
134 | return false; |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | function page_rows( $parent = 0, $level = 0, $pages = 0 ) { |
---|
139 | global $wpdb, $class, $user_level, $post; |
---|
140 | if (!$pages) |
---|
141 | $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static' ORDER BY menu_order"); |
---|
142 | |
---|
143 | if ($pages) { |
---|
144 | foreach ($pages as $post) { start_wp(); |
---|
145 | if ($post->post_parent == $parent) { |
---|
146 | $post->post_title = wp_specialchars($post->post_title); |
---|
147 | $pad = str_repeat('— ', $level); |
---|
148 | $id = $post->ID; |
---|
149 | $class = ('alternate' == $class) ? '' : 'alternate'; |
---|
150 | ?> |
---|
151 | <tr class='<?php echo $class; ?>'> |
---|
152 | <th scope="row"><?php echo $post->ID; ?></th> |
---|
153 | <td> |
---|
154 | <?php echo $pad; ?><?php the_title() ?> |
---|
155 | </td> |
---|
156 | <td><?php the_author() ?></td> |
---|
157 | <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td> |
---|
158 | <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td> |
---|
159 | <td><?php if (($user_level > $authordata->user_level) or ($user_login == $authordata->user_login)) { echo "<a href='post.php?action=edit&post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td> |
---|
160 | <td><?php if (($user_level > $authordata->user_level) or ($user_login == $authordata->user_login)) { echo "<a href='post.php?action=delete&post=$id' class='delete' onclick=\"return confirm('" . sprintf(__("You are about to delete this post \'%s\'\\n \'OK\' to delete, \'Cancel\' to stop."), the_title('','',0)) . "')\">" . __('Delete') . "</a>"; } ?></td> |
---|
161 | </tr> |
---|
162 | |
---|
163 | <?php |
---|
164 | page_rows($id, $level + 1, $pages); |
---|
165 | } |
---|
166 | } |
---|
167 | } else { |
---|
168 | return false; |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) { |
---|
173 | global $wpdb, $bgcolor; |
---|
174 | if (!$categories) { |
---|
175 | $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name"); |
---|
176 | } |
---|
177 | if ($categories) { |
---|
178 | foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { |
---|
179 | $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); |
---|
180 | $pad = str_repeat('– ', $level); |
---|
181 | $category->cat_name = wp_specialchars($category->cat_name); |
---|
182 | echo "\n\t<option value='$category->cat_ID'"; |
---|
183 | if ($currentparent == $category->cat_ID) |
---|
184 | echo " selected='selected'"; |
---|
185 | echo ">$pad$category->cat_name</option>"; |
---|
186 | wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level + 1, $categories); |
---|
187 | } } |
---|
188 | } else { |
---|
189 | return false; |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | function wp_create_thumbnail($file, $max_side, $effect = '') { |
---|
194 | |
---|
195 | // 1 = GIF, 2 = JPEG, 3 = PNG |
---|
196 | |
---|
197 | if(file_exists($file)) { |
---|
198 | $type = getimagesize($file); |
---|
199 | |
---|
200 | // if the associated function doesn't exist - then it's not |
---|
201 | // handle. duh. i hope. |
---|
202 | |
---|
203 | if(!function_exists('imagegif') && $type[2] == 1) { |
---|
204 | $error = __('Filetype not supported. Thumbnail not created.'); |
---|
205 | }elseif(!function_exists('imagejpeg') && $type[2] == 2) { |
---|
206 | $error = __('Filetype not supported. Thumbnail not created.'); |
---|
207 | }elseif(!function_exists('imagepng') && $type[2] == 3) { |
---|
208 | $error = __('Filetype not supported. Thumbnail not created.'); |
---|
209 | } else { |
---|
210 | |
---|
211 | // create the initial copy from the original file |
---|
212 | if($type[2] == 1) { |
---|
213 | $image = imagecreatefromgif($file); |
---|
214 | } elseif($type[2] == 2) { |
---|
215 | $image = imagecreatefromjpeg($file); |
---|
216 | } elseif($type[2] == 3) { |
---|
217 | $image = imagecreatefrompng($file); |
---|
218 | } |
---|
219 | |
---|
220 | if (function_exists('imageantialias')) |
---|
221 | imageantialias($image, TRUE); |
---|
222 | |
---|
223 | $image_attr = getimagesize($file); |
---|
224 | |
---|
225 | // figure out the longest side |
---|
226 | |
---|
227 | if($image_attr[0] > $image_attr[1]) { |
---|
228 | $image_width = $image_attr[0]; |
---|
229 | $image_height = $image_attr[1]; |
---|
230 | $image_new_width = $max_side; |
---|
231 | |
---|
232 | $image_ratio = $image_width/$image_new_width; |
---|
233 | $image_new_height = $image_height/$image_ratio; |
---|
234 | //width is > height |
---|
235 | } else { |
---|
236 | $image_width = $image_attr[0]; |
---|
237 | $image_height = $image_attr[1]; |
---|
238 | $image_new_height = $max_side; |
---|
239 | |
---|
240 | $image_ratio = $image_height/$image_new_height; |
---|
241 | $image_new_width = $image_width/$image_ratio; |
---|
242 | //height > width |
---|
243 | } |
---|
244 | |
---|
245 | $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); |
---|
246 | @imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); |
---|
247 | |
---|
248 | // move the thumbnail to it's final destination |
---|
249 | |
---|
250 | $path = explode('/', $file); |
---|
251 | $thumbpath = substr($file, 0, strrpos($file, '/')) . '/thumb-' . $path[count($path)-1]; |
---|
252 | |
---|
253 | if($type[2] == 1) { |
---|
254 | if(!imagegif($thumbnail, $thumbpath)) { |
---|
255 | $error = __("Thumbnail path invalid"); |
---|
256 | } |
---|
257 | } elseif($type[2] == 2) { |
---|
258 | if(!imagejpeg($thumbnail, $thumbpath)) { |
---|
259 | $error = __("Thumbnail path invalid"); |
---|
260 | } |
---|
261 | } elseif($type[2] == 3) { |
---|
262 | if(!imagepng($thumbnail, $thumbpath)) { |
---|
263 | $error = __("Thumbnail path invalid"); |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | if(!empty($error)) |
---|
271 | { |
---|
272 | return $error; |
---|
273 | } |
---|
274 | else |
---|
275 | { |
---|
276 | return 1; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | // Some postmeta stuff |
---|
281 | function has_meta($postid) { |
---|
282 | global $wpdb; |
---|
283 | |
---|
284 | return $wpdb->get_results(" |
---|
285 | SELECT meta_key, meta_value, meta_id, post_id |
---|
286 | FROM $wpdb->postmeta |
---|
287 | WHERE post_id = '$postid' |
---|
288 | ORDER BY meta_key,meta_id",ARRAY_A); |
---|
289 | |
---|
290 | } |
---|
291 | |
---|
292 | function list_meta($meta) { |
---|
293 | global $post_ID; |
---|
294 | // Exit if no meta |
---|
295 | if (!$meta) return; |
---|
296 | $count = 0; |
---|
297 | ?> |
---|
298 | <table id='meta-list' cellpadding="3"> |
---|
299 | <tr> |
---|
300 | <th><?php _e('Key') ?></th> |
---|
301 | <th><?php _e('Value') ?></th> |
---|
302 | <th colspan='2'><?php _e('Action') ?></th> |
---|
303 | </tr> |
---|
304 | <?php |
---|
305 | |
---|
306 | foreach ($meta as $entry) { |
---|
307 | ++$count; |
---|
308 | if ( $count % 2 ) $style = 'alternate'; |
---|
309 | else $style = ''; |
---|
310 | if ( '_' == $entry['meta_key']{0} ) $style .= ' hidden'; |
---|
311 | echo " |
---|
312 | <tr class='$style'> |
---|
313 | <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td> |
---|
314 | <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td> |
---|
315 | <td align='center' width='10%'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='" . __('Update') ."' /></td> |
---|
316 | <td align='center' width='10%'><input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='" . __('Delete') ."' /></td> |
---|
317 | </tr> |
---|
318 | "; |
---|
319 | } |
---|
320 | echo " |
---|
321 | </table> |
---|
322 | "; |
---|
323 | } |
---|
324 | |
---|
325 | // Get a list of previously defined keys |
---|
326 | function get_meta_keys() { |
---|
327 | global $wpdb; |
---|
328 | |
---|
329 | $keys = $wpdb->get_col(" |
---|
330 | SELECT meta_key |
---|
331 | FROM $wpdb->postmeta |
---|
332 | GROUP BY meta_key |
---|
333 | ORDER BY meta_key"); |
---|
334 | |
---|
335 | return $keys; |
---|
336 | } |
---|
337 | |
---|
338 | function meta_form() { |
---|
339 | global $wpdb; |
---|
340 | $keys = $wpdb->get_col(" |
---|
341 | SELECT meta_key |
---|
342 | FROM $wpdb->postmeta |
---|
343 | GROUP BY meta_key |
---|
344 | ORDER BY meta_id DESC |
---|
345 | LIMIT 10"); |
---|
346 | ?> |
---|
347 | <h3><?php _e('Add a new custom field to this post:') ?></h3> |
---|
348 | <table cellspacing="3" cellpadding="3"> |
---|
349 | <tr> |
---|
350 | <th colspan="2"><?php _e('Key') ?></th> |
---|
351 | <th><?php _e('Value') ?></th> |
---|
352 | </tr> |
---|
353 | <tr valign="top"> |
---|
354 | <td align="right" width="18%"> |
---|
355 | <?php if ($keys) : ?> |
---|
356 | <select id="metakeyselect" name="metakeyselect" tabindex="7"> |
---|
357 | <option value="#NONE#"><?php _e('- Select -'); ?></option> |
---|
358 | <?php |
---|
359 | foreach($keys as $key) { |
---|
360 | echo "\n\t<option value='$key'>$key</option>"; |
---|
361 | } |
---|
362 | ?> |
---|
363 | </select> <?php _e('or'); ?> |
---|
364 | <?php endif; ?> |
---|
365 | </td> |
---|
366 | <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td> |
---|
367 | <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td> |
---|
368 | </tr> |
---|
369 | |
---|
370 | </table> |
---|
371 | <p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field »') ?>" /></p> |
---|
372 | <?php |
---|
373 | } |
---|
374 | |
---|
375 | function add_meta($post_ID) { |
---|
376 | global $wpdb; |
---|
377 | |
---|
378 | $metakeyselect = $wpdb->escape( stripslashes( trim($_POST['metakeyselect']) ) ); |
---|
379 | $metakeyinput = $wpdb->escape( stripslashes( trim($_POST['metakeyinput']) ) ); |
---|
380 | $metavalue = $wpdb->escape( stripslashes( trim($_POST['metavalue']) ) ); |
---|
381 | |
---|
382 | if (!empty($metavalue) && ((('#NONE#' != $metakeyselect) && !empty($metakeyselect)) || !empty($metakeyinput))) { |
---|
383 | // We have a key/value pair. If both the select and the |
---|
384 | // input for the key have data, the input takes precedence: |
---|
385 | |
---|
386 | if ('#NONE#' != $metakeyselect) |
---|
387 | $metakey = $metakeyselect; |
---|
388 | |
---|
389 | if ($metakeyinput) |
---|
390 | $metakey = $metakeyinput; // default |
---|
391 | |
---|
392 | $result = $wpdb->query(" |
---|
393 | INSERT INTO $wpdb->postmeta |
---|
394 | (post_id,meta_key,meta_value) |
---|
395 | VALUES ('$post_ID','$metakey','$metavalue') |
---|
396 | "); |
---|
397 | } |
---|
398 | } // add_meta |
---|
399 | |
---|
400 | function delete_meta($mid) { |
---|
401 | global $wpdb; |
---|
402 | |
---|
403 | $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'"); |
---|
404 | } |
---|
405 | |
---|
406 | function update_meta($mid, $mkey, $mvalue) { |
---|
407 | global $wpdb; |
---|
408 | |
---|
409 | return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'"); |
---|
410 | } |
---|
411 | |
---|
412 | function touch_time($edit = 1, $for_post = 1) { |
---|
413 | global $month, $postdata, $commentdata; |
---|
414 | if ( $for_post && ('draft' == $postdata->post_status) ) { |
---|
415 | $checked = 'checked="checked" '; |
---|
416 | $edit = false; |
---|
417 | } else { |
---|
418 | $checked = ' '; |
---|
419 | } |
---|
420 | |
---|
421 | echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" '.$checked.'/> <label for="timestamp">' . __('Edit timestamp') . '</label></legend>'; |
---|
422 | |
---|
423 | $time_adj = time() + (get_settings('gmt_offset') * 3600); |
---|
424 | $post_date = ($for_post) ? $postdata->post_date : $commentdata['comment_date']; |
---|
425 | $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj); |
---|
426 | $mm = ($edit) ? mysql2date('m', $post_date) : gmdate('m', $time_adj); |
---|
427 | $aa = ($edit) ? mysql2date('Y', $post_date) : gmdate('Y', $time_adj); |
---|
428 | $hh = ($edit) ? mysql2date('H', $post_date) : gmdate('H', $time_adj); |
---|
429 | $mn = ($edit) ? mysql2date('i', $post_date) : gmdate('i', $time_adj); |
---|
430 | $ss = ($edit) ? mysql2date('s', $post_date) : gmdate('s', $time_adj); |
---|
431 | |
---|
432 | echo "<select name=\"mm\">\n"; |
---|
433 | for ($i=1; $i < 13; $i=$i+1) { |
---|
434 | echo "\t\t\t<option value=\"$i\""; |
---|
435 | if ($i == $mm) |
---|
436 | echo " selected='selected'"; |
---|
437 | if ($i < 10) { |
---|
438 | $ii = "0".$i; |
---|
439 | } else { |
---|
440 | $ii = "$i"; |
---|
441 | } |
---|
442 | echo ">".$month["$ii"]."</option>\n"; |
---|
443 | } |
---|
444 | |
---|
445 | ?> |
---|
446 | </select> |
---|
447 | <input type="text" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" /> |
---|
448 | <input type="text" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" /> @ |
---|
449 | <input type="text" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" /> : |
---|
450 | <input type="text" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" /> |
---|
451 | <input type="hidden" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" /> |
---|
452 | <?php _e('Existing timestamp'); ?>: |
---|
453 | <?php |
---|
454 | // We might need to readjust to display proper existing timestamp |
---|
455 | if ( $for_post && ('draft' == $postdata->post_status) ) { |
---|
456 | $jj = mysql2date('d', $post_date); |
---|
457 | $mm = mysql2date('m', $post_date); |
---|
458 | $aa = mysql2date('Y', $post_date); |
---|
459 | $hh = mysql2date('H', $post_date); |
---|
460 | $mn = mysql2date('i', $post_date); |
---|
461 | $ss = mysql2date('s', $post_date); |
---|
462 | } |
---|
463 | echo "{$month[$mm]} $jj, $aa @ $hh:$mn"; ?> |
---|
464 | </fieldset> |
---|
465 | <?php |
---|
466 | } |
---|
467 | |
---|
468 | function check_admin_referer() { |
---|
469 | $adminurl = strtolower( get_settings('siteurl') ) . '/wp-admin'; |
---|
470 | $referer = strtolower( $_SERVER['HTTP_REFERER'] ); |
---|
471 | if ( !strstr($referer, $adminurl) ) |
---|
472 | die(__('Sorry, you need to <a href="http://codex.wordpress.org/Enable_Sending_Referrers">enable sending referrers</a> for this feature to work.')); |
---|
473 | do_action('check_admin_referer'); |
---|
474 | } |
---|
475 | |
---|
476 | // insert_with_markers: Owen Winkler |
---|
477 | // Inserts an array of strings into a file (.htaccess), placing it between |
---|
478 | // BEGIN and END markers. Replaces existing marked info. Retains surrounding |
---|
479 | // data. Creates file if none exists. |
---|
480 | // Returns true on write success, false on failure. |
---|
481 | function insert_with_markers($filename, $marker, $insertion) { |
---|
482 | if (!file_exists($filename) || is_writeable($filename)) { |
---|
483 | if (!file_exists($filename)) { |
---|
484 | $markerdata = ''; |
---|
485 | } else { |
---|
486 | $markerdata = explode("\n", implode('', file($filename))); |
---|
487 | } |
---|
488 | |
---|
489 | $f = fopen($filename, 'w'); |
---|
490 | $foundit = false; |
---|
491 | if ($markerdata) { |
---|
492 | $state = true; |
---|
493 | $newline = ''; |
---|
494 | foreach($markerdata as $markerline) { |
---|
495 | if (strstr($markerline, "# BEGIN {$marker}")) $state = false; |
---|
496 | if ($state) fwrite($f, "{$newline}{$markerline}"); |
---|
497 | if (strstr($markerline, "# END {$marker}")) { |
---|
498 | fwrite($f, "{$newline}# BEGIN {$marker}"); |
---|
499 | if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$newline}{$insertline}"); |
---|
500 | fwrite($f, "{$newline}# END {$marker}"); |
---|
501 | $state = true; |
---|
502 | $foundit = true; |
---|
503 | } |
---|
504 | $newline = "\n"; |
---|
505 | } |
---|
506 | } |
---|
507 | if (!$foundit) { |
---|
508 | fwrite($f, "# BEGIN {$marker}\n"); |
---|
509 | foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); |
---|
510 | fwrite($f, "# END {$marker}"); |
---|
511 | } |
---|
512 | fclose($f); |
---|
513 | return true; |
---|
514 | } else { |
---|
515 | return false; |
---|
516 | } |
---|
517 | } |
---|
518 | |
---|
519 | // insert_with_markers: Owen Winkler |
---|
520 | // Returns an array of strings from a file (.htaccess) from between BEGIN |
---|
521 | // and END markers. |
---|
522 | function extract_from_markers($filename, $marker) { |
---|
523 | $result = array(); |
---|
524 | |
---|
525 | if (!file_exists($filename)) { |
---|
526 | return $result; |
---|
527 | } |
---|
528 | |
---|
529 | if($markerdata = explode("\n", implode('', file($filename)))); |
---|
530 | { |
---|
531 | $state = false; |
---|
532 | foreach($markerdata as $markerline) { |
---|
533 | if(strstr($markerline, "# END {$marker}")) $state = false; |
---|
534 | if($state) $result[] = $markerline; |
---|
535 | if(strstr($markerline, "# BEGIN {$marker}")) $state = true; |
---|
536 | } |
---|
537 | } |
---|
538 | |
---|
539 | return $result; |
---|
540 | } |
---|
541 | |
---|
542 | function save_mod_rewrite_rules() { |
---|
543 | global $is_apache, $wp_rewrite; |
---|
544 | $home_path = get_home_path(); |
---|
545 | |
---|
546 | if (! $wp_rewrite->using_mod_rewrite_permalinks()) |
---|
547 | return; |
---|
548 | |
---|
549 | if ( ! ((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')) ) |
---|
550 | return; |
---|
551 | |
---|
552 | if (! $is_apache) |
---|
553 | return; |
---|
554 | |
---|
555 | $rules = explode("\n", $wp_rewrite->mod_rewrite_rules()); |
---|
556 | insert_with_markers($home_path.'.htaccess', 'WordPress', $rules); |
---|
557 | } |
---|
558 | |
---|
559 | function generate_page_rewrite_rules() { |
---|
560 | global $wpdb; |
---|
561 | $posts = $wpdb->get_results("SELECT ID, post_name FROM $wpdb->posts WHERE post_status = 'static' ORDER BY post_parent DESC"); |
---|
562 | |
---|
563 | $page_rewrite_rules = array(); |
---|
564 | |
---|
565 | if ($posts) { |
---|
566 | foreach ($posts as $post) { |
---|
567 | // URI => page name |
---|
568 | $uri = get_page_uri($post->ID); |
---|
569 | |
---|
570 | $page_rewrite_rules[$uri] = $post->post_name; |
---|
571 | } |
---|
572 | |
---|
573 | update_option('page_uris', $page_rewrite_rules); |
---|
574 | |
---|
575 | save_mod_rewrite_rules(); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | function the_quicktags () { |
---|
580 | // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP |
---|
581 | if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) : |
---|
582 | echo ' |
---|
583 | <div id="quicktags"> |
---|
584 | <a href="http://wordpress.org/docs/reference/post/#quicktags" title="' . __('Help with quicktags') . '">' . __('Quicktags') . '</a>: |
---|
585 | <script src="quicktags.js" type="text/javascript"></script> |
---|
586 | <script type="text/javascript">edToolbar();</script> |
---|
587 | '; |
---|
588 | echo '</div>'; |
---|
589 | endif; |
---|
590 | } |
---|
591 | |
---|
592 | function validate_current_theme() { |
---|
593 | $theme_loc = 'wp-content/themes'; |
---|
594 | $theme_root = ABSPATH . $theme_loc; |
---|
595 | |
---|
596 | $template = get_settings('template'); |
---|
597 | $stylesheet = get_settings('stylesheet'); |
---|
598 | |
---|
599 | if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) { |
---|
600 | update_option('template', 'default'); |
---|
601 | update_option('stylesheet', 'default'); |
---|
602 | do_action('switch_theme', 'Default'); |
---|
603 | return false; |
---|
604 | } |
---|
605 | |
---|
606 | if (($stylesheet != 'default') && (! file_exists("$theme_root/$stylesheet/style.css"))) { |
---|
607 | update_option('template', 'default'); |
---|
608 | update_option('stylesheet', 'default'); |
---|
609 | do_action('switch_theme', 'Default'); |
---|
610 | return false; |
---|
611 | } |
---|
612 | |
---|
613 | return true; |
---|
614 | } |
---|
615 | |
---|
616 | function get_broken_themes() { |
---|
617 | global $wp_broken_themes; |
---|
618 | |
---|
619 | get_themes(); |
---|
620 | return $wp_broken_themes; |
---|
621 | } |
---|
622 | |
---|
623 | function get_page_templates() { |
---|
624 | $themes = get_themes(); |
---|
625 | $theme = get_current_theme(); |
---|
626 | $templates = $themes[$theme]['Template Files']; |
---|
627 | $page_templates = array(); |
---|
628 | |
---|
629 | if( is_array( $templates ) ) { |
---|
630 | foreach ($templates as $template) { |
---|
631 | $template_data = implode('', file(ABSPATH . $template)); |
---|
632 | preg_match("|Template Name:(.*)|i", $template_data, $name); |
---|
633 | preg_match("|Description:(.*)|i", $template_data, $description); |
---|
634 | |
---|
635 | $name = $name[1]; |
---|
636 | $description = $description[1]; |
---|
637 | |
---|
638 | if (! empty($name)) { |
---|
639 | $page_templates[trim($name)] = basename($template); |
---|
640 | } |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | return $page_templates; |
---|
645 | } |
---|
646 | |
---|
647 | function page_template_dropdown($default = '') { |
---|
648 | $templates = get_page_templates(); |
---|
649 | foreach (array_keys($templates) as $template) : |
---|
650 | if ($default == $templates[$template]) $selected = " selected='selected'"; |
---|
651 | else $selected = ''; |
---|
652 | echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>"; |
---|
653 | endforeach; |
---|
654 | } |
---|
655 | |
---|
656 | function parent_dropdown($default = 0, $parent = 0, $level = 0) { |
---|
657 | global $wpdb, $post_ID; |
---|
658 | $items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_status = 'static' ORDER BY menu_order"); |
---|
659 | |
---|
660 | if ($items) { |
---|
661 | foreach ($items as $item) { |
---|
662 | // A page cannot be it's own parent. |
---|
663 | if (!empty($post_ID)) { |
---|
664 | if ($item->ID == $post_ID) { |
---|
665 | continue; |
---|
666 | } |
---|
667 | } |
---|
668 | $pad = str_repeat(' ', $level * 3); |
---|
669 | if ($item->ID == $default) |
---|
670 | $current = ' selected="selected"'; |
---|
671 | else |
---|
672 | $current = ''; |
---|
673 | |
---|
674 | echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>"; |
---|
675 | parent_dropdown($default, $item->ID, $level + 1); |
---|
676 | } |
---|
677 | } else { |
---|
678 | return false; |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | function user_can_access_admin_page() { |
---|
683 | global $pagenow; |
---|
684 | global $menu; |
---|
685 | global $submenu; |
---|
686 | global $user_level; |
---|
687 | |
---|
688 | $parent = get_admin_page_parent(); |
---|
689 | |
---|
690 | foreach ($menu as $menu_array) { |
---|
691 | //echo "parent array: " . $menu_array[2]; |
---|
692 | if ($menu_array[2] == $parent) { |
---|
693 | if ($user_level < $menu_array[1]) { |
---|
694 | return false; |
---|
695 | } else { |
---|
696 | break; |
---|
697 | } |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | if (isset($submenu[$parent])) { |
---|
702 | foreach ($submenu[$parent] as $submenu_array) { |
---|
703 | if ($submenu_array[2] == $pagenow) { |
---|
704 | if ($user_level < $submenu_array[1]) { |
---|
705 | return false; |
---|
706 | } else { |
---|
707 | return true; |
---|
708 | } |
---|
709 | } |
---|
710 | } |
---|
711 | } |
---|
712 | |
---|
713 | return true; |
---|
714 | } |
---|
715 | |
---|
716 | function get_admin_page_title() { |
---|
717 | global $title; |
---|
718 | global $menu; |
---|
719 | global $submenu; |
---|
720 | global $pagenow; |
---|
721 | global $plugin_page; |
---|
722 | |
---|
723 | if (isset($title) && ! empty($title)) { |
---|
724 | return $title; |
---|
725 | } |
---|
726 | |
---|
727 | $parent = get_admin_page_parent(); |
---|
728 | if (empty($parent)) { |
---|
729 | foreach ($menu as $menu_array) { |
---|
730 | if (isset($menu_array[3])) { |
---|
731 | if ($menu_array[2] == $pagenow) { |
---|
732 | $title = $menu_array[3]; |
---|
733 | return $menu_array[3]; |
---|
734 | } else if (isset($plugin_page) && ($plugin_page == $menu_array[2])) { |
---|
735 | $title = $menu_array[3]; |
---|
736 | return $menu_array[3]; |
---|
737 | } |
---|
738 | } |
---|
739 | } |
---|
740 | } else { |
---|
741 | foreach (array_keys($submenu) as $parent) { |
---|
742 | foreach ($submenu[$parent] as $submenu_array) { |
---|
743 | if (isset($submenu_array[3])) { |
---|
744 | if ($submenu_array[2] == $pagenow) { |
---|
745 | $title = $submenu_array[3]; |
---|
746 | return $submenu_array[3]; |
---|
747 | } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) { |
---|
748 | $title = $submenu_array[3]; |
---|
749 | return $submenu_array[3]; |
---|
750 | } |
---|
751 | } |
---|
752 | } |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | return ''; |
---|
757 | } |
---|
758 | |
---|
759 | function get_admin_page_parent() { |
---|
760 | global $parent_file; |
---|
761 | global $menu; |
---|
762 | global $submenu; |
---|
763 | global $pagenow; |
---|
764 | global $plugin_page; |
---|
765 | |
---|
766 | if (isset($parent_file) && ! empty($parent_file)) { |
---|
767 | return $parent_file; |
---|
768 | } |
---|
769 | |
---|
770 | if ($pagenow == 'admin.php' && isset($plugin_page)) { |
---|
771 | foreach ($menu as $parent_menu) { |
---|
772 | if ($parent_menu[2] == $plugin_page) { |
---|
773 | $parent_file = $plugin_page; |
---|
774 | return $plugin_page; |
---|
775 | } |
---|
776 | } |
---|
777 | } |
---|
778 | |
---|
779 | foreach (array_keys($submenu) as $parent) { |
---|
780 | foreach ($submenu[$parent] as $submenu_array) { |
---|
781 | if ($submenu_array[2] == $pagenow) { |
---|
782 | $parent_file = $parent; |
---|
783 | return $parent; |
---|
784 | } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) { |
---|
785 | $parent_file = $parent; |
---|
786 | return $parent; |
---|
787 | } |
---|
788 | } |
---|
789 | } |
---|
790 | |
---|
791 | $parent_file = ''; |
---|
792 | return ''; |
---|
793 | } |
---|
794 | |
---|
795 | function plugin_basename($file) { |
---|
796 | return preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file); |
---|
797 | } |
---|
798 | |
---|
799 | function add_menu_page($page_title, $menu_title, $access_level, $file, $function = '') { |
---|
800 | global $menu, $admin_page_hooks; |
---|
801 | |
---|
802 | $file = plugin_basename($file); |
---|
803 | |
---|
804 | $menu[] = array($menu_title, $access_level, $file, $page_title); |
---|
805 | |
---|
806 | $admin_page_hooks[$file] = sanitize_title($menu_title); |
---|
807 | |
---|
808 | $hookname = get_plugin_page_hookname($file, ''); |
---|
809 | if ( !empty($function) && !empty($hookname) ) |
---|
810 | add_action($hookname, $function); |
---|
811 | |
---|
812 | return $hookname; |
---|
813 | } |
---|
814 | |
---|
815 | function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') { |
---|
816 | global $submenu; |
---|
817 | global $menu; |
---|
818 | |
---|
819 | $parent = plugin_basename($parent); |
---|
820 | $file = plugin_basename($file); |
---|
821 | |
---|
822 | // If the parent doesn't already have a submenu, add a link to the parent |
---|
823 | // as the first item in the submenu. If the submenu file is the same as the |
---|
824 | // parent file someone is trying to link back to the parent manually. In |
---|
825 | // this case, don't automatically add a link back to avoid duplication. |
---|
826 | if (! isset($submenu[$parent]) && $file != $parent) { |
---|
827 | foreach ($menu as $parent_menu) { |
---|
828 | if ($parent_menu[2] == $parent) { |
---|
829 | $submenu[$parent][] = $parent_menu; |
---|
830 | } |
---|
831 | } |
---|
832 | } |
---|
833 | |
---|
834 | $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title); |
---|
835 | |
---|
836 | $hookname = get_plugin_page_hookname($file, $parent); |
---|
837 | if ( !empty($function) && !empty($hookname) ) |
---|
838 | add_action($hookname, $function); |
---|
839 | |
---|
840 | return $hookname; |
---|
841 | } |
---|
842 | |
---|
843 | function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') { |
---|
844 | return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function); |
---|
845 | } |
---|
846 | |
---|
847 | function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') { |
---|
848 | return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function); |
---|
849 | } |
---|
850 | |
---|
851 | function validate_file($file, $allowed_files = '') { |
---|
852 | if ( false !== strpos($file, './')) |
---|
853 | return 1; |
---|
854 | |
---|
855 | if (':' == substr($file,1,1)) |
---|
856 | return 2; |
---|
857 | |
---|
858 | if ( !empty($allowed_files) && (! in_array($file, $allowed_files)) ) |
---|
859 | return 3; |
---|
860 | |
---|
861 | return 0; |
---|
862 | } |
---|
863 | |
---|
864 | function validate_file_to_edit($file, $allowed_files = '') { |
---|
865 | $file = stripslashes($file); |
---|
866 | |
---|
867 | $code = validate_file($file, $allowed_files); |
---|
868 | |
---|
869 | if (! $code) |
---|
870 | return $file; |
---|
871 | |
---|
872 | switch ($code) { |
---|
873 | case 1: |
---|
874 | die (__('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.')); |
---|
875 | |
---|
876 | case 2: |
---|
877 | die (__('Sorry, can’t call files with their real path.')); |
---|
878 | |
---|
879 | case 3: |
---|
880 | die (__('Sorry, that file cannot be edited.')); |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | function get_home_path() { |
---|
885 | $home = get_settings('home'); |
---|
886 | if ( $home != '' && $home != get_settings('siteurl') ) { |
---|
887 | $home_path = parse_url($home); |
---|
888 | $home_path = $home_path['path']; |
---|
889 | $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]); |
---|
890 | $home_path = trailingslashit($root . $home_path); |
---|
891 | } else { |
---|
892 | $home_path = ABSPATH; |
---|
893 | } |
---|
894 | |
---|
895 | return $home_path; |
---|
896 | } |
---|
897 | |
---|
898 | function get_real_file_to_edit($file) { |
---|
899 | if ('index.php' == $file || |
---|
900 | '.htaccess' == $file) { |
---|
901 | $real_file = get_home_path() . $file; |
---|
902 | } else { |
---|
903 | $real_file = ABSPATH . $file; |
---|
904 | } |
---|
905 | |
---|
906 | return $real_file; |
---|
907 | } |
---|
908 | |
---|
909 | $wp_file_descriptions = |
---|
910 | array( |
---|
911 | 'index.php' => __('Main Template'), |
---|
912 | 'style.css' => __('Stylesheet'), |
---|
913 | 'comments.php' => __('Comments Template'), |
---|
914 | 'comments-popup.php' => __('Popup Comments Template'), |
---|
915 | 'footer.php' => __('Footer Template'), |
---|
916 | 'header.php' => __('Header Template'), |
---|
917 | 'sidebar.php' => __('Sidebar Template'), |
---|
918 | 'archive.php' => __('Archive Template'), |
---|
919 | 'category.php' => __('Category Template'), |
---|
920 | 'page.php' => __('Page Template'), |
---|
921 | 'search.php' => __('Search Template'), |
---|
922 | 'single.php' => __('Post Template'), |
---|
923 | '404.php' => __('404 Template'), |
---|
924 | 'my-hacks.php' => __('my-hacks.php (legacy hacks support)'), |
---|
925 | '.htaccess' => __('.htaccess (for rewrite rules)'), |
---|
926 | // Deprecated files |
---|
927 | 'wp-layout.css' => __('Stylesheet'), |
---|
928 | 'wp-comments.php' => __('Comments Template'), |
---|
929 | 'wp-comments-popup.php' => __('Popup Comments Template') |
---|
930 | ); |
---|
931 | |
---|
932 | function get_file_description($file) { |
---|
933 | global $wp_file_descriptions; |
---|
934 | |
---|
935 | if ( isset($wp_file_descriptions[basename($file)] ) ) { |
---|
936 | return $wp_file_descriptions[basename($file)]; |
---|
937 | } elseif ( file_exists( ABSPATH . $file ) ) { |
---|
938 | $template_data = implode('', file(ABSPATH . $file)); |
---|
939 | if ( preg_match("|Template Name:(.*)|i", $template_data, $name) ) |
---|
940 | return $name[1]; |
---|
941 | } |
---|
942 | |
---|
943 | return basename( $file ); |
---|
944 | } |
---|
945 | |
---|
946 | function update_recently_edited($file) { |
---|
947 | $oldfiles = (array) get_option('recently_edited'); |
---|
948 | if ($oldfiles) { |
---|
949 | $oldfiles = array_reverse($oldfiles); |
---|
950 | $oldfiles[] = $file; |
---|
951 | $oldfiles = array_reverse($oldfiles); |
---|
952 | $oldfiles = array_unique($oldfiles); |
---|
953 | if ( 5 < count($oldfiles) ) |
---|
954 | array_pop($oldfiles); |
---|
955 | } else { |
---|
956 | $oldfiles[] = $file; |
---|
957 | } |
---|
958 | update_option('recently_edited', $oldfiles); |
---|
959 | } |
---|
960 | |
---|
961 | function get_plugin_data($plugin_file) { |
---|
962 | $plugin_data = implode('', file($plugin_file)); |
---|
963 | preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); |
---|
964 | preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri); |
---|
965 | preg_match("|Description:(.*)|i", $plugin_data, $description); |
---|
966 | preg_match("|Author:(.*)|i", $plugin_data, $author_name); |
---|
967 | preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri); |
---|
968 | if ( preg_match("|Version:(.*)|i", $plugin_data, $version) ) |
---|
969 | $version = $version[1]; |
---|
970 | else |
---|
971 | $version =''; |
---|
972 | |
---|
973 | $description = wptexturize($description[1]); |
---|
974 | |
---|
975 | $name = $plugin_name[1]; |
---|
976 | $name = trim($name); |
---|
977 | $plugin = $name; |
---|
978 | if ('' != $plugin_uri[1] && '' != $name) { |
---|
979 | $plugin = '<a href="' . $plugin_uri[1] . '" title="' . __('Visit plugin homepage') . '">' . $plugin . '</a>'; |
---|
980 | } |
---|
981 | |
---|
982 | if ('' == $author_uri[1]) { |
---|
983 | $author = $author_name[1]; |
---|
984 | } else { |
---|
985 | $author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>'; |
---|
986 | } |
---|
987 | |
---|
988 | return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]); |
---|
989 | } |
---|
990 | |
---|
991 | function get_plugins() { |
---|
992 | global $wp_plugins; |
---|
993 | |
---|
994 | if (isset($wp_plugins)) { |
---|
995 | return $wp_plugins; |
---|
996 | } |
---|
997 | |
---|
998 | $wp_plugins = array(); |
---|
999 | $plugin_loc = 'wp-content/plugins'; |
---|
1000 | $plugin_root = ABSPATH . $plugin_loc; |
---|
1001 | |
---|
1002 | // Files in wp-content/plugins directory |
---|
1003 | $plugins_dir = @ dir($plugin_root); |
---|
1004 | if ($plugins_dir) { |
---|
1005 | while(($file = $plugins_dir->read()) !== false) { |
---|
1006 | if ( preg_match('|^\.+$|', $file) ) |
---|
1007 | continue; |
---|
1008 | if (is_dir($plugin_root . '/' . $file)) { |
---|
1009 | $plugins_subdir = @ dir($plugin_root . '/' . $file); |
---|
1010 | if ($plugins_subdir) { |
---|
1011 | while(($subfile = $plugins_subdir->read()) !== false) { |
---|
1012 | if ( preg_match('|^\.+$|', $subfile) ) |
---|
1013 | continue; |
---|
1014 | if ( preg_match('|\.php$|', $subfile) ) |
---|
1015 | $plugin_files[] = "$file/$subfile"; |
---|
1016 | } |
---|
1017 | } |
---|
1018 | } else { |
---|
1019 | if ( preg_match('|\.php$|', $file) ) |
---|
1020 | $plugin_files[] = $file; |
---|
1021 | } |
---|
1022 | } |
---|
1023 | } |
---|
1024 | |
---|
1025 | if (!$plugins_dir || !$plugin_files) { |
---|
1026 | return $wp_plugins; |
---|
1027 | } |
---|
1028 | |
---|
1029 | sort($plugin_files); |
---|
1030 | |
---|
1031 | foreach($plugin_files as $plugin_file) { |
---|
1032 | $plugin_data = get_plugin_data("$plugin_root/$plugin_file"); |
---|
1033 | |
---|
1034 | if (empty($plugin_data['Name'])) { |
---|
1035 | continue; |
---|
1036 | } |
---|
1037 | |
---|
1038 | $plugin_data['Filename'] = plugin_basename($plugin_file); |
---|
1039 | |
---|
1040 | $wp_plugins[$plugin_data['Name']] = $plugin_data; |
---|
1041 | } |
---|
1042 | |
---|
1043 | ksort($wp_plugins); |
---|
1044 | |
---|
1045 | return $wp_plugins; |
---|
1046 | } |
---|
1047 | |
---|
1048 | function get_plugin_page_hookname($plugin_page, $parent_page) { |
---|
1049 | global $admin_page_hooks; |
---|
1050 | |
---|
1051 | $parent = get_admin_page_parent(); |
---|
1052 | |
---|
1053 | if ( empty($parent_page) || 'admin.php' == $parent_page ) { |
---|
1054 | if ( isset($admin_page_hooks[$plugin_page]) ) |
---|
1055 | $page_type = 'toplevel'; |
---|
1056 | else if ( isset($admin_page_hooks[$parent]) ) |
---|
1057 | $page_type = $admin_page_hooks[$parent]; |
---|
1058 | } else if ( isset($admin_page_hooks[$parent_page]) ) { |
---|
1059 | $page_type = $admin_page_hooks[$parent_page]; |
---|
1060 | } else { |
---|
1061 | $page_type = 'admin'; |
---|
1062 | } |
---|
1063 | |
---|
1064 | $plugin_name = preg_replace('!\.php!', '', $plugin_page); |
---|
1065 | |
---|
1066 | return $page_type . '_page_' . $plugin_name; |
---|
1067 | } |
---|
1068 | |
---|
1069 | function get_plugin_page_hook($plugin_page, $parent_page) { |
---|
1070 | global $wp_filter; |
---|
1071 | |
---|
1072 | $hook = get_plugin_page_hookname($plugin_page, $parent_page); |
---|
1073 | if ( isset($wp_filter[$hook]) ) |
---|
1074 | return $hook; |
---|
1075 | else |
---|
1076 | return ''; |
---|
1077 | } |
---|
1078 | |
---|
1079 | function pimp_firefox() { |
---|
1080 | if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'Firefox' ) ) |
---|
1081 | return; |
---|
1082 | $getit = __('WordPress recommends the open-source Firefox browser'); |
---|
1083 | echo ' |
---|
1084 | <p id="firefoxlink" style="text-align: center;"><a href="http://spreadfirefox.com/community/?q=affiliates&id=2490&t=1" title="' . $getit . '"><img src="../wp-images/get-firefox.png" alt="Get Firefox" /></a></p> |
---|
1085 | '; |
---|
1086 | } |
---|
1087 | add_action('admin_footer', 'pimp_firefox'); |
---|
1088 | |
---|
1089 | ?> |
---|