README:
MP - minimalist photo gallery
Very simple photo gallery for a personal website.
This script is a total hack, but, it shows off two things.
First, it is a usable application to manage your small photo gallery.
Second, it uses a tiny "oo cms" class that can be used
to turn any regular HTML site into a CMS-managed site
without too much effort.
It lacks many functions, but, it was pretty nice
so I figured it could "compete" with some of the code
already out there. It's not meant for non-programmers,
but, you might learn something by using it.
----------------------------------------------------------
This code is released without any warranty, or even
quality control. It's public domain.
This is version 0. New versions will come out over time,
as the foundation class improves.
----------------------------------------------------------
To install and use this software, unpack the archive
into its own directory. Do something (like use an
.htaccess file) to add passwords to the cms directory.
Then, change the file permissions on gallery/ to allow
the server to write files into there.
The CMS is in cms/index.php
The gallery page is index.php.
To add a photo, do this:
cms/index.php
click on Add Photo
click on the photo's name, "photo.1".
click on edit.
upload a photo that's not too big.
type in a caption.
click on save.
that's it!
You can click on Home or Gallery to return to the respective indexes.
There is no delete feature yet. To delete, you have to go and
delete the file from the server via FTP or the shell.
If you want to edit your image, upload a new one. If you
just want to alter the caption, do so, but don't re-upload
the image.
-----------------------------------------------------------
Overview for Programmers
j_oocms.inc.php are a few classes that help me to turn
html-style sites into CMS'd sites, via the traditional
server-side-include (or PHP include, which is what I use.)
The included application -- the gallery -- is a relatively
fancy use, because it creates new objects to be CMSd. Normally,
you don't do that. Normally, you take the text or graphic
that's supposed to turn into a "slot to include stuff in" and
replace it with code like "include(foo.html)".
What the CMS does is create that file, foo.html. It may contain
text, or some HTML that links to an image.
The CMS also does a little "revision control" by keeping old
versions of files. It won't keep every version, but it will keep
the last version of the day, and uses the date as the version
number. The version number becomes part of the file name, and
old versions are retained forever, or until you delete them.
The current version of the file is symlinked into "foo.html",
so the "include" always brings up the latest version.
How to CMS Some Text
Text is the easiest thing to manage. Here's how you do it.
Cut the text to be managed, and save it into a file in
a directory. Let's call it text/foo.txt.
In the page, replace the cut text with an include, like
<?include('text/foo.txt')?>
Create a new PHP file, foo.php. Next release, I'll include
sample code. For now, please look at the file photos.php.
This code below is untested.
foo.php:
<?php
include('j_oocms.inc.php');
$path = '../text';
$filename = 'foo.txt';
$state = $_REQUEST['state'];
$text = $_REQUEST['text'];
$cms = new Text( $path, $filename );
switch( $state )
{
case 'edit':
$cms->load();
$content = $cms->editForm();
break;
case 'save':
$version = $cms->save( $text );
$cms->export( $version );
refresh();
break;
default: // view
$content = $cms->load();
$content .= editButton();
$state = 'view';
break;
}
?>
<h1><?=$state?> <?=$filename?></h1>
<?=$content?>
--------------------------------------------------------
This code is your typical "controller". The $state
variable determines which of three actions we'll do.
The default action is to view the file foo.txt,
and load() simply returns the file. editButton() is
some HTML that will display an 'edit' button.
Clicks on the 'edit' button set the state to 'edit',
and that action displays a form to edit the file.
That HTML is created by editForm(). Note that we
had to load() the cms with the data first.
The edit form has a "save" button, and clicking on it
will save the data $text, via a call to save(). The
subsequent call to export() symlinks in the latest
version of the text. Then instead of displaying anything,
it refreshes the page back to the default view.
--------------------------------------------------------
You integrate this script into your back end, and
you will have a nice little CMS'd chunk of text on the
server.
--------------------------------------------------------
CMSing photos and other attachments is similar, though
more complex.
Before going on, I have to briefly describe two more classes.
Form is a web form. What it does is take arbitrary form data
and save it as a serialized file. This is useful for saving
form data.
Multi is a generic multimedia object. It is a Form with
file attachments. Multi includes a method, generateFile, which
applies templates to the form data, and generates extra files.
These files become new attachments. The template language is
PHP's string substitutions. Any value in the form can be used
like this - $htmlinputfieldname. URLs to the attached files
can be used the same way -- if a file in the form was named "gar",
then you link it in your template like this <img src="$gar">.
It's easy.
Multi attachments are all stored in versioned directories.
The $filename parameter in the construction is really the name
of the directory that will contain the attachments. The current
version of the Multi is symlinked into the directory. To make
sense of this, play with the sample app and see what files it
creates.
The Photo class is a refinement of a Multi. It works like Multi,
but generates a thumnail image as an extra attachment. It only
works with JPEG at this time.
-----------------------------------------------------------
The included application extends the Photo class by adding
code to manage a single directory into which we create many
Photo objects. (By definition, a photo gallery.)
The only "trick" we use is to attach a number to the end
of the directory name, so you have "photo.1" "photo.2" and
so on.
------------------------------------------------------------
Security
It's important to put a password on the CMS area, because,
the security hasn't been checked too hard.
Other Image Galleries Scripts: