Mullanaphy!
Blog
Portfolio
About Me
Contact Me
I'm Mullanaphy!, anything can happen.
Mullanaphy!
Mullanaphy @ bitbucket
Ny newer stuff is on Bitbucket.
Mullanaphy @ github
My older stuff is on Githut.
Final Sandwich
Delivering tasty treats in the form of writings and comics. Enjoy, now!
Jin Hee K.im
She's Korean, so that pretty much guarantees that she's smart, humorous, and cute... mmmmm...
Art of Tom Pollock Jr.
His site might not actually cure AIDS but it might make you ballsy enough to get them and see if it does.
Chris Stein's Artwork
Definitely a good guy to have during an intense brainstorming session. Filled to the brim with mythology, creativity, and a vocabulary. Thats right, vocabulary.
Matt Laskodi
Matt Laskodi is a lot more humorous than you could ever imagine to be... ever... So just deal with it, I know I have.

Blog »

Feeds | Blog RSS 2.0 | Blog Atom 1.0 | Artwork RSS 2.0 | Artwork Atom 1.0

« Previous | 1 2 3 4 5 6 7 | Next »

2010-11-16: PHP's SimpleXMLElement and XML Namespaces.

So decided to use SimpleXMLElement to create simple RSS feeds for Lafango. However there seems to be no easy way to create a simple file like this:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
  <channel>
    <title>Lafango - Videos</title>
    <link>http://lafango.com/</link>
    <description>Directory of Videos on Lafango</description>
    <language>en-us</language>
    <pubDate>Tue, 16 Nov 2010 15:29:19 EST</pubDate>
    <lastBuildDate>Tue, 16 Nov 2010 15:29:19 EST</lastBuildDate>
    <managingEditor>support@lafango.com (Admin)</managingEditor>
    <webMaster>webmaster@lafango.com (Admin)</webMaster>
    <ttl>5</ttl>
    <item>
    <link>http://lafango.com/btfffilms/media/12228-pennysavers-trailer</link>
    <pubDate>Tue, 13 Jan 2009 15:29:19 EST</pubDate>
      <title>PennySavers Trailer</title>
    <description>The Theatrical Trailer to this summer's breakout hit...</description>
    <media:title>PennySavers Trailer</media:title>
    <media:description>The Theatrical Trailer to this summer's breakout hit...</media:description>
  </item>
  </channel>
</rss>

Which would think was simple enough to accomplish, yet to get the 'media' namespace was a pain in the tush. With the built in addAttribute('media:title','PennySavers Trailer','http://search.yahoo.com/mrss/'); it was adding the namespace alright, just the problem being it was being added to the nodes themselves and there was no way to just append it to the main RSS node.

So, without adding the namespace to the RSS node as in the example, the readers these were being sent to just laughed at me. That usually means it's time to rummage through php.net's documentation and comments and see if someone else already solved this tiny problem. Unfortunately nothing good came out of it other then having to write my own basic extended SimpleXMLElement. So here it is:

<?php
  class Extended_SimpleXMLElement extends SimpleXMLElement {
    # Source: http://phy.im/m/blog_31/extended_simplexmlelement.php
    
    # Add a namespace to the main node.
    public function addNamespace($namespace=false,$url=false) {
      # Make sure we have a namespace to add.
      if(!$namespace||!$url) return false;
      
      # Add the attribute to the beginning. This will later be
      # stripped out, we just want SimpleXMLElement's auto attribute.

      $this->addAttribute($namespace.':mullanaphy','',$url);
      return $url;
    }
    
    # We need to preg_replace the added $ns:mullanaphy="" out.
    public function asXML() { return preg_replace('# \w+\:mullanaphy=""#','',parent::asXML()); }
    
    # This I actually got from 'Yuri Vecchi' via php.net.
    # liked the idea so added it in. It allows you to chain
    # addAttribute() on the same node.
    # e.g. $node = $XML->addChild('node','')->addAttribute('a',1)->addAttribute('b',2);

    public function addAttribute($name,$value,$namespace=NULL) {
      parent::addAttribute($name,$value,$namespace);
      return $this;
    }
  }

?>

The extension add the addNamespace to the class which allowed me to do what was needed. On top of that added something that seemed pretty cool that was done by a Yuri on php.net's comment section. Lastly asXML needed to be overwritten just for the simple clean up preg_replace.

Here's an example of using the extended class:

<?php
  class Example {
    public function __construct() {
      # Require the class file if you don't have an __autoload() set.
      require_once 'extended_simplexmlelement.php';
      
      # Define the class and provide the default RSS.
      $XML = new Extended_SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"></rss>');
      
      # Add a namespace.
      $media = $XML->addNamespace('media','http://search.yahoo.com/mrss/');
      
      # Add a channel node and fill it up.
      $channel->addChild('title','Lafango - Videos');
      $channel->addChild('link','http://lafango.com/');
      $channel->addChild('description','Directory of Videos on Lafango');
      $channel->addChild('language','en-us');
      $channel->addChild('pubDate',date('D, d M Y H:i:s T');
      $channel->addChild('lastBuildDate',date('D, d M Y H:i:s T'));
      $channel->addChild('managingEditor','support@lafango.com (Admin)');
      $channel->addChild('webMaster','webmaster@lafango.com (Admin)');
      $channel->addChild('ttl',5);
      
      # Iterate through an array and append item nodes.
      foreach($this->fetch() as $row):
        $item = $channel->addChild('item');
        $item->addChild('title',$row->title);
        $item->addChild('link',$row->url);
        $item->addChild('description',$row->description);
        $item->addChild('media:title',$row->title,$media);
        $item->addChild('media:description',$row->description,$media);
      endforeach;
      echo $XML->asXML();
    }
    
    private function fetch() { /* gets some array data from someplace, don't worry about it. */ }
  }

  
  new Example;
?>

Granted in this example we could have easily included the namespace inside the rss node during the __construct(), however in my situation the RSS attributes needed to be dynamic as RSS was defined on an abstract class and those extending it all had different needs.

This solution is probably not that relevant yet if it saves someone time then so be it. Please use and abuse this freely.

2 Comments | 3 Karma ++ -- | Click to hide

2010-06-23: We'll Fight For Uncle Sam!

What a day! What a goal!

USA had the world against them, well at least FIFA refs (you know, the same group of guys that had it out for Ireland). Yet USA stood tall and with sheer determination they fought through and by the aid of Donovan's foot the break through came in the 91st minute.

Wow, my heart raced as I watched the goal blast in from 8 yards back. What a game goal that erased the two stolen goals by the refs. Which personally don't understand why FIFA won't follow hockey's foot steps with replays for goals. Common sense yet they like giving off the impression that there are conspiracies a foot.

Oh well, USA advances on top while France burned in flames. The Curse of Ireland did them in, dirty. Thank you Mexico and South Africa for utterly destroying France. Congrats to Mexico as well for advancing.

Lastly, have to also say congrats to South Korea for advancing. They were making me nervous... If you don't know why I'd be rooting for South Korea, well my fiancée (indeed, proposed last month) is Korean-American so that answers that very easily.

I part with the songs that were playing on my way to work.

We'll Fight For Uncle Sam.

Johnny Comes Marching Home.

Battle Cry of Freedom.

Army of the Free.

0 Comments | 5 Karma ++ -- | Click to hide

2009-11-18: Thierry Henry Interrupted!

Some one had to... so share and share alike.

Yo Henry I'm really happy for you and Im'ma let you finish,but Maradona had the best 'Hand of God' of all time!

11 Comments | 6 Karma ++ -- | Click to hide

2009-11-18: Thierry Henry and his 'Hand of God'

Thierry Henry's blatant hand ball
That should sum up my mood right now. Even if he was playing basketball he would've been called with traveling...

Anyone else outraged by his actions or worse his commenting on it please feel free to let FIFA know. I sent them this via http://www.fifa.com/contact/form.html

It is absolutely deplorable that FIFA deems it necessary to cover up the fact that Thierry Henry completely changed the course of the game via a blatant and intentional hand ball.
To not even mention that and to hide\delete comments by members is just a sad state of affairs.
Ireland was robbed hands down and it seems that FIFA and UEFA have no problems with this sort of behaviour.
Absolutely despicable. Any credibility that FIFA tried to hold on to is now more than gone.
I don't want a reply back and am done looking towards FIFA with hopes of fair play. The debacle that was 2006 World Cup and now this.

Yes, to make matters even worse FIFA and UEFA make zero mention of this incident although they did mention that Anelka was possibly fouled for a penalty kick. Seriously, I know FIFA has always had integrity issues but that's just getting batty.

To follow up I and I am quite sure others have posted comments on that article that it wasn't Gallas who broke Ireland's heart, it was Henry. Yet as you can clearly see all comments have been removed although the 1.2 star is still there.

Anyone interested here's some facebook groups:

And Twitter info:

Finally the things that bother me the most are that Henry isn't sorry for what he did and FIFA isn't going to do anything substantial about it.

0 Comments | 3 Karma ++ -- | Click to hide

2009-10-28: Busy at the Trove

So, I've been working like a mofo at my place of business, TalentTrove, and been making some pretty sweet smut. For example, developed their forums, BackStage, Manage Media\Friends, Uploader, and on the backend a huge chunk on how things communicate with each other.

Anyways won't get into too much details since it's mostly nerdy stuff and the average person will end up wanting to punch me in the sack. Instead I'll just leave you with these links to one of our users, Superstar and Star:

As you can tell by going to any of those videos Superstar And Star is absolutely brilliant. Such good times... Alright it's back to work time.

0 Comments | 3 Karma ++ -- | Click to hide

« Previous | 1 2 3 4 5 6 7 | Next »