Make WordPress Core


Ignore:
Timestamp:
03/01/2012 09:15:44 PM (14 years ago)
Author:
ryan
Message:

wp-app.php cleanup:

  • Put the atom server class in class-wp-atom-server.php
  • Remove log_api calls
  • Update the query filter
  • Replace exit calls with wp_die() for unit test compat
  • Add override handler for wp_die()
  • Allow plugins to replace the atom class
  • Whitespace cleanup

Props kurtpayne. fixes #20042

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-atom-server.php

    r20059 r20062  
    11<?php
    2 /**
    3  * Atom Publishing Protocol support for WordPress
    4  *
    5  * @version 1.0.5-dc
    6  */
    7 
    8 /**
    9  * WordPress is handling an Atom Publishing Protocol request.
    10  *
    11  * @var bool
    12  */
    13 define('APP_REQUEST', true);
    14 
    15 /** Set up WordPress environment */
    16 require_once('./wp-load.php');
    17 
    18 /** Atom Publishing Protocol Class */
    19 require_once(ABSPATH . WPINC . '/atomlib.php');
    20 
    21 /** Admin Image API for metadata updating */
    22 require_once(ABSPATH . '/wp-admin/includes/image.php');
    23 
    24 $_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
    25 
    26 /**
    27  * Whether to always authenticate user. Permanently set to true.
    28  *
    29  * @name always_authenticate
    30  * @var int|bool
    31  * @todo Should be an option somewhere
    32  */
    33 $always_authenticate = 1;
    34 
    35 /**
    36  * Writes logging info to a file.
    37  *
    38  * @since 2.2.0
    39  * @deprecated 3.4.0
    40  * @deprecated Use error_log()
    41  * @link http://www.php.net/manual/en/function.error-log.php
    42  *
    43  * @param string $label Type of logging
    44  * @param string $msg Information describing logging reason.
    45  */
    46 function log_app( $label, $msg ) {
    47     _deprecated_function( __FUNCTION__, '3.4', 'error_log()' );
    48     if ( ! empty( $GLOBALS['app_logging'] ) )
    49         error_log( $label . ' - ' . $message );
    50 }
    51 
    52 /**
    53  * Filter to add more post statuses.
    54  *
    55  * @since 2.2.0
    56  *
    57  * @param string $where SQL statement to filter.
    58  * @return string Filtered SQL statement with added post_status for where clause.
    59  */
    60 function wa_posts_where_include_drafts_filter($where) {
    61     $where = str_replace("post_status = 'publish'","post_status = 'publish' OR post_status = 'future' OR post_status = 'draft' OR post_status = 'inherit'", $where);
    62     return $where;
    63 
    64 }
    65 add_filter('posts_where', 'wa_posts_where_include_drafts_filter');
    662
    673/**
     
    728 * @since 2.2.0
    739 */
    74 class AtomServer {
     10class wp_atom_server {
    7511
    7612    /**
     
    240176                        'DELETE' => 'delete_attachment'),
    241177        );
     178
     179        add_filter( 'wp_die_handler', array( $this, 'return_atom_die_handler' ) );
     180    }
     181
     182    /**
     183     * Override die handler
     184     * @return callback
     185     */
     186    public function return_atom_die_handler() {
     187        return array( $this, 'atom_die_handler' );
     188    }
     189
     190    /**
     191     * Die with a message.  Only accept strings, no WP_Error objects yet
     192     * @param string $message
     193     * @return void
     194     */
     195    public function atom_die_handler( $message ) {
     196        if ( is_scalar( $message ) )
     197            die( (string) $message );
     198        die();
    242199    }
    243200
     
    248205     */
    249206    function handle_request() {
    250         global $always_authenticate;
    251207
    252208        if ( !empty( $_SERVER['ORIG_PATH_INFO'] ) )
     
    282238                    // user. each handler will decide if auth is required or not.
    283239                    if ( !$this->authenticate() ) {
    284                         if ( $always_authenticate )
    285                             $this->auth_required('Credentials required.');
     240                        $this->auth_required('Credentials required.');
    286241                    }
    287242
    288243                    array_shift($matches);
    289                     call_user_func_array(array(&$this,$funcs[$method]), $matches);
    290                     exit();
     244                    call_user_func_array(array($this,$funcs[$method]), $matches);
     245                    wp_die();
    291246                } else {
    292247                    // only allow what we have handlers for...
     
    306261     */
    307262    function get_service() {
     263
    308264        if ( !current_user_can( 'edit_posts' ) )
    309265            $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) );
     
    345301     */
    346302    function get_categories_xml() {
     303
    347304        if ( !current_user_can( 'edit_posts' ) )
    348305            $this->auth_required( __( 'Sorry, you do not have the right to access this site.' ) );
     
    411368        $post_excerpt = '';
    412369        $pubtimes     = '';
    413 
     370       
    414371        if ( isset( $entry->title ) && is_array( $entry->title ) && !empty( $entry->title[1] ) )
    415372            $post_title = (string) $entry->title[1];
     
    420377        if ( !empty( $entry->published ) )
    421378            $pubtimes = (string) $entry->published;
    422 
     379       
    423380        $pubtimes = $this->get_publish_time( $pubtimes );
    424381
     
    684641     */
    685642    function delete_attachment($postID) {
     643
    686644        // check for not found
    687645        global $entry;
     
    751709        }
    752710
    753         exit;
     711        wp_die();
    754712    }
    755713
     
    994952     */
    995953    function get_posts($page = 1, $post_type = 'post') {
    996             $feed = $this->get_feed($page, $post_type);
    997             $this->output($feed);
     954        $feed = $this->get_feed($page, $post_type);
     955        $this->output($feed);
    998956    }
    999957
     
    1034992        $count = get_option('posts_per_rss');
    1035993
    1036         wp('posts_per_page=' . $count . '&offset=' . ($count * ($page-1) . '&orderby=modified'));
     994        wp('posts_per_page=' . $count . '&offset=' . ($count * ($page-1)) . '&orderby=modified&post_status=any');
    1037995
    1038996        $post = $GLOBALS['post'];
     
    11601118        header('Content-Type: text/plain');
    11611119        status_header('200');
    1162         exit;
     1120        wp_die();
    11631121    }
    11641122
     
    11721130        status_header('204');
    11731131        echo "Moved to Trash.";
    1174         exit;
     1132        wp_die();
    11751133    }
    11761134
     
    11861144        status_header('500');
    11871145        echo $msg;
    1188         exit;
     1146        wp_die();
    11891147    }
    11901148
     
    11971155        header('Content-Type: text/plain');
    11981156        status_header('400');
    1199         exit;
     1157        wp_die();
    12001158    }
    12011159
     
    12091167        header('Content-Type: text/plain');
    12101168        status_header('411');
    1211         exit;
     1169        wp_die();
    12121170    }
    12131171
     
    12201178        header("HTTP/1.1 415 Unsupported Media Type");
    12211179        header('Content-Type: text/plain');
    1222         exit;
     1180        wp_die();
    12231181    }
    12241182
     
    12321190        status_header('403');
    12331191        echo $reason;
    1234         exit;
     1192        wp_die();
    12351193    }
    12361194
     
    12431201        header('Content-Type: text/plain');
    12441202        status_header('404');
    1245         exit;
     1203        wp_die();
    12461204    }
    12471205
     
    12541212        header('Allow: ' . join(',', $allow));
    12551213        status_header('405');
    1256         exit;
     1214        wp_die();
    12571215    }
    12581216
     
    12811239        header('Location: ' . $url);
    12821240        echo $content;
    1283         exit;
     1241        wp_die();
    12841242
    12851243    }
     
    12931251        header('Content-Type: text/plain');
    12941252        status_header('400');
    1295         exit;
     1253        wp_die();
    12961254    }
    12971255
     
    13191277        status_header('201');
    13201278        echo $content;
    1321         exit;
     1279        wp_die();
    13221280    }
    13231281
     
    13491307EOD;
    13501308        echo $content;
    1351         exit;
     1309        wp_die();
    13521310    }
    13531311
     
    13611319     */
    13621320    function output($xml, $ctype = 'application/atom+xml') {
    1363             status_header('200');
    1364             $xml = '<?xml version="1.0" encoding="' . strtolower(get_option('blog_charset')) . '"?>'."\n".$xml;
    1365             header('Connection: close');
    1366             header('Content-Length: '. strlen($xml));
    1367             header('Content-Type: ' . $ctype);
    1368             header('Content-Disposition: attachment; filename=atom.xml');
    1369             header('Date: '. date('r'));
    1370             if ($this->do_output)
    1371                 echo $xml;
    1372             exit;
     1321        status_header('200');
     1322        $xml = '<?xml version="1.0" encoding="' . strtolower(get_option('blog_charset')) . '"?>'."\n".$xml;
     1323        header('Connection: close');
     1324        header('Content-Length: '. strlen($xml));
     1325        header('Content-Type: ' . $ctype);
     1326        header('Content-Disposition: attachment; filename=atom.xml');
     1327        header('Date: '. date('r'));
     1328        if ($this->do_output)
     1329            echo $xml;
     1330        wp_die();
    13731331    }
    13741332
     
    14021360     */
    14031361    function authenticate() {
     1362
    14041363        // if using mod_rewrite/ENV hack
    14051364        // http://www.besthostratings.com/articles/http-auth-php-cgi.html
     
    14161375        // If Basic Auth is working...
    14171376        if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
     1377
    14181378            $user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
    14191379            if ( $user && !is_wp_error($user) ) {
     
    15031463        (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
    15041464            status_header( 304 );
    1505             exit;
     1465            wp_die();
    15061466        }
    15071467    }
     
    15471507
    15481508}
    1549 
    1550 /**
    1551  * AtomServer
    1552  * @var AtomServer
    1553  * @global object $server
    1554  */
    1555 $server = new AtomServer();
    1556 $server->handle_request();
Note: See TracChangeset for help on using the changeset viewer.