juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

a social spider

juust | 24/01/2009

I was reading about the BloGee project and some other stuff and then I thought “how much trouble would it be writing a Wordpress plugin to do some basic ’social spidering’”. BloGee is about a micro-content format and that’s a bit out of my scope.

I want a simple ’social’ spider for Wordpress so I am going to take some functions of simpleTags and add them to the Wordpress xml-rpc server methods, to get some basic functionality I can call upon through the xml-rpc endpoint.

I don’t know if I mentioned that, adding methods to Wordpress XML-RPC differs from the straight forward use of Incutio because Wordpress uses its own filter/hook system, the actual IXR_Server instance is made and managed by Wordpress itself.

I hence don’t use the

  1. class PeekAtYouServer extends IXR_Server {

style class instancing, in stead I make a class where I hook the function I would normally hand to the IXR_Server as callback into wordpress by adding method/callback to the ‘xmlrpc_methods’ filter array.

  1.  class PeekAtYouServer {
  2.  
  3.   function PeekAtYouServer() {
  4.   //  add callbacks as methods to the array (filter) xmlrpc_methods
  5.    add_filter('xmlrpc_methods', array(&$this, 'filterXmlrpcMethods'));
  6.   }
  7.  
  8.   /**
  9.    * Here I connect the methodName pay.PeekAtYou to a custom function
  10.    *
  11.    * This is the array that is added (as pair) to the xmlrpc_methods filter
  12.    **/
  13.  
  14.   function filterXmlrpcMethods(&$methods) {
  15.    $methods['pay.PeekAtYou'] = array(&$this, 'onXmlRpcpayPeekAtYou');
  16.    return $methods;
  17.   }
  18.  
  19.   /**
  20.    * the custom function used as callback for pay.PeekAtYou
  21.    **/
  22.  
  23.   function onXmlRpcpayPeekAtYou($args) {
  24.     global $wpdb;
  25. //grab posts
  26.     $sql = "SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_status = 'publish'";
  27.     $posts = $wpdb->get_results($sql);
  28. //cycle through all posts and grab the IDs
  29.  
  30.     $result = array();
  31.     if (!empty($posts)) {
  32.      foreach ($posts as $post) $this->postids[] = $post->ID;
  33. //I got all the ids in an array,
  34. //now I grab the tags (query is from the simpleTags plugin)
  35.      $this->getTagsFromCurrentPosts();
  36.     } else {
  37.      return new IXR_Error(404, 'no posts for the selected criterium.');
  38.     }
  39.     return $this->tags_currentposts;
  40.   }
  41.  
  42.  /**
  43.   * Get tags from current post views
  44.   * (SimpleTags plugin)
  45.   * @return boolean
  46.   */
  47.  function getTagsFromCurrentPosts() {
  48.   if ( is_array($this->postids) && count($this->postids) > 0 ) {
  49.  
  50.    // Generate SQL from post id
  51.    $postlist = implode( "', '", $this->postids);
  52.  
  53.    global $wpdb;
  54.    $results = $wpdb->get_results("
  55.    SELECT t.name AS name, t.term_id AS term_id, tt.count AS count
  56.    FROM {$wpdb->term_relationships} AS tr
  57.    INNER JOIN {$wpdb->term_taxonomy} AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
  58.    INNER JOIN {$wpdb->terms} AS t ON (tt.term_id = t.term_id)
  59.    WHERE tt.taxonomy = 'post_tag'
  60.    AND ( tr.object_id IN ('{$postlist}') )
  61.    GROUP BY t.term_id
  62.    ORDER BY tt.count DESC");
  63.  
  64.    $this->tags_currentposts = $results;
  65.    unset($results, $key);
  66.   }
  67.   return true;
  68.  }
  69.  }

I saved the file as PeekAtYouServer.class.php.

Now I need a simple file for Wordpress to ’spot the plugin’, so I can activate it and make the class instance, that adds the custom method and callback function.

  1.  /*
  2.  Plugin Name: PeekAtYou XMLRPC Server
  3.  Plugin URI: http://www.juust.org/
  4.  Description: Adds Social Spidering to your blog
  5.  Author: juust
  6.  Author URI: http://www.juust.org/
  7.  License: GPL
  8.  Version: 1.1
  9.  */
  10.  
  11.  require_once 'PeekAtYouServer.class.php';
  12.  $PeekAtYouServer = new PeekAtYouServer();

I save that as PeekAtYouServer.php and upload the lot to a directory /wp-plugins/pay-xmlrpc-server.

In the Plugin screen (wp 2.5) I can activate the plugin, and then make a call to the xmlrpc-endpoint of the blog using pay.PeekAtYou as methodName.

  1.  include('wp-includes/class-IXR.php');
  2.         $client = new IXR_Client('http://www.juust.org/xmlrpc.php');
  3.  $client->query('pay.PeekAtYou');
  4.  $response = &$client->getResponse();
  5.  print_r( $response);

That returns all tags the blog uses.

Next week : adding some basic social blog-spider functions.

Categories
wordpress, xml-rpc
Tags
wordpress, xml-rpc
Comments rss
Comments rss
Trackback
Trackback

« hands on xml-rpc : copying msql tables work »

One Response to “a social spider”

  1. fjbnheipsssf says:
    31/01/2009 at 9:31 pm

    fjbnheipsssf…

    Anyway, you should do your best ;)…

    Reply

Leave a Reply

Click here to cancel reply.

Recent Posts

  • geert wilders
  • gone till september
  • socialize me
  • Pagerank sculpting session
  • wish you were here

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
22260 confirmed spam kills