I'm migrating from another gallery script where I created my own public image upload form. To prevent images with duplicate names from being uploaded, the upload script automatically added "date_" to the filename when saving it.
So I have 600 images named like this: 1160345185-IMG_1439.jpg
I want to keep the image names the way they are, and to keep using my upload form so the pubic (private website) can continue uploading images.
However, I want zenphoto to exclude the "date_" from the filename when displaying it.
I'm trying to implement this script in there to remove only read what's after the underscore:
`$imgname = substr(strrchr('$actualfilename', "_"), 1); echo $imgname;`
(
http://www.php.net/strrchr )
When implementing this, it would be great to not have to replace every "`<?php echo getImageTitle();?>`" in all the zenphoto files...
In order to accomplish that, it appears I need to use this with the getImageTitle() function on line 430 of template-functions.php, but I'm not sure exactly how it should be used.
Actual code before changes:
`
function getImageTitle() {
if(!in_context(ZP_IMAGE)) return false;
global $_zp_current_image;
return $_zp_current_image->getTitle();
}
`
Here's my guess. Code with my changes:
`
function getImageTitle() {
if(!in_context(ZP_IMAGE)) return false;
global $_zp_current_image;
$new-filename = substr(strrchr('$_zp_current_image, "_"), 1);
return $new-filename->getTitle();
}
`
(< average PHP knowledge, so...)
Thanks in advance for your help!
... and super thanks to zenphoto for the only decent, not-bloated gallery software!
Comments
I would use `substr_replace(substr(getImageTitle(true),15), "",-4)`. Skips the first 15 characters of the datestamp and then deletes the last 4 for the ".jpg". (If you want the .jpg to be shown write only `substr(getImageTitle(true),15)`)
and your filename should read "1439" instead of "1160345185-IMG_1439.jpg"
You can do this with a texteditor like TextWrangler (Mac) for all theme files at once. Not that much work.
There's not many getImageTitle functions on my theme either, however when searching the zenphoto directory there was like a thousand... I guess those aren't being displayed anywhere then.
That looks promising, I'll try it out (except the 15 part - only a few images start with IMG_ or DSC_). Also, thanks for the .jpg part, I hadn't really thought about doing that.
`function getImageTitleStripped() {
$imgname = substr(strrchr(getImageTitle(), "_"), 1);
return $imgname;
}`
Or, with the change comming up in the SVN, you could just edit the IPTC data in your images to put the title you want displayed in the heading tag. Then it does not matter what the name of the file is.
Tries that, at least with one image, still doesn't work. Maybe I have to delete the image completely..
that didn't work either...
Everything still works, but nothing changes in the filenames...
Editing meta data would be a nice solution, except theres 600+ pictures, and people still add pictures.
It doesn't make since.
Oh well, since this isn't necessarily zenphoto-specific I guess I'd better look elsewhere.
Thanks for your help
Simple answer: I created my own getImageTitle function with the modifications:
(template-functions.php)
`
function getImageTitle() {
if(!in_context(ZP_IMAGE)) return false;
global $_zp_current_image;
return $_zp_current_image->getTitle();
}
function getImageTitleStripped() { //mine
$imgname = substr(getImageTitle(true),11);
return $imgname;
}
`
HOWEVER, on themes/image.php, the image name is displayed using the function below that: printImageTitle(true); (I was changing it to getImageTitle)
So I created a function for that:
(template-functions.php)
`
function printImageTitle($editable=false) {
global $_zp_current_image;
if ($editable && zp_loggedin()) {
echo "
echo "initEditableTitle('imageTitleEditable');";
} else {
echo htmlspecialchars(getImageTitle());
}
}
function printImageTitleStripped($editable=false) { //mine
global $_zp_current_image;
$imageName = substr(getImageTitle(true),11);
if ($editable && zp_loggedin()) {
echo "
echo "initEditableTitle('imageTitleEditable');";
} else {
echo htmlspecialchars(getImageTitle());
}
}
`
Thanks for all your help!