Codeistry

Archive for the ‘Technical’ Category

MODx Snippet: New version of Wayfinder

Wednesday, January 7th, 2009

Good news everyone! During my development travails, I’ve created an updated version of Wayfinder that fixes two issues and adds two handy new features!

Fixes

I’ve incorporated this fix which makes the hereClass work properly with weblinks in the menu and I’ve fixed the SQL query to work around the MySQL 5.0.51 sorting bug.

New Features

lastRowTpl

I’ve also added a new parameter called lastRowTpl which allows you specify a chunk to be used for the last menu item output. It works the same way as all the other wayfinder tpl’s and defaults to using rowTpl is it isn’t specified.

It’s very useful for little menu’s that currently look like this if you do them with Wayfinder:

item1 | item2 | item3 | lastitem |

and should look like this:

item1 | item2 | item3 | lastitem

Odd & Even classes

Finally, I’ve added support for even & odd classes on rows. These work like all the other wayfinder classes – you specify a class name in the parameter and this will be added to the wf.classes placeholder. These ones are only output on the appropriate rows, though – and you don’t have to specify both if you don’t want to – it’ll still work with just one.

These are really useful for menu’s which are supposed to be stripey, with every other item a different colour.

To implement this, I’ve modified both Wayfinder files. You can download the new versions from here (.zip) or here (.tar.gz).

I’m using these on live sites, because I’m a crazy fool, but if we can get some more testing from everyone, maybe this can be added to the repository as a new version and maybe then into the main MODx distribution, so that everyone can share the love.

What do you think – let me know in the MODx forum thread.

New version of MODx CMS out – 0.9.6.3

Sunday, January 4th, 2009

Another pretty sizeable release, despite the small version increment. There are over 100 changes but my personal highlights from the changelog are:

  • Updated AjaxSearch to version 1.8.1
  • Update eForm to version 1.4.4.5
  • Update Jot to version 1.1.4
  • Duplicate TV associations when duplicating a template
  • Allow ‘.’,'-’,’ ‘ and ‘_’ in TV names
  • Amend the top username link to explicitly state a ‘change password’ link instead of just linking the username
  • Added database version to MySQL DBAPI class and to the System Information report
  • File manager can now handle files with illegal url characters (added urlencode escaping).

The latest version of MODx can be downloaded here.

Flexible working

Saturday, December 20th, 2008

Looking down Jones Street, San Francisco, towards Alcatraz islandI’ve been working from San Francisco, CA this week, as opposed to my normal Birmingham, UK. My wife was attending the ASCB conference here, so we decided to make a holiday of it and come together.

Unfortunately, there hasn’t been as much holiday as we’d hoped – as I’ve suddenly got more work than expected – but for me, it’s proved to be a very useful and successful experiment in flexible working.

While I’ve been sitting in our apartment on Sutter Street, I’ve been continuing some web development work for clients in Memphis, TN & done some consulting for a client in London, followed up with a transatlantic training session via Skype.

My wife had a job interview in beautiful and (unusually) snowy Vancouver after the conference, so we spent a day there too. I ended up doing a couple of hours work there, including a Skype call to Memphis, all on my little laptop – which I bought last time I was in Vancouver.

Back in San Francisco now for a few days of proper holiday and then back to the UK for Christmas Eve – it’s been a pretty busy couple of weeks!

Tools for flexible working

There were a load of bits of software that helped to make seamlessly working on the road possible, even easy. My laptop is a HP NC6400 that’s been upgraded to 4Gb of Ram and runs the excellent Ubuntu Linux (Intrepid 8.10). This setup is easily capable of running a full LAMP stack, so I can develop websites on the go. I generally use gedit for code editing, setup basically like textmate as explained here, minus the ruby specific bits.

Screenshot of SpiderOak window, showing device list.I keep a copy of everything – the contents of my /home folders from my desktop and laptop – in the cloud using SpiderOak. This means that I have rolling versioned backups of everything, automatically kept, all the time – this is very handy on its own. It also means that I can download anything from any of my computers, wherever I am, given internet access. This is very useful when you’re away from home, as you know that you can’t really forget anything – if it’s available on your desktop PC at home, then you can access it via SpiderOak.

As a last resort, Ubuntu ships with remote desktop support built in, so I can also just connect to my desktop PC over the internet and use it like I was at home, albeit rather slowly.

I also use Basecamp for project management which means that my clients and I can manage projects together and keep in touch, wherever I happen to be.

Those are the bits of software that really shone on this trip – but all the other little ones that I use everyday, most of which are open source, were also just as useful as they always are: gmail, pidgin/empathy, dropbox, firefox + firebug, tomboy, GnoTime, bazaar, etc…

MODx Snippet: ChunkIf

Friday, November 28th, 2008

Ages ago, I wrote a MODx snippet called ChunkIf and I thought it was about time that I shared it with the MODx community. ChunkIf allows you to choose which of two chunks gets output, based on a template variable being set or not; its not big or clever but I find it useful and hopefully you might do, too.

The long form of the snippet call looks like this:

[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` &falseChunk=`chunkname`  &debug=`1|0` ]]

The parameters to the snippet call work like this:

&tv
This is the name of the template variable you want to test. The value of this variable will be checked and if it’s not empty or blank, &trueChunk will be output – otherwise &falseChunk will be.
&trueChunk
The name of the chunk who’s content you want output, in the event that your template variable (&tv) has a value.
&falseChunk
The name of the chunk who’s content you want output, if your template variable (&tv) is empty. If you omit this parameter, an empty string will be output if &tv is empty.
&debug
Set this to 1 to emit debugging comments into the HTML output; set it to 0 or leave it out to switch off.

There is a short version too:

[[ChunkIf? &tv=`tvname` ]]

The shorthand form attempts to output the contents of a chunk with the same name as &tv, if &tv is set, or an empty string. If there’s no chunk with the same name, it also returns an empty string.

This shorthand version is very handy for switching chunks on and off using a single variable. As chunks can contain other chunks and snippet calls, you can use this to switch sidebars, footers and other complex bits of layout on and off on a per page basis, with a simple checkbox template variable.


<?php
	/*
		Version: 0.2
		Date: 21/07/2008
		Description:
			<strong>0.2</strong> Outputs the contents of the chunk passed in
			$trueChunk if the template variable passed in $tv is set (i.e. has a value).
			Otherwise outputs the contents of the $falseChunk chunk. Expects $tv to be the
			name of the Template Variable to test, and $trueChunk & $falseChunk to be names
			of chunks.

		eg:

		[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` &falseChunk=`chunkname` ]]
			- Long version outputs $trueChunk if $tv has a value, otherwise
			outputs $falseChunk.
		[[ChunkIf? &tv=`tvname` &trueChunk=`chunkname` ]]
			- This short version outputs an empty string if $tv has no value.
		[[ChunkIf? &tv=`tvname` ]]
			- This very short version attempts to output the contents of a chunk
			 with the same name as $tv
		[[ChunkIf? &tv=`tvname` &debug=`1` ]]
			- Switches on debugging output - output's HTML comments for debugging.

	*/

	// get tv name
	$tv = isset( $tv ) ? $tv : '';

	// get current page ID
	$id = isset( $id )? $id: $modx -> documentObject['id'];

	// Get the value of $tv
	$tvarray = $modx -> getTemplateVarOutput( $tv, $id );
	$value = ''.trim($tvarray[$tv]);

	if ($debug) {
		$dtmp = '<!--';
		$dtmp .= 'tv: '.$tv.', ';
		$dtmp .=  'id: '.$id.', ';
		$dtmp .=  'value: '.$value;
		$dtmp .=  '-->';

		echo $dtmp;
	}

	// Decide which chunk to return.
	if ($value == '') {
		// get chunk to return if $tv has no value
		$falseChunk = isset( $falseChunk )? $modx -> getChunk( $falseChunk ): '';
		return $falseChunk;
	} else {
		// get chunk to return if $tv has a value
		if (isset( $trueChunk ))
		{
			$trueChunk = $modx -> getChunk( $trueChunk );
		} else {
			// Attempt to get the chunk with the same name as $tv
			$trueChunk = $modx -> getChunk( $tv );
		}
		return $trueChunk;
	}
?>

New version of MODx CMS out – 0.9.6.2

Wednesday, September 17th, 2008

A new version of MODx has just been released – 0.9.6.2, with a whole bunch of fixes and updates. There have been loads of fixes and updates checked-in by the MODx team & the community since 0.9.6.1 and lots of code clean-up and multi-language fixes done.

See here for MODx forum announcement and here for the complete (long & technical) changelog.

I’ll be upgrading the Codeistry site over the next few days and and then rolling the update out to all client sites as soon as possible after that.

My highlights amongst the many changes are:

Allow weblinks to have summary (introtext) fields

Weblink documents can now have an introtext summary, like normal documents, which is quite handy.

Set the published status of duplicated documents to unpublished

When you duplicate a document, it will now be set to un-published. Previously it would copy the published status of the document that you were duplicating – which was almost never what you really wanted.

Updated @INHERIT TV command to see through un-published pages.

Template variables which inherit their values from their parent documents, will now do so even if their parent document isn’t published; this propagates down through the site structure.

Added a manager role for emptying the trash/permanently purging docs

There’s now a manager role for permanently deleting documents which is handy in setups with lots of users.

Added plugin to show image previews in the manager for Image TVs

Screenshot showing Template variable Image plugin working.Really nice feature which shows you a thumbnail preview of the image being used by a template variable while you’re editing the page.

TinyMCE 3.1.0.1a and MCPUCK file browser improvements

This is great – the document content editor component has been updated to the latest version – which saves me from doing it on every install. This newer version of the editor is a big improvement on the previous one shipped with MODx 0.9.6.1

Updated ‘built-in’ snippets:

  • Updated Jot snippet to version 1.1.3
  • Updated Breadcrumbs snippet to 1.0.1
  • Update AjaxSearch to 1.7.1 and Search Highlighting plugin to 1.2.0.2
  • Update Ditto/Reflect to version 2.1
  • Migrated Mootools to 1.11

Patches to Ditto 2.1 to fix sorting and change default docs displayed number from 3 to “all”

Ditto will now display all documents it finds by default, instead on only the first 3, and sort order fixes for MySQL 5.0.31a

Added the ability to easily add custom help pages to the manager.

Screenshot of the help MODx manager help page, showing a new test tab.This really is simple – just create the HTML files in the /manager/help folder and they appear at tabs on the Help page. Neat – I’ll be taking advantage of this in due course.

Fix to alphabetical sorting in MCPUCK browser

Fix for sorting images alphabetically in the image browser. This now seems to work properly, the image browser sorts images alphabetically, making it much easier to use, especially if you’ve got lots of images in a folder.

Added XML doctype and header to MCPUK for file uploads

This should fix a very annoying error when uploading files via the resource browser, especially in Internet Explorer.

Added RSS Feeds of the Security Announcements and Important News to the Manager Login Welcome Page.

Screenshot on the new MODx Manager Welcome page, showing new RSS feed tabs.This is quite useful – it helps keep site administrators up to date with the latest MODx releases and security updates.

Fix ‘Allowed Days’ checkboxes for Manager users

These were previously the wrong way round – unchecked when they should have been checked, as I discovered the other day during a live demo.

Codeistry blog is proudly powered by WordPress Entries (RSS) and Comments (RSS).