<?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>Jam Jar - Alistair Robinson&#039;s Blog</title>
	<atom:link href="http://www.moonbaseinternet.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moonbaseinternet.com/blog</link>
	<description>Alistair Robinson&#039;s blog</description>
	<lastBuildDate>Wed, 03 Mar 2010 22:32:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fear and Trembling</title>
		<link>http://www.moonbaseinternet.com/blog/fear-and-trembling/</link>
		<comments>http://www.moonbaseinternet.com/blog/fear-and-trembling/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 14:09:58 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=906</guid>
		<description><![CDATA[It is facile to mock or criticize philosophy for its difficult language, and I like to think I&#8217;m not a facile thinker, but I had an &#8220;oh sod this&#8221; moment while reading Kierkegaard this morning. The obscure, tangled, repetitive and willfully paradoxical language is just tedious &#8211; at least, so it strikes me so far. [...]]]></description>
			<content:encoded><![CDATA[<p>It is facile to mock or criticize philosophy for its difficult language, and I like to think I&#8217;m not a facile thinker, but I had an &#8220;oh sod this&#8221; moment while reading Kierkegaard this morning. The obscure, tangled, repetitive and willfully paradoxical language is just tedious &#8211; at least, so it strikes me so far. I know a little bit about philosophy: I&#8217;ve read some Plato, Hume, Nietzsche, Bertrand Russell, and recently Roger Scruton. So I can be quite confident that my repugnance is not a knee-jerk reaction to difficult concepts. I don&#8217;t know, perhaps it just isn&#8217;t to my taste. Like Nietzsche, it is rhetorical and poetical rather than clear and elegant. I suppose that you can find truth, maybe not <i>anywhere</i>, but in many places; and where you find it depends on your tastes. Analyze this&#8230;</p>
<p>&#8220;Faith is precisely the paradox that the single individual as the single individual is higher than the universal, is justified before it, not as inferior to it but superior—yet in such a way, please note, that it is the single individual who, after being subordinate as the single individual to the universal, now by means of the universal becomes the single individual who as the single individual is superior, that the single individual as the single individual stands in an absolute relation to the absolute. This position cannot be mediated, for all mediation takes place only by virtue of the universal; it is and remains for all eternity a paradox, impervious to thought. And yet faith is this paradox&#8230;&#8221;</p>
<p>From <a href="http://en.wikipedia.org/wiki/Fear_and_Trembling"><i>Fear and Trembling</i></a> by Søren Kierkegaard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/fear-and-trembling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Woes and Upcoming Redesign</title>
		<link>http://www.moonbaseinternet.com/blog/wordpress-woes-and-upcoming-redesign/</link>
		<comments>http://www.moonbaseinternet.com/blog/wordpress-woes-and-upcoming-redesign/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 09:42:25 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=904</guid>
		<description><![CDATA[After my last post, in which I briefly sang the praises of Wordpress, I became increasingly troubled by the horribly slow page load times of this blog, so I spent an hour or two last night trying to speed things up. It&#8217;s a while since I installed WP Super Cache, and all this time I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>After my last post, in which I briefly sang the praises of Wordpress, I became increasingly troubled by the horribly slow page load times of this blog, so I spent an hour or two last night trying to speed things up. It&#8217;s a while since I installed WP Super Cache, and all this time I&#8217;ve been thinking that my troubles were over. I even tried pretending that the occasions when it took 10 seconds to load a page were just freak occurrences, only ever noticed by me. As various authority figures from my childhood would say, I was only fooling myself. Even with WP Super Cache it&#8217;s still been crap.</p>
<p>I&#8217;ve managed to improve the speed substantially now, so I thought it was worth recording here the changes that seemed to make the biggest difference. I knew the problem wasn&#8217;t a heavy theme, uncompressed CSS (it&#8217;s compressed but it really doesn&#8217;t need to be), too many images or any of that, so I knew it had to be all those pointless database queries (see <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/">here</a>, <a href="http://elliottback.com/wp/why-my-wordpress-site-is-so-much-faster-than-yours/">here</a> and <a href="http://yoast.com/speed-up-wordpress/">here</a> for details).</p>
<p>Well, it was partly that: removing them made a big difference. But the <i>biggest</i> difference I noticed after a single change (not from rigorous testing, I should add) was when I removed the <b>WP Spam Free</b> plugin. Looking at what the plugin was actually doing on every page load (even with caching), I did have a feeling it would help to get rid of it. That it&#8217;s known to be slow is confirmed in a few places online, including <a href="http://support.tigertech.net/wordpress-performance">here</a>.</p>
<p>I guess the lesson of this is that if you&#8217;re using particularly slow plugins, you might not see the gains from WP Super Cache that you&#8217;d hoped for.</p>
<p>Greedy for speed, I also removed a few things from the theme, including the Cufon text-replacement JavaScript that drew the headings in the Diavlo font. It wasn&#8217;t working very well (there was always a delay) and, although it&#8217;s a beautiful font, I don&#8217;t think it was right for me or this blog. Nothing wrong with Georgia.</p>
<p>Anyway, soon I&#8217;ll be moving this blog to my new host, WebFaction, and it&#8217;ll be getting a redesign, along with the rest of my site. I&#8217;m at the stage where I&#8217;ve designed an HTML/CSS template that I&#8217;m very happy with, but now&#8217;s when I have to commit to the software, and I&#8217;m avoiding facing up to it. Realistically, though, I can&#8217;t see myself choosing anything but Wordpress.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/wordpress-woes-and-upcoming-redesign/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Nice and Simple Photo Gallery Solution for MODx</title>
		<link>http://www.moonbaseinternet.com/blog/a-nice-and-simple-photo-gallery-solution-for-modx/</link>
		<comments>http://www.moonbaseinternet.com/blog/a-nice-and-simple-photo-gallery-solution-for-modx/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 03:18:04 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[MODx]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[content management]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[modx]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=828</guid>
		<description><![CDATA[My third MODx site is about to launch. It&#8217;s relatively simple (no forms!) so I had the chance to really concentrate on refining my architecture, and the work I&#8217;ve done will stand me in good stead for a while (unless I give in to the enticements of SilverStripe or ExpressionEngine, or just ditch the PHP [...]]]></description>
			<content:encoded><![CDATA[<p>My third MODx site is about to launch. It&#8217;s relatively simple (no forms!) so I had the chance to really concentrate on refining my architecture, and the work I&#8217;ve done will stand me in good stead for a while (unless I give in to the enticements of SilverStripe or ExpressionEngine, or just ditch the PHP altogether and finally get up-and-running with Django).</p>
<p>&#8220;Refining his architecture? What does he mean?&#8221; For me, learning to use MODx well has been about working out how to combine templates, template variables, chunks and snippets in a logical and efficient structure. A good application &#8211; a small one, at least &#8211; should have a shape that you can envision (if you&#8217;re the kind of person who envisions shapes, that is). The shape should be pleasing, natural and economical. In my first two MODx sites I fashioned a few butt-ugly shapes that would certainly have sullied the pages of Euclid&#8217;s Elements.</p>
<p>They worked, and they were clever in their ways, but I feel I&#8217;ve moved past all that now, that I&#8217;m approaching the gleaming heavenly realm of the Platonic solids, of perfect dodecahedrons and icosahedrons.</p>
<p>Maybe I make it difficult for myself. Two components that are mentioned so often in the MODx forum and documentation that you could be forgiven for assuming were part of the core itself, are the snippets Ditto and Jot &#8211; but I&#8217;ve never used them. And then there&#8217;s Wayfinder. I used it once, and it was great, but I didn&#8217;t really know what I was doing and I wasn&#8217;t comfortable with it, and it was a hassle to learn how to use it. In the project I&#8217;m on now I&#8217;ve just done it myself, with a &#8220;menu&#8221; snippet and a couple of chunks. I know the boundaries of the project so I can decide to avoid complication by battening things down; and there&#8217;s so little code that changing it will be easy in the event that the structure of the navigation needs to change in the future.</p>
<p>Incidentally, Jot and Ditto are often mentioned in connection with blogs, for which they appear to be indispensable in MODx. Well, say what you like about Wordpress but it does blogging pretty damn well and is equally customizable. I fear if I try putting a blog together with MODx, things might get pretty sticky. Even if I was successful I&#8217;d still end up with something far inferior to Wordpress. This is a tricky situation, because I really do want to be able to use MODx for blogs &#8211; the templating system is close to perfection, and Wordpress&#8217;s is horrible.  But this is all by the way.</p>
<p>I really appreciate the work that people put in to writing freely available, open-source code. Wonders abound. But I have to confess: I don&#8217;t have much patience when it comes to using plugins, widgets, modules or whatever. If I&#8217;m looking for one it&#8217;s to save time, so 1. I want it to behave roughly as I&#8217;m expecting, and 2. I want good documentation, i.e. documentation I don&#8217;t have to spend much time with. Otherwise, I&#8217;d rather just do it myself, gaining into the bargain the extra advantage of avoiding the overhead of features I don&#8217;t need.</p>
<p>In this last project I&#8217;ve been working on, the most common type of page required an image gallery to go underneath the main content, and a main image in the body of the content text. Any page of this type could have photos added to it, and they should appear in the gallery in the same format. For the solution I needed: an easy way for editors to add photos without any resizing woes; auto-generated thumbnails; a way of outputting the gallery HTML; some good HTML and CSS; and a nice Lightbox on the client-side.</p>
<p>I had a look around for a plugin or module but it really wasn&#8217;t worth the hassle and nothing I found seemed like a good fit, so here&#8217;s what I did. If anyone spots a problem in the code or in the concept itself, let me know. </p>
<p>UPDATES &amp; THINGS TO NOTE:</p>
<ul style="list-style-type:disc;padding-left:20px">
<li>I&#8217;m not aiming here to provide full site-wide image management. For that, something like <a href="http://wiki.modxcms.com/index.php/MaxiGallery">MaxiGallery</a> might be a good choice, and certainly provides loads more features.</li>
<li>The plugin might not work in the 0.9.x versions of MODx. I&#8217;m using 1.0.2. Thanks to <a href="http://www.1-vision.nl/">Dimmy</a> for pointing this out in the comments</li>
<li>The plugin doesn&#8217;t seem to work correctly when using the front-end editor</li>
<li>It&#8217;s not included here but I’d recommend checking the size of the uploaded photos in the first place, and you might want to actually resize all uploaded images so as to standardize the “full-size” photos that are displayed in the lightbox.</i>
<li>The code here doesn&#8217;t check for the existence of files, or handle exceptions</li>
</ul>
<h3>What we&#8217;re aiming for</h3>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/mocgc_gallery.jpg" alt="" title="mocgc_gallery" width="580" height="464" class="alignleft size-full wp-image-844" /></p>
<p>Above is an example of the page type in question, with the portion of the page we&#8217;re interested in highlighted. By the way, the <a href="http://www.flickr.com/photos/alistairrobinson" title="my flickr photos">photos</a> are not at all relevant to the website &#8211; this is just for illustration.</p>
<p></p>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/mocgc_gallery_lightbox.jpg" alt="" title="mocgc_gallery_lightbox" width="580" height="388" class="alignleft size-full wp-image-851" /></p>
<p>This is not particularly relevant to the MODx side of things, but for the sake of completion the image above shows the lightbox that pops up when you click on a thumbnail. </p>
<p>To achieve all this we need:</p>
<ul style="list-style-type:disc;padding-left:20px">
<li>A template for this kind of page</li>
<li>Template variables for the photos, to apply to this template</li>
<li>A chunk for the outer HTML of the gallery: <i>gallery</i></li>
<li>A chunk for the inner HTML: <i>gallery_item</i>, to be repeated for each photo</li>
<li>A snippet for the body photo: <i>body_photo</i></li>
<li>A snippet for the gallery: <i>gallery</i></li>
<li>A plugin: <i>thumbnailer</i>, which generates thumbnails, and runs when a document is saved</li>
<li>Some CSS to style the gallery HTML</li>
<li>Some javascript to display the full-size images in a lightbox &#8211; I&#8217;ll use jQuery</li>
</ul>
<p>Although it might make sense to explain the thumbnail generation first, I&#8217;m going to start with the template, template variables, snippets and chunks to demonstrate the output we&#8217;re aiming to produce, and from there move backwards to the plugin. Finally, with the MODx side dealt with I&#8217;ll say a bit about the client-side, specifically the lightbox for viewing the full-size photos.</p>
<h3>The Template</h3>
<p>The template itself can be whatever you like, just so long as there <i>is</i> one that you can target the template variables to and which you can use for all pages of this type. The relevant portion looks like this:</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>[*longtitle*]<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span><br />
&nbsp; &nbsp; [!body_photo!]<br />
&nbsp; &nbsp; [*content*]<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span><br />
[!gallery!]</div></div>
<p>It&#8217;s not important that I&#8217;m using HTML5 (see the &lt;section&gt; tag). But if you haven&#8217;t coded in HTML5 before I heartily recommend it &#8211; you can even get it to work in IE with the <a href="http://html5doctor.com/how-to-get-html5-working-in-ie-and-firefox-2/">inclusion of a wee javascript file</a>. This is the first line of an HTML5 document:</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span></div></div>
<p> Beautiful.</p>
<h3>The Template Variables</h3>
<p>We need some template variables, one for the main body image and one for each photo in the gallery, and the latter variables need to go in a new category, which I&#8217;ve called &#8220;Gallery.&#8221;</p>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/tmplvars.jpg" alt="" title="tmplvars" width="355" height="342" class="alignleft size-full wp-image-890" /></p>
<p>In the editor, this gives you something like this:</p>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/tmplvars_editor.jpg" alt="" title="tmplvars_editor" width="567" height="490" class="alignleft size-full wp-image-898" /></p>
<p>You may pick up on a crucial implication of this, namely that the number of photos an editor can add to a page is limited, almost <i>hard-coded</i>. I think this is probably fairly standard practice in the world of CMSs, but it went against my instincts: it&#8217;s natural to want to provide the flexibility of being able to add limitless photos. But ultimate flexibility is mostly a complete waste of time, and often holds its own problems. So editors will only be able to add eight photos to a gallery. So what? Looking at the requirements, eight was plenty. To paraphrase 37 Signals in <a href="http://gettingreal.37signals.com/toc.php">Getting Real</a>, <i>it just didn&#8217;t matter.</i> It&#8217;s amazing the time you can save by making decisions like this.</p>
<p>Anyway, providing for more photos per page at some point in the future would be a simple matter of the developer/administrator adding more template variables.</p>
<h3>The Chunks</h3>
<p>We need an outer and an inner chunk.</p>
<p><i>gallery</i></p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gallery&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; [+gallery_items+]<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span></div></div>
<p><i>gallery_item</i></p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+big+]&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+title+]&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+thumb+]&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+alt+]&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+thumb_width+]&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;[+thumb_height+]&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span></div></div>
<p></p>
<h3>The Snippets</h3>
<p>First of all, some configuration values to be used both by the snippets and by the plugin.</p>
<p><i>config.php</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAGES_FOLDER'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'assets/images/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMBS_FOLDER'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'assets/images/thumbs/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MEDIUM_FOLDER'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'assets/images/medium/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_TMPLVAR'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'body_photo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_WIDTH'</span><span style="color: #339933;">,</span>100<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_HEIGHT'</span><span style="color: #339933;">,</span>75<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_WIDTH'</span><span style="color: #339933;">,</span>300<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_HEIGHT'</span><span style="color: #339933;">,</span>225<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GALLERY_CATEGORY_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Gallery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>It&#8217;s not very important where this config file lives. Somewhere in &#8220;assets&#8221; is good. (And if you&#8217;re a big fan of config files you could put other things in here, such as the chunk names. Or, now that I think of it, you could pass in the chunk names in the snippet calls.)</p>
<p>The <i>body_photo</i> snippet is pretty basic, and it&#8217;s not crucial to do it this way. As usual with snippets I just include a separate file:</p>
<p><i>body_photo</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/snippets/body_photo.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p><i>body_photo.php</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/utility.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$medium_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MEDIUM_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> get_tv_value<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'body_photo'</span><span style="color: #339933;">,</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documentIdentifier</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><br />
<br />
<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;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$full_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$path</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$full_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$medium_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$size</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: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// portrait, so swap the dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$body_photo_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$body_photo_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$body_photo_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$body_photo_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;&quot; width=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$body_photo_width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; height=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$body_photo_height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>All this does is echo out an image tag to the page if there&#8217;s a value for the <i>body_photo</i> template variable, and nothing if there isn&#8217;t. Crucially, though, the image is not the one uploaded but a resized version held in a folder for the medium-sized images. More on the resizing later.</p>
<p>By the way, <i>get_tv_value</i> is just a helper function which I&#8217;ve got in utility.php:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> get_tv_value<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$doc_id</span><span style="color: #339933;">=</span>0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTemplateVarOutput</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$doc_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Now for the gallery. Again, in the MODx manager we need to just include our snippet code:</p>
<p><i>gallery</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/snippets/gallery.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p><i>gallery.php</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/utility.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$images_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAGES_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumbs_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMBS_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$gallery_category_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GALLERY_CATEGORY_NAME'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumb_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_WIDTH'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumb_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_HEIGHT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$gal_vars</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;modx_site_tmplvars A INNER JOIN modx_categories B ON A.category = B.id &quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;B.category = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$gallery_category_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$gal_var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gal_vars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$photo</span> <span style="color: #339933;">=</span> get_tv_value<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gal_var</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documentIdentifier</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &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;">$photo</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$full_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$photo</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$full_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thumbs_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$big</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$images_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$chunkArr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'big'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$big</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'alt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumb_width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$thumb_width</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'thumb_height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$thumb_height</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parseChunk</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gallery_item'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$chunkArr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[+'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'+]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<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;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parseChunk</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gallery'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gallery_items'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[+'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'+]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>In gallery.php, line 12 shows why we put the template variables for the gallery in a new category: we can get a MySQL result for the eight variables. Immediately afterwards we loop through that result to build a bunch of list items, each time injecting values into the <i>gallery_item</i> chunk, which is the inner, repeated chunk of the gallery HTML. Each iteration will replace the various placeholders, <i>[+big+]</i>, <i>[+title+]</i> and so on, producing something like this:</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/lochawe.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/lochawe.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span></div></div>
<p>Notice that the actual image for the image tag is the thumbnail version, and the surrounding anchor links to the original. Also notice the <i>rel=&#8221;lightbox&#8221;</i> value, which will be used by the JavaScript.</p>
<p>When we&#8217;ve got all the list items it&#8217;s time (line 41) to inject them into the outer chunk, <i>gallery</i>, by replacing the placeholder <i>[+gallery_items+]</i>. The end result is something like this:</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gallery&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/lochawe.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/lochawe.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/skull.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;skull.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/skull.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;skull.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/cammo.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cammo.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/cammo.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cammo.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/bavelaw.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bavelaw.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/bavelaw.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bavelaw.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/piano.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;piano.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/piano.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;piano.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/calton.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calton.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/calton.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calton.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span></div></div>
<p>And then it&#8217;s echoed out to the page. With all the template parsing done, the HTML that&#8217;s sent to the browser will look something like this:</p>
<div class="codecolorer-container html4strict dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Corporate Events<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/medium/meadows.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;225&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem. In fringilla mi in ligula. Pellentesque aliquam quam vel dolor. Nunc adipiscing. Sed quam odio, tempus ac, aliquam molestie, varius ac, tellus. Vestibulum ut nulla aliquam risus rutrum interdum. Pellentesque lorem. Curabitur sit amet erat quis risus feugiat viverra. Pellentesque augue justo, sagittis et, lacinia at, venenatis non, arcu. Nunc nec libero. In cursus dictum risus. Etiam tristique nisl a nulla. Ut a orci. Curabitur dolor nunc, egestas at, accumsan at, malesuada nec, magna.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span> <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span> <br />
<span style="color: #009900;">&lt;section <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gallery&quot;</span>&gt;</span> <br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/lochawe.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/lochawe.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lochawe.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/skull.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;skull.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/skull.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;skull.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/cammo.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cammo.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/cammo.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cammo.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/bavelaw.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bavelaw.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/bavelaw.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bavelaw.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/piano.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;piano.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/piano.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;piano.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/calton.jpg&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calton.jpg&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lightbox&quot;</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://example.com/assets/images/thumbs/calton.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;calton.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span> <br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span></div></div>
<p>That&#8217;s it for the output side of things. But how do we get those thumbnails, and the medium image, where they&#8217;re meant to be?</p>
<h3>The Plugin</h3>
<p>I&#8217;ve called the plugin <i>thumbnailer</i>, but it actually does one other thing, which is generate a medium-sized version of the body photo, which is exactly the size required for the page.</p>
<p>As with the snippets I include an external file:</p>
<p><i>thumbnailer</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/plugins/thumbnailer/thumbnailer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Notice the lack of PHP opening and closing tags. In plugins, unlike snippets, you always exclude them (and you always forget to.)</p>
<p>The one other thing to do to set up the plugin in the manager is check the <i>OnDocFormSave</i> System Event, as shown below.
<p>
<img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/system_events.jpg" alt="" title="system_events" width="371" height="253" class="alignleft size-full wp-image-899" /></p>
<p></p>
<p><i>thumbnailer.php</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/ImageHelper.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/bin/config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$gallery_category_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GALLERY_CATEGORY_NAME'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// The name of the body photo template variable</span><br />
<span style="color: #000088;">$body_photo_tmplvar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_TMPLVAR'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Dimensions</span><br />
<span style="color: #000088;">$body_photo_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_WIDTH'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$body_photo_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'BODY_PHOTO_HEIGHT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumb_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_WIDTH'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumb_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMB_HEIGHT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Directory paths</span><br />
<span style="color: #000088;">$images_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IMAGES_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$thumbs_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'THUMBS_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$medium_folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">constant</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MEDIUM_FOLDER'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$gal_vars</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;A.id&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;modx_site_tmplvars A INNER JOIN modx_categories B ON A.category = B.id &quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">&quot;B.category = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$gallery_category_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Generate the thumbnails</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$gal_var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gal_vars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$upload_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tv'</span><span style="color: #339933;">.</span><span style="color: #000088;">$gal_var</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &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;">$upload_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$full_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$upload_file</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$full_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">resizeImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumbs_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumb_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumb_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000088;">$body_photo_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;modx_site_tmplvars&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;name = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$body_photo_tmplvar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Also create the medium-sized image</span><br />
<span style="color: #000088;">$upload_file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tv'</span><span style="color: #339933;">.</span><span style="color: #000088;">$body_photo_id</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<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;">$upload_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$full_path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$modx</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$upload_file</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$full_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Swap the dimensions if it's portrait</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">isPotrait</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$body_photo_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$body_photo_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$body_photo_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$body_photo_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">resizeImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$medium_folder</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_photo_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_photo_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; <br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>My first instinct when writing this was to use the MODx API to get the template variable values, but when the plugin runs it&#8217;s too early to do that, so we have to use $_REQUEST to get the form values directly from the editor. The naming scheme for template variable input elements is &#8220;tv[template variable id],&#8221; e.g. in my case it was <i>tv9</i> to <i>tv17</i> for the gallery variables.</p>
<p>For the thumbnails, we can get the same MySQL result that we used for the snippet (line 21), and then in the loop, concatenate the input name using the template variable IDs (line 28). For the body photo, we can get the name for the input by first getting the ID of the <i>body_photo</i> template variable based on its name (line 37).</p>
<p>For the resizing itself, I&#8217;ve used a small class called ImageHelper, which is kindly provided <a href="http://t.wits.sg/2009/02/07/howto-php-image-resize-centered-and-cropped/">here at Tips for Twits</a>. I&#8217;ll include the code here for completeness:</p>
<p><i>ImageHelper.php</i></p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000000; font-weight: bold;">class</span> ImageHelper <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; static <span style="color: #000000; font-weight: bold;">function</span> treatFilename<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$newfilename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$newfilename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$newfilename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$newfilename</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; static <span style="color: #000000; font-weight: bold;">function</span> isPotrait<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">!</span>ImageHelper<span style="color: #339933;">::</span><span style="color: #004000;">isLandscape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; static <span style="color: #000000; font-weight: bold;">function</span> isLandscape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$size</span> &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$srcimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; static <span style="color: #000000; font-weight: bold;">function</span> resizeImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//if (!file_exists(realpath($srcimage)))</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//return;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$srcpathinfo</span> &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$srcext</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcpathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$destpathinfo</span> &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$destimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$destext</span> &nbsp; &nbsp;&nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$destpathinfo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$size</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$srcimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the size of the original image into an array [0]=&gt; width, [1]=&gt; height</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$canvas</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; <span style="color: #666666; font-style: italic;">// Prepare canvas</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create a new image in the memory from the file </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'wbmp'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bmp'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromwbmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpeg'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'png'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'gif'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromgif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xpm'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> imagecreatefromxpm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$srcimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Calculate dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$widthratio</span> &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$heightratio</span>&nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span><span style="color: #000088;">$height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span> &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'ratio'</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$widthratio</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'source_cropwidth'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'source_cropheight'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'source_offsetx'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'source_offsety'</span> &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$heightratio</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$widthratio</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$heightratio</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_width'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_height'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp;&nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsetx'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsety'</span><span style="color: #009900;">&#93;</span> &nbsp; &nbsp; &nbsp; <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> 0<span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsetx'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_offsety'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'source_cropheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$destext</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'jpeg'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'png'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'gif'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'wbmp'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bmp'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagewbmp</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span><span style="color: #339933;">,</span> <span style="color: #000088;">$destimage</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$canvas</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$image</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>It takes care of cropping and resizing very nicely, and is the simplest and most effective code for this kind of circumstance that I&#8217;ve found.</p>
<p>So let&#8217;s say an editor has their document looking like this:</p>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/editor_photos.jpg" alt="" title="editor_photos" width="569" height="882" class="alignleft size-full wp-image-900" /></p>
<p>In the file system, the result of saving this document will be the following (with all other files excluded).</p>
<p><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/files.jpg" alt="" title="files" width="446" height="607" class="alignleft size-full wp-image-901" /></p>
<h3>Client-Side</h3>
<p>It&#8217;s a simple job to style the HTML output with CSS, so I won&#8217;t cover that. So, let&#8217;s briefly cover the lightbox. First it needs some CSS like this:</p>
<div class="codecolorer-container css dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #cc00cc;">#lightbox</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;">;</span>opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0.85</span><span style="color: #00AA00;">;</span>filter<span style="color: #00AA00;">:</span>alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">=</span>85<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>position<span style="color: #00AA00;">:</span><span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>top<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>left<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>height<span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>z-index<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#lightbox-panel</span> <span style="color: #00AA00;">&#123;</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>right<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>display<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>position<span style="color: #00AA00;">:</span><span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>top<span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>background<span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>z-index<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1001</span><span style="color: #00AA00;">;</span>text-align<span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#lightbox-panel</span> a <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FEF9EB</span><span style="color: #00AA00;">&#125;</span></div></div>
<p>Recall that in the gallery each list item&#8217;s image link has <i>rel=&#8221;lightbox&#8221;</i>. We can use this in following code, which, aside from its dependence on jquery, is the entirety of the lightbox script (it doesn&#8217;t work in IE6 though, last time I checked &#8211; some tweaking required for that). </p>
<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<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><br />
<br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[rel^='lightbox']&quot;</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">===</span>0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> lightbox <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div id=&quot;lightbox-panel&quot;&gt;<span style="color: #000099; font-weight: bold;">\</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;img src=&quot;'</span><span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; alt=&quot;photo&quot; /&gt;&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a id=&quot;close-panel&quot; href=&quot;[~[*id*]~]#&quot;&gt;Click anywhere or press Escape to close the image&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<span style="color: #000099; font-weight: bold;">\</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;lightbox&quot;&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span>lightbox<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox-panel img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox, #lightbox-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span>300<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox-panel img&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a#close-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox, #lightbox-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span>300<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox, #lightbox-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span>300<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">keyCode</span><span style="color: #339933;">===</span><span style="color: #CC0000;">27</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Escape</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lightbox, #lightbox-panel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span>300<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// DOM ready</span></div></div>
<p>Click on the photo below for a demo.</p>
<style>
/* LIGHTBOX */
#lightbox {display:none;background:#000000;opacity:0.85;filter:alpha(opacity=85);position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:1000;}
#lightbox-panel {left:0;right:0;display:none;position:fixed;top:100px;background:transparent;z-index:1001;text-align:center;}
#lightbox-panel a {color:#FEF9EB}
</style>
<p><a href="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/010.jpg" rel="lightbox"><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/02/010-150x150.jpg" alt="" title="010" width="150" height="150" class="alignright size-thumbnail wp-image-902" /></a></p>
<p></p>
<p>So there you have it. I hope you find it shapely, pleasingly simple, and easy to maintain.</p>
<p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><br />
<script type="text/javascript" src="/blog/examples/js/modx_gallery_lightbox.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/a-nice-and-simple-photo-gallery-solution-for-modx/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Magical MODx ManagerManager Plugin</title>
		<link>http://www.moonbaseinternet.com/blog/the-magical-modx-managermanager-plugin/</link>
		<comments>http://www.moonbaseinternet.com/blog/the-magical-modx-managermanager-plugin/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 01:22:23 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[MODx]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[managermanager]]></category>
		<category><![CDATA[modx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=744</guid>
		<description><![CDATA[
My first MODx-powered website went live today (Pinnacle Telecom Group plc), and my intention now is to share some of my experiences. From a development point of view MODx is so flexible that there are several ways of doing most things, so if like me you constantly fret about your architecture and constantly refactor your [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.glengroup.co.uk/"><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2010/01/blog_screenshot_pinnacle.png" alt="Pinnacle Telecom Group plc" title="Pinnacle Telecom Group plc" width="315" height="401" class="alignleft size-full wp-image-762" /></a></p>
<p>My first MODx-powered website went live today (<a href="http://www.glengroup.co.uk/">Pinnacle Telecom Group plc</a>), and my intention now is to share some of my experiences. From a development point of view MODx is so flexible that there are several ways of doing most things, so if like me you constantly fret about your architecture and constantly refactor your code for re-usability, you might be confused about just what is the <i>best</i> way of doing things, especially if you&#8217;re just starting out. So in this and forthcoming posts I&#8217;ll be discussing some of my development techniques.</p>
<p>This post is mainly an introduction to the ManagerManager plugin written by <a href="http://www.rckt.co.uk/">Nick Crossland</a>. In my opinion it is absolutely indispensable, unless you&#8217;ve come up with your own way of doing the same thing. But it took me a while to get it. It&#8217;s possible I was just having a stupid day, but on my first encounter with it I was puzzled and frustrated for a while about how and when to use it, so maybe I can plug some gaps here. Let me just say again that this plugin is <i>absolutely indispensable</i>. Well, I guess you could get by without it, but at the very least it&#8217;s <i>very excellent</i>.</p>
<p>Essentially, it allows you to control how resources (also referred to as &#8220;documents,&#8221; mostly corresponding to web pages) are edited, depending on the role of the user and/or the template used by the resource. Using it you can customize and control the user-experience for content editors by changing, in several ways, the document fields and template variables that are available to users editing a resource. And you do all this by defining &#8220;rules&#8221; in a single rules file or chunk.</p>
<h3>Install</h3>
<p>Before I go into what exactly you can do with it, here&#8217;s how to set it up. ManagerManager came bundled with my MODx 1.0.2 installation, but you can also <a href="http://modxcms.com/extras/package/255">get the package from the MODx website.</a> The two things to look out for in the download are <span class="inline_code">plugin.txt</span> and the <span class="inline_code">managermanager</span> folder. Put that folder in <span class="inline_code">yoursite.com/assets/plugins</span> and go to <span class="inline_code">yoursite.com/assets/plugins/managermanager/docs</span> in a browser to read the documentation (you can also see it <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/">here on my site</a> if you haven&#8217;t downloaded it yet).</p>
<p>In the documentation you get details on installing and setting up, but I&#8217;ll briefly go over the steps here. Basically all that&#8217;s left to do at this point is to create the plugin in MODx with the contents of <span class="inline_code">plugin.txt</span>. Go to <span class="inline_code">Elements > Manage Elements > Plugins > New Plugin</span> and paste in the code, then check the System Events described in the docs, and then paste in the configuration string in the Configuration tab. The string looks like this:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;config_chunk=Configuration Chunk;text; &amp;remove_deprecated_tv_types_pref=Remove deprecated TV types;list;yes,no;yes &amp;which_jquery=jQuery source;list;local (assets/js),remote (google code),manual url (specify below);remote (google code) &amp;js_src_type=jQuery URL override;text;</div></div>
<p>By the way, if you&#8217;re not aware, configuration parameters are defined like this:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&amp;name=Description;datatype;value</div></div>
<p>So in the configuration string for ManagerManager given above, it sets up a text-field parameter called <span class="inline_code">config_chunk</span> but leaves it blank. If you want to use a chunk to manage your rules, put the name of it in here. My MODx installation already had the chunk <span class="inline_code">mm_demo_rules</span>.</p>
<p>When the plugin runs, it looks for rules in the chunk that you&#8217;ve defined in the configuration tab, but if that chunk is empty or nonexistent or <i>not</i> defined in the configuration tab (as in my case), then it looks in the file <span class="inline_code">managermanager/mm_rules.inc.php</span>. I use this file for my rules rather than a chunk, but it&#8217;s a matter of taste. Note that if there&#8217;s something in the chunk (and the chunk is defined in the configuration), none of the rules in the file will be applied, because the file won&#8217;t even be included.</p>
<h3>The Rules</h3>
<p>So what do the rules actually look like? Basically they&#8217;re function calls. All of them are described in the documentation, in the <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/fields.htm">Fields</a>, <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/tabs.htm">Tabs</a>, <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/widgets.htm">Widgets</a> and <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/sections.htm">Sections</a> pages, and the names to use to refer to the fields are described in <a href="http://www.moonbaseinternet.com/blog/examples/managermanager/docs/field-names.htm">Field names</a>. Note that the although these field names mostly correspond to the MODx database field names, not all of them do.</p>
<p>Here&#8217;s an example rule:</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_renameField('longtitle','Page heading');</div></div>
<p>Your rules file or chunk is just a bunch of these calls, and every time somebody edits a resource, they will be applied. Easy.</p>
<h3>Hiding Fields</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// Hide these fields for resources using templates 3 and 5,<br />
// for all users except administrators<br />
<br />
mm_hideFields('alias,link_attributes,introtext,menutitle,menuindex,show_in_menu', '!1', '3,5');</div></div>
<p>You may want to hide fields from users who are editing certain resources, because you don&#8217;t want those values to be changed. Say you want to fix the value of the parent resource, or you want to ensure that <span class="inline_code">Show in menu</span> is always set to true and can&#8217;t be changed. Or maybe you just don&#8217;t want to confuse users with too many fields (if there&#8217;s no need for them to see the <span class="inline_code">URL alias</span> or <span class="inline_code">Link Attributes</span> fields, why not hide them?).</p>
<p>One of my uses for this is hiding the resource content editor for templates that contain only dynamic data such as tables, feeds, blog post excerpts, and so on. For these pages, all the content is generated by snippets, in combination with chunks, and anything entered as content by the user will not show up (because in the templates and chunks I&#8217;m not using the <span class="inline_code">[*content*]</span> field at all) &#8211; so it makes sense to remove that functionality.</p>
<h3>Setting Default Values</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// Set the default value for the content_type field to<br />
// &quot;application/pdf&quot;, for resources using template 10,<br />
// for all users<br />
&nbsp; &nbsp; <br />
mm_default('content_type', 'application/pdf', '', '10');</div></div>
<p>You may want to ensure that certain resources always have the same default value for particular fields. I used this recently when I wanted to set the value of <span class="inline_code">content-type</span> to <span class="inline_code">application/pdf</span> by default. I saw this as a must-have feature, rather than a nice-to-have, because one of the main ongoing actions of editors of this site was to add new PDF documents, the links to which would then be displayed by a snippet in various parts of the site.</p>
<p>Incidentally, this only made sense if I could make sure that the resources in question had a specific default template, so I also used my own plugin to automatically set the template for these resources. I didn&#8217;t realize at the time, but I probably could have used an MM rule for that too, namely <span class="inline_code">mm_hideTemplates</span> (see below).</p>
<h3>Renaming Fields</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_renameField('longtitle','Page Heading');</div></div>
<p>Renaming fields changes their labels. One way that I used this was to change &#8220;Long title&#8221; to &#8220;Page heading,&#8221; because that&#8217;s how I was using <span class="inline_code">[*longtitle*]</span>, i.e. as the &lt;h1&gt; heading (in other words, in the relevant chunk I had <span class="inline_code">&lt;h1&gt;[*longtitle*]&lt;/h1&gt;</span>). Changing the label just made it clearer for users. The flexibility of MODx means that, by default, fields are named in a fairly abstract way, because you can use them however you want, so more meaningful labels are often better, once you&#8217;ve settled on how you&#8217;re going to use them.</p>
<h3>Changing the Help Text</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_changeFieldHelp('longtitle','This is the main heading that appears at the top of the main content. It\'s also the name that appears in navigation menus and links.');</div></div>
<p>This way you can help to tailor the user&#8217;s experience to the specific functionality of your implementation. If you&#8217;ve customized things to a great extent, some of the help text will begin to be useless or even misleading, so it&#8217;s good to keep things tight by paying attention to stuff like this.</p>
<h3>Synching Fields</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_synch_fields('pagetitle,menutitle,longtitle');</div></div>
<p>Use this to ensure that fields always have the same value. I haven&#8217;t used this myself, but I&#8217;m sure I will.</p>
<h3>Inheriting Values From the Parent Resource</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_inherit('pagetitle,longtitle');</div></div>
<p>Does what it says on the tin.</p>
<h3>Hiding Templates</h3>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mm_hideTemplates('0');</div></div>
<p>The above example removes the <span class="inline_code">(blank)</span> template from the <span class="inline_code">Uses Template</span> drop-down. As I noted above, it looks like I could have used this when I needed to set a default template by hiding all the other templates from the drop-down list, instead of using my own plugin. I haven&#8217;t tried it though.</p>
<h3>Tabs, Widgets and Sections</h3>
<p>There are also a number of functions for changing the tabs and sections. For example, if you want to restrict users to editing the content field and nothing else, hide the <span class="inline_code">Settings</span> tab as well as hiding fields in the <span class="inline_code">General</span> tab. Sections, by the way, are a MODx way of grouping fields together in the edit screen. Common ones you&#8217;ll see are &#8220;Resource content&#8221; and &#8220;Template variables.&#8221; As for widgets, ManagerManager provides a few functions for changing the widget that is rendered for a field, eg. colour-picker or image preview.</p>
<p></p>
<p>With careful combinations of rules, and any logic you fancy putting in the rules file, you can get as clever as you like.</p>
<p>For more information on ManagerManager have a look at the <a href="http://modxcms.com/forums/index.php/board,349.0.html">dedicated board on the MODx forum</a>.</p>
<p>For the next MODx-related post&#8230;I&#8217;m not sure. One thing I&#8217;ve found interesting: I struggled for a while to find a satisfying way of combining two requirements regarding javascript. 1) How to manage and maintain my javascript files easily and avoid any duplicated code; and 2) also ensure that the resulting page is optimized for speed (sometimes I find it quite hard to settle for a <a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow</a> grade of B). I&#8217;d love to see how other developers manage this in MODx.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/the-magical-modx-managermanager-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FoxyCart: Replacing A Cart Item</title>
		<link>http://www.moonbaseinternet.com/blog/foxycart-replacing-a-cart-item/</link>
		<comments>http://www.moonbaseinternet.com/blog/foxycart-replacing-a-cart-item/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:14:16 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[foxycart]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[shopping cart]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=658</guid>
		<description><![CDATA[function add_pre_process&#40;&#41; &#123;
&#160; &#160; //Find the id of the existing registration in the cart, if it does exist
&#160; &#160; $.each&#40;fc_json.products, function&#40;key, product&#41; &#123;
&#160; &#160; &#160; &#160; if&#40;product.name==&#34;Registration&#34;&#41; &#123;
&#160; &#160; &#160; &#160; &#160; &#160; // Do the remove request, with parameter quantity=0
&#160; &#160; &#160; &#160; &#160; &#160; $.ajax&#40;&#123;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; async: [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container javascript dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> add_pre_process<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Find the id of the existing registration in the cart, if it does exist</span><br />
&nbsp; &nbsp; $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>fc_json.<span style="color: #660066;">products</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">,</span> product<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>product.<span style="color: #000066;">name</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Registration&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Do the remove request, with parameter quantity=0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;https://mydomain.foxycart.com/cart?output=json&amp;cart=update&amp;id=&quot;</span><span style="color: #339933;">+</span>product.<span style="color: #660066;">id</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;quantity=0&amp;callback=?&quot;</span> <span style="color: #339933;">+</span> fc_AddSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Add the new one</span><br />
&nbsp; &nbsp; add_item<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> add_item<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Get the form data</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> submitted_data <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#signup&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//Do the add request</span><br />
&nbsp; &nbsp; $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;https://mydomain.foxycart.com/cart?&quot;</span><span style="color: #339933;">+</span>submitted_data<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;callback=?&quot;</span> <span style="color: #339933;">+</span> fc_AddSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This javascript/jQuery code gets the contents of your cart (which is in the variable fc_json, made available by foxycart_includes.js), removes any item whose name matches a certain string, and then adds your new item. It looks so obvious now, but it took a while for me to get it.</p>
<p>I&#8217;m working on a shopping cart at the moment, and it&#8217;s my first day with <a href="http://www.foxycart.com/" title="">FoxyCart</a>, which is a really nice solution for a common but pretty badly-catered-for requirement (ie. online shopping carts and checkouts). I wanted to just plug and play: just set up a few templates for the cart, checkout and email receipt, and go with that, because FoxyCart is pretty nice without too much customization. But things are rarely so simple. The website will be selling not only products in a shop, but registrations to an event. Yep, that&#8217;s still easy, but a registration can be for multiple attendees, and the registrant needs to fill in the same information about each of them as he did for himself, and some of that information determines the price.</p>
<p>So the registrant&#8217;s gone through the whole process of filling in the forms for each attendee, and they get to their registration summary page, and there&#8217;s a list of the names of the attendees with the cost for each one (which depends on what information was supplied, what boxes were ticked), and a grand total at the bottom. This is all before they get to the shopping cart. It&#8217;s true that when adding to the FoxyCart cart you can supply it with options and corresponding prices, and this would have been good for allowing for the selection of multiple attendees; but it wouldn&#8217;t have allowed for the entry of all the attendee-specific details and their corresponding prices.</p>
<h3>A Problem</h3>
<p>So they hit &#8220;Add to cart&#8221; and then &#8220;Checkout&#8221; and everything&#8217;s great &#8211; if that&#8217;s the only thing they do. But what if, after adding the registration to the cart, they go back and change the details for an attendee, thereby changing the price? First of all I set the quantity_max parameter to 1 to prevent them adding it twice. But if what you&#8217;re adding has a different price, it&#8217;s treated as a different item. If they click to update the cart with a registration that comes to a different price from the one they previously added, the amended registration is <i>added as a new product</i>, so that they now have two in the cart.</p>
<p>It seems odd that FoxyCart gets stuck on this, and I thought there must be some parameter I could use, but I couldn&#8217;t find it. The solution had to be to either somehow update the price of the item in the cart, or remove any registration in the cart before adding the amended one. I ended up using the latter. To do it requires JSON AJAX requests, which you can do in jQuery with $.getJSON or $.ajax. Anyway, I quickly arrived at the essential logic on which the above code is based. But I couldn&#8217;t get it to work.</p>
<p>I was led first of all to use the fc_PreProcess() function. From reading the documentation it seemed that I should define a function called fc_PreProcess, put all the code inside that, and then the included FoxyCart javascript file would find my function definition and execute it prior to adding anything to the cart. Sounds perfect, I thought.</p>
<p>Here&#8217;s how it didn&#8217;t work. You add a registration to the cart, close the cart, amend your registration so that it now has a new price, and then add to the cart again (although as far as the user is concerned they are <i>updating</i> the cart), at which point the new one should be substituted for the old. And at first it seemed to work: only one registration item in the cart, and with the new price too! I cheered at the time, until I clicked &#8220;checkout&#8221; to find that the item had just fallen out. And doing it all again I saw that in the cart itself the item would disappear if you refreshed it.</p>
<p>What seemed to be happening was that even though the item was displayed in the cart, it had since disappeared. The item was being removed <i>after it was added</i>; more precisely: a new one was added, making a total of two items; the cart was displayed; and then my code found and removed both items. I&#8217;m still not quite sure how this happened, but blame may lie in the asynchronous nature of the JSON calls, mixed use of http and https, sessions, or in my lack of sleep.</p>
<h3>A Solution</h3>
<p>So what you see above is the hand-made solution. The &#8220;add to cart&#8221; or &#8220;update cart&#8221; button on my registration summary page doesn&#8217;t submit the form, it just executes the function add_pre_process(), which looks for an existing registration and removes any it finds; and then adds the new one. There is a separate &#8220;View cart&#8221; button.</p>
<p>Ideally I would have liked to use the success callback of the ajax request in add_item(), but it doesn&#8217;t fire.</p>
<p>So, the problem seems to be solved, but not <i>properly</i> solved. The question now is do I spend time investigating what the problem was and delve deep into the workings of FoxyCart, or move on to the next stage, which is the shop. Well, I&#8217;ve got two websites going live in the first week of January, so it&#8217;s no contest. Onwards!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/foxycart-replacing-a-cart-item/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Development Frameworks: Developing For vs. Developing With</title>
		<link>http://www.moonbaseinternet.com/blog/web-development-frameworks-developing-for-vs-developing-with/</link>
		<comments>http://www.moonbaseinternet.com/blog/web-development-frameworks-developing-for-vs-developing-with/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 00:16:40 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=641</guid>
		<description><![CDATA[I&#8217;ve been hunting for a web development framework for a few months. Back in the summer I was immersed in CSS and javascript, just sticking with my tried and tested server-side techniques. Using the TinyButStrong (TBS) template class I could put together a highly organized dynamic website pretty quickly. In retrospect it seems that I&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been hunting for a web development framework for a few months. Back in the summer I was immersed in CSS and javascript, just sticking with my tried and tested server-side techniques. Using the TinyButStrong (TBS) template class I could put together a highly organized dynamic website pretty quickly. In retrospect it seems that I&#8217;d found my own path towards an MVC-like pattern: nothing but HTML and logic-less TBS tags in the templates; PHP pages acting like controllers, for form processing and manipulating data; and a class for each table in the database (more or less). Very neat. Framework junkies amongst you could tell me exactly why this isn&#8217;t really MVC, but I don&#8217;t care.</p>
<p>Anyway, my first intention was to stick with PHP, so I was led to have a look at the <a href="http://codeigniter.com/">CodeIgniter</a> framework after I watched a couple of <a href="http://net.tutsplus.com/videos/screencasts/codeigniter-from-scratch-day-1/">excellent tutorial screencasts</a> by Jeffrey Way on <a href="http://net.tutsplus.com">nettuts</a>. But then I discovered <a href="http://www.kohanaphp.com/">Kohana</a>, originally a fork of CodeIgniter but apparently better in several ways. Last time I checked, CodeIgniter was very PHP4-centric, whereas Kohana is most definitely a PHP5 beast, with all the OO stuff that entails.</p>
<p>I haven&#8217;t been able to use it in anger yet, but I&#8217;ve set a few things up with it, and it gives me a nice warm feeling. It seems really lean and simple and built in the right spirit, and it didn&#8217;t take me as long to get my head around the MVC pattern as I&#8217;d expected.</p>
<p>The thing is, now I find my thoughts drifting into alien territory&#8230;</p>
<p>This goes back to my <a href="http://www.moonbaseinternet.com/blog/web-development-and-chopping-garlic/">previous post</a> about web development choices. The more I look, the more confused I become. I wouldn&#8217;t consider anything Java or .NET, so in the area I&#8217;m looking at the big [puts on suit and pulls a sombre, earnest expression] <b>SERIOUS</b> frameworks seem to be <a href="http://rubyonrails.org/">Ruby on Rails</a> and <a href="http://www.djangoproject.com/">Django</a>. I&#8217;ve been trying out Python with the Google App Engine, and I forgot how great it was to learn a new programming language, so Django &#8211; a Python framework &#8211; looks like a good way to go. But something in me cries out NO &#8211; do I really need all that stuff? Look, there&#8217;s this guy over here says Django&#8217;s too big and bloated; but wait, there&#8217;s <i>that</i> guy over <i>there</i> says with Django he can spit out ten amazing websites every day.</p>
<p>But coalescing out of my confusion is the perception of a contrast in the community, and for those who build websites and web apps it&#8217;s good to be aware of this. On the one hand there are those whose overriding concerns arise from their work in creating and maintaining the frameworks themselves; and on the other hand there are those who just want to make websites. This became obvious to me after watching two video talks from DjangoCon 2008 (yes, I&#8217;m still catching up with all this), <a href="http://www.youtube.com/watch?v=fipFKyW2FA4">one by Mark Ramm</a>, one of the guys behind TurboGears (another Python framework), and the <a href="http://www.youtube.com/watch?v=A-S0tqpPga4">other by James Bennett</a>, one of the Django guys.</p>
<p>Now, I&#8217;m aware that the subjects of these talks were quite different, and pitched at different levels, but nevertheless I do think it&#8217;s fruitful to compare them.</p>
<p>Mark Ramm seemed most interested in guiding the philosophy of the Python community, about the future of Python frameworks and how they should be taken forward. In particular he criticized the &#8220;monolithic,&#8221; all-things-to-all-people approach of Django, opposing it to the Turbogears/Pylons approach, which is to open things up, to make it easy (even <i>necessary</i>) for developers to grab this bit here and that bit there and carefully craft an optimal whole. His standpoint reflected his immersion in developing <i>for</i> &#8211; or the development <i>of</i> &#8211; web app frameworks.</p>
<p>James Bennett&#8217;s focus was on developing <i>with</i> frameworks &#8211; that is, building web applications &#8211; rather than on how best to build the frameworks themselves. He talked about the most efficient ways to approach the development of an application using Django, for maximum code re-use and maintainability.</p>
<p>Of course, these are not implacably opposed positions: it&#8217;s just a difference of focus. Both may be right in their own ways, but as a freelance developer of &#8211; currently &#8211; small to medium websites, I naturally find James Bennett&#8217;s focus on the day-to-day business of making a web app much more appealing.</p>
<p>It might be true, as Mark Ramm says, that you don&#8217;t get perfection by installing everything in one bundle and just running with it, but to me that&#8217;s rather academic. Everyone is agreed that the purpose of frameworks is to free us from the boring repetitive tasks of this line of work. We shouldn&#8217;t have to even <i>think</i> about admin interfaces, form-handling, nice URLs, templating, or ORM data-mapping. But further, I just want <i>some one thing</i> that does all that pretty well. If I have to pick and choose between different combinations, and try to get all the bits working nicely together, then I&#8217;m <i>thinking</i> about it: I&#8217;m wasting my time. I don&#8217;t want to think about the optimal key set-up of a saxophone &#8211; I just want to make music (is that a cheesy analogy?)</p>
<p>Before I realized this I struggled to stay a course through the choices facing me, taken first in one direction and then another, each with its own passionate and persuasive adherents. But now, even if the two approaches I&#8217;ve perceived are just sides of the same coin, I can use this idea of a dichotomy to sort and prioritize the opinions I find.</p>
<p>However, I now find myself considering having a go at building a web app with Haskell, a functional programming language beloved of geniuses, hippies, mad scientists and my good friend <a href="http://miremare.wordpress.com/">Paul Keir</a> (who might fall in all three of those categories). The introductory message at <a href="http://www.haskell.org/">haskell.org</a> has the words ADVANCED, PURE, CUTTING EDGE, RESEARCH, CORRECT, and PARALLELISM (eh?). That&#8217;s all a bit scary to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/web-development-frameworks-developing-for-vs-developing-with/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>I Undressed Her by Mistake</title>
		<link>http://www.moonbaseinternet.com/blog/i-undressed-her-by-mistake/</link>
		<comments>http://www.moonbaseinternet.com/blog/i-undressed-her-by-mistake/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 15:21:03 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[mind]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=636</guid>
		<description><![CDATA[Freud&#8217;s Psychopathology of Everyday Life reads a lot like today&#8217;s popular science books. In particular it reminds me of Musicophilia by Oliver Sacks, with its conversational style.
Much of the pleasure is the spectacle of all these Viennese doctors revelling in the exciting new theories of psychoanalysis, sharing their little anecdotes. Writing about inadvertent actions and [...]]]></description>
			<content:encoded><![CDATA[<p>Freud&#8217;s <i>Psychopathology of Everyday Life</i> reads a lot like today&#8217;s popular science books. In particular it reminds me of <i>Musicophilia</i> by Oliver Sacks, with its conversational style.</p>
<p>Much of the pleasure is the spectacle of all these Viennese doctors revelling in the exciting new theories of psychoanalysis, sharing their little anecdotes. Writing about inadvertent actions and how they can reveal unconscious motives, he quotes another psychologist:</p>
<p>&#8220;I entered someone&#8217;s home, and gave the lady of the house my right hand. Oddly enough, in the process I untied the bow holding her loose morning dress together. I was not aware of any dishonourable intentions, yet I had performed this unskilful movement with a conjuror&#8217;s sleight of hand.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/i-undressed-her-by-mistake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chemicals and Complexes</title>
		<link>http://www.moonbaseinternet.com/blog/chemicals-and-complexes/</link>
		<comments>http://www.moonbaseinternet.com/blog/chemicals-and-complexes/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 21:00:09 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[mind]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=617</guid>
		<description><![CDATA[As I wrote in the last post, I&#8217;m a tangle of complexes. Why didn&#8217;t I know this before? Lately I&#8217;ve been examining how my own self-awareness has changed over the years. I suppose you could call this self-awareness-awareness.
For years I would sometimes have bad moods of a particular kind, and during those moods my thoughts [...]]]></description>
			<content:encoded><![CDATA[<p>As I wrote in the last post, I&#8217;m a tangle of complexes. Why didn&#8217;t I know this before? Lately I&#8217;ve been examining how my own self-awareness has changed over the years. I suppose you could call this self-awareness-awareness.</p>
<p>For years I would sometimes have bad moods of a particular kind, and during those moods my thoughts would turn to violence. Sometimes while walking in town on my way to or from work I would slip into a self-righteous rage, but lacking a very good reason for it I would fantasize about people offending me more than anyone in fact <i>was</i> doing, and about what I would do to them if this happened (normally involving a beating of some kind, but nothing so bad as murder or the inflicting of permanent injuries).</p>
<p>Occasionally I would get a nasty look from a driver as I crossed a road too slowly for their liking, and that would set me off on an internal rant about arrogant BMW drivers. I would imagine that they had been much more obnoxious than they had been, and fantasize about causing damage to their car by kicking it or launching my umbrella, like a javelin, through the back window as he drove away.</p>
<p>It never occurred to me in those moments that my thoughts were unreasonable, and later, when I had calmed down, I would not think about it again. Such was my lack of self-awareness that I didn&#8217;t even begin to look for reasons, and thus missed the obvious. Over the past few years I have pinned down the cause of these moods: nicotine withdrawal. I felt those feelings when I hadn&#8217;t had a cigarette for a while.</p>
<p>The realization began when I gave up and used nicotine gum as a replacement, after initial scepticism about its efficacy. Varying the amount of gum I chewed in one day, I began to see how my moods were changing. It&#8217;s old news, but I had not appreciated, or not <i>believed</i>, that my addiction was mainly chemical. I imagined that I somehow transcended chemistry, controlling my moods and behaviour with conscious mastery, that until then I had <i>chosen</i> to keep on smoking, free of any base animal influences.*</p>
<p>I honestly never understood what people meant when they talked about the effects of coffee or sugary foods. I thought that I was always in control, and I didn&#8217;t notice how my body and mind changed with the action of these substances. The main exception is alcohol, the effect of which is so overwhelming that it cannot be ignored even by me; but I suppose I always viewed it as something special, something extraordinary. I completely failed to notice the more subtle changes.</p>
<p>Now I&#8217;m reading Freud, and the explorations into my self continue. Not only does he reveal another hidden influence that I had never taken seriously, partly controlling my behaviour and thoughts, namely the unconscious mind; but this also prompts me to ask why I, normally an introspective and thoughtful person, would fail to see the obvious chemical agencies causing my mood swings. And this leads me to the idea that there is some combination of complexes within me that obliges me to ignore the evidence. For some reason, I do not want to face the facts of my biology. Related to this is my complete lack of interest in epilepsy, despite the fact that 1. I have had it since adolescence, and 2. I am normally very interested in neuroscience.</p>
<p>Before reading <i>The Psychopathology of Everyday Life</i> I was quite unfamiliar with Freud, except for the more or less vague references that appear throughout our culture. I had read an excerpt from <i>Civilization and Its Discontents</i>, and I was fascinated by it, but I didn&#8217;t really understand it because all the theory was out of context.</p>
<p>The honesty and humanity of the man shine through in his writing, and he has pretty much won me over. It was just the same with <a href="http://en.wikipedia.org/wiki/Ernst_Gombrich">Ernst Gombrich</a> and <a href="http://en.wikipedia.org/wiki/Jacob_Bronowski">Jacob Bronowski</a>. The experience of reading Freud is similar, because of the serious, unpatronizing, liberal and rational attitudes that they all share.</p>
<p>Over the past few days I have bashed my hand on a particular door handle in my flat, on two separate occasions, never having done it before. Wasn&#8217;t it just simple clumsiness? I do sometimes have difficulty resisting the temptation to pronounce &#8220;oh come on Sigmund, that&#8217;s a bit far-fetched,&#8221; but on the whole I&#8217;m beginning to appreciate how great he was, and I plan to go into this more in later posts.</p>
<p></p>
<p>
*Another surprising thing I discovered when I began to chew nicotine gum was that the dominant taste in cigarettes, and the slight feeling of burning in your mouth, is not, as I had presumed, from the hot smoke. It is the <i>nicotine itself.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/chemicals-and-complexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Development and Chopping Garlic</title>
		<link>http://www.moonbaseinternet.com/blog/web-development-and-chopping-garlic/</link>
		<comments>http://www.moonbaseinternet.com/blog/web-development-and-chopping-garlic/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 23:59:14 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[content management]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[freud]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[garlic]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[modx]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[paradigms]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sweaty]]></category>
		<category><![CDATA[tinybutstrong]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=571</guid>
		<description><![CDATA[For this post it was a toss-up between:
1. My observations on Freud&#8217;s Psychopathology of Everyday Life (boiling down to my realization that I&#8217;m a tangle of complexes, but also that I&#8217;m actually doing alright and won&#8217;t be running to an analyst any time soon)
2. A vague and geeky ramble over the broken, scarred and unstable [...]]]></description>
			<content:encoded><![CDATA[<p>For this post it was a toss-up between:</p>
<p>1. My observations on Freud&#8217;s <i>Psychopathology of Everyday Life</i> (boiling down to my realization that I&#8217;m a tangle of complexes, but also that I&#8217;m actually doing alright and won&#8217;t be running to an analyst any time soon)</p>
<p>2. A vague and geeky ramble over the broken, scarred and unstable terrain of web development.</p>
<p>Since moving this blog over to my website, I&#8217;m conscious I may be losing those who enjoyed such posts as <a href="http://www.moonbaseinternet.com/blog/sweaty-rectangle/">Sweaty Rectangle</a> and <a href="http://www.moonbaseinternet.com/blog/my-25-year-old-earworm/">My 25-year-old Earworm</a>, but the geeky ramble won out this time. Bear with me though: I am large, I contain multitudes.</p>
<p>Though I&#8217;ve been doing web development off and on for ten years, I&#8217;ve never been as enthusiastic about it as I am now, having begun several months ago to work for myself. After a couple of years gripped by saxophone and camera obsessions, I&#8217;ve now succeeded in bringing my web knowledge up-to-date, and it&#8217;s dawning on me how many choices I have about which path to follow. Faced with these I ask myself:  what is it that drives my enthusiasm for web development, and how should that influence my choices?</p>
<p>With quite a few projects on the go or about to start, recently I&#8217;ve been having to choose between different tools. If we assume that all these tools are, potentially, equally powerful, still there are other considerations beyond economics, development time and learning time. There is the consideration of how much a particular tool fits well in my hand and allows me to work as well as I can, that is to say, allows me to <i>enjoy</i> my work. But I&#8217;m getting ahead of myself&#8230;</p>
<h3>Guided by Mother Microsoft</h3>
<p>In 1998 I started out with classic ASP, and just when I&#8217;d built up a nice collection of functions and snippets and settled down to an efficient way of working, ASP.NET came along. I&#8217;d like to say that it rocked my world, but it was more like upsetting the apple cart. It all seemed so unnecessary, so restrictive, so complicated, yet so unavoidable for a web developer using Microsoft. I didn&#8217;t really get it. True, I did some cool stuff, such as a system combining a Windows mobile app and a web app, with MS Exchange integration and XML web services and signature capture and GPRS and all that &#8211; but I was never comfortable with the framework. I yearned to get back to the freedom of scripting with notepad, without all the junk.</p>
<p>Now I won&#8217;t claim that my distaste for .NET was purely technical or aesthetic: for me it still has associations of the corporate world that I&#8217;m very glad to have left. It always represented a straightjacket to me.</p>
<h3>Personal Home Page, I mean, PHP: Hypertext Preprocessor</h3>
<p>So when I discovered PHP in my spare time a year or two ago, I smelled the fresh clean air of freedom.*</p>
<p>But things were pretty messy to begin with. Seeking more efficiency and tidiness, but repulsed by the baggage and complexity of many of the feature-laden templating engines and CMSs (not only sledgehammers to crack nuts, but sledgehammers that are very difficult to hold and which fall apart for no apparent reason if you don&#8217;t hold them in a certain way), I began using a templating system called <a href="http://www.tinybutstrong.com/">TinyButStrong</a>. I was very happy with that (and I&#8217;m still very fond of it) until a few months ago, when I began to pay more attention to all the web technologies that were popping up (or which had popped up without my noticing.)</p>
<h3>Coming of Age</h3>
<p>In my work I was being faced with the same tedious tasks again and again, such as forms and validation, administration interfaces, and content management; and coming from ASP.NET I knew that there were tools out there that would help me with all that, that there had been a whole movement towards frameworks going on for years, which aimed at relieving developers of all the hassle.</p>
<p>However, my priority was getting my front-end skills up-to-speed with the bleeding edge of CSS, javascript frameworks, AJAX and so on, so until quite recently I carried on as before with the PHP. But now all of a sudden I&#8217;m working with (or at least playing with) MODx, Kohana, Wordpress and now Python and Google App Engine.</p>
<p>I&#8217;m using the <a href="http://modxcms.com/">MODx</a> content management system for something right now, and it&#8217;s superb. For building websites it&#8217;s quick, flexible, limitlessly customizable, and I have almost nothing but praise for it so far. But sometimes it just doesn&#8217;t feel like real development. If you&#8217;re a coder, you write plain old text in some fancy version of Notepad (or even Notepad itself), and there&#8217;s something about having to use a CMS interface that is alienating. Although I can set things up in MODx so that I&#8217;m using include files, I still feel removed from the PHP code, the HTML and the CSS.</p>
<p>As for <a href="http://wordpress.org/">Wordpress</a>, it&#8217;s great, but I don&#8217;t feel like I&#8217;m <i>building</i> something, more <i>hacking</i> something together.</p>
<h3>Clients</h3>
<p>As an aside I should say that clients don&#8217;t care about all this, and neither should they. I&#8217;ll continue to use MODx and Wordpress because of the convenience and speed of developing with them, and for the easy content management they provide for clients. But no, what I&#8217;m on about here is how it feels to use these tools, and hence about how I can achieve a harmony between my instinctual way of working and the jobs I have to do.</p>
<p>Oh and as it seems to be the fashion these days for web developers to proudly proclaim &#8220;I love my clients,&#8221; I&#8217;d better point out right now that I love my clients. I do, really.</p>
<h3>I&#8217;m a GAEboy</h3>
<p>So I&#8217;m strongly drawn to, rather than CMSs, <i>frameworks</i> and new <i>languages</i>. I&#8217;ve recently been seduced by the <a href="http://www.kohanaphp.com/">Kohana PHP framework</a>, and by Python on <a href="http://code.google.com/appengine/">Google App Engine</a>, and they do satisfy my desire for control over, and intimacy with, the code that makes up a site or application. Kohana because for me it&#8217;s an introduction to the MVC paradigm, and simplifies those horrible tasks I referred to above; and Python with GAE because not only am I learning a real proper all-purpose language, but I&#8217;m entering the world of cloud computing and non-relational datastores, leaving the world of server configuration, architectural compromises and unwieldy file structures. Oh and there&#8217;s the <i>one-click deployment</i>.</p>
<p>The question is, what&#8217;s the best path to take? But it&#8217;s mostly a rhetorical question. Obviously only time will tell. But the conclusion I&#8217;m tentatively driving at is that even if the toolbox I choose might not be full of explicitly labour-saving gadgets, I will end up working more efficiently if they feel better in my hands. My girlfriend Laura has a little wheeled gadget to chop garlic. I like using a good sharp heavy knife. For me, it just feels <i>right</i>. I believe that little things like this are important.</p>
<p>Now, if I can actually find the time to get something up and running on GAE beyond <a href="http://code.google.com/appengine/docs/python/gettingstarted/">this tutorial</a>; and if the project manager in me (who is admittedly quite ineffectual) can resist the temptations of MODx and Wordpress for my next big website project, and choose Kohana instead; well, maybe then I&#8217;ll be in a better position to answer all these questions with something other than waffle.</p>
<p></p>
<p>*Incidentally, I happened upon a fight between the .NET and PHP tribes in the comments of a .NET tutorial on <a href="http://net.tutsplus.com/">nettuts</a>. One of the comments was &#8220;PHP is ok for your Mum&#8217;s embroidery page or a pointless blog that nobody will read, but if you want to be taken seriously by Corporation X, then it&#8217;s got to be .NET&#8221; (I&#8217;m radically paraphrasing, but he did use the term &#8216;Corporation X&#8217;). I didn&#8217;t reply to him because I had nothing to contribute relating to the tutorial, but I did feel like saying, well, yes, if your ambition in life is to work for Corporation X then perhaps .NET <i>is</i> the way to go. For the rest of us, PHP is just fine, thanks. That probably would&#8217;ve been childish.</p>
<p></p>
<p>
UPDATE: I should point out that ASP.NET has come a long way since I used it. Specifically there is ASP.NET MVC, which I gather is a vast improvement on Web Forms, which I really didn&#8217;t take to, to put it mildly. Now I think about it, I was very happy using .NET for Windows and mobile development. So maybe ASP.NET is worth a look now that it&#8217;s possible to avoid Web Forms. These days there are some nice free development tools available, and you can even use Python. However, I&#8217;m having difficulty enough with the choices I have so I don&#8217;t want to complicate matters.</p>
<p>ANOTHER UPDATE (Jan 2010): Never mind Kohana, I&#8217;m moving straight to <a href="http://www.djangoproject.com/">Django!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/web-development-and-chopping-garlic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Work</title>
		<link>http://www.moonbaseinternet.com/blog/new-work/</link>
		<comments>http://www.moonbaseinternet.com/blog/new-work/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:11:04 +0000</pubDate>
		<dc:creator>Alistair Robinson</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[fixed]]></category>
		<category><![CDATA[fluid]]></category>
		<category><![CDATA[golfworldsoldest.co.uk]]></category>
		<category><![CDATA[graphael]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[photograph]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.moonbaseinternet.com/blog/?p=548</guid>
		<description><![CDATA[
This is a taster of what&#8217;s to come in a few weeks. I&#8217;m building this website, for the Scottish Golf Heritage Festival, with an array of incredibly useful components and features: I&#8217;m using the MODx content management system, FoxyCart for an integrated shop and registration process, and a wealth of snazzy (I&#8217;m certain I can [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.golfworldsoldest.co.uk"><img src="http://www.moonbaseinternet.com/blog/wp-content/uploads/2009/11/screenshot_golfworldsoldest_collage.png" alt="golfworldsoldest.co.uk screenshots" title="golfworldsoldest.co.uk" width="315" height="401" class="alignnone size-full wp-image-549" /></a></p>
<p>This is a taster of what&#8217;s to come in a few weeks. I&#8217;m building this website, for the Scottish Golf Heritage Festival, with an array of incredibly useful components and features: I&#8217;m using the MODx content management system, FoxyCart for an integrated shop and registration process, and a wealth of snazzy (I&#8217;m certain I can make that word cool again) rich interface components. I&#8217;m particularly looking forward to building the graphing functionality for the admin system, for which I&#8217;m probably going to use the <a href="http://g.raphaeljs.com/">gRaphael</a> javascript library.</p>
<p><a href="http://www.golfworldsoldest.co.uk">The holding page</a>, two screenshots of which are shown above, is the result of a lot of work in establishing the general layout and style of the forthcoming site. It combines several approaches to web design, having elements of both fixed and fluid styles. Using the background photograph effectively was quite a challenge. It would probably be fruitful to break down the CSS and go through it here, but maybe next time. Ciao!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moonbaseinternet.com/blog/new-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
