### Eclipse Workspace Patch 1.0
#P wordpress-trunk bare
|
|
|
1 | 1 | <?php |
2 | | /* |
3 | | * app.php - Atom Publishing Protocol support for WordPress |
4 | | * Original code by: Elias Torres, http://torrez.us/archives/2006/08/31/491/ |
5 | | * Modified by: Dougal Campbell, http://dougal.gunters.org/ |
6 | | * |
7 | | * Version: 1.0.0-dc |
8 | | */ |
9 | | |
10 | | define('APP_REQUEST', true); |
| 2 | // vim:sw=2:sts=2:ts=2:noet:sta:tw=200 |
| 3 | /* |
| 4 | An Atom Publishing Protocol implementation for WordPress. |
| 5 | Author: Elias Torres <elias@torrez.us> |
| 6 | */ |
11 | 7 | |
12 | | require_once('wp-config.php'); |
| 8 | /* |
13 | 9 | |
14 | | $use_querystring = 1; |
| 10 | Copyright 2006 Elias Torres <elias@torrez.us> |
15 | 11 | |
16 | | // If using querystring, we need to put the path together manually: |
17 | | if ($use_querystring) { |
18 | | $_GLOBALS['use_querystring'] = $use_querystring; |
19 | | $action = $_GET['action']; |
20 | | $eid = (int) $_GET['eid']; |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 2 of the License, or |
| 15 | (at your option) any later version. |
21 | 16 | |
22 | | $_SERVER['PATH_INFO'] = $action; |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | |
| 26 | */ |
23 | 27 | |
24 | | if ($eid) { |
25 | | $_SERVER['PATH_INFO'] .= "/$eid"; |
26 | | } |
27 | | } else { |
28 | | $_SERVER['PATH_INFO'] = str_replace( '/app.php', '', $_SERVER['REQUEST_URI'] ); |
| 28 | define('APP_REQUEST', true); |
| 29 | |
| 30 | require_once('wp-config.php'); |
| 31 | |
| 32 | if (!isset($PATH_INFO)) { |
| 33 | $PATH_INFO = substr($_SERVER['REQUEST_URI'],strlen($_SERVER['SCRIPT_NAME']), |
| 34 | strlen($_SERVER['REQUEST_URI'])); |
29 | 35 | } |
30 | 36 | |
31 | 37 | $app_logging = 1; |
… |
… |
|
91 | 97 | global $app_logging; |
92 | 98 | array_unshift($this->ns_contexts, array()); |
93 | 99 | |
94 | | $parser = xml_parser_create_ns(); |
| 100 | $parser = xml_parser_create_ns("UTF-8"); |
95 | 101 | xml_set_object($parser, $this); |
96 | 102 | xml_set_element_handler($parser, "start_element", "end_element"); |
97 | 103 | xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
… |
… |
|
109 | 115 | |
110 | 116 | if($app_logging) $contents .= $line; |
111 | 117 | |
112 | | if(!xml_parse($parser, $line)) { |
| 118 | if(!xml_parse($parser, $line, feof($fp))) { |
113 | 119 | log_app("xml_parse_error", "line: $line"); |
114 | | $this->error = sprintf("XML error: %s at line %d\n", |
115 | | xml_error_string(xml_get_error_code($xml_parser)), |
116 | | xml_get_current_line_number($xml_parser)); |
117 | | log_app("xml_parse_error", $this->error); |
| 120 | xml_parser_free($parser); |
118 | 121 | return false; |
119 | 122 | } |
120 | 123 | } |
… |
… |
|
290 | 293 | array('GET' => 'get_posts', |
291 | 294 | 'POST' => 'create_post'), |
292 | 295 | '@/attachments/?(\d+)?@' => |
293 | | array('GET' => 'get_attachment', |
| 296 | array('GET' => 'get_attachments', |
294 | 297 | 'POST' => 'create_attachment'), |
295 | 298 | '@/attachment/file/(\d+)@' => |
296 | 299 | array('GET' => 'get_file', |
… |
… |
|
308 | 311 | $path = $_SERVER['PATH_INFO']; |
309 | 312 | $method = $_SERVER['REQUEST_METHOD']; |
310 | 313 | |
311 | | log_app('REQUEST',"$method $path\n================"); |
| 314 | $this->process_conditionals(); |
312 | 315 | |
313 | | //$this->process_conditionals(); |
314 | | |
315 | 316 | // exception case for HEAD (treat exactly as GET, but don't output) |
316 | 317 | if($method == 'HEAD') { |
317 | 318 | $this->do_output = false; |
… |
… |
|
319 | 320 | } |
320 | 321 | |
321 | 322 | // lame. |
322 | | if(strlen($path) == 0 || $path == '/') { |
| 323 | if(strlen($path) == 0) { |
323 | 324 | $path = '/service'; |
324 | 325 | } |
325 | 326 | |
… |
… |
|
346 | 347 | } |
347 | 348 | |
348 | 349 | function get_service() { |
349 | | log_app('function','get_service()'); |
350 | 350 | $entries_url = $this->get_entries_url(); |
351 | 351 | $media_url = $this->get_attachments_url(); |
352 | 352 | $accepted_content_types = join(',',$this->media_content_types); |
353 | 353 | $introspection = <<<EOD |
354 | 354 | <service xmlns="http://purl.org/atom/app#" xmlns:atom="http://www.w3.org/2005/Atom"> |
355 | 355 | <workspace title="WordPress Experimental Workspace"> |
356 | | <collection href="$entries_url" title="WordPress Posts"> |
| 356 | <collection href="$entries_url"> |
357 | 357 | <accept>entry</accept> |
358 | 358 | <atom:title>WordPress Posts</atom:title> |
359 | 359 | </collection> |
360 | | <collection href="$media_url" title="WordPress Media"> |
| 360 | <collection href="$media_url"> |
361 | 361 | <accept>$accepted_content_types</accept> |
362 | 362 | <atom:title>WordPress Media</atom:title> |
363 | 363 | </collection> |
… |
… |
|
394 | 394 | $post_author = $user->ID; |
395 | 395 | $post_title = $entry->title; |
396 | 396 | $post_content = $entry->content; |
397 | | $post_excerpt = $entry->summary; |
398 | 397 | $post_date = current_time('mysql'); |
399 | 398 | $post_date_gmt = current_time('mysql', 1); |
400 | 399 | |
401 | | $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); |
| 400 | $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); |
402 | 401 | |
403 | 402 | $postID = wp_insert_post($post_data); |
404 | 403 | |
… |
… |
|
408 | 407 | |
409 | 408 | $output = $this->get_entry($postID); |
410 | 409 | |
411 | | log_app('function',"create_post($postID)"); |
412 | 410 | $this->created($postID, $output); |
413 | 411 | } |
414 | 412 | |
… |
… |
|
417 | 415 | global $entry; |
418 | 416 | $this->set_current_entry($postID); |
419 | 417 | $output = $this->get_entry($postID); |
420 | | log_app('function',"get_post($postID)"); |
421 | 418 | $this->output($output); |
422 | 419 | |
423 | 420 | } |
… |
… |
|
449 | 446 | |
450 | 447 | $post_title = $parsed->title; |
451 | 448 | $post_content = $parsed->content; |
452 | | $post_excerpt = $parsed->summary; |
453 | 449 | |
454 | 450 | // let's not go backwards and make something draft again. |
455 | 451 | if(!$publish && $post_status == 'draft') { |
… |
… |
|
464 | 460 | $this->internal_error('For some strange yet very annoying reason, this post could not be edited.'); |
465 | 461 | } |
466 | 462 | |
467 | | log_app('function',"put_post($postID)"); |
468 | 463 | $this->ok(); |
469 | 464 | } |
470 | 465 | |
… |
… |
|
477 | 472 | if(!current_user_can('edit_post', $postID)) { |
478 | 473 | $this->auth_required('Sorry, you do not have the right to delete this post.'); |
479 | 474 | } |
480 | | |
481 | | if ($entry['post_type'] == 'attachment') { |
482 | | $this->delete_attachment($postID); |
483 | | } else { |
484 | | $result = wp_delete_post($postID); |
485 | 475 | |
| 476 | $result = wp_delete_post($postID); |
| 477 | |
486 | 478 | if (!$result) { |
487 | 479 | $this->internal_error('For some strange yet very annoying reason, this post could not be deleted.'); |
488 | 480 | } |
489 | 481 | |
490 | | log_app('function',"delete_post($postID)"); |
491 | 482 | $this->ok(); |
492 | | } |
493 | | |
494 | 483 | } |
495 | | |
496 | | function get_attachment($postID = NULL) { |
497 | 484 | |
498 | | global $entry; |
499 | | if (!isset($postID)) { |
500 | | $this->get_attachments(); |
501 | | } else { |
502 | | $this->set_current_entry($postID); |
503 | | $output = $this->get_entry($postID, 'attachment'); |
504 | | log_app('function',"get_attachment($postID)"); |
505 | | $this->output($output); |
506 | | } |
507 | | } |
508 | | |
509 | 485 | function create_attachment() { |
510 | 486 | |
511 | 487 | $type = $this->get_accepted_content_type(); |
… |
… |
|
519 | 495 | $bits .= fread($fp, 4096); |
520 | 496 | } |
521 | 497 | fclose($fp); |
522 | | |
523 | | $slug = ''; |
524 | | if ( isset( $_SERVER['HTTP_SLUG'] ) ) |
525 | | $slug = sanitize_file_name( $_SERVER['HTTP_SLUG'] ); |
526 | | elseif ( isset( $_SERVER['HTTP_TITLE'] ) ) |
527 | | $slug = sanitize_file_name( $_SERVER['HTTP_TITLE'] ); |
528 | | elseif ( empty( $slug ) ) // just make a random name |
529 | | $slug = substr( md5( uniqid( microtime() ) ), 0, 7);; |
530 | | $ext = preg_replace( '|.*/([a-z]+)|', '$1', $_SERVER['CONTENT_TYPE'] ); |
531 | | $slug = "$slug.$ext"; |
532 | | $file = wp_upload_bits( $slug, NULL, $bits); |
533 | 498 | |
| 499 | $file = wp_upload_bits('noah.jpg',NULL,$bits); |
| 500 | |
534 | 501 | $url = $file['url']; |
535 | 502 | $file = $file['file']; |
536 | 503 | $filename = basename($file); |
537 | 504 | |
538 | | $header = apply_filters('wp_create_file_in_uploads', $file); // replicate |
539 | | |
540 | 505 | // Construct the attachment array |
541 | 506 | $attachment = array( |
542 | | 'post_title' => $slug, |
543 | | 'post_content' => $slug, |
| 507 | 'post_title' => $imgtitle ? $imgtitle : $filename, |
| 508 | 'post_content' => $descr, |
544 | 509 | 'post_status' => 'attachment', |
545 | 510 | 'post_parent' => 0, |
546 | 511 | 'post_mime_type' => $type, |
… |
… |
|
557 | 522 | $output = $this->get_entry($postID, 'attachment'); |
558 | 523 | |
559 | 524 | $this->created($postID, $output, 'attachment'); |
560 | | log_app('function',"create_attachment($postID)"); |
561 | 525 | } |
562 | 526 | |
563 | 527 | function put_attachment($postID) { |
… |
… |
|
596 | 560 | $this->internal_error('For some strange yet very annoying reason, this post could not be edited.'); |
597 | 561 | } |
598 | 562 | |
599 | | log_app('function',"put_attachment($postID)"); |
600 | 563 | $this->ok(); |
601 | 564 | } |
602 | 565 | |
603 | 566 | function delete_attachment($postID) { |
604 | | log_app('function',"delete_attachment($postID). File '$location' deleted."); |
605 | 567 | |
606 | 568 | // check for not found |
607 | 569 | global $entry; |
… |
… |
|
623 | 585 | $this->internal_error('For some strange yet very annoying reason, this post could not be deleted.'); |
624 | 586 | } |
625 | 587 | |
626 | | log_app('function',"delete_attachment($postID). File '$location' deleted."); |
627 | 588 | $this->ok(); |
628 | 589 | } |
629 | 590 | |
… |
… |
|
651 | 612 | } |
652 | 613 | fclose($fp); |
653 | 614 | |
654 | | log_app('function',"get_file($postID)"); |
655 | 615 | $this->ok(); |
656 | 616 | } |
657 | 617 | |
… |
… |
|
685 | 645 | fclose($fp); |
686 | 646 | fclose($localfp); |
687 | 647 | |
688 | | log_app('function',"put_file($postID)"); |
689 | 648 | $this->ok(); |
690 | 649 | } |
691 | 650 | |
692 | 651 | function get_entries_url($page = NULL) { |
693 | | global $use_querystring; |
694 | 652 | $url = get_bloginfo('url') . '/' . $this->script_name; |
695 | | if ($use_querystring) { |
696 | | $url .= '?action=/' . $this->ENTRIES_PATH; |
697 | | if(isset($page) && is_int($page)) { |
698 | | $url .= "&eid=$page"; |
699 | | } |
700 | | } else { |
701 | 653 | $url .= '/' . $this->ENTRIES_PATH; |
702 | 654 | if(isset($page) && is_int($page)) { |
703 | 655 | $url .= "/$page"; |
704 | 656 | } |
705 | | } |
706 | 657 | return $url; |
707 | 658 | } |
708 | 659 | |
… |
… |
|
712 | 663 | } |
713 | 664 | |
714 | 665 | function get_attachments_url($page = NULL) { |
715 | | global $use_querystring; |
716 | 666 | $url = get_bloginfo('url') . '/' . $this->script_name; |
717 | | if ($use_querystring) { |
718 | | $url .= '?action=/' . $this->MEDIA_PATH; |
719 | | if(isset($page) && is_int($page)) { |
720 | | $url .= "&eid=$page"; |
721 | | } |
722 | | } else { |
723 | 667 | $url .= '/' . $this->MEDIA_PATH; |
724 | 668 | if(isset($page) && is_int($page)) { |
725 | 669 | $url .= "/$page"; |
726 | 670 | } |
727 | | } |
728 | 671 | return $url; |
729 | 672 | } |
730 | 673 | |
… |
… |
|
735 | 678 | |
736 | 679 | |
737 | 680 | function get_entry_url($postID = NULL) { |
738 | | global $use_querystring; |
739 | 681 | if(!isset($postID)) { |
740 | 682 | global $post; |
741 | 683 | $postID = $post->ID; |
742 | 684 | } |
743 | | |
744 | | if ($use_querystring) { |
745 | | $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->ENTRY_PATH . "&eid=$postID"; |
746 | | } else { |
747 | | $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; |
748 | | } |
749 | 685 | |
750 | | log_app('function',"get_entry_url() = $url"); |
| 686 | $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; |
751 | 687 | return $url; |
752 | 688 | } |
753 | 689 | |
… |
… |
|
757 | 693 | } |
758 | 694 | |
759 | 695 | function get_media_url($postID = NULL) { |
760 | | global $use_querystring; |
761 | 696 | if(!isset($postID)) { |
762 | 697 | global $post; |
763 | 698 | $postID = $post->ID; |
764 | 699 | } |
765 | | |
766 | | if ($use_querystring) { |
767 | | $url = get_bloginfo('url') . '/' . $this->script_name . '?action=/' . $this->MEDIA_SINGLE_PATH ."&eid=$postID"; |
768 | | } else { |
769 | | $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/$postID"; |
770 | | } |
771 | 700 | |
772 | | log_app('function',"get_media_url() = $url"); |
| 701 | $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/$postID"; |
773 | 702 | return $url; |
774 | 703 | } |
775 | 704 | |
… |
… |
|
780 | 709 | |
781 | 710 | function set_current_entry($postID) { |
782 | 711 | global $entry; |
783 | | log_app('function',"set_current_entry($postID)"); |
784 | 712 | |
785 | 713 | if(!isset($postID)) { |
786 | | // $this->bad_request(); |
787 | | $this->not_found(); |
| 714 | $this->bad_request(); |
788 | 715 | } |
789 | 716 | |
790 | 717 | $entry = wp_get_single_post($postID,ARRAY_A); |
… |
… |
|
797 | 724 | |
798 | 725 | function get_posts_count() { |
799 | 726 | global $wpdb; |
800 | | log_app('function',"get_posts_count()"); |
801 | 727 | return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date_gmt < '" . gmdate("Y-m-d H:i:s",time()) . "'"); |
802 | 728 | } |
803 | 729 | |
804 | 730 | |
805 | | function get_posts($page = 1, $post_type = 'post') { |
806 | | log_app('function',"get_posts($page, '$post_type')"); |
807 | | $feed = $this->get_feed($page, $post_type); |
808 | | $this->output($feed); |
| 731 | function get_posts($page = 1) { |
| 732 | $feed = $this->get_feed($page); |
| 733 | $this->output($feed, $do_output); |
809 | 734 | } |
810 | 735 | |
811 | | function get_attachments($page = 1, $post_type = 'attachment') { |
812 | | log_app('function',"get_attachments($page, '$post_type')"); |
813 | | $feed = $this->get_feed($page, $post_type); |
814 | | $this->output($feed); |
815 | | } |
816 | | |
817 | 736 | function get_feed($page = 1, $post_type = 'post') { |
818 | | log_app('function',"get_feed($page, '$post_type')"); |
| 737 | log_app("get_feed", $post_type); |
819 | 738 | ob_start(); |
820 | 739 | |
821 | 740 | if(!isset($page)) { |
… |
… |
|
826 | 745 | $count = get_settings('posts_per_rss'); |
827 | 746 | $query = "paged=$page&posts_per_page=$count&order=DESC"; |
828 | 747 | if($post_type == 'attachment') { |
829 | | $query .= "&post_type=$post_type"; |
| 748 | $query .= "&show_post_type=$post_type"; |
830 | 749 | } |
831 | 750 | query_posts($query); |
832 | 751 | global $post; |
833 | 752 | |
| 753 | $feed_update = get_lastpostmodified('GMT') ? get_lastpostmodified('GMT') : current_time('mysql', 1); |
834 | 754 | $total_count = $this->get_posts_count(); |
835 | 755 | $last_page = (int) ceil($total_count / $count); |
836 | 756 | $next_page = (($page + 1) > $last_page) ? NULL : $page + 1; |
837 | 757 | $prev_page = ($page - 1) < 1 ? NULL : $page - 1; |
838 | | $last_page = ((int)$last_page == 1 || (int)$last_page == 0) ? NULL : (int) $last_page; |
| 758 | $last_page = ((int)$last_page <= 1) ? NULL : (int) $last_page; |
839 | 759 | ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xml:lang="<?php echo get_option('rss_language'); ?>"> |
840 | 760 | <id><?php $this->the_entries_url() ?></id> |
841 | | <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT')); ?></updated> |
| 761 | <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', $feed_update); ?></updated> |
842 | 762 | <title type="text"><?php bloginfo_rss('name') ?></title> |
843 | 763 | <subtitle type="text"><?php bloginfo_rss("description") ?></subtitle> |
844 | 764 | <link rel="first" type="application/atom+xml" href="<?php $this->the_entries_url() ?>" /> |
… |
… |
|
851 | 771 | <link rel="last" type="application/atom+xml" href="<?php $this->the_entries_url($last_page) ?>" /> |
852 | 772 | <link rel="self" type="application/atom+xml" href="<?php $this->the_entries_url() ?>" /> |
853 | 773 | <rights type="text">Copyright <?php echo mysql2date('Y', get_lastpostdate('blog')); ?></rights> |
854 | | <generator uri="http://wordpress.com/" version="1.0.0-dc">WordPress.com Atom API</generator> |
| 774 | <generator uri="http://wordpress.org/" version="<?php bloginfo_rss('version'); ?>">WordPress APP</generator> |
855 | 775 | <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> |
856 | 776 | <entry> |
857 | 777 | <id><?php the_guid(); ?></id> |
858 | | <title type="html"><![CDATA[<?php the_title() ?>]]></title> |
| 778 | <title type="html"><![CDATA[<?php the_title_rss() ?>]]></title> |
859 | 779 | <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> |
860 | 780 | <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> |
861 | 781 | <app:control> |
… |
… |
|
878 | 798 | <?php foreach(get_the_category() as $category) { ?> |
879 | 799 | <category scheme="<?php bloginfo_rss('home') ?>" term="<?php echo $category->cat_name?>" /> |
880 | 800 | <?php } ?> <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> |
881 | | <?php if ( strlen( $post->post_content ) ) : ?> |
882 | | <content type="html"><?php echo get_the_content('', 0, '') ?></content> |
883 | | <?php endif; ?> |
884 | 801 | </entry> |
885 | 802 | <?php |
886 | 803 | endwhile; |
… |
… |
|
889 | 806 | <?php |
890 | 807 | $feed = ob_get_contents(); |
891 | 808 | ob_end_clean(); |
| 809 | log_app("get_feed", $feed); |
892 | 810 | return $feed; |
893 | 811 | } |
894 | 812 | |
895 | 813 | function get_entry($postID, $post_type = 'post') { |
896 | | log_app('function',"get_entry($postID, '$post_type')"); |
897 | 814 | ob_start(); |
898 | | global $posts, $post, $wp_query; |
| 815 | global $post; |
899 | 816 | switch($post_type) { |
900 | 817 | case 'post': |
901 | 818 | $varname = 'p'; |
… |
… |
|
909 | 826 | <entry xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://purl.org/atom/app#" xml:lang="<?php echo get_option('rss_language'); ?>"> |
910 | 827 | <id><?php the_guid(); ?></id> |
911 | 828 | <title type="html"><![CDATA[<?php the_title_rss() ?>]]></title> |
912 | | |
913 | 829 | <updated><?php echo get_post_modified_time('Y-m-d\TH:i:s\Z', true); ?></updated> |
914 | 830 | <published><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></published> |
915 | 831 | <app:control> |
… |
… |
|
920 | 836 | <email><?php the_author_email()?></email> |
921 | 837 | <uri><?php the_author_url()?></uri> |
922 | 838 | </author> |
923 | | <?php if($post->post_type == 'attachment') { ?> |
| 839 | <?php if($post->post_status == 'attachment') { ?> |
924 | 840 | <link rel="edit" href="<?php $this->the_entry_url() ?>" /> |
925 | 841 | <link rel="edit-media" href="<?php $this->the_media_url() ?>" /> |
926 | 842 | <content type="<?php echo $post->post_mime_type ?>" src="<?php the_guid(); ?>"/> |
… |
… |
|
933 | 849 | <summary type="html"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> |
934 | 850 | <?php } |
935 | 851 | if ( strlen( $post->post_content ) ) : ?> |
936 | | <content type="html"><?php echo get_the_content('', 0, '') ?></content> |
| 852 | <content type="html"><![CDATA[<?php echo get_the_content('', 0, '') ?>]]></content> |
937 | 853 | <?php endif; ?> |
938 | 854 | </entry> |
939 | 855 | <?php |
… |
… |
|
945 | 861 | endif; |
946 | 862 | ob_end_clean(); |
947 | 863 | |
948 | | log_app('get_entry returning:',$entry); |
| 864 | log_app("get_entry", $entry); |
949 | 865 | return $entry; |
950 | 866 | } |
951 | 867 | |
952 | 868 | function ok() { |
953 | | log_app('Status','200: OK'); |
954 | 869 | header('Content-Type: text/plain'); |
955 | 870 | status_header('200'); |
956 | 871 | exit; |
957 | 872 | } |
958 | 873 | |
959 | | function no_content() { |
960 | | log_app('Status','204: No Content'); |
961 | | header('Content-Type: text/plain'); |
962 | | status_header('204'); |
963 | | echo "Deleted."; |
964 | | exit; |
965 | | } |
966 | | |
967 | 874 | function internal_error($msg = 'Internal Server Error') { |
968 | | log_app('Status','500: Server Error'); |
969 | 875 | header('Content-Type: text/plain'); |
970 | 876 | status_header('500'); |
971 | 877 | echo $msg; |
… |
… |
|
973 | 879 | } |
974 | 880 | |
975 | 881 | function bad_request() { |
976 | | log_app('Status','400: Bad Request'); |
977 | 882 | header('Content-Type: text/plain'); |
978 | 883 | status_header('400'); |
979 | 884 | exit; |
980 | 885 | } |
981 | 886 | |
982 | 887 | function length_required() { |
983 | | log_app('Status','411: Length Required'); |
984 | 888 | header("HTTP/1.1 411 Length Required"); |
985 | 889 | header('Content-Type: text/plain'); |
986 | 890 | status_header('411'); |
… |
… |
|
988 | 892 | } |
989 | 893 | |
990 | 894 | function invalid_media() { |
991 | | log_app('Status','415: Unsupported Media Type'); |
992 | 895 | header("HTTP/1.1 415 Unsupported Media Type"); |
993 | 896 | header('Content-Type: text/plain'); |
994 | 897 | exit; |
995 | 898 | } |
996 | 899 | |
997 | 900 | function not_found() { |
998 | | log_app('Status','404: Not Found'); |
999 | 901 | header('Content-Type: text/plain'); |
1000 | 902 | status_header('404'); |
1001 | 903 | exit; |
1002 | 904 | } |
1003 | 905 | |
1004 | 906 | function not_allowed($allow) { |
1005 | | log_app('Status','405: Not Allowed'); |
1006 | 907 | header('Allow: ' . join(',', $allow)); |
1007 | 908 | status_header('405'); |
1008 | 909 | exit; |
1009 | 910 | } |
1010 | 911 | |
1011 | 912 | function client_error($msg = 'Client Error') { |
1012 | | log_app('Status','400: Client Errir'); |
1013 | | header('Content-Type: text/plain'); |
1014 | 913 | status_header('400'); |
| 914 | header('Content-Type: text/plain'); |
| 915 | header('Status: ' . $msg); |
| 916 | echo $msg; |
1015 | 917 | exit; |
1016 | 918 | } |
1017 | 919 | |
1018 | 920 | function created($post_ID, $content, $post_type = 'post') { |
1019 | | global $use_querystring; |
1020 | | log_app('created()::$post_ID',"$post_ID, $post_type"); |
| 921 | log_app('created()::$post_ID',"$post_ID"); |
1021 | 922 | $edit = $this->get_entry_url($post_ID); |
1022 | 923 | switch($post_type) { |
1023 | 924 | case 'post': |
1024 | 925 | $ctloc = $this->get_entry_url($post_ID); |
1025 | 926 | break; |
1026 | 927 | case 'attachment': |
1027 | | if ($use_querystring) { |
1028 | | $edit = get_bloginfo('url') . '/' . $this->script_name . "?action=/attachments&eid=$post_ID"; |
1029 | | } else { |
1030 | | $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; |
1031 | | } |
1032 | 928 | break; |
1033 | 929 | } |
1034 | 930 | header('Content-Type: application/atom+xml'); |
… |
… |
|
1041 | 937 | } |
1042 | 938 | |
1043 | 939 | function auth_required($msg) { |
1044 | | log_app('Status','401: Auth Required'); |
1045 | 940 | nocache_headers(); |
1046 | 941 | header('WWW-Authenticate: Basic realm="WordPress Atom Protocol"'); |
1047 | | header('WWW-Authenticate: Form action="' . get_settings('siteurl') . '/wp-login.php"', false); |
1048 | 942 | header("HTTP/1.1 401 $msg"); |
1049 | 943 | header('Status: ' . $msg); |
1050 | | header('Content-Type: plain/text'); |
| 944 | header('Content-Type: text/plain'); |
1051 | 945 | echo $msg; |
1052 | 946 | exit; |
1053 | 947 | } |
… |
… |
|
1062 | 956 | header('Date: '. date('r')); |
1063 | 957 | if($this->do_output) |
1064 | 958 | echo $xml; |
1065 | | log_app('function', "output:\n$xml"); |
1066 | 959 | exit; |
1067 | 960 | } |
1068 | 961 | |
… |
… |
|
1081 | 974 | } |
1082 | 975 | |
1083 | 976 | |
1084 | | |
1085 | 977 | /* |
1086 | 978 | * Access credential through various methods and perform login |
1087 | 979 | */ |
… |
… |
|
1113 | 1005 | if (!empty($login_data) && wp_login($login_data['login'], $login_data['password'], $already_md5)) { |
1114 | 1006 | $current_user = new WP_User(0, $login_data['login']); |
1115 | 1007 | wp_set_current_user($current_user->ID); |
1116 | | log_app("authenticate()",$login_data['login']); |
1117 | 1008 | } |
1118 | 1009 | } |
1119 | 1010 | |