topical media & game development

talk show tell print

mashup-delicious-08-autoposter-autoposter.php / php



  <?php
  //del.icio.us account information
  define('DELICIOUS_USERNAME','username');
  define('DELICIOUS_PASSWORD','password');
  
  //wordpress information
  define('WP_USERNAME','admin');
  define('WP_PASSWORD','password');
  define('WP_XMLRPC_HOST','localhost');
  define('WP_XMLRPC_URL','/wordpress/xmlrpc.php');
  
  //bring in Snoopy goodness
  include('lib/Snoopy.class.php');
  //get rid of error Notices because Snoopy produces some
  error_reporting(E_ERROR | E_WARNING | E_PARSE);
  
  //bring in xml-rpc for php
  include('lib/xmlrpc.inc');
  
  //bring in the del.icio.us Mashups PHP library made ealrier
  include('lib/delicious_mashups.inc.php');
  //get yesterday's date in CCYY-MM-DD
  yesterday = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
  
  //set up a log and html post content variable
  log = "yesterday autoposter.php:";
  post_content = "";
  
  //grab yesterday's bookmarks via the del.icio.us API
  do_api_call("/posts/get?","&dt=yesterday");
  
  //make sure the api return status code is 200 before moving on
  if (api_return['status'] == 200) {
      //make sure we have some posts
      if (isset(api_return[0]['children'])) {
          //create the list of links
          posts = api_return[0]['children'];
          post_content .= "<ul>";
          foreach (posts as post)
          {
              post_content .= "<li><a href=\"".post['attributes']['HREF']."\">".post['attributes']['DESCRIPTION']."</a></li>";
              if (isset(post['attributes']['EXTENDED']))
                  post_content .= "<p>".post['attributes']['EXTENDED']."</p>";
          }
          post_content .= "</ul>";
      } else {
          //no bookmarks for today
          post_content .= 
             "<em>Sorry, but I didn't save any bookmarks to del.icio.us today.</em>";
      }
  
      //create the xml-rpc client object
      client = new xmlrpc_client(WP_XMLRPC_URL,WP_XMLRPC_HOST,80);
  
      //create an array for our post data
      post = array();
      post['title' ]= "del.icio.us links for today";
      post['description'] = post_content;
  
      //assemble the xml-rpc message
      paramaters = array(
                  php_xmlrpc_encode("1"),
                  php_xmlrpc_encode(WP_USERNAME),
                  php_xmlrpc_encode(WP_PASSWORD),
                  php_xmlrpc_encode(post),
                  php_xmlrpc_encode("1")
              );
      message = new xmlrpcmsg("metaWeblog.newPost",paramaters);
  
      //what do we want our response to be?
      client->return_type = 'phpvals';
  
      //send the XML-RPC message to the server
      response = client->send(message);
      
      //check the response to make sure all went well
      if (response->errstr != '')
          log .= " XML-RPC CALL FAILED - ".response->errstr;
      else
          log .= " success";
  } else {
      log .= 
          " DEL.ICIO.US API CALL FAILED - status code was ".api_return['status'];
  }
  
  //output log to screen
  echo log;
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.