Oct 29

Good news for Blogger Beta users, now Ngeblog can be used to manipulate your blog entry. :)

If you’re using previous version of Ngeblog, don’t worry, you still can use all the methods as before, only now you can do more. Especially if you’re using Blogger in beta version.

As usual, i’m going to blab on a bit about this newest version, so if you can’t wait any longer to play around with it (i know some of you are like that) just go here and try it out yourself.

Ok, here are some additional features in Ngeblog 0.1 :

ClientLogin Authentication

As clearly stated in Blogger Data API documentation, now ClientLogin authentication can be used for both versions of Blogger. That surely makes our lives easier.

Unfortunately, previous version of Ngeblog still used BasicAuth for its authentication method, which is only valid for current version of Blogger, not for Blogger currently in beta . That’s why you need to download Ngeblog ver. 0.1 to be able to access Blogger in Beta version.

In implementation case, there’s nothing new in Ngeblog. You put some parameters (username and password) in constructor to connect to Blogger, like this:

<?php

  $username = "yourusername";
  $password = "yourpassword";

  $myblog = new Ngeblog($username,$password);
  $bloginfo = $myblog->getBlogInfo();
  print_r($bloginfo);

?>

Only now, Ngeblog will try to detect whether you’re trying to connect to current version of Blogger or beta version. And all authentication is done using Google ClientLogin method.

Multiple Blogs Shorthand

As i mentioned in previous post, Blogger allows you to have more than one blog per account, and each blog has its own Blog ID. Ngeblog supports multiple blogs access by defining which blog ID are you trying to access.

Thanks to Bill, now you don’t have to carry Blog ID in all methods like before, you just need to define it once in constructor, like this:

  $username = "yourusername";
  $password = "yourpassword";
  $blogid   = "81928938";

  $myblog = new Ngeblog($username,$password,$blogid);

then the rest of methods will assume you’re manipulating blog ID 81928938 without having to define it in all methods. For example to add new post, you just have to write something like this,

  $title   = "My Title";
  $content = "My content for this blog";

  $myblog->newPost($title,$content);

If you need to switch to another blog in the middle of your scripts, use setActiveBlog() method, like this:

  $anotherblogid  = "84748478";
  $anothertitle   = "My Title for another blog";
  $anothercontent = "My content for another blog";

  $myblog->setActiveBlog($anotherblogid);
  $myblog->newPost($anothertitle,$anothercontent);

Tester

Enough talks, if you still can’t understand what i’m talking about here, check out the tester here, i build it with Ngeblog 0.1. Just enter your username and password whether for current version or beta version of Blogger.

Oct 22

What is Ngeblog? A nice guy from phpclasses has made great description for me,

This class can be used to manipulate Blogger blogs using the GData, the Google Data API.

You can download the newest files here. I included some example files there.

There are some dramatic changes i made for this version, including methodes naming and code beautification. Hopefully, with this new codes, it will be easy to extends it in the future.

So, if you happened to use the older version, you should make some changes too. Here are the newest howto's,

Get an entry

<?php

  require_once "Ngeblog.php";
  
  $myblog = new Ngeblog("yourusername","yourpassword");
  
  $entryid = 116086097264268587;  // entry ID you want to get
  $res = $my blog->getPost($entryid);
  
  echo "<pre>";
  print_r($res);
  echo "</pre>";
  
?>

Get list of entries

<?php

  require_once "Ngeblog.php";
  
  $myblog = new Ngeblog("yourusername","yourpassword");
  
  $res = $myblog->getPosts(1,5);  // this will get five entries from first index
  
  echo "<pre>";
  print_r($res);
  echo "</pre>";
  
?>

Post a new entry

<?php

  require_once "Ngeblog.php";
  
  $myblog = new Ngeblog("yourusername","yourpassword");
  
  $title  = "This is my title";
  $msg    = "<p>This is your <i>content</i></p>";
  
  if ( $myblog->newPost($title,$msg) ) {
    echo "posting success";
  } else {
    echo "posting failed";
  }
  
?>

Delete an entry

<?php

  require_once 'Ngeblog.php';
  
  $myblog = new Ngeblog("yourusername","yourpassword");
  
  $entryid = '116086019043835900'; // the entry id to be deleted
  
  if ( $myblog->deletePost($entryid) ) {
    echo "The entry with id $entryid has been deleted";
  }
  
?>

Update an entry

<?php

  require_once "Ngeblog.php";
  
  $myblog = new Ngeblog("yourusername","yourpassword");
  
  $entryid  = "116148936968661097"; // entry ID you want to update
  $newtitle    = "My New Title";
  $newmsg      = "<p>This is your <i>content</i></p>";
  
  if ( $myblog->editPost($entryid,$newtitle,$newmsg) ) {
    echo "Updating entry $entryid success";
  } else {
    echo "Updating failed";
  }
  
?>

Oct 18

As most of you might have known, Joshua Eichorn, author of Understanding AJAX, has written a cool web service called "Webthumb". Its a nice web app that captures a website and turn it into an image thumbnail.

There are many reasons why we need to create such web thumbnail, Cal Evans mentioned some of them,

  • Graphic Designers can use it to create thumbnails of their work for archival purposes.
  • You may want to create a history of a web page to show it's progress.
  • Since Amazon is now charging for Alexa's thumbnail service, you may want to create thumbnails of sites you are talking about on your blog.

He also has made a nice wrapper for us, in PHP off course, made our live easier. You can try it out yourself for free, just download the source in his website here. But you're going to need API Key for that, just take some simple registration steps here, and you can use the web service to create your web thumbnail up to 250 times a month.

I know, some of you perhaps more interesting in trying it now than go to some websites to see how it really works. That's why i made this simple script just for you. Just enter the URL website you'd like to capture and your own API Key. Then again, if you're too lazy to get the API key, just use mine, here (if it failed then it might have over quote, sorry):

5b3e41f00ba60aabf3f1e81d8eec12c5






Oct 16

So, couple days ago, i found this nice Perl script to solve TextTwist games in Priyadi’s blog. And i said to myself, “hmm, i think i can make it too in PHP”. So here you go,

<?php

  function yatts($words)
  {
    $pspell_link = pspell_new("en");

    $aword=str_split($words);
    $length = count($aword);

    $res=array();
    for ( $sublength=3;$sublength<$length;$sublength++ )
    {
      for ( $k=1,$max=1;$k<=$length;$k++ )
        $max=$k*$max;

      for ($a=1; $a<($length+1); $a++) {
        $options[$a] = $pattern[$a] = $a;
      }

      for ($x=0; $x<$max; $x++)
      {
        $N = $x;
        for ($i=1; $i<= $length;) {
          $pattern[($length+1-$i)] = $N % $i;
          $N = $N/$i;
          $i++;
        } 

        unset($perm);
        $b = $options;

        foreach($pattern as $offset) {
          list($char) = array_splice($b, $offset, 1);
          $perm[] = $char;
        } 

        $m = array_slice($perm, 0, $sublength);   

        $jj='';
        foreach ( $m as $v )
          $jj.=$aword[$v-1];

        if ( !in_array($jj,$res) ) {
          if ( pspell_check($pspell_link,$jj) ) {
            $res[]=$jj;
          }
        }
      }
    }

    return $res;
  }

?>

All you have to do is write something like this,

<?php

  $res = yatts('ltorslt');
  echo implode(' ',$res);

?>

where “lorstl” is the letters presented in the game, and the output would be,

lot tor tot ors rot sol sot lots lost toll tors tort tots trot roll
rots slot sort tolls torts troll trots rolls trolls stroll

Yep, grab one and make scores. :)

Notes:

  • To make this script works you need to compile PHP with pspell support. Read the manual for that.
  • You also need to install Aspell program and its english dictionary, get it here.
  • For windows user, you’re going to need dos2unix program for windows. Somehow, some Aspell binary files can not be read because it’s in DOS format. Just type this in your DOS-prompt,
    C:\Program Files\Aspell\data> dos2unix iso8859-1.dat
    C:\Program Files\Aspell\data> dos2unix standard.kbd
Oct 14

If you were like me, you wanted to be able to access Blogger using your own interface. Unfortunately, many Blogger API’s out there still using Atom API, which will be deprecated soon. Google plans to change it using Blogger GData API.

What is Blogger GData API? This is what the guidelines said,

The Blogger data API allows client applications to view and update Blogger content in the form of Google data API (”GData”) feeds. Your client application can use GData to create new blog posts, edit or delete existing posts, and query for posts that match particular criteria.

I will show you how to do that with PHP, using curl and simpleXML functions. So, make sure you have them installed in your PHP.

Continue reading »

Oct 11

I don’t know when it started, but i’ve just found out someone has cute custom logo generator here. From its subdomain (tst4php) i guess he used PHP for this. I wouldn’t surprise.

Cute isn’t it?

ngoprekYahoo

ngoprekwebGoogie