View Full Version : PHP Photo Album script v2.0 help

08-06-2009, 09:40 PM
I was wondering how in the PHP Photo Album script v2.0 script if I can modify it to use the file names of the pictures as the photo description. I want to parse out the extension in the file names and simply use the names for all the photo descriptions. I looked at the php file and I know the file names are passed and I think the file is gets these paths and file names, but I can't seem to figure out how to parse them and assign them to the auto-generated description.

The DD files are located at http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

Thanks for your help

08-07-2009, 12:21 AM
Sure. This is untested, but should work. Inside ddphpalbum.js, find the lines below, and add to it the line in red:

var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
}) : ''
desc=(desc=="%filename")? albumvar.images[i][1].split('.')[0] : desc

Then, for a particular album, if you want the description to just be the filename of each image, inside its invocation code, do the following:

new phpimagealbum({
albumvar: myvacation, //ID of photo album to display (based on getpics.php?id=xxx)
dimensions: [3,2],
sortby: ["file", "asc"], //["file" or "date", "asc" or "desc"]
autodesc: "%filename", //Auto add a description beneath each picture? (use keyword %i for image position, %d for image date)
showsourceorder: true, //Show source order of each picture? (helpful during set up stage)
onphotoclick:function(thumbref, thumbindex, thumbfilename){
thumbnailviewer.loadimage(thumbref.src, "fit2screen")

08-07-2009, 12:25 AM
I have added the first if statment that is commented out at the beg of this function (this is only a partial copy of the function). the rest is the original code. I think it is getting the desc array values from the html file that is calling this function. I wanted to override the values and insert the name of the image. I put an alert on this.albumvar.images[i][1] so I know this is where the file name is housed. I want to take this and use it as the desc but get an error that says phpimagealbum is undefined. Please any suggestions would be appreciated.

function phpimagealbum(setting)
for (var i=0; i<this.albumvar.images.length; i++){

//if (this.albumvar.images[i][1])
//this.albumvar.desc[i]= this.albumvar.images[i][1]
//this.albumvar.desc[i]="no name found"
// }
if (this.albumvar.desc[i]) //if a manual desc exists for this image
this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc

08-07-2009, 12:26 AM
Thank you I will try it.

08-07-2009, 12:36 AM
I get "%filename" for each picture. If I only have one album do I leave autodesc: an empty string in the html file?

08-07-2009, 01:29 AM
No, autodesc should be set to "%filename". Anyhow, I just realized an error in my code above. The line in red should read the following instead:

var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
}) : ''
desc=(desc.indexOf('%filename')!=-1)? albumvar.images[i][1].split('.')[0] : desc

08-07-2009, 02:18 AM
Thanks that worked I concatenated the break.

08-08-2009, 06:41 PM
I have a related question. After making the updates listed in this thread I notice that some of the filenames are a little longer than the images and end up pushing the images to the right. Is there a way to do a character wrap for the file names?

08-08-2009, 07:55 PM
If you mean trim the filenames if they exceed a certain length, you can try:

desc=(desc.indexOf('%filename')!=-1)? albumvar.images[i][1].split('.')[0].substring(0, 10) : desc

where 10 means the first 10 characters.

08-08-2009, 08:38 PM
I was thinking more along the lines of a character wrap, but I like your suggestion more because it helps to avoid vertical pushdown of the second or third row.

08-08-2009, 10:29 PM
I like the idea of a character wrap too as per james438's suggestion - what would the code be to try that?

08-09-2009, 07:11 AM
Character wrapping is something handled by the browser actually. In CSS3 for example, you can specify text and word wrapping (http://www.w3.org/TR/css3-text/#word-wrap). Now, using JavaScript, you can trim the length of a text, such as in the example I posted.

08-11-2009, 06:07 PM
I am trying to do the same thing in adding a new line after 18 char, this is what I have done.

formatdesc= albumvar.images[i][1].split('.')[0];
formatdesc= formatdesc.substring(0,18) + '\n' + formatdesc.substring(18);

//desc=(desc.indexOf('%filename')!=-1)? '<br />' + albumvar.images[i][1].split('.')[0] : desc
desc=(desc.indexOf('%filename')!=-1)? '<br />' + formatdesc : desc

But I get and error, so I looked on the interenet for what I was looking for and I found:

// Line Splitter Function
// copyright Stephen Chapman, 19th April 2006
// you may copy this code but please keep the copyright notice as well
function splitLine(st,n) {var b = ''; var s = st;while (s.length > n) {var c = s.substring(0,n);var d = c.lastIndexOf(' ');var e =c.lastIndexOf('\n');if (e != -1) d = e; if (d == -1) d = n; b += c.substring(0,d) + '\n';s = s.substring(d+1);}return b+s;}

Then you add

var myText40 = splitLine(myText,40);
var myHTML = myText40.replace(/\n/g,'<br \/>');

I put this in and I got the same error, I think it is possible, but obviously don't know what I am doing.

08-11-2009, 08:59 PM
Can anyone what my mistake is, besides inexperience.

08-12-2009, 05:57 AM
Yak, if all you're trying to do is insert a <br> after the first 18(th) character of a string, continuing from the original modification, you'd add the code in red to it:

var desc=(desc && desc!="")? '<br />' + desc.replace(/(%i)|(%d)|(%s)/g, function(m){
return (m=="%i")? i+1 : (m=="%d")? albumvar.images[i][2] : ""
}) : ''
desc=(desc.indexOf('%filename')!=-1)? albumvar.images[i][1].split('.')[0] : desc
if (desc.length>18)
desc=desc.substr(0,18) + '<br />' + desc.substr(18)

08-12-2009, 01:10 PM
Thank you very much!

05-01-2012, 06:48 AM
I know this topic is almost 2.5 years old, but I just spent over an hour trying to figure out how to get those words to wrap.
To all of you, forget all the coding, just go to where you would put the description in.
then simply enter in the good old '<br />' and viola, your description will break there, start up underneath. Continue to put the '<br />' until you have completed your entire description....

Good Night its 0247am e/t on a Tuesday morning....Welcome May 1, 2012