| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | // Creates a new post from the "Write Post" form using $_POST information.
|
|---|
| 4 | function write_post() {
|
|---|
| 5 | global $user_ID;
|
|---|
| 6 |
|
|---|
| 7 | if ( ! current_user_can('edit_posts') )
|
|---|
| 8 | die( __('You are not allowed to create posts or drafts on this blog.') );
|
|---|
| 9 |
|
|---|
| 10 | // Rename.
|
|---|
| 11 | $_POST['post_content'] = $_POST['content'];
|
|---|
| 12 | $_POST['post_excerpt'] = $_POST['excerpt'];
|
|---|
| 13 | $_POST['post_parent'] = $_POST['parent_id'];
|
|---|
| 14 | $_POST['to_ping'] = $_POST['trackback_url'];
|
|---|
| 15 |
|
|---|
| 16 | if (! empty($_POST['post_author_override'])) {
|
|---|
| 17 | $_POST['$post_author'] = (int) $_POST['post_author_override'];
|
|---|
| 18 | } else if (! empty($_POST['post_author'])) {
|
|---|
| 19 | $_POST['post_author'] = (int) $_POST['post_author'];
|
|---|
| 20 | } else {
|
|---|
| 21 | $_POST['post_author'] = (int) $_POST['user_ID'];
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') )
|
|---|
| 25 | die( __('You cannot post as this user.') );
|
|---|
| 26 |
|
|---|
| 27 | // What to do based on which button they pressed
|
|---|
| 28 | if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft';
|
|---|
| 29 | if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private';
|
|---|
| 30 | if ('' != $_POST['publish']) $_POST['post_status'] = 'publish';
|
|---|
| 31 | if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft';
|
|---|
| 32 | if ('' != $_POST['savepage']) $_POST['post_status'] = 'static';
|
|---|
| 33 |
|
|---|
| 34 | if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') )
|
|---|
| 35 | $_POST['post_status'] = 'draft';
|
|---|
| 36 |
|
|---|
| 37 | if ( !empty($_POST['edit_date']) ) {
|
|---|
| 38 | $aa = $_POST['aa'];
|
|---|
| 39 | $mm = $_POST['mm'];
|
|---|
| 40 | $jj = $_POST['jj'];
|
|---|
| 41 | $hh = $_POST['hh'];
|
|---|
| 42 | $mn = $_POST['mn'];
|
|---|
| 43 | $ss = $_POST['ss'];
|
|---|
| 44 | $jj = ($jj > 31) ? 31 : $jj;
|
|---|
| 45 | $hh = ($hh > 23) ? $hh - 24 : $hh;
|
|---|
| 46 | $mn = ($mn > 59) ? $mn - 60 : $mn;
|
|---|
| 47 | $ss = ($ss > 59) ? $ss - 60 : $ss;
|
|---|
| 48 | $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
|
|---|
| 49 | $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | // Create the post.
|
|---|
| 53 | $post_ID = wp_insert_post($_POST);
|
|---|
| 54 | add_meta($post_ID);
|
|---|
| 55 |
|
|---|
| 56 | return $post_ID;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | // Update an existing post with values provided in $_POST.
|
|---|
| 60 | function edit_post() {
|
|---|
| 61 | global $user_ID;
|
|---|
| 62 |
|
|---|
| 63 | $post_ID = (int) $_POST['post_ID'];
|
|---|
| 64 |
|
|---|
| 65 | if ( ! current_user_can('edit_post', $post_ID) )
|
|---|
| 66 | die( __('You are not allowed to edit this post.') );
|
|---|
| 67 |
|
|---|
| 68 | // Rename.
|
|---|
| 69 | $_POST['ID'] = (int) $_POST['post_ID'];
|
|---|
| 70 | $_POST['post_content'] = $_POST['content'];
|
|---|
| 71 | $_POST['post_excerpt'] = $_POST['excerpt'];
|
|---|
| 72 | $_POST['post_parent'] = $_POST['parent_id'];
|
|---|
| 73 | $_POST['to_ping'] = $_POST['trackback_url'];
|
|---|
| 74 |
|
|---|
| 75 | if (! empty($_POST['post_author_override'])) {
|
|---|
| 76 | $_POST['$post_author'] = (int) $_POST['post_author_override'];
|
|---|
| 77 | } else if (! empty($_POST['post_author'])) {
|
|---|
| 78 | $_POST['post_author'] = (int) $_POST['post_author'];
|
|---|
| 79 | } else {
|
|---|
| 80 | $_POST['post_author'] = (int) $_POST['user_ID'];
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') )
|
|---|
| 84 | die( __('You cannot post as this user.') );
|
|---|
| 85 |
|
|---|
| 86 | // What to do based on which button they pressed
|
|---|
| 87 | if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft';
|
|---|
| 88 | if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private';
|
|---|
| 89 | if ('' != $_POST['publish']) $_POST['post_status'] = 'publish';
|
|---|
| 90 | if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft';
|
|---|
| 91 | if ('' != $_POST['savepage']) $_POST['post_status'] = 'static';
|
|---|
| 92 |
|
|---|
| 93 | if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') )
|
|---|
| 94 | $_POST['post_status'] = 'draft';
|
|---|
| 95 |
|
|---|
| 96 | if ( !empty($_POST['edit_date']) ) {
|
|---|
| 97 | $aa = $_POST['aa'];
|
|---|
| 98 | $mm = $_POST['mm'];
|
|---|
| 99 | $jj = $_POST['jj'];
|
|---|
| 100 | $hh = $_POST['hh'];
|
|---|
| 101 | $mn = $_POST['mn'];
|
|---|
| 102 | $ss = $_POST['ss'];
|
|---|
| 103 | $jj = ($jj > 31) ? 31 : $jj;
|
|---|
| 104 | $hh = ($hh > 23) ? $hh - 24 : $hh;
|
|---|
| 105 | $mn = ($mn > 59) ? $mn - 60 : $mn;
|
|---|
| 106 | $ss = ($ss > 59) ? $ss - 60 : $ss;
|
|---|
| 107 | $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
|
|---|
| 108 | $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | wp_update_post($_POST);
|
|---|
| 112 |
|
|---|
| 113 | // Meta Stuff
|
|---|
| 114 | if ($_POST['meta']) :
|
|---|
| 115 | foreach ($_POST['meta'] as $key => $value) :
|
|---|
| 116 | update_meta($key, $value['key'], $value['value']);
|
|---|
| 117 | endforeach;
|
|---|
| 118 | endif;
|
|---|
| 119 |
|
|---|
| 120 | if ($_POST['deletemeta']) :
|
|---|
| 121 | foreach ($_POST['deletemeta'] as $key => $value) :
|
|---|
| 122 | delete_meta($key);
|
|---|
| 123 | endforeach;
|
|---|
| 124 | endif;
|
|---|
| 125 |
|
|---|
| 126 | add_meta($post_ID);
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | function edit_comment() {
|
|---|
| 130 | global $user_ID;
|
|---|
| 131 |
|
|---|
| 132 | $comment_ID = (int) $_POST['comment_ID'];
|
|---|
| 133 | $comment_post_ID = (int) $_POST['comment_post_ID'];
|
|---|
| 134 |
|
|---|
| 135 | if ( ! current_user_can('edit_post', $comment_post_ID) )
|
|---|
| 136 | die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
|
|---|
| 137 |
|
|---|
| 138 | $_POST['comment_author'] = $_POST['newcomment_author'];
|
|---|
| 139 | $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
|
|---|
| 140 | $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
|
|---|
| 141 | $_POST['comment_approved'] = $_POST['comment_status'];
|
|---|
| 142 | $_POST['comment_content'] = $_POST['content'];
|
|---|
| 143 | $_POST['comment_ID'] = (int) $_POST['comment_ID'];
|
|---|
| 144 |
|
|---|
| 145 | if ( !empty($_POST['edit_date']) ) {
|
|---|
| 146 | $aa = $_POST['aa'];
|
|---|
| 147 | $mm = $_POST['mm'];
|
|---|
| 148 | $jj = $_POST['jj'];
|
|---|
| 149 | $hh = $_POST['hh'];
|
|---|
| 150 | $mn = $_POST['mn'];
|
|---|
| 151 | $ss = $_POST['ss'];
|
|---|
| 152 | $jj = ($jj > 31) ? 31 : $jj;
|
|---|
| 153 | $hh = ($hh > 23) ? $hh - 24 : $hh;
|
|---|
| 154 | $mn = ($mn > 59) ? $mn - 60 : $mn;
|
|---|
| 155 | $ss = ($ss > 59) ? $ss - 60 : $ss;
|
|---|
| 156 | $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | wp_update_comment($_POST);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | // Get an existing post and format it for editing.
|
|---|
| 163 | function get_post_to_edit($id) {
|
|---|
| 164 | $post = get_post($id);
|
|---|
| 165 |
|
|---|
| 166 | $post->post_content = format_to_edit($post->post_content);
|
|---|
| 167 | $post->post_content = apply_filters('content_edit_pre', $post->post_content);
|
|---|
| 168 |
|
|---|
| 169 | $post->post_excerpt = format_to_edit($post->post_excerpt);
|
|---|
| 170 | $post->post_excerpt = apply_filters('excerpt_edit_pre', $post->post_excerpt);
|
|---|
| 171 |
|
|---|
| 172 | $post->post_title = format_to_edit($post->post_title);
|
|---|
| 173 | $post->post_title = apply_filters('title_edit_pre', $post->post_title);
|
|---|
| 174 |
|
|---|
| 175 | if ($post->post_status == 'static')
|
|---|
| 176 | $post->page_template = get_post_meta($id, '_wp_page_template', true);
|
|---|
| 177 |
|
|---|
| 178 | return $post;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | // Default post information to use when populating the "Write Post" form.
|
|---|
| 182 | function get_default_post_to_edit() {
|
|---|
| 183 | global $content, $excerpt, $edited_post_title;
|
|---|
| 184 |
|
|---|
| 185 | $post->post_status = 'draft';
|
|---|
| 186 | $post->comment_status = get_settings('default_comment_status');
|
|---|
| 187 | $post->ping_status = get_settings('default_ping_status');
|
|---|
| 188 | $post->post_pingback = get_settings('default_pingback_flag');
|
|---|
| 189 | $post->post_category = get_settings('default_category');
|
|---|
| 190 | $content = wp_specialchars($content);
|
|---|
| 191 | $post->post_content = apply_filters('default_content', $content);
|
|---|
| 192 | $post->post_title = apply_filters('default_title', $edited_post_title);
|
|---|
| 193 | $post->post_excerpt = apply_filters('default_excerpt', $excerpt);
|
|---|
| 194 | $post->page_template = 'default';
|
|---|
| 195 | $post->post_parent = 0;
|
|---|
| 196 | $post->menu_order = 0;
|
|---|
| 197 |
|
|---|
| 198 | return $post;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | function get_comment_to_edit($id) {
|
|---|
| 202 | $comment = get_comment($id);
|
|---|
| 203 |
|
|---|
| 204 | $comment->comment_content = format_to_edit($comment->comment_content);
|
|---|
| 205 | $comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content);
|
|---|
| 206 |
|
|---|
| 207 | $comment->comment_author = format_to_edit($comment->comment_author);
|
|---|
| 208 | $comment->comment_author_email = format_to_edit($comment->comment_author_email);
|
|---|
| 209 | $comment->comment_author_url = format_to_edit($comment->comment_author_url);
|
|---|
| 210 |
|
|---|
| 211 | return $comment;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | function get_category_to_edit($id) {
|
|---|
| 215 | $category = get_category($id);
|
|---|
| 216 |
|
|---|
| 217 | return $category;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | function wp_insert_category($catarr) {
|
|---|
| 221 | global $wpdb;
|
|---|
| 222 |
|
|---|
| 223 | extract($catarr);
|
|---|
| 224 |
|
|---|
| 225 | $cat_ID = (int) $cat_ID;
|
|---|
| 226 |
|
|---|
| 227 | // Are we updating or creating?
|
|---|
| 228 | if ( !empty($cat_ID) ) {
|
|---|
| 229 | $update = true;
|
|---|
| 230 | } else {
|
|---|
| 231 | $update = false;
|
|---|
| 232 | $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'");
|
|---|
| 233 | $cat_ID = $id_result->Auto_increment;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | $cat_name = wp_specialchars($cat_name);
|
|---|
| 237 |
|
|---|
| 238 | if ( empty($category_nicename) )
|
|---|
| 239 | $category_nicename = sanitize_title($cat_name, $cat_ID);
|
|---|
| 240 | else
|
|---|
| 241 | $category_nicename = sanitize_title($category_nicename, $cat_ID);
|
|---|
| 242 |
|
|---|
| 243 | if ( empty($category_description) )
|
|---|
| 244 | $category_description = '';
|
|---|
| 245 |
|
|---|
| 246 | if ( empty($category_parent) )
|
|---|
| 247 | $category_parent = 0;
|
|---|
| 248 |
|
|---|
| 249 | if ( !$update)
|
|---|
| 250 | $query = "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')";
|
|---|
| 251 | else
|
|---|
| 252 | $query = "UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'";
|
|---|
| 253 |
|
|---|
| 254 | $result = $wpdb->query($query);
|
|---|
| 255 |
|
|---|
| 256 | if ( $update ) {
|
|---|
| 257 | $rval = $wpdb->rows_affected;
|
|---|
| 258 | do_action('edit_category', $cat_ID);
|
|---|
| 259 | } else {
|
|---|
| 260 | $rval = $wpdb->insert_id;
|
|---|
| 261 | do_action('create_category', $cat_ID);
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | return $rval;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | function wp_update_category($catarr) {
|
|---|
| 268 | global $wpdb;
|
|---|
| 269 |
|
|---|
| 270 | $cat_ID = (int) $catarr['cat_ID'];
|
|---|
| 271 |
|
|---|
| 272 | // First, get all of the original fields
|
|---|
| 273 | $category = get_category($cat_ID, ARRAY_A);
|
|---|
| 274 |
|
|---|
| 275 | // Escape data pulled from DB.
|
|---|
| 276 | $category = add_magic_quotes($category);
|
|---|
| 277 |
|
|---|
| 278 | // Merge old and new fields with new fields overwriting old ones.
|
|---|
| 279 | $catarr = array_merge($category, $catarr);
|
|---|
| 280 |
|
|---|
| 281 | return wp_insert_category($catarr);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | function wp_delete_category($cat_ID) {
|
|---|
| 285 | global $wpdb;
|
|---|
| 286 |
|
|---|
| 287 | $cat_ID = (int) $cat_ID;
|
|---|
| 288 |
|
|---|
| 289 | // Don't delete the default cat.
|
|---|
| 290 | if ( 1 == $cat_ID )
|
|---|
| 291 | return 0;
|
|---|
| 292 |
|
|---|
| 293 | $category = get_category($cat_ID);
|
|---|
| 294 |
|
|---|
| 295 | $parent = $category->category_parent;
|
|---|
| 296 |
|
|---|
| 297 | // Delete the category.
|
|---|
| 298 | $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'");
|
|---|
| 299 |
|
|---|
| 300 | // Update children to point to new parent.
|
|---|
| 301 | $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'");
|
|---|
| 302 |
|
|---|
| 303 | // TODO: Only set categories to general if they're not in another category already
|
|---|
| 304 | $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'");
|
|---|
| 305 |
|
|---|
| 306 | do_action('delete_category', $cat_ID);
|
|---|
| 307 |
|
|---|
| 308 | return 1;
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | function wp_delete_user($id, $reassign = 'novalue') {
|
|---|
| 312 | global $wpdb;
|
|---|
| 313 |
|
|---|
| 314 | $id = (int) $id;
|
|---|
| 315 |
|
|---|
| 316 | if($reassign == 'novalue') {
|
|---|
| 317 | $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
|
|---|
| 318 |
|
|---|
| 319 | if ($post_ids) {
|
|---|
| 320 | $post_ids = implode(',', $post_ids);
|
|---|
| 321 |
|
|---|
| 322 | // Delete comments, *backs
|
|---|
| 323 | $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
|
|---|
| 324 | // Clean cats
|
|---|
| 325 | $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
|
|---|
| 326 | // Clean post_meta
|
|---|
| 327 | $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
|
|---|
| 328 | // Delete posts
|
|---|
| 329 | $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | // Clean links
|
|---|
| 333 | $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
|
|---|
| 334 | } else {
|
|---|
| 335 | $reassign = (int)$reassign;
|
|---|
| 336 | $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}");
|
|---|
| 337 | $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}");
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | // FINALLY, delete user
|
|---|
| 341 | $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
|
|---|
| 342 |
|
|---|
| 343 | do_action('delete_user', $id);
|
|---|
| 344 |
|
|---|
| 345 | return true;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | function url_shorten ($url) {
|
|---|
| 349 | $short_url = str_replace('http://', '', stripslashes($url));
|
|---|
| 350 | $short_url = str_replace('www.', '', $short_url);
|
|---|
| 351 | if ('/' == substr($short_url, -1))
|
|---|
| 352 | $short_url = substr($short_url, 0, -1);
|
|---|
| 353 | if (strlen($short_url) > 35)
|
|---|
| 354 | $short_url = substr($short_url, 0, 32).'...';
|
|---|
| 355 | return $short_url;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | function selected($selected, $current) {
|
|---|
| 359 | if ($selected == $current) echo ' selected="selected"';
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | function checked($checked, $current) {
|
|---|
| 363 | if ($checked == $current) echo ' checked="checked"';
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | function return_categories_list( $parent = 0 ) {
|
|---|
| 367 | global $wpdb;
|
|---|
| 368 | return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC");
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | function get_nested_categories($default = 0, $parent = 0) {
|
|---|
| 372 | global $post_ID, $mode, $wpdb;
|
|---|
| 373 |
|
|---|
| 374 | if ($post_ID) {
|
|---|
| 375 | $checked_categories = $wpdb->get_col("
|
|---|
| 376 | SELECT category_id
|
|---|
| 377 | FROM $wpdb->categories, $wpdb->post2cat
|
|---|
| 378 | WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID'
|
|---|
| 379 | ");
|
|---|
| 380 |
|
|---|
| 381 | if(count($checked_categories) == 0)
|
|---|
| 382 | {
|
|---|
| 383 | // No selected categories, strange
|
|---|
| 384 | $checked_categories[] = $default;
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | } else {
|
|---|
| 388 | $checked_categories[] = $default;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | $cats = return_categories_list($parent);
|
|---|
| 392 | $result = array();
|
|---|
| 393 |
|
|---|
| 394 | foreach($cats as $cat) {
|
|---|
| 395 | //$result[$cat]['children'] = get_nested_categories($default, $cat);
|
|---|
| 396 | $result[$cat]['cat_ID'] = $cat;
|
|---|
| 397 | $result[$cat]['checked'] = in_array($cat, $checked_categories);
|
|---|
| 398 | $result[$cat]['cat_name'] = get_the_category_by_ID($cat);
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | return $result;
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | function write_nested_categories($categories) {
|
|---|
| 405 | foreach($categories as $category) {
|
|---|
| 406 | echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'],
|
|---|
| 407 | '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"',
|
|---|
| 408 | ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n";
|
|---|
| 409 |
|
|---|
| 410 | if(isset($category['children'])) {
|
|---|
| 411 | echo "\n<span class='cat-nest'>\n";
|
|---|
| 412 | write_nested_categories($category['children']);
|
|---|
| 413 | echo "</span>\n";
|
|---|
| 414 | }
|
|---|
| 415 | }
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | function dropdown_categories($default = 0) {
|
|---|
| 419 | write_nested_categories(get_nested_categories($default));
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | // Dandy new recursive multiple category stuff.
|
|---|
| 423 | function cat_rows($parent = 0, $level = 0, $categories = 0) {
|
|---|
| 424 | global $wpdb, $class;
|
|---|
| 425 |
|
|---|
| 426 | if ( !$categories )
|
|---|
| 427 | $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
|
|---|
| 428 |
|
|---|
| 429 | if ($categories) {
|
|---|
| 430 | foreach ($categories as $category) {
|
|---|
| 431 | if ($category->category_parent == $parent) {
|
|---|
| 432 | $category->cat_name = wp_specialchars($category->cat_name);
|
|---|
| 433 | $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
|
|---|
| 434 | $pad = str_repeat('— ', $level);
|
|---|
| 435 | if ( current_user_can('manage_categories') )
|
|---|
| 436 | $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."), $wpdb->escape($category->cat_name)) . "')\" class='delete'>" . __('Delete') . "</a>";
|
|---|
| 437 | else
|
|---|
| 438 | $edit = '';
|
|---|
| 439 |
|
|---|
| 440 | $class = ('alternate' == $class) ? '' : 'alternate';
|
|---|
| 441 | echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
|
|---|
| 442 | <td>$category->category_description</td>
|
|---|
| 443 | <td>$count</td>
|
|---|
| 444 | <td>$edit</td>
|
|---|
| 445 | </tr>";
|
|---|
| 446 | cat_rows($category->cat_ID, $level + 1, $categories);
|
|---|
| 447 | }
|
|---|
| 448 | }
|
|---|
| 449 | } else {
|
|---|
| 450 | return false;
|
|---|
| 451 | }
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | function page_rows( $parent = 0, $level = 0, $pages = 0 ) {
|
|---|
| 455 | global $wpdb, $class, $post;
|
|---|
| 456 | if (!$pages)
|
|---|
| 457 | $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static' ORDER BY menu_order");
|
|---|
| 458 |
|
|---|
| 459 | if ($pages) {
|
|---|
| 460 | foreach ($pages as $post) { start_wp();
|
|---|
| 461 | if ($post->post_parent == $parent) {
|
|---|
| 462 | $post->post_title = wp_specialchars($post->post_title);
|
|---|
| 463 | $pad = str_repeat('— ', $level);
|
|---|
| 464 | $id = $post->ID;
|
|---|
| 465 | $class = ('alternate' == $class) ? '' : 'alternate';
|
|---|
| 466 | ?>
|
|---|
| 467 | <tr class='<?php echo $class; ?>'>
|
|---|
| 468 | <th scope="row"><?php echo $post->ID; ?></th>
|
|---|
| 469 | <td>
|
|---|
| 470 | <?php echo $pad; ?><?php the_title() ?>
|
|---|
| 471 | </td>
|
|---|
| 472 | <td><?php the_author() ?></td>
|
|---|
| 473 | <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
|
|---|
| 474 | <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
|
|---|
| 475 | <td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=edit&post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
|
|---|
| 476 | <td><?php if ( current_user_can('edit_pages') ) { 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>
|
|---|
| 477 | </tr>
|
|---|
| 478 |
|
|---|
| 479 | <?php
|
|---|
| 480 | page_rows($id, $level + 1, $pages);
|
|---|
| 481 | }
|
|---|
| 482 | }
|
|---|
| 483 | } else {
|
|---|
| 484 | return false;
|
|---|
| 485 | }
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {
|
|---|
| 489 | global $wpdb, $bgcolor;
|
|---|
| 490 | if (!$categories) {
|
|---|
| 491 | $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
|
|---|
| 492 | }
|
|---|
| 493 | if ($categories) {
|
|---|
| 494 | foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) {
|
|---|
| 495 | $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
|
|---|
| 496 | $pad = str_repeat('– ', $level);
|
|---|
| 497 | $category->cat_name = wp_specialchars($category->cat_name);
|
|---|
| 498 | echo "\n\t<option value='$category->cat_ID'";
|
|---|
| 499 | if ($currentparent == $category->cat_ID)
|
|---|
| 500 | echo " selected='selected'";
|
|---|
| 501 | echo ">$pad$category->cat_name</option>";
|
|---|
| 502 | wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level + 1, $categories);
|
|---|
| 503 | } }
|
|---|
| 504 | } else {
|
|---|
| 505 | return false;
|
|---|
| 506 | }
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | function wp_create_thumbnail($file, $max_side, $effect = '') {
|
|---|
| 510 |
|
|---|
| 511 | // 1 = GIF, 2 = JPEG, 3 = PNG
|
|---|
| 512 |
|
|---|
| 513 | if(file_exists($file)) {
|
|---|
| 514 | $type = getimagesize($file);
|
|---|
| 515 |
|
|---|
| 516 | // if the associated function doesn't exist - then it's not
|
|---|
| 517 | // handle. duh. i hope.
|
|---|
| 518 |
|
|---|
| 519 | if(!function_exists('imagegif') && $type[2] == 1) {
|
|---|
| 520 | $error = __('Filetype not supported. Thumbnail not created.');
|
|---|
| 521 | }elseif(!function_exists('imagejpeg') && $type[2] == 2) {
|
|---|
| 522 | $error = __('Filetype not supported. Thumbnail not created.');
|
|---|
| 523 | }elseif(!function_exists('imagepng') && $type[2] == 3) {
|
|---|
| 524 | $error = __('Filetype not supported. Thumbnail not created.');
|
|---|
| 525 | } else {
|
|---|
| 526 |
|
|---|
| 527 | // create the initial copy from the original file
|
|---|
| 528 | if($type[2] == 1) {
|
|---|
| 529 | $image = imagecreatefromgif($file);
|
|---|
| 530 | } elseif($type[2] == 2) {
|
|---|
| 531 | $image = imagecreatefromjpeg($file);
|
|---|
| 532 | } elseif($type[2] == 3) {
|
|---|
| 533 | $image = imagecreatefrompng($file);
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | if (function_exists('imageantialias'))
|
|---|
| 537 | imageantialias($image, TRUE);
|
|---|
| 538 |
|
|---|
| 539 | $image_attr = getimagesize($file);
|
|---|
| 540 |
|
|---|
| 541 | // figure out the longest side
|
|---|
| 542 |
|
|---|
| 543 | if($image_attr[0] > $image_attr[1]) {
|
|---|
| 544 | $image_width = $image_attr[0];
|
|---|
| 545 | $image_height = $image_attr[1];
|
|---|
| 546 | $image_new_width = $max_side;
|
|---|
| 547 |
|
|---|
| 548 | $image_ratio = $image_width/$image_new_width;
|
|---|
| 549 | $image_new_height = $image_height/$image_ratio;
|
|---|
| 550 | //width is > height
|
|---|
| 551 | } else {
|
|---|
| 552 | $image_width = $image_attr[0];
|
|---|
| 553 | $image_height = $image_attr[1];
|
|---|
| 554 | $image_new_height = $max_side;
|
|---|
| 555 |
|
|---|
| 556 | $image_ratio = $image_height/$image_new_height;
|
|---|
| 557 | $image_new_width = $image_width/$image_ratio;
|
|---|
| 558 | //height > width
|
|---|
| 559 | }
|
|---|
| 560 |
|
|---|
| 561 | $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
|
|---|
| 562 | @imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
|
|---|
| 563 |
|
|---|
| 564 | // move the thumbnail to it's final destination
|
|---|
| 565 |
|
|---|
| 566 | $path = explode('/', $file);
|
|---|
| 567 | $thumbpath = substr($file, 0, strrpos($file, '/')) . '/thumb-' . $path[count($path)-1];
|
|---|
| 568 |
|
|---|
| 569 | if($type[2] == 1) {
|
|---|
| 570 | if(!imagegif($thumbnail, $thumbpath)) {
|
|---|
| 571 | $error = __("Thumbnail path invalid");
|
|---|
| 572 | }
|
|---|
| 573 | } elseif($type[2] == 2) {
|
|---|
| 574 | if(!imagejpeg($thumbnail, $thumbpath)) {
|
|---|
| 575 | $error = __("Thumbnail path invalid");
|
|---|
| 576 | }
|
|---|
| 577 | } elseif($type[2] == 3) {
|
|---|
| 578 | if(!imagepng($thumbnail, $thumbpath)) {
|
|---|
| 579 | $error = __("Thumbnail path invalid");
|
|---|
| 580 | }
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 586 | if(!empty($error))
|
|---|
| 587 | {
|
|---|
| 588 | return $error;
|
|---|
| 589 | }
|
|---|
| 590 | else
|
|---|
| 591 | {
|
|---|
| 592 | return 1;
|
|---|
| 593 | }
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | // Some postmeta stuff
|
|---|
| 597 | function has_meta($postid) {
|
|---|
| 598 | global $wpdb;
|
|---|
| 599 |
|
|---|
| 600 | return $wpdb->get_results("
|
|---|
| 601 | SELECT meta_key, meta_value, meta_id, post_id
|
|---|
| 602 | FROM $wpdb->postmeta
|
|---|
| 603 | WHERE post_id = '$postid'
|
|---|
| 604 | ORDER BY meta_key,meta_id",ARRAY_A);
|
|---|
| 605 |
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | function list_meta($meta) {
|
|---|
| 609 | global $post_ID;
|
|---|
| 610 | // Exit if no meta
|
|---|
| 611 | if (!$meta) return;
|
|---|
| 612 | $count = 0;
|
|---|
| 613 | ?>
|
|---|
| 614 | <table id='meta-list' cellpadding="3">
|
|---|
| 615 | <tr>
|
|---|
| 616 | <th><?php _e('Key') ?></th>
|
|---|
| 617 | <th><?php _e('Value') ?></th>
|
|---|
| 618 | <th colspan='2'><?php _e('Action') ?></th>
|
|---|
| 619 | </tr>
|
|---|
| 620 | <?php
|
|---|
| 621 |
|
|---|
| 622 | foreach ($meta as $entry) {
|
|---|
| 623 | ++$count;
|
|---|
| 624 | if ( $count % 2 ) $style = 'alternate';
|
|---|
| 625 | else $style = '';
|
|---|
| 626 | if ( '_' == $entry['meta_key']{0} ) $style .= ' hidden';
|
|---|
| 627 | echo "
|
|---|
| 628 | <tr class='$style'>
|
|---|
| 629 | <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>
|
|---|
| 630 | <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>
|
|---|
| 631 | <td align='center' width='10%'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='" . __('Update') ."' /></td>
|
|---|
| 632 | <td align='center' width='10%'><input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='" . __('Delete') ."' /></td>
|
|---|
| 633 | </tr>
|
|---|
| 634 | ";
|
|---|
| 635 | }
|
|---|
| 636 | echo "
|
|---|
| 637 | </table>
|
|---|
| 638 | ";
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | // Get a list of previously defined keys
|
|---|
| 642 | function get_meta_keys() {
|
|---|
| 643 | global $wpdb;
|
|---|
| 644 |
|
|---|
| 645 | $keys = $wpdb->get_col("
|
|---|
| 646 | SELECT meta_key
|
|---|
| 647 | FROM $wpdb->postmeta
|
|---|
| 648 | GROUP BY meta_key
|
|---|
| 649 | ORDER BY meta_key");
|
|---|
| 650 |
|
|---|
| 651 | return $keys;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | function meta_form() {
|
|---|
| 655 | global $wpdb;
|
|---|
| 656 | $keys = $wpdb->get_col("
|
|---|
| 657 | SELECT meta_key
|
|---|
| 658 | FROM $wpdb->postmeta
|
|---|
| 659 | GROUP BY meta_key
|
|---|
| 660 | ORDER BY meta_id DESC
|
|---|
| 661 | LIMIT 10");
|
|---|
| 662 | ?>
|
|---|
| 663 | <h3><?php _e('Add a new custom field to this post:') ?></h3>
|
|---|
| 664 | <table cellspacing="3" cellpadding="3">
|
|---|
| 665 | <tr>
|
|---|
| 666 | <th colspan="2"><?php _e('Key') ?></th>
|
|---|
| 667 | <th><?php _e('Value') ?></th>
|
|---|
| 668 | </tr>
|
|---|
| 669 | <tr valign="top">
|
|---|
| 670 | <td align="right" width="18%">
|
|---|
| 671 | <?php if ($keys) : ?>
|
|---|
| 672 | <select id="metakeyselect" name="metakeyselect" tabindex="7">
|
|---|
| 673 | <option value="#NONE#"><?php _e('- Select -'); ?></option>
|
|---|
| 674 | <?php
|
|---|
| 675 | foreach($keys as $key) {
|
|---|
| 676 | echo "\n\t<option value='$key'>$key</option>";
|
|---|
| 677 | }
|
|---|
| 678 | ?>
|
|---|
| 679 | </select> <?php _e('or'); ?>
|
|---|
| 680 | <?php endif; ?>
|
|---|
| 681 | </td>
|
|---|
| 682 | <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
|
|---|
| 683 | <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
|
|---|
| 684 | </tr>
|
|---|
| 685 |
|
|---|
| 686 | </table>
|
|---|
| 687 | <p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field »') ?>" /></p>
|
|---|
| 688 | <?php
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | function add_meta($post_ID) {
|
|---|
| 692 | global $wpdb;
|
|---|
| 693 |
|
|---|
| 694 | $metakeyselect = $wpdb->escape( stripslashes( trim($_POST['metakeyselect']) ) );
|
|---|
| 695 | $metakeyinput = $wpdb->escape( stripslashes( trim($_POST['metakeyinput']) ) );
|
|---|
| 696 | $metavalue = $wpdb->escape( stripslashes( trim($_POST['metavalue']) ) );
|
|---|
| 697 |
|
|---|
| 698 | if (!empty($metavalue) && ((('#NONE#' != $metakeyselect) && !empty($metakeyselect)) || !empty($metakeyinput))) {
|
|---|
| 699 | // We have a key/value pair. If both the select and the
|
|---|
| 700 | // input for the key have data, the input takes precedence:
|
|---|
| 701 |
|
|---|
| 702 | if ('#NONE#' != $metakeyselect)
|
|---|
| 703 | $metakey = $metakeyselect;
|
|---|
| 704 |
|
|---|
| 705 | if ($metakeyinput)
|
|---|
| 706 | $metakey = $metakeyinput; // default
|
|---|
| 707 |
|
|---|
| 708 | $result = $wpdb->query("
|
|---|
| 709 | INSERT INTO $wpdb->postmeta
|
|---|
| 710 | (post_id,meta_key,meta_value)
|
|---|
| 711 | VALUES ('$post_ID','$metakey','$metavalue')
|
|---|
| 712 | ");
|
|---|
| 713 | }
|
|---|
| 714 | } // add_meta
|
|---|
| 715 |
|
|---|
| 716 | function delete_meta($mid) {
|
|---|
| 717 | global $wpdb;
|
|---|
| 718 |
|
|---|
| 719 | $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");
|
|---|
| 720 | }
|
|---|
| 721 |
|
|---|
| 722 | function update_meta($mid, $mkey, $mvalue) {
|
|---|
| 723 | global $wpdb;
|
|---|
| 724 |
|
|---|
| 725 | return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");
|
|---|
| 726 | }
|
|---|
| 727 |
|
|---|
| 728 | function touch_time($edit = 1, $for_post = 1) {
|
|---|
| 729 | global $month, $post, $comment;
|
|---|
| 730 | if ( $for_post && ('draft' == $post->post_status) ) {
|
|---|
| 731 | $checked = 'checked="checked" ';
|
|---|
| 732 | $edit = false;
|
|---|
| 733 | } else {
|
|---|
| 734 | $checked = ' ';
|
|---|
| 735 | }
|
|---|
| 736 |
|
|---|
| 737 | echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" '.$checked.'/> <label for="timestamp">' . __('Edit timestamp') . '</label></legend>';
|
|---|
| 738 |
|
|---|
| 739 | $time_adj = time() + (get_settings('gmt_offset') * 3600);
|
|---|
| 740 | $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
|
|---|
| 741 | $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj);
|
|---|
| 742 | $mm = ($edit) ? mysql2date('m', $post_date) : gmdate('m', $time_adj);
|
|---|
| 743 | $aa = ($edit) ? mysql2date('Y', $post_date) : gmdate('Y', $time_adj);
|
|---|
| 744 | $hh = ($edit) ? mysql2date('H', $post_date) : gmdate('H', $time_adj);
|
|---|
| 745 | $mn = ($edit) ? mysql2date('i', $post_date) : gmdate('i', $time_adj);
|
|---|
| 746 | $ss = ($edit) ? mysql2date('s', $post_date) : gmdate('s', $time_adj);
|
|---|
| 747 |
|
|---|
| 748 | echo "<select name=\"mm\">\n";
|
|---|
| 749 | for ($i=1; $i < 13; $i=$i+1) {
|
|---|
| 750 | echo "\t\t\t<option value=\"$i\"";
|
|---|
| 751 | if ($i == $mm)
|
|---|
| 752 | echo " selected='selected'";
|
|---|
| 753 | if ($i < 10) {
|
|---|
| 754 | $ii = "0".$i;
|
|---|
| 755 | } else {
|
|---|
| 756 | $ii = "$i";
|
|---|
| 757 | }
|
|---|
| 758 | echo ">".$month["$ii"]."</option>\n";
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| 761 | ?>
|
|---|
| 762 | </select>
|
|---|
| 763 | <input type="text" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" />
|
|---|
| 764 | <input type="text" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" /> @
|
|---|
| 765 | <input type="text" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" /> :
|
|---|
| 766 | <input type="text" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" />
|
|---|
| 767 | <input type="hidden" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
|
|---|
| 768 | <?php _e('Existing timestamp'); ?>:
|
|---|
| 769 | <?php
|
|---|
| 770 | // We might need to readjust to display proper existing timestamp
|
|---|
| 771 | if ( $for_post && ('draft' == $post->post_status) ) {
|
|---|
| 772 | $jj = mysql2date('d', $post_date);
|
|---|
| 773 | $mm = mysql2date('m', $post_date);
|
|---|
| 774 | $aa = mysql2date('Y', $post_date);
|
|---|
| 775 | $hh = mysql2date('H', $post_date);
|
|---|
| 776 | $mn = mysql2date('i', $post_date);
|
|---|
| 777 | $ss = mysql2date('s', $post_date);
|
|---|
| 778 | }
|
|---|
| 779 | echo "{$month[$mm]} $jj, $aa @ $hh:$mn"; ?>
|
|---|
| 780 | </fieldset>
|
|---|
| 781 | <?php
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | function check_admin_referer() {
|
|---|
| 785 | $adminurl = strtolower( get_settings('siteurl') ) . '/wp-admin';
|
|---|
| 786 | $referer = strtolower( $_SERVER['HTTP_REFERER'] );
|
|---|
| 787 | if ( !strstr($referer, $adminurl) )
|
|---|
| 788 | die(__('Sorry, you need to <a href="http://codex.wordpress.org/Enable_Sending_Referrers">enable sending referrers</a> for this feature to work.'));
|
|---|
| 789 | do_action('check_admin_referer');
|
|---|
| 790 | }
|
|---|
| 791 |
|
|---|
| 792 | // insert_with_markers: Owen Winkler
|
|---|
| 793 | // Inserts an array of strings into a file (.htaccess), placing it between
|
|---|
| 794 | // BEGIN and END markers. Replaces existing marked info. Retains surrounding
|
|---|
| 795 | // data. Creates file if none exists.
|
|---|
| 796 | // Returns true on write success, false on failure.
|
|---|
| 797 | function insert_with_markers($filename, $marker, $insertion) {
|
|---|
| 798 | if (!file_exists($filename) || is_writeable($filename)) {
|
|---|
| 799 | if (!file_exists($filename)) {
|
|---|
| 800 | $markerdata = '';
|
|---|
| 801 | } else {
|
|---|
| 802 | $markerdata = explode("\n", implode('', file($filename)));
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | $f = fopen($filename, 'w');
|
|---|
| 806 | $foundit = false;
|
|---|
| 807 | if ($markerdata) {
|
|---|
| 808 | $state = true;
|
|---|
| 809 | $newline = '';
|
|---|
| 810 | foreach($markerdata as $markerline) {
|
|---|
| 811 | if (strstr($markerline, "# BEGIN {$marker}")) $state = false;
|
|---|
| 812 | if ($state) fwrite($f, "{$newline}{$markerline}");
|
|---|
| 813 | if (strstr($markerline, "# END {$marker}")) {
|
|---|
| 814 | fwrite($f, "{$newline}# BEGIN {$marker}");
|
|---|
| 815 | if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$newline}{$insertline}");
|
|---|
| 816 | fwrite($f, "{$newline}# END {$marker}");
|
|---|
| 817 | $state = true;
|
|---|
| 818 | $foundit = true;
|
|---|
| 819 | }
|
|---|
| 820 | $newline = "\n";
|
|---|
| 821 | }
|
|---|
| 822 | }
|
|---|
| 823 | if (!$foundit) {
|
|---|
| 824 | fwrite($f, "# BEGIN {$marker}\n");
|
|---|
| 825 | foreach($insertion as $insertline) fwrite($f, "{$insertline}\n");
|
|---|
| 826 | fwrite($f, "# END {$marker}");
|
|---|
| 827 | }
|
|---|
| 828 | fclose($f);
|
|---|
| 829 | return true;
|
|---|
| 830 | } else {
|
|---|
| 831 | return false;
|
|---|
| 832 | }
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | // insert_with_markers: Owen Winkler
|
|---|
| 836 | // Returns an array of strings from a file (.htaccess) from between BEGIN
|
|---|
| 837 | // and END markers.
|
|---|
| 838 | function extract_from_markers($filename, $marker) {
|
|---|
| 839 | $result = array();
|
|---|
| 840 |
|
|---|
| 841 | if (!file_exists($filename)) {
|
|---|
| 842 | return $result;
|
|---|
| 843 | }
|
|---|
| 844 |
|
|---|
| 845 | if($markerdata = explode("\n", implode('', file($filename))));
|
|---|
| 846 | {
|
|---|
| 847 | $state = false;
|
|---|
| 848 | foreach($markerdata as $markerline) {
|
|---|
| 849 | if(strstr($markerline, "# END {$marker}")) $state = false;
|
|---|
| 850 | if($state) $result[] = $markerline;
|
|---|
| 851 | if(strstr($markerline, "# BEGIN {$marker}")) $state = true;
|
|---|
| 852 | }
|
|---|
| 853 | }
|
|---|
| 854 |
|
|---|
| 855 | return $result;
|
|---|
| 856 | }
|
|---|
| 857 |
|
|---|
| 858 | function save_mod_rewrite_rules() {
|
|---|
| 859 | global $is_apache, $wp_rewrite;
|
|---|
| 860 | $home_path = get_home_path();
|
|---|
| 861 |
|
|---|
| 862 | if (! $wp_rewrite->using_mod_rewrite_permalinks())
|
|---|
| 863 | return;
|
|---|
| 864 |
|
|---|
| 865 | if ( ! ((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')) )
|
|---|
| 866 | return;
|
|---|
| 867 |
|
|---|
| 868 | if (! $is_apache)
|
|---|
| 869 | return;
|
|---|
| 870 |
|
|---|
| 871 | $rules = explode("\n", $wp_rewrite->mod_rewrite_rules());
|
|---|
| 872 | insert_with_markers($home_path.'.htaccess', 'WordPress', $rules);
|
|---|
| 873 | }
|
|---|
| 874 |
|
|---|
| 875 | function the_quicktags () {
|
|---|
| 876 | // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP
|
|---|
| 877 | if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) :
|
|---|
| 878 | echo '
|
|---|
| 879 | <div id="quicktags">
|
|---|
| 880 | <script src="quicktags.js" type="text/javascript"></script>
|
|---|
| 881 | <script type="text/javascript">edToolbar();</script>
|
|---|
| 882 | ';
|
|---|
| 883 | echo '</div>';
|
|---|
| 884 | endif;
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | function validate_current_theme() {
|
|---|
| 888 | $theme_loc = 'wp-content/themes';
|
|---|
| 889 | $theme_root = ABSPATH . $theme_loc;
|
|---|
| 890 |
|
|---|
| 891 | $template = get_settings('template');
|
|---|
| 892 | $stylesheet = get_settings('stylesheet');
|
|---|
| 893 |
|
|---|
| 894 | if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) {
|
|---|
| 895 | update_option('template', 'default');
|
|---|
| 896 | update_option('stylesheet', 'default');
|
|---|
| 897 | do_action('switch_theme', 'Default');
|
|---|
| 898 | return false;
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | if (($stylesheet != 'default') && (! file_exists("$theme_root/$stylesheet/style.css"))) {
|
|---|
| 902 | update_option('template', 'default');
|
|---|
| 903 | update_option('stylesheet', 'default');
|
|---|
| 904 | do_action('switch_theme', 'Default');
|
|---|
| 905 | return false;
|
|---|
| 906 | }
|
|---|
| 907 |
|
|---|
| 908 | return true;
|
|---|
| 909 | }
|
|---|
| 910 |
|
|---|
| 911 | function get_broken_themes() {
|
|---|
| 912 | global $wp_broken_themes;
|
|---|
| 913 |
|
|---|
| 914 | get_themes();
|
|---|
| 915 | return $wp_broken_themes;
|
|---|
| 916 | }
|
|---|
| 917 |
|
|---|
| 918 | function get_page_templates() {
|
|---|
| 919 | $themes = get_themes();
|
|---|
| 920 | $theme = get_current_theme();
|
|---|
| 921 | $templates = $themes[$theme]['Template Files'];
|
|---|
| 922 | $page_templates = array();
|
|---|
| 923 |
|
|---|
| 924 | if( is_array( $templates ) ) {
|
|---|
| 925 | foreach ($templates as $template) {
|
|---|
| 926 | $template_data = implode('', file(ABSPATH . $template));
|
|---|
| 927 | preg_match("|Template Name:(.*)|i", $template_data, $name);
|
|---|
| 928 | preg_match("|Description:(.*)|i", $template_data, $description);
|
|---|
| 929 |
|
|---|
| 930 | $name = $name[1];
|
|---|
| 931 | $description = $description[1];
|
|---|
| 932 |
|
|---|
| 933 | if (! empty($name)) {
|
|---|
| 934 | $page_templates[trim($name)] = basename($template);
|
|---|
| 935 | }
|
|---|
| 936 | }
|
|---|
| 937 | }
|
|---|
| 938 |
|
|---|
| 939 | return $page_templates;
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | function page_template_dropdown($default = '') {
|
|---|
| 943 | $templates = get_page_templates();
|
|---|
| 944 | foreach (array_keys($templates) as $template) :
|
|---|
| 945 | if ($default == $templates[$template]) $selected = " selected='selected'";
|
|---|
| 946 | else $selected = '';
|
|---|
| 947 | echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>";
|
|---|
| 948 | endforeach;
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | function parent_dropdown($default = 0, $parent = 0, $level = 0) {
|
|---|
| 952 | global $wpdb, $post_ID;
|
|---|
| 953 | $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");
|
|---|
| 954 |
|
|---|
| 955 | if ($items) {
|
|---|
| 956 | foreach ($items as $item) {
|
|---|
| 957 | // A page cannot be it's own parent.
|
|---|
| 958 | if (!empty($post_ID)) {
|
|---|
| 959 | if ($item->ID == $post_ID) {
|
|---|
| 960 | continue;
|
|---|
| 961 | }
|
|---|
| 962 | }
|
|---|
| 963 | $pad = str_repeat(' ', $level * 3);
|
|---|
| 964 | if ($item->ID == $default)
|
|---|
| 965 | $current = ' selected="selected"';
|
|---|
| 966 | else
|
|---|
| 967 | $current = '';
|
|---|
| 968 |
|
|---|
| 969 | echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>";
|
|---|
| 970 | parent_dropdown($default, $item->ID, $level + 1);
|
|---|
| 971 | }
|
|---|
| 972 | } else {
|
|---|
| 973 | return false;
|
|---|
| 974 | }
|
|---|
| 975 | }
|
|---|
| 976 |
|
|---|
| 977 | function user_can_access_admin_page() {
|
|---|
| 978 | global $pagenow;
|
|---|
| 979 | global $menu;
|
|---|
| 980 | global $submenu;
|
|---|
| 981 |
|
|---|
| 982 | $parent = get_admin_page_parent();
|
|---|
| 983 |
|
|---|
| 984 | foreach ($menu as $menu_array) {
|
|---|
| 985 | //echo "parent array: " . $menu_array[2];
|
|---|
| 986 | if ($menu_array[2] == $parent) {
|
|---|
| 987 | if ( !current_user_can($menu_array[1]) ) {
|
|---|
| 988 | return false;
|
|---|
| 989 | } else {
|
|---|
| 990 | break;
|
|---|
| 991 | }
|
|---|
| 992 | }
|
|---|
| 993 | }
|
|---|
| 994 |
|
|---|
| 995 | if (isset($submenu[$parent])) {
|
|---|
| 996 | foreach ($submenu[$parent] as $submenu_array) {
|
|---|
| 997 | if ($submenu_array[2] == $pagenow) {
|
|---|
| 998 | if ( !current_user_can($submenu_array[1]) ) {
|
|---|
| 999 | return false;
|
|---|
| 1000 | } else {
|
|---|
| 1001 | return true;
|
|---|
| 1002 | }
|
|---|
| 1003 | }
|
|---|
| 1004 | }
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | return true;
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | function get_admin_page_title() {
|
|---|
| 1011 | global $title;
|
|---|
| 1012 | global $menu;
|
|---|
| 1013 | global $submenu;
|
|---|
| 1014 | global $pagenow;
|
|---|
| 1015 | global $plugin_page;
|
|---|
| 1016 |
|
|---|
| 1017 | if (isset($title) && ! empty($title)) {
|
|---|
| 1018 | return $title;
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | $parent = get_admin_page_parent();
|
|---|
| 1022 | if (empty($parent)) {
|
|---|
| 1023 | foreach ($menu as $menu_array) {
|
|---|
| 1024 | if (isset($menu_array[3])) {
|
|---|
| 1025 | if ($menu_array[2] == $pagenow) {
|
|---|
| 1026 | $title = $menu_array[3];
|
|---|
| 1027 | return $menu_array[3];
|
|---|
| 1028 | } else if (isset($plugin_page) && ($plugin_page == $menu_array[2])) {
|
|---|
| 1029 | $title = $menu_array[3];
|
|---|
| 1030 | return $menu_array[3];
|
|---|
| 1031 | }
|
|---|
| 1032 | }
|
|---|
| 1033 | }
|
|---|
| 1034 | } else {
|
|---|
| 1035 | foreach (array_keys($submenu) as $parent) {
|
|---|
| 1036 | foreach ($submenu[$parent] as $submenu_array) {
|
|---|
| 1037 | if (isset($submenu_array[3])) {
|
|---|
| 1038 | if ($submenu_array[2] == $pagenow) {
|
|---|
| 1039 | $title = $submenu_array[3];
|
|---|
| 1040 | return $submenu_array[3];
|
|---|
| 1041 | } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) {
|
|---|
| 1042 | $title = $submenu_array[3];
|
|---|
| 1043 | return $submenu_array[3];
|
|---|
| 1044 | }
|
|---|
| 1045 | }
|
|---|
| 1046 | }
|
|---|
| 1047 | }
|
|---|
| 1048 | }
|
|---|
| 1049 |
|
|---|
| 1050 | return '';
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | function get_admin_page_parent() {
|
|---|
| 1054 | global $parent_file;
|
|---|
| 1055 | global $menu;
|
|---|
| 1056 | global $submenu;
|
|---|
| 1057 | global $pagenow;
|
|---|
| 1058 | global $plugin_page;
|
|---|
| 1059 |
|
|---|
| 1060 | if (isset($parent_file) && ! empty($parent_file)) {
|
|---|
| 1061 | return $parent_file;
|
|---|
| 1062 | }
|
|---|
| 1063 |
|
|---|
| 1064 | if ($pagenow == 'admin.php' && isset($plugin_page)) {
|
|---|
| 1065 | foreach ($menu as $parent_menu) {
|
|---|
| 1066 | if ($parent_menu[2] == $plugin_page) {
|
|---|
| 1067 | $parent_file = $plugin_page;
|
|---|
| 1068 | return $plugin_page;
|
|---|
| 1069 | }
|
|---|
| 1070 | }
|
|---|
| 1071 | }
|
|---|
| 1072 |
|
|---|
| 1073 | foreach (array_keys($submenu) as $parent) {
|
|---|
| 1074 | foreach ($submenu[$parent] as $submenu_array) {
|
|---|
| 1075 | if ($submenu_array[2] == $pagenow) {
|
|---|
| 1076 | $parent_file = $parent;
|
|---|
| 1077 | return $parent;
|
|---|
| 1078 | } else if (isset($plugin_page) && ($plugin_page == $submenu_array[2])) {
|
|---|
| 1079 | $parent_file = $parent;
|
|---|
| 1080 | return $parent;
|
|---|
| 1081 | }
|
|---|
| 1082 | }
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | $parent_file = '';
|
|---|
| 1086 | return '';
|
|---|
| 1087 | }
|
|---|
| 1088 |
|
|---|
| 1089 | function add_menu_page($page_title, $menu_title, $access_level, $file, $function = '') {
|
|---|
| 1090 | global $menu, $admin_page_hooks;
|
|---|
| 1091 |
|
|---|
| 1092 | $file = plugin_basename($file);
|
|---|
| 1093 |
|
|---|
| 1094 | $menu[] = array($menu_title, $access_level, $file, $page_title);
|
|---|
| 1095 |
|
|---|
| 1096 | $admin_page_hooks[$file] = sanitize_title($menu_title);
|
|---|
| 1097 |
|
|---|
| 1098 | $hookname = get_plugin_page_hookname($file, '');
|
|---|
| 1099 | if ( !empty($function) && !empty($hookname) )
|
|---|
| 1100 | add_action($hookname, $function);
|
|---|
| 1101 |
|
|---|
| 1102 | return $hookname;
|
|---|
| 1103 | }
|
|---|
| 1104 |
|
|---|
| 1105 | function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') {
|
|---|
| 1106 | global $submenu;
|
|---|
| 1107 | global $menu;
|
|---|
| 1108 |
|
|---|
| 1109 | $parent = plugin_basename($parent);
|
|---|
| 1110 | $file = plugin_basename($file);
|
|---|
| 1111 |
|
|---|
| 1112 | // If the parent doesn't already have a submenu, add a link to the parent
|
|---|
| 1113 | // as the first item in the submenu. If the submenu file is the same as the
|
|---|
| 1114 | // parent file someone is trying to link back to the parent manually. In
|
|---|
| 1115 | // this case, don't automatically add a link back to avoid duplication.
|
|---|
| 1116 | if (! isset($submenu[$parent]) && $file != $parent) {
|
|---|
| 1117 | foreach ($menu as $parent_menu) {
|
|---|
| 1118 | if ($parent_menu[2] == $parent) {
|
|---|
| 1119 | $submenu[$parent][] = $parent_menu;
|
|---|
| 1120 | }
|
|---|
| 1121 | }
|
|---|
| 1122 | }
|
|---|
| 1123 |
|
|---|
| 1124 | $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
|
|---|
| 1125 |
|
|---|
| 1126 | $hookname = get_plugin_page_hookname($file, $parent);
|
|---|
| 1127 | if ( !empty($function) && !empty($hookname) )
|
|---|
| 1128 | add_action($hookname, $function);
|
|---|
| 1129 |
|
|---|
| 1130 | return $hookname;
|
|---|
| 1131 | }
|
|---|
| 1132 |
|
|---|
| 1133 | function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') {
|
|---|
| 1134 | return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function);
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') {
|
|---|
| 1138 | return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function);
|
|---|
| 1139 | }
|
|---|
| 1140 |
|
|---|
| 1141 | function validate_file($file, $allowed_files = '') {
|
|---|
| 1142 | if ( false !== strpos($file, './'))
|
|---|
| 1143 | return 1;
|
|---|
| 1144 |
|
|---|
| 1145 | if (':' == substr($file,1,1))
|
|---|
| 1146 | return 2;
|
|---|
| 1147 |
|
|---|
| 1148 | if ( !empty($allowed_files) && (! in_array($file, $allowed_files)) )
|
|---|
| 1149 | return 3;
|
|---|
| 1150 |
|
|---|
| 1151 | return 0;
|
|---|
| 1152 | }
|
|---|
| 1153 |
|
|---|
| 1154 | function validate_file_to_edit($file, $allowed_files = '') {
|
|---|
| 1155 | $file = stripslashes($file);
|
|---|
| 1156 |
|
|---|
| 1157 | $code = validate_file($file, $allowed_files);
|
|---|
| 1158 |
|
|---|
| 1159 | if (! $code)
|
|---|
| 1160 | return $file;
|
|---|
| 1161 |
|
|---|
| 1162 | switch ($code) {
|
|---|
| 1163 | case 1:
|
|---|
| 1164 | 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.'));
|
|---|
| 1165 |
|
|---|
| 1166 | case 2:
|
|---|
| 1167 | die (__('Sorry, can’t call files with their real path.'));
|
|---|
| 1168 |
|
|---|
| 1169 | case 3:
|
|---|
| 1170 | die (__('Sorry, that file cannot be edited.'));
|
|---|
| 1171 | }
|
|---|
| 1172 | }
|
|---|
| 1173 |
|
|---|
| 1174 | function get_home_path() {
|
|---|
| 1175 | $home = get_settings('home');
|
|---|
| 1176 | if ( $home != '' && $home != get_settings('siteurl') ) {
|
|---|
| 1177 | $home_path = parse_url($home);
|
|---|
| 1178 | $home_path = $home_path['path'];
|
|---|
| 1179 | $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]);
|
|---|
| 1180 | $home_path = trailingslashit($root . $home_path);
|
|---|
| 1181 | } else {
|
|---|
| 1182 | $home_path = ABSPATH;
|
|---|
| 1183 | }
|
|---|
| 1184 |
|
|---|
| 1185 | return $home_path;
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | function get_real_file_to_edit($file) {
|
|---|
| 1189 | if ('index.php' == $file ||
|
|---|
| 1190 | '.htaccess' == $file) {
|
|---|
| 1191 | $real_file = get_home_path() . $file;
|
|---|
| 1192 | } else {
|
|---|
| 1193 | $real_file = ABSPATH . $file;
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | return $real_file;
|
|---|
| 1197 | }
|
|---|
| 1198 |
|
|---|
| 1199 | $wp_file_descriptions =
|
|---|
| 1200 | array(
|
|---|
| 1201 | 'index.php' => __('Main Template'),
|
|---|
| 1202 | 'style.css' => __('Stylesheet'),
|
|---|
| 1203 | 'comments.php' => __('Comments Template'),
|
|---|
| 1204 | 'comments-popup.php' => __('Popup Comments Template'),
|
|---|
| 1205 | 'footer.php' => __('Footer Template'),
|
|---|
| 1206 | 'header.php' => __('Header Template'),
|
|---|
| 1207 | 'sidebar.php' => __('Sidebar Template'),
|
|---|
| 1208 | 'archive.php' => __('Archive Template'),
|
|---|
| 1209 | 'category.php' => __('Category Template'),
|
|---|
| 1210 | 'page.php' => __('Page Template'),
|
|---|
| 1211 | 'search.php' => __('Search Template'),
|
|---|
| 1212 | 'single.php' => __('Post Template'),
|
|---|
| 1213 | '404.php' => __('404 Template'),
|
|---|
| 1214 | 'my-hacks.php' => __('my-hacks.php (legacy hacks support)'),
|
|---|
| 1215 | '.htaccess' => __('.htaccess (for rewrite rules)'),
|
|---|
| 1216 | // Deprecated files
|
|---|
| 1217 | 'wp-layout.css' => __('Stylesheet'),
|
|---|
| 1218 | 'wp-comments.php' => __('Comments Template'),
|
|---|
| 1219 | 'wp-comments-popup.php' => __('Popup Comments Template')
|
|---|
| 1220 | );
|
|---|
| 1221 |
|
|---|
| 1222 | function get_file_description($file) {
|
|---|
| 1223 | global $wp_file_descriptions;
|
|---|
| 1224 |
|
|---|
| 1225 | if ( isset($wp_file_descriptions[basename($file)] ) ) {
|
|---|
| 1226 | return $wp_file_descriptions[basename($file)];
|
|---|
| 1227 | } elseif ( file_exists( ABSPATH . $file ) ) {
|
|---|
| 1228 | $template_data = implode('', file(ABSPATH . $file));
|
|---|
| 1229 | if ( preg_match("|Template Name:(.*)|i", $template_data, $name) )
|
|---|
| 1230 | return $name[1];
|
|---|
| 1231 | }
|
|---|
| 1232 |
|
|---|
| 1233 | return basename( $file );
|
|---|
| 1234 | }
|
|---|
| 1235 |
|
|---|
| 1236 | function update_recently_edited($file) {
|
|---|
| 1237 | $oldfiles = (array) get_option('recently_edited');
|
|---|
| 1238 | if ($oldfiles) {
|
|---|
| 1239 | $oldfiles = array_reverse($oldfiles);
|
|---|
| 1240 | $oldfiles[] = $file;
|
|---|
| 1241 | $oldfiles = array_reverse($oldfiles);
|
|---|
| 1242 | $oldfiles = array_unique($oldfiles);
|
|---|
| 1243 | if ( 5 < count($oldfiles) )
|
|---|
| 1244 | array_pop($oldfiles);
|
|---|
| 1245 | } else {
|
|---|
| 1246 | $oldfiles[] = $file;
|
|---|
| 1247 | }
|
|---|
| 1248 | update_option('recently_edited', $oldfiles);
|
|---|
| 1249 | }
|
|---|
| 1250 |
|
|---|
| 1251 | function get_plugin_data($plugin_file) {
|
|---|
| 1252 | $plugin_data = implode('', file($plugin_file));
|
|---|
| 1253 | preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
|
|---|
| 1254 | preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
|
|---|
| 1255 | preg_match("|Description:(.*)|i", $plugin_data, $description);
|
|---|
| 1256 | preg_match("|Author:(.*)|i", $plugin_data, $author_name);
|
|---|
| 1257 | preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
|
|---|
| 1258 | if ( preg_match("|Version:(.*)|i", $plugin_data, $version) )
|
|---|
| 1259 | $version = $version[1];
|
|---|
| 1260 | else
|
|---|
| 1261 | $version ='';
|
|---|
| 1262 |
|
|---|
| 1263 | $description = wptexturize($description[1]);
|
|---|
| 1264 |
|
|---|
| 1265 | $name = $plugin_name[1];
|
|---|
| 1266 | $name = trim($name);
|
|---|
| 1267 | $plugin = $name;
|
|---|
| 1268 | if ('' != $plugin_uri[1] && '' != $name) {
|
|---|
| 1269 | $plugin = '<a href="' . $plugin_uri[1] . '" title="' . __('Visit plugin homepage') . '">' . $plugin . '</a>';
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | if ('' == $author_uri[1]) {
|
|---|
| 1273 | $author = $author_name[1];
|
|---|
| 1274 | } else {
|
|---|
| 1275 | $author = '<a href="' . $author_uri[1] . '" title="' . __('Visit author homepage') . '">' . $author_name[1] . '</a>';
|
|---|
| 1276 | }
|
|---|
| 1277 |
|
|---|
| 1278 | return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
|
|---|
| 1279 | }
|
|---|
| 1280 |
|
|---|
| 1281 | function get_plugins() {
|
|---|
| 1282 | global $wp_plugins;
|
|---|
| 1283 |
|
|---|
| 1284 | if (isset($wp_plugins)) {
|
|---|
| 1285 | return $wp_plugins;
|
|---|
| 1286 | }
|
|---|
| 1287 |
|
|---|
| 1288 | $wp_plugins = array();
|
|---|
| 1289 | $plugin_loc = 'wp-content/plugins';
|
|---|
| 1290 | $plugin_root = ABSPATH . $plugin_loc;
|
|---|
| 1291 |
|
|---|
| 1292 | // Files in wp-content/plugins directory
|
|---|
| 1293 | $plugins_dir = @ dir($plugin_root);
|
|---|
| 1294 | if ($plugins_dir) {
|
|---|
| 1295 | while(($file = $plugins_dir->read()) !== false) {
|
|---|
| 1296 | if ( preg_match('|^\.+$|', $file) )
|
|---|
| 1297 | continue;
|
|---|
| 1298 | if (is_dir($plugin_root . '/' . $file)) {
|
|---|
| 1299 | $plugins_subdir = @ dir($plugin_root . '/' . $file);
|
|---|
| 1300 | if ($plugins_subdir) {
|
|---|
| 1301 | while(($subfile = $plugins_subdir->read()) !== false) {
|
|---|
| 1302 | if ( preg_match('|^\.+$|', $subfile) )
|
|---|
| 1303 | continue;
|
|---|
| 1304 | if ( preg_match('|\.php$|', $subfile) )
|
|---|
| 1305 | $plugin_files[] = "$file/$subfile";
|
|---|
| 1306 | }
|
|---|
| 1307 | }
|
|---|
| 1308 | } else {
|
|---|
| 1309 | if ( preg_match('|\.php$|', $file) )
|
|---|
| 1310 | $plugin_files[] = $file;
|
|---|
| 1311 | }
|
|---|
| 1312 | }
|
|---|
| 1313 | }
|
|---|
| 1314 |
|
|---|
| 1315 | if (!$plugins_dir || !$plugin_files) {
|
|---|
| 1316 | return $wp_plugins;
|
|---|
| 1317 | }
|
|---|
| 1318 |
|
|---|
| 1319 | sort($plugin_files);
|
|---|
| 1320 |
|
|---|
| 1321 | foreach($plugin_files as $plugin_file) {
|
|---|
| 1322 | $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
|
|---|
| 1323 |
|
|---|
| 1324 | if (empty($plugin_data['Name'])) {
|
|---|
| 1325 | continue;
|
|---|
| 1326 | }
|
|---|
| 1327 |
|
|---|
| 1328 | $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
|
|---|
| 1329 | }
|
|---|
| 1330 |
|
|---|
| 1331 | return $wp_plugins;
|
|---|
| 1332 | }
|
|---|
| 1333 |
|
|---|
| 1334 | function get_plugin_page_hookname($plugin_page, $parent_page) {
|
|---|
| 1335 | global $admin_page_hooks;
|
|---|
| 1336 |
|
|---|
| 1337 | $parent = get_admin_page_parent();
|
|---|
| 1338 |
|
|---|
| 1339 | if ( empty($parent_page) || 'admin.php' == $parent_page ) {
|
|---|
| 1340 | if ( isset($admin_page_hooks[$plugin_page]) )
|
|---|
| 1341 | $page_type = 'toplevel';
|
|---|
| 1342 | else if ( isset($admin_page_hooks[$parent]) )
|
|---|
| 1343 | $page_type = $admin_page_hooks[$parent];
|
|---|
| 1344 | } else if ( isset($admin_page_hooks[$parent_page]) ) {
|
|---|
| 1345 | $page_type = $admin_page_hooks[$parent_page];
|
|---|
| 1346 | } else {
|
|---|
| 1347 | $page_type = 'admin';
|
|---|
| 1348 | }
|
|---|
| 1349 |
|
|---|
| 1350 | $plugin_name = preg_replace('!\.php!', '', $plugin_page);
|
|---|
| 1351 |
|
|---|
| 1352 | return $page_type . '_page_' . $plugin_name;
|
|---|
| 1353 | }
|
|---|
| 1354 |
|
|---|
| 1355 | function get_plugin_page_hook($plugin_page, $parent_page) {
|
|---|
| 1356 | global $wp_filter;
|
|---|
| 1357 |
|
|---|
| 1358 | $hook = get_plugin_page_hookname($plugin_page, $parent_page);
|
|---|
| 1359 | if ( isset($wp_filter[$hook]) )
|
|---|
| 1360 | return $hook;
|
|---|
| 1361 | else
|
|---|
| 1362 | return '';
|
|---|
| 1363 | }
|
|---|
| 1364 |
|
|---|
| 1365 | function pimp_firefox() {
|
|---|
| 1366 | if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'Firefox' ) )
|
|---|
| 1367 | return;
|
|---|
| 1368 | $getit = __('WordPress recommends the open-source Firefox browser');
|
|---|
| 1369 | echo '
|
|---|
| 1370 | <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>
|
|---|
| 1371 | ';
|
|---|
| 1372 | }
|
|---|
| 1373 | add_action('admin_footer', 'pimp_firefox');
|
|---|
| 1374 |
|
|---|
| 1375 | function documentation_link( $for ) {
|
|---|
| 1376 | return;
|
|---|
| 1377 | }
|
|---|
| 1378 |
|
|---|
| 1379 | ?>
|
|---|