Skip to content


The Google Buzz API with PHP and SimplePie, a.k.a Just ATOM Feeds

Alright, first to get some things clear before I get a super super ass load of dick head responses about how this could be better, this is an intro! Here is what I have done. I have created a small script that gets my Buzz; this script will eventually include all of the functions of the Google Buzz API, or at least most of them. For now it includes what I have, minus a few things. They are sending me all the enclosures, but I am going to go ahead and just use SimplePie’s get_enclosures() method and calling it good. The reason why is that you should research your own implmentations, that and I am too lazy to perfect this because without the location, search functionality, or a complete understanding of PubSubHubBub (PuSH) I don’t feel the need to spend my time on perfecting it or doing anything more than an intro to it.

To get a few things straight, ease up on Google Buzz. I am not a spokesmen, salesmen, or in anyway paid to promote Buzz at all. I am only trying to give them a chance. If you are a web developer and you don’t like Google Buzz, you are not paying attention. Google Buzz, while it might be arguabaly commercial, is the bet attempt and including some great standard into the major web offerings ever. Google Buzz’s API page lists the standard that they have deicded are the futures. Some of them are exciting, others are just so-so. In my opinion the two that are the most exciting, and should be implemented as a standard, are Activity Streams and of course PubHubSubBub (not PubSubHubBub :) ). These are the future I think, I could be wrong and so could Google but these are great ideas and should be supported and explored by us all. I am sure someone will point out some point that will make me look like a Google fan boy and mention funding, etc… from Google. Well I don’t care, ask yourself if you had the money to waste and knew something was a great idea would you not throw some money as research and development too?

Sooooooo, ok, lets get started on it and get some basics out of the way. To prepare we need a few standard things, these should be kind of obvious from the title but here goes:

  1. Download SimplePie – http://github.com/rmccue/simplepie/downloads
  2. (optional) Check out the SimplePie Developer Wishlists :) at http://bit.ly/9sZc9L or http://bit.ly/9YAjD7 or http://bit.ly/9CCsuG
  3. Alright we got the SimplePie class and we have thanked the developers, really, at least tweet that you use their awesome library!
  4. In all fairness, if I haven’t done good enough so far, you should read at least some of the SimplePie documentation. I will go ahead and be the first to say I haven’t read all of it. I have read what I needed and also checked out their tutorials. All I have to say is that they have done an excellent job, only on a few occasions have I not been able to find what I want, so go read it and see what you learn. You will be amazed at what SimplePie does that you would never imagine that these guys would have thought of.
  5. Go ahead and start a new *.php(name it whatever you want) file and open the php tags and include SimplePie <?php include('/classes/SimplePie.class.php'); ?>
  6. There is a standard opening of the feed for SimplePie, it goes as follows and it will basically create your new object instance and let it know which feed to read. Make sure to replace the {username} tag with your username, or anyone else you would like to feature with Buzz
    • $feed_url = 'http://buzz.googleapis.com/feeds/{username}/public/posted';
      $feed = new <a href="http://simplepie.org/" title="SimplePie">SimplePie</a>();
      $feed->set_feed_url($feed_url);
      $feed->set_cache_duration($cacheDuration);
      $feed->init();
      
  7. In a standard SimplePie way you need to check for a feed error before we move on to parsing the Google Buzz feed
    • if($feed->error())
      {
          echo '<div class="error">' . $feed->error() . '</p>';
      }
      
  8. Now if we don’t have an error we can look for some content. If you read the SimplePie documentation like I mentioned earlier then you know a few of the commands that we will be using here. If you haven’t read the documentation then go do it. I know that a lot of peeps like to copy-paste their way through life, but really bear with me and try to understand this one. SimplePie is useful in almost any site and I need to spend more time with it too so go read those docs.
    • echo '<a href="' . $item->get_link() . '">' . $item->get_title() . '</a>';
  9. So now we have printed out an anchor tag with and title from each Buzz from the user and also the right link to that Buzz post. Next we need to handle if their are any media elements we should display. This is one of the things that I have skimped on a bit. I really haven’t perfected this because they are using the Yahoo Media RSS namespace and I don’t want to get into this yet. It is simple actually and I might do another post on it, or if you want to post a comment on the code go ahead. I just want to get the basics out of the way. So for now lets use SimplePie and just print out the enclosure links. I know that this will print out each enclosure twice, remember that this is just the beginning.
    • if($item->get_enclosures())
      {
          echo '<br /><h3>Enclosures</h3><br />';
          foreach($item->get_enclosures() as $enclosure)
          {
              echo "<p>" . $enclosure->get_link() . "</p>";
          }
      }
      
  10. The next part is one of the more interesting parts of SimplePie to me, I said these guys thought of everything! The developers put in a way to get namespace elements from other feed namespaces if you specify the namespace. Well really you don’t even have to specify any namespace at all! You can just use this function to get things from RSS feeds as you need them. So using the get_item_tags() method we can get any namespaced, or not, element we want. In this case we are going to use the purl.org thread namespace to get the number of replies to the original Buzz.
    • $total = $item->get_item_tags('http://purl.org/syndication/thread/1.0', 'total');
  11. So now we have that number we can use that to run our next conditional and see if we need to even try to fetch some comments.
    • if($total[0]['data'] > 0)
  12. So if that exists we need to get replies. I haven’t reall polished the reply fetching yet, and I don’t plan to anytime soon. You can do that part yourself! Well now we have the basics to actually start parsing the feed. I have some things that I haven’t included here yet. So below is the entire code of a sample page that I created to test the parsing of the Google Buzz response. It is really simple and basic. Don’t flame me for simplicity, realize that some people need to see it in this manner to get started.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <title>Buzz Test</title>
            <style type="text/css" media="screen">
                div.item {
                  background: #efefef;
                  border: 2px solid #333;
                  margin-bottom: 20px;
                }
                div#wrapper {
                    width: 960px
                }
            </style>
        </head>
        <body>
            <?php include('/classes/SimplePie.class.php'); //Include the SimplePie Library ?>
            <div id="wrapper">
                <?php
                    $feed_url = 'http://buzz.googleapis.com/feeds/{username}/public/posted';
                    $feed = new SimplePie();
                    $feed->set_feed_url($feed_url);
                    $feed->set_cache_duration($cacheDuration);
                    $feed->init();

                    if($feed->error())
                    {
                        echo '<div class="error">' . $feed->error() . '</p>';
                    }
                    else
                    {
                        foreach($feed->get_items() as $item)
                        {
                            echo "<div class='item'><ul>";
                            echo '<li><a href="' . $item->get_link() . '">' . $item->get_title() . '</a></li>';
                            echo '<li>' . $item->get_date() . '</li>';
                            echo '<li>' . $item->get_content() . '</li>';
                            if($item->get_enclosures())
                            {
                                echo '<h3>Media</h3>';
                                foreach($item->get_enclosures() as $enclosure)
                                {
                                    echo '<li>' . $enclosure->get_link() . '</li>';
                                }
                            }
                            $total = $item->get_item_tags('http://purl.org/syndication/thread/1.0', 'total');
                            if($total[0]['data'] > 0)
                            {
                                $links = $item->get_item_tags('http://www.w3.org/2005/Atom', 'link');
                                foreach($links as $link)
                                {
                                    if($link['attribs']['']['rel'] == 'replies')
                                    {
                                        $replyFeed = new SimplePie();
                                        $replyFeed->set_feed_url($link['attribs']['']['href']);
                                        $replyFeed->set_cache_duration($cacheDuration);
                                        $replyFeed->init();

                                        if($replyFeed->error())
                                        {
                                            echo '<p>' . $replyFeed->error() . '</p>';
                                        }
                                        else
                                        {
                                            echo '<h3>Replies</h3>';
                                            foreach($replyFeed->get_items() as $replyItem)
                                            {
                                                echo '<li>' . $replyItem->get_content() . '</li>';
                                            }
                                        }
                                    }
                                }
                            }
                            echo "</div></ul>";
                        }
                    }
                ?>
            </div>
        </body>
    </html>

That code is gross, well at least it is to me. You can use way more xhtml and way less php echos which will increase your readability a whole lot! This is a very basic intro, so enjoy it, play with it, change it, see what you can get! If you have any questions then please post your code and what you need to know and I’ll see if I can help at all. If I can’t then maybe a reader can.

Posted in Code, PHP. Tagged with , , , .

How to Spot a Web Designer You Shouldn’t Hire

They have this anywhere on their page, I also have linked this to one of the best sites ever.

artmail

Posted in Other.

Using the Right Words when it Comes to Twestivals

Twitter doesn’t allow me enough space to even begin to start with this one. First of all lets go down the list on a few terms here.

Twestival – A event held by a city using twitter to organize it and come together for the good of a charity.
SFTwestival – The actual City that is having a Twestival, in this example San Francisco.
DNALounge – Venue in SF that claims to have lost money due to SFTwestival

Twestival is a the main organization, they setup and provide space for cities to have their own blogs to post information to they also initially had the idea for Twestivals. DNALounge is having a dispute with SFTwestival over the venue and mixups. Everyone should be clear in their tweets that this is not Twestival as a whole or any other cities fault. The use of Twestival in general and tweets such as “Twestival Sucks” or “F#$% Twestival” only hurt other cities and a lot of really good charities.

Make sure if you are tweeting things about these disputes that you use the right names when you tweet so you don’t do damage to these other cities that have worked very hard to try to raise as much money as possible for their areas.

If DNALounge wanted Twestival to mediate a discussion between them and the San Francisco team then they should of asked them to and also made to sure to have their facts straight from the get go. The amount of negative tweets that went around may have already done damage due to not actually understanding the whole situation before getting everyone riled up.

I am not saying either side is definitely right or that I am siding with either one. I am saying make sure to think about what you are saying and how it effects other people before putting it out there.

Posted in Other. Tagged with , , .

Best Spam Ever…

This makes no sense

I have seen plenty of funny spam messages, but it was as if this one tried to make sense. Spousal Funt Lamp Grogery for those of you who know.

Posted in Other.

New Update to Picora

All right, I recently posted some info about Picora and I had my own bitches and gripes as usual. I am one of the few who prefer their frameworks to actually be Rails clones. Sue me, I liked Rails and just hated deploying it! Either way, a friend of mine Chris Pittman has posted some interesting news over at his page. Lets get started with some skinny.

Chris is probably, apart from the developers, the leading source of info when it comes to Picora. While Picora might be dead in the water as a project it is actually one of only two, that I know of, PHP 5 only MVC frameworks. Chris has done some pretty amazing things with the framework and has now released some code that while it is unsupported and young might still be useful to some people out there.

Chris has released code to help generate scaffolding in Picora. For peeps that have been using other frameworks this might be extremely useful for you. I used scaffolding in Rails but never used it in Code Igniter, although i did use it to some extent with Cake. Either way, head on over and get some scaffolding code and probably the only available copy of the Picora framework, since their site has been down for quite some time now.

Also keep a look out on Chris‘ blog as their might be some good info on Picora over there. I know i promised to post some info but I have been deep into getting my mind back in the C mode and working with Objective-C. I can promise that i am definitely rusty when it comes to memory management, spoiled by the PHP i guess :) . So keep checking his blog for info and maybe someday I will get around to writing the tutorials that i promised.

Posted in Other.

HDR Chair and Toys




DHchaiR

Originally uploaded by LokNessMobster

Been trying a little bit lately to get into doing some nice photography work. Unfortunately a short period into it I found something difficult and time consuming that is slowly becoming the coolest thing in the world to me, HDR. HDR stands for High Dynamic Range and it is cool as hell. For examples of peeps who actually know what they are doing please look into the following.

http://www.stuckincustoms.com/hdr-tutorial/
http://www.vanilladays.com/hdr-guide/
http://www.photoshopcafe.com/tutorials/HDR_ps/hdr-ps.htm

Those also, coincidentally, double as tutorials to learn. I am still reading as many as I can find. But posting this to show the first one I have completed that I actually like, it is not as obviously HDR as I wanted but I like the picture and wanted to post it up.

Posted in Other.

Asheville Twestival, what the hell is that?

Well I will tell you what the hell it is, it is awesome. It is awesome * infinity * infinity. So getting away from vague dumbass answers it is a charity event that over one hundred cities nationwide are participating in to raise money for charity. But we don’t care about the other cities, we care about Asheville so here is the rundown. Asheville is raising money to give to www.charitywater.org go over there and read about them since they obviously will explain it better than me.

On top of having an actual fundraiser featuring one dollar beers, more on that later, there are also other small functions going on and they are going on soon too so you have to get up and get going now. The first event will be at Pritchard Park in downtown Asheville. For a little bit o cash you get to make your own short video spot that will make you famous for being so generous and awesome. You will be some famously awesome you will win chicks, or dudes, or both!

What’s that? I mentioned cheap, good, beer? Yeah I did, Windows at the Park will be the venue for the Twestival and there will be  a 10 dollar donation to get in but after you are in you will be able to drink beer for a dollar a beer and Bruising Ales will be supplying that beer. So on top of it being cheap beer, money wise, it is good beer. You can’t lose with showing up for this one. But that would be pretty boring just standing around drinking cheap, good beer at Windows with peeps, or tweets, you don’t know. So to help out with that we have some live music happening also. The music will be a range of styles so if you don’t like the first band, suck it up and wait for the next one, which you will love more than anything. To help raise some money there will be a silent auction also at the fundraiser.

So that is about it for that, make sure to head over to asheville.twestival.com to read more details on the events and what is going on and also make sure to come out to these fundraisers, it is for an awesome cause and you really are a jerk if you don’t show up. If you have an opinion on that statement then come to the fundraiser and we can talk it over in person! Just make sure to donate some extra cash before we talk.

Buy These Books!

Posted in Other. Tagged with , , , .

What frameworks are for and why some are better than others

I posted earlier tonight about installing and setting up Picora and I also mentioned that I would probably write a few tutorials and doing something basic with it. I am going to write these tutorials so people will have the option of using Picora if they like. I personally don’t really think that this would be my choice for a few reasons. First of all their website is place holder, which in terms of the web and applications means you will end up supporting the framework as if it were your own. Chances are in a year, if that long, it won’t even have that placeholder. You will just see some girl holding her bookbag and a guy dancing because he got a lower mortgage payment. I could be wrong but I have called it before. On another note if less than one hour after I post a blog entry on how to install and get Picora running I am #1 in Google for “Picora Install” or “How to Install Picora” then their own documentation obviously is horrible, or rather it is nonexistent. If you are going to go the route of supporting dead frameworks then why not just build your own? If you are interested then take a look at this.

Second of all, a lot of the options available in their classes look kind of thrown together or somewhat copied over from CI. In fact I just spent the last two hour avoiding using their ActiveRecord class because I see no need for it. I would rather define my own Application Model class with my own functions to handle a few things, if I even need that, and then extend it in my models. So what I am saying is that there are a lot of frameworks out there, most people won’t know what you use either so don’t go for the hardest crap just to be L337. The point of a framework is to SAVE you time not steal it from you slowly.

So if a framework is supposed to save you time and make your life easier then, in my opinion, the most important things it can have are the following:

  1. A great community such as the one at any of the CakePHP sites or IRC Channels
  2. Awesome documentation, CodeIgniter wins this one. No one can even begin to mess with CI Docs
  3. Extensibility, you should be able to extend and improve every part of the framework in a standardized manner. i.e. Plugins or Modules

Because of the way I see frameworks and development I think that the best choice for those who want loose structure that is not required then go with CodeIgniter. If you need help constantly and know that you will need others to help you figure things out then on top of taking a class at your local community college you should check out Cake, their communities aren’t always the friendliest but there are so many that you are very likely to eventually get some poor guy to write the code for you.

The overall message here is that while I may not have chosen this as my primary, go-to framework for rapid development, others may. So when you are out there and see a blog post about using something like Django and you know that it sucks and you can’t stand Python and you really want to post a comment on how much Python sucks and Django is the natural extension of it’s suck then don’t. Just walk away and be happy that they enjoy developing in something that you can’t stand. By my rules above Django has great community, great documentation, plenty of modular additions, and on top of that a good number of books. So why make fun of that guy, he has all he needs to build and get support.

Always remember above all else though that this is all personal choice, that is the main point and to show you what I mean. Look at how irritated Allard obviously must of been by all the talk and the flooding of the internet with frameworks. Here it is, promises everything you could possibly ever want. Check it out and see what I mean.

Buy These Books!

Posted in Code, Other, PHP, Personal, Picora. Tagged with , , .

Installing or Setting up Picora Micro Framework

I was recently introduced to the Picora framework by the great guys and my new employers over at Applied Solutions Group. If you fit the following then this might be a good one to checkout.

  1. Don’t like the HUGE frameworks that get all the attention, talking about you CakePHP
  2. Really don’t care for being forced to use strict MVC and prefer to have the choice
  3. Really aren’t super experienced with frameworks and need to get started in a forgiving way

While I do care for and support strict MVC and not straying from it, other wise what is the point, I can see how some people don’t want to spend their development time worrying about what should and shouldn’t be done in a certain way. So to get started you may be asking yourself why I would need an article on how to setup a framework that is not as in depth as the large ones. Well the thing is that there isn’t much documentation to Picora. To me this isn’t a huge problem because as I have said before, if you learn one of these then you know them all. But setup can be frustrating when there is no README and you need to create a few files to get this thing up and running. So lets get started and remember that once we get these files made before you start playing make yourself a copy of the working framework so you can just be ready to get going each time you need it.

Step One – Download

First of all we need to get the core files so head on over to Picora and download the files. I will assume you know how to get a site installed on a server. So now we have our server pointing to and serving our Picora install. Open your install in your browser and you will more than likely see the following.

Picora Installed, Maybe

WOW that is impressive huh? Well the problem is that in addition to not including all the file you need to get started it also doesn’t include a stock .htaccess file, the “.” is important so don’t forget it. So lets start by identifying the problem, hey I ain’t doing all the work for you without teaching you something.

Step Two – Find our Errors

In the root of your Picora install create a file names .htaccess, in other words it should be at the same level as the controller folder, etc… Now in that file you want to type the following:

	php_value display_errors on

Remember that little line right there because it will save you many hours of heartache. Anytime php doens’t work for you just add that into your .htaccess file, just make sure to comment it before launch for obvious reasons. So lets take another look at our browser. Refresh your page and you should have the following.

Step Three – Fix our Broken Download

WOW again, ok now we at least have something to work with. Looks like the index.php file is trying to require a file called config.php that….doens’t exist huh? I think this is kind of crappy for the download not to include a default one that can be modified to show the ropes some but either way easy enough to figure out what is going on. In true step by step fashion lets create config.php, the file it wants, and see what we get.

Well again we get errors and it wants the base url so lets add some stuff to the config.php and see what happens next. We are going to add some stuff that is required for this work and move a bit quicker now because fixing every error one at a time is going to take up 8 pages here and I know you don’t want to read it and I don’t want to type it.

	define('BASE_URL','http://picora.local/');
 
	require_once('classes/PicoraAutoLoader.php');
	PicoraAutoLoader::addFolder($path.'/classes/');
	PicoraAutoLoader::addFolder($path.'/controllers/');
	PicoraAutoLoader::addFolder($path.'/models/');
 
	$routes = array(
		'/' => array('Application','welcome')
	);

Ok so now we got a config.php file that does a few things. We are defining a base url which is used by the system for many things, for instance flash messages and redirects usually rely on the base url. Either whoo, the require we have here could also be done inside a different file such as your index.php but I choose to separate it because I am calling in a class that will be required for the next few statements and because this is the config, don’t clutter your index.php file with a bunch of crap, but if you do, do it everytime so you know where to find it. Next up is something that since you will probably want to play with it isn’t a bad thing. We load everything class we have. In a release version we would narrow this down to only the classes that we are using and even at that you could argue, with good reason, to only loading these classes as need as part of the top of a controller. Either way I will stay out of influencing you to properly use conventions.

Well we added this here so now we need to clean up our index.php file a bit so we can get the rest of this working. Again I will give you a full dump of my index.php so you can copy paste and then read more to understand what it does.

	$path = dirname(__FILE__);
	require_once($path.'/config.php');
 
	PicoraDispatcher::addRoute($routes);
 
	print PicoraDispatcher::dispatch($path,BASE_URL,(isset($_GET['__route__']) ? '/'.$_GET['__route__'] : '/'));

Almost all of these things were already in there so we basically just took a few of them out to clean up our file and make it easier to understand. First off we get our path for use in config, and other places I am sure. Next we require our config.php. The next one is new though, we are calling the PicoraDispatcher that we loaded in the config, by loading all those classes, so that we can add in our routes. In every framework routes are always a huge and powerful option that any developer will gladly take advantage of. Last of all is the same line that was already there just calling that dispatcher to get our right routes. Now we want to refresh our browser again and see what we get. I get the following but you may not, if you do not then use the PHP error that gets printed or the Picora error message, won’t be much help, or finally post a comment here and maybe I can help you.

Step Four – Play with your Picora

Well that heading sounds retarded and kind of sexual but it is true, the only way to learn any framework is to use it. When I started programming I had a teacher tell me one time to try to NOT remember everything. Remember the basics and the conceptual side of programming and everything will always be possible. Syntax can be learned in a couple hours IF you know the concepts. It makes sense if you think about it, in the computer world if you know Java you can learn C, if you know Java and C then you can obviously learn anything because you know the concepts. If you just repeatedly repeat syntax then you will never understand it.

I will probably write a tutorial, or rather tutorials, soon and we will maybe build a blog application or some other stupid intro project with Picora just to show you around and let you see how you can extend classes in PHP so you don’t have to repeat yourself. I am in no way an expert with this system, I have around 10 minutes working in it and it took me about an hour to figure out all the weirdness with setting it up so take advantage of that and as I said before, save your working copy and use it to start new projects.

Posted in Code, Other, PHP, Personal, Picora. Tagged with , , , .

Why Mosaic Mix is a great company that is doing more than just selling ethnically diverse clothing

I think that few people take into account a lot of the small details of the world around them. I have posted a few times in the past about one of our clients, Mosaic Mix, and how much we really like them but instead of just talking about why they are great clients lets take a look at why what they are doing is also as awesome as they are.

Many people would not see the reason for needing ethnically diverse clothing. If you had asked me if there was a need 3 years ago I would probably of not seen as much of reason as I do now. One night while watching a documentary on T.V. I saw a few clips from a video made by a young girl named Kiri Davis, then a high school student. After seeing a few clips of her documentary I went and found the full film, which is only about seven minutes long, and it is really a sad, eye opening short film. The video is at the bottom of this post so you can see it, it really is only about seven minutes long and I recommend that you watch it.

In the 40’s a man named Kenneth Clark conducted an experiment in which two dolls were presented to an African-American child and they are asked questions such as “Which doll is the good doll”, or “Which doll would you want to be” and the majority of the children chose the white doll. So Kiri Davis recreated the experiment to see if things had changed in the last 60 years, and she got very similar results.

So I hope you are starting to see my point about why Morinee and Richard Terry are doing a good thing with their business. They both realize the need for clothing that will not only allow children and parents to feel good but will also help promote self-esteem and build a better self image in children. I think it is the small companies like Mosaic Mix that may just have a shot at making sure if we do this experiment again in another 20 or 40 years that the results can finally change.

So head on over to Mosaic Mix and show some support for them, if you don’t need to buy any children’s or tween’s clothes then I am sure they would appreciate you sending them an email, or just letting some of your friends with children know about their company and their site.

Posted in Groovy Web Design, Other, Personal. Tagged with , , , , , .