Make WordPress Core

Changeset 1568


Ignore:
Timestamp:
08/27/2004 08:46:24 AM (20 years ago)
Author:
michelvaldrighi
Message:

added mw.newMediaObject (not tested yet), fixed local/gmt dates confusion, removed debug edits, ate an apple too and taught a coworker how to use our espresso machine (it only takes a button to press)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r1565 r1568  
    1414$post_default_category = 1; // posts submitted via the xmlrpc interface go into that category
    1515
    16 $xmlrpc_logging = 1;
     16$xmlrpc_logging = 0;
    1717
    1818function logIO($io,$msg) {
     
    3535logIO("I", $HTTP_RAW_POST_DATA);
    3636
    37 function printr ( $var, $do_not_echo = false )
    38 {
    39    ob_start();
    40    print_r($var);
    41    $code =  htmlentities(ob_get_contents());
    42    ob_clean();
    43    if ( !$do_not_echo )
    44    {
    45        echo "<pre>$code</pre>";
    46    }
    47    return $code;
     37function printr($var, $do_not_echo = false) {
     38    // from php.net/print_r user contributed notes
     39    ob_start();
     40    print_r($var);
     41    $code =  htmlentities(ob_get_contents());
     42    ob_clean();
     43    if (!$do_not_echo) {
     44      echo "<pre>$code</pre>";
     45    }
     46    return $code;
    4847}
    4948
     
    6766          'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
    6867          'metaWeblog.getCategories' => 'this:mw_getCategories',
     68          'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
    6969
    7070          'demo.sayHello' => 'this:sayHello',
     
    170170      $struct = array(
    171171        'userid'    => $post_data['post_author'],
    172         'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s\Z', $post_data['post_date_gmt'])),
     172        'dateCreated' => new IXR_Date(mysql2date('Ymd\TH:i:s', $post_data['post_date'])),
    173173        'content'     => $content,
    174174        'postid'  => $post_data['ID']
     
    202202      foreach ($posts_list as $entry) {
    203203     
    204         $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
     204        $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
    205205        $categories = implode(',', wp_get_post_cats(1, $entry['ID']));
    206206
     
    478478
    479479      $catnames = $content_struct['categories'];
    480       // FIXME: commented until a fix to print_r is found: logio('O', 'Post cats: ' . print_r($catnames,true));
    481       //logio('O', 'Post cats: ' . printr($catnames,true));
     480      logio('O', 'Post cats: ' . printr($catnames,true));
    482481      $post_category = array();
    483482
     
    595594      if ($postdata['post_date'] != '') {
    596595
    597         $post_date = mysql2date('Ymd\TH:i:s\Z', $postdata['post_date_gmt']);
     596        $post_date = mysql2date('Ymd\TH:i:s', $postdata['post_date']);
    598597
    599598        $categories = array();
     
    653652      foreach ($posts_list as $entry) {
    654653     
    655         $post_date = mysql2date('Ymd\TH:i:s\Z', $entry['post_date_gmt']);
     654        $post_date = mysql2date('Ymd\TH:i:s', $entry['post_date']);
    656655        $categories = array();
    657656        $catids = wp_get_post_cats('', $entry['ID']);
     
    724723    }
    725724
     725
     726    /* metaweblog.newMediaObject uploads a file, following your settings */
     727    function mw_newMediaObject($args) {
     728      // adapted from a patch by Johann Richard
     729      // http://mycvs.org/archives/2004/06/30/file-upload-to-wordpress-in-ecto/
     730
     731      $blog_ID     = $args[0];
     732      $user_login  = $args[1];
     733      $user_pass   = $args[2];
     734      $data        = $args[3];
     735
     736      $name = $data['name'];
     737      $type = $data['type'];
     738      $bits = $data['bits'];
     739
     740      $file_realpath = get_settings('fileupload_realpath');
     741      $file_url = get_settings('fileupload_url');
     742
     743      if (!$this->login_pass_ok($user_login, $user_pass)) {
     744        return $this->error;
     745      }
     746
     747      $user_data = get_userdatabylogin($user_login);
     748
     749      if(!get_settings('use_fileupload')) {
     750        // Uploads not allowed
     751        logIO('O', '(MW) Uploads not allowed');
     752        $this->error = new IXR_Error(405, 'No uploads allowed for this site.');
     753        return $this->error;
     754      }
     755
     756      if(get_settings('fileupload_minlevel') > $userlevel) {
     757        // User has not enough privileges
     758        logIO('O', '(MW) Not enough privilege: user level too low');
     759        $this->error = new IXR_Error(401, 'You are not allowed to upload files to this site.');
     760        return $this->error;
     761      }
     762
     763      if(trim($file_realpath) == '' || trim($file_url) == '' ) {
     764        // WordPress is not correctly configured
     765        logIO('O', '(MW) Bad configuration. Real/URL path not defined');
     766        $this->error = new IXR_Error(500, 'Please configure WordPress with valid paths for file upload.');
     767        return $this->error;
     768      }
     769
     770      $prefix = '/';
     771
     772      if(!strlen(trim($name))) {
     773        // Create the path
     774        $localpath = $file_realpath.$prefix.$name;
     775        $url = $file_url.$prefix.$name;
     776
     777        /* encode & write data (binary) */
     778        $ifp = fopen($localpath, 'wb');
     779        $success = fwrite($ifp, $bits);
     780        fclose($ifp);
     781        @chmod($localpath, 0666);
     782
     783        if( $success ) {
     784          $resp = array($url);
     785          return $resp;
     786        } else {
     787          logIO('O', '(MW) Could not write file '.$name.' to '.$localpath);
     788          return new IXR_Error(500, 'Could not write file '.$name.' to '.$localpath);
     789        }
     790      }
     791    }
     792
    726793}
    727794
Note: See TracChangeset for help on using the changeset viewer.