Ticket #986: 986-root.diff

File 986-root.diff, 69.2 KB (added by Nazgul, 6 years ago)
  • index.php

     
    1 <?php  
     1<?php 
    22/* Short and sweet */ 
    33define('WP_USE_THEMES', true); 
    44require('./wp-blog-header.php'); 
  • wp-atom.php

     
    1111?> 
    1212<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?> 
    1313<feed version="0.3" 
    14   xmlns="http://purl.org/atom/ns#" 
    15   xmlns:dc="http://purl.org/dc/elements/1.1/" 
    16   xml:lang="<?php echo get_option('rss_language'); ?>" 
    17   <?php do_action('atom_ns'); ?> 
    18   > 
     14        xmlns="http://purl.org/atom/ns#" 
     15        xmlns:dc="http://purl.org/dc/elements/1.1/" 
     16        xml:lang="<?php echo get_option('rss_language'); ?>" 
     17        <?php do_action('atom_ns'); ?> 
     18> 
    1919        <title><?php bloginfo_rss('name') ?></title> 
    2020        <link rel="alternate" type="text/html" href="<?php bloginfo_rss('home') ?>" /> 
    2121        <tagline><?php bloginfo_rss("description") ?></tagline> 
     
    2525        <?php do_action('atom_head'); ?> 
    2626        <?php $items_count = 0; if ($posts) { foreach ($posts as $post) { start_wp(); ?> 
    2727        <entry> 
    28                 <author> 
     28                <author> 
    2929                        <name><?php the_author() ?></name> 
    3030                </author> 
    3131                <title type="text/html" mode="escaped"><![CDATA[<?php the_title_rss() ?>]]></title> 
     
    3333                <id><?php the_guid(); ?></id> 
    3434                <modified><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></modified> 
    3535                <issued><?php echo get_post_time('Y-m-d\TH:i:s\Z', true); ?></issued> 
    36                 <?php the_category_rss('rdf') ?>  
     36                <?php the_category_rss('rdf') ?> 
    3737                <summary type="text/plain" mode="escaped"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary> 
    3838<?php if ( !get_settings('rss_use_excerpt') ) : ?> 
    3939                <content type="<?php bloginfo('html_type'); ?>" mode="escaped" xml:base="<?php permalink_single_rss() ?>"><![CDATA[<?php the_content('', 0, '') ?>]]></content> 
  • wp-blog-header.php

     
    44if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) { 
    55        if ( strstr( $_SERVER['PHP_SELF'], 'wp-admin') ) $path = ''; 
    66        else $path = 'wp-admin/'; 
    7     die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file."); 
     7        die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file."); 
    88} 
    99 
    1010$wp_did_header = true; 
  • wp-comments-post.php

     
    5757        setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); 
    5858endif; 
    5959 
    60 $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];  
     60$location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to']; 
    6161 
    6262wp_redirect( $location ); 
    6363 
  • wp-commentsrss2.php

     
    1 <?php  
     1<?php 
    22 
    33if (empty($wp)) { 
    44        require_once('wp-config.php'); 
     
    77 
    88header('Content-type: text/xml;charset=' . get_settings('blog_charset'), true); 
    99 
    10 echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>';  
     10echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; 
    1111?> 
    1212<!-- generator="wordpress/<?php echo $wp_version ?>" --> 
    13 <rss version="2.0"  
     13<rss version="2.0" 
    1414        xmlns:content="http://purl.org/rss/1.0/modules/content/"> 
    1515<channel> 
    1616<?php 
    1717$i = 0; 
    1818if (have_posts()) : 
    19   while (have_posts()) : the_post(); 
     19        while (have_posts()) : the_post(); 
    2020        if ($i < 1) { 
    2121                $i++; 
    2222?> 
     
    2626        <pubDate><?php echo gmdate('r'); ?></pubDate> 
    2727        <generator>http://wordpress.org/?v=<?php echo $wp_version ?></generator> 
    2828 
    29 <?php  
     29<?php 
    3030                if (is_single() || is_page()) { 
    31                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,  
    32                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,  
    33                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments  
    34                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "'  
    35                         AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish'  
    36                         AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "'  
     31                        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email, 
     32                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, 
     33                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments 
     34                        LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '" . get_the_ID() . "' 
     35                        AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status = 'publish' 
     36                        AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "' 
    3737                        ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') ); 
    3838                } else { // if no post id passed in, we'll just ue the last 10 comments. 
    39                         $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,  
    40                         comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,  
    41                         $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments  
    42                         LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish'  
    43                         AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "'   
     39                        $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email, 
     40                        comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, 
     41                        $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments 
     42                        LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status = 'publish' 
     43                        AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "' 
    4444                        ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') ); 
    4545                } 
    4646        // this line is WordPress' motor, do not delete it. 
     
    6363                <link><?php comment_link() ?></link> 
    6464                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate> 
    6565                <guid><?php comment_link() ?></guid> 
    66                         <?php  
     66                        <?php 
    6767                        if (!empty($comment->post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { 
    6868                        ?> 
    6969                <description><?php _e('Protected Comments: Please enter your password to view comments.'); ?></description> 
     
    7373                        ?> 
    7474                <description><?php comment_text_rss() ?></description> 
    7575                <content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded> 
    76                         <?php  
    77                         } // close check for password  
     76                        <?php 
     77                        } // close check for password 
    7878                        ?> 
    7979        </item> 
    80 <?php  
    81                         }  
     80<?php 
     81                        } 
    8282                } 
    8383        } 
    8484endwhile; endif; 
  • wp-feed.php

     
    11<?php 
    22 
    33if (empty($doing_rss)) { 
    4     $doing_rss = 1; 
    5     require(dirname(__FILE__) . '/wp-blog-header.php'); 
     4        $doing_rss = 1; 
     5        require(dirname(__FILE__) . '/wp-blog-header.php'); 
    66} 
    77 
    88do_feed(); 
  • wp-links-opml.php

     
    1616?><?php echo '<?xml version="1.0"?'.">\n"; ?> 
    1717<!-- generator="wordpress/<?php bloginfo_rss('version') ?>" --> 
    1818<opml version="1.0"> 
    19     <head> 
    20         <title>Links for <?php echo get_bloginfo('name').$cat_name ?></title> 
    21         <dateCreated><?php echo gmdate("D, d M Y H:i:s"); ?> GMT</dateCreated> 
    22     </head> 
    23     <body> 
     19        <head> 
     20                <title>Links for <?php echo get_bloginfo('name').$cat_name ?></title> 
     21                <dateCreated><?php echo gmdate("D, d M Y H:i:s"); ?> GMT</dateCreated> 
     22        </head> 
     23        <body> 
    2424<?php 
    2525 
    2626if (empty ($link_cat)) 
     
    3636        $bookmarks = get_bookmarks("category={$cat->cat_ID}"); 
    3737        foreach ((array) $bookmarks as $bookmark) { 
    3838?> 
    39             <outline text="<?php echo wp_specialchars($bookmark->link_name); ?>" type="link" xmlUrl="<?php echo wp_specialchars($bookmark->link_rss); ?>" htmlUrl="<?php echo wp_specialchars($bookmark->link_url); ?>" updated="<?php if ('0000-00-00 00:00:00' != $bookmark->link_updated) echo $bookmark->link_updated; ?>" /> 
     39        <outline text="<?php echo wp_specialchars($bookmark->link_name); ?>" type="link" xmlUrl="<?php echo wp_specialchars($bookmark->link_rss); ?>" htmlUrl="<?php echo wp_specialchars($bookmark->link_url); ?>" updated="<?php if ('0000-00-00 00:00:00' != $bookmark->link_updated) echo $bookmark->link_updated; ?>" /> 
    4040<?php 
    4141 
    4242        } 
  • wp-login.php

     
    106106        // Generate something random for a password... md5'ing current time with a rand salt 
    107107        $key = substr( md5( uniqid( microtime() ) ), 0, 8); 
    108108        // now insert the new pass md5'd into the db 
    109         $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); 
     109        $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); 
    110110        $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; 
    111111        $message .= get_option('siteurl') . "\r\n\r\n"; 
    112112        $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 
     
    116116        $m = wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_settings('blogname')), $message); 
    117117 
    118118        if ($m == false) { 
    119                  echo '<p>' . __('The e-mail could not be sent.') . "<br />\n"; 
    120          echo  __('Possible reason: your host may have disabled the mail() function...') . "</p>"; 
     119                echo '<p>' . __('The e-mail could not be sent.') . "<br />\n"; 
     120                echo  __('Possible reason: your host may have disabled the mail() function...') . "</p>"; 
    121121                die(); 
    122122        } else { 
    123123                echo '<p>' .  sprintf(__("The e-mail was sent successfully to %s's e-mail address."), $user_login) . '<br />'; 
     
    140140        do_action('password_reset'); 
    141141 
    142142        $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 
    143         $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 
     143        $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 
    144144        wp_cache_delete($user->ID, 'users'); 
    145145        wp_cache_delete($user->user_login, 'userlogins'); 
    146146        $message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n"; 
     
    155155                die(); 
    156156        } else { 
    157157                echo '<p>' .  sprintf(__('Your new password is in the mail.'), $user_login) . '<br />'; 
    158         echo  "<a href='wp-login.php' title='" . __('Check your e-mail first, of course') . "'>" . __('Click here to login!') . '</a></p>'; 
     158                echo  "<a href='wp-login.php' title='" . __('Check your e-mail first, of course') . "'>" . __('Click here to login!') . '</a></p>'; 
    159159                // send a copy of password change notification to the admin 
    160160                $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n"; 
    161161                wp_mail(get_settings('admin_email'), sprintf(__('[%s] Password Lost/Change'), get_settings('blogname')), $message); 
     
    163163        } 
    164164break; 
    165165 
    166 case 'login' :  
     166case 'login' : 
    167167default: 
    168168 
    169169        $user_login = ''; 
     
    237237<p><label><?php _e('Username:') ?><br /><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1); ?>" size="20" tabindex="1" /></label></p> 
    238238<p><label><?php _e('Password:') ?><br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label></p> 
    239239<p> 
    240   <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />  
    241   <?php _e('Remember me'); ?></label></p> 
     240        <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" /> 
     241        <?php _e('Remember me'); ?></label></p> 
    242242<p class="submit"> 
    243243        <input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> &raquo;" tabindex="4" /> 
    244244        <input type="hidden" name="redirect_to" value="<?php echo wp_specialchars($redirect_to); ?>" /> 
  • wp-register.php

     
    6666</head> 
    6767<body> 
    6868 
    69 <div id="login">  
     69<div id="login"> 
    7070        <h2><?php _e('Registration Complete') ?></h2> 
    7171        <p><?php printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>") ?><br /> 
    7272        <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>') ?> <br /> 
  • wp-rss2.php

     
    1212<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?> 
    1313 
    1414<!-- generator="wordpress/<?php bloginfo_rss('version') ?>" --> 
    15 <rss version="2.0"  
     15<rss version="2.0" 
    1616        xmlns:content="http://purl.org/rss/1.0/modules/content/" 
    1717        xmlns:wfw="http://wellformedweb.org/CommentAPI/" 
    1818        xmlns:dc="http://purl.org/dc/elements/1.1/" 
  • wp-settings.php

     
    1111        $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix'); 
    1212 
    1313        $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array()); 
    14         foreach ( $input as $k => $v )  
     14        foreach ( $input as $k => $v ) 
    1515                if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) 
    1616                        unset($GLOBALS[$k]); 
    1717} 
    1818 
    19 unregister_GLOBALS();  
     19unregister_GLOBALS(); 
    2020 
    2121unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories ); 
    2222 
     
    140140require (ABSPATH . WPINC . '/script-loader.php'); 
    141141 
    142142if (!strstr($_SERVER['PHP_SELF'], 'install.php')) : 
    143     // Used to guarantee unique hash cookies 
    144     $cookiehash = md5(get_settings('siteurl')); // Remove in 1.4 
    145         define('COOKIEHASH', $cookiehash);  
     143        // Used to guarantee unique hash cookies 
     144        $cookiehash = md5(get_settings('siteurl')); // Remove in 1.4 
     145        define('COOKIEHASH', $cookiehash); 
    146146endif; 
    147147 
    148148if ( !defined('USER_COOKIE') ) 
  • wp-trackback.php

     
    4747        $blog_name = mb_convert_encoding($blog_name, get_settings('blog_charset'), $charset); 
    4848} 
    4949 
    50 if ( is_single() || is_page() )  
    51     $tb_id = $posts[0]->ID; 
     50if ( is_single() || is_page() ) 
     51        $tb_id = $posts[0]->ID; 
    5252 
    5353if ( !intval( $tb_id ) ) 
    5454        trackback_response(1, 'I really need an ID for this to work.'); 
  • xmlrpc.php

     
    1111 
    1212include('./wp-config.php'); 
    1313 
    14 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd  
     14if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd 
    1515header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true); 
    1616 
    1717?> 
    1818<?php echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?'.'>'; ?> 
    1919<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> 
    20   <service> 
    21     <engineName>WordPress</engineName> 
    22     <engineLink>http://wordpress.org/</engineLink> 
    23     <homePageLink><?php bloginfo_rss('url') ?></homePageLink> 
    24     <apis> 
    25       <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
    26       <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
    27       <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
    28     </apis> 
    29   </service> 
     20        <service> 
     21                <engineName>WordPress</engineName> 
     22                <engineLink>http://wordpress.org/</engineLink> 
     23                <homePageLink><?php bloginfo_rss('url') ?></homePageLink> 
     24                <apis> 
     25                        <api name="Movable Type" blogID="1" preferred="true" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
     26                        <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
     27                        <api name="Blogger" blogID="1" preferred="false" apiLink="<?php bloginfo_rss('url') ?>/xmlrpc.php" /> 
     28                </apis> 
     29        </service> 
    3030</rsd> 
    3131<?php 
    3232exit; 
     
    6262 
    6363 
    6464function mkdir_p($target) { 
    65         // from php.net/mkdir user contributed notes  
     65        // from php.net/mkdir user contributed notes 
    6666        if (file_exists($target)) { 
    67           if (!is_dir($target)) { 
    68             return false; 
    69           } else { 
    70             return true; 
    71           } 
     67                if (!is_dir($target)) { 
     68                        return false; 
     69                } else { 
     70                        return true; 
     71                } 
    7272        } 
    7373 
    7474        // Attempting to create the directory may clutter up our display. 
    7575        if (@mkdir($target)) { 
    76           return true; 
     76                return true; 
    7777        } 
    7878 
    7979        // If the above failed, attempt to create the parent node, then try again. 
    8080        if (mkdir_p(dirname($target))) { 
    81           return mkdir_p($target); 
     81                return mkdir_p($target); 
    8282        } 
    8383 
    8484        return false; 
     
    8989 
    9090        function wp_xmlrpc_server() { 
    9191                $this->methods = array( 
    92                   // Blogger API 
    93                   'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', 
    94                   'blogger.getUserInfo' => 'this:blogger_getUserInfo', 
    95                   'blogger.getPost' => 'this:blogger_getPost', 
    96                   'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', 
    97                   'blogger.getTemplate' => 'this:blogger_getTemplate', 
    98                   'blogger.setTemplate' => 'this:blogger_setTemplate', 
    99                   'blogger.newPost' => 'this:blogger_newPost', 
    100                   'blogger.editPost' => 'this:blogger_editPost', 
    101                   'blogger.deletePost' => 'this:blogger_deletePost', 
     92                        // Blogger API 
     93                        'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs', 
     94                        'blogger.getUserInfo' => 'this:blogger_getUserInfo', 
     95                        'blogger.getPost' => 'this:blogger_getPost', 
     96                        'blogger.getRecentPosts' => 'this:blogger_getRecentPosts', 
     97                        'blogger.getTemplate' => 'this:blogger_getTemplate', 
     98                        'blogger.setTemplate' => 'this:blogger_setTemplate', 
     99                        'blogger.newPost' => 'this:blogger_newPost', 
     100                        'blogger.editPost' => 'this:blogger_editPost', 
     101                        'blogger.deletePost' => 'this:blogger_deletePost', 
    102102 
    103                   // MetaWeblog API (with MT extensions to structs) 
    104                   'metaWeblog.newPost' => 'this:mw_newPost', 
    105                   'metaWeblog.editPost' => 'this:mw_editPost', 
    106                   'metaWeblog.getPost' => 'this:mw_getPost', 
    107                   'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', 
    108                   'metaWeblog.getCategories' => 'this:mw_getCategories', 
    109                   'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', 
     103                        // MetaWeblog API (with MT extensions to structs) 
     104                        'metaWeblog.newPost' => 'this:mw_newPost', 
     105                        'metaWeblog.editPost' => 'this:mw_editPost', 
     106                        'metaWeblog.getPost' => 'this:mw_getPost', 
     107                        'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts', 
     108                        'metaWeblog.getCategories' => 'this:mw_getCategories', 
     109                        'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', 
    110110 
    111                   // MetaWeblog API aliases for Blogger API 
    112                   // see http://www.xmlrpc.com/stories/storyReader$2460 
    113                   'metaWeblog.deletePost' => 'this:blogger_deletePost', 
    114                   'metaWeblog.getTemplate' => 'this:blogger_getTemplate', 
    115                   'metaWeblog.setTemplate' => 'this:blogger_setTemplate', 
    116                   'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', 
     111                        // MetaWeblog API aliases for Blogger API 
     112                        // see http://www.xmlrpc.com/stories/storyReader$2460 
     113                        'metaWeblog.deletePost' => 'this:blogger_deletePost', 
     114                        'metaWeblog.getTemplate' => 'this:blogger_getTemplate', 
     115                        'metaWeblog.setTemplate' => 'this:blogger_setTemplate', 
     116                        'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', 
    117117 
    118                   // MovableType API 
    119                   'mt.getCategoryList' => 'this:mt_getCategoryList', 
    120                   'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', 
    121                   'mt.getPostCategories' => 'this:mt_getPostCategories', 
    122                   'mt.setPostCategories' => 'this:mt_setPostCategories', 
    123                   'mt.supportedMethods' => 'this:mt_supportedMethods', 
    124                   'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', 
    125                   'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', 
    126                   'mt.publishPost' => 'this:mt_publishPost', 
     118                        // MovableType API 
     119                        'mt.getCategoryList' => 'this:mt_getCategoryList', 
     120                        'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles', 
     121                        'mt.getPostCategories' => 'this:mt_getPostCategories', 
     122                        'mt.setPostCategories' => 'this:mt_setPostCategories', 
     123                        'mt.supportedMethods' => 'this:mt_supportedMethods', 
     124                        'mt.supportedTextFilters' => 'this:mt_supportedTextFilters', 
     125                        'mt.getTrackbackPings' => 'this:mt_getTrackbackPings', 
     126                        'mt.publishPost' => 'this:mt_publishPost', 
    127127 
    128                   // PingBack 
    129                   'pingback.ping' => 'this:pingback_ping', 
    130                   'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', 
     128                        // PingBack 
     129                        'pingback.ping' => 'this:pingback_ping', 
     130                        'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks', 
    131131 
    132                   'demo.sayHello' => 'this:sayHello', 
    133                   'demo.addTwoNumbers' => 'this:addTwoNumbers' 
     132                        'demo.sayHello' => 'this:sayHello', 
     133                        'demo.addTwoNumbers' => 'this:addTwoNumbers' 
    134134                ); 
    135135                $this->methods = apply_filters('xmlrpc_methods', $this->methods); 
    136136                $this->IXR_Server($this->methods); 
     
    147147        } 
    148148 
    149149        function login_pass_ok($user_login, $user_pass) { 
    150           if (!user_pass_ok($user_login, $user_pass)) { 
    151             $this->error = new IXR_Error(403, 'Bad login/pass combination.'); 
    152             return false; 
    153           } 
    154           return true; 
     150                if (!user_pass_ok($user_login, $user_pass)) { 
     151                        $this->error = new IXR_Error(403, 'Bad login/pass combination.'); 
     152                        return false; 
     153                } 
     154                return true; 
    155155        } 
    156156 
    157157        function escape(&$array) { 
     
    178178 
    179179                $this->escape($args); 
    180180 
    181           $user_login = $args[1]; 
    182           $user_pass  = $args[2]; 
     181                $user_login = $args[1]; 
     182                $user_pass  = $args[2]; 
    183183 
    184           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    185             return $this->error; 
    186           } 
     184                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     185                        return $this->error; 
     186                } 
    187187 
    188           set_current_user(0, $user_login); 
    189           $is_admin = current_user_can('level_8'); 
     188                set_current_user(0, $user_login); 
     189                $is_admin = current_user_can('level_8'); 
    190190 
    191           $struct = array( 
    192             'isAdmin'  => $is_admin, 
    193             'url'      => get_settings('home') . '/', 
    194             'blogid'   => '1', 
    195             'blogName' => get_settings('blogname') 
    196           ); 
     191                $struct = array( 
     192                        'isAdmin'  => $is_admin, 
     193                        'url'      => get_settings('home') . '/', 
     194                        'blogid'   => '1', 
     195                        'blogName' => get_settings('blogname') 
     196                ); 
    197197 
    198           return array($struct); 
     198                return array($struct); 
    199199        } 
    200200 
    201201 
     
    204204 
    205205                $this->escape($args); 
    206206 
    207           $user_login = $args[1]; 
    208           $user_pass  = $args[2]; 
     207                $user_login = $args[1]; 
     208                $user_pass  = $args[2]; 
    209209 
    210           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    211             return $this->error; 
    212           } 
     210                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     211                        return $this->error; 
     212                } 
    213213 
    214           $user_data = get_userdatabylogin($user_login); 
     214                $user_data = get_userdatabylogin($user_login); 
    215215 
    216           $struct = array( 
    217             'nickname'  => $user_data->nickname, 
    218             'userid'    => $user_data->ID, 
    219             'url'       => $user_data->user_url, 
    220             'email'     => $user_data->user_email, 
    221             'lastname'  => $user_data->last_name, 
    222             'firstname' => $user_data->first_name 
    223           ); 
     216                $struct = array( 
     217                        'nickname'  => $user_data->nickname, 
     218                        'userid'    => $user_data->ID, 
     219                        'url'       => $user_data->user_url, 
     220                        'email'     => $user_data->user_email, 
     221                        'lastname'  => $user_data->last_name, 
     222                        'firstname' => $user_data->first_name 
     223                ); 
    224224 
    225           return $struct; 
     225                return $struct; 
    226226        } 
    227227 
    228228 
     
    231231 
    232232                $this->escape($args); 
    233233 
    234           $post_ID    = $args[1]; 
    235           $user_login = $args[2]; 
    236           $user_pass  = $args[3]; 
     234                $post_ID    = $args[1]; 
     235                $user_login = $args[2]; 
     236                $user_pass  = $args[3]; 
    237237 
    238           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    239             return $this->error; 
    240           } 
     238                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     239                        return $this->error; 
     240                } 
    241241 
    242           $user_data = get_userdatabylogin($user_login); 
    243           $post_data = wp_get_single_post($post_ID, ARRAY_A); 
     242                $user_data = get_userdatabylogin($user_login); 
     243                $post_data = wp_get_single_post($post_ID, ARRAY_A); 
    244244 
    245           $categories = implode(',', wp_get_post_categories($post_ID)); 
     245                $categories = implode(',', wp_get_post_categories($post_ID)); 
    246246 
    247           $content  = '<title>'.stripslashes($post_data['post_title']).'</title>'; 
    248           $content .= '<category>'.$categories.'</category>'; 
    249           $content .= stripslashes($post_data['post_content']); 
     247                $content  = '<title>'.stripslashes($post_data['post_title']).'</title>'; 
     248                $content .= '<category>'.$categories.'</category>'; 
     249                $content .= stripslashes($post_data['post_content']); 
    250250 
    251           $struct = array( 
    252             'userid'    => $post_data['post_author'], 
    253             'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])), 
    254             'content'     => $content, 
    255             'postid'  => $post_data['ID'] 
    256           ); 
     251                $struct = array( 
     252                        'userid'    => $post_data['post_author'], 
     253                        'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])), 
     254                        'content'     => $content, 
     255                        'postid'  => $post_data['ID'] 
     256                ); 
    257257 
    258           return $struct; 
     258                return $struct; 
    259259        } 
    260260 
    261261 
    262262        /* blogger.getRecentPosts ...gets recent posts */ 
    263263        function blogger_getRecentPosts($args) { 
    264264 
    265           global $wpdb; 
     265                global $wpdb; 
    266266 
    267267                $this->escape($args); 
    268268 
    269           $blog_ID    = $args[1]; /* though we don't use it yet */ 
    270           $user_login = $args[2]; 
    271           $user_pass  = $args[3]; 
    272           $num_posts  = $args[4]; 
     269                $blog_ID    = $args[1]; /* though we don't use it yet */ 
     270                $user_login = $args[2]; 
     271                $user_pass  = $args[3]; 
     272                $num_posts  = $args[4]; 
    273273 
    274           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    275             return $this->error; 
    276           } 
     274                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     275                        return $this->error; 
     276                } 
    277277 
    278           $posts_list = wp_get_recent_posts($num_posts); 
     278                $posts_list = wp_get_recent_posts($num_posts); 
    279279 
    280           if (!$posts_list) { 
    281             $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
    282             return $this->error; 
    283           } 
     280                if (!$posts_list) { 
     281                        $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
     282                        return $this->error; 
     283                } 
    284284 
    285           foreach ($posts_list as $entry) { 
    286            
    287             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
    288             $categories = implode(',', wp_get_post_categories($entry['ID'])); 
     285                foreach ($posts_list as $entry) { 
    289286 
    290             $content  = '<title>'.stripslashes($entry['post_title']).'</title>'; 
    291             $content .= '<category>'.$categories.'</category>'; 
    292             $content .= stripslashes($entry['post_content']); 
     287                        $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
     288                        $categories = implode(',', wp_get_post_categories($entry['ID'])); 
    293289 
    294             $struct[] = array( 
    295               'userid' => $entry['post_author'], 
    296               'dateCreated' => new IXR_Date($post_date), 
    297               'content' => $content, 
    298               'postid' => $entry['ID'], 
    299             ); 
     290                        $content  = '<title>'.stripslashes($entry['post_title']).'</title>'; 
     291                        $content .= '<category>'.$categories.'</category>'; 
     292                        $content .= stripslashes($entry['post_content']); 
    300293 
    301           } 
     294                        $struct[] = array( 
     295                                'userid' => $entry['post_author'], 
     296                                'dateCreated' => new IXR_Date($post_date), 
     297                                'content' => $content, 
     298                                'postid' => $entry['ID'], 
     299                        ); 
    302300 
    303           $recent_posts = array(); 
    304           for ($j=0; $j<count($struct); $j++) { 
    305             array_push($recent_posts, $struct[$j]); 
    306           } 
     301                } 
    307302 
    308           return $recent_posts; 
     303                $recent_posts = array(); 
     304                for ($j=0; $j<count($struct); $j++) { 
     305                        array_push($recent_posts, $struct[$j]); 
     306                } 
     307 
     308                return $recent_posts; 
    309309        } 
    310310 
    311311 
     
    314314 
    315315                $this->escape($args); 
    316316 
    317           $blog_ID    = $args[1]; 
    318           $user_login = $args[2]; 
    319           $user_pass  = $args[3]; 
    320           $template   = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
     317                $blog_ID    = $args[1]; 
     318                $user_login = $args[2]; 
     319                $user_pass  = $args[3]; 
     320                $template   = $args[4]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
    321321 
    322           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    323             return $this->error; 
    324           } 
     322                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     323                        return $this->error; 
     324                } 
    325325 
    326           set_current_user(0, $user_login); 
    327           if ( !current_user_can('edit_themes') ) { 
    328             return new IXR_Error(401, 'Sorry, this user can not edit the template.'); 
    329           } 
     326                set_current_user(0, $user_login); 
     327                if ( !current_user_can('edit_themes') ) { 
     328                        return new IXR_Error(401, 'Sorry, this user can not edit the template.'); 
     329                } 
    330330 
    331           /* warning: here we make the assumption that the weblog's URI is on the same server */ 
    332           $filename = get_settings('home') . '/'; 
    333           $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); 
     331                /* warning: here we make the assumption that the weblog's URI is on the same server */ 
     332                $filename = get_settings('home') . '/'; 
     333                $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); 
    334334 
    335           $f = fopen($filename, 'r'); 
    336           $content = fread($f, filesize($filename)); 
    337           fclose($f); 
     335                $f = fopen($filename, 'r'); 
     336                $content = fread($f, filesize($filename)); 
     337                fclose($f); 
    338338 
    339           /* so it is actually editable with a windows/mac client */ 
    340           // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented.     $content = str_replace("\n", "\r\n", $content);  
     339                /* so it is actually editable with a windows/mac client */ 
     340                // FIXME: (or delete me) do we really want to cater to bad clients at the expense of good ones by BEEPing up their line breaks? commented.     $content = str_replace("\n", "\r\n", $content); 
    341341 
    342           return $content; 
     342                return $content; 
    343343        } 
    344344 
    345345 
     
    348348 
    349349                $this->escape($args); 
    350350 
    351           $blog_ID    = $args[1]; 
    352           $user_login = $args[2]; 
    353           $user_pass  = $args[3]; 
    354           $content    = $args[4]; 
    355           $template   = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
     351                $blog_ID    = $args[1]; 
     352                $user_login = $args[2]; 
     353                $user_pass  = $args[3]; 
     354                $content    = $args[4]; 
     355                $template   = $args[5]; /* could be 'main' or 'archiveIndex', but we don't use it */ 
    356356 
    357           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    358             return $this->error; 
    359           } 
     357                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     358                        return $this->error; 
     359                } 
    360360 
    361           set_current_user(0, $user_login); 
    362           if ( !current_user_can('edit_themes') ) { 
    363             return new IXR_Error(401, 'Sorry, this user can not edit the template.'); 
    364           } 
     361                set_current_user(0, $user_login); 
     362                if ( !current_user_can('edit_themes') ) { 
     363                        return new IXR_Error(401, 'Sorry, this user can not edit the template.'); 
     364                } 
    365365 
    366           /* warning: here we make the assumption that the weblog's URI is on the same server */ 
    367           $filename = get_settings('home') . '/'; 
    368           $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); 
     366                /* warning: here we make the assumption that the weblog's URI is on the same server */ 
     367                $filename = get_settings('home') . '/'; 
     368                $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); 
    369369 
    370           if ($f = fopen($filename, 'w+')) { 
    371             fwrite($f, $content); 
    372             fclose($f); 
    373           } else { 
    374             return new IXR_Error(500, 'Either the file is not writable, or something wrong happened. The file has not been updated.'); 
    375           } 
     370                if ($f = fopen($filename, 'w+')) { 
     371                        fwrite($f, $content); 
     372                        fclose($f); 
     373                } else { 
     374                        return new IXR_Error(500, 'Either the file is not writable, or something wrong happened. The file has not been updated.'); 
     375                } 
    376376 
    377           return true; 
     377                return true; 
    378378        } 
    379379 
    380380 
    381381        /* blogger.newPost ...creates a new post */ 
    382382        function blogger_newPost($args) { 
    383383 
    384           global $wpdb; 
     384                global $wpdb; 
    385385 
    386386                $this->escape($args); 
    387387 
    388           $blog_ID    = $args[1]; /* though we don't use it yet */ 
    389           $user_login = $args[2]; 
    390           $user_pass  = $args[3]; 
    391           $content    = $args[4]; 
    392           $publish    = $args[5]; 
     388                $blog_ID    = $args[1]; /* though we don't use it yet */ 
     389                $user_login = $args[2]; 
     390                $user_pass  = $args[3]; 
     391                $content    = $args[4]; 
     392                $publish    = $args[5]; 
    393393 
    394           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    395             return $this->error; 
    396           } 
    397            
    398           $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 
    399           $user = set_current_user(0, $user_login); 
    400           if ( !current_user_can($cap) ) 
    401             return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.'); 
     394                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     395                        return $this->error; 
     396                } 
    402397 
    403           $post_status = ($publish) ? 'publish' : 'draft'; 
     398                $cap = ($publish) ? 'publish_posts' : 'edit_posts'; 
     399                $user = set_current_user(0, $user_login); 
     400                if ( !current_user_can($cap) ) 
     401                        return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.'); 
    404402 
    405           $post_author = $user->ID; 
     403                $post_status = ($publish) ? 'publish' : 'draft'; 
    406404 
    407           $post_title = xmlrpc_getposttitle($content); 
    408           $post_category = xmlrpc_getpostcategory($content); 
    409           $post_content = xmlrpc_removepostdata($content); 
     405                $post_author = $user->ID; 
    410406 
    411           $post_date = current_time('mysql'); 
    412           $post_date_gmt = current_time('mysql', 1); 
     407                $post_title = xmlrpc_getposttitle($content); 
     408                $post_category = xmlrpc_getpostcategory($content); 
     409                $post_content = xmlrpc_removepostdata($content); 
    413410 
    414           $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); 
     411                $post_date = current_time('mysql'); 
     412                $post_date_gmt = current_time('mysql', 1); 
    415413 
    416           $post_ID = wp_insert_post($post_data); 
     414                $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); 
    417415 
    418           if (!$post_ID) { 
    419             return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 
    420           } 
     416                $post_ID = wp_insert_post($post_data); 
    421417 
    422           logIO('O', "Posted ! ID: $post_ID"); 
     418                if (!$post_ID) { 
     419                        return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 
     420                } 
    423421 
    424           return $post_ID; 
     422                logIO('O', "Posted ! ID: $post_ID"); 
     423 
     424                return $post_ID; 
    425425        } 
    426426 
    427427 
    428428        /* blogger.editPost ...edits a post */ 
    429429        function blogger_editPost($args) { 
    430430 
    431           global $wpdb; 
     431                global $wpdb; 
    432432 
    433433                $this->escape($args); 
    434434 
    435           $post_ID     = $args[1]; 
    436           $user_login  = $args[2]; 
    437           $user_pass   = $args[3]; 
    438           $content     = $args[4]; 
    439           $publish     = $args[5]; 
     435                $post_ID     = $args[1]; 
     436                $user_login  = $args[2]; 
     437                $user_pass   = $args[3]; 
     438                $content     = $args[4]; 
     439                $publish     = $args[5]; 
    440440 
    441           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    442             return $this->error; 
    443           } 
     441                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     442                        return $this->error; 
     443                } 
    444444 
    445           $actual_post = wp_get_single_post($post_ID,ARRAY_A); 
     445                $actual_post = wp_get_single_post($post_ID,ARRAY_A); 
    446446 
    447           if (!$actual_post) { 
    448                 return new IXR_Error(404, 'Sorry, no such post.'); 
    449           } 
     447                if (!$actual_post) { 
     448                        return new IXR_Error(404, 'Sorry, no such post.'); 
     449                } 
    450450 
    451451                $this->escape($actual_post); 
    452452 
    453           set_current_user(0, $user_login); 
    454           if ( !current_user_can('edit_post', $post_ID) ) 
    455             return new IXR_Error(401, 'Sorry, you do not have the right to edit this post.'); 
     453                set_current_user(0, $user_login); 
     454                if ( !current_user_can('edit_post', $post_ID) ) 
     455                        return new IXR_Error(401, 'Sorry, you do not have the right to edit this post.'); 
    456456 
    457           extract($actual_post); 
     457                extract($actual_post); 
    458458 
    459           $post_title = xmlrpc_getposttitle($content); 
    460           $post_category = xmlrpc_getpostcategory($content); 
    461           $post_content = xmlrpc_removepostdata($content); 
     459                $post_title = xmlrpc_getposttitle($content); 
     460                $post_category = xmlrpc_getpostcategory($content); 
     461                $post_content = xmlrpc_removepostdata($content); 
    462462 
    463           $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); 
     463                $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); 
    464464 
    465           $result = wp_update_post($postdata); 
     465                $result = wp_update_post($postdata); 
    466466 
    467           if (!$result) { 
    468                 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.'); 
    469           } 
     467                if (!$result) { 
     468                        return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.'); 
     469                } 
    470470 
    471           return true; 
     471                return true; 
    472472        } 
    473473 
    474474 
    475475        /* blogger.deletePost ...deletes a post */ 
    476476        function blogger_deletePost($args) { 
    477477 
    478           global $wpdb; 
     478                global $wpdb; 
    479479 
    480480                $this->escape($args); 
    481481 
    482           $post_ID     = $args[1]; 
    483           $user_login  = $args[2]; 
    484           $user_pass   = $args[3]; 
    485           $publish     = $args[4]; 
     482                $post_ID     = $args[1]; 
     483                $user_login  = $args[2]; 
     484                $user_pass   = $args[3]; 
     485                $publish     = $args[4]; 
    486486 
    487           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    488             return $this->error; 
    489           } 
     487                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     488                        return $this->error; 
     489                } 
    490490 
    491           $actual_post = wp_get_single_post($post_ID,ARRAY_A); 
     491                $actual_post = wp_get_single_post($post_ID,ARRAY_A); 
    492492 
    493           if (!$actual_post) { 
    494                 return new IXR_Error(404, 'Sorry, no such post.'); 
    495           } 
     493                if (!$actual_post) { 
     494                        return new IXR_Error(404, 'Sorry, no such post.'); 
     495                } 
    496496 
    497           set_current_user(0, $user_login); 
    498           if ( !current_user_can('edit_post', $post_ID) ) 
    499             return new IXR_Error(401, 'Sorry, you do not have the right to delete this post.'); 
     497                set_current_user(0, $user_login); 
     498                if ( !current_user_can('edit_post', $post_ID) ) 
     499                        return new IXR_Error(401, 'Sorry, you do not have the right to delete this post.'); 
    500500 
    501           $result = wp_delete_post($post_ID); 
     501                $result = wp_delete_post($post_ID); 
    502502 
    503           if (!$result) { 
    504                 return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be deleted.'); 
    505           } 
     503                if (!$result) { 
     504                        return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be deleted.'); 
     505                } 
    506506 
    507           return true; 
     507                return true; 
    508508        } 
    509509 
    510510 
     
    516516        /* metaweblog.newPost creates a post */ 
    517517        function mw_newPost($args) { 
    518518 
    519           global $wpdb, $post_default_category; 
     519                global $wpdb, $post_default_category; 
    520520 
    521521                $this->escape($args); 
    522522 
    523           $blog_ID     = $args[0]; // we will support this in the near future 
    524           $user_login  = $args[1]; 
    525           $user_pass   = $args[2]; 
    526           $content_struct = $args[3]; 
    527           $publish     = $args[4]; 
     523                $blog_ID     = $args[0]; // we will support this in the near future 
     524                $user_login  = $args[1]; 
     525                $user_pass   = $args[2]; 
     526                $content_struct = $args[3]; 
     527                $publish     = $args[4]; 
    528528 
    529           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    530             return $this->error; 
    531           } 
     529                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     530                        return $this->error; 
     531                } 
    532532 
    533           $user = set_current_user(0, $user_login); 
    534           if ( !current_user_can('publish_posts') ) 
    535             return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.'); 
     533                $user = set_current_user(0, $user_login); 
     534                if ( !current_user_can('publish_posts') ) 
     535                        return new IXR_Error(401, 'Sorry, you can not post on this weblog or category.'); 
    536536 
    537           $post_author = $user->ID; 
     537                $post_author = $user->ID; 
    538538 
    539           $post_title = $content_struct['title']; 
    540           $post_content = apply_filters( 'content_save_pre', $content_struct['description'] ); 
    541           $post_status = $publish ? 'publish' : 'draft'; 
     539                $post_title = $content_struct['title']; 
     540                $post_content = apply_filters( 'content_save_pre', $content_struct['description'] ); 
     541                $post_status = $publish ? 'publish' : 'draft'; 
    542542 
    543           $post_excerpt = $content_struct['mt_excerpt']; 
    544           $post_more = $content_struct['mt_text_more']; 
     543                $post_excerpt = $content_struct['mt_excerpt']; 
     544                $post_more = $content_struct['mt_text_more']; 
    545545 
    546           $comment_status = (empty($content_struct['mt_allow_comments'])) ? 
    547             get_settings('default_comment_status') 
    548             : $content_struct['mt_allow_comments']; 
     546                $comment_status = (empty($content_struct['mt_allow_comments'])) ? 
     547                        get_settings('default_comment_status') 
     548                        : $content_struct['mt_allow_comments']; 
    549549 
    550           $ping_status = (empty($content_struct['mt_allow_pings'])) ? 
    551             get_settings('default_ping_status') 
    552             : $content_struct['mt_allow_pings']; 
     550                $ping_status = (empty($content_struct['mt_allow_pings'])) ? 
     551                        get_settings('default_ping_status') 
     552                        : $content_struct['mt_allow_pings']; 
    553553 
    554           if ($post_more) { 
    555             $post_content = $post_content . "\n<!--more-->\n" . $post_more; 
    556           } 
     554                if ($post_more) { 
     555                        $post_content = $post_content . "\n<!--more-->\n" . $post_more; 
     556                } 
    557557 
    558558                $to_ping = $content_struct['mt_tb_ping_urls']; 
    559559 
    560           // Do some timestamp voodoo 
    561           $dateCreatedd = $content_struct['dateCreated']; 
    562           if (!empty($dateCreatedd)) { 
    563             $dateCreated = $dateCreatedd->getIso(); 
    564             $post_date     = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 
    565             $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); 
    566           } else { 
    567             $post_date     = current_time('mysql'); 
    568             $post_date_gmt = current_time('mysql', 1); 
    569           } 
     560                // Do some timestamp voodoo 
     561                $dateCreatedd = $content_struct['dateCreated']; 
     562                if (!empty($dateCreatedd)) { 
     563                        $dateCreated = $dateCreatedd->getIso(); 
     564                        $post_date     = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 
     565                        $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); 
     566                } else { 
     567                        $post_date     = current_time('mysql'); 
     568                        $post_date_gmt = current_time('mysql', 1); 
     569                } 
    570570 
    571           $catnames = $content_struct['categories']; 
    572           logIO('O', 'Post cats: ' . printr($catnames,true)); 
    573           $post_category = array(); 
     571                $catnames = $content_struct['categories']; 
     572                logIO('O', 'Post cats: ' . printr($catnames,true)); 
     573                $post_category = array(); 
    574574 
    575           if (is_array($catnames)) { 
    576             foreach ($catnames as $cat) { 
    577               $post_category[] = get_cat_ID($cat); 
    578             } 
    579           } 
     575                if (is_array($catnames)) { 
     576                        foreach ($catnames as $cat) { 
     577                                $post_category[] = get_cat_ID($cat); 
     578                        } 
     579                } 
    580580 
    581           // We've got all the data -- post it: 
    582           $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping'); 
     581                // We've got all the data -- post it: 
     582                $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping'); 
    583583 
    584           $post_ID = wp_insert_post($postdata); 
     584                $post_ID = wp_insert_post($postdata); 
    585585 
    586           if (!$post_ID) { 
    587             return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 
    588           } 
     586                if (!$post_ID) { 
     587                        return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.'); 
     588                } 
    589589 
    590           logIO('O', "Posted ! ID: $post_ID"); 
     590                logIO('O', "Posted ! ID: $post_ID"); 
    591591 
    592           return strval($post_ID); 
     592                return strval($post_ID); 
    593593        } 
    594594 
    595595 
    596596        /* metaweblog.editPost ...edits a post */ 
    597597        function mw_editPost($args) { 
    598598 
    599           global $wpdb, $post_default_category; 
     599                global $wpdb, $post_default_category; 
    600600 
    601601                $this->escape($args); 
    602602 
    603           $post_ID     = $args[0]; 
    604           $user_login  = $args[1]; 
    605           $user_pass   = $args[2]; 
    606           $content_struct = $args[3]; 
    607           $publish     = $args[4]; 
     603                $post_ID     = $args[0]; 
     604                $user_login  = $args[1]; 
     605                $user_pass   = $args[2]; 
     606                $content_struct = $args[3]; 
     607                $publish     = $args[4]; 
    608608 
    609           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    610             return $this->error; 
    611           } 
     609                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     610                        return $this->error; 
     611                } 
    612612 
    613           set_current_user(0, $user_login); 
    614           if ( !current_user_can('edit_post', $post_ID) ) 
    615             return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
     613                set_current_user(0, $user_login); 
     614                if ( !current_user_can('edit_post', $post_ID) ) 
     615                        return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
    616616 
    617           $postdata = wp_get_single_post($post_ID, ARRAY_A); 
    618           extract($postdata); 
     617                $postdata = wp_get_single_post($post_ID, ARRAY_A); 
     618                extract($postdata); 
    619619                $this->escape($postdata); 
    620620 
    621           $post_title = $content_struct['title']; 
    622           $post_content = apply_filters( 'content_save_pre', $content_struct['description'] ); 
    623           $catnames = $content_struct['categories']; 
     621                $post_title = $content_struct['title']; 
     622                $post_content = apply_filters( 'content_save_pre', $content_struct['description'] ); 
     623                $catnames = $content_struct['categories']; 
    624624 
    625           $post_category = array(); 
     625                $post_category = array(); 
    626626 
    627           if (is_array($catnames)) { 
    628             foreach ($catnames as $cat) { 
    629               $post_category[] = get_cat_ID($cat); 
    630             } 
    631           } 
     627                if (is_array($catnames)) { 
     628                        foreach ($catnames as $cat) { 
     629                                $post_category[] = get_cat_ID($cat); 
     630                        } 
     631                } 
    632632 
    633           $post_excerpt = $content_struct['mt_excerpt']; 
    634           $post_more = $content_struct['mt_text_more']; 
    635           $post_status = $publish ? 'publish' : 'draft'; 
     633                $post_excerpt = $content_struct['mt_excerpt']; 
     634                $post_more = $content_struct['mt_text_more']; 
     635                $post_status = $publish ? 'publish' : 'draft'; 
    636636 
    637           if ($post_more) { 
    638             $post_content = $post_content . "\n<!--more-->\n" . $post_more; 
    639           } 
     637                if ($post_more) { 
     638                        $post_content = $post_content . "\n<!--more-->\n" . $post_more; 
     639                } 
    640640 
    641641                $to_ping = $content_struct['mt_tb_ping_urls']; 
    642642 
    643           $comment_status = (empty($content_struct['mt_allow_comments'])) ? 
    644             get_settings('default_comment_status') 
    645             : $content_struct['mt_allow_comments']; 
     643                $comment_status = (empty($content_struct['mt_allow_comments'])) ? 
     644                        get_settings('default_comment_status') 
     645                        : $content_struct['mt_allow_comments']; 
    646646 
    647           $ping_status = (empty($content_struct['mt_allow_pings'])) ? 
    648             get_settings('default_ping_status') 
    649             : $content_struct['mt_allow_pings']; 
     647                $ping_status = (empty($content_struct['mt_allow_pings'])) ? 
     648                        get_settings('default_ping_status') 
     649                        : $content_struct['mt_allow_pings']; 
    650650 
    651           // Do some timestamp voodoo 
    652           $dateCreatedd = $content_struct['dateCreated']; 
    653           if (!empty($dateCreatedd)) { 
    654             $dateCreated = $dateCreatedd->getIso(); 
    655             $post_date     = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 
    656             $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); 
    657           } else { 
    658             $post_date     = $postdata['post_date']; 
    659             $post_date_gmt = $postdata['post_date_gmt']; 
    660           } 
     651                // Do some timestamp voodoo 
     652                $dateCreatedd = $content_struct['dateCreated']; 
     653                if (!empty($dateCreatedd)) { 
     654                        $dateCreated = $dateCreatedd->getIso(); 
     655                        $post_date     = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 
     656                        $post_date_gmt = iso8601_to_datetime($dateCreated, GMT); 
     657                } else { 
     658                        $post_date     = $postdata['post_date']; 
     659                        $post_date_gmt = $postdata['post_date_gmt']; 
     660                } 
    661661 
    662           // We've got all the data -- post it: 
    663           $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping'); 
     662                // We've got all the data -- post it: 
     663                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping'); 
    664664 
    665           $result = wp_update_post($newpost); 
    666           if (!$result) { 
    667             return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); 
    668           } 
     665                $result = wp_update_post($newpost); 
     666                if (!$result) { 
     667                        return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.'); 
     668                } 
    669669 
    670           logIO('O',"(MW) Edited ! ID: $post_ID"); 
     670                logIO('O',"(MW) Edited ! ID: $post_ID"); 
    671671 
    672           return true; 
     672                return true; 
    673673        } 
    674674 
    675675 
    676676        /* metaweblog.getPost ...returns a post */ 
    677677        function mw_getPost($args) { 
    678678 
    679           global $wpdb; 
     679                global $wpdb; 
    680680 
    681681                $this->escape($args); 
    682682 
    683           $post_ID     = $args[0]; 
    684           $user_login  = $args[1]; 
    685           $user_pass   = $args[2]; 
     683                $post_ID     = $args[0]; 
     684                $user_login  = $args[1]; 
     685                $user_pass   = $args[2]; 
    686686 
    687           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    688             return $this->error; 
    689           } 
     687                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     688                        return $this->error; 
     689                } 
    690690 
    691           $postdata = wp_get_single_post($post_ID, ARRAY_A); 
     691                $postdata = wp_get_single_post($post_ID, ARRAY_A); 
    692692 
    693           if ($postdata['post_date'] != '') { 
     693                if ($postdata['post_date'] != '') { 
    694694 
    695             $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']); 
     695                        $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']); 
    696696 
    697             $categories = array(); 
    698             $catids = wp_get_post_categories($post_ID); 
    699             foreach($catids as $catid) { 
    700               $categories[] = get_cat_name($catid); 
    701             } 
     697                        $categories = array(); 
     698                        $catids = wp_get_post_categories($post_ID); 
     699                        foreach($catids as $catid) { 
     700                                $categories[] = get_cat_name($catid); 
     701                        } 
    702702 
    703             $post = get_extended($postdata['post_content']); 
    704             $link = post_permalink($postdata['ID']); 
     703                        $post = get_extended($postdata['post_content']); 
     704                        $link = post_permalink($postdata['ID']); 
    705705 
    706             $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0; 
    707             $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; 
     706                        $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0; 
     707                        $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0; 
    708708 
    709             $resp = array( 
    710               'dateCreated' => new IXR_Date($post_date), 
    711               'userid' => $postdata['post_author'], 
    712               'postid' => $postdata['ID'], 
    713               'description' => $post['main'], 
    714               'title' => $postdata['post_title'], 
    715               'link' => $link, 
    716               'permaLink' => $link, 
     709                        $resp = array( 
     710                                'dateCreated' => new IXR_Date($post_date), 
     711                                'userid' => $postdata['post_author'], 
     712                                'postid' => $postdata['ID'], 
     713                                'description' => $post['main'], 
     714                                'title' => $postdata['post_title'], 
     715                                'link' => $link, 
     716                                'permaLink' => $link, 
    717717// commented out because no other tool seems to use this 
    718718//            'content' => $entry['post_content'], 
    719               'categories' => $categories, 
    720               'mt_excerpt' => $postdata['post_excerpt'], 
    721               'mt_text_more' => $post['extended'], 
    722               'mt_allow_comments' => $allow_comments, 
    723               'mt_allow_pings' => $allow_pings 
    724             ); 
     719                                'categories' => $categories, 
     720                                'mt_excerpt' => $postdata['post_excerpt'], 
     721                                'mt_text_more' => $post['extended'], 
     722                                'mt_allow_comments' => $allow_comments, 
     723                                'mt_allow_pings' => $allow_pings 
     724                        ); 
    725725 
    726             return $resp; 
    727           } else { 
    728                 return new IXR_Error(404, 'Sorry, no such post.'); 
    729           } 
     726                        return $resp; 
     727                } else { 
     728                        return new IXR_Error(404, 'Sorry, no such post.'); 
     729                } 
    730730        } 
    731731 
    732732 
     
    735735 
    736736                $this->escape($args); 
    737737 
    738           $blog_ID     = $args[0]; 
    739           $user_login  = $args[1]; 
    740           $user_pass   = $args[2]; 
    741           $num_posts   = $args[3]; 
     738                $blog_ID     = $args[0]; 
     739                $user_login  = $args[1]; 
     740                $user_pass   = $args[2]; 
     741                $num_posts   = $args[3]; 
    742742 
    743           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    744             return $this->error; 
    745           } 
     743                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     744                        return $this->error; 
     745                } 
    746746 
    747           $posts_list = wp_get_recent_posts($num_posts); 
     747                $posts_list = wp_get_recent_posts($num_posts); 
    748748 
    749           if (!$posts_list) { 
    750             $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
    751             return $this->error; 
    752           } 
     749                if (!$posts_list) { 
     750                        $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
     751                        return $this->error; 
     752                } 
    753753 
    754           foreach ($posts_list as $entry) { 
    755            
    756             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
    757             $categories = array(); 
    758             $catids = wp_get_post_categories($entry['ID']); 
    759             foreach($catids as $catid) { 
    760               $categories[] = get_cat_name($catid); 
    761             } 
     754                foreach ($posts_list as $entry) { 
    762755 
    763             $post = get_extended($entry['post_content']); 
    764             $link = post_permalink($entry['ID']); 
     756                        $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
     757                        $categories = array(); 
     758                        $catids = wp_get_post_categories($entry['ID']); 
     759                        foreach($catids as $catid) { 
     760                                $categories[] = get_cat_name($catid); 
     761                        } 
    765762 
    766             $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0; 
    767             $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0; 
     763                        $post = get_extended($entry['post_content']); 
     764                        $link = post_permalink($entry['ID']); 
    768765 
    769             $struct[] = array( 
    770               'dateCreated' => new IXR_Date($post_date), 
    771               'userid' => $entry['post_author'], 
    772               'postid' => $entry['ID'], 
    773               'description' => $post['main'], 
    774               'title' => $entry['post_title'], 
    775               'link' => $link, 
    776               'permaLink' => $link, 
     766                        $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0; 
     767                        $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0; 
     768 
     769                        $struct[] = array( 
     770                                'dateCreated' => new IXR_Date($post_date), 
     771                                'userid' => $entry['post_author'], 
     772                                'postid' => $entry['ID'], 
     773                                'description' => $post['main'], 
     774                                'title' => $entry['post_title'], 
     775                                'link' => $link, 
     776                                'permaLink' => $link, 
    777777// commented out because no other tool seems to use this 
    778778//            'content' => $entry['post_content'], 
    779               'categories' => $categories, 
    780               'mt_excerpt' => $entry['post_excerpt'], 
    781               'mt_text_more' => $post['extended'], 
    782               'mt_allow_comments' => $allow_comments, 
    783               'mt_allow_pings' => $allow_pings 
    784             ); 
     779                                'categories' => $categories, 
     780                                'mt_excerpt' => $entry['post_excerpt'], 
     781                                'mt_text_more' => $post['extended'], 
     782                                'mt_allow_comments' => $allow_comments, 
     783                                'mt_allow_pings' => $allow_pings 
     784                        ); 
    785785 
    786           } 
     786                } 
    787787 
    788           $recent_posts = array(); 
    789           for ($j=0; $j<count($struct); $j++) { 
    790             array_push($recent_posts, $struct[$j]); 
    791           } 
    792            
    793           return $recent_posts; 
     788                $recent_posts = array(); 
     789                for ($j=0; $j<count($struct); $j++) { 
     790                        array_push($recent_posts, $struct[$j]); 
     791                } 
     792 
     793                return $recent_posts; 
    794794        } 
    795795 
    796796 
    797797        /* metaweblog.getCategories ...returns the list of categories on a given weblog */ 
    798798        function mw_getCategories($args) { 
    799799 
    800           global $wpdb; 
     800                global $wpdb; 
    801801 
    802802                $this->escape($args); 
    803803 
    804           $blog_ID     = $args[0]; 
    805           $user_login  = $args[1]; 
    806           $user_pass   = $args[2]; 
     804                $blog_ID     = $args[0]; 
     805                $user_login  = $args[1]; 
     806                $user_pass   = $args[2]; 
    807807 
    808           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    809             return $this->error; 
    810           } 
     808                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     809                        return $this->error; 
     810                } 
    811811 
    812           $categories_struct = array(); 
     812                $categories_struct = array(); 
    813813 
    814           // FIXME: can we avoid using direct SQL there? 
    815           if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) { 
    816             foreach ($cats as $cat) { 
    817               $struct['categoryId'] = $cat['cat_ID']; 
    818               $struct['description'] = $cat['cat_name']; 
    819               $struct['categoryName'] = $cat['cat_name']; 
    820               $struct['htmlUrl'] = wp_specialchars(get_category_link($cat['cat_ID'])); 
    821               $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name'])); 
     814                // FIXME: can we avoid using direct SQL there? 
     815                if ($cats = $wpdb->get_results("SELECT cat_ID,cat_name FROM $wpdb->categories", ARRAY_A)) { 
     816                        foreach ($cats as $cat) { 
     817                                $struct['categoryId'] = $cat['cat_ID']; 
     818                                $struct['description'] = $cat['cat_name']; 
     819                                $struct['categoryName'] = $cat['cat_name']; 
     820                                $struct['htmlUrl'] = wp_specialchars(get_category_link($cat['cat_ID'])); 
     821                                $struct['rssUrl'] = wp_specialchars(get_category_rss_link(false, $cat['cat_ID'], $cat['cat_name'])); 
    822822 
    823               $categories_struct[] = $struct; 
    824             } 
    825           } 
     823                                $categories_struct[] = $struct; 
     824                        } 
     825                } 
    826826 
    827           return $categories_struct; 
     827                return $categories_struct; 
    828828        } 
    829829 
    830830 
     
    875875 
    876876                $this->escape($args); 
    877877 
    878           $blog_ID     = $args[0]; 
    879           $user_login  = $args[1]; 
    880           $user_pass   = $args[2]; 
    881           $num_posts   = $args[3]; 
     878                $blog_ID     = $args[0]; 
     879                $user_login  = $args[1]; 
     880                $user_pass   = $args[2]; 
     881                $num_posts   = $args[3]; 
    882882 
    883           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    884             return $this->error; 
    885           } 
     883                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     884                        return $this->error; 
     885                } 
    886886 
    887           $posts_list = wp_get_recent_posts($num_posts); 
     887                $posts_list = wp_get_recent_posts($num_posts); 
    888888 
    889           if (!$posts_list) { 
    890             $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
    891             return $this->error; 
    892           } 
     889                if (!$posts_list) { 
     890                        $this->error = new IXR_Error(500, 'Either there are no posts, or something went wrong.'); 
     891                        return $this->error; 
     892                } 
    893893 
    894           foreach ($posts_list as $entry) { 
    895            
    896             $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
     894                foreach ($posts_list as $entry) { 
    897895 
    898             $struct[] = array( 
    899               'dateCreated' => new IXR_Date($post_date), 
    900               'userid' => $entry['post_author'], 
    901               'postid' => $entry['ID'], 
    902               'title' => $entry['post_title'], 
    903             ); 
     896                        $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']); 
    904897 
    905           } 
     898                        $struct[] = array( 
     899                                'dateCreated' => new IXR_Date($post_date), 
     900                                'userid' => $entry['post_author'], 
     901                                'postid' => $entry['ID'], 
     902                                'title' => $entry['post_title'], 
     903                        ); 
    906904 
    907           $recent_posts = array(); 
    908           for ($j=0; $j<count($struct); $j++) { 
    909             array_push($recent_posts, $struct[$j]); 
    910           } 
    911            
    912           return $recent_posts; 
     905                } 
     906 
     907                $recent_posts = array(); 
     908                for ($j=0; $j<count($struct); $j++) { 
     909                        array_push($recent_posts, $struct[$j]); 
     910                } 
     911 
     912                return $recent_posts; 
    913913        } 
    914914 
    915915 
    916916        /* mt.getCategoryList ...returns the list of categories on a given weblog */ 
    917917        function mt_getCategoryList($args) { 
    918918 
    919           global $wpdb; 
     919                global $wpdb; 
    920920 
    921921                $this->escape($args); 
    922922 
    923           $blog_ID     = $args[0]; 
    924           $user_login  = $args[1]; 
    925           $user_pass   = $args[2]; 
     923                $blog_ID     = $args[0]; 
     924                $user_login  = $args[1]; 
     925                $user_pass   = $args[2]; 
    926926 
    927           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    928             return $this->error; 
    929           } 
     927                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     928                        return $this->error; 
     929                } 
    930930 
    931           $categories_struct = array(); 
     931                $categories_struct = array(); 
    932932 
    933           // FIXME: can we avoid using direct SQL there? 
    934           if ($cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_A)) { 
    935             foreach ($cats as $cat) { 
    936               $struct['categoryId'] = $cat['cat_ID']; 
    937               $struct['categoryName'] = $cat['cat_name']; 
     933                // FIXME: can we avoid using direct SQL there? 
     934                if ($cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories", ARRAY_A)) { 
     935                        foreach ($cats as $cat) { 
     936                                $struct['categoryId'] = $cat['cat_ID']; 
     937                                $struct['categoryName'] = $cat['cat_name']; 
    938938 
    939               $categories_struct[] = $struct; 
    940             } 
    941           } 
     939                                $categories_struct[] = $struct; 
     940                        } 
     941                } 
    942942 
    943           return $categories_struct; 
     943                return $categories_struct; 
    944944        } 
    945945 
    946946 
     
    949949 
    950950                $this->escape($args); 
    951951 
    952           $post_ID     = $args[0]; 
    953           $user_login  = $args[1]; 
    954           $user_pass   = $args[2]; 
     952                $post_ID     = $args[0]; 
     953                $user_login  = $args[1]; 
     954                $user_pass   = $args[2]; 
    955955 
    956           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    957             return $this->error; 
    958           } 
     956                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     957                        return $this->error; 
     958                } 
    959959 
    960           $categories = array(); 
    961           $catids = wp_get_post_categories(intval($post_ID)); 
    962           // first listed category will be the primary category 
    963           $isPrimary = true; 
    964           foreach($catids as $catid) { 
    965             $categories[] = array( 
    966               'categoryName' => get_cat_name($catid), 
    967               'categoryId' => $catid, 
    968               'isPrimary' => $isPrimary 
    969             ); 
    970             $isPrimary = false; 
    971           } 
    972   
    973           return $categories; 
     960                $categories = array(); 
     961                $catids = wp_get_post_categories(intval($post_ID)); 
     962                // first listed category will be the primary category 
     963                $isPrimary = true; 
     964                foreach($catids as $catid) { 
     965                        $categories[] = array( 
     966                                'categoryName' => get_cat_name($catid), 
     967                                'categoryId' => $catid, 
     968                                'isPrimary' => $isPrimary 
     969                        ); 
     970                        $isPrimary = false; 
     971                } 
     972 
     973                return $categories; 
    974974        } 
    975975 
    976976 
     
    979979 
    980980                $this->escape($args); 
    981981 
    982           $post_ID     = $args[0]; 
    983           $user_login  = $args[1]; 
    984           $user_pass   = $args[2]; 
    985           $categories  = $args[3]; 
     982                $post_ID     = $args[0]; 
     983                $user_login  = $args[1]; 
     984                $user_pass   = $args[2]; 
     985                $categories  = $args[3]; 
    986986 
    987           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    988             return $this->error; 
    989           } 
     987                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     988                        return $this->error; 
     989                } 
    990990 
    991           set_current_user(0, $user_login); 
    992           if ( !current_user_can('edit_post', $post_ID) ) 
    993             return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
     991                set_current_user(0, $user_login); 
     992                if ( !current_user_can('edit_post', $post_ID) ) 
     993                        return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
    994994 
    995           foreach($categories as $cat) { 
    996             $catids[] = $cat['categoryId']; 
    997           } 
     995                foreach($categories as $cat) { 
     996                        $catids[] = $cat['categoryId']; 
     997                } 
    998998 
    999           wp_set_post_categories($post_ID, $catids); 
     999                wp_set_post_categories($post_ID, $catids); 
    10001000 
    1001           return true; 
     1001                return true; 
    10021002        } 
    10031003 
    10041004 
    10051005        /* mt.supportedMethods ...returns an array of methods supported by this server */ 
    10061006        function mt_supportedMethods($args) { 
    10071007 
    1008           $supported_methods = array(); 
    1009           foreach($this->methods as $key=>$value) { 
    1010             $supported_methods[] = $key; 
    1011           } 
     1008                $supported_methods = array(); 
     1009                foreach($this->methods as $key=>$value) { 
     1010                        $supported_methods[] = $key; 
     1011                } 
    10121012 
    1013           return $supported_methods; 
     1013                return $supported_methods; 
    10141014        } 
    10151015 
    10161016 
    10171017        /* mt.supportedTextFilters ...returns an empty array because we don't 
    1018           support per-post text filters yet */ 
     1018                support per-post text filters yet */ 
    10191019        function mt_supportedTextFilters($args) { 
    1020           return array(); 
     1020                return array(); 
    10211021        } 
    10221022 
    10231023 
    10241024        /* mt.getTrackbackPings ...returns trackbacks sent to a given post */ 
    10251025        function mt_getTrackbackPings($args) { 
    10261026 
    1027           global $wpdb; 
     1027                global $wpdb; 
    10281028 
    1029           $post_ID = intval($args); 
     1029                $post_ID = intval($args); 
    10301030 
    1031           $actual_post = wp_get_single_post($post_ID, ARRAY_A); 
     1031                $actual_post = wp_get_single_post($post_ID, ARRAY_A); 
    10321032 
    1033           if (!$actual_post) { 
    1034                 return new IXR_Error(404, 'Sorry, no such post.'); 
    1035           } 
     1033                if (!$actual_post) { 
     1034                        return new IXR_Error(404, 'Sorry, no such post.'); 
     1035                } 
    10361036 
    1037           $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID"); 
     1037                $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID"); 
    10381038 
    1039           if (!$comments) { 
    1040                 return array(); 
    1041           } 
     1039                if (!$comments) { 
     1040                        return array(); 
     1041                } 
    10421042 
    1043           $trackback_pings = array(); 
    1044           foreach($comments as $comment) { 
    1045             if ( 'trackback' == $comment->comment_type ) { 
    1046               $content = $comment->comment_content; 
    1047               $title = substr($content, 8, (strpos($content, '</strong>') - 8)); 
    1048               $trackback_pings[] = array( 
    1049                 'pingTitle' => $title, 
    1050                 'pingURL'   => $comment->comment_author_url, 
    1051                 'pingIP'    => $comment->comment_author_IP 
    1052               ); 
     1043                $trackback_pings = array(); 
     1044                foreach($comments as $comment) { 
     1045                        if ( 'trackback' == $comment->comment_type ) { 
     1046                                $content = $comment->comment_content; 
     1047                                $title = substr($content, 8, (strpos($content, '</strong>') - 8)); 
     1048                                $trackback_pings[] = array( 
     1049                                        'pingTitle' => $title, 
     1050                                        'pingURL'   => $comment->comment_author_url, 
     1051                                        'pingIP'    => $comment->comment_author_IP 
     1052                                ); 
    10531053                } 
    1054           } 
     1054                } 
    10551055 
    1056           return $trackback_pings; 
     1056                return $trackback_pings; 
    10571057        } 
    10581058 
    10591059 
     
    10621062 
    10631063                $this->escape($args); 
    10641064 
    1065           $post_ID     = $args[0]; 
    1066           $user_login  = $args[1]; 
    1067           $user_pass   = $args[2]; 
     1065                $post_ID     = $args[0]; 
     1066                $user_login  = $args[1]; 
     1067                $user_pass   = $args[2]; 
    10681068 
    1069           if (!$this->login_pass_ok($user_login, $user_pass)) { 
    1070             return $this->error; 
    1071           } 
     1069                if (!$this->login_pass_ok($user_login, $user_pass)) { 
     1070                        return $this->error; 
     1071                } 
    10721072 
    1073           set_current_user(0, $user_login); 
    1074           if ( !current_user_can('edit_post', $post_ID) ) 
    1075             return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
     1073                set_current_user(0, $user_login); 
     1074                if ( !current_user_can('edit_post', $post_ID) ) 
     1075                        return new IXR_Error(401, 'Sorry, you can not edit this post.'); 
    10761076 
    1077           $postdata = wp_get_single_post($post_ID,ARRAY_A); 
     1077                $postdata = wp_get_single_post($post_ID,ARRAY_A); 
    10781078 
    1079           $postdata['post_status'] = 'publish'; 
     1079                $postdata['post_status'] = 'publish'; 
    10801080 
    1081           // retain old cats 
    1082           $cats = wp_get_post_categories($post_ID); 
    1083           $postdata['post_category'] = $cats; 
     1081                // retain old cats 
     1082                $cats = wp_get_post_categories($post_ID); 
     1083                $postdata['post_category'] = $cats; 
    10841084                $this->escape($postdata); 
    10851085 
    1086           $result = wp_update_post($postdata); 
     1086                $result = wp_update_post($postdata); 
    10871087 
    1088           return $result; 
     1088                return $result; 
    10891089        } 
    10901090 
    10911091 
     
    10961096 
    10971097        /* pingback.ping gets a pingback and registers it */ 
    10981098        function pingback_ping($args) { 
    1099                 global $wpdb, $wp_version;  
     1099                global $wpdb, $wp_version; 
    11001100 
    11011101                $this->escape($args); 
    11021102 
     
    11131113                // Check if the page linked to is in our site 
    11141114                $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_settings('home'))); 
    11151115                if( !$pos1 ) 
    1116                         return new IXR_Error(0, 'Is there no link to us?'); 
     1116                                return new IXR_Error(0, 'Is there no link to us?'); 
    11171117 
    11181118                // let's find which post is linked to 
    11191119                // FIXME: does url_to_postid() cover all these cases already? 
     
    11471147                                $sql = "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE '$title'"; 
    11481148                                if (! ($post_ID = $wpdb->get_var($sql)) ) { 
    11491149                                        // returning unknown error '0' is better than die()ing 
    1150                                         return new IXR_Error(0, ''); 
     1150                                        return new IXR_Error(0, ''); 
    11511151                                } 
    11521152                                $way = 'from the fragment (title)'; 
    11531153                        } 
    11541154                } else { 
    11551155                        // TODO: Attempt to extract a post ID from the given URL 
    1156                         return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
     1156                        return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
    11571157                } 
    11581158                $post_ID = (int) $post_ID; 
    11591159 
     
    11631163                $post = get_post($post_ID); 
    11641164 
    11651165                if ( !$post ) // Post_ID not found 
    1166                         return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
     1166                        return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
    11671167 
    11681168                if ( $post_ID == url_to_postid($pagelinkedfrom) ) 
    11691169                        return new IXR_Error(0, 'The source URI and the target URI cannot both point to the same resource.'); 
    11701170 
    11711171                // Check if pings are on 
    11721172                if ( 'closed' == $post->ping_status ) 
    1173                         return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
     1173                        return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
    11741174 
    11751175                // Let's check that the remote site didn't already pingback this entry 
    11761176                $result = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_ID' AND comment_author_url = '$pagelinkedfrom'"); 
    11771177 
    11781178                if ( $wpdb->num_rows ) // We already have a Pingback from this URL 
    1179                         return new IXR_Error(48, 'The pingback has already been registered.'); 
     1179                        return new IXR_Error(48, 'The pingback has already been registered.'); 
    11801180 
    11811181                // very stupid, but gives time to the 'from' server to publish ! 
    11821182                sleep(1); 
     
    11841184                // Let's check the remote site 
    11851185                $linea = wp_remote_fopen( $pagelinkedfrom ); 
    11861186                if ( !$linea ) 
    1187                         return new IXR_Error(16, 'The source URI does not exist.'); 
     1187                        return new IXR_Error(16, 'The source URI does not exist.'); 
    11881188 
    11891189                // Work around bug in strip_tags(): 
    11901190                $linea = str_replace('<!DOC', '<DOC', $linea); 
     
    12441244 
    12451245 
    12461246        /* pingback.extensions.getPingbacks returns an array of URLs 
    1247            that pingbacked the given URL 
    1248            specs on http://www.aquarionics.com/misc/archives/blogite/0198.html */ 
     1247        that pingbacked the given URL 
     1248        specs on http://www.aquarionics.com/misc/archives/blogite/0198.html */ 
    12491249        function pingback_extensions_getPingbacks($args) { 
    12501250 
    12511251                global $wpdb; 
     
    12571257                $post_ID = url_to_postid($url); 
    12581258                if (!$post_ID) { 
    12591259                        // We aren't sure that the resource is available and/or pingback enabled 
    1260                         return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
     1260                        return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 
    12611261                } 
    12621262 
    12631263                $actual_post = wp_get_single_post($post_ID, ARRAY_A); 
    12641264 
    12651265                if (!$actual_post) { 
    12661266                        // No such post = resource not found 
    1267                         return new IXR_Error(32, 'The specified target URI does not exist.'); 
     1267                        return new IXR_Error(32, 'The specified target URI does not exist.'); 
    12681268                } 
    12691269 
    12701270                $comments = $wpdb->get_results("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = $post_ID");