<?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/"
	>

<channel>
	<title>maSnun&#039;s logs &#187; php</title>
	<atom:link href="http://masnun.com/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://masnun.com/blog</link>
	<description>Personal Blog of maSnun</description>
	<lastBuildDate>Sat, 24 Jul 2010 04:33:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automated MySQL Database Backup System</title>
		<link>http://masnun.com/blog/2010/07/24/automated-mysql-database-backup-system/</link>
		<comments>http://masnun.com/blog/2010/07/24/automated-mysql-database-backup-system/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 04:32:30 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=979</guid>
		<description><![CDATA[I just finished writing a tool to automate mysql database backup. It dumps the configured mysql database, zips the SQL file into a TGZ archive and emails the attachment to a predefined email address. Download: http://masnun.googlecode.com/files/sqlbackup.zip What you need to &#8230; <a href="http://masnun.com/blog/2010/07/24/automated-mysql-database-backup-system/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just finished writing a tool to automate mysql database backup. It dumps the configured mysql database, zips the SQL file into a TGZ archive and emails the attachment to a predefined email address.</p>
<p><strong>Download:</strong> <a href="http://masnun.googlecode.com/files/sqlbackup.zip">http://masnun.googlecode.com/files/sqlbackup.zip</a></p>
<p>What you need to do to use this tool is to download it, extract the folder named &#8220;sqlbackup&#8221;, edit the index.php file to configure the database and email settings, upload the folder to your webhost and set up a cron job to run the tool periodically.</p>
<p>In fact, it&#8217;s simple though it looks complicated.  Try it yourself! Gonna be easy.</p>
<p>I am using Yahoo! Mail and a custom filter to store the database backups into a dedicated folder inside my Yahoo! Mailbox. Yahoo! has un-metered storage. So you can use this huge storage to have your databases backed up safely.</p>
<p>I am running the cron job once everyhour for testing purpose. I will set it to run once a day since I don&#8217;t have much database operations everyday. If your application sees frequent database changes, use a frequent cron job. Please consider checking out your control panel to know how to set a cron job if you don&#8217;t know already.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/07/24/automated-mysql-database-backup-system/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coupling Zend Framework with CodeIgniter</title>
		<link>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/</link>
		<comments>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 11:48:13 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=959</guid>
		<description><![CDATA[CodeIgniter is a super cool web application framework for PHP. It is lightweight and lets you get the jobs done in a fashion. It is the first framework I have used and I am still using it. On the other &#8230; <a href="http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter is a super cool web application framework for PHP. It is lightweight and lets you get the jobs done in a fashion. It is the first framework I have used and I am still using it. On the other hand, Zend Framework is from Zend, the PHP company. I appreciate the huge library and the full stack nature. I respect the fact that ZF is from the people who maintain PHP. But honestly, I don&#8217;t find it feasible for medium and small projects. </p>
<p>One of the brighter aspects of the Zend Framework is that it has many cool libraries. The framework itself is loosely tied and the components are available as stand alone. We can take this opportunity to integrate the powerful library of the Zend Framework into the beautiful CodeIgniter making ourselves more productive than before. Specially, we can relieve ourselves from writing and maintaining wrappers to different APIs.</p>
<p>Ok then, let&#8217;s see how do we integrate the Zend Framework libraries into CI.</p>
<p>1) Setup CodeIgniter.</p>
<p>2) Download the Zend Framework. Extract the archive. </p>
<p>3) From the ZF files, copy the &#8220;Zend&#8221; directory from inside the &#8220;library&#8221; directory.</p>
<p>4) Paste the directory into the &#8220;system/application/libraries&#8221; directory. So ultimately, the new location of the copied &#8220;Zend&#8221; directory would be &#8220;system/application/libraries/Zend&#8221;. If you&#8217;re on Linux/Unix, we need to deal with file permission. Make the Zend directory accessible by all. I don&#8217;t think I need to tell you how to do that with chmod, do I ? <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>5) In the same  &#8220;system/application/libraries/&#8221; directory, create a new file named &#8220;Zend.php&#8221; and put the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BASEPATH'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No direct script access allowed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Zend
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> APPPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'libraries'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$class</span> <span style="color: #339933;">.</span> EXT<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We are done. That completes the integration. Now we can load any Zend component inside our controllers. Let&#8217;s make our hands dirty by modifying the default welcome controller. Open the &#8220;system/application/controllers/welcome.php&#8221; and put the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Welcome <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> Welcome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zend'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">zend</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend/Service/Flickr'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$flickr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Service_Flickr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'12e99caebb8f305fff5a943606ecde18'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tagSearch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'worldcup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
                      <span style="color: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Small</span><span style="color: #339933;">;</span>
                      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$photo-&gt;clickUri}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$photo-&gt;uri}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you read the codes above, you already know what it does <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If everything goes right, you&#8217;ll see a bunch of Flickr photos with the &#8220;worldcup&#8221; tag. Clicking on a photo will take you to the Flickr page of that photo.</p>
<p>Now, what we have seen is pretty straightforward. We don&#8217;t use any hooks or don&#8217;t go for any complexity. We simply put the Zend library in the application library. Then we write a loader class that loads Zend libraries. When we construct this &#8220;Zend Loader&#8221; object, it adds the Zend library directory to the include path. Then when we use the load() method of the object, it imports the library and adds the functionalities to the current scope <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enjoy the Zend Services with the cool CodeIgniter framework! Have fun <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/06/16/coupling-zend-framework-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Code Completion with the Netbeans IDE for PHP</title>
		<link>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/</link>
		<comments>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 06:38:51 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=953</guid>
		<description><![CDATA[CodeIgniter is my favorite web application framework for PHP and Netbeans is the IDE I use for all sorts of web development. The latest version of Netbeans IDE (6.9) has support for both Symfony and Zend Framework. But it still &#8230; <a href="http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter is my favorite web application framework for PHP and Netbeans is the IDE I use for all sorts of web development. The latest version of Netbeans IDE (6.9) has support for both Symfony and Zend Framework. But it still has no official support for CodeIgniter. So, in the default installation, you will always miss the fantastic code completion feature of the IDE.</p>
<p>After Googling a while, I just learned a magic trick that can emulate this feature in Netbeans. The process is pretty simple. We feed Netbeans a php file that has a simple sample &#8220;Controller&#8221; class definition that has phpdoc specifying the necessary properties. We put this file in a place readable by the IDE by invisible or worthless for the CodeIgniter framework. The &#8220;nbproject&#8221; directory inside the project root could be a good place to put this file. What really happens is that Netbeans reads the phpdoc and offers the completion of the specified properties in any class that extends the Controller class. Hiding it from CodeIgniter helps not to mess up with the system.</p>
<p>This is what I did. I created a php file and named it &#8220;nb.php&#8221;. I filled this file with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
* @property CI_Loader $load
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Email $email
* @property CI_DB_active_record $db
* @property CI_DB_forge $dbforge
* @property CI_Table $table
* @property CI_Session $session
* @property CI_FTP $ftp
* ....
*/</span>
<span style="color: #000000; font-weight: bold;">Class</span> Controller <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And put the file inside my nbproject directory. Now I am getting code completion in my Netbeans for CodeIgniter. </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/06/16/codeigniter-code-completion-with-the-netbeans-ide-for-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Changing Font Style in PHP Generated Image</title>
		<link>http://masnun.com/blog/2010/06/11/changing-font-style-in-php-generated-image/</link>
		<comments>http://masnun.com/blog/2010/06/11/changing-font-style-in-php-generated-image/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 18:20:15 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=949</guid>
		<description><![CDATA[To change the font style, you need to use different fonts. You can use the imagettftext() function to draw text on a php generated image using GD. Here&#8217;s a code snippet: &#60;?php header&#40;'Content-type: image/png'&#41;; $im = imagecreatetruecolor&#40;400, 300&#41;; $white = &#8230; <a href="http://masnun.com/blog/2010/06/11/changing-font-style-in-php-generated-image/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To change the font style, you need to use different fonts. You can use the imagettftext() function to draw text on a php generated image using GD. Here&#8217;s a code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$white</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$grey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">128</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">128</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$black</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagefilledrectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">399</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">299</span><span style="color: #339933;">,</span> <span style="color: #000088;">$white</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'maSnun'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">180</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">130</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Have a look at the function&#8217;s doc on php.net to learn more. <a href="http://www.php.net/imagettftext">http://www.php.net/imagettftext</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>It&#8217;s not that hard! Put the file in the www directory of a ubuntu LAMP server and visit the url on a web browser <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/06/11/changing-font-style-in-php-generated-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Facebook Graph API</title>
		<link>http://masnun.com/blog/2010/04/30/using-the-facebook-graph-api/</link>
		<comments>http://masnun.com/blog/2010/04/30/using-the-facebook-graph-api/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 20:20:01 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=902</guid>
		<description><![CDATA[I caught viral fever and decided to take the day off from work. To pass my leisure I decided to play with the Facebook APIs. I noticed that Facebook Platform has changed a lot. They have released the new &#8220;php-sdk&#8221; &#8230; <a href="http://masnun.com/blog/2010/04/30/using-the-facebook-graph-api/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I caught viral fever and decided to take the day off from work. To pass my leisure I decided to play with the Facebook APIs. I noticed that Facebook Platform has changed a lot. They have released the new &#8220;php-sdk&#8221; to let the devlopers integrate facebook into their own sites. Actually, they have released SDKs for other languages too (namely Python and JS). For playing with the toys at hand, I picked up the php-sdk and started browsing through the docs. Amazingly, Facebook has launched OAuth support. I am very happy about that. I no longer need to run my applications inside the facebook frame. Rather I can customize my contents for the facebook users. This is plain cool!</p>
<p>I downloaded the php-sdk and started off. But soon, I faced problem. The php-sdk is not well documented (in my opinion) and I had a very hard time figuring things out. It became even worse when I failed to test some of the features which are tightly integrated deep inside facebook. For example, I couldn&#8217;t find a way to construct some advanced URLs and also the sdk was not suitable for my debugging needs. The sdk is not poor, I later found it out to be strong but the main problem is it&#8217;s not much documented.</p>
<p>So, to try out things and to figure out how the Facebook OAuth works, I started writing my own codes. That helped though I struggled a bit to setup permissions. When I saw that the code is working fine, I chose to pack it up in a class file and rewrite the testing environment.</p>
<p>It took me 30 minutes to rewrite everything up. The package now contains the library and a console to test different methods.</p>
<p>You can download it from: <a href="http://masnun.googlecode.com/files/facebook-graph_API-oauth.zip">http://masnun.googlecode.com/files/facebook-graph_API-oauth.zip</a></p>
<p>Extract it into a directory on your website. Register a facebook application. Go through the traditional setup. Please remember to add your domain name on the Connect tab of the application you created <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Edit the config.php and visit the index.php using your browser. You&#8217;ll be redirected to Facebook without a word. When you authorize and return, you get a fine console to test things out and see for yourself! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Lets see a quick intro to the library (facebook.php) <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Facebook requires you to redirect the user to an authorization URL with your client id and the callback url. So, we first do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Construct a Facebook object with your app id and secret</span>
<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$client_secret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Get the authorization url. $perms is an array of extended permission. See config.php</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAuthorizeUrl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback_url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$perms</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Redirect the user to that url</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">{$url}</span> &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You have to ask for permissions on Authorization. I couldn&#8217;t get to make the user extend permissions on the post authorization phase. So, I have included **ALL** available permissions in the config.php. Permission is what I suffered with most. If you use my library, it&#8217;ll ask the user for all permissions so that you can test everything out. I know you won&#8217;t need all those permissions in production environment. Just comment out the ones you don&#8217;t want! </p>
<p>Facebook returns the user to the $callback_url with a GET parameter named &#8220;code&#8221; with others. By using this code with the application secret and callback url, we can get the access_token for the user <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We can do that easily using the client :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><span style="color: #000088;">$client_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$client_secret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$callback_url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call_api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/me/feed&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;message=Hello, Facebook!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>getAccessToken() retrieves the access_token from the facebook server. setAccessToken() adds the token to the facebook object and makes it ready to make api calls.</p>
<p>The $data is an array with the keys &#8211; access_token and expires. After we set the access token, we can make API calls from the client. For the details on API Paths, please visit: <a href="http://developers.facebook.com/docs/api">http://developers.facebook.com/docs/api</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I really liked the new structure of the facebook API. The previous API was bloated and sometimes very hard to implement. I do thank Facebook very much for making things easy for the developers! </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/04/30/using-the-facebook-graph-api/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Setting Up Twitter Bots with OAuth</title>
		<link>http://masnun.com/blog/2010/04/30/setting-up-twitter-bots-with-oauth/</link>
		<comments>http://masnun.com/blog/2010/04/30/setting-up-twitter-bots-with-oauth/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 02:43:56 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=889</guid>
		<description><![CDATA[Twitter has decided to kill Basic Authentication on the Twitter API from June 30. They have setup a nice website at http://www.countdowntooauth.com/ to let you all know and help you migrate your apps to use the OAuth OAuth is cool. &#8230; <a href="http://masnun.com/blog/2010/04/30/setting-up-twitter-bots-with-oauth/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Twitter has decided to kill Basic Authentication on the Twitter API from June 30. They have setup a nice website at <a href="http://www.countdowntooauth.com/">http://www.countdowntooauth.com/</a> to let you all know and help you migrate your apps to use the OAuth <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>OAuth is cool. It&#8217;s safe and secure for the end user. It&#8217;s convenient for the developers as well. Basic Auth entirely depends on the username and password of the user. So, the developer can do whatever s/he wishes with the user account as long as the user doesn&#8217;t change the password. On the other hand, if the user for some reason changes his/her password, the application will no longer be able to access the account and provide the desired service. OAuth helps both parties here! When the user authenticates an app via OAuth, it provides the developer with an access token ( a key and a secret ) which is by no way related to the user&#8217;s password. It&#8217;s unique for every user and application pair. That is every user will have an unique access token only for that application. Now even if the user changes the password, the access token will remain unchanged. The developer can safely store the token and use that to access the user&#8217;s account without hassle. Similarly, if the user wants to revoke the access permitted to an application, he or she can easily do that. In that case, the access token becomes invalid and the application loses access to that account.</p>
<p>In the Basic Auth age, it was very easy to develop twitter bots. You just setup the username and password into a configuration file, call the REST API with the login details and you&#8217;re done! Yeah, it was quite easy. But it&#8217;s not harder now <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Don&#8217;t fret, OAuth is also very simple and easy to implement for twitter bots. While you need to go through a two phase OAuth dance to authorize other users, Twitter displays the access token of the developer directly into the dashboard! Thanks to Twitter for making things so plain for developers! With your own access token, you can authorize your apps directly without any further verification.</p>
<p>To get the access token, first go to : <a href="http://dev.twitter.com">http://dev.twitter.com</a>. Login if you&#8217;re not already logged in. Use the twitter ID you want to run as a bot. Go to <a href="http://dev.twitter.com/apps">http://dev.twitter.com/apps</a> by clicking the &#8220;Your Apps&#8221; on top right corner. You will see a list of applications under the logged in twitter account. One big advantage of the basic auth was that you didn&#8217;t need to create applications. But now you need! Create an application if you don&#8217;t already have one created. In most cases you won&#8217;t have one since this is probably the first time you&#8217;re using OAuth. In that situation, please create an application. Note down the Consumer Key and Consumer Secret after visiting the application page by clicking on any of the application name. Now, on the right hand navigation bar, you&#8217;ll see &#8220;My Access Token&#8221;. Please visit that section and retrieve your Access Token and Access Token Secret. That&#8217;s all we needed. Now let&#8217;s do some coding to demonstrate the use of these keys and secrets.</p>
<p>We first need to get a Twitter Client library. If you&#8217;re already using one, just check to make sure that it has OAuth support. The work flow is simple. First construct the client with the consumer key and consumer secret. Then set the access token key and the access token secret. Now use the client to make Twitter API calls, in our case, to update statuses! </p>
<p>You can get the OAuth libraries from : <a href="http://dev.twitter.com/pages/oauth_libraries">http://dev.twitter.com/pages/oauth_libraries</a> . But I recommend using <a href="http://github.com/joshthecoder/tweepy">Tweepy</a> with Python and <a href="http://github.com/abraham/twitteroauth">Abraham&#8217;s TwitterOAuth</a> with PHP . They are not generic OAuth clients. They were built for Twitter and you don&#8217;t need to configure any extra parameters to make it work with Twitter. </p>
<p>Here&#8217;s the code samples on how to use the libraries to update status via OAuth.</p>
<p><strong>PHP</strong> (Abraham&#8217;s TwitterOAuth)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$consumer_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$consumer_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$access_key</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$access_secret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitteroauth/twitteroauth.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterOAuth <span style="color: #009900;">&#40;</span><span style="color: #000088;">$consumer_key</span> <span style="color: #339933;">,</span><span style="color: #000088;">$consumer_secret</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$access_key</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$access_secret</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Hello Twitter OAuth!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Python</strong> (Tweepy)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">consumer_key = <span style="color: #483d8b;">&quot;&quot;</span>
consumer_secret = <span style="color: #483d8b;">&quot;&quot;</span>
access_token = <span style="color: #483d8b;">&quot;&quot;</span>
access_token_secret = <span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
auth = tweepy.<span style="color: black;">OAuthHandler</span><span style="color: black;">&#40;</span>consumer_key, consumer_secret<span style="color: black;">&#41;</span>
auth.<span style="color: black;">set_access_token</span><span style="color: black;">&#40;</span>access_token, access_token_secret<span style="color: black;">&#41;</span>
bot = tweepy.<span style="color: black;">API</span><span style="color: black;">&#40;</span>auth<span style="color: black;">&#41;</span>
&nbsp;
bot.<span style="color: black;">update_status</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello Twitter OAuth!&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/04/30/setting-up-twitter-bots-with-oauth/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Gedit as a PHP IDE</title>
		<link>http://masnun.com/blog/2010/04/10/using-gedit-as-a-php-ide/</link>
		<comments>http://masnun.com/blog/2010/04/10/using-gedit-as-a-php-ide/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 08:25:07 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=845</guid>
		<description><![CDATA[I&#8217;ve been using Ubuntu 9.04 as my primary OS for a while now. I love the power and flexibility of this free and open source OS. Besides PHP, I code Python mainly. I use the Netbeans IDE for PHP and &#8230; <a href="http://masnun.com/blog/2010/04/10/using-gedit-as-a-php-ide/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Ubuntu 9.04 as my primary OS for a while now. I love the power and flexibility of this free and open source OS. Besides PHP, I code Python mainly. I use the Netbeans IDE for PHP and the built in Gedit editor for editing all other sorts of text files and scripts. I like the simplicity and lightweight nature of this editor. Netbeans IDE is very good for web application development. Specially, I have always enjoyed the project management features for easy management of my different projects. The main reason I have been using Netbeans is the Alt+Shift+F command. The formatting option that reformats my entire page with appropriate indentation and makes it readable. Yes, it is cool! But I hate the sluggishness of Netbeans. I know, this is the fault of the slow JVM. Also, when Netbeans lose the focus and regains later, I need to right click or interact with the GUI before I can start typing. This was pissing me off. So, I started using Gedit for quick fixes and hacks. I like the font of the editor, not to mention the cool color schemes. I was wondering if there were any plugins for Gedit to format php codes like Netbeans.</p>
<p>No, there is no dedicated plugin for that. But Gedit has the ability to use external tools to interact with the documents. I installed the php_beautifier pear package and used it with Gedit to partially achieve what I was looking for.</p>
<p>1) I downloaded the PHP_Beautifier package from PHP Pear (http://pear.php.net)<br />
2) Installed it by typing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> Desktop
<span style="color: #c20cb9; font-weight: bold;">sudo</span> pear <span style="color: #c20cb9; font-weight: bold;">install</span> PHP_Beautifier-0.1.14.tgz</pre></div></div>

<p>The pear package installed a command line utility &#8220;php_beautifier&#8221; which lets us beautify php codes.</p>
<p>3) Open Gedit. Go to: Edit > Preferences. Visit the &#8220;Plugins&#8221; tab and activate the External Tools command.</p>
<p>4) The plugin will enable you to let external commands help you process the document. Let&#8217;s build our php beautifier for Gedit.</p>
<p>5) Go to: Tools > External Tools. Click &#8220;New&#8221;. Fill up the form like below:<br />
Description: PHP Beautifier<br />
Shortcut Key:<br />
Commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php_beautifier <span style="color: #660033;">-l</span> <span style="color: #ff0000;">&quot;Pear()&quot;</span></pre></div></div>

<p>Input: Current Document<br />
Output: Replace Current Document<br />
Applicability: All documents.</p>
<p>You can click on the &#8220;New Tool&#8221; label to rename the tool. Let&#8217;s rename it to &#8220;PHP Beautify&#8221; and close the dialog box.</p>
<p>Now, we are ready to beautify our php codes from Gedit. Just type in some php codes. Go to: Tools > PHP Beautify and see the output. Please Save the document. You can&#8217;t edit the document unless you save after the processing.</p>
<p>PS: Please remember that, it beautifies php only. It will not be able to beautify inline html and php together. I am looking for some command line tool that can help me achieve that. And then, I will say goodbye to Netbeans and stick to Gedit <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/04/10/using-gedit-as-a-php-ide/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Power of PHP: Resizing Images on Command Line</title>
		<link>http://masnun.com/blog/2010/04/03/power-of-php-resizing-images-on-command-line/</link>
		<comments>http://masnun.com/blog/2010/04/03/power-of-php-resizing-images-on-command-line/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 08:57:00 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=843</guid>
		<description><![CDATA[I&#8217;m too busy to explain the script now. In short, it scans the current directory for all the JPG images and converts them into smaller image files hardly compromising the quality. I managed to convert a 211 MB album into &#8230; <a href="http://masnun.com/blog/2010/04/03/power-of-php-resizing-images-on-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m too busy to explain the script now. In short, it scans the current directory for all the JPG images and converts them into smaller image files hardly compromising the quality. I managed to convert a 211 MB album into a 5.8 MB collection with this script. Modify the $dir varible which holds the location of target directory. Make sure the target directory already exists. Also change the $percent inside the resize function to control the output quality.</p>
<p>Thanks to PHP for such powerful image processing. I just ran the following command on my Ubuntu terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>photos
php img.php</pre></div></div>

<p>I was done! Here&#8217;s the source code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/home/masnun/Desktop/photos/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">glob</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*.JPG&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; to process <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$files</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Processing: <span style="color: #006699; font-weight: bold;">{$file}</span> ....&quot;</span><span style="color: #339933;">;</span>
        resize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; -- done <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$new_loc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$constrain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get image size of img</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// image width</span>
<span style="color: #000088;">$sw</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// image height</span>
<span style="color: #000088;">$sh</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$percent</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// calculate resized height and width if percent is defined</span>
	<span style="color: #000088;">$percent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$percent</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.01</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sw</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$percent</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sh</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$percent</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span> AND <span style="color: #339933;">!</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// autocompute height if only width is set</span>
		<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> AND <span style="color: #339933;">!</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// autocompute width if only height is set</span>
		<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$constrain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// get the smaller resulting image dimension if both height</span>
		<span style="color: #666666; font-style: italic;">// and width are set and $constrain is also set</span>
		<span style="color: #000088;">$hx</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$hx</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$hx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wx</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$wx</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$wx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hx</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sh</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">.01</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">round</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sw</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ImageCreateFromJPEG</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> or <span style="color: #666666; font-style: italic;">// Read JPEG Image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ImageCreateFromPNG</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> or <span style="color: #666666; font-style: italic;">// or PNG Image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ImageCreateFromGIF</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span> or <span style="color: #666666; font-style: italic;">// or GIF Image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// If image is not JPEG, PNG, or GIF</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// We get errors from PHP's ImageCreate functions...</span>
	<span style="color: #666666; font-style: italic;">// So let's echo back the contents of the actual image.</span>
	<span style="color: #990000;">readfile</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Create the resized image destination</span>
	<span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ImageCreateTrueColor</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Copy from image source, resize it, and paste to image destination</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">ImageCopyResampled</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sw</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Output resized image</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">ImageJPEG</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_loc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/04/03/power-of-php-resizing-images-on-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending SMS With AloAshbei Platform (GP APIs) and PHP</title>
		<link>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/</link>
		<comments>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 12:41:21 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=833</guid>
		<description><![CDATA[Here&#8217;s a working example of Grameen Phone&#8217;s AloAshbei Platform. &#160; &#60;?php /* * Demo of the SMS API * Author: maSnun * URL: http://masnun.com */ &#160; &#160; // I hosted the WSDL on my own host $soap = new SoapClient&#40;&#34;http://masnun.com/wsdl/wsdl.php&#34;&#41;; &#8230; <a href="http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a working example of Grameen Phone&#8217;s AloAshbei Platform.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
* Demo of the SMS API
* Author: maSnun
* URL: http://masnun.com
*/</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// I hosted the WSDL on my own host</span>
<span style="color: #000088;">$soap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://masnun.com/wsdl/wsdl.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the parameters in an array</span>
&nbsp;
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'registrationID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;masnun&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;******&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sourceMsisdn'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'8801711960803'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'destinationMsisdn'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'88017********'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'smsPort'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7424</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msgType'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'charge'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color:#800080;">2.00</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'chargedParty'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'8801711960803'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'contentArea'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gpgp_psms'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msgContent'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello GP API!'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
try <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$soap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendSMS</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SendSMSRequest&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Example Response:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&nbsp;
masnun@ubuntu:~$ cd random
masnun@ubuntu:~/random$ php gpsoap.php
object(stdClass)#2 (1) {
  [&quot;SendSMSResponse&quot;]=&gt;
  object(stdClass)#3 (2) {
    [&quot;status&quot;]=&gt;
    string(2) &quot;OK&quot;
    [&quot;msgID&quot;]=&gt;
    string(17) &quot;20100204183047653&quot;
  }
}
masnun@ubuntu:~/random$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A reflect() Function For Quick Reflection in PHP</title>
		<link>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/</link>
		<comments>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 15:25:43 +0000</pubDate>
		<dc:creator>masnun</dc:creator>
				<category><![CDATA[Blog Post]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=798</guid>
		<description><![CDATA[The Reflection API is the perfect way to reverse engineer and inspect php objects and functions. I have written a function to quickly pass params to the Reflection API and get things done. Here&#8217;s the source codes: &#160; &#60;?php &#160; &#8230; <a href="http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Reflection API is the perfect way to reverse engineer and inspect php objects and functions. I have written a function to quickly pass params to the Reflection API and get things done.</p>
<p>Here&#8217;s the source codes:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> reflect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>Reflecting: <span style="color: #006699; font-weight: bold;">{$data}</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> Reflection<span style="color: #339933;">::</span><span style="color: #004000;">export</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> Reflection<span style="color: #339933;">::</span><span style="color: #004000;">export</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionFunction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
