Make WordPress Core

Changeset 8954


Ignore:
Timestamp:
09/22/2008 08:06:48 AM (16 years ago)
Author:
azaozz
Message:

Complete inline documentation for AtomPub, props jacobsantos, fixes #7777

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-app.php

    r8952 r8954  
    4747
    4848/**
    49  * log_app() - Writes logging info to a file.
     49 * Writes logging info to a file.
    5050 *
     51 * @since 2.2.0
    5152 * @uses $app_logging
    5253 * @package WordPress
     
    6869if ( !function_exists('wp_set_current_user') ) :
    6970/**
    70  * Sets the current WordPress User.
    71  *
    72  * Pluggable function which is also found in pluggable.php.
    73  *
    74  * @see wp-includes/pluggable.php Documentation for this function.
    75  * @uses $current_user Global of current user to test whether $id is the same.
    76  *
    77  * @param int $id The user's ID.
    78  * @param string $name Optional. The username of the user.
    79  * @return WP_User Current user's User object
     71 * @ignore
    8072 */
    8173function wp_set_current_user($id, $name = '') {
     
    9486 * Filter to add more post statuses.
    9587 *
    96  * @param string $where SQL statement to filter
    97  * @return string Filtered SQL statement with added post_status for where clause
     88 * @since 2.2.0
     89 *
     90 * @param string $where SQL statement to filter.
     91 * @return string Filtered SQL statement with added post_status for where clause.
    9892 */
    9993function wa_posts_where_include_drafts_filter($where) {
     
    113107class AtomServer {
    114108
     109    /**
     110     * ATOM content type.
     111     *
     112     * @since 2.2.0
     113     * @var string
     114     */
    115115    var $ATOM_CONTENT_TYPE = 'application/atom+xml';
     116
     117    /**
     118     * Categories ATOM content type.
     119     *
     120     * @since 2.2.0
     121     * @var string
     122     */
    116123    var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml';
     124
     125    /**
     126     * Service ATOM content type.
     127     *
     128     * @since 2.3.0
     129     * @var string
     130     */
    117131    var $SERVICE_CONTENT_TYPE = 'application/atomsvc+xml';
    118132
     133    /**
     134     * ATOM XML namespace.
     135     *
     136     * @since 2.3.0
     137     * @var string
     138     */
    119139    var $ATOM_NS = 'http://www.w3.org/2005/Atom';
     140
     141    /**
     142     * ATOMPUB XML namespace.
     143     *
     144     * @since 2.3.0
     145     * @var string
     146     */
    120147    var $ATOMPUB_NS = 'http://www.w3.org/2007/app';
    121148
     149    /**
     150     * Entries path.
     151     *
     152     * @since 2.2.0
     153     * @var string
     154     */
    122155    var $ENTRIES_PATH = "posts";
     156
     157    /**
     158     * Categories path.
     159     *
     160     * @since 2.2.0
     161     * @var string
     162     */
    123163    var $CATEGORIES_PATH = "categories";
     164
     165    /**
     166     * Media path.
     167     *
     168     * @since 2.2.0
     169     * @var string
     170     */
    124171    var $MEDIA_PATH = "attachments";
     172
     173    /**
     174     * Entry path.
     175     *
     176     * @since 2.2.0
     177     * @var string
     178     */
    125179    var $ENTRY_PATH = "post";
     180
     181    /**
     182     * Service path.
     183     *
     184     * @since 2.2.0
     185     * @var string
     186     */
    126187    var $SERVICE_PATH = "service";
     188
     189    /**
     190     * Media single path.
     191     *
     192     * @since 2.2.0
     193     * @var string
     194     */
    127195    var $MEDIA_SINGLE_PATH = "attachment";
    128196
     197    /**
     198     * ATOMPUB parameters.
     199     *
     200     * @since 2.2.0
     201     * @var array
     202     */
    129203    var $params = array();
     204
     205    /**
     206     * Supported ATOMPUB media types.
     207     *
     208     * @since 2.3.0
     209     * @var array
     210     */
    130211    var $media_content_types = array('image/*','audio/*','video/*');
     212
     213    /**
     214     * ATOMPUB content type(s).
     215     *
     216     * @since 2.2.0
     217     * @var array
     218     */
    131219    var $atom_content_types = array('application/atom+xml');
    132220
     221    /**
     222     * ATOMPUB methods.
     223     *
     224     * @since 2.2.0
     225     * @var unknown_type
     226     */
    133227    var $selectors = array();
    134228
    135     // support for head
     229    /**
     230     * Whether to do output.
     231     *
     232     * Support for head.
     233     *
     234     * @since 2.2.0
     235     * @var bool
     236     */
    136237    var $do_output = true;
    137238
     239    /**
     240     * PHP4 constructor - Sets up object properties.
     241     *
     242     * @since 2.2.0
     243     * @return AtomServer
     244     */
    138245    function AtomServer() {
    139246
     
    170277    }
    171278
     279    /**
     280     * Handle ATOMPUB request.
     281     *
     282     * @since 2.2.0
     283     */
    172284    function handle_request() {
    173285        global $always_authenticate;
     
    227339    }
    228340
     341    /**
     342     * Retrieve XML for ATOMPUB service.
     343     *
     344     * @since 2.2.0
     345     */
    229346    function get_service() {
    230347        log_app('function','get_service()');
     
    262379    }
    263380
     381    /**
     382     * Retrieve categories list in XML format.
     383     *
     384     * @since 2.2.0
     385     */
    264386    function get_categories_xml() {
    265387        log_app('function','get_categories_xml()');
     
    285407}
    286408
    287     /*
    288      * Create Post (No arguments)
     409    /**
     410     * Create new post.
     411     *
     412     * @since 2.2.0
    289413     */
    290414    function create_post() {
     
    358482    }
    359483
     484    /**
     485     * Retrieve post.
     486     *
     487     * @since 2.2.0
     488     *
     489     * @param int $postID Post ID.
     490     */
    360491    function get_post($postID) {
    361492        global $entry;
     
    371502    }
    372503
     504    /**
     505     * Update post.
     506     *
     507     * @since 2.2.0
     508     *
     509     * @param int $postID Post ID.
     510     */
    373511    function put_post($postID) {
    374512        // checked for valid content-types (atom+xml)
     
    420558    }
    421559
     560    /**
     561     * Remove post.
     562     *
     563     * @since 2.2.0
     564     *
     565     * @param int $postID Post ID.
     566     */
    422567    function delete_post($postID) {
    423568
     
    445590    }
    446591
    447     function get_attachment($postID = NULL) {
     592    /**
     593     * Retrieve attachment.
     594     *
     595     * @since 2.2.0
     596     *
     597     * @param int $postID Optional. Post ID.
     598     */
     599    function get_attachment($postID = null) {
    448600        if( !current_user_can( 'upload_files' ) )
    449601            $this->auth_required( __( 'Sorry, you do not have permission to upload files.' ) );
     
    459611    }
    460612
     613    /**
     614     * Create new attachment.
     615     *
     616     * @since 2.2.0
     617     */
    461618    function create_attachment() {
    462619
     
    467624
    468625        $fp = fopen("php://input", "rb");
    469         $bits = NULL;
     626        $bits = null;
    470627        while(!feof($fp)) {
    471628            $bits .= fread($fp, 4096);
     
    513670    }
    514671
     672    /**
     673     * Update attachment.
     674     *
     675     * @since 2.2.0
     676     *
     677     * @param int $postID Post ID.
     678     */
    515679    function put_attachment($postID) {
    516680        // checked for valid content-types (atom+xml)
     
    553717    }
    554718
     719    /**
     720     * Remove attachment.
     721     *
     722     * @since 2.2.0
     723     *
     724     * @param int $postID Post ID.
     725     */
    555726    function delete_attachment($postID) {
    556727        log_app('function',"delete_attachment($postID). File '$location' deleted.");
     
    584755    }
    585756
     757    /**
     758     * Retrieve attachment from post.
     759     *
     760     * @since 2.2.0
     761     *
     762     * @param int $postID Post ID.
     763     */
    586764    function get_file($postID) {
    587765
     
    615793    }
    616794
     795    /**
     796     * Upload file to blog and add attachment to post.
     797     *
     798     * @since 2.2.0
     799     *
     800     * @param int $postID Post ID.
     801     */
    617802    function put_file($postID) {
    618803
     
    663848    }
    664849
    665     function get_entries_url($page = NULL) {
     850    /**
     851     * Retrieve entries URL.
     852     *
     853     * @since 2.2.0
     854     *
     855     * @param int $page Page ID.
     856     * @return string
     857     */
     858    function get_entries_url($page = null) {
    666859        if($GLOBALS['post_type'] == 'attachment') {
    667860            $path = $this->MEDIA_PATH;
     
    676869    }
    677870
    678     function the_entries_url($page = NULL) {
     871    /**
     872     * Display entries URL.
     873     *
     874     * @since 2.2.0
     875     *
     876     * @param int $page Page ID.
     877     */
     878    function the_entries_url($page = null) {
    679879        echo $this->get_entries_url($page);
    680880    }
    681881
     882    /**
     883     * Retrieve categories URL.
     884     *
     885     * @since 2.2.0
     886     *
     887     * @param mixed $deprecated Optional, not used.
     888     * @return string
     889     */
    682890    function get_categories_url($deprecated = '') {
    683891        return $this->app_base . $this->CATEGORIES_PATH;
    684892    }
    685893
     894    /**
     895     * Display category URL.
     896     *
     897     * @since 2.2.0
     898     */
    686899    function the_categories_url() {
    687900        echo $this->get_categories_url();
    688901    }
    689902
    690     function get_attachments_url($page = NULL) {
     903    /**
     904     * Retrieve attachment URL.
     905     *
     906     * @since 2.2.0
     907     *
     908     * @param int $page Page ID.
     909     * @return string
     910     */
     911    function get_attachments_url($page = null) {
    691912        $url = $this->app_base . $this->MEDIA_PATH;
    692913        if(isset($page) && is_int($page)) {
     
    696917    }
    697918
    698     function the_attachments_url($page = NULL) {
     919    /**
     920     * Display attachment URL.
     921     *
     922     * @since 2.2.0
     923     *
     924     * @param int $page Page ID.
     925     */
     926    function the_attachments_url($page = null) {
    699927        echo $this->get_attachments_url($page);
    700928    }
    701929
     930    /**
     931     * Retrieve service URL.
     932     *
     933     * @since 2.3.0
     934     *
     935     * @return string
     936     */
    702937    function get_service_url() {
    703938        return $this->app_base . $this->SERVICE_PATH;
    704939    }
    705940
    706     function get_entry_url($postID = NULL) {
     941    /**
     942     * Retrieve entry URL.
     943     *
     944     * @since 2.7.0
     945     *
     946     * @param int $postID Post ID.
     947     * @return string
     948     */
     949    function get_entry_url($postID = null) {
    707950        if(!isset($postID)) {
    708951            global $post;
     
    716959    }
    717960
    718     function the_entry_url($postID = NULL) {
     961    /**
     962     * Display entry URL.
     963     *
     964     * @since 2.7.0
     965     *
     966     * @param int $postID Post ID.
     967     */
     968    function the_entry_url($postID = null) {
    719969        echo $this->get_entry_url($postID);
    720970    }
    721971
    722     function get_media_url($postID = NULL) {
     972    /**
     973     * Retrieve media URL.
     974     *
     975     * @since 2.2.0
     976     *
     977     * @param int $postID Post ID.
     978     * @return string
     979     */
     980    function get_media_url($postID = null) {
    723981        if(!isset($postID)) {
    724982            global $post;
     
    732990    }
    733991
    734     function the_media_url($postID = NULL) {
     992    /**
     993     * Display the media URL.
     994     *
     995     * @since 2.2.0
     996     *
     997     * @param int $postID Post ID.
     998     */
     999    function the_media_url($postID = null) {
    7351000        echo $this->get_media_url($postID);
    7361001    }
    7371002
     1003    /**
     1004     * Set the current entry to post ID.
     1005     *
     1006     * @since 2.2.0
     1007     *
     1008     * @param int $postID Post ID.
     1009     */
    7381010    function set_current_entry($postID) {
    7391011        global $entry;
     
    7531025    }
    7541026
     1027    /**
     1028     * Display posts XML.
     1029     *
     1030     * @since 2.2.0
     1031     *
     1032     * @param int $page Optional. Page ID.
     1033     * @param string $post_type Optional, default is 'post'. Post Type.
     1034     */
    7551035    function get_posts($page = 1, $post_type = 'post') {
    7561036            log_app('function',"get_posts($page, '$post_type')");
     
    7591039    }
    7601040
     1041    /**
     1042     * Display attachment XML.
     1043     *
     1044     * @since 2.2.0
     1045     *
     1046     * @param int $page Page ID.
     1047     * @param string $post_type Optional, default is 'attachment'. Post type.
     1048     */
    7611049    function get_attachments($page = 1, $post_type = 'attachment') {
    762         log_app('function',"get_attachments($page, '$post_type')");
    763         $GLOBALS['post_type'] = $post_type;
    764         $feed = $this->get_feed($page, $post_type);
    765         $this->output($feed);
    766     }
    767 
     1050        log_app('function',"get_attachments($page, '$post_type')");
     1051        $GLOBALS['post_type'] = $post_type;
     1052        $feed = $this->get_feed($page, $post_type);
     1053        $this->output($feed);
     1054    }
     1055
     1056    /**
     1057     * Retrieve feed XML.
     1058     *
     1059     * @since 2.2.0
     1060     *
     1061     * @param int $page Page ID.
     1062     * @param string $post_type Optional, default is post. Post type.
     1063     * @return string
     1064     */
    7681065    function get_feed($page = 1, $post_type = 'post') {
    7691066        global $post, $wp, $wp_query, $posts, $wpdb, $blog_id;
     
    8231120    }
    8241121
     1122    /**
     1123     * Display entry XML.
     1124     *
     1125     * @since 2.2.0
     1126     *
     1127     * @param int $postID Post ID.
     1128     * @param string $post_type Optional, default is post. Post type.
     1129     * @return string.
     1130     */
    8251131    function get_entry($postID, $post_type = 'post') {
    8261132        log_app('function',"get_entry($postID, '$post_type')");
     
    8501156    }
    8511157
     1158    /**
     1159     * Display post content XML.
     1160     *
     1161     * @since 2.3.0
     1162     */
    8521163    function echo_entry() { ?>
    8531164<entry xmlns="<?php echo $this->ATOM_NS ?>"
     
    8871198<?php }
    8881199
     1200    /**
     1201     * Set 'OK' (200) status header.
     1202     *
     1203     * @since 2.2.0
     1204     */
    8891205    function ok() {
    8901206        log_app('Status','200: OK');
     
    8941210    }
    8951211
     1212    /**
     1213     * Set 'No Content' (204) status header.
     1214     *
     1215     * @since 2.2.0
     1216     */
    8961217    function no_content() {
    8971218        log_app('Status','204: No Content');
     
    9021223    }
    9031224
     1225    /**
     1226     * Display 'Internal Server Error' (500) status header.
     1227     *
     1228     * @since 2.2.0
     1229     *
     1230     * @param string $msg Optional. Status string.
     1231     */
    9041232    function internal_error($msg = 'Internal Server Error') {
    9051233        log_app('Status','500: Server Error');
     
    9101238    }
    9111239
     1240    /**
     1241     * Set 'Bad Request' (400) status header.
     1242     *
     1243     * @since 2.2.0
     1244     */
    9121245    function bad_request() {
    9131246        log_app('Status','400: Bad Request');
     
    9171250    }
    9181251
     1252    /**
     1253     * Set 'Length Required' (411) status header.
     1254     *
     1255     * @since 2.2.0
     1256     */
    9191257    function length_required() {
    9201258        log_app('Status','411: Length Required');
     
    9251263    }
    9261264
     1265    /**
     1266     * Set 'Unsupported Media Type' (415) status header.
     1267     *
     1268     * @since 2.2.0
     1269     */
    9271270    function invalid_media() {
    9281271        log_app('Status','415: Unsupported Media Type');
     
    9321275    }
    9331276
     1277    /**
     1278     * Set 'Forbidden' (403) status header.
     1279     *
     1280     * @since 2.6.0
     1281     */
    9341282    function forbidden($reason='') {
    9351283        log_app('Status','403: Forbidden');
     
    9401288    }
    9411289
     1290    /**
     1291     * Set 'Not Found' (404) status header.
     1292     *
     1293     * @since 2.2.0
     1294     */
    9421295    function not_found() {
    9431296        log_app('Status','404: Not Found');
     
    9471300    }
    9481301
     1302    /**
     1303     * Set 'Not Allowed' (405) status header.
     1304     *
     1305     * @since 2.2.0
     1306     */
    9491307    function not_allowed($allow) {
    9501308        log_app('Status','405: Not Allowed');
     
    9541312    }
    9551313
     1314    /**
     1315     * Display Redirect (302) content and set status headers.
     1316     *
     1317     * @since 2.3.0
     1318     */
    9561319    function redirect($url) {
    9571320
     
    9791342    }
    9801343
    981 
     1344    /**
     1345     * Set 'Client Error' (400) status header.
     1346     *
     1347     * @since 2.2.0
     1348     */
    9821349    function client_error($msg = 'Client Error') {
    9831350        log_app('Status','400: Client Error');
     
    9871354    }
    9881355
     1356    /**
     1357     * Set created status headers (201).
     1358     *
     1359     * Sets the 'content-type', 'content-location', and 'location'.
     1360     *
     1361     * @since 2.2.0
     1362     */
    9891363    function created($post_ID, $content, $post_type = 'post') {
    9901364        log_app('created()::$post_ID',"$post_ID, $post_type");
     
    10071381    }
    10081382
     1383    /**
     1384     * Set 'Auth Required' (401) headers.
     1385     *
     1386     * @since 2.2.0
     1387     *
     1388     * @param string $msg Status header content and HTML content.
     1389     */
    10091390    function auth_required($msg) {
    10101391        log_app('Status','401: Auth Required');
     
    10311412    }
    10321413
     1414    /**
     1415     * Display XML and set headers with content type.
     1416     *
     1417     * @since 2.2.0
     1418     *
     1419     * @param string $xml Display feed content.
     1420     * @param string $ctype Optional, default is 'atom+xml'. Feed content type.
     1421     */
    10331422    function output($xml, $ctype = 'application/atom+xml') {
    10341423            status_header('200');
     
    10451434    }
    10461435
     1436    /**
     1437     * Sanitize content for database usage.
     1438     *
     1439     * @since 2.2.0
     1440     *
     1441     * @param array $array Sanitize array and multi-dimension array.
     1442     */
    10471443    function escape(&$array) {
    10481444        global $wpdb;
     
    10591455    }
    10601456
    1061     /*
    1062      * Access credential through various methods and perform login
     1457    /**
     1458     * Access credential through various methods and perform login.
     1459     *
     1460     * @since 2.2.0
     1461     *
     1462     * @return bool
    10631463     */
    10641464    function authenticate() {
     
    10861486    }
    10871487
    1088     function get_accepted_content_type($types = NULL) {
     1488    /**
     1489     * Retrieve accepted content types.
     1490     *
     1491     * @since 2.2.0
     1492     *
     1493     * @param array $types Optional. Content Types.
     1494     * @return string
     1495     */
     1496    function get_accepted_content_type($types = null) {
    10891497
    10901498        if(!isset($types)) {
     
    11121520    }
    11131521
     1522    /**
     1523     * Process conditionals for posts.
     1524     *
     1525     * @since 2.2.0
     1526     */
    11141527    function process_conditionals() {
    11151528
     
    11551568    }
    11561569
     1570    /**
     1571     * Convert RFC3339 time string to timestamp.
     1572     *
     1573     * @since 2.3.0
     1574     *
     1575     * @param string $str String to time.
     1576     * @return bool|int false if format is incorrect.
     1577     */
    11571578    function rfc3339_str2time($str) {
    11581579
    1159         $match = false;
    1160         if(!preg_match("/(\d{4}-\d{2}-\d{2})T(\d{2}\:\d{2}\:\d{2})\.?\d{0,3}(Z|[+-]+\d{2}\:\d{2})/", $str, $match))
     1580        $match = false;
     1581        if(!preg_match("/(\d{4}-\d{2}-\d{2})T(\d{2}\:\d{2}\:\d{2})\.?\d{0,3}(Z|[+-]+\d{2}\:\d{2})/", $str, $match))
    11611582            return false;
    11621583
    1163         if($match[3] == 'Z')
     1584        if($match[3] == 'Z')
    11641585            $match[3] == '+0000';
    11651586
    1166         return strtotime($match[1] . " " . $match[2] . " " . $match[3]);
    1167     }
    1168 
     1587        return strtotime($match[1] . " " . $match[2] . " " . $match[3]);
     1588    }
     1589
     1590    /**
     1591     * Retrieve published time to display in XML.
     1592     *
     1593     * @since 2.3.0
     1594     *
     1595     * @param string $published Time string.
     1596     * @return string
     1597     */
    11691598    function get_publish_time($published) {
    11701599
    1171         $pubtime = $this->rfc3339_str2time($published);
    1172 
    1173         if(!$pubtime) {
     1600        $pubtime = $this->rfc3339_str2time($published);
     1601
     1602        if(!$pubtime) {
    11741603            return array(current_time('mysql'),current_time('mysql',1));
    1175         } else {
     1604        } else {
    11761605            return array(date("Y-m-d H:i:s", $pubtime), gmdate("Y-m-d H:i:s", $pubtime));
    1177         }
     1606        }
    11781607    }
    11791608
    11801609}
    11811610
     1611/**
     1612 * AtomServer
     1613 * @var AtomServer
     1614 * @global object $server
     1615 */
    11821616$server = new AtomServer();
    11831617$server->handle_request();
Note: See TracChangeset for help on using the changeset viewer.