<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My Fedora / Open Source Notes</title>
	<atom:link href="http://mfosn.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mfosn.wordpress.com</link>
	<description>Just another programmer blog</description>
	<lastBuildDate>Mon, 23 Jan 2012 16:28:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mfosn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/5898441e997d31bf101d5ffedf5182c9?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>My Fedora / Open Source Notes</title>
		<link>http://mfosn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mfosn.wordpress.com/osd.xml" title="My Fedora / Open Source Notes" />
	<atom:link rel='hub' href='http://mfosn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Bank Islam phishing site through e-mail</title>
		<link>http://mfosn.wordpress.com/2011/09/12/bank-islam-phishing-site-through-e-mail/</link>
		<comments>http://mfosn.wordpress.com/2011/09/12/bank-islam-phishing-site-through-e-mail/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 04:20:51 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Rant]]></category>
		<category><![CDATA[phishing]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=343</guid>
		<description><![CDATA[This is one phishing mail I received today. If you hover the link, the URL seems correct, but you can&#8217;t fool me waltersgreenhouse.ca / rumahhawa.com, see the bottom left of the browser windows, it shows the link it&#8217;ll redirect you to. Don&#8217;t enter your info to that site!!! P/S: I don&#8217;t have Bank Islam account&#8230;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=343&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://mfosn.files.wordpress.com/2011/09/bankislam.jpg"><img class="alignnone size-medium wp-image-344" title="bankislam" src="http://mfosn.files.wordpress.com/2011/09/bankislam.jpg?w=300&#038;h=210" alt="" width="300" height="210" /></a></p>
<p>This is one phishing mail I received today. If you hover the link, the URL seems correct, but you can&#8217;t fool me <span style="text-decoration:underline;">waltersgreenhouse.ca</span> /<span style="text-decoration:underline;"> rumahhawa.com</span>, see the bottom left of the browser windows, it shows the link it&#8217;ll redirect you to.</p>
<div id="attachment_347" class="wp-caption alignnone" style="width: 310px"><a href="http://mfosn.files.wordpress.com/2011/09/bankislam2.jpg"><img class="size-medium wp-image-347" title="bankislam2" src="http://mfosn.files.wordpress.com/2011/09/bankislam2.jpg?w=300&#038;h=210" alt="" width="300" height="210" /></a><p class="wp-caption-text">See where they send the form to</p></div>
<p><strong>Don&#8217;t enter your info to that site!!!</strong></p>
<p>P/S: I don&#8217;t have Bank Islam account&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/343/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=343&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/12/bank-islam-phishing-site-through-e-mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>

		<media:content url="http://mfosn.files.wordpress.com/2011/09/bankislam.jpg?w=300" medium="image">
			<media:title type="html">bankislam</media:title>
		</media:content>

		<media:content url="http://mfosn.files.wordpress.com/2011/09/bankislam2.jpg?w=300" medium="image">
			<media:title type="html">bankislam2</media:title>
		</media:content>
	</item>
		<item>
		<title>Singleton class</title>
		<link>http://mfosn.wordpress.com/2011/09/11/singleton-class/</link>
		<comments>http://mfosn.wordpress.com/2011/09/11/singleton-class/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 13:18:51 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=335</guid>
		<description><![CDATA[This is continuation from singleton pattern post. Here&#8217;s the abstract class for singleton pattern, and other classes that need to be singleton just need to extend this class. We can&#8217;t directly use self::$instance = new self(); because self will refer to this singleton class itself, not the class we extend. So, to get the extending [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=335&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is continuation from <a href="http://mfosn.wordpress.com/2011/09/02/singleton-pattern/">singleton pattern</a> post.</p>
<p>Here&#8217;s the abstract class for singleton pattern, and other classes that need to be singleton just need to extend this class.</p>
<p><pre class="brush: php;">class singleton {
    private static $instance;
    private function __construct() {}
    private function __clone() {}
    protected static function init($class) {
        if (!isset(self::$instance[$class]) ||
            !self::$instance[$class] instanceof $class) {
            self::$instance[$class] = new $class();
        }
        return self::$instance[$class];
    }
}</pre></p>
<p>We can&#8217;t directly use <code>self::$instance = new self();</code> because <code>self</code> will refer to this singleton class itself, not the class we extend. So, to get the extending class, the extending class need to explicitly pass the classname to parent class to init().</p>
<p><pre class="brush: php;">class app extends singleton {
    var $i = 0;
    static function o() {
        return parent::init(__CLASS__);
    }
    function run() {
        $this-&gt;i++;
        echo 'run app...';
    }
}
// to access app class and its methods &amp; attr
app::o()-&gt;run();
echo app::o()-&gt;i;</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/335/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/335/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/335/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=335&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/11/singleton-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>Filter nudity with PHP</title>
		<link>http://mfosn.wordpress.com/2011/09/08/filter-nudity-with-php/</link>
		<comments>http://mfosn.wordpress.com/2011/09/08/filter-nudity-with-php/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 14:04:17 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[nudity filter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=331</guid>
		<description><![CDATA[nude.js is JS based nudity scanner using HTML5 Canvas and Webworker. The algorithm is based on this research paper http://www.math.admu.edu.ph/~raf/pcsc05/proceedings/AI4.pdf. I&#8217;ve been working on to port the script to PHP and using GD library. So, here&#8217;s the result: php-nudity-filter. It&#8217;s a direct porting of the nude.js script to PHP, where I maintain the data structure, functions [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=331&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/pa7/nude.js">nude.js</a> is JS based nudity scanner using HTML5 Canvas and Webworker. The algorithm is based on this research paper <a href="http://www.math.admu.edu.ph/~raf/pcsc05/proceedings/AI4.pdf">http://www.math.admu.edu.ph/~raf/pcsc05/proceedings/AI4.pdf</a>.</p>
<p>I&#8217;ve been working on to port the script to PHP and using GD library. So, here&#8217;s the result: <a href="https://github.com/azwan082/php-nudity-filter">php-nudity-filter</a>. It&#8217;s a direct porting of the nude.js script to PHP, where I maintain the data structure, functions and algorithm, therefore its performance is not very optimized for PHP. Scanning a 500&#215;500 image will take around 8-10 seconds.</p>
<p>But overall it&#8217;s working as expected, it can detect nude picture at rate similar to nude.js. There are several steps that still not complete (esp. the bounding polygon) and optimization. <a href="https://github.com/azwan082/php-nudity-filter">Fork it at Github</a>, improve it and make internet a better place.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/331/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/331/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/331/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=331&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/08/filter-nudity-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>Git basic</title>
		<link>http://mfosn.wordpress.com/2011/09/07/git-basic/</link>
		<comments>http://mfosn.wordpress.com/2011/09/07/git-basic/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 15:22:11 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[revision control]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=326</guid>
		<description><![CDATA[I&#8217;m a noob in using Git, and I&#8217;m using Github to host some of the code I wrote. Here are some basic commands to host a project with Github (or using Git revision control generally) (sometimes I forgot the command or the order of which command goes first) Global setup: Set up git git config [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=326&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a noob in using Git, and I&#8217;m using Github to host some of the code I wrote. Here are some basic commands to host a project with Github (or using Git revision control generally) (sometimes I forgot the command or the order of which command goes first)</p>
<p>Global setup:</p>
<p>Set up git</p>
<pre>git config --global user.name "Your Name"
git config --global user.email myemail@maildomain.com</pre>
<p>Next steps:</p>
<pre>mkdir project-name
cd project-name
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:username/project-name.git
git push -u origin master</pre>
<p>Existing Git Repo?</p>
<pre>cd existing_git_repo
git remote add origin git@github.com:username/project-name.git
git push -u origin master</pre>
<p>To commit changes (and optionally push changes to Github)</p>
<pre>git add .
git commit -m 'commit message'
git push -u origin master</pre>
<p>Common SVN users may find it confusing when using Git. Here&#8217;s some of the tips:</p>
<ul>
<li>There are no centralized server or repo. You are the server / repo</li>
<li>In SVN, what&#8217;s in your computer is working copy and the center for committing changes is the repository, In Git, your working copy is your repository.</li>
<li>In SVN, project members checked out a working copy and commit changes to a centralized repository. In Git, everyone in a project can be the repository, can checkout (pull) and commit (push) changes to each other<br />
(Note: In Git, &#8216;checkout&#8217; is called `pull`, &#8216;commit&#8217; is saving changes to your own repository, &#8216;push&#8217; is sending and merging changes to remote repository</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=326&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/07/git-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>GIMP Single Window Mode</title>
		<link>http://mfosn.wordpress.com/2011/09/06/gimp-single-window-mode/</link>
		<comments>http://mfosn.wordpress.com/2011/09/06/gimp-single-window-mode/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 07:33:54 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Rant]]></category>
		<category><![CDATA[gimp]]></category>
		<category><![CDATA[image editor]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=321</guid>
		<description><![CDATA[I&#8217;ve been using Gimp as my primary image editing software. I never used photoshop (and I don&#8217;t want to). The only thing that make using Gimp quite difficult is the user interface &#8211; the main application window is separated into 3 (sometimes 2) tiny windows. I used to promote the software to other users, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=321&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Gimp as my primary image editing software. I never used photoshop (and I don&#8217;t want to). The only thing that make using Gimp quite difficult is the user interface &#8211; the main application window is separated into 3 (sometimes 2) tiny windows. I used to promote the software to other users, but this one important feature has been missing since the existence of Gimp, cause many of them prefer photoshop.</p>
<h1>Finally!</h1>
<p>Single window mode is available for Gimp (2.7.3). However this version is still in development phase, and it&#8217;s rumoured that version 2.8 will be the stable release for this most requested feature.</p>
<p><a href="http://www.linuxjournal.com/content/gimp-273-adds-single-window-mode"><img class="alignnone" title="gimp-273-adds-single-window-mode - linuxjournal" src="http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1002061/thegimp273_ljr_600b.jpg" alt="" width="550" height="413" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=321&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/06/gimp-single-window-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>

		<media:content url="http://www.linuxjournal.com/files/linuxjournal.com/ufiles/imagecache/large-550px-centered/u1002061/thegimp273_ljr_600b.jpg" medium="image">
			<media:title type="html">gimp-273-adds-single-window-mode - linuxjournal</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP timezone handling</title>
		<link>http://mfosn.wordpress.com/2011/09/05/php-timezone-handling/</link>
		<comments>http://mfosn.wordpress.com/2011/09/05/php-timezone-handling/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 05:11:36 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=316</guid>
		<description><![CDATA[Within PHP app, we need to set the timezone to only one timezone &#8211; UTC. All timestamp data that going in and out of the database must use UTC timezone so that it&#8217;s easier to convert to other timezone value. It&#8217;s a basic in PHP script to first set the timezone data Then it is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=316&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Within PHP app, we need to set the timezone to only one timezone &#8211; UTC. All timestamp data that going in and out of the database must use UTC timezone so that it&#8217;s easier to convert to other timezone value. It&#8217;s a basic in PHP script to first set the timezone data</p>
<p><pre class="brush: php;">date_default_timezone_set('UTC');</pre></p>
<p>Then it is highly encourage to store all datetime related data in UNIX timestamp, since retrieving it from database is faster than formatted datetime, also easier to format using date() function, and also easy to convert from one timezone to another timezone value, using function below:</p>
<p><pre class="brush: php;">timezone_offset_get(new DateTimeZone($timezone), new DateTime()));</pre></p>
<p>$timezone value is one of the timezone identifier listed at <a href="http://www.php.net/manual/en/timezones.php" target="_blank">List of Supported Timezones</a> at php.net. This function will handle the DST conversion automatically.</p>
<p>To summarize, here&#8217;s the correct usage and handling of timezone in PHP</p>
<ol>
<li>Always set default timezone to UTC, and store user specific timezone info in database or in cookies</li>
<li>Store and retrieve timestamp in UTC timezone</li>
<li>Only convert to local timezone when displaying the timestamp info</li>
</ol>
<p><pre class="brush: php;">
// set first early in the script
date_default_timezone_set('UTC');

// data retrieved from database is based on UTC timezone
$timestamp = 1310529794;

// and you're in Los Angeles
$timezone = 'America/Los_Angeles';

// show the formatted datetime for time in L.A
echo date('F j Y, g:i:s a', $timestamp + timezone_offset_get(new DateTimeZone($timezone), new DateTime()));
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=316&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/05/php-timezone-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP async request with auth</title>
		<link>http://mfosn.wordpress.com/2011/09/05/php-async-request-with-auth/</link>
		<comments>http://mfosn.wordpress.com/2011/09/05/php-async-request-with-auth/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 04:07:38 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[background process]]></category>
		<category><![CDATA[fsock]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=307</guid>
		<description><![CDATA[In http://stackoverflow.com/questions/962915/how-do-i-make-an-asynchronous-get-request-in-php, it shows how to send asynchronous request from PHP script, so that the webpage is immediately rendered without waiting the request to finish. This technique is important if you want to implement background processing in web app, just by send a request to own script that going to run the process at background, while [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=307&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://stackoverflow.com/questions/962915/how-do-i-make-an-asynchronous-get-request-in-php">http://stackoverflow.com/questions/962915/how-do-i-make-an-asynchronous-get-request-in-php</a>, it shows how to send asynchronous request from PHP script, so that the webpage is immediately rendered without waiting the request to finish.</p>
<p>This technique is important if you want to implement background processing in web app, just by send a request to own script that going to run the process at background, while the main script continue to run and produce the webpage.</p>
<p>However, the request made to the background process page maybe can be accessed directly, just by entering the correct URL to browser, and you want to make sure this page is not being abused by users.</p>
<p>During sending the request, we can modify the request header as an authentication method to check if request is originally come from our own web application. You may modify user agent header and set it as your own webapp UA</p>
<p>&#8216;User-Agent: my-web-app&#8217;, and in your script, check the value of $_SERVER['HTTP_USER_AGENT']</p>
<p>Or, for more security, use custom header name, as follows:</p>
<p><pre class="brush: php;">
$host = 'localhost';
$path = '/bg.php';
$qs = array(); // query string
if (!empty($qs)) {
    $qs = http_build_query($qs);
    $path = $path .'?'. $qs;
}
$fp = fsockopen($host, 80, $errno, $errdesc);
if ($fp) {
    $req  = &quot;GET $path HTTP/1.0\r\n&quot;;
    $req .= &quot;Host: $host\r\n&quot;;
    $req .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
    $req .= &quot;Content-Length: &quot;. strlen($qs) .&quot;\r\n&quot;;
    $req .= &quot;Anxx0Wjoiw3: asmkd3A0das2wq2\r\n&quot;;
    $req .= &quot;Connection: Close\r\n\r\n&quot;;
    fputs($fp, $req);
    fclose($fp);
}</pre></p>
<p>And in the background process script, check if the custom header is correct:</p>
<p><pre class="brush: php;">if (isset($_SERVER['HTTP_ANXX0WJOIW3']) &amp;&amp; $_SERVER['HTTP_ANXX0WJOIW3'] == 'asmkd3A0das2wq2') {
    // do background process
}</pre></p>
<p>Note: Custom header (or other headers), can be access using $_SERVER variables, with the key prepended with &#8216;HTTP_&#8217;</p>
<p>As an addition, use encrypted value for the header name and value, and also change the value for every several hour by autogenerate it using mktime() and strtotime(), provided you secure the encrypted string with salt data, example:</p>
<p><pre class="brush: php;">$salt = 'secret-key';
$hash = md5($salt . mktime(date('H', strtotime('+6 hour')), 0, 0));</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/307/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/307/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/307/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=307&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/05/php-async-request-with-auth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Templating</title>
		<link>http://mfosn.wordpress.com/2011/09/02/php-templating/</link>
		<comments>http://mfosn.wordpress.com/2011/09/02/php-templating/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 08:34:59 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=295</guid>
		<description><![CDATA[Here&#8217;s a simplified template class that was inspired by PHP Tip: Extract, Variable Variables and Templating. It supports template inheritance, it&#8217;s object oriented &#38; got auto escaping variables. Furthermore, it doesn&#8217;t need to be compiled, since it&#8217;s using plain PHP The class: tpl.class.php This class is just a basic class that organize the template files, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=295&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simplified template class that was inspired by <a href="http://www.ejeliot.com/blog/101" target="_blank">PHP Tip: Extract, Variable Variables and Templating</a>. It supports template inheritance, it&#8217;s object oriented &amp; got auto escaping variables. Furthermore, it doesn&#8217;t need to be compiled, since it&#8217;s using plain PHP</p>
<p>The class: tpl.class.php</p>
<p><pre class="brush: php;">
class tpl {

    var $file;
    var $folder = 'template';
    var $vars;

    function __construct($file) {
        $this-&gt;file = $file;
    }

    /**
     * Assign variables to class attributes
     */
    function assign($name, $value) {
        // need to render child template
        if ($value instanceof self) {
            ob_start();
            foreach ($this-&gt;vars as $k =&gt; $v) {
                if (is_scalar($v) || is_array($v)) {
                    // copy variables to child template
                    $value-&gt;assign($k, $v);
                }
            }
            $value-&gt;render();
            $html = ob_get_contents();
            ob_end_clean();
            // assign output HTML to parent template variable
            $this-&gt;vars[$name] =&amp; $html;
        } else {
            $this-&gt;vars[$name] =&amp; $value;
        }
    }

    /**
     * Echo variables and auto escape HTML for string vars
     */
    function e($name) {
        if (is_string($this-&gt;vars[$name])) {
            echo htmlspecialchars($this-&gt;vars[$name], ENT_QUOTES, 'UTF-8');
        } else {
            echo $this-&gt;vars[$name];
        }
    }

    /**
     * Display the main template (usually master/layout template)
     * and set header
     */
    function display() {
        if (!headers_sent()) {
            header('Content-type: text/html; charset=utf-8');
        }
        $this-&gt;render();
    }

    /**
     * Include template file
     */
    private function render() {
        require_once dirname(__FILE__) .'/'. $this-&gt;folder .'/'. $this-&gt;file .'.php';
    }
}</pre></p>
<p>This class is just a basic class that organize the template files, and it can be easily applied to your page controller script, so that you can separate the presentation layer and business logic part.</p>
<p>To use, here are some of the template files, that consist of 3 inheritance levels.</p>
<p>Top level: layout.tpl.php</p>
<p><pre class="brush: php;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;

&lt;head&gt;
    &lt;title&gt;&lt;?php echo $this-&gt;vars['title']; ?&gt;&lt;/title&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html;charset=utf-8&quot; /&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;?php echo $this-&gt;vars['body']; ?&gt;
&lt;/body&gt;

&lt;/html&gt;
</pre></p>
<p>Middle level: body.tpl.php</p>
<p><pre class="brush: php;">&lt;h2&gt;&lt;?php $this-&gt;e('blog_title'); ?&gt;&lt;/h2&gt;
&lt;p&gt;&lt;?php $this-&gt;e('blog_content'); ?&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;?php echo $this-&gt;vars['portlet']; ?&gt;</pre></p>
<p>Bottom level: portlet.tpl.php</p>
<p><pre class="brush: php;">&lt;div style=&quot;width: 120px; border: 1px solid #ccc; background: #eee; text-align: center; padding: 10px;&quot;&gt;
    &lt;span style=&quot;color: #333; font-size: 11px; font-family: sans-serif;&quot;&gt;This is portlet&lt;br/&gt;&lt;?php $this-&gt;e('portlet_name'); ?&gt;&lt;/span&gt;
&lt;/div&gt;
</pre></p>
<p>Then in your page controller code, add this to the bottom of the file to render the template &amp; output:</p>
<p><pre class="brush: php;">require_once 'tpl.class.php';

$tpl = new tpl('layout.tpl');
// assign all variables first before display the template
$tpl-&gt;assign('title', 'New Test Template');
$tpl-&gt;assign('blog_title', 'My First Post');
$tpl-&gt;assign('blog_content', 'Lorem ipsum dolor sit amet');
$tpl-&gt;assign('portlet_name', 'My lil\' portlet');
$tpl-&gt;assign('portlet', new tpl('portlet.tpl')); // this variable needed by body.tpl, so assign it first
$tpl-&gt;assign('body', new tpl('body.tpl'));
$tpl-&gt;display();</pre></p>
<p>The order of assigning the variables is important, because you cannot echo or access variables that are not yet assigned.</p>
<p>This class is very much working now, and you may add more features to it &#8211; template caching, setting custom header to support other output type (such as RSS, XML etc.), data formatting functions, language translation support, gzip support etc.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=295&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/02/php-templating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>Singleton pattern</title>
		<link>http://mfosn.wordpress.com/2011/09/02/singleton-pattern/</link>
		<comments>http://mfosn.wordpress.com/2011/09/02/singleton-pattern/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 06:36:32 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[registry pattern]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=291</guid>
		<description><![CDATA[Singleton class is class that allow only one instance of its class to be instantiated. A lot of examples I see the way to implement singleton pattern whether: 1. Extends a base singleton class 2. Each class apply singleton pattern (get_instance() method, has static $instance attribute) 3. Using registry pattern where one dedicated class act [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=291&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Singleton class is class that allow only one instance of its class to be instantiated.</p>
<p>A lot of examples I see the way to implement singleton pattern whether:</p>
<p>1. Extends a base singleton class<br />
2. Each class apply singleton pattern (get_instance() method, has static $instance attribute)<br />
3. Using registry pattern where one dedicated class act as the singleton instances manager</p>
<p>Well, things shouldn&#8217;t get too hard. Here, I will use the combination of registry pattern and singleton in just a function</p>
<p><pre class="brush: php;">function o($class) {
    static $instances;
    if (!isset($instances[$class]) || !$instances[$class] instanceof $class) {
        $instances[$class] =&amp; new $class();
    }
    return $instances[$class];
}</pre></p>
<p>To use it:</p>
<p><pre class="brush: php;">o('db')-&gt;query(...);
o('db')-&gt;fetch();
o('singleton_class')-&gt;do_something();
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/291/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=291&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/02/singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP Hooks System</title>
		<link>http://mfosn.wordpress.com/2011/09/02/php-hooks-system/</link>
		<comments>http://mfosn.wordpress.com/2011/09/02/php-hooks-system/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 03:19:12 +0000</pubDate>
		<dc:creator>아쓰완</dc:creator>
				<category><![CDATA[Ideas]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://mfosn.wordpress.com/?p=289</guid>
		<description><![CDATA[After reading Explaining Hooks, finally I understand the concept of hooks in PHP and why people use it in WordPress and say WP codes is poetry. The general idea is, in a web application, during the runtime of the program it go through stages of processes, such as connecting to database, start the session, rendering [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=289&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://blog.phpbb.com/2010/10/09/explaining-hooks/" target="_blank">Explaining Hooks</a>, finally I understand the concept of hooks in PHP and why people use it in WordPress and say WP codes is poetry.</p>
<p>The general idea is, in a web application, during the runtime of the program it go through stages of processes, such as connecting to database, start the session, rendering template etc. These are known as events. When these events occured during the runtime of the program, some external code can be run as additional processing to the core program. These external/additional process is known as plugin.</p>
<p>So, the hooks system expose these events for the plugins to attach to. So that when the event occur, the plugin will be run. Even though the concept seems simple, but there are problem that we need to handle:</p>
<p>Which plugin to call first when this event occur? The hooks system need to have priority feature to make sure plugins are called in correct order, to produce the intended result</p>
<p>What plugin need to load? If load all, wouldn&#8217;t it affect the site performance? This is why plugins need to be registered to the plugins system of an application. So that, the core application know what plugins to load at what time, and what function to run.</p>
<p>Therefore, the hooks system need to have plugin registration section, priority section, specify the list of hooks event available and know how to handle unknown events. The plugin data can be stored in database, and stored the configuration data temporarily in cache for faster access.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mfosn.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mfosn.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mfosn.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mfosn.wordpress.com&amp;blog=12071314&amp;post=289&amp;subd=mfosn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mfosn.wordpress.com/2011/09/02/php-hooks-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9c03e0e51479821612f400ad749aa41c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">E</media:title>
		</media:content>
	</item>
	</channel>
</rss>
