<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="http://feeds.feedburner.com/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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" version="2.0">

<channel>
	<title>Makebeta</title>
	
	<link>http://www.merchantos.com/makebeta</link>
	<description>Web Developer Tools and Tutorials</description>
	<pubDate>Fri, 30 May 2008 17:38:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/makebeta" type="application/rss+xml" /><item>
		<title>Making A Wordpress 2.5 Sidebar Widget Plugin</title>
		<link>http://www.merchantos.com/makebeta/wordpress/making-a-wordpress-25-sidebar-widget-plugin/</link>
		<comments>http://www.merchantos.com/makebeta/wordpress/making-a-wordpress-25-sidebar-widget-plugin/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 18:41:57 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[dynamic_sidebar]]></category>

		<category><![CDATA[plugins_loaded]]></category>

		<category><![CDATA[register_sidebar]]></category>

		<category><![CDATA[register_sidebar_widget]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/wordpress/making-a-wordpress-25-sidebar-widget-plugin/</guid>
		<description><![CDATA[Wordpress 2.5 And Widgets
A Wordpress Widget is a dynamic element that can be placed in the sidebars (or anywhere that is declared a sidebar) in your Wordpress theme. For example on this blog there is a right sidebar with these widgets: Search It, Recent Entries, Categories, Related Sites, Recent Visitors (by Feedjit), Recent Readers (by [...]]]></description>
			<content:encoded><![CDATA[<h2>Wordpress 2.5 And Widgets</h2>
<p>A Wordpress Widget is a dynamic element that can be placed in the sidebars (or anywhere that is declared a sidebar) in your Wordpress theme. For example on this blog there is a right sidebar with these widgets: Search It, Recent Entries, Categories, Related Sites, Recent Visitors (by Feedjit), Recent Readers (by MyBlogLog). A widget can be any small modular piece of html (usually a list but not always) that can be stuck into a sidebar.</p>
<h3>Widgets Make Your Plugin More Flexible</h3>
<p>If you write your plugin as a widget your users will easily be able to move your plugin to which ever sidebar they want and arrange it with their other widgets how they want to. And they can do all of this without touching their theme&#8217;s code. This is great for users who don&#8217;t know how to modify a Wordpress theme template.</p>
<h3>Sidebars Are Not Just Sidebars</h3>
<p>Though they are called sidebars, they can actually be any block element of the page. A sidebar could be a heading, a footer, a section within a particular page, anything you want. It&#8217;s easy to declare a sidebar. Usually sidebars are declared within a theme&#8217;s functions.php file.</p>
<h3>Declaring Your Sidebars - From Within A Theme</h3>
<p>Update: There&#8217;s a great tutorial just on <a href="http://www.themelab.com/2008/04/18/see-how-easy-it-is-to-widgetize-wordpress-themes/">making your theme widget ready over here.</a><br />
For example in a theme I&#8217;m working on I have 3 sidebars, normal left and right sidebars, and a top navigation bar that I&#8217;m also using as a dynamic sidebar for widgets. In my functions.php file I have:</p>
<pre style="clear: both;"><code>register_sidebar(array(
    	'name'=&gt;'top_sidebar',
        'before_widget' =&gt; '&lt;li id="%1$s" class="widget %2$s"&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h2 class="widgettitle"&gt;',
        'after_title' =&gt; '&lt;/h2&gt;',
    ));
    register_sidebar(array(
    	'name'=&gt;'left_sidebar',
        'before_widget' =&gt; '&lt;li id="%1$s" class="widget %2$s"&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h2 class="widgettitle"&gt;',
        'after_title' =&gt; '&lt;/h2&gt;',
    ));
    register_sidebar(array(
    	'name'=&gt;'right_sidebar',
        'before_widget' =&gt; '&lt;li id="%1$s" class="widget %2$s"&gt;',
        'after_widget' =&gt; '&lt;/li&gt;',
        'before_title' =&gt; '&lt;h2 class="widgettitle"&gt;',
        'after_title' =&gt; '&lt;/h2&gt;',
    ));</code></pre>
<p>You can see some basic documentation on <a href="http://automattic.com/code/widgets/api/">register_sidebar here</a>. The name=&gt;top_sidebar&#8217; tells Wordpress what I&#8217;m calling my sidebar. This name will be displayed in the Admin interface under Design->Widgets->Current Widgets in the drop down list. You also use this name to place all the sidebar widgets within your them template. Users can choose to add widgets to any of the declared sidebars. The before_widget, after_widget, before_title, and after_title specify some html to wrap the widget in. This is handy if you need to style the widgets in a special way for your theme.</p>
<h3>Using Dynamic Sidebars Within Your Theme</h3>
<p>To use your sidebars within a theme you just call the dynamic_sidebar function. Here&#8217;s how I do it in my theme:</p>
<pre style="clear: both;"><code>&lt;?php if (function_exists('dynamic_sidebar')) {
dynamic_sidebar('right_sidebar');
} ?&gt;</code></pre>
<p>This tells Wordpress to call the display functions for all the widgets the user has added to the &#8216;right_sidebar&#8217; sidebar.</p>
<h3>A Hook To Hang Your Widget From</h3>
<p>You&#8217;ll need to tell Wordpress about your plugin&#8217;s widget. To do this you declare a &#8220;plugins_loaded&#8221; action hook like so:</p>
<pre style="clear: both;"><code>    function mycoolplugin_loaded()
    {
        $widget_ops = array('classname' =&gt; 'mycoolplugin_widget', 'description' =&gt; "A very cool widget for your sidebar." );
        wp_register_sidebar_widget('mycoolplugin_widget', 'CoolPlugin', 'mycoolplugin_widget', $widget_ops);
    {
    add_action('plugins_loaded','mycoolplugin_loaded');</code></pre>
<p>In your widget you&#8217;ll want to replace mycoolplugin with the unique name you&#8217;ve chosen for your plugin. And you&#8217;ll want to replace &#8220;A very cool widget for your sidebar.&#8221; with the real description for your widget.</p>
<h4 style='color: #777; margin: 10px 0px 0px 20px; padding: 5px;'>A Note For Uber-Geeks</h4>
<div style='font-size: 10pt; color: #777; margin: 0px 0px 20px 20px;'>
So if you read the documentation <a href="http://automattic.com/code/widgets/api/">here</a> they will tell you to use register_sidebar_widget instead of wp_register_sidebar_widget. I found register_sidebar_widget really frustrating because I couldn&#8217;t get it to display the description of my widget (above &#8220;A very cool widget for your sidebar.&#8221;). The internal widgets like Pages and Categories use the wp_register_sidebar_widget to declare themselves. If your interested you can find the these functions in wp-includes/widgets.php.
</div>
<h3>Your Widget Display Code</h3>
<p>In the code above we specified mycoolplugin_widget as the callback function for Wordpress to use when it wants to display your widget. So we&#8217;ll need to declare this function and use it to generate our widget&#8217;s HTML code.</p>
<pre style="clear: both;"><code>
function mycoolplugin_widget($args)
{
	extract($args); // extracts before_widget,before_title,after_title,after_widget
	echo $before_widget . $before_title . 'CoolPlugin' . $after_title . "&lt;ul&gt;";
	for ($i=0; $i&lt;10; $i++)
	{
		echo "&lt;li&gt;List Item $i&lt;/li&gt;";
	}
	echo "&lt;/ul&gt;" . $after_widget;
}</code></pre>
<p>My widget simply displays a header of &#8220;CoolPlugin&#8221; and then a list of ten items. Of course you&#8217;ll want to make your widget do something much cooler, but I&#8217;ll leave that to you!</p>
<h3>Further Reading &amp; Resources</h3>
<p>Most of these resources a little out of date for Wordpress 2.5. Most of the screen shots show the admin widget pannel for 2.3 instead of 2.5.</p>
<ul>
<li><a href="http://automattic.com/code/widgets/api/">Widget API Documentation</a> - documents the functions register_sidebar and   register_sidebar_widget</li>
<li><a href="http://automattic.com/code/widgets/plugins/">Making New Widgets</a> - Recommended tips for designing plugin widgets.</li>
<li><a href="http://automattic.com/code/widgets/themes/">Widetizing Your Wordpress Themes</a></li>
<li><a href="http://codex.wordpress.org/Plugin_API/Action_Reference">Worpress API Actions</a> - Documents action hooks like &#8216;plugins_loaded&#8217; you can use to change Wordpress.</li>
<li><a href="http://codex.wordpress.org/Plugin_API/Filter_Reference">Wordpress API Filters</a> - Documents all the filters you can use to change Wordpress.</li>
<li><a href="http://automattic.com/code/widgets/">Wordpress Widget Information</a> - Basic information on widgets.</li>
<li><a href="http://wordpress.org/development/2008/03/wordpress-25-brecker/">Blog Post: Wodpress 2.5 Released</a> - A blog post introducing Wordpress 2.5.</li>
<li><a href="/makebeta/wordpress/wordpress-customization/">Makebeta Wordpress Customization</a> - A tutorial I wrote about how to customize Wordpress.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/wordpress/making-a-wordpress-25-sidebar-widget-plugin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pick Up A Great Website For Cheap</title>
		<link>http://www.merchantos.com/makebeta/tools/sitefinder301/</link>
		<comments>http://www.merchantos.com/makebeta/tools/sitefinder301/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 23:47:17 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/tools/sitefinder301/</guid>
		<description><![CDATA[<div class="right" style="margin: 15px;">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/09/sitefinder301_shark.jpg' title='Shark'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/09/sitefinder301_shark.jpg' alt='Shark' /></a>
</div>
We've all seen those websites that show up in the SERPs that are just there because the domain has been around for years and has managed to pick up a few links along the way. They're listed in dmoz, PR 4 or 5, but the content is really old. What if there was a way to...]]></description>
			<content:encoded><![CDATA[<div class="right" style="margin: 15px;">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/09/sitefinder301_shark.jpg' title='Shark'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/09/sitefinder301_shark.jpg' alt='Shark' /></a>
</div>
<p>We&#8217;ve all seen those websites that show up in the SERPs that are just there because the domain has been around for years and has managed to pick up a few links along the way. They&#8217;re listed in dmoz, PR 4 or 5, but the content is really old. What if there was a way to dig through the list of sites in your niche and find the few that been abandoned by their owners? Don&#8217;t you think a some of those owners would be willing to sell you their websites far below their true value? They are! You just need to find them.</p>
<h2>Old, Authoritative, Ranking Websites Are Waiting For You</h2>
<p>I built a tool that will help you find sites you can buy that are old and authoritative in your niche. There are websites in almost every niche that have built up authority over years but have been abandoned by their owners. These absentee owners are often happy to unload their old websites on you for very little. The trick is finding these hidden gems amongst all the active websites. You can spend hours going through directories and SERPs looking for websites that are abandoned or <strong>you can use the tool I built to find them quickly and automatically.</strong></p>
<h2>Sitefinder301 - Find A Killer Deal On An Old Website.</h2>
<p>Sitefinder301 uses the dmoz Open Directory and the Internet Archive to find sites that are relevant to your niche that haven&#8217;t been updated in a long time. If you&#8217;re lucky you can find a great site with an owner that is willing to sell it for very little.</p>
<h2>How It Works</h2>
<p>You supply a dmoz category URL and Sitefinder301 examines all the sites that are in it and finds the ones that haven&#8217;t been updated in a long time. It gives you PageRank and Whois information on the sites so you can quickly determine if it&#8217;s worth buying and who to contact. It&#8217;s a quick and easy way to come up with a short list of acquisition targets out of hundreds of possible websites.</p>
<h2>Enough Already Where&#8217;s The Goods?</h2>
<p>Ok here it is, the product of late night php hacking:<br />
<a href="/makebeta/sitefinder301/" title="Find Killer Deals On Old Websites: Sitefinder301"><br />
<img src="/makebeta/sitefinder301/sitefinder301_button.jpg" width="150" height="44" border="0" alt="Find Killer Deals On Old Websites: Sitefinder301"><br />
</a></p>
<h2>Benefiting From Your Acquisition</h2>
<p>Here&#8217;s a couple ideas for what to do with your new site:</p>
<ul>
<li>Put up new content and rank quickly for valuable terms. Build upon the old sites authority and create something of real value.</li>
<li>Put up a page that promotes your product or service and funnels visitors to your current website.</li>
<li>Redirect the old site to your current site and benefit from it&#8217;s authority and traffic.</li>
</ul>
<h2>Share And Share Alike</h2>
<p>Sitefinder301 is open source. You can install it on your SEO tools website or hack it for your own purposes. Download the source here: <a href="/makebeta/sitefinder301/sitefinder301code.zip">/makebeta/sitefinder301/sitefinder301code.zip</a><br />
All I ask is you pass some link friendship back my direction :).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/tools/sitefinder301/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Floating Point Comparisons In PHP and Javascript</title>
		<link>http://www.merchantos.com/makebeta/php/floating-point-comparisons-in-php-and-javascript/</link>
		<comments>http://www.merchantos.com/makebeta/php/floating-point-comparisons-in-php-and-javascript/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 07:33:05 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/php/floating-point-comparisons-in-php-and-javascript/</guid>
		<description><![CDATA[A simple function to ease your floating point comparison headaches. Implemented in PHP and Javascript. Compare floating point numbers safely like this: moneycomp($income,'>',$debt) return 'Happy'; Escape the plague of the .000000001!]]></description>
			<content:encoded><![CDATA[<p>I just had to make a quick post about this. Hopefully it will save someone the trouble I&#8217;ve been through!</p>
<h1>Beware Comparing Floating Point Values Can Be Hazardous!</h1>
<h3>&#8220;The curse of the .0000000001 and .9999999999!&#8221;</h3>
<p>Here&#8217;s the problem. Say you&#8217;re comparing two floating point numbers a (71.00) and b (71.00) to see if they are the same. The problem is if you&#8217;ve done any calculations to arrive at these numbers they might actually be stored as 71.00000000001. Now if one of them is stored that way and the other isn&#8217;t and you compare the two to see if they are equal you&#8217;ll get a FALSE as the response, even though they should be the same.</p>
<p>This isn&#8217;t a bug, it&#8217;s how floating point comparisons are designed to work. It makes it so people writing complex software that requires floating point arithmetic can do what they need to. Unfortunately for the rest of us that usually are just using floating point numbers to represent things like currency (dollars in my case) it really makes life difficult!</p>
<h2>PHP Floating Point Comparison Made Easy</h2>
<p>Here&#8217;s my php function that compares floating point numbers:</p>
<pre style="clear: both;"><code>function moneycomp($a,$comp,$b,$decimals=2) {
	$res = bccomp($a,$b,$decimals); // php function for comparing floating point numbers with a specified level of precision
	switch ($comp) {
		case "&gt;":
			return ($res==1);
		case "&gt;=":
			return ($res==1 || $res==0);
		case "&lt;":
			return ($res==-1);
		case "&lt;=":
			return ($res==-1 || $res==0);
		default:
		case "==":
			return ($res==0);
	}
}

// example usage: if ($total &gt; $payments) ...
if (moneycomp($total,'&gt;',$payments)) ...

// example usage: if ($debt &lt;= $income) ...
if (moneycomp($debt,'&lt;=',$income) ...

// example usage: if ($cost == $price) ...
if (moneycomp($cost,'==',$price) ...</code></pre>
<p>So that makes life really simple. You just write your comparisons wrapped in the moneycomp() function.</p>
<h2>Javascript Floating Point Comparison Made Easy</h2>
<p>And here&#8217;s my javascript function that compares floating point numbers:</p>
<pre style="clear: both;"><code>function moneycomp(a,comp,b,decimals) {
	if (!decimals)
		decimals = 2;
	var multiplier = Math.pow(10,decimals);
	a = Math.round(a * multiplier); // multiply to do integer comparison instead of floating point
	b = Math.round(b * multiplier);
	switch (comp) {
		case "&gt;":
			return (a &gt; b);
		case "&gt;=":
			return (a &gt;= b);
		case "&lt;":
			return (a &lt; b);
		case "&lt;=":
			return (a &lt;= b);
		case "==":
			return (a == b);
	}
	return null;
}

// example usage: if (total &gt; payments) ...
if (moneycomp(total,'&gt;',payments)) ...

// example usage: if (debt &lt;= income) ...
if (moneycomp(debt,'&lt;=',income) ...

// example usage: if (cost == price) ...
if (moneycomp(cost,'==',price) ...</code></pre>
<h3>Resources And Further Reading</h3>
<ul class="unordered">
<li><a href="http://php.net/float">PHP Floating Point Numbers</a></li>
<li><a href="http://devzone.zend.com/article/168-PHP-Gotchas">PHP Gotchas!</a></li>
<li><a href="http://php.net/bccomp">PHP Manual: bccomp() function</a></li>
<li><a href="http://www.javascripter.net/faq/mathfunc.htm">Javascript Math Functions</a></li>
<li><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math">Mozilla Documentation - Javascript 1.5 Math Object</a>
</ul>
<p>Thanks for visiting. Stay tuned, I&#8217;m about to release a cool SEO tool I&#8217;ve been working on and using =).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/php/floating-point-comparisons-in-php-and-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Scraping Links With PHP</title>
		<link>http://www.merchantos.com/makebeta/php/scraping-links-with-php/</link>
		<comments>http://www.merchantos.com/makebeta/php/scraping-links-with-php/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 07:19:43 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/php/scraping-links-with-php/</guid>
		<description><![CDATA[<div class="right" style="padding: 10px;">
<img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/abstract_network.thumbnail.jpg' alt='Abstract Network' />
</div>
In this tutorial I will show you how to build a PHP script that will scrape links from a web page. I also discuss the legal issues involved with scraping website content.]]></description>
			<content:encoded><![CDATA[<div class="right" style="padding: 10px;">
<img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/abstract_network.jpg' alt='Abstract Network' />
</div>
<p>In this tutorial you will learn how to build a PHP script that <a href="http://en.wikipedia.org/wiki/Web_scraping">scrapes</a> links from any web page.</p>
<h3>What You&#8217;ll Learn</h3>
<ol>
<li><a href="#curl_content">How to use cURL</a> to get the content from a website (URL).</li>
<li><a href="#php_dom">Call PHP DOM functions</a> to parse the HTML so you can extract links.</li>
<li><a href="#xpath_easy">Use XPath to grab links</a> from specific parts of a page.</li>
<li><a href="#store_links">Store the scraped links</a> in a MySQL database.</li>
<li><a href="#put_together">Put it all together into a link scraper.</a></li>
<li><a href="#more_uses">What else you could use a scraper for.</a></li>
<li><a href="#legal_issues">Legal issues</a> associated with scraping content.</li>
</ol>
<h3>What You Will Need</h3>
<ul>
<li>Basic knowledge of <a href="http://php.net/">PHP</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/">MySQL</a>.</li>
<li>A web server running PHP 5.</li>
<li>The <a href="http://us.php.net/curl">cURL</a> extension for PHP.</li>
<li>MySQL - if you want to store the links.</li>
</ul>
<div class="right" style="padding: 10px;">
<img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/backhoe_digging.jpg' alt='Backhoe Digging' />
</div>
<h2 id='curl_content'>Get The Page Content</h2>
<p><a href="http://php.net/curl">cURL</a> is a great tool for making requests to remote servers in PHP. It can imitate a browser in pretty much every way. Here&#8217;s the code to grab our target site content:</p>
<pre style="clear: both;"><code>$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
if (!$html) {
	echo "&lt;br /&gt;cURL error number:" .curl_errno($ch);
	echo "&lt;br /&gt;cURL error:" . curl_error($ch);
	exit;
}</code></pre>
<p>If the request is successful $html will be filled with the content of $target_url. If the call fails then we&#8217;ll see an error message about the failure.</p>
<pre><code>curl_setopt($ch, CURLOPT_URL,$target_url);</code></pre>
<p>This line determines what URL will be requested. For example if you wanted to scrape this site you&#8217;d have $target_url = &#8220;/makebeta/&#8221;. I won&#8217;t go into the rest of the options that are set (except for CURLOPT_USERAGENT - see below). You can read an in depth <a href="http://devzone.zend.com/node/view/id/1081">tutorial on PHP and cURL here</a>.</p>
<h2><i>Tip: Fake Your User Agent</i></h2>
<p>Many websites won&#8217;t play nice with you if you come knocking with the wrong <a href="http://en.wikipedia.org/wiki/User_agent">User Agent</a> string. What&#8217;s a User Agent string? It&#8217;s part of every request to a web server that tells it what type of agent (browser, spider, etc) is requesting the content. Some websites will give you different content depending on the user agent, so you might want to experiment. You do this in cURL with a call to curl_setopt() with CURLOPT_USERAGENT as the option:</p>
<pre><code>$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);</code></pre>
<p>This would set cURL&#8217;s user agent to mimic Google&#8217;s. You can find a comprehensive list of user agents here: <a href="http://www.user-agents.org/index.shtml">User Agents</a>.</p>
<h3>Common User Agents</h3>
<p>I&#8217;ve done a bit of the leg work for you and gathered the <a href="<br />
http://whatsmyuseragent.com/CommonUserAgents.asp">most common user agents</a>:</p>
<h4>Search Engine User Agents</h4>
<ul>
<li>Google - Googlebot/2.1 ( http://www.googlebot.com/bot.html) </li>
<li>Google Image - Googlebot-Image/1.0 ( http://www.googlebot.com/bot.html)</li>
<li>MSN Live - msnbot-Products/1.0 (+http://search.msn.com/msnbot.htm)</li>
<li>Yahoo -  Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)</li>
<li>ask</li>
</ul>
<h4>Browser User Agents</h4>
<ul>
<li>Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6</li>
<li>IE 7 - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)</li>
<li>IE 6 - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)</li>
<li>Safari - Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/522.11 (KHTML, like Gecko) Safari/3.0.2</li>
<li>Opera - Opera/9.00 (Windows NT 5.1; U; en)</li>
</ul>
<h2 id='php_dom'>Using PHP&#8217;s DOM Functions To Parse The HTML</h2>
<div class="left" style="padding: 10px;">
<img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/puzzle_workers.jpg' alt='Puzzle Workers' />
</div>
<p>PHP provides with a really cool tool for working with HTML content: <a href="http://php.net/dom">DOM Functions</a>. The DOM Functions allow you to parse HTML (or XML) into an object structure (or DOM - Document Object Model). Let&#8217;s see how we do it:</p>
<pre style="clear:both;"><code>$dom = new DOMDocument();
@$dom-&gt;loadHTML($html);</code></pre>
<p>Wow is it really that easy? Yes! Now we have a nice <a href="http://php.net/dom/#dom.class.domdocument">DOMDocument</a> object that we can use to access everything within the HTML in a nice clean way. I discovered this over at Russll Beattie&#8217;s post on: <a href="http://www.russellbeattie.com/blog/using-php-to-scrape-web-sites-as-feeds">Using PHP TO Scrape Sites As Feeds</a>, thanks Russell!</p>
<p><strong>Tip: You may have noticed I put @ in front of loadHTML(), this suppresses some annoying warnings that the HTML parser throws on many pages that have non-standard compliant code.</strong></p>
<h2 id='xpath_easy'>XPath Makes Getting The Links You Want Easy</h2>
<p>Now for the real magic of the DOM: <a href="http://php.net/dom/#dom.class.domxpath">XPath</a>! XPath allows you to gather collections of DOM nodes (otherwise known as tags in HTML). Say you want to only get links that are within unordered lists. All you have to do is write a query like &#8220;/html/body//ul//li//a&#8221; and pass it to <a href="http://php.net/manual/en/function.dom-domxpath-evaluate.php">XPath->evaluate()</a>. I&#8217;m not going to go into all the ways you can use XPath because I&#8217;m just learning myself and someone else has already made a great list of examples: <a href="http://doc.ddart.net/xmlsdk/htm/xpath_syntax2_3prn.htm">XPath Examples</a>. Here&#8217;s a code snippet that will just get every link on the page using XPath:</p>
<pre><code>$xpath = new DOMXPath($dom);
$hrefs = $xpath-&gt;evaluate("/html/body//a");</code></pre>
<h2 id='store_links'>Iterate And Store Your Links</h2>
<p>Next we&#8217;ll iterate through all the links we&#8217;ve gathered using XPath and store them in a database. First the code to iterate through the links:</p>
<pre><code>for ($i = 0; $i &lt; $hrefs-&gt;length; $i++) {
	$href = $hrefs-&gt;item($i);
	$url = $href-&gt;getAttribute('href');
	storeLink($url,$target_url);
}</code></pre>
<p>$hrefs is an object of type <a href="http://php.net/dom/#dom.class.domnodelist">DOMNodeList</a> and <a href="http://php.net/manual/en/function.dom-domnodelist-item.php">item()</a> is a function that returns a DOMNode object for the specified index. The index can be between 0 and $hrefs->length. So we&#8217;ve got a loop that retrieves each link as a DOMNode object.</p>
<pre><code>$url = $href-&gt;getAttribute('href');</code></pre>
<p>DOMNodes inherit the <a href="http://php.net/manual/en/function.dom-domelement-getattribute.php">getAttribute()</a> function from the <a href="http://php.net/dom/#dom.class.domelement">DOMElement</a> class. getAttribute() returns any attribute of the node (in this case an &lt;a&gt; tag with the href attribute). Now we&#8217;ve got our URL and we can store it in the database.</p>
<p>We&#8217;ll want a database table that looks something like this:</p>
<pre><code>CREATE TABLE `links` (
`url` TEXT NOT NULL ,
`gathered_from` TEXT NOT NULL ,
`time_stamp` TIMESTAMP NOT NULL
);</code></pre>
<p>We&#8217;ll a storeLink() function to put the links in the database. I&#8217;ll assume you know the basics of how to connect to a database (If not grab a <a href="http://www.php-mysql-tutorial.com/">MySQL &amp; PHP tutorial here</a>).</p>
<pre><code>function storeLink($url,$gathered_from) {
	$query = "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
	mysql_query($query) or die('Error, insert query failed');
}</code></pre>
<h2 id='put_together'>Your Completed Link Scraper</h2>
<pre><code>function storeLink($url,$gathered_from) {
	$query = "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
	mysql_query($query) or die('Error, insert query failed');
}

$target_url = "http://www.merchantos.com/";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
	echo "&lt;br /&gt;cURL error number:" .curl_errno($ch);
	echo "&lt;br /&gt;cURL error:" . curl_error($ch);
	exit;
}

// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom-&gt;loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath-&gt;evaluate("/html/body//a");

for ($i = 0; $i &lt; $hrefs-&gt;length; $i++) {
	$href = $hrefs-&gt;item($i);
	$url = $href-&gt;getAttribute('href');
	storeLink($url,$target_url);
	echo "&lt;br /&gt;Link stored: $url";
}</code></pre>
<h2 id='more_uses'>What Else Could I Do With This Thing?</h2>
<p>The possibilities are limitless. For starters you might want to store a list of sites that you want scraped in a database and then set up the script so it runs on a regular basis to scrap those sites. You could then compare the link structure over time or maybe republish the links in some sort of directory. Leave a comment below and say what you&#8217;re using this script for. Here are a few other things people have done with scrapers in the past:</p>
<ul>
<li>Build a search engine from the content you gather. <a href="http://www.google.com">Google</a></li>
<li>Analyze a site to determine how well it is SEO optomized for keywords. <a href="http://tools.seobook.com/general/keyword-density/">SEO Book&#8217;s Keyword Density Tool</a>.</li>
<li>Republish free content dynamically on your website.</li>
<li>Create an RSS feed from a website. <a href="http://www.russellbeattie.com/blog/using-php-to-scrape-web-sites-as-feeds">Using PHP To Scrape Web Sites As Feeds</a></li>
</ul>
<div class="right" style="padding: 10px;">
<img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/lawbook_gavel.jpg' alt='Law Book and Gavel' />
</div>
<h2 id='legal_issues'>Is Scraping Content Legal?</h2>
<p>There is no easy answer to this question. Many organizations scrap content from all over the web - Google, Yahoo, Microsoft, and many others. These companies get away with it under <a href="http://www.copyright.gov/title17/92chap1.html#107">fair use</a> and because site owners want to be included in the search results. However, there have been <a href="http://www.searchenginejournal.com/partial-ruling-on-google-image-search-copyright-infringement/2978/">copyright infringement rulings</a> against these companies.</p>
<p><strong>The real answer is that it depends who you scrape and what you do with the content.</strong> Basic copyright law gives authors an automatic <a href="http://www.copyright.gov/title17/92chap1.html">copyright</a> on everything they create. But the same law permits <a href="http://www.copyright.gov/title17/92chap1.html#107">fair use</a> of copyrighted material. Fair use includes: criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research. But even these uses could be considered copyright infringement in some circumstances. So be careful before you claim &#8220;fair use&#8221; as your defense!</p>
<p>Here&#8217;s a couple sites that have <strong>granted you the right to use their content</strong>. They do require you to attribute the content to the author or the URL you scraped it from:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Wikipedia:Copyrights">Wikipedia</a> - GNU Free Documentation License</li>
<li><a href="http://www.dmoz.org/license.html">Open Directory Project</a> - Open Directory License</li>
<li><a href='http://creativecommons.org/' title='Creative Commons'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/08/creative_commons_logo.gif' alt='Creative Commons Logo' /></a><br />
<a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons</a> - Creative Commons Attribution 3.0</p>
<div>Many sites publish their content under some form of the Creative Commons license. You can search for creative commons licensed works here: <a href="http://search.creativecommons.org/">Creative Commons Search</a>. Remember that it&#8217;s your responsibility to verify the copyright rules for anything you use, even stuff found using the Creative Commons Search.</div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/php/scraping-links-with-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Facebook PHP Tutorial</title>
		<link>http://www.merchantos.com/makebeta/facebook/facebook-php-tutorial/</link>
		<comments>http://www.merchantos.com/makebeta/facebook/facebook-php-tutorial/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 22:27:26 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/facebook/facebook-php-tutorial/</guid>
		<description><![CDATA[<div class="right">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/logo-f8-150x123.gif' title='F8 Logo'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/logo-f8-150x123.gif' alt='F8 Logo' /></a>
</div>
I will cover the basics of using the Facebook PHP Client Library and how to get your application started, including:
<ol>
<li>Installing The Facebook Developer Application</li>
<li>Downloading The Facebook PHP Client Library</li>
<li>Creating Your Application</li>
<li>Hello Facebook! Example</li>
<li>FBML - Facebook Markup Language</li>
<li>Using the Facebook API</li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href='http://developers.facebook.com/' title='Facebook Platform Intro'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_platform_intro.jpg' alt='Facebook Platform Intro' /></a></p>
<h2>Facebook Is The New Black.</h2>
<p>Everyone is talking about Facebook and their new Application Platform:</p>
<ul>
<li><a href="http://www.techcrunch.com/2007/05/24/facebook-launches-facebook-platform-they-are-the-anti-myspace/">Techcrunch - Facebook Launches Facebook Platform; They are the Anti-MySpace</a></li>
<li><a href="http://mashable.com/2007/07/31/facebook-powertools-1/">Mashable - Facebook Powertools: 150+ Apps, Scripts and Add-ons for Facebook</a></li>
<li><a href="http://digg.com/tech_news/The_Impact_of_Facebook_s_Platform">Digg - The Impact of Facebook&#8217;s Platform</a></li>
<li><a href="http://mashable.com/2007/05/24/facebook-platform-30-apps/">Mashable - Facebook Platform: 30+ Awesome Applications for Facebook</a></li>
<li><a href="http://valleywag.com/tech/facebook/developers-beware-facebook-really-is-the-new-microsoft-283941.php">Valleywag -  Developers, beware. Facebook really is the new Microsoft.</a></li>
<li><a href="http://blog.facebook.com/blog.php?post=2437282130">Facebook&#8217;s Blog Post on the Facebook Platform</a></li>
<li><a href="http://www.insidefacebook.com/2007/07/29/hottest-facebook-apps-july-28th/">Inside Facebook - Hottest Facebook Apps: July 28th</a></li>
</ul>
<p>And I have to admit I think it&#8217;s pretty cool too. So I decided to create an application that uses the Facebook Platform. I&#8217;m writing the application in PHP and I thought it might be useful for others to know how to write their own Facebook applications with PHP. So here we are.</p>
<h2>What Will I Learn?</h2>
<p>I will cover the basics of using the Facebook PHP library and how to get your application started, including:</p>
<ol>
<li>Installing The Facebook Developer Application</li>
<li>Downloading The Facebook PHP Client Library</li>
<li>Creating Your Application</li>
<li>Hello Facebook! Example</li>
<li>FBML - Facebook Markup Language</li>
<li>Using the Facebook API</li>
</ol>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/logo-f8-150x123.gif' title='F8 Logo'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/logo-f8-150x123.gif' alt='F8 Logo' /></a></p>
<h2>Getting Started As A Facebook Developer</h2>
<p>The first thing you need of course is a Facebook account. You can sign up for Facebook at <a href="http://www.facebook.com">www.facebook.com</a>. Once you have your account you&#8217;ll need to install the Facebook developer application. This little tool will allow you to generate your application profile and get an API key (more on that later). Once you&#8217;ve logged into Facebook visit: www.facebook.com/developers/ or click below to install the developer application:</p>
<p><strong><a href="http://www.facebook.com/developers"><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/icn_dev_app.gif' alt='Facebook Developer Icon' /> Add The Facebook Developer Application.</a></strong></p>
<h2>PHP Facebook API Client Library</h2>
<p>Facebook has created a nice php library that allows you to use their API without writing a lot of extra code. You can grab the PHP version of the library at <a href="http://developers.facebook.com/resources.php">developers.facebook.com/resources.php</a>. Download the &#8216;PHP (4 and 5) Client Library&#8217;.</p>
<p>Once you&#8217;ve downloaded the library unzip it into a folder that is accessible by your PHP scripts. So you would have something like /php_include_directory/facebook/ and in that folder you will have the entire Facebook PHP Client Library (3 folders: client, footprints, php4client). I&#8217;m using PHP5 so my examples will be using the &#8220;client&#8221; directory of the library. The footprints folder is an example application.</p>
<h2>Creating Your Application Profile And API Key</h2>
<div class="right">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/developer_start_new_app.jpg' title='Facebook Developer Set Up New Application'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/developer_start_new_app.jpg' alt='Facebook Developer Set Up New Application' /></a>
</div>
<p>Facebook requires that you register each application you make. Once you&#8217;ve logged into <a href="http://www.facebook.com">Facebook</a> and installed the <a href="http://developers.facebook.com/resources.php">developer application</a> go to the developer panel (or <a href="http://developers.facebook.com/resources.php">click here</a>). Inside the developer application click &#8220;Set Up New Application&#8221;.</p>
<p><strong>Choose a name for your application</strong>. This is important because it&#8217;s what users will see when they are browsing the application directory. Currently the name field is the only thing used when searching for applications. So it&#8217;s doubly important at this point.</p>
<p><strong>Click on &#8220;Optional Fields&#8221;.</strong> Then fill out the <strong>Callback Url</strong> with the location of your script. This is the public URL on your webserver where the Facebook application will be.</p>
<p><strong>Next fill out the &#8220;Canvas Page URL&#8221;</strong>. This is your application URL within Facebook. For example if the application was called &#8220;Makebeta Is Cool&#8221; then the application URL could be: &#8220;makebeta&#8221; which would make the full URL: http://apps.facebook.com/makebeta/.</p>
<p>Check <strong>Yes</strong> for <strong>Can your application be added on Facebook?</strong></p>
<p>You should check the <strong>Developer Mode</strong> checkbox so that no one can add your application until you are done working on it.</p>
<p>Under <strong>Integration Points</strong> fill out <strong>Side Nav URL</strong> with the full Canvas Page URL. In the example above it would be http://apps.facebook.com/makebeta/. This allows users to add your application to their Facebook left side bar navigation.</p>
<p><strong>All of these settings can be changed after the application has been created.</strong> But it&#8217;s a good idea not to change the Canvas Page URL or Name once you have users that have installed your application.</p>
<p><strong>Further Reading:</strong> <a href="http://www.ajaxninja.com/?p=55">Starting your First Facebook App: Demystifying Application Form Field by Field</a></p>
<div class="right">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_app_keys.jpg' title='Facebook App Key'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_app_keys.jpg' alt='Facebook App Key' /></a></div>
<p><strong>Get the API Key and Secret.</strong> You should now see your application listed with a unique API Key and Secret code. You&#8217;ll use these within your application.</p>
<h2>Hello Facebook!</h2>
<p>Let&#8217;s create a really simple first application that just says hello to the current Facebook user. Here&#8217;s the code for the Hello Facebook! application:</p>
<pre>
<code>&lt;?php
/* include the PHP Facebook Client Library to help
  with the API calls and make life easy */
require_once('facebook/client/facebook.php');

/* initialize the facebook API with your application API Key
  and Secret */
$facebook = new Facebook(YOUR_API_KEY,YOUR_SECRET_CODE);

/* require the user to be logged into Facebook before
  using the application. If they are not logged in they
  will first be directed to a Facebook login page and then
  back to the application's page. require_login() returns
  the user's unique ID which we will store in fb_user */
$fb_user = $facebook-&gt;require_login();

/* now we will say:
  Hello USER_NAME! Welcome to my first application! */
?&gt;

Hello &lt;fb:name uid='&lt;?php echo $fb_user; ?&gt;' useyou='false' possessive='true' /&gt;! Welcome to my first application!

&lt;?php

/* We'll also echo some information that will
  help us see what's going on with the Facebook API: */
echo "&lt;pre&gt;Debug:" . print_r($facebook,true) . "&lt;/pre&gt;";

?&gt;</code>
</pre>
<p>So what happens when a user hits the Canvas Page URL (from the example it would be: http://apps.facebook.com/makebeta/)? The <strong>require_login()</strong> call will produce a screen like this for the user:</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_require_login.jpg' title='Facebook Require Login Screen'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_require_login.jpg' alt='Facebook Require Login Screen' /></a></p>
<p>If you change require_login() to <strong>require_add()</strong> the user will get a page that looks like this:</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_require_add.jpg' title='Facebook Require Add Screen'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_require_add.jpg' alt='Facebook Require Add Screen' /></a></p>
<p>After the user logs into or adds the application they will get the canvas page with the &#8220;Hello&#8230;&#8221; text. It should look something like this:</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_hello_screen.jpg' title='Facebook Hello Screen'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/07/facebook_hello_screen.jpg' alt='Facebook Hello Screen' /></a></p>
<h2>Facebook Markup Language - FBML</h2>
<p>Facebook has provided a bunch of built in tags that will render dynamic data inside your application. All you have to do is include the tags with the correct parameters. In the example above the <strong>fb:name</strong> tag is used to generate the user&#8217;s name on the canvas page. fb:name has a couple of parameters, one of which is <strong>uid</strong>. In the example above we set uid = $fb_user which is the unique ID of the current user. There are lots of FBML tags you can use, check them all out at: <a href="http://developers.facebook.com/documentation.php?doc=fbml">developers.facebook.com/documentation.php?doc=fbml</a></p>
<h2>Facebook API REST-based Interface</h2>
<p>The Facebook Client Library provides you with an easy to use wrapper for the Facebook API REST interface. All of the API calls are available under the $facebook->api_client object (after you initiate the $facebook object). Many of the calls will require that the user has either added or logged into the application. Here&#8217;s an example call that would retrieve the user&#8217;s About Me text from their profile:</p>
<pre><code>$fb_user = $facebook-&gt;user;
$about = $facebook-&gt;api_client-&gt;users_getInfo($fb_user,'about_me');</code></pre>
<p>There are a number of API calls, and a list of them can be found here:<br />
<a href="http://developers.facebook.com/documentation.php">developers.facebook.com/documentation.php</a></p>
<h2>Resources and Further Reading</h2>
<p>These are very helpful pieces of information that I highly recommend reading before you get too far into making your Facebook application.</p>
<ul>
<li><a href="http://wiki.developers.facebook.com/index.php/Random_questions#Basic_Application_Architecture">Basic Facebook Application Architecture</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Random_questions#URLS_in_my_application">How URLs Are Handled Within An Application</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Your_callback_page_and_you">Understanding Your Callback Page</a></li>
</ul>
<p>And of course the official documentation / developer site:</p>
<ul>
<li><a href="http://developers.facebook.com/">Facebook Developers Site</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Main_Page">Facebook Developers Wiki</a></li>
</ul>
<p>Other Facebook tutorials and how-to articles:</p>
<ul>
<li><a href="http://services.tucows.com/developers/2007/07/25/getting-started-with-facebook-application-development/">Tucows - Getting Started With Facebook Application Development</a></li>
<li><a href="http://padrenel.blogs.experienceproject.com/3459.html">10 Things That Would Have Been Nice to Know When Starting My Facebook Application</a></li>
<li><a href="http://www.sitepoint.com/article/developing-facebook-platform">Developing with the Facebook Platform and PHP</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/facebook/facebook-php-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Spy Is Dead - Spyjax Offline</title>
		<link>http://www.merchantos.com/makebeta/tools/the-spy-is-dead/</link>
		<comments>http://www.merchantos.com/makebeta/tools/the-spy-is-dead/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 23:20:20 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">/makebeta/tools/the-spy-is-dead/</guid>
		<description><![CDATA[
I will no longer be hosting Spyjax.
It&#8217;s been fun and very interesting, but it&#8217;s time to call it quits. Spyjax is just a side project but it&#8217;s eating up server power so I&#8217;ve decided to turn it off. I kicked around the idea of turning into a real service / business but I&#8217;m just not [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; padding: 10px;"><a href='/makebeta/wp-content/uploads/101/makebeta/2007/06/the_end.jpg' title='The End Of Spyjax'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/06/the_end.jpg' alt='The End Of Spyjax' /></a></div>
<h3>I will no longer be hosting Spyjax.</h3>
<p>It&#8217;s been fun and very interesting, but it&#8217;s time to call it quits. Spyjax is just a side project but it&#8217;s eating up server power so I&#8217;ve decided to turn it off. I kicked around the idea of turning into a real service / business but I&#8217;m just not that interested in it.</p>
<h3>Thank You For Commenting and Linking!</h3>
<p>It&#8217;s been really fun reading everyone&#8217;s comments here and on all the blogs that wrote about Spyjax. There were some great discussions around privacy and ethics. Some of the best comments where on the SEO Book blog: <a href="http://www.seobook.com/archives/002271.shtml">Spy on Visitor Browsing History for Competitive Research</a>.</p>
<h3>Full Source Code Available</h3>
<p>Because I&#8217;ve decided to shutdown the service I&#8217;m giving away all the code as open source. Anyone can install the Spyjax service on their server. Someone else could even start the service up and let others user it. You can download the source here: <a href="/makebeta/wp-content/uploads/101/makebeta/2008/05/spyjax_service.zip">Spyjax Source Code</a>.<br />
Spyjax uses PHP and MySQL so most web servers should be able to run it. You&#8217;ll need to do a little bit of configuration, mainly in the config.php file. There might be a place or two where you need to put your email address for sign up and feedback emails to work correctly. Also the urls.php file needs your MySQL database host, user name, and password. The service assumes that it&#8217;s using a database named &#8220;spyjax&#8221;. The schema for the database can be found in spyjax.sql. If you have any questions about how to install it contact me using the form on <a href="/makebeta/spyjax/">over here</a>.</p>
<h3>4,808,202 URLs Were Found</h3>
<p>While Spyjax was running it tracked 282,542 visitors and collected 4,802,202 URLs from their browser history. Here&#8217;s the top 50 URLs found by Spyjax:</p>
<ol>
<li>http://www.google.com - 59927</li>
<li>http://www.yahoo.com  - 45591</li>
<li>http://www.myspace.com - 29869</li>
<li>http://www.youtube.com - 27057</li>
<li>http://www.msn.com - 22045</li>
<li>http://www.hotmail.com - 16969</li>
<li>http://www.ebay.com  - 16123</li>
<li>http://www.facebook.com - 13855</li>
<li>http://www.mapquest.com - 11689</li>
<li>http://www.cnn.com - 9285</li>
<li>http://www.weather.com - 8634</li>
<li>http://www.amazon.com - 7852</li>
<li>http://www.wikipedia.org - 7401</li>
<li>http://www.aol.com - 7381</li>
<li>http://www.imdb.com - 6023</li>
<li>http://www.walmart.com - 5826</li>
<li>http://www.gmail.com - 5740</li>
<li>http://www.apple.com - 5549</li>
<li>http://www.flickr.com - 5197</li>
<li>http://www.chase.com - 5053</li>
<li>http://www.ask.com - 4919</li>
<li>http://www.google.co.uk - 4876</li>
<li>http://www.bestbuy.com - 4682</li>
<li>http://www.usps.com - 4607</li>
<li>http://www.craigslist.org - 4555</li>
<li>http://www.download.com - 4474</li>
<li>http://www.digg.com - 4389</li>
<li>http://www.paypal.com - 4038</li>
<li>http://www.dell.com - 3944</li>
<li>http://www.bankofamerica.com - 3846</li>
<li>http://www.bbc.co.uk - 3798</li>
<li>http://www.southwest.com - 3753</li>
<li>http://www.adobe.com - 3704</li>
<li>http://www.comcast.net - 3657</li>
<li>http://www.t-mobile.com - 3636</li>
<li>http://www.yellowpages.com - 3584</li>
<li>http://www.monster.com - 3578</li>
<li>http://www.nytimes.com - 3556</li>
<li>http://www.live.com - 3550</li>
<li>http://www.hp.com - 472</li>
<li>http://www.orbitz.com - 3456</li>
<li>http://www.whitepages.com - 3339</li>
<li>http://www.microsoft.com - 3310</li>
<li>http://www.capitalone.com - 3251</li>
<li>http://www.ticketmaster.com - 3228</li>
<li>http://www.target.com - 3157</li>
<li>http://www.realtor.com - 3114</li>
<li>http://www.ebay.co.uk - 3064</li>
<li>http://www.kbb.com - 3036</li>
<li>http://www.blogger.com - 3031</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/tools/the-spy-is-dead/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spyjax - Your browser history is not private!</title>
		<link>http://www.merchantos.com/makebeta/tools/spyjax/</link>
		<comments>http://www.merchantos.com/makebeta/tools/spyjax/#comments</comments>
		<pubDate>Wed, 23 May 2007 08:00:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/tools/spyjax/</guid>
		<description><![CDATA[If youâ€™re like most web users, you assume that your browser history is private. For example if you visit an online store, you assume they canâ€™t see if youâ€™ve been looking at their competitor. Just a few weeks ago I assumed this was the case. Guess what? Your browser history is not private!]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like most web users, you assume that your browser history is private. For example if you visit an online store, you assume they can&#8217;t see if you&#8217;ve been looking at their competitor. Just a few weeks ago I assumed this was the case. Guess what?</p>
<h2>Your browser history is not private!</h2>
<div class="right">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/peeping_tom.jpg' title='Peeping Tom'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/05/peeping_tom.jpg' alt='Peeping Tom' /></a>
</div>
<p>In fact with a few well crafted lines of Javascript, websites can examine your browser history and record what pages you have been to. Keep reading and I&#8217;ll tell you exactly how it&#8217;s done and introduce you to a service that any webmaster can put on their site to see what pages their users have visited. I&#8217;ll also tell you exactly what type of information can be retrieved, and how you can protect yourself.</p>
<h3>How JavaScript Can Be Used To Steal Your Browser History:</h3>
<p>With <a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets" title="Cascading Style Sheets">CSS</a> website designers can make links a different color if they have been visited by the user. For example <a href="/makebeta/tools/spyjax" style="color: #000;">this link</a> should be colored differently than <a href="http://www.this-is-a-bogus.com/url/">this other link</a>. The first link you have been to before (it&#8217;s the page you are on right now) while the second link you have never visited (because it is fictitious). Now you&#8217;re thinking &#8220;but how can this be used to steal my history?&#8221;. Let&#8217;s dive a little deeper.</p>
<h3>Javascript Can Examine The Color Of Your Links = Steal Your Browsing History</h3>
<p><a href="http://en.wikipedia.org/wiki/Javascript">Javascript</a> can examine the rendered state of an HTML document, called the <a href="http://en.wikipedia.org/wiki/Document_Object_Model" title="Document Object Model">DOM</a>. One of the properties that is available through the DOM is the current CSS attributes of a node (nodes are HTML tags, one of which is the <a href="http://www.w3schools.com/html/html_links.asp" "hyper link tag">&lt;a&gt;</a> or link tag).<br />
All a website has to do to see what pages you&#8217;ve been to is place a list of links on the page and examine the color of those links. <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" title="Asynchronous JavaScript and XML">Ajax</a> can be used to retrieve a list of links to test and also send the results back to the server without the user ever knowing.<br />
The code to do this examination can be a little tricky due to cross browser issues. Here is a snippet of Javascript that can do the evaluation (based on the <a href="http://www.vdgraaf.info/hey-you-where-have-you-been.html">Hey you! Where have you been?</a> blog post by Peter van der Graaf and script from <a href="http://jeremiahgrossman.blogspot.com/">Jeremiah Grossman</a> and <a href="http://www.dicabrio.com/javascript/steal-history.php">Robert Cabri</a>):<br />
<code>&lt;pre&gt;<br />
function hasLinkBeenVisited(url) {<br />
	var link = document.createElement('a');<br />
	link.href = url;<br />
	document.body.appendChild(link);<br />
	if (link.currentStyle) {<br />
		var color = link.currentStyle.color;<br />
		if (color == '#ff0000')<br />
			return true;<br />
		return false;<br />
	} else {<br />
		link.setAttribute("href",url);<br />
		var computed_style = document.defaultView.getComputedStyle( link, null );<br />
		if (computed_style) {<br />
			if (computed_style.color == 'rgb(255, 0, 0)')<br />
				return true;<br />
		}<br />
		return false;<br />
	}<br />
}<br />
&lt;/pre&gt;</code><br />
The code above assumes that CSS rules are making links that have been visited red (#ff0000) and new links a different color.</p>
<h3>Ajax Can Be Used To Examine Thousands Of Links Dynamically</h3>
<p>A clever web developer can use Ajax to dynamically load a list of links for each new visitor. A couple hundred links can be grabbed at a time and examined without slowing down the page noticeably. If you spend just a few seconds on a website thousands of URLs can be checked.</p>
<h2>The Limitations</h2>
<p>This technique does not allow sites to read your entire browser history. It only allows a site to test a predefined list of URLs to see if you have visited any of them. It&#8217;s like the card game &#8220;go fish&#8221;, you can&#8217;t see the players cards but you can ask them if they have any particular card. Most likely the way this technology would be used is to examine a list of competing URLs. This could give a website valuable information on who their competitors really are and what information on those sites is being looked at.</p>
<h2>How To Stop People From Spying On Your Browser History</h2>
<p>There are two sure fire ways to stop people from stealing your browser history.</p>
<ol>
<li>The nuclear option is to <strong>disable JavaScript within your browser</strong>. In Firefox you&#8217;d just go to Tools -> Options -> Content tab and then uncheck &#8220;Enable JavaScript&#8221;. This method is very limiting because you probably enjoy all the JavaScript goodness on the web.</li>
<li><strong>Limit your browser history</strong>. The less browser history you store the fewer URLs someone can steal from that history. In Firefox you can change the amount of browser history by going to Tools -> Options -> Privacy and then either uncheck the &#8220;Remember visited pages&#8221; checkbox or change the number of days that history is stored for.</li>
</ol>
<h2 style="background-color: #FFFF99">UPDATE: Spyjax Has Been Turned Off</h2>
<p>I will no longer be hosting Spyjax. It&#8217;s been fun and very interesting, but it&#8217;s time to call it quits. <a href="/makebeta/tools/the-spy-is-dead/">Read more here.</a></p>
<h1>Introducing <a href="/makebeta/spyjax/">Spyjax</a></h1>
<h3>One Line Of JavaScript And You Can Start Spying</h3>
<div class="right">
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/spycat.jpg' title='Spycat stealin urls'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/05/spycat.jpg' alt='Spycat stealin urls' /></a>
</div>
<p>Ok, now that I&#8217;ve explained how this all works and how you can protect yourself, I want to introduce you to a small piece of code that I wrote that makes it super easy for you to spy on your website visitors. It&#8217;s called Spyjax and here&#8217;s how it works.</p>
<ol>
<li>
<h5>Sign Up For An Account</h5>
<p> All that&#8217;s required is your email address and a password of your choosing. I promise I will not send you any unwanted email or give your email address away to anyone else. <a href="/makebeta/spyjax/">Sign Up For Spyjax</a></li>
<li>
<h5>Add URLs To Look For</h5>
<p> You can add custom URLs, the top 12 Google results for any search, or just look for the home page of the top 10,000 sites on the web.</li>
<li>
<h5>Put One Line Of Code At The Bottom Of Your Pages</h5>
<p> A simple &lt;script&gt; tag will insert all the JavaScript needed to spy on your visitors as well as communicate with the Spyjax service to record the results.</li>
<li>
<h5>Optionally Add A Spyjax Widget To Your Site</h5>
<p> If you just want to have some fun and show people that you&#8217;re spying on them you can put one of three Spyjax widgets on your website. There&#8217;s one on this site on the right sidebar.</li>
</ol>
<h3>Update: Spyjax Only Gives You Anonymous Data</h3>
<p>There have been some concerns raised since I first published this article and released Spyjax. So I just wanted to point out that the service does not link specific websites with identifiable user data. It simply tells you things like 36% of your visitors have been to http://www.google.com/. Basically all the data collected by Spyjax is anonymous and shown in aggregate form. Obviously this same technology could be used to track specific user&#8217;s history, especially if you&#8217;re on a site that records your identity in some way. In my humble opinion it&#8217;s much better to debate these issues in the open than to have this sort of technology floating around without people knowing about it.</p>
<h3>So You Just Want The Code?</h3>
<p>Well I&#8217;m not greedy, so I&#8217;m giving it away for free. You can do anything you want with it, just don&#8217;t blame me if it breaks or gets you in trouble.</p>
<p>You can download the code here: <a href="/makebeta/spyjax/spyjax_service.zip">Spyjax Code</a>. It&#8217;s got an open source <a href="/makebeta/spyjax/license.php">Attribution Assurance License</a> attached to it.</p>
<p>Check out these services by my company MerchantOS:</p>
<ul>
<li><a href="http://www.merchantos.com/">POS Software</a> - A point of sale and inventory control system for small retailers.</li>
<li><a href="http://www.merchantos.com/bike-shop-pos-software/">Bike Shop Point of Sale</a> - A full POS solution specifically designed for independent bicycle retailers.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/tools/spyjax/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WordPress Customization</title>
		<link>http://www.merchantos.com/makebeta/wordpress/wordpress-customization/</link>
		<comments>http://www.merchantos.com/makebeta/wordpress/wordpress-customization/#comments</comments>
		<pubDate>Thu, 10 May 2007 05:56:36 +0000</pubDate>
		<dc:creator>justin</dc:creator>
		
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.merchantos.com/makebeta/makebeta/wordpress/wordpress-customization/</guid>
		<description><![CDATA[A presentation on customizing WordPress. It gives an introduction to WordPress, and covers the basics of customizing themes.]]></description>
			<content:encoded><![CDATA[<h2>
  A. Introduction To WordPress<br />
</h2>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/home_page_default.png' title='Wordpress Default Theme'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/home_page_default.thumbnail.png' alt='Wordpress Default Theme' /></a><br />
<br />
<span style=FONT-WEIGHT:bold>Site: http://wordpress.org/</span></p>
<p>Description</p>
<p style=MARGIN-LEFT:40px>
  &#8220;WordPress is a state-of-the-art semantic personal publishing platform with a focus on aesthetics, web standards, and usability. What a mouthful. WordPress is both free and priceless at the same time. More simply, WordPress is what you use when you want to work with your blogging software, not fight it.&#8221;
</p>
<p>
<span style=FONT-WEIGHT:bold>Benefits</span></p>
<ul>
<li>
    Easy to use back end for writing content and making other dynamic changes to your site.
  </li>
<li>
    Simple setup, anyone with a little bit of server experience can install it.
  </li>
<li>
    Themes and Plugins are numerous and mostly free.
  </li>
<li>
    Easy to build your own theme or customize an existing one.
  </li>
<li>
    Uses standard/free web server technologies: PHP &amp; MySQL.
  </li>
</ul>
<p>
<span style=FONT-WEIGHT:bold>Using WordPress</span></p>
<ol>
<li>
    Login to the administration features by going to: http://&lt;your blogurl&gt;/wp-admin/
  </li>
<li>
    To write a post click on the &#8220;Write&#8221; tab. You can write in a visual editor or you can write straight HTML. I recommend learning HTML and editing pages in it, you&#8217;re posts will come out a lot better and be easier to modify later. Choose your editor under My Profile -&gt; &#8220;Use visual editor when writing&#8221;. If you have a normal sized monitor you may also want to turn up the number of lines you can see at once in the editor at: Options -&gt; Writing -&gt; &#8220;Size of the post box&#8221;, I recommend setting it to about 30 lines instead of 20.<br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/write_post_html.png' title='Write A Post In HTML'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/write_post_html.thumbnail.png' alt='Write A Post In HTML' /></a>
  </li>
<li>
    General options for your blog are under: Options -&gt; General.<br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/general_options.png' title='General WordPress Blog Options'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/general_options.thumbnail.png' alt='General WordPress Blog Options' /></a>
  </li>
<li>
    An important option is: Permalinks. These determine the directory structure of your blog. You probably want to change it from default to custom with structure of something like: &#8220;/%category%/%postname%/&#8221;. This will help your site rank in Google and other search engines. %category% will be the category you choose for your post. <span style=FONT-WEIGHT:bold>Warning: For SEO optimization give each post only one category. If you use multiple categories Google will find your post in multiple locations and may discard it as duplicate content.</span> Your %postname% comes from the &#8220;Post slug&#8221; field on the post writing screen. It will default to your post title but you can change it to anything you want, just make sure that it&#8217;s something that will be valid as a url (no spaces or weird characters). For example if we categorized our post as &#8220;Awesome&#8221; and made a slug of &#8220;this-is-the-most-awesome-slug&#8221; it would show up on our blog at /awesome/this-is-the-most-awesome-slug/ which would rank well in Google for phrases like &#8220;awesome slug&#8221;.
  </li>
<li>
    Your theme is chosen under Presentation -&gt; Theme<br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/choose_theme.png' title='Choose WordPress Theme'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/choose_theme.thumbnail.png' alt='Choose WordPress Theme' /></a>
  </li>
</ol>
<p></p>
<h2>
  B. WordPress Themes<br />
</h2>
<p>Almost everything about Wordpress can be customized through your theme. Themes are where WordPress really starts to shine. Here are a few example themes:<br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_bluedog.jpg' title='Bluedog Theme Screenshot'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_bluedog.thumbnail.jpg' alt='Bluedog Theme Screenshot' /></a><br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_ismart.jpg' title='ismart Theme Screenshot'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_ismart.thumbnail.jpg' alt='ismart Theme Screenshot' /></a><br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_newstart.jpg' title='Newstart Theme Screenshot'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/theme_newstart.thumbnail.jpg' alt='Newstart Theme Screenshot' /></a><br />
You can browse and download thousands of themes from:<br />
<a href=http://themes.wordpress.net/ title=http://themes.wordpress.net/>http://themes.wordpress.net/</a></p>
<p><span style=FONT-WEIGHT:bold>How do I install a new theme?</span><br />
Your themes are located in a subdirectory of your WordPress installation: &lt;your WordPress installation directory&gt;/wp-content/themes/. Each theme has it&#8217;s own directory, which is the name of theme. You&#8217;ll always start out with a<br />
theme called &#8220;default&#8221; which is the standard WordPress theme. To add a new theme download the zip file for the theme and unzip it into your /wp-content/themes/ directory. That&#8217;s it! You should now see the new theme under the Presentation -&gt; Theme tab in the administration back end.</p>
<h2>
  C. Structure Of A WordPress Theme<br />
</h2>
<p><span style=FONT-WEIGHT:bold>Theme Templates</span></p>
<p>There are a couple different types of pages in WordPress. Each type of page can have a customized look and feel. This customization is done by templates. Templates are how themes work. Each template is a seperate PHP file inside the theme&#8217;s directory. Here are the standard templates:</p>
<ul>
<li>
    404 Template = 404.php - It&#8217;s handy to create a custom 404 page (Page Not Found) template. You can list common links and ways for users to find what they are looking for.
  </li>
<li>
    Archive Template = archive.php
  </li>
<li>
    Archive Index Page = archives.php
  </li>
<li>
    Comments Template = comments.php - This template defines how comments look under individual posts on the &#8220;Post Template&#8221;.
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Footer Template = footer.php</span> - HTML that is placed at the bottom of each page, saves you time and produces less duplicate HTML code in your templates.
 </li>
<li>
    <span style=FONT-WEIGHT:bold> Header Template = header.php</span> - HTML that is placed at the top of each page, usually has the &lt;head&gt; section in it.
  </li>
<li>
    Links = links.php
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Main Template = index.php</span> - Usually this page lists your most recent posts. This is the &#8220;home&#8221; page of your site.
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Page Template = page.php</span> - Used for single pages, instead of blog posts. Your &#8220;About&#8221; page uses this template. This is the default page template, you can make your own custom page templates. I&#8217;ll cover this more in detail later.
  </li>
<li>
    Popup Comments Template = comments-popup.php
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Post Template = single.php</span> - This is where you customize pages that display single posts. Click on a post title (permalink) and you will be at it&#8217;s single post page using the post template.
  </li>
<li>
    Search Form = searchform.php
  </li>
<li>
    Search Template = search.php
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Sidebar Template = sidebar.php</span> - Usually the right hand side bar of the page. Some themes have more than one side bar so you&#8217;ll see templates like left_sidebar.php.
  </li>
<li>
    <span style=FONT-WEIGHT:bold> Stylesheet = style.css</span> - Default place to put your CSS. It also contains the name and description of the theme. You must always have this file with the name and description of your theme. Many themes will have multiple CSS files that are linked to from the header.php file or the individual page templates to customize individual pages with different style rules.
  </li>
</ul>
<p></p>
<h2>
  D. Making Your New Theme<br />
</h2>
<ol>
<li>
    Find a theme you want to base your new theme off of. A good place to start is the default theme, but you may also want to just tweak another theme that&#8217;s closer to the look/feel you are going for.
  </li>
<li>
    Copy the existing theme to a new directory in your themes directory for example if I was making a theme called &#8220;webdesign_meetup&#8221; I might copy the &#8220;default&#8221; directory into a new directory called &#8220;webdesign_meetup&#8221;.
  </li>
<li>
    In your new theme directory edit the <span style=FONT-WEIGHT:bold>style.css</span> file. You should see something<br />
    like this in that file:<br />
   /*<br />
Theme Name: WordPress Default<br />
Theme URI: http://wordpress.org/<br />
Description: The default WordPress theme based on the famous <a href=â€http://binarybonsai.com/kubrick/â€>Kubrick</a>.<br />
Version: 1.6<br />
Author: Michael Heilemann<br />
Author URI: http://binarybonsai.com/<br />
*/
  </li>
<li>
    Edit the theme information. This is the information that will show up under Presentation -&gt; Theme in the administrator.
  </li>
<li>
    Go into the WordPress administrator and change your current them to the new one you just created.
  </li>
<li>
    Now you can start customizing and see the affects in real time on your site!
  </li>
</ol>
<h2>
  E. Modifying The Header<br />
</h2>
<p>
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/header_example.png' title='Wordpress Header Example'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/header_example.thumbnail.png' alt='Wordpress Header Example' /></a><br />
<br />
The first thing you might want to do when customizing your theme is change the header. Most sites have a custom header image, usually a company logo or a picture that has to do with the theme of your site. To edit the header just go into your theme directory and edit the <span style=FONT-WEIGHT:bold>header.php</span> file. The header HTML will usually be stored in this file. In some more rare cases theme authors may have placed header information in the individual page templates (if they did you&#8217;ll have to hunt around a bit more!). You&#8217;ll usually see a piece of HTML under the opening &lt;body&gt; tag that&#8217;s something like lt;div id=&#8221;header&#8221;&gt;&#8230;header content&#8230;&lt;/div&gt;. You can customize this content with your new header.</p>
<h2>
  F. Blog / Post Templates<br />
</h2>
<p>
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/single_post_example.png' title='Single Post Example'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/single_post_example.thumbnail.png' alt='Single Post Example' /></a><br />
<br />
Maybe you want to display an ad at the bottom of each post, or perhaps you&#8217;d like to add or remove the author information under the post header? The place to do these things is in the single.php file. This file controls the layout of your individual post pages.<br />
<br />
Let&#8217;s examine the components of this file for the default WordPress theme:</p>
<p><span style=FONT-WEIGHT:bold>&lt;?php get_header();<br />
?&gt;</span><br style=FONT-WEIGHT:bold><br />
</p>
<div style=MARGIN-LEFT:40px>
  This just calls your header.php template. It&#8217;s nice to use your header.php file to display all the common header HTML code for all your pages. That way you can avoid writing the same &lt;head&gt;&#8230;&lt;/head&gt; and beginning &lt;body&gt;&#8230; content over and over.
</div>
<p></p>
<p><span style=FONT-WEIGHT:bold>&lt;div id=&#8221;content&#8221;<br />
class=&#8221;widecolumn&#8221;&gt;</span><br style=FONT-WEIGHT:bold><br />
<br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php<br />
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;</p>
<p></span></p>
<div style=MARGIN-LEFT:40px>
  Here is where we start &#8220;The Loop&#8221;. In WordPress each page normally has a &#8220;loop&#8221; on it that cycles through the content that should be displayed on that page. In our single.php template there would normally just be one &#8220;post&#8221;, which means the loop would just execute once to display that one post. The <span style=FONT-WEIGHT:bold>if (have_posts()) </span>code first checks to see if we have a post to display, then the <span style=FONT-WEIGHT:bold>while (have_posts()) </span>loops through each of the posts, <span style=FONT-WEIGHT:bold>the_post(); </span>simply prepares the post for display. Most pages will have this same loop code on them. WordPress takes care of deciding what posts should go on which pages in most instances. Occasionally you&#8217;ll want to customize what posts are displayed within the loop, but we&#8217;ll cover that in a second.
</div>
<p><span style=FONT-WEIGHT:bold><br />
&lt;div class=&#8221;navigation&#8221;&gt;</span><br style=FONT-WEIGHT:bold></p>
<p><span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;div<br />
class=&#8221;alignleft&#8221;&gt;&lt;?php previous_post_link(&#8217;&amp;laquo; %link&#8217;)<br />
?&gt;&lt;/div&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;div<br />
class=&#8221;alignright&#8221;&gt;&lt;?php next_post_link(&#8217;%link &amp;raquo;&#8217;)<br />
?&gt;&lt;/div&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&lt;/div&gt;</p>
<p></span></p>
<div style=MARGIN-LEFT:40px>
  Here the template is laying out some basic navigation that allows the user to move between blog posts. The previous_post_link() function places a &lt;a href=&#8221;..&#8221;&gt; tag that if clicked will navigate the user to the previous post in the blog. The next_post_link() is very similar.
</div>
<p></p>
<p><span style=FONT-WEIGHT:bold>&lt;div<br />
class=&#8221;entry&#8221;&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;?php the_content(&#8217;&lt;p<br />
class=&#8221;serif&#8221;&gt;Read the rest of this entry &amp;raquo;&lt;/p&gt;&#8217;);<br />
?&gt;</span><br style=FONT-WEIGHT:bold></p>
<p></p>
<div style=MARGIN-LEFT:40px>
  This code displays the actual post content (the content that you created under the &#8220;Writing&#8221; tab in the admin interface). The <span style=FONT-WEIGHT:bold>the_content(); </span>function displays the HTML for the current &#8220;post&#8221; within &#8220;The Loop&#8221;. The argument within the function &#8220;&#8230;Read the rest of this entry&#8230;&#8221; is text that will be displayed in a &lt;a href&gt;&lt;/a&gt; tag at the end of the content if the content spans more than one page.
</div>
<p></p>
<p><span style=FONT-WEIGHT:bold>So how do I add some author information and maybe date of the post to this?<br />
</span>It&#8217;s easy! There&#8217;s a lot of information stored with each post that is accessible within &#8220;The Loop&#8221;. To see a list of all the functions you can use to get at this information visit this documentation page: <a href=http://codex.wordpress.org/Template_Tags title=http://codex.wordpress.org/Template_Tags>http://codex.wordpress.org/Template_Tags</a>. There you&#8217;ll see all the template functions that are available to you. So to get the author of the post we&#8217;d just call the_author();. Of course we&#8217;d want to put some HTML formating around it so we might do:</p>
<div>
  <br />
  <span style=FONT-WEIGHT:bold>&lt;p&gt;This post was written by &lt;?php<br />
  the_author();&nbsp;?&gt;&lt;/p&gt;</span>
</div>
<p>
Now to put the date the post was written we could put:<br />
<span style=FONT-FAMILY:monospace><br />
</span><span style=FONT-WEIGHT:bold>&lt;?php the_date(&#8217;Y-m-d&#8217;,<br />
&#8216;&lt;h2&gt;Published On &#8216;, &#8216;&lt;/h2&gt;&#8217;);&nbsp;?&gt;</span></p>
<p><span style=FONT-WEIGHT:bold> </span><br />
There are tons of stuff you can do with posts so check out: <a href=http://codex.wordpress.org/Template_Tags title=http://codex.wordpress.org/Template_Tags>http://codex.wordpress.org/Template_Tags</a> and get started.</p>
<h2>
  G. The Post Loop<br />
</h2>
<p>So you want a custom loop? The loop is powered off of the current page query. The query is generated by WordPress, typically from your URL. So if your on your site and your at /category1/a-blog-post-with-id-12 the query to get blog post id 12 in category 1. The internal mechanics of how this happens are fairly complex, so we won&#8217;t go into them. It&#8217;s enough to know that each page has a query generated for it that will grab the correct content for that page. So if you want to customize your loop and grab something besides what WordPress would do by default you need to modify the query before you call your loop.</p>
<p>Let&#8217;s say you want to put just the 3 most recent blog posts on a page, maybe under some other content. On my site the home page has static content and then displays some recent blog posts. Here&#8217;s how you do it:</p>
<p><span style=FONT-WEIGHT:bold>&lt;?php query_posts(&#8221;showposts=3&#8243;);<br />
?&gt;</span></p>
<p>This does a new query to grab the 3 most recent posts to the blog. I can then display these posts in a normal loop:</p>
<p><span style=FONT-WEIGHT:bold>&lt;?php if (have_posts()) {<br />
?&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;h3&gt;Recent<br />
News&lt;/h3&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;?php while (have_posts()) :<br />
the_post(); ?&gt;</span><br style=FONT-WEIGHT:bold></p>
<p><span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div<br />
class=&#8221;blog_post&#8221;&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp; &lt;?php the_content();<br />
?&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />
&lt;/div&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&nbsp;&nbsp;&nbsp; &lt;?php endwhile;<br />
?&gt;</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>&lt;?php } ?&gt;</p>
<p></span><br />
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/loop_example_3_posts.png' title='Loop Example 3 Posts'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/loop_example_3_posts.thumbnail.png' alt='Loop Example 3 Posts' /></a></p>
<p>There are almost infinite ways you can write queries to get the posts you want for your loop. Visit these two pages for more information:<br /> <br />
<a href=http://codex.wordpress.org/The_Loop title=http://codex.wordpress.org/The_Loop>http://codex.wordpress.org/The_Loop</a><br />
<a href=http://codex.wordpress.org/Function_Reference/WP_Query%20 title=http://codex.wordpress.org/Function_Reference/WP_Query>http://codex.wordpress.org/Function_Reference/WP_Query</a></p>
<h2>
  H. Page Templates</p>
</h2>
<p>Page templates are used to format specific pages. For example if you want your About page to have a specific template you can assign it a page template. Posts can not have templates, only pages (under Write -&gt; Write Page). To start a new page create a new php file, for example we could call our new file about_us.php. In the file put this code at the top:<br />
<span style=FONT-WEIGHT:bold>&lt;?php</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>/*</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>Template Name: About<br />
Us</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>*/</span><br style=FONT-WEIGHT:bold><br />
<span style=FONT-WEIGHT:bold>?&gt;</span><br />
WordPress will see this file as a page template and will display it in the list of page templates you choose from when you are editing a page. To create a page in the admin interface go to Write -&gt; Write Page. Then on the right side bar you can pick a custom page template. Pick your new &#8220;About Us&#8221; template.</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/choose_page_template.png' title='Choose Page Template'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/choose_page_template.png' alt='Choose Page Template' /></a></p>
<p>You probably want a number of standard template elements on your custom page template. Here&#8217;s a good framework to start you template with:</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/page_template_code.gif' title='Page Template Code'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/05/page_template_code.gif' alt='Page Template Code' /></a><br />
</p>
<p>The loop on your page template will by default grab the content your write for your page in the admin interface.</p>
<h2>
  I. Sidebars<br />
</h2>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/sidebars.png' title='Wordpress Sidebar Example'><img class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/sidebars.png' alt='Wordpress Sidebar Example' /></a></p>
<p>
  
</p>
<p>
  Most templates have one or sidebars. Sidebars usually contain navigational links, but they can also include search boxes, lists of related pages, and other widgets (like mybloglog etc.). It&#8217;s really easy to edit your sidebars. Just find the sidebar.php file and open it your editor. You&#8217;ll see the HTML that creates the side bar and puts the content within it. There are a few template functions that are helpful within the sidebar like <span style=FONT-WEIGHT:bold>wp_get_archives(); </span>which will display a list of time periods that you wrote blog posts (think August (8), September (2) which are links to those months posts). Most sidebar functions are meant to be placed within &lt;ul&gt;&lt;/ul&gt; tags because they format their output as lists. So in your side bar you might have this code:
</p>
<p>
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/sidebar_code.gif' title='Sidebar Code'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/05/sidebar_code.gif' alt='Sidebar Code' /></a><br />
</p>
<p>
  This code would generate two lists, one of archive months, and one of categories you have posted under.
</p>
<p>
  You can find more of these functions at:<br />
  <a href=http://codex.wordpress.org/Template_Tags title=http://codex.wordpress.org/Template_Tags>http://codex.wordpress.org/Template_Tags</a>
</p>
<h2>
  J. Meta Data / Custom Fields For Page Customization</p>
</h2>
<p>
<a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/edit_meta_data.png' title='Edit Meta Data'><img  class="nofloat" src='/makebeta/wp-content/uploads/101/makebeta/2007/05/edit_meta_data.png' alt='Edit Meta Data' /></a><br />
<br />
Meta data can be added to any blog post or page. It&#8217;s located under the edit box on the Write Post and Write Page sections of the admin interface. Look for the section called &#8220;Custom Fields&#8221;, that&#8217;s your post meta data. Each piece of meta data has a key and a value. You can use meta data to store almost anything, and you can retrieve it within the page using some template functions/tags. Here some code I use so that each page can have a custom title, description, keywords, and style rules. This code is placed within my &lt;head&gt;&lt;/head&gt; tags in my header.php file:</p>
<p><a href='/makebeta/wp-content/uploads/101/makebeta/2007/05/meta_customization_code.gif' title='Meta Customization Code'><img src='/makebeta/wp-content/uploads/101/makebeta/2007/05/meta_customization_code.gif' alt='Meta Customization Code' /></a></p>
<p>
The first section of the code loads the meta data. For example to get the title meta data I call <span style=FONT-WEIGHT:bold> $title = get_post_meta($wp_query-&gt;post-&gt;ID, &#8220;title&#8221;, true);</span>. I can then use the $title variable within my code to display the title information I retrieved. The <span style=FONT-WEIGHT:bold>styles </span>meta data I retrieve is a little<br />
more complex because it is grabbing an array of styles. So if there are more than one meta data elements with the title &#8220;style&#8221; I will get all these styles within one array. The last parameter of get_post_meta determines if an array is to be returned or just single value. I loop through the array and display each style using this code: <span style=FONT-WEIGHT:bold>&lt;?php foreach ($styles as $s) echo $s . &#8220;\n&#8221;; ?&gt;</span>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.merchantos.com/makebeta/wordpress/wordpress-customization/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
