Implement a folder-based saving with tree-structure

Phoca Gallery - image gallery extension
Antares
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 28 Jun 2016, 12:29

Implement a folder-based saving with tree-structure

Post by Antares » 06 Aug 2016, 10:25

Hello,

for me it was important to save the pictures in a folder-based tree structure like you do in Windows/Linux e.g.
Actually the structure is "PhocaGallery-ROOT/aliasname-aliasfolder-timestamp", so every new folder is saved in the phocagallery-root and there is no other relationship to the main category.

The new structure should be "PhocaGallery-ROOT/MainCategory/Subcategory/...".

I also have changed the default access-rights, which are set when a user is creating a new category. What i have with this changes, is a better usage for cloud-systems. Every user, that has access to the menu, can create new folders and everyone can upload images into it, without any admin maintenance.

I have implement it by my own; sure that there is a better way to to it, but my way works perfectly.

What have i changed?

.../components/com_phocagallery/controllers/category.php

Search for:

Code: Select all

$userFolder	= PhocaGalleryText::getAliasName($user->username) .'-'.substr($post['aliasfolder'], 0, 10) .'-'. substr(md5(uniqid(time())), 0, 4);
Uncomment this line. After that it should be:

Code: Select all

// $userFolder	= PhocaGalleryText::getAliasName($user->username) .'-'.substr($post['aliasfolder'], 0, 10) .'-'. substr(md5(uniqid(time())), 0, 4);
After the line add the following:

Code: Select all

// new creation of folders, to implement a folder-based saving with tree-structure (like in windows e.g.)
			$db = JFactory::getDbo();								// DB-Connection 
			define( "DATA", "#__phocagallery_categories" );			// Define a short key "DATA" for table "__phocagallery_categories"
			$query = $db->getQuery( true );							// New object
			$query													// Define query
				->select( '*' )
				->from( $db->quoteName(DATA) )
				->where( $db->quoteName('id') . " = " . $db->quote( $catid ) );		// search the row with "id == catid"
			$db->setQuery( $query );			// execute the query				
			$row = $db->loadRow();			// save the result in $row
			$path = $row[24];				// on pos. 25 is saved the "userfolder", which is the path to the categorie (webspace)
			$userFolder = $path . '/' . substr($post['aliasfolder'], 0, 40); 	// save the path with a "/" and the aliasname (up to 40 character) of the new folder/categorie. 
			// New syntax: "PhocaGallery_ROOT/FirstCategorie/FirstSubcategorie/..."
			// end of new creation of folders, to implement a folder-based saving with tree-structure (like in windows e.g.)


Explanations are added as comments.
For new folders i also use the aliasname (with up to 40 character) of the folder, so german umlaute or other special character will be eliminated to ensure that there are no problems with.

If you also want to change the default rights for new folders, which was created by users, than go down to

Code: Select all

$post['uploaduserid']
change the value to "-1"
It should be

Code: Select all

$post['uploaduserid'] = "-1";
Maybe it helps someone. ;=)

All the best,
Christian

Tags:

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 44227
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Implement a folder-based saving with tree-structure

Post by Jan » 08 Aug 2016, 09:19

Hi, great to hear it.

Which version did you edit?
Did you test all possible managing function, like what happened when deleted, moved, etc?

Thank you,
Jan
If you find Phoca extensions useful, please support the project

Antares
Phoca Newbie
Phoca Newbie
Posts: 6
Joined: 28 Jun 2016, 12:29

Re: Implement a folder-based saving with tree-structure

Post by Antares » 09 Aug 2016, 11:37

Hi,

i have use the current version (4.3.1).

Everything works fine, no problems here (deleting, moving e.g. tested). Special charakters in folders (existing or new one) are also no problem. It writes the path directly into the database, so it is exactly the same, if you are adding pictures multible in the backend (were the tree structure already works).

Christian

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 44227
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Implement a folder-based saving with tree-structure

Post by Jan » 10 Aug 2016, 14:18

Ok
If you find Phoca extensions useful, please support the project

Post Reply