<?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>Adrian Callaghan`s Blog &#187; Programming</title>
	<atom:link href="http://adriancallaghan.co.uk/Categorys/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://adriancallaghan.co.uk</link>
	<description>A general mix of everything</description>
	<lastBuildDate>Tue, 10 Jan 2012 12:05:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>javascript image rotation</title>
		<link>http://adriancallaghan.co.uk/javascript-image-rotation/</link>
		<comments>http://adriancallaghan.co.uk/javascript-image-rotation/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 17:50:39 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=653</guid>
		<description><![CDATA[Very simple class that rotates images on any event, on any target element (with a preloader). Click here for an example. To use it yourself (how the example works): 1. include jquery and the class &#60;script type=&#34;text/javascript&#34; src=&#34;jquery.js&#34;&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34; src=&#34;galleryRotate.js&#34;&#62;&#60;/script&#62; 2. Instantiate the class with an array of images $images = &#91;'1.jpg','2.jpg','3.jpg'&#93;; var rotator [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fjavascript-image-rotation%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Very simple class that rotates images on any event, on any target element (with a preloader).</p>
<p>Click <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=653&Ck_lnk=http://adriancallaghan.co.uk/demos/rotation/" target="_BLANK">here</a> for an example.</p>
<p>To use it yourself (how the example works):</p>
<p>1. include jquery and the class</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;galleryRotate.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>2. Instantiate the class with an array of images</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$images <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'1.jpg'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'2.jpg'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'3.jpg'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> rotator <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GalleryRotate<span style="color: #009900;">&#40;</span>$images<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>3. bind the objects change method to an event, such as mouseclick, telling it the name of target element (always done once the webpage is ready)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// click the image</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> rotator.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once again an example can be found <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=653&Ck_lnk=http://adriancallaghan.co.uk/demos/rotation/" target="_BLANK">here</a>.</p>
<p>The full source code can be downloaded <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=653&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/rotation.zip" target="_BLANK">here</a>.</p>
<p>The class code is very straight forward and below for completeness.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> GalleryRotate <span style="color: #009900;">&#40;</span>$images<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">preload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">images</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img/&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">change</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		$img <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">images</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgNo</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$element<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>$element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;src&quot;</span><span style="color: #339933;">,</span> $img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$img<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgNo</span><span style="color: #339933;">++;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgNo</span><span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">images</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgNo</span><span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>$images<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">images</span> <span style="color: #339933;">=</span> $images<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgNo</span><span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">preload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span>$images<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fjavascript-image-rotation%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/javascript-image-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>adding password authentication for a zend cms or controller</title>
		<link>http://adriancallaghan.co.uk/adding-password-authentication-for-a-zend-cms-or-controller/</link>
		<comments>http://adriancallaghan.co.uk/adding-password-authentication-for-a-zend-cms-or-controller/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 12:00:33 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[applications]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=631</guid>
		<description><![CDATA[This is a very quick way to add password protection to a controller such as a cms controller. This code intercepts the login within the init() method of your chosen controller, if they are logged in they are free to go, if not they are required to login, the form is rendered and validated against [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fadding-password-authentication-for-a-zend-cms-or-controller%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>This is a very quick way to add password protection to a controller such as a cms controller.</p>
<p>This code intercepts the login within the init() method of your chosen controller, if they are logged in they are free to go, if not they are required to login, the form is rendered and validated against the access model.</p>
<p>The session is obfuscated to deter tampering.</p>
<p>so firstly in your controller init() add</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$adminSession</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Session_Namespace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Application_Model_accessControl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// access control</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// logged in user</span>
<span style="color: #000088;">$loginMsg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Please login'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$loginForm</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #339933;">;</span>
<span style="color: #000088;">$loginForm</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttrib</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'required'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'pass'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'required'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$loginForm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validateUser</span><span style="color: #009900;">&#40;</span>
		<span style="color: #000088;">$loginForm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
		<span style="color: #000088;">$loginForm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInSession</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$session</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInUser</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$loginForm</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$loginMsg</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Access denied'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 			
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sessionIsValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInSession</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInUser</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">header</span><span style="color: #339933;">=</span><span style="color: #000088;">$loginMsg</span><span style="color: #339933;">;</span>			
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$loginForm</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// renew session, will always be the &quot;Now&quot; session, but three are provided, see the model </span>
	<span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInSession</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userIdent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$adminSession</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loggedInUser</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>$this->view->userIdent will always contain the logged in user</p>
<p>The next step is to create the model for authentication in models/accessControl.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Application_Model_accessControl
<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// set users, password is the key, because this is less likely to be duplicated</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsers</span><span style="color: #009900;">&#40;</span>
        	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'password1'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'admin'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'password2'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'admin'</span>
				<span style="color: #009900;">&#41;</span>
       		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// salt for session key</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSalt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySaltGoesHere1234'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> validateUser<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * return session if correct, null otherwise
		 */</span>
&nbsp;
		<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUsers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sessionIsValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span><span style="color: #000088;">$debug</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$validSessions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSessions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$debug</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;MY KEY: <span style="color: #006699; font-weight: bold;">$session</span>&lt;br &gt;KEYS: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validSessions</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$session</span><span style="color: #339933;">,</span> <span style="color: #000088;">$validSessions</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getValidSessions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$sessions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSession</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'past'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSession</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'now'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidSession</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'future'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sessions</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getValidSession<span style="color: #009900;">&#40;</span><span style="color: #000088;">$for</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'now'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Three sessions are provided,
		 * 
		 * past, now and present
		 * 
		 * past, person logs in at 11:59 spends ten minutes editing, clicks save at 12:09, past would be the valid session
		 * now, person is logged in during 11:00 - 11:59
		 * future, is provided encase of time travel, or if the british summer time kicks in while editing, unlikely but more is better than not enough...
		 */</span>
&nbsp;
		<span style="color: #000088;">$hour</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'H'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$for</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'past'</span> <span style="color: #339933;">:</span> 
				<span style="color: #000088;">$validSession</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hour</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> ? <span style="color: #cc66cc;">23</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$hour</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'now'</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$validSession</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hour</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'future'</span> <span style="color: #339933;">:</span> 
				<span style="color: #000088;">$validSession</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$hour</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">23</span> ? <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$hour</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * obsfucation
		 */</span>
		<span style="color: #666666; font-style: italic;">// firstly grab specific details to stop session hijacking </span>
		<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$browser</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// then mix it up and md5 it</span>
		<span style="color: #000088;">$validSession</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">.</span><span style="color: #000088;">$validSession</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSalt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$browser</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$validSession</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validSession</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$validSession</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUsers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$users</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUsers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">users</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setSalt<span style="color: #009900;">&#40;</span><span style="color: #000088;">$salt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">salt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$salt</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getSalt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">salt</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and finally create a view login.phtml (this is just bare bones)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;<span style="color: #006699; font-weight: bold;">{$this-&gt;header}</span>&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Thats it!
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fadding-password-authentication-for-a-zend-cms-or-controller%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/adding-password-authentication-for-a-zend-cms-or-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>session_start hangs when it used to work</title>
		<link>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/</link>
		<comments>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 09:48:35 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=626</guid>
		<description><![CDATA[I had a problem with my zend application hanging with a white screen for no reason. I narrowed it down to when 1 $adminSession = new Zend_Session_Namespace&#40;'Admin'&#41;; was executed, this is just a session? so debugging further, confirmed that session_start() hangs when it used to work. There are lots of explanations for this, but before [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsession_start-hangs-when-it-used-to-work%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>I had a problem with my zend application hanging with a white screen for no reason.<br />
I narrowed it down to when</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$adminSession</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Session_Namespace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>was executed, this is just a session? so debugging further, confirmed that session_start() hangs when it used to work.</p>
<p>There are lots of explanations for this, but before you start modifying ini settings, just try this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">session_write_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I found this resolved the problem completely.<br />
I then just removed this debug-code and went back to developing my zend app.</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsession_start-hangs-when-it-used-to-work%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/session_start-hangs-when-it-used-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ckeditor to upload images</title>
		<link>http://adriancallaghan.co.uk/ckeditor-to-upload-images/</link>
		<comments>http://adriancallaghan.co.uk/ckeditor-to-upload-images/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 17:24:32 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=619</guid>
		<description><![CDATA[A few posts on how to do this, and a lot of frustrated people so here is how: Download both ckeditor and ckfinder. Decompress them into the root directory. Include them in your php include_once &#8216;ckeditor/ckeditor.php&#8217;; include_once &#8216;ckfinder/ckfinder.php&#8217;; hopefully no error messages? ok cool&#8230;. now simply 1 2 3 4 5 6 7 8 9 [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fckeditor-to-upload-images%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>A few posts on how to do this, and a lot of frustrated people so here is how:</p>
<p>Download both <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=619&Ck_lnk=http://ckeditor.com/download">ckeditor</a> and <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=619&Ck_lnk=http://ckfinder.com/download">ckfinder</a>.</p>
<p>Decompress them into the root directory.</p>
<p>Include them in your php</p>
<p>include_once &#8216;ckeditor/ckeditor.php&#8217;;<br />
include_once &#8216;ckfinder/ckfinder.php&#8217;;</p>
<p>hopefully no error messages? ok cool&#8230;. now simply</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$ckeditor</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CKEditor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">basePath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckeditor/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserBrowseUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/ckfinder.html'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserImageBrowseUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/ckfinder.html?type=Images'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserFlashBrowseUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/ckfinder.html?type=Flash'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserUploadUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/core/connector/php/connector.php?command=QuickUpload&amp;type=Files'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserImageUploadUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/core/connector/php/connector.php?command=QuickUpload&amp;type=Images'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filebrowserFlashUploadUrl'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/ckfinder/core/connector/php/connector.php?command=QuickUpload&amp;type=Flash'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ckeditor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">editor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CKEditor1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>To add the field to the form.</p>
<p>Ensure that in ckfinder/userfiles is writable</p>
<p>You also need to alter in ckfinder/userfiles/config.php the function CheckAuthentication(), to return true, take note of the warning!!</p>
<p>ive put it all together in one zip file displaying the submission <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=619&Ck_lnk=/wp-content/downloads/ckeditor.zip">here</a></p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fckeditor-to-upload-images%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/ckeditor-to-upload-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>database class php</title>
		<link>http://adriancallaghan.co.uk/database-class-php/</link>
		<comments>http://adriancallaghan.co.uk/database-class-php/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 17:05:05 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=615</guid>
		<description><![CDATA[Updated the database class Usage: 1 2 3 4 5 6 &#160; // min instantiation $dataBase = new DB&#40;'hostname','username','password','database'&#41;; &#160; // max instantiation $dataBase = new DB&#40;'hostname','username','password','database',DEBUG_LEVEL,array&#40;'admin@domain.com','admin@domain2.com)); Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fdatabase-class-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Updated the database class </p>
<p>Usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// min instantiation</span>
<span style="color: #000088;">$dataBase</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hostname'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// max instantiation</span>
<span style="color: #000088;">$dataBase</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'hostname'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #339933;">,</span>DEBUG_LEVEL<span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin@domain.com'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'admin@domain2.com));</span></pre></td></tr></table></div>

<p>Class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DB<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* 
	 * DESCRIPTION:		Object class, Handles all database requests and returns content accordingly
	 * WRITER:			Adrian Callaghan 12,08,08      
	 * UPDATED: 		Adrian Callaghan 08,08,11
	 * 
	 * 
	 * errLvl 
	 * 		(0), none, 
	 * 		(1) show a user error, 
	 * 		(2) (1) + mysql error
	 * 		(3) (2) + show a full error (mysql errors), 
	 * 		(4) (3) + plus debugging 
	*/</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mySqlHost</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dataBase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$emailAddresses</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$adminEmails</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Sets up a new connection
		 */</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// MIN required</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setHost</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPwd</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pwd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setErrLvl</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// sets defualt RTE</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEmailErrsTo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adminEmails</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// connect</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDb</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
 	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 		<span style="color: #666666; font-style: italic;">/*
 		 * Close the connection
 		 */</span>
 		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setHost<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the hostname
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">host</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$host</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
 	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setUsr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$usr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the username
		 */</span>
 		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usr</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setPwd<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pwd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the password
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pwd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pwd</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> setErrLvl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errLvl</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Sets the error reporting level
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$errLvl</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Connect to server
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pwd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot connect to server'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * closes current connection
		 */</span> 
		<span style="color: #339933;">@</span><span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setDb<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * Set the database
		 */</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBase</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mySqlHost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dataBase</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Cannot select database'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setEmailErrsTo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// ensure it is an array</span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// if empty return</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// assign the email addresses</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> getQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// executes a query</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// create a 2D array of results</span>
		<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$return</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> setQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// executes a query without returning any results, used for insert, create etc, returns the ID of the last auto-increment</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query'</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$SQL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$SQL</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Handles errors
		 * 
		 */</span>
&nbsp;
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>	<span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kill the mysql output</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>	<span style="color: #000088;">$SQL</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kill the sql output</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span> 
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">:</span> 
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1 style='color:#444444;'&gt;<span style="color: #006699; font-weight: bold;">$message</span>&lt;/h1&gt;&lt;hr&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">!==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;span style='color:#ff0000; font-weight:bold;'&gt;Mysql: &lt;/span&gt;<span style="color: #006699; font-weight: bold;">$mysqlErr</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">!==</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;span style='color:#ff0000; font-weight:bold;'&gt;Whole query: &lt;/span&gt;<span style="color: #006699; font-weight: bold;">$SQL</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>			
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
 		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateEmail</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Mysql'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$mysqlErr</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Sql'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Err Level'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 		<span style="color: #666666; font-style: italic;">// three is for debugging</span>
 		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errLvl</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$sent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendEmails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sent</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;The administrator has been notified&lt;/h2&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h2&gt;Please notify the administrator'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;'s &quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' or '</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> generateEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$err</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'Server name'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'Query'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'Ip'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_PORT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'@'</span><span style="color: #339933;">=&gt;</span>date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D dS M,Y h:i a&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
		<span style="color: #000088;">$rtn</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;table bgcolor=&quot;#cccccc&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span> <span style="color: #000088;">$err</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$title</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$rtn</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td bgcolor='#aaaaaa'&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/td&gt;&lt;td bgcolor='#bbbbbb'&gt;<span style="color: #006699; font-weight: bold;">$value</span>&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$rtn</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sendEmails<span style="color: #009900;">&#40;</span><span style="color: #000088;">$reciptents</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// email message</span>
		<span style="color: #000088;">$Name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//senders name </span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;noreply@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//senders e-mail adress </span>
&nbsp;
		<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; Error&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//subject </span>
&nbsp;
		<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-type: text/html; charset=iso-8859-1'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>		
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;From: &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$Name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; &lt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #000088;">$success</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">emailAddresses</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$admin_email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sent</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$admin_email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mail_body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sent</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$success</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// holds state for any email being succesfully sent</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$success</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fdatabase-class-php%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/database-class-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>compile your own lamp stack with mysqli</title>
		<link>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/</link>
		<comments>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 10:44:21 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=596</guid>
		<description><![CDATA[Install LAMP with one line One liner sudo apt-get install lamp-server^ Add CURL and enable mod-rewrite sudo apt-get install php5-curl sudo a2enmod rewrite To compile LAMP with mysqli and mysql Assuming you have a fresh clean minimal install of ubuntu start by install gcc and wget sudo apt-get gcc sudo apt-get wget Download apache and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fcompile-your-own-lamp-stack-with-mysqli%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<h2>Install LAMP with one line</h2>
<p>One liner</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> lamp-server^</pre></div></div>

<p>Add CURL and enable mod-rewrite</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-curl
<span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod rewrite</pre></div></div>

<h2>To compile LAMP with mysqli and mysql</h2>
<p>Assuming you have a fresh clean minimal install of ubuntu start by install gcc and wget</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">wget</span></pre></div></div>

<p>Download <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=596&Ck_lnk=http://httpd.apache.org/">apache</a> and <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=596&Ck_lnk=http://www.php.net/downloads.php">php</a> and use filezilla or a similar SFTP client to upload them to the server (I was unable to find a direct link that didnt pass through a mirror), once uploaded move to the directory on the cmd line.</p>
<p>unpack apache</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-d</span> httpd-<span style="color: #000000;">2</span>_x_NN.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xf</span> httpd-<span style="color: #000000;">2</span>_x_NN.tar</pre></td></tr></table></div>

<p>unpack PHP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-d</span> php-NN.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xf</span> php-NN.tar</pre></td></tr></table></div>

<p>Compile and install Apache</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> httpd-<span style="color: #000000;">2</span>_x_NN
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-so</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Compile PHP</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>php-NN
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd</pre></td></tr></table></div>

<p>This will fail with an error &#8220;error locating libxml2&#8243; fix this with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libxml2</pre></div></div>

<p>Next the error below will appear</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xml2 config not found Please check your libxml2 installation</pre></div></div>

<p>Point your browser or ftp client at ftp://xmlsoft.org/libxml2/ and take note of the latest version for libxml2-2.6.28 and then grab it and install it from the server</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>xmlsoft.org<span style="color: #000000; font-weight: bold;">/</span>libxml2<span style="color: #000000; font-weight: bold;">/</span>libxml2-<span style="color: #000000;">2</span>.X.XX.tar.gz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> libxml2-<span style="color: #000000;">2</span>.X.XX.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> libxml2-<span style="color: #000000;">2</span>.X.XX<span style="color: #000000; font-weight: bold;">/</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Try to compile PHP again:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd</pre></td></tr></table></div>

<p>next problem is Mysql</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">configure: error: Cannot <span style="color: #c20cb9; font-weight: bold;">find</span> MySQL header files under <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config</pre></div></div>

<p>To fix this, Install mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server</pre></div></div>

<p>But now even though Mysql is found there are still no headers so first install php module for mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-mysql</pre></div></div>

<p>and add the header library</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libmysqlclient15-dev</pre></div></div>

<p>Now PHP should compile and install fine:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-aspxs2</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apxs <span style="color: #660033;">--with-mysql</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config  <span style="color: #660033;">--with-mysqli</span>=mysqlnd <span style="color: #660033;">--with-pdo-mysql</span>=mysqlnd
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>Set up an ini file for PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> php.ini-development <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>tell apache to load the module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadModule php5_module modules<span style="color: #000000; font-weight: bold;">/</span>libphp5.so</pre></div></div>

<p>You need to re/start apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>apachectl start</pre></div></div>

<p> personally I like to restart the entire server with changes this big</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">shutdown now <span style="color: #660033;">-r</span></pre></div></div>

<p>Thats it!</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fcompile-your-own-lamp-stack-with-mysqli%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/compile-your-own-lamp-stack-with-mysqli/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>simple mvc</title>
		<link>http://adriancallaghan.co.uk/simple-mvc/</link>
		<comments>http://adriancallaghan.co.uk/simple-mvc/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 13:18:47 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=579</guid>
		<description><![CDATA[Need a lightweight, fast, php mvc framework? I have written a small framework named &#8220;Simple MVC&#8221; it does exactly what it says on the box, its quick to install and can be configured to handle most tasks. Once the file is unzipped you will be presented with this structure: Simply upload the whole structure, and [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsimple-mvc%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Need a lightweight, fast, php mvc framework?</p>
<p>I have written a small framework named &#8220;<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">Simple MVC</a>&#8221; it does exactly what it says on the box, its quick to install and can be configured to handle most tasks.</p>
<p>Once the file is unzipped you will be presented with this structure:<br />
<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/uploads/2010/08/layout.jpg"><img src="http://adriancallaghan.co.uk/wp-content/uploads/2010/08/layout.jpg" alt="" title="layout" width="211" height="129" class="alignnone size-full wp-image-580" /></a></p>
<p>Simply upload the whole structure, and the framework will work.</p>
<p>It is designed to be very fast and lightweight, however it can be configured, opening the file mvc_env.php within the &#8220;<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">Simple MVC</a>&#8221; folder displays the following preferences:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">/*
 * 
 * Simple MVC settings file (this file does not need to be present)
 * Examples of different settings are contained here, just uncomment to use
 * 
 * By Adrian Callaghan 300810
 * 
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// error controller</span>
<span style="color: #666666; font-style: italic;">// defines a controller to handle errors, namely the page not found</span>
<span style="color: #666666; font-style: italic;">// the controller is automatically exempt from an actual page request</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;error['controller']='error';
$env-&gt;error['view']='index';
$env-&gt;error['pageNotFoundAction']='pageNotFound';
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// routerMap</span>
<span style="color: #666666; font-style: italic;">// holds controller and action mappings to different controller, action (comma delimited)</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;routerMap['foo,bar']='index,index';
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// routerDeny</span>
<span style="color: #666666; font-style: italic;">// holds controller and action mappings to deny (comma delimited)</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;routerDeny[]='controller,action'; // will deny the page /controller/action/
$env-&gt;routerDeny[]=''; // will deny homepage
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// prelayout</span>
<span style="color: #666666; font-style: italic;">// defines an array of elements to be included before the main view</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;prelayout = array('header');
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// postlayout</span>
<span style="color: #666666; font-style: italic;">// defines an array of elements to be included after the main view</span>
<span style="color: #666666; font-style: italic;">/*
$env-&gt;postlayout = array('sidebar','footer');
*/</span></pre></td></tr></table></div>

<p>As you can see, page routing, error controllers, page denials etc can all be added here.</p>
<p>The whole framework is just one file and the source looks like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * 
 * Simple MVC 
 * 
 * By Adrian Callaghan 300810
 * 
 */</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// enviroment</span>
<span style="color: #000088;">$env</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// url mapping</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'relative'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'//'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../application/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'__url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// mvc</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// settings</span>
<span style="color: #339933;">@</span><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mvc_env.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tell the controllers where to load models from</span>
<span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$env</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>models/<span style="color: #006699; font-weight: bold;">$class_name</span>.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// add custom error controller to list of denys</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// mapping</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>,<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerMap</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>,<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the controller</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// unset the controller if this is a denied resource, this is done on URL only, so not to interfere with any mappings</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request_array'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">routerDeny</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">// if neither the controller or action was found set an error for the error controller to handle</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// can we run the error handler?</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controller'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pageNotFoundAction'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #339933;">@</span><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/controllers/<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$controller</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h1&gt;Fatal error&lt;/h1&gt;Missing action: &lt;b&gt;<span style="color: #006699; font-weight: bold;">{$env-&gt;action}</span>&lt;/b&gt; in controller: &lt;b&gt;<span style="color: #006699; font-weight: bold;">{$env-&gt;controller}</span>&lt;/b&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// output will be handled by the dispatcher below	</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// if we do not even have an error handler, throw a traditional 404 and die</span>
		<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;
		&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body&gt;
		&lt;h1&gt;Not Found&lt;/h1&gt;
		&lt;p&gt;The requested URL <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'request'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> was not found on this server.&lt;/p&gt;
		&lt;/body&gt;&lt;/html&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// dispatcher /////////////////////////////////////////////////</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//attempt to execute the action in the controller,</span>
<span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">// check to see if the view has been altered</span>
<span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set up the content and view</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">content</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prelayout</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prelayout</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">$element</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">{$env-&gt;view}</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postlayout</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$env</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postlayout</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$env-&gt;url['relative']}</span>/views/<span style="color: #006699; font-weight: bold;">$element</span>.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>A helloworld quickstart can be downloaded from <a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=579&Ck_lnk=http://adriancallaghan.co.uk/wp-content/downloads/simple_mvc.zip">here</a></p>
<p>The helloworld also has examples of where to instaniate the models, and how to redirect the view in the comments.
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsimple-mvc%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/simple-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sort a array by its value</title>
		<link>http://adriancallaghan.co.uk/sort-a-array-by-its-value/</link>
		<comments>http://adriancallaghan.co.uk/sort-a-array-by-its-value/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 12:45:07 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=577</guid>
		<description><![CDATA[To sort an array by its value, similiar to mysql sort by just use 1 usort&#40;$array, create_function&#40;'$a, $b, $sortBy=&#34;distance&#34;', 'return strnatcmp($a[$sortBy], $b[$sortBy]);'&#41;&#41;; $array stores the array $sortBy set the key to sort by i.e 1 2 3 4 5 6 7 $array = array &#40; 1=&#62;array&#40;'name'=&#62;'me','location'=&#62;'somewhere','distance'=&#62;'200'&#41;, 2=&#62;array&#40;'name'=&#62;'you','location'=&#62;'somewhere','distance'=&#62;'2'&#41; &#41;; &#160; usort&#40;$array, create_function&#40;'$a, $b, $sortBy=&#34;distance&#34;', 'return strnatcmp($a[$sortBy], [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsort-a-array-by-its-value%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>To sort an array by its value, similiar to mysql sort by just use</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$a, $b, $sortBy=&quot;distance&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strnatcmp($a[$sortBy], $b[$sortBy]);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>$array stores the array<br />
$sortBy set the key to sort by</p>
<p>i.e</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #cc66cc;">1</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'me'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'somewhere'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'distance'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #cc66cc;">2</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'you'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'somewhere'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'distance'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">usort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$a, $b, $sortBy=&quot;distance&quot;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strnatcmp($a[$sortBy], $b[$sortBy]);'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>will result in the array being re-ordered with location 2 now being in location 1 (preserving the keys)</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fsort-a-array-by-its-value%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/sort-a-array-by-its-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>styling form buttons with divs</title>
		<link>http://adriancallaghan.co.uk/styling-form-buttons-with-divs/</link>
		<comments>http://adriancallaghan.co.uk/styling-form-buttons-with-divs/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 15:57:46 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=541</guid>
		<description><![CDATA[Styling a button inside a form with multiple div`s to achieve a curved button with click events etc, can be done relatively easy with the use of javascript. For example: function submitform(){ document.mainForm.submit(); } document.write(''); document.write(' '); document.write(' '); document.write('submit'); document.write(' '); document.write(' '); document.write(''); #container { width:200px; height:40px; padding:10px; color:#323232; display:block; background:#E4E4E4; border:4px solid [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fstyling-form-buttons-with-divs%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Styling a button inside a form with multiple div`s to achieve a curved button with click events etc, can be done relatively easy with the use of javascript.</p>
<link rel="stylesheet" type="text/css" href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=541&Ck_lnk=http://adriancallaghan.co.uk/demos/button/button.css" />
<div id="container">
For example:</p>
<form method="post" action="" name="mainForm">
<noscript><br />
<input type="submit" name="submit"></noscript><br />
<script type="text/javascript">				
function submitform(){
document.mainForm.submit();
}
document.write('<a href="http://adriancallaghan.co.uk/wp-content/plugins/clikstats/ck.php?Ck_id=541&Ck_lnk=javascript:submitform();" style="text-decoration:none; color:#fff; font-weight:bold;">');
document.write('
<div id="buyButtonMid">');
document.write('
<div id="buyButtonLeft"></div>
<p>');
document.write('submit');
document.write('
<div id="buyButtonRight"></div>
<p>');
document.write('</p></div>
<p>');
document.write('</a>');
</script><br />
</form>
</div>
<style>
#container {
	width:200px;
	height:40px;
	padding:10px;
	color:#323232;
	display:block;
	background:#E4E4E4;
	border:4px solid #C8C8C8;
	}</p>
<p>/* buy button */
#buyButtonRight{
	width:16px;
	height:44px;
	display:block;
	position:absolute;
	top:0;
	right:0;
	cursor:pointer;
	}</p>
<p>#buyButtonLeft{
	width:16px;
	height:44px;
	display:block;
	position:absolute;
	top:0;
	left:0;
	cursor:pointer;
	}</p>
<p>#buyButtonMid{
	height:24px;
	min-width:20px;
	/*max-width:300px;*/
	padding:13px 20px 7px 20px;
	display:block;
	position:relative;
	float:left;
	cursor:pointer;
	color:#ffffff; 
	font-size:13px; 
	text-decoration:none;
	}</p>
<p>/* normal */
#buyButtonLeft{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_left.jpg');}	
#buyButtonMid{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_mid.jpg');}	
#buyButtonRight{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_right.jpg');}</p>
<p>/* hover */
#buyButtonMid:hover #buyButtonLeft{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_left_hover.jpg');}
#buyButtonMid:hover {background:url('http://adriancallaghan.co.uk/demos/button/add2bas_mid_hover.jpg');}
#buyButtonMid:hover #buyButtonRight{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_right_hover.jpg');}</p>
<p>/* click */
#buyButtonMid:active #buyButtonLeft{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_left_click.jpg') no-repeat;}
#buyButtonMid:active {background:url('http://adriancallaghan.co.uk/demos/button/add2bas_mid_click.jpg');}
#buyButtonMid:active #buyButtonRight{background:url('http://adriancallaghan.co.uk/demos/button/add2bas_right_click.jpg');}
</style>
<p>firstly lets take a look at our raw code</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
      &lt;input type=&quot;submit&quot; name=&quot;submit&quot;&gt;
&lt;/form&gt;</pre></div></div>

<p>Next we place the button within no script tags, so it only displays if javascript is switched off, so that<br />
non javascript enabled browsers can still submit.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
      &lt;noscript&gt;
          &lt;input type=&quot;submit&quot; name=&quot;submit&quot;&gt;
      &lt;/noscript&gt;
&lt;/form&gt;</pre></div></div>

<p>Now we add the javascript styled button</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
&lt;form method=&quot;post&quot; action=&quot;&quot; name=&quot;mainForm&quot;&gt;
      &lt;noscript&gt;
          &lt;input type=&quot;submit&quot; name=&quot;submit&quot;&gt;
      &lt;/noscript&gt;
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;!--</span>					
&nbsp;
	<span style="color: #006600; font-style: italic;">// do the submission</span>
	<span style="color: #003366; font-weight: bold;">function</span> submitform<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		document.<span style="color: #660066;">mainForm</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// print the button</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;javascript:submitform();&quot; style=&quot;text-decoration:none; color:#fff; font-weight:bold;&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;buyButtonMid&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;buyButtonLeft&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;buyButtonRight&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">// --&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>Then style your button accordingly with your css,</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* buy button */</span>
<span style="color: #cc00cc;">#buyButtonRight</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">44px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#buyButtonLeft</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">44px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #808080; font-style: italic;">/*max-width:300px;*/</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span> <span style="color: #933;">20px</span> <span style="color: #933;">7px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/* normal */</span>
<span style="color: #cc00cc;">#buyButtonLeft</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_left.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>	
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_mid.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>	
<span style="color: #cc00cc;">#buyButtonRight</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_right.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* hover */</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:hover </span><span style="color: #cc00cc;">#buyButtonLeft</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_left_hover.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_mid_hover.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:hover </span><span style="color: #cc00cc;">#buyButtonRight</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_right_hover.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* click */</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:active </span><span style="color: #cc00cc;">#buyButtonLeft</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_left_click.jpg'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_mid_click.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#buyButtonMid</span><span style="color: #3333ff;">:active </span><span style="color: #cc00cc;">#buyButtonRight</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/add2bas_right_click.jpg'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Job done <img src='http://adriancallaghan.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fstyling-form-buttons-with-divs%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/styling-form-buttons-with-divs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress comment count as a button</title>
		<link>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/</link>
		<comments>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 13:46:56 +0000</pubDate>
		<dc:creator>Adrian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://adriancallaghan.co.uk/?p=533</guid>
		<description><![CDATA[Styling the wordpress comment count as a button/icon etc can be tricky because the normal call to the comments 1 comments_popup_link&#40;__&#40;'Comments (0)'&#41;, __&#40;'Comments (1)'&#41;, __&#40;'Comments (%)'&#41;&#41;; formats the output as an anchor point with the correct link, alt tags etc already set up. So in order to intercept this and then add you own anchor [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fwordpress-comment-count-as-a-button%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<p>Styling the wordpress comment count as a button/icon etc can be tricky because the normal call to the comments</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">comments_popup_link<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (0)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (1)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments (%)'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>formats the output as an anchor point with the correct link, alt tags etc already set up.</p>
<p>So in order to intercept this and then add you own anchor point with divs/imagery etc you need to make a custom request</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">// SQL</span>
<span style="color: #000088;">$SQL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(*) AS Count FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span> WHERE comment_approved='1'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$SQL</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_post_ID='&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sort the array into a string prefixed with 'Comments '</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$SQL</span><span style="color: #339933;">,</span> ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
<span style="color: #000088;">$comments</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Comments ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Count'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// generate the alt and title tags</span>
<span style="color: #000088;">$alt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Comment on '</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// echo the button if this is not a single and not a page</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// anchor open</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$alt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$alt</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// complex formatting rules for the comment pop up, go here</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$comments</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// anchor close</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above does exactly the same, formats the link etc, but now you can access the anchor point directly and format it your own way.</p>
<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fadriancallaghan.co.uk%2Fwordpress-comment-count-as-a-button%2F&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
]]></content:encoded>
			<wfw:commentRss>http://adriancallaghan.co.uk/wordpress-comment-count-as-a-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

