Album Slugs
Overview
Notes on the implementation of slugs—specifically for classes derived from the album_class—in the "littled" CMS system.
Workflow
Back-end
- Include
/scripts/littled/gallery.json the page. - Within the record editing form, add a hidden input to pass along the class name to the AJAX script:
<input type="hidden" name="type" value="<?=get_class($input) ?>" />
- On the record editing page, add handlers for the title and slug form inputs:
$(document).ready(function() {
<? if ($input->id->value>0): ?>
$('#pages-<?=$input->id->value?>').galleries('retrieveGallery');
<? else: ?>
$('input[name="<?=$input->title->param?>"]').galleries('bindSlugWatch');
<? endif; ?>
$('input[name="<?=$input->slug->param?>"]').galleries('bindSlugWatch');
$('.image-upload-container').galleries('bindImageOverlayHandlers');
});
Overriding the default "title" property
In some cases the record doesn't use the default album_class property ($title) to generate the slug.
The form input selector can be overridden using the options argument to $.listings('bindSlugWatch'). This needs to be done for both the "title" and the "slug" form input.
$('input[name="<?=$input->code->param ?>"]').galleries('bindSlugWatch', {
edit: {
id_param: '<?=$input->id->param ?>',
title_param: '<?=$input->code->param ?>',
slug_param: '<?=$input->slug->param ?>'
}
});
The derived class must override the album_class::collect_slug_input() to collect the values for the appropriate properties.
class DerivedClass extends album_class
{
/**
* Override of album_class::collect_slug_input() to collect input for the
* $code property instead of the album_class's $title property.
*/
public function collect_slug_input()
{
$this->title = &$this->code;
parent::collect_slug_input();
}
Front-end
- Add rule to .htaccess for the content type.
The example here accommodatesISAPI_Rewrite3functionality. It could be written more intuitively for an Apache server.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(characters|garden|sketchbook|storage)(.*) /$1/details.php [L,NC]
Apache version. The first two lines test if the requested URI is a physical file on the server. The 3rd line skips the following RewriteRules if it is a physical file. ([S=2] where 2 is the number of lines to skip.) The following two lines handle the slug redirects.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [S=2]
RewriteRule ^characters(.*) /characters/ [L,NC]
RewriteRule ^sketchbooks(.*) /sketchbooks/ [L,NC]
Examples
- littledamien.com: Characters CMS (borrowing most of its functionality from the shared
album_classresources. - littledamien.com: Garden CMS (overriding the default source of the slug (using "common name" instead of "album title"))
- littledamien.com: Storage CMS (overriding the default source of the slug (using "package code" instead of "album title"))
- littledamien.com: Sketchbook CMS (borrowing most of its functionality from the shared
album_classresources. - damienjay.com: Comics CMS implemented on the front-end also
- damienjay.com: Sketchbooks CMS