(SOLVED) Force filename change

Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Thu, 2007-07-12 13:20

Hello,

Some time ago, a guy helped me with a code for Gallery, where it would force Gallery to ignore the picture's filename and created them as aaa_001.jpg, aaa_002.jpg, etc...

I REALLY prefer that it does this.

But, since I upgraded to 2.2, the code does not work anymore.

Below is the old code for 2.1, which worked beautifully!!
Can someone please help me so this works on 2.2??

The file to edit is:
/www/gallery2/modules/core/classes/helpers/GalleryItemHelper_medium.class

    function addItemToAlbum($fileName, $itemName, $title, $summary,
			    $description, $mimeType, $albumId, $symlink=false) {
	global $gallery;
--------- THIS PART BELOW WAS THE ADDED CODE ----------------
	$platform = $gallery->getPlatform();
	list ($base, $extension) = GalleryUtilities::getFileNameComponents($fileName); 
	$itemName = 'aaa' . $extension; 

	$title = ""; 
	$summary = ""; 
	$description = ""; 

Thank you so much!!
Alexandra

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Thu, 2007-07-12 22:24

Have you tried the code? Looking at the older version of /modules/core/classes/helpers/GalleryItemHelper_medium.class this function has not changed much so I can only assume it would still work.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Sat, 2008-02-02 16:01

Hi Dave!!! Yes, of course I tried... and what it does is it makes a HUGE long gibberish filename.

Look at these URLs:

Pic uploaded BEFORE upgrade to 2.2
gallery2/v/buddytaz/taz/aaa_007.html

Pic uploaded AFTER upgrade to 2.2
gallery2/v/buddytaz/taz/aaasite_htdocs_family_gallery2_g2data_tmp_MUF_E5Hh43.html

See?? Instead of a nice short "aaa_007.html"
I get "aaasite_htdocs_family_gallery2_g2data_tmp_MUF_E5Hh43.html"

It's putting the "aaa" in front of the filename, but then adding my whole server path after that and some gibberish "tmp_MUF_E5Hh43"!!

Why??? No idea.. I don't know anything about codes to figure out what could be wrong.

Very strange huh??

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Mon, 2007-10-22 14:41

Dave or anybody!!

Can someone please help me resolve this issue?? It might be simple, but I don't know how to write/edit these codes.

Please??

 
Slayergirl
Slayergirl's picture

Joined: 2007-09-12
Posts: 180
Posted: Mon, 2007-10-22 14:49

API info on addItem:

Quote:
string $fileName: the path to the file on the local disk
string $itemName: the name of the new item
string $title: the title of the new item
string $summary: the summary of the new item
string $description: the description of the new item
string $mimeType: the mime type of the new item
int $albumId: the id of the target album
boolean $symlink: (optional) a boolean true if we should symlink instead of copy (default is false).

Just a wild guess that maybe $itemName is closer to what you want...it's worth a try at least.

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Mon, 2007-10-22 17:27

Thanks Slayergirl, but I'm not sure I understood your response. Is that a code that I need to put in /modules/core/classes/helpers/GalleryItemHelper_medium.class where the old code used to be?

Doesn't look like a code. So I am not sure what am I supposed to do with what you wrote.

The old code that I posted at the top used to work perfectly.... but only on 2.1 and below... So it just needs to be tweaked for 2.2, which I do not know how.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2007-10-23 02:06

If you add a item to gallery with the same filename the title of the item is saved. You can have more than one item in the same album wit the same name.
That said the path name to the item changes if you add items with the same name. EG: You add a item called picture.jpg and you add another item called picture.jpg the second item will now have the same name but the path will be amended with _001 to become picture_001.jpg

The code that does that is in /core/GalleryFileSystemEntityHelper_medium.class. look for:

    /**
     * Truncate the given path component to the maximum allowed length.
     * If an extension is given, it truncates the base and then appends the extension.
     * 
     * @param string basename of path component
     * @param string variable part (optional), e.g. '_001'
     * @param string extension (optional), e.g. '.jpg'
     * @return string truncated path component 
     * @acccess private
     */
    function _truncatePathComponent($baseName, $variablePart='', $extension='') {

	$length = 128 - strlen($variablePart) - strlen($extension);
	$baseName = GalleryCoreApi::utf8Substring($baseName, 0, $length);

	return $baseName . $variablePart . $extension;
    }

Dave

_____________________________________________
Blog & G2 |
| floridave - Gallery Team

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Sat, 2008-02-02 16:02

Thanks Dave, but that's not what I need because it's not a matter of uploading 2 files with the same name, but keeping it neat and having all filenames short.

So no matter what I upload, whether it's IMG24573.jpg or triptothebeachinthesummer.jpg, it just becomes aaa_003.jpg, aaa_004.jpg, etc...

And I REALLY like that, because I have family members who sometimes contribute to the album, and they sometimes have really stupid filenames or filenames that are too long (don't know why they rename them from the camera's original, but I don't bother arguing with them). So that script used to work wonders and made everything all neat.

Alex

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Wed, 2008-01-30 11:29

Hello... I am STILL trying to get this to work... it USED to work, but doesn't anymore with the new version..

Can someone just take a little closer look into it? Please???

Thanks!!

 
Alexandra70

Joined: 2004-12-08
Posts: 143
Posted: Sat, 2008-02-02 15:59

Solved...

Removed "$base, $extension" next to "list"..

$platform = $gallery->getPlatform();
list ($base, $extension) = GalleryUtilities::getFileNameComponents($fileName);
$itemName = 'aaa' . $extension;

Works perfectly now.