<?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>swape.net &#187; Scripts</title>
	<atom:link href="http://www.swape.net/w/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.swape.net/w</link>
	<description>alireza balouch</description>
	<lastBuildDate>Thu, 05 Apr 2012 11:42:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Function Caching</title>
		<link>http://www.swape.net/w/2012/04/function-caching/</link>
		<comments>http://www.swape.net/w/2012/04/function-caching/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 11:42:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.swape.net/w/?p=184</guid>
		<description><![CDATA[Many PHP caching systems like Vanish or others are great for less dynamic sites. I could not find any so I made my own. But you should always use it when the output of the function do not change so much in caching time. And the output is just a text. You can not use [...]]]></description>
			<content:encoded><![CDATA[<p>Many PHP caching systems like Vanish or others are great for less dynamic sites. I could not find any so I made my own.<br/><br />
But you should always use it when the output of the function do not change so much in caching time. And the output is just a text.<br/><br />
You can not use it if the function returns an array or object. But if it returns an array you can make another wrapper function to convert it from and to JSON instead of an array.<br />
<br/><br/></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw2">public</span> <span class="kw2">function</span> ccache<span class="br0">&#40;</span><span class="re0">$arrCallable</span> ,<span class="re0">$strFilename</span> , <span class="re0">$intTTL</span> = <span class="st0">&#8217;10 min ago&#8217;</span> &nbsp;, <span class="re0">$arrParameter</span> = <span class="st0">&#8221;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// custom cache by Alireza Balouch</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strReturn</span> = <span class="st0">&#8221;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strCCpath</span> = <span class="st0">&#8216;/tmp/mem/&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strFile</span> = <span class="re0">$strCCpath</span> . <span class="st0">&#8216;ccache_&#8217;</span> . <a href="http://www.php.net/md5"><span class="kw3">md5</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;REQUEST_URI&#8217;</span><span class="br0">&#93;</span> . <span class="re0">$strFilename</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$strFile</span><span class="br0">&#41;</span> and <a href="http://www.php.net/filemtime"><span class="kw3">filemtime</span></a><span class="br0">&#40;</span><span class="re0">$strFile</span><span class="br0">&#41;</span> &gt;= <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="re0">$intTTL</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strReturn</span> = <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$strFile</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/is_callable"><span class="kw3">is_callable</span></a><span class="br0">&#40;</span><span class="re0">$arrCallable</span> <span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$arrParameter</span> == <span class="st0">&#8221;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strReturn</span> = <a href="http://www.php.net/call_user_func"><span class="kw3">call_user_func</span></a><span class="br0">&#40;</span><span class="re0">$arrCallable</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strReturn</span> = <a href="http://www.php.net/call_user_func_array"><span class="kw3">call_user_func_array</span></a><span class="br0">&#40;</span><span class="re0">$arrCallable</span> , <span class="re0">$arrParameter</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file_put_contents<span class="br0">&#40;</span><span class="re0">$strFile</span>, <span class="re0">$strReturn</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sf_tools::<span class="me2">ccache_Clean</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// this should be from cron</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strReturn</span> = <span class="st0">&#8216;not callable&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$strReturn</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> ccache_Clean<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// mkdir mem</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// mount -t ramfs -o size=250M ramfs /tmp/mem</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// chown www-data mem</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strCCpath</span> = <span class="st0">&#8216;/tmp/mem/&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$arrDir</span> = scandir<span class="br0">&#40;</span><span class="re0">$strCCpath</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$arrDir</span> <span class="kw1">as</span> <span class="re0">$row</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$row</span>, <span class="nu0">0</span> ,<span class="nu0">1</span><span class="br0">&#41;</span> == <span class="st0">&#8216;.&#8217;</span> OR <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$row</span>, <span class="nu0">0</span> ,<span class="nu0">7</span><span class="br0">&#41;</span> != <span class="st0">&#8216;ccache_&#8217;</span> <span class="br0">&#41;</span><span class="br0">&#123;</span><span class="kw1">continue</span>;<span class="br0">&#125;</span> <span class="co1">// skip the . and non ccache_</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$strFile</span> = <span class="re0">$strCCpath</span> . <span class="re0">$row</span> ;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/filemtime"><span class="kw3">filemtime</span></a><span class="br0">&#40;</span><span class="re0">$strFile</span><span class="br0">&#41;</span> &lt;= <a href="http://www.php.net/strtotime"><span class="kw3">strtotime</span></a><span class="br0">&#40;</span><span class="st0">&#8217;4 hour ago&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="st0">&#8216;mv &#8216;</span> . <span class="re0">$strFile</span> . <span class="st0">&#8216; &#8216;</span> . <span class="re0">$strCCpath</span> . <span class="st0">&#8216;old &amp;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>&nbsp;<br />
<br/><br />
<strong>How it works</strong></p>
<p>
- First you have to put those 2 functions in a class. I have a utility class that I put all those small handy functions in.<br/><br />
- Now log in to your server and make a directory under /tmp called /tmp/mem/<br/><br />
- if you have lots of memory on your server you should mount ramfs to improve the speed. just use <em>mount -t ramfs -o size=250M ramfs /tmp/mem</em> . I assign 250Mb to that. but watch out to not to store bigger files there so it do not exceeds the limit.<br/><br />
- in my UBUNTU server, apache runs as www-data so I changing the owner to www-data. <em>chown www-data /tmp/mem</em><br/>
</p>
<p>Now we have set it up,so lets use it.<br />
<br/><br/><br />
I have put those functions in my sf_tools class. So when I need to call up the caching system I use sf_tools::ccache(array($this , &#8216;functionName&#8217;) , $strUniqueCachName , &#8217;10 min ago&#8217; );<br />
<br/><br/><br />
array($this , &#8216;functionName&#8217;) is the class function I want to cache. So normally I would call it like this <em>$this-&gt;functionName()</em><br />
<br/><br/><br />
The second parameter is the unique name for that function so we do not end up overwriting or using the wrong function cache output.<br />
<br/><br/><br />
The third is the parameter that feeds the strtotime(). It tells it how long to store the cache. You can use sentences like &#8220;10 min ago&#8221; or &#8220;-1 hour&#8221; &#8230; check the function sepcs on php.net site. I don&#8217;t use more than 10 min by default.<br />
<br/><br/><br />
The fourth parameter is the array of parameters to pass to that function that are being cached.<br />
<br/><br/><br />
So if you normally call it like this: $this-&gt;myCoolFunction($intID,$strText);<br />
, then the caching would be like this:<br/></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">sf_tools::<span class="me2">ccache</span><span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$this</span> , <span class="st0">&#8216;myCoolFunction&#8217;</span><span class="br0">&#41;</span> , <span class="st0">&#8216;myCoolFunction&#8217;</span> . <span class="re0">$intID</span> . <span class="re0">$strText</span> , <span class="st0">&#8217;10 min ago&#8217;</span> , <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$intID</span>,<span class="re0">$strText</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><br/><br/><br />
I use this when I have to do lots of number crunching or when I getting data from other servers by API.<br/><br />
It is much faster and server can save those CPU and Disk resources for other things ;)<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.swape.net/w/2012/04/function-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>niceUpload</title>
		<link>http://www.swape.net/w/2011/03/niceupload/</link>
		<comments>http://www.swape.net/w/2011/03/niceupload/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 19:23:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plug-ins]]></category>

		<guid isPermaLink="false">http://www.swape.net/w/?p=175</guid>
		<description><![CDATA[NiceUpload is a jQuery plug ins that replace the normal file input and makes it much more prettier.  You can adjust and tweak it with CSS if you want. See the demo here: http://lab.swape.net/niceUpload.1.0/ niceUpload.1.0.zip]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-176" title="Screen shot 2011-03-29 at 9.22.32 PM" src="http://www.swape.net/w/wp-content/uploads/2011/03/Screen-shot-2011-03-29-at-9.22.32-PM-300x97.png" alt="" width="300" height="97" />NiceUpload is a jQuery plug ins that replace the normal file input and makes it much more prettier.  You can adjust and tweak it with CSS if you want.</p>
<p>See the demo here: <a href="http://lab.swape.net/niceUpload.1.0/" target="_blank">http://lab.swape.net/niceUpload.1.0/</a></p>
<p><a href="http://lab.swape.net/niceUpload.1.0/niceUpload.1.0.zip" class="download">niceUpload.1.0.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.swape.net/w/2011/03/niceupload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multitag</title>
		<link>http://www.swape.net/w/2011/03/multitag/</link>
		<comments>http://www.swape.net/w/2011/03/multitag/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 19:17:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plug-ins]]></category>

		<guid isPermaLink="false">http://www.swape.net/w/?p=170</guid>
		<description><![CDATA[Multitag is a jQuery plug ins for making nice tag boxes. Click on the box and start writing a tag names and then press the “,” (comma) or enter button to make a tag See the demo here: http://lab.swape.net/multitag.1.0/ &#160; You can download the source from here https://github.com/swape/multitag]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-171" title="Screen shot 2011-03-29 at 9.12.58 PM" src="http://www.swape.net/w/wp-content/uploads/2011/03/Screen-shot-2011-03-29-at-9.12.58-PM-300x189.png" alt="" width="240" height="151" />Multitag is a jQuery plug ins for making nice tag boxes.<br />
Click on the box and start writing a tag names and then press the “,” (comma) or enter button to make a tag</p>
<p>See the demo here: <a href="http://lab.swape.net/multitag.1.0/" target="_blank">http://lab.swape.net/multitag.1.0/</a></p>
<p>&nbsp;</p>
<p>You can download the source from here <a href="https://github.com/swape/multitag">https://github.com/swape/multitag</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.swape.net/w/2011/03/multitag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swape Gallery Light</title>
		<link>http://www.swape.net/w/2009/08/swape-gallery-light/</link>
		<comments>http://www.swape.net/w/2009/08/swape-gallery-light/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 19:40:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SGL is a php5 script to list pictures. A fat way of making a galery and showing your pictures. This script finds all the pictures in a directory under ./test_pic/ and makes menus based on directories. All you have to do is putt your pictures in ./test_pic/ directory. Or edit $strPathToFiles = &#8216;./test_pic&#8217;; in sgl4.class.php [...]]]></description>
			<content:encoded><![CDATA[<p>SGL is a php5 script to list pictures. A fat way of making a galery and showing your pictures.</p>
<p>This script finds all the pictures in a directory under <strong>./test_pic/</strong> and makes menus based on directories.</p>
<p>All you have to do is putt your pictures in <strong>./test_pic/</strong><strong></strong> directory. Or edit <strong>$strPathToFiles = &#8216;./test_pic&#8217;;</strong> in <strong>sgl4.class.php</strong> file.</p>
<p>You can organize your pictures by category, by putting it under sub-directories.</p>
<p>The thumbs/ directory must be writable (CHMOD 755) to generate thumbnails automatically first time you visit the site. It will help loading your images faster.</p>
<p><strong>HOW TO INSTALL</strong></p>
<p>All you have to do is unzip the file.<br />
Unpack the <strong>sgl4.php</strong> and configure the paths.</p>
<p>Putt your pictures under <strong>./</strong><strong>test_pic</strong><strong>/</strong> directory.<br />
And don&#8217;t forget to <em>chmod 755</em> thumbs directory.</p>
<p><strong>SYSTEM REQUIRED.</strong></p>
<p>Server with PHP5.</p>
<p><a class="download" href="http://www.swape.net/w/wp-content/uploads/2009/08/sgl4.zip">sgl4.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.swape.net/w/2009/08/swape-gallery-light/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>favicon2png</title>
		<link>http://www.swape.net/w/2008/02/favicon2png/</link>
		<comments>http://www.swape.net/w/2008/02/favicon2png/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 20:22:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Here is a script to download the favicon.ico files from a website and save it as a png file. You must have imagemagick installed on your server to convert the ico file to png. &#160; &#60;!&#8212; html code &#8212;-&#62; &#60;form action=&#34;?&#34; method=&#34;post&#34;&#62; &#160; &#60;input id=&#34;site&#34; name=&#34;site&#34; type=&#34;text&#34; value=&#34;&#60;?php echo $_POST['site']; ?/&#62;&#34; /&#62; &#160; &#60;input type=&#34;submit&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a script to download the favicon.ico files from a website and save it as a png file.</p>
<p>You must have imagemagick installed on your server to convert the ico file to png.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;!&#8212; html code &#8212;-&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;form action=<span class="st0">&quot;?&quot;</span> method=<span class="st0">&quot;post&quot;</span>&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;input id=<span class="st0">&quot;site&quot;</span> name=<span class="st0">&quot;site&quot;</span> type=<span class="st0">&quot;text&quot;</span></div>
</li>
<li class="li2">
<div class="de2">value=<span class="st0">&quot;&lt;?php echo $_POST['site']; ?/&gt;&quot;</span> /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;input type=<span class="st0">&quot;submit&quot;</span> /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt; ?php</div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//&#8212; favicon2png by Alireza Balouch @ swape.net 2008</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;site&#8217;</span><span class="br0">&#93;</span> != <span class="st0">&#8221;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//finding the hostname</span></div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$host</span> = <a href="http://www.php.net/parse_url"><span class="kw3">parse_url</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;site&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$host</span> = <span class="re0">$host</span><span class="br0">&#91;</span><span class="st0">&#8216;host&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$host</span> = <a href="http://www.php.net/explode"><span class="kw3">explode</span></a><span class="br0">&#40;</span><span class="st0">&#8216;.&#8217;</span> , <span class="re0">$host</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$host</span> = <span class="re0">$host</span><span class="br0">&#91;</span><a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$host</span><span class="br0">&#41;</span> <span class="nu0">-2</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$filename</span> = <span class="st0">&#8216;img/&#8217;</span> . <span class="re0">$host</span> . <span class="st0">&#8216;.png&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/is_file"><span class="kw3">is_file</span></a><span class="br0">&#40;</span><span class="re0">$filename</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// getting the favicon</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$handle</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span> <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;site&#8217;</span><span class="br0">&#93;</span> . <span class="st0">&#8216;/favicon.ico&#8217;</span>, <span class="st0">&quot;rb&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$contents</span> = stream_get_contents<span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$handle</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">file_put_contents<span class="br0">&#40;</span><span class="st0">&#8216;fav.ico&#8217;</span> , <span class="re0">$contents</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// converting to png</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$StrExec</span> = <span class="st0">&#8216;/usr/local/bin/convert fav.ico -resize 24&#215;24<span class="es0">\></span> &#8216;</span> . <span class="re0">$filename</span> ;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$ret</span> = <a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="re0">$StrExec</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;img src=&quot;&#8217;</span> . <span class="re0">$filename</span> . <span class="st0">&#8216;&quot; /&gt;&#8217;</span> . <span class="re0">$_POST</span><span class="br0">&#91;</span><span class="st0">&#8216;site&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.swape.net/w/2008/02/favicon2png/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

