<?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>AjaxMasters Blog &#187; Tutorial</title> <atom:link href="http://blog.ajaxmasters.com/category/tutorial/feed/" rel="self" type="application/rss+xml" /><link>http://blog.ajaxmasters.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Fri, 27 Jan 2012 15:44:56 +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>Google Font Directory</title><link>http://blog.ajaxmasters.com/google-font-directory/</link> <comments>http://blog.ajaxmasters.com/google-font-directory/#comments</comments> <pubDate>Wed, 19 May 2010 23:37:17 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Trends]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[css]]></category> <category><![CDATA[directory]]></category> <category><![CDATA[fonts]]></category> <category><![CDATA[google]]></category> <category><![CDATA[layout]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=381</guid> <description><![CDATA[I just watched a video from nettuts where they show the new Google Font Directory and how easy it is to use it. I just had to share this with you guys. Here is the video And the links to the font directory: Google Font Directory and a tutorial on...]]></description> <content:encoded><![CDATA[<p>I just watched a video from <a
href="http://net.tutsplus.com/" target="_blank">nettuts</a> where they show the new <a
href="http://code.google.com/webfonts" target="_blank">Google Font Directory</a> and how easy it is to use it. I just had to share this with you guys.</p><p>Here is the video<br/><br
/> <object
width="600" height="385"><param
name="movie" value="http://www.youtube.com/v/ivhgb0urkFA&#038;hl=en_US&#038;fs=1&#038;"></param><param
name="allowFullScreen" value="true"></param><param
name="allowscriptaccess" value="always"></param><embed
src="http://www.youtube.com/v/ivhgb0urkFA&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="385"></embed></object></p><p>And the links to the font directory: <a
href="http://code.google.com/webfonts" target="_blank">Google Font Directory</a> and a tutorial on getting started: <a
href="http://code.google.com/apis/webfonts/docs/getting_started.html" target="_blank">tutorial</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/google-font-directory/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Awesome CSS+JS form styling</title><link>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/</link> <comments>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/#comments</comments> <pubDate>Tue, 09 Mar 2010 17:23:39 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[css]]></category> <category><![CDATA[form]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[js]]></category> <category><![CDATA[sexy]]></category> <category><![CDATA[styling]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=309</guid> <description><![CDATA[I was working on our new open source project that i think you will like and I was working on the registration page. This is what I got in the end and i will walk you trough the process with me. This new tutorial is about styling the forms of...]]></description> <content:encoded><![CDATA[<div
id="attachment_312" class="wp-caption alignleft" style="width: 310px"><a
href="http://blog.ajaxmasters.com/awesome-cssjs-form-styling/sexy-form/" rel="attachment wp-att-312"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2010/03/sexy-form-300x214.png" alt="Sexy CSS Form" title="sexy-form" width="300" height="214" class="size-medium wp-image-312" /></a><p
class="wp-caption-text">Sexy CSS+JS Form</p></div><p>I was working on our new open source project that i think you will like and I was working on the registration page. This is what I got in the end and i will walk you trough the process with me. This new tutorial is about styling the forms of your website, I find it very good looking and very simple to implement. We will use simple CSS and some JavaScript.</p><p>Usually for inserting text into the inputs or our forms we set the value attribute with the text and then use javascript to check for different scenarios for doing some fancy things. This is different we will use labels to fill the text and move them under the inputs and then just do our magic with JS.</p><p>The JavaScript library that we will use to create this effect for our forms is <a
href="http://jquery.com" target="_blank">Jquery</a></p><p><br/><br
/> <strong
class="in_title">1. Creating the markup!</strong><br
/> <br/></p><pre class="brush: xml; title: ; notranslate">
            &lt;div id=&quot;login&quot;&gt;
                &lt;div class=&quot;sayit&quot;&gt;Log In:&lt;/div&gt;
                &lt;form action=&quot;javascript:void(0)&quot; onsubmit=&quot;login()&quot; autocomplete=&quot;off&quot;&gt;
                    &lt;label for=&quot;username&quot;&gt;Username&lt;/label&gt;
                    &lt;input type=&quot;text&quot; id=&quot;username&quot;/&gt;
                    &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                    &lt;input type=&quot;password&quot; id=&quot;password&quot;/&gt;
                    &lt;input type=&quot;submit&quot; class=&quot;medium button green&quot; value=&quot;Log me In&quot;/&gt;
                &lt;/form&gt;
            &lt;/div&gt;
</pre><p>The above code is our markup and as you can see is very simple and it can be changed as you like because the code that we will use for checking for different scenarios in javascript will work without necessary classes or ids. We have 2 inputs and 2 labels, one is password one is text and we can work with these ones, you can add as many as you like.</p><p>Now let&#8217;s style these bastards! <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p><p><strong
class="in_title">2. Use CSS to style the form elements!</strong><br
/> <br/></p><pre class="brush: css; title: ; notranslate">
input[type=text],input[type=password]{padding: 5px 10px; background-color: transparent;	position: relative; z-index: 2;}
label{position: absolute; z-index: 1;-webkit-transition: opacity 0.15s linear; color: #bababa; background-color: #FFFFFF; }

#login{width: 290px; margin: 0 auto;}
#login input[type=text],#login input[type=password]{width:270px; margin: 5px 0; font-size: 24px; font-weight: bold; border: 1px solid #ccc; -moz-border-radius:5px; -webkit-border-radius:5px; color: #595959;}
#login label{font-size: 24px; margin: 14px 10px;}

#login .sayit{font-size:24px; color: #595959; font-style: italic; padding-bottom: 5px;}
</pre><p>What we did here is make the label absolute so it will go under the input. This is important you will have to place the label before the input so remember this! The input will have a position relative and a z-index of 2 so we can be sure it will land above the label. Next we define the login div by using his id(<i>#login</i>). We use CSS3 for creating the round borders for the input and style the label by setting a big font-size to fit the input. The rest is pretty obvious, if you have trouble understanding this then let us know in the comments.</p><p><strong
class="in_title">3. Make everything move with JS!</strong><br
/> <br/></p><pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
    $.string(String.prototype);
    $(&quot;input,textarea&quot;).each(function (type) {
        $(this).focus(function () {
            if($(this).val().blank())
                $(this).prev(&quot;label&quot;).fadeTo('fast',0.45);
        });

        $(this).keypress(function () {
            $(this).prev(&quot;label&quot;).fadeTo('fast',0);
        });

        $(this).blur(function () {
            if($(this).val().blank()){
                $(this).prev(&quot;label&quot;).fadeTo('fast',1);
            }
        });
    });
});
</pre><p>We use here jQuery of course that we add using the google api like this:</p><pre class="brush: xml; title: ; notranslate">
        &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js&quot;&gt;&lt;/script&gt;
</pre><p>And one plugin that I use to extend the jQuery string properties and that is <a
href="http://stilldesigning.com/dotstring/">$.string plugin</a>. After we do that we create the above code and we assign to input and textarea elements a focus, keypress and blur actions. We use the focus action to lower the labels opacity to 45% then on keypress we just hide it for good. Then on blur we check to see if anything was written in our sexy element and if not then we fade the label back to 100%. This is kind of everything we do here, pretty simple. <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><strong
class="in_title">4. Showing of a demo and download source</strong><br
/> <br/></p><p>I&#8217;ve set up a demo here: <a
href="http://tutorials.ajaxmasters.com/sexy-form/" target="_blank"><b><i>DEMO</i></b></a></p><p>The source code you can either pick it from the demo page or from here: <a
href="http://tutorials.ajaxmasters.com/sexy-form/source.zip"><b><i>SOURCE</i></b></a></p><p><strong
class="in_title">5. Wrapping up!</strong><br
/> <br/></p><p>So here is our nice form styling that you can use on your website and that can be done very easily. Feel free to leave us comments and suggestions. <b>Thanks a lot!</b></p><p>Have fun coding!</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/awesome-cssjs-form-styling/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Guide to a very fast website</title><link>http://blog.ajaxmasters.com/guide-to-a-very-fast-website/</link> <comments>http://blog.ajaxmasters.com/guide-to-a-very-fast-website/#comments</comments> <pubDate>Sat, 02 Jan 2010 23:53:25 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[code]]></category> <category><![CDATA[fast]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[php]]></category> <category><![CDATA[website]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=259</guid> <description><![CDATA[I was experimenting with new features for the past few weeks and while i was working on optimizing a website we are working on currently i was wondering what would it take to get a very big score on Yslow. But as Jeff says in this old post: &#8220;Yahoo&#8217;s Problems...]]></description> <content:encoded><![CDATA[<div
id="attachment_281" class="wp-caption alignleft" style="width: 138px"><a
href="http://blog.ajaxmasters.com/2010/01/02/guide-to-a-very-fast-website/1262476500_performance-systeme-os/" rel="attachment wp-att-281"><img
class="size-full wp-image-281" title="Performance" src="http://blog.ajaxmasters.com/wp-content/uploads/2010/01/1262476500_performance-systeme-OS.png" alt="Performance" width="128" height="128" /></a><p
class="wp-caption-text">Performance</p></div><p>I was experimenting with new features for the past few weeks and while i was working on optimizing a website we are working on currently i was wondering what would it take to get a very big score on <a
href="http://developer.yahoo.com/yslow/">Yslow</a>. But as Jeff says in <a
href="http://www.codinghorror.com/blog/archives/000932.html">this</a> old post: &#8220;Yahoo&#8217;s Problems Are Not Your Problems&#8221;. So i was just doing the usual putting the javascript files at the bottom, minify every single one of them. I usually use this website: <a
href="http://yui.2clics.net/">YUI Compressor Online</a>it always does the job for me.</p><p>What Yslow goes round and round is the cache system of the browser. So what you are actually doing is making everything cacheable and as small as possible so that the browser takes everything loading from one bite. The browsers have a limited number of requests that they address at once so if you can get into that margin then you are good. So very important <strong>combine every file and make is small!</strong> <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>What have i done is use the gzip module of the apache server by using php and a .htaccess file. I believe this is one of the most nice ways to take advantage of this feature without making any changes to your website. What it does is adding lines of code at the beginning of txt/html/htm/php files, css files and js files. After we do this we add a closing line at the end and we are good. Gzip is in place up and running.</p><p>How do we do it? Well here is the code:</p><pre class="brush: php; title: ; notranslate">&lt;FilesMatch &quot;\.(css)&quot;&gt;
    ForceType application/x-httpd-php
	php_value auto_prepend_file &quot;address-to-this-file/gzip/gzip-css.php&quot;
php_value auto_append_file &quot;address-to-this-file/gzip/gzip-end.php&quot;
&lt;/FilesMatch&gt;

&lt;FilesMatch &quot;\.(txt|html|htm|php)&quot;&gt;
    ForceType application/x-httpd-php
	php_value auto_prepend_file &quot;address-to-this-file/gzip/gzip-gen.php&quot;
php_value auto_append_file &quot;address-to-this-file/gzip/gzip-end.php&quot;
&lt;/FilesMatch&gt;

&lt;FilesMatch &quot;\.(js)&quot;&gt;
    ForceType application/x-httpd-php
	php_value auto_prepend_file &quot;address-to-this-file/gzip/gzip-js.php&quot;
php_value auto_append_file &quot;address-to-this-file/gzip/gzip-end.php&quot;
&lt;/FilesMatch&gt;</pre><p>The next step is a selective one since what we are doing is telling the browser to not look for a file until we tell it to. So if we set the expiration to 2 years from now the browser will always use the one it has in it&#8217;s cache until 2 years pass. <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><pre class="brush: php; title: ; notranslate">&lt;IfModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A86400
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
&lt;/IfModule&gt;
</pre><p>We check for the expires module and if it&#8217;s activated then we just set the expiration dates. What does &#8220;ExpiresByType text/css A17200&#8243; means? Css files &#8220;<strong>expire after 4.8 hours&#8221;</strong><br
/> &#8220;A&#8221; before the numbers above stands for Access. This means that the stopwatch starts when a client accesses the file. You can also use &#8220;M&#8221; for modified.</p><p
style="text-align: left;"><em><strong>TIME CHEAT SHEET</strong></em></p><ul><li><em>300 5 MIN</em></li><li><em> 600 10 MIN</em></li><li><em> 900 15 MIN</em></li><li><em> 1800 30 MIN</em></li><li><em> 2700 45 MIN</em></li></ul><ul><li><em>3600 1 HR</em></li><li><em>7200 2 HR</em></li><li><em>86400 24 HR</em></li></ul><ul><li><em>86400 1 DAY</em></li><li><em>604800 7 DAY</em></li></ul><ul><li><em>604800 1 WEEK</em></li><li><em>2419200 4 WEEK</em></li></ul><ul><li><em>2419200 1 MONTH (FEBRUARY)</em></li><li><em>2505600 1 MONTH (FEBRUARY LEAP YEAR)</em></li><li><em> 2592000 1 MONTH (APRIL, JUNE, SEPTEMBER, NOVEMBER)</em></li><li><em>2678400 1 MONTH (JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER)</em></li><li><em>31536000 12 MONTH</em></li></ul><p>Now just download this thing and get a faster website. The rest of the Yslow rules are pretty simple to follow so i just felt i would let you know what i use for these 2 because i found them hard to figure out than the rest.</p><hr
/><p><strong
class="in_title">Update</strong></p><p>Today I was trying to get the gzip code to work on our server and since we have a shared hosting here we are forced to comply with the rules. And guess what I get a &#8220;500&#8243; error. So i found a new way of doing the same thing. This as long as you have Rewrite_module activated if this is not activated then i don&#8217;t think you can do much of a thing.</p><p>Here it is the .htaccess code:</p><pre class="brush: php; title: ; notranslate">
RewriteRule ^.+\.(css|js|png|jpg|swf)$ gzip/compress.php [NC]
</pre><p>This will pass all files that are css, js, png, jpg, swf trough the compress.php file. And here is what the compress.php file does:</p><pre class="brush: php; title: ; notranslate">
&lt;?php
$basedir = $_SERVER['DOCUMENT_ROOT'];
$file = realpath( $basedir . $_SERVER[&quot;REQUEST_URI&quot;] );

if( !file_exists($file) &amp;&amp; strpos($file, $basedir) === 0 ) {
    header(&quot;HTTP/1.0 404 Not Found&quot;);
    print &quot;File does not exist.&quot;;
    exit();
}

$path_info = pathinfo($file);
$extension=$path_info['extension'];

switch($extension) {
    case 'css':
        $mime = &quot;text/css&quot;;
        break;
    case'js':
        $mine = &quot;text/javascript&quot;;
        break;
    default:
        $mime = &quot;text/plain&quot;;
}

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start(&quot;ob_gzhandler&quot;);
else
    ob_start();
header( &quot;Content-Type: &quot; . $mime . &quot;; charset: UTF-8&quot;);
header (&quot;cache-control: must-revalidate&quot;);
readfile($file);
?&gt;
</pre><p>The file checks for the extension of the file that is receives and ads the corresponding headers to it&#8217;s top.<br
/> Pretty simple. Download the zip file to get both versions.</p><div
id="attachment_269" class="wp-caption aligncenter" style="width: 138px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2010/01/optimize1.zip"><img
class="size-full wp-image-269" title="Awesome website optimizer" src="http://blog.ajaxmasters.com/wp-content/uploads/2010/01/1262475037_zip.png" alt="Awesome website optimizer" width="128" height="128" /></a><p
class="wp-caption-text">Awesome website optimizer</p></div> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/guide-to-a-very-fast-website/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Playing with CSS3</title><link>http://blog.ajaxmasters.com/playing-with-css3/</link> <comments>http://blog.ajaxmasters.com/playing-with-css3/#comments</comments> <pubDate>Thu, 01 Oct 2009 18:55:57 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[css]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[imageroll]]></category> <category><![CDATA[shadows]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=185</guid> <description><![CDATA[<p>If you saw our "<b>ImageRoll</b>" page and you used Firefox, Chrome or Safari then you saw the images being rotated in different angles well the way i did that is by using CSS3. I guess you already figured that out from the title. :)</p><p>CSS3 implements a lot of new features that can make your life easier of course you will not be able to use them quite yet. IE is not supporting like more than 90% of them so it's useless if you want to make this for a client. The ones that we used on our blog are: <b>box-shadow</b>, <b>border-radius</b> and <b>text-shadow</b>. [...]</p>]]></description> <content:encoded><![CDATA[<div
id="attachment_186" class="wp-caption alignleft" style="width: 249px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/play_css3.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/play_css3.png" alt="Play with CSS3" title="play_css3" width="239" height="239" class="size-full wp-image-186" /></a><p
class="wp-caption-text">Play with CSS3</p></div><p>If you saw our &#8220;<b>ImageRoll</b>&#8221; page and you used Firefox, Chrome or Safari then you saw the images being rotated in different angles well the way i did that is by using CSS3. I guess you already figured that out from the title. <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>CSS3 implements a lot of new features that can make your life easier of course you will not be able to use them quite yet. IE is not supporting like more than 90% of them so it&#8217;s useless if you want to make this for a client. The ones that we used on our blog are: <b>box-shadow</b>, <b>border-radius</b> and <b>text-shadow</b>. I think these are the most important of them but you can check all of them out by taking a look at this page: <a
href="http://www.css3.info/preview/" title="http://www.css3.info/preview/">css3.info/preview/</a>.</p><p>I&#8217;m gonna do a simple explanation on the ones we used and show you some code.</p><p>We used on the hrefs of the page this property:</p><pre class="brush: css; title: ; notranslate">
-moz-box-shadow: 0px 2px 15px #333;
</pre><p>Now let&#8217;s explain. Why &#8220;-moz&#8221; in front of it? This is a simple hack for those who don&#8217;t know it. It tells the browser to render this only in <b>mozilla</b> based browsers. Next we have the property box-shadow  and 0px means the top margin of the shadow, 2px means we move the shadow 2 pixels to the left and 15px<br
/> means we create a shadow with 15 pixels of size of blur if you want, #333 is of course the color of the box shadow. Pretty simple <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><p>Now let&#8217;s rotate the images:</p><pre class="brush: css; title: ; notranslate">
   -webkit-transform: rotate(-10deg);
    -moz-transform: rotate(-10deg);
</pre><p>You know -moz- already but we have a new one &#8220;-webkit-&#8221; this one means it will render in webkit based browsers, the most popular are: Safari and Chrome. Next we have the property &#8220;transform&#8221; and the degree of rotation &#8220;-10deg&#8221;.</p><p>The other one that we used all over the blog is text-shadow</p><pre class="brush: css; title: ; notranslate">
text-shadow:1px 1px 0px #000;
</pre><p>This property is like this 1px means we move the shadow with 1 pixel from the top, 1 pixel from the left and 0 blur or size, #000 means of course the color of the shadow.</p><p>And here is a preview in 2 browsers IE and Firefox so you can see maybe you are not using a browser that supports CSS3.</p><div
id="attachment_193" class="wp-caption aligncenter" style="width: 610px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/ie.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/ie-600x705.png" alt="Ie view" title="ie" width="600" height="705" class="size-large wp-image-193" /></a><p
class="wp-caption-text">Ie view</p></div><div
id="attachment_194" class="wp-caption aligncenter" style="width: 610px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/firefox.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/10/firefox-600x642.png" alt="Firefox view" title="firefox" width="600" height="642" class="size-large wp-image-194" /></a><p
class="wp-caption-text">Firefox view</p></div><p>My imageroll page is inspired from this page: <a
href="http://line25.com/tutorials/how-to-create-a-pure-css-polaroid-photo-gallery">line25.com/tutorials/how-to-create-a-pure-css-polaroid-photo-gallery</a> . Go and check it out (Y) .</p><p>Thank you and happy coding! <img
src='http://blog.ajaxmasters.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/playing-with-css3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Use ajax to create a cacheing system</title><link>http://blog.ajaxmasters.com/use-ajax-to-create-a-cacheing-system/</link> <comments>http://blog.ajaxmasters.com/use-ajax-to-create-a-cacheing-system/#comments</comments> <pubDate>Tue, 29 Sep 2009 10:49:52 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[cache]]></category> <category><![CDATA[html]]></category> <category><![CDATA[imageroll]]></category> <category><![CDATA[images]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[php]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[system]]></category> <category><![CDATA[vi.sualize.us]]></category> <category><![CDATA[wordpress]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=163</guid> <description><![CDATA[<p>As I said in my last post, I wanted from the first time to make a cacheing system for my imageroll page. Because i take the images from vi.sualize.us servers and we don't want to make to much trafic and make stuff worse for them.</p><p>So what i did is simple, i made a class that extracts the rss data from theirs servers and get the images to display them. I do this every time someone visits the page.</p>]]></description> <content:encoded><![CDATA[<div
id="attachment_164" class="wp-caption alignleft" style="width: 287px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/cache.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/cache.png" alt="Cache Pic" title="cache" width="277" height="277" class="size-full wp-image-164" /></a><p
class="wp-caption-text">Cache Pic</p></div><p>As I said in my last post, I wanted from the first time to make a cacheing system for my imageroll page. Because i take the images from vi.sualize.us servers and we don&#8217;t want to make to much trafic and make stuff worse for them.</p><p>So what i did is simple, i made a class that extracts the rss data from theirs servers and get the images to display them. I do this every time someone visits the page. If any image is new for the first time we display the image from vi.sualize.us and run a functions in javascript to check for new images. If any new images exist then we cache them in a folder on our server and the next time a user visits the page that image will be shown from our server. Pretty simple.</p><p>For now i&#8217;ll just show you the stuff that makes this thing run and if you want i can share the whole script so that you can make one for your blog or website.</p><p>I&#8217;ll also try to make a WordPress plugin so you can integrate it easily in your blog.</p><p>So here we go. We start with the function that checks for new images:</p><pre class="brush: php; title: ; notranslate">
functio checkCache($image_url){
            $path=pathinfo($image_url);
            $img_cached = 'cache/'.$path['filename'].'.'.$path['extension'];
            if(!file_exists($img_cached)) {
                createCacheImg($image_url);
            }
}
</pre><p>This function just checks if the image exists in the &#8220;<b>cache</b>&#8221; folder. If it&#8217;s not there then we run the &#8220;<b>createCacheImg</b>&#8221; function.</p><p>We now need a function to get the image so we check if the image is in the cache folder or not so we know what to display.</p><pre class="brush: php; title: ; notranslate">
    function getImage($or_img) {
        $path=pathinfo($or_img);
        $filename=$path['filename'];
        $img_cached = 'cache/'.$filename.'.'.$path['extension'];
        if(file_exists($img_cached)) {
            $url=$img_cached;
        }else {
            $url=$or_img;
        }

        return $url;
    }
</pre><p>Very simple function that just returns the right url of the image.</p><p>Now we cache the image.</p><pre class="brush: php; title: ; notranslate">
function createCacheImg($image){
        $srcsize = getimagesize($image);
        $w = $srcsize[0];
        $h = $srcsize[1];

        $path=pathinfo($image);
        $dest='cache/'.$path['filename'].'.'.$path['extension'];
        if($path['extension']=='jpg' || $path['extension']=='jpeg' || $path['extension']=='JPG') {
            $src_img = imagecreatefromjpeg($image);
        }else if($path['extension']=='gif') {
                $src_img = imagecreatefromgif($image);
            }else if($path['extension']=='png') {
                    $src_img = imagecreatefrompng($image);
                }
        $img_cpy=imagecreatetruecolor($w,$h);
        imagecopy($img_cpy, $src_img, 0, 0, 0, 0, $w, $h);
        if($path['extension']=='jpg' || $path['extension']=='jpeg' || $path['extension']=='JPG') {
            imagejpeg($img_cpy,$dest);
        }else if($path['extension']=='gif') {
                imagegif($img_cpy,$dest);
            }else if($path['extension']=='png') {
                    imagepng($img_cpy,$dest);
                }
        imagedestroy($src_img);
}
</pre><p>This function will save the image into the cache folder. Now we need a new file &#8220;<b>checkcache.php</b>&#8221; where we put this code:</p><pre class="brush: php; title: ; notranslate">
include('functions.php');
$image=$_GET['image'];
checkCache($image);
</pre><p> Right now we should have this kind of structure in our imageroll folder: A folder &#8220;<b>cache</b>&#8221; a file &#8220;<b>functions.php</b>&#8221; where we place all these functions we just did and a file &#8220;<b>index.php</b>&#8221; where we run the javascript function and display the images.</p><p>The &#8220;<b>index.php</b>&#8221; file requires this code:</p><pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
    &lt;head&gt;

        &lt;title&gt;
            Image ROLL
        &lt;/title&gt;

        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
        &lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;  google.load(&quot;jquery&quot;, &quot;1.3.2&quot;); &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
&lt;input type=&quot;hidden&quot; id=&quot;image&quot; value=&quot;http://test.com/image.jpg&quot;&gt;
&lt;img src=&quot;&lt;?=getImage($image)?&gt;&quot; alt=&quot;test image&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre><p>We have here a simple index.php file that imports the google api and jquery so we can run a simple ajax function. This is the javascript code that you should insert in this file or a separate one if you want:</p><pre class="brush: jscript; title: ; notranslate">

            $(document).ready(function() {
                checkCache();
            });

            function checkCache(){
                var page=$('#image');
                var url='checkcache.php';
                var pars='page='+page.val();
                $.get(url,pars);
            }
</pre><p>This will run this function after the page loads and it will check for new images. So this is just a simple script that will make you pages load faster expecialy if you load the images from outside of your server.</p><p>If you liked this i&#8217;ll go and make a more complex one and even share the imageroll script i did. That until i find the time and make a WordPress Plugin.</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/use-ajax-to-create-a-cacheing-system/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Write better CSS</title><link>http://blog.ajaxmasters.com/css-shortcuts/</link> <comments>http://blog.ajaxmasters.com/css-shortcuts/#comments</comments> <pubDate>Wed, 23 Sep 2009 23:10:09 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[css]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=94</guid> <description><![CDATA[<p>When writing your CSS, it is possible to write neater, more readable code by making use of CSS shortcuts. A shortcut is a feature of CSS that allows the developer to specify a number of related properties on a single line rather than specify them all separately. Lets look at the following example:</p> .header {
padding-top:5px;
padding-right:10px;
padding-bottom:5px;
[...]]]></description> <content:encoded><![CDATA[<p>When writing your CSS, it is possible to write neater, more readable code by making use of CSS shortcuts. A shortcut is a feature of CSS that allows the developer to specify a number of related properties on a single line rather than specify them all separately. Lets look at the following example:</p><pre class="brush: css; title: ; notranslate">
.header {
padding-top:5px;
padding-right:10px;
padding-bottom:5px;
padding-left:10px;
}
</pre><p>The code above is perfectly valid and will work fine, but we can save time and make the code much neater using the following code:</p><pre class="brush: css; title: ; notranslate">
.header {
padding:5px 10px 5px 10px;
}
</pre><p>Using the code above we can specify all of the padding for the header div on one line. It works by applying the first attribute (5px) to the top padding of the div. The second (10px) applies to the right side padding, the 3rd (5px) attribute means the padding on the bottom of the div, and the forth (10px) attribute means the left side padding. The padding is always applied in this order.</p><p>It is possible to shorten this code even further using the following code:</p><pre class="brush: css; title: ; notranslate">
.header {
padding:5px 10px;
}
</pre><p>This works by taking the first (5px) attribute to mean the top and bottom, or vertical padding, and the second (10px) attribute to mean the horizontal padding (left and right).</p><p>The exact same principles can be used to declare the margin of your divs, so what could have looked like this:</p><pre class="brush: css; title: ; notranslate">
.header {
padding-top:5px;
padding-right:10px;
padding-bottom:5px;
padding-left:10px;
margin-top:5px;
margin-right:10px;
margin-bottom:5px;
margin-left:10px;
}
</pre><p>Can now look much neater, and is obviously much quicker to write using the following:</p><pre class="brush: css; title: ; notranslate">
.header {
padding:5px 10px;
margin:5px 10px;
}
</pre><div
class="in_title"><strong>Background properties</strong></div><p>One of my favorite CSS shortcuts is the background property shortcut. This is how a typical CSS file could look without shortcuts:</p><pre class="brush: css; title: ; notranslate">
.header {
background-image:url(images/image.jpg);
background-position:top;
background-repeat:repeat-x;
background-color:#fff;
}
</pre><p>However, with some nifty CSS it could look like this:</p><pre class="brush: css; title: ; notranslate">
.header {
background: #fff url(images/image.jpg) repeat-x top;
}
</pre><p>The above code is much quicker and more manageable. Take note though, that all of the properties must be provided when using the background shortcut. If I missed off the colour specification at the beginning for example, the code would not work.</p><div
class="in_title"><strong>Font shortcuts</strong></div><p>Another very useful shortcut is the font shortcut. The code below can be shorted considerably:</p><pre class="brush: css; title: ; notranslate">
body {
font-weight: bold;
font-family: verdana, sans-serif;
font-size: 0.8em;
line-height: 1.2em;
}
</pre><p>Here is the shortcut:</p><pre class="brush: css; title: ; notranslate">
body {
font: bold 0.8em/1.2em verdana, sans-serif;
}
</pre><p>It is important to write the shortcut in the same order as above so that web browsers don&#8217;t get confused!</p><div
class="in_title"><strong>Borders</strong></div><p>This is my favorite shortcut of all. This saves me a great deal of time when I am developing web sites because whenever I have a problem with a layout or an element, the first thing I do is put a border around it so that I can see its dimensions and work out what&#8217;s going on.</p><p>Here is some typical code:</p><pre class="brush: css; title: ; notranslate">
.header {
border-width: 1px;
border-color: #000;
border-style: solid;
}
</pre><p>This can be shorted to the following:</p><pre class="brush: css; title: ; notranslate">
.header {
border:1px solid #000;
}
</pre><p>Then, whenever you are not sure why an element is not behaving properly, just use the border shortcut above to debug your code and see what the dimensions of the element are.</p><div
class="in_title"><strong>Conclusion</strong></div><p>As you can see, you can make your code much shorter and neater using the CSS shortcuts outlined here. Once you get into the habit of using them, I guarantee that you will wonder why you ever did it differently in the past!</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/css-shortcuts/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Ajax file upload with jQuery</title><link>http://blog.ajaxmasters.com/ajax-file-upload-with-jquery/</link> <comments>http://blog.ajaxmasters.com/ajax-file-upload-with-jquery/#comments</comments> <pubDate>Tue, 22 Sep 2009 22:25:44 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[jquery]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=30</guid> <description><![CDATA[Sometimes we come into a problem that is a little harder to do when it comes to customizing and that is the file upload input. Well Andris Valums helps us with a plugin he created for jQuery. The plugin requires jQuery 1.2 or above and allows users to upload multiple...]]></description> <content:encoded><![CDATA[<div
id="attachment_33" class="wp-caption aligncenter" style="width: 510px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/upload-pic.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/upload-pic.png" alt="JQUERY upload plugin" title="upload-pic" width="500" height="300" class="size-full wp-image-33" /></a><p
class="wp-caption-text">JQUERY upload plugin</p></div><p>Sometimes we come into a problem that is a little harder to do when it comes to customizing and that is the file upload input. Well <strong>Andris Valums</strong> helps us with a plugin he created for jQuery.</p><p>The plugin requires jQuery 1.2 or above and allows users to upload multiple files without refreshing the page.</p><p>To make the plugin work you have to include jQuery and the plugin in your websites head.</p><pre name="code" class="html">%MINIFYHTML797fbaecd23cebcfff11fa70afacb1410%%MINIFYHTML797fbaecd23cebcfff11fa70afacb1411%</pre><p>And after that you can add this for a div with a specific id:</p><pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){

$.ajax_upload('#div_id', {
  // Location of the server-side upload script
  action: 'upload.php',
  // File upload name
  name: 'userfile',
  // Additional data to send
  data: {
    key1 : 'value',
    key2 : 'value2'
  },
  // Fired when user selects file
  // You can return false to cancel upload
  onSubmit: function(file, extension) {},
  // Fired when file upload is completed
  onComplete: function(file, response) {},
  // Fired when server returns the string
  onSuccess: function(file){},
  // Fired when server return something else
  onError: function(file, response){}
});

});
</pre><p>And after that just upload the file using:</p><pre class="brush: php; title: ; notranslate">
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo &amp;amp;quot;success&amp;amp;quot;;
} else {
  echo &amp;amp;quot;error&amp;amp;quot;;
}
</pre><p>You can find more info on: <a
rel="extern" href="http://valums.com/projects/ajax-upload/" target="_blank">http://valums.com/projects/ajax-upload/</a> or check out the demo page : <a
rel="extern" href="http://valums.com/s/p/ajax-upload/demo.htm" target="_blank">Demo</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/ajax-file-upload-with-jquery/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>jQuery Pagination Plugin</title><link>http://blog.ajaxmasters.com/jquery-pagination-plugin/</link> <comments>http://blog.ajaxmasters.com/jquery-pagination-plugin/#comments</comments> <pubDate>Tue, 22 Sep 2009 22:15:03 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[pagination]]></category> <category><![CDATA[plugin]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=26</guid> <description><![CDATA[Description When you have a a large list of items (e.g. search results or news articles), you can display them grouped in pages and present navigational elements to move from one page to another. This plugin creates these navigational elements. Usage Include the pagination plugin script and the pagination.css file...]]></description> <content:encoded><![CDATA[<div
id="attachment_27" class="wp-caption aligncenter" style="width: 510px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/jquery-pag-pic.png"><img
class="size-full wp-image-27" title="jquery-pag-pic" src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/jquery-pag-pic.png" alt="jQuery pagination" width="500" height="300" /></a><p
class="wp-caption-text">jQuery pagination</p></div><p><strong>Description</strong></p><p>When you have a a large list of items (e.g. search results or news articles), you can display them grouped in pages and present navigational elements to move from one page to another. This plugin creates these navigational elements.</p><p><strong>Usage</strong></p><p>Include the pagination plugin script and the pagination.css file in your HTML page. In your HTML body create a container tag pair that will hold the link elements. Give it an id attribute (e.g. &#8220;News-Pagination&#8221;)</p><p>After you have loaded the contents and know how many items you want to display overall, create the pagination like this:</p><pre class="brush: jscript; title: ; notranslate">
	// First Parameter: number of items
	// Second Parameter: options object
	$(&quot;#News-Pagination&quot;).pagination(122, {
		items_per_page:20,
		callback:loadContents
	});
</pre><p>This will create the navigation links inside the container. You will see the numbers 1-7, the first number is highlighted. When you click on another number, the highlighting changes and your callback function &#8220;loadContents&#8221; is called.</p><p>The plugin is highly configurable through the option parameter and all elements can be styled separately.</p><p>You can check out a demo <a
href="http://tutorials.ajaxmasters.com/pagination-demo/">here</a>.<br
/> And download the source code <a
href="http://tutorials.ajaxmasters.com/pagination-demo/source.zip">here</a>.</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/jquery-pagination-plugin/feed/</wfw:commentRss> <slash:comments>36</slash:comments> </item> <item><title>PNG rollover function for IE 6 using JavaScript</title><link>http://blog.ajaxmasters.com/png-rollover-function-for-ie-6-using-javascript/</link> <comments>http://blog.ajaxmasters.com/png-rollover-function-for-ie-6-using-javascript/#comments</comments> <pubDate>Tue, 22 Sep 2009 21:38:35 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[fix]]></category> <category><![CDATA[ie6]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[png]]></category> <category><![CDATA[transparency]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=19</guid> <description><![CDATA[Last night i was working on a site that uses a lot of transparent .png&#8217;s . As we all know, our dear MS IE 6 doesn&#8217;t know how to handle the transparency of PNG files. For quite a while, i was using a Javascript png fix called SUPERSLEIGHT and i...]]></description> <content:encoded><![CDATA[<div
id="attachment_23" class="wp-caption alignleft" style="width: 310px"><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/PNG-fixie6.png"><img
src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/PNG-fixie6.png" alt="PNG Fix for IE6" title="PNG-fixie6" width="300" height="300" class="size-full wp-image-23" /></a><p
class="wp-caption-text">PNG Fix for IE6</p></div><p>Last night i was working on a site that uses a lot of transparent .png&#8217;s . As we all know, our dear MS IE 6 doesn&#8217;t know how to handle the transparency of PNG files.</p><p>For quite a while, i was using a Javascript png fix called <a
href="http://snipplr.com/view/4224/ie-6-transparent-png-fix--supersleight/">SUPERSLEIGHT</a> and i was very happy about how it worked.</p><p>But last night i came into a problem. I needed to make some rollover images which were transparent PNG&#8217;s, and when the images change, the transparency fix will break. So i started looking for a solution and i came over <a
href="http://homepage.ntlworld.com/bobosola/png_mouseover.htm">this</a> function, which works perfect. The only thing was that this won`t work togheter with the original SUPERSLEIGHT script and it only fixes the png`s in IMG tags, and i had a lot of PNG images as backgrounds, inputs, etc.</p><p>So i changed the supersleight script to ignore PNG`s in IMG tags, and i merged it with the other script.</p><p><strong
class="in_title">How it works :</strong></p><p>- Link the &#8216;supersleight-swap.js&#8217; file into your document inside conditional comments so that it is delivered to only Internet Explorer 6 or older.</p><pre class="brush: xml; title: ; notranslate">
&lt;!--[if lte IE 6]&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;path/to/supersleight-swap.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;
</pre><p>- Copy &#8216;x.gif&#8217; in the same directory as the page you&#8217;re using PNG&#8217;s on.</p><p>- Put in the function that swaps the images (for NORMAL browsers) :</p><pre class="brush: jscript; title: ; notranslate">
function imgSwap(oImg)
{
   var strOver  = &quot;_on&quot;    // image to be used with mouse over
   var strOff = &quot;_off&quot;     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1)
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}
</pre><p>- Call the function in the &#8216;onmouseover&#8217; and &#8216;onmouseout&#8217; event of the IMG.</p><pre class="brush: xml; title: ; notranslate">
&lt;img alt=&quot;a png image&quot; src=&quot;path/to/image_off.png&quot; onmouseover=&quot;imgSwap(this)&quot; onmouseout=&quot;imgSwap(this)&quot; id=&quot;img1&quot;&gt;
</pre><p>Note that each PNG must have an ID attribute for this to work.</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/png-rollover-function-for-ie-6-using-javascript/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Twitter followers counter tutorial</title><link>http://blog.ajaxmasters.com/twitter-followers-counter-tutorial/</link> <comments>http://blog.ajaxmasters.com/twitter-followers-counter-tutorial/#comments</comments> <pubDate>Tue, 22 Sep 2009 18:56:38 +0000</pubDate> <dc:creator>Chocksy</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[counter]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[php]]></category> <category><![CDATA[twitter]]></category><guid
isPermaLink="false">http://blog.ajaxmasters.com/?p=7</guid> <description><![CDATA[You&#8217;re probably wondering why should i bother if we have TwitterCounter to show us the followers, well what if i don&#8217;t like the way it shows them what if i wanna do a counter with my own graphics , well i&#8217;m gonna show you how. We&#8217;re gonna need the jpg...]]></description> <content:encoded><![CDATA[<div
id="attachment_9" class="wp-caption alignleft" style="width: 310px"><img
class="size-full wp-image-9" title="twitter-poster" src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/twitter-poster.png" alt="Twitter followers tutorial" width="300" height="300" /><p
class="wp-caption-text">Twitter followers tutorial</p></div><p>You&#8217;re probably wondering why should i bother if we have <a
href="http://twittercounter.com/" target="_blank">TwitterCounter</a> to show us the followers, well what if i don&#8217;t like the way it shows them what if i wanna do a counter with my own graphics , well i&#8217;m gonna show you how.</p><p>We&#8217;re gonna need the jpg to show the followers on and 2 classes to read the data.</p><p>Let&#8217;s get some twitter icons so that we can create a simple image in photoshop. With a simple google search we get on this article <a
href="http://www.hongkiat.com/blog/100-remarkably-beautiful-twitter-icons-and-buttons/" target="_blank">100+ Remarkably Beautiful Twitter Icons And Buttons</a> created by <a
href="http://www.hongkiat.com/" target="_blank">www.hongkiat.com</a>.</p><p>I did a simple image that you can use if you want it&#8217;s all added to the download package.</p><p>Now let&#8217;s create the php code that will display that followers number&#8230;</p><p>We&#8217;re gonna need 2 classes that will get our job done easily, a twitter class and a class that will transform the xml output into an array one.</p><div
id="attachment_12" class="wp-caption alignright" style="width: 180px"><img
class="size-full wp-image-12" title="follow chocksy" src="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/follow-chocksy1.jpg" alt="My follow chocksy image" width="170" height="85" /><p
class="wp-caption-text">My follow chocksy image</p></div><p>Also you have to find out your id number that&#8217;s a little tricky and i don&#8217;t understand why twitter is not showing that so that you can find it. So here is how you can find your twitter id:</p><p>Go on your account page and on the right you have a button named RSS, now that button has an url like http://twitter.com/statuses/user_timeline/<strong>18107925</strong>.rss so the bolded number is your id that you&#8217;ll have to use in our php code.</p><pre class="brush: php; title: ; notranslate">
include('xml2array.php');
include('twitter.lib.php');
$user = 'yournickname';
$password = 'yourpassword';

$twitter = new Twitter($user, $password);

$friends = $twitter-&gt;showUser('xml','yourid_number');
$xml=new XML2Array();
$arr=$xml-&gt;parse($friends);
$followers=$arr['user']['followers_count']['value'].' &lt;span style='font-size:12px;'&gt;followers&lt;/span&gt;';
</pre><p>We will now show the image with the number in the right place. We&#8217;ll link the image to our account so that people can follow us and place the followers in the div we have between the a tags.</p><pre class="brush: xml; title: ; notranslate">
&lt;div&gt;
&lt;a href=&quot;http://www.twitter.com/yournickname&quot; target=&quot;_blank&quot; style=&quot;text-decoration:none;&quot;&gt;&lt;div class=&quot;twitter&quot; id=&quot;tell_followers&quot;&gt;&lt;?=$followers?&gt;&lt;/div&gt;&lt;/a&gt;
&lt;/div&gt;
</pre><p>Here we have the css that takes care of the followers number display.</p><pre class="brush: css; title: ; notranslate">
.twitter{
color:#FFFFFF;
font-family:Tahoma;
font-size:24px;
line-height:14pt;
background:url(follow_me.png) no-repeat;
height:85px;
width:170px;
padding:35px 0 0 57px;
text-decoration:none;
cursor:pointer;
}
</pre><p><strong
class="in_title">UPDATE (for blogers with a lot of visitors)</strong></p><p>Since we use this script to make requests to the twitter API we have to be careful because the API does not allow us to make more than 100 requests per hour so if you have more than 100 visitors per hour you have to make this changes:</p><p>First of all let&#8217;s create a MYSQL table here is the SQL code for the table, a very simple one :</p><pre class="brush: sql; title: ; notranslate">
 CREATE TABLE `ajaxmast_blog`.`twitter_counter` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`followers` BIGINT NOT NULL ,
`last_set` DATETIME NOT NULL
) ENGINE = MYISAM
</pre><p>Ok after we&#8217;ve done that let&#8217;s connect to the db.</p><pre class="brush: php; title: ; notranslate">
//DATA FOR SQL
define(USERNAME,'db_username');
define(PASSWORD,'db_password');
define(DATABASE,'db_name');
//END CONF

//connect to db
@mysql_connect('localhost',USERNAME,PASSWORD);
@mysql_select_db(DATABASE);
$db_query=mysql_query('SELECT * FROM twitter_counter LIMIT 1');
</pre><p>We&#8217;ll put the request to the twitter API in a function so we don&#8217;t have a very heavy code:</p><pre class="brush: php; title: ; notranslate">
//function to get the followers nore easily
function get_followers($user,$password){
$twitter = new Twitter($user, $password);

$friends = $twitter-&gt;showUser('xml','18107925');
$xml=new XML2Array();
$arr=$xml-&gt;parse($friends);
$nr_followers=$arr['user']['followers_count']['value'];

return $nr_followers;
}
</pre><p>After that we create a difference function so we can calculate the minutes that have passed since we checked the twitter API:</p><pre class="brush: php; title: ; notranslate">
function dateDiff($date, $date2)
{
    if($date2 &gt; $date) {
        $tmp = $date2 - $date;
    }

    else {
        $tmp = $date - $date2;
    }

    $seconds = $tmp;

// Relative ////////
    $minutes = floor($tmp/60);
    $tmp -= $minutes * 60;

    // Total ///////////
    $tminutes = floor($seconds/60);

return $tminutes;
}
</pre><p>And for the final touch we check to see if the time has passed so we can call again the twitter API or if not we should display the followers from our database:</p><pre class="brush: php; title: ; notranslate">
$curent_time=date('Y-m-d H:i:s');
$info=mysql_fetch_array($db_query);
$last_set=$info['last_set'];

$dif=dateDiff(strtotime($curent_time),strtotime($last_set));

//check for last request
if(mysql_num_rows($db_query)==0){
$nr_followers=get_followers($user,$password);

mysql_query(&amp;quot;INSERT INTO twitter_counter (followers,last_set) VALUES('&quot;.$nr_followers.&quot;',NOW())&quot;);
}else if($dif&lt;=10){
$nr_followers=get_followers($user,$password);

mysql_query(&quot;UPDATE twitter_counter SET followers='&quot;.$nr_followers.&quot;',last_set=NOW()&quot;);
}else
$nr_followers=$info['followers'];

$followers=$nr_followers.' &lt;span style=&quot;font-size:12px;&quot;&gt; followers&lt;/span&gt;';
</pre><p>And that&#8217;s it the rest is the same. I will place this version in the .rar file too so you can use it as you may like tell me if you want any changes done to it or anything.  I would like to thank smashing magazine for the feature  here is the article: <a
href="http://www.smashingmagazine.com/2009/03/02/twitter-web-designer-and-developer-toolbox-api-and-tutorials/" target="_blank">ARTICLE</a>.</p><p><a
href="http://blog.ajaxmasters.com/wp-content/uploads/2009/09/twitter_followers1.rar">Download SOURCES</a></p><p>You have in the download package the PSD file and the 2 classes that will help you work this out, also there is a test file too. Hope you find this useful.<br
/> Thanks for reading.</p> ]]></content:encoded> <wfw:commentRss>http://blog.ajaxmasters.com/twitter-followers-counter-tutorial/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching 1/44 queries in 0.048 seconds using disk: basic
Object Caching 776/896 objects using disk: basic

Served from: blog.ajaxmasters.com @ 2012-02-05 05:57:04 -->
