[Feature Request] Improving gallery nesting

Phoca Gallery - image gallery extension
bulgarion
Phoca Member
Phoca Member
Posts: 15
Joined: 11 Sep 2008, 11:28

[Feature Request] Improving gallery nesting

Post by bulgarion »

Hi,
I'm opening a new thread for asking this, and see if there's some response from the other users.
I think that Phoca is FAR the best Joomla! 1.5 gallery, for many reasons (Cooliris, now shadowboxes...). But it could be really better, with the integration of some useful parameters needed to create a REAL custom nested gallery.
Something like:
  • category list view from a single parent category
  • in the "Hide category ID", being able to hide a parent item with all its subategories at once
  • display just a detemined number of "childs" (eg. max 2 subgallery depth)
Suggestions? Ideas? Does this sounds totally insane? :lol:
User avatar
caro84g
Phoca Hero
Phoca Hero
Posts: 1369
Joined: 11 Feb 2008, 17:52
Location: Holland
Contact:

Re: [Feature Request] Improving gallery nesting

Post by caro84g »

Sounds a good idea to me...

Some comments:
  • category list view from a single parent category
When there are images as well as subcategories, then only the subcategories must be displayed - otherwise you'd take the category view :twisted:
  • in the "Hide category ID", being able to hide a parent item with all its subategories at once
:idea: This is a difficult one to make I think. I'd prefer to have the flexibilty to hide some subcategories and to display others... It might be possible combined with the next one
  • display just a detemined number of "childs" (eg. max 2 subgallery depth)
yes, I like that one :twisted:

P.S. Jan: I love your improved naming (categories displayed en images not) :| :twisted:
Please ask your support questions in the forums and not via PM - I delete those PM's
Backup before you do any major change to your website (and test first)
bulgarion
Phoca Member
Phoca Member
Posts: 15
Joined: 11 Sep 2008, 11:28

Re: [Feature Request] Improving gallery nesting

Post by bulgarion »

caro84g wrote: When there are images as well as subcategories, then only the subcategories must be displayed - otherwise you'd take the category view
Definitely agree - I'm asking this because I definitely love the look&feel of the "Category List View", and I find somehow reductive being able to use it only on the root category!
caro84g wrote: in the "Hide category ID", being able to hide a parent item with all its subategories at once
This is a difficult one to make I think. I'd prefer to have the flexibilty to hide some subcategories and to display others... It might be possible combined with the next one
I was thinking of it in conjunction with the "hide category ID" box - I mean, if you have

Gallery ID 4 --> ID 5 --> ID 6
Gallery ID 4 --> ID 5 --> ID 7
Gallery ID 4 --> ID 5 --> ID 8
Gallery ID 3 --> ID 2 --> ID 1

and you want to show something in gallery 2 or below, it may be SO NICE to being able to hide all the other galleries together.
I think of it simply putting in "4" in the "hide category ID" and then flagging to "yes" another parameter, which tells to hide all the child sub-categories of the entered one.
vdneut
Phoca Newbie
Phoca Newbie
Posts: 8
Joined: 13 Aug 2009, 18:56

Re: [Feature Request] Improving gallery nesting

Post by vdneut »

I fully support this request!

The reason is that I delegate the maintenance of some categories to other groups, enabling them to create sub-categories (great feature btw).
These groups have their own page of showing their galleries and I don't want them to appear in the websites home galery.
So I thought, lets hide the category of the group, but then still subcategories are shown. Now I have to hide each subdirectory other groups create. But that's hardly delegating :)
Thanks! Nico
vdneut
Phoca Newbie
Phoca Newbie
Posts: 8
Joined: 13 Aug 2009, 18:56

Re: [Feature Request] Improving gallery nesting

Post by vdneut »

Could not wait for another 2 years for this... So I did some programming and this is the result.
Yes, it is a hack... so only for experienced users that now what to do with it! Especially after upgrades!

I hope the Phoca team includes this in the next release.

For now, I wrote it for 2.7.5
File: components/com_phocagallery/views/categories/view.html.php

Code: Select all

<?php
/*
 * @package Joomla 1.5
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component Phoca Component
 * @copyright Copyright (C) Jan Pavelka www.phoca.cz
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die();
jimport( 'joomla.application.component.view');
jimport( 'joomla.filesystem.file' );
phocagalleryimport('phocagallery.access.access');
phocagalleryimport('phocagallery.path.path');
phocagalleryimport('phocagallery.file.file');
phocagalleryimport('phocagallery.render.renderinfo');
phocagalleryimport('phocagallery.picasa.picasa');

class PhocaGalleryViewCategories extends JView
{
	// 10/10/2010 N. van der Neut (vdneut@gmail.com) NNE
	// Extended the Show and Hide Categories parameters in the List of Categories view to include all its sub-categories.
	// It's up to the developers of Phoca to in/exclude this in their standard and extend it with an 
	//  'Automatically include sub-categories' checkbox for both Show as well as Hide Categories to activate this function.
	
	function _doExtendSubCategories($parentCategory) {
		// Recursive function walking down the tree of sub-categories
		$db = & JFactory::getDBO();
		$query = 'SELECT c.id'
			.' FROM #__phocagallery_categories AS c'
			.' WHERE c.parent_id = '.(int) $parentCategory
			.' AND c.published = 1'
			.' AND c.approved = 1'
			.' AND c.id <> '.(int) $parentCategory
			.' GROUP BY c.id';

		$db->setQuery($query);
		$subCategories = $db->loadObjectList();
		$returnSubCategories = "";

		foreach ($subCategories as $subCategory) {
			$returnSubCategories = $returnSubCategories . $subCategory->id . ";" . $this->_doExtendSubCategories($subCategory->id);
		}
		return $returnSubCategories;
	}

	// NNE
	function _extendSubCategories($parentCategories) {
		// Extend the string holding Categories with all their sub-categories
		$subCategories = "";
		$catArray = explode( ';', $parentCategories);
		if (!empty($catArray) && is_array($catArray)) {
			foreach ($catArray as $key => $item) {
				if ($item <> "") {
					$subCategories = $subCategories . $this->_doExtendSubCategories($item);
				}
			}
			if ($subCategories <> "") {
				$subCategories = ";".$subCategories;
			}
		}
		return $parentCategories . $subCategories;
	}

	function display($tpl = null) {		
		
		global $mainframe;
		$user 		= &JFactory::getUser();
		$uri 		= &JFactory::getURI();
		$path		= &PhocaGalleryPath::getPath();
		$params		= &$mainframe->getParams();
		$tmpl		= array();
		$tmplGeo	= array();
		
		$this->_setLibraries();
		
		// PARAMS - - - - - - - - - -
		$image_categories_size 			= $params->get( 'image_categories_size', 4 );
		$medium_image_width 			= (int)$params->get( 'medium_image_width', 100 ) + 18;
		$medium_image_height 			= (int)$params->get( 'medium_image_height', 100 ) + 18;
		$small_image_width 				= (int)$params->get( 'small_image_width', 50 ) + 18;
		$small_image_height 			= (int)$params->get( 'small_image_height', 50 ) + 18;
		$tmpl['phocagallerywidth'] 		= $params->get( 'phocagallery_width', '' );
		$tmpl['categoriescolumns'] 		= $params->get( 'categories_columns', 1 );
		$tmpl['displayrating']			= $params->get( 'display_rating', 0 );
		$tmpl['phocagallerycenter']		= $params->get( 'phocagallery_center', '');
		$tmpl['categoriesimageordering']= $params->get( 'categories_image_ordering', 9 );
		$tmpl['displayimagecategories'] = $params->get( 'display_image_categories', 1 );// Display or hide image beside the category name
		$display_categories_geotagging 	= $params->get( 'display_categories_geotagging', 0 );// Display Geo CATEGORIES VIEW
		// Access Category - display category in CATEGORIES VIEW, which user cannot access
		$display_access_category 		= $params->get( 'display_access_category', 1 );
		$display_empty_categories		= $params->get( 'display_empty_categories', 0 );
		
		// NNE $hideCatArray					= explode( ';', trim( $params->get( 'hide_categories', '' ) ) );
		// NNE $showCatArray    				= explode( ';', trim( $params->get( 'show_categories', '' ) ) );
		$hideCatArray					= explode( ';', $this->_extendSubCategories(trim( $params->get( 'hide_categories', '' ) ) ) );
		$showCatArray    				= explode( ';', $this->_extendSubCategories(trim( $params->get( 'show_categories', '' ) ) ) );

		$tmpl['equalpercentagewidth']	= $params->get( 'equal_percentage_width');
		$tmpl['categoriesdisplayavatar']= $params->get( 'categories_display_avatar');
		$tmpl['categoriesboxwidth']		= $params->get( 'categories_box_width');
		$tmpl['gallerymetakey'] 		= $params->get( 'gallery_metakey', '' );
		$tmpl['gallerymetadesc'] 		= $params->get( 'gallery_metadesc', '' );
		
		
		

		
		// Correct Picasa Images - get Info
		switch($image_categories_size) {
			// medium
			case 1:
			case 5:
				$tmpl['picasa_correct_width']	= (int)$params->get( 'medium_image_width', 100 );	
				$tmpl['picasa_correct_height']	= (int)$params->get( 'medium_image_height', 100 );
			break;
			
			case 0:
			case 4:
			default:
				$tmpl['picasa_correct_width']	= (int)$params->get( 'small_image_width', 50 );	
				$tmpl['picasa_correct_height']	= (int)$params->get( 'small_image_height', 50 );
			break;
		}
		
		// - - - - - - - - - - - - - - - 
	
		// Get background for the image
		phocagalleryimport('phocagallery.image.imagefront');
		$catImg = PhocaGalleryImageFront::getCategoriesImageBackground($image_categories_size, $small_image_width, $small_image_height,  $medium_image_height, $medium_image_width);
		
		$tmpl['imagebg'] 		= $catImg->image;
		$tmpl['imagewidth'] 	= $catImg->width;
		

		//$total				= $this->get('total');
		//$tmpl['pagination']	= &$this->get('pagination');
		
		// Image next to Category in Categories View is ordered by Random as default
		phocagalleryimport('phocagallery.ordering.ordering');
		$categoriesImageOrdering = PhocaGalleryOrdering::getOrderingString($tmpl['categoriesimageordering']);
		
		// MODEL
		$model		= &$this->getModel();
		$items		= $this->get('data');
		
		
		// Add link and unset the categories which user cannot see (if it is enabled in params)
		// If it will be unset while access view, we must sort the keys from category array - ACCESS
		$unSet = 0;
		foreach ($items as $key => $item) {

			// Unset empty categories if it is set
			if ($display_empty_categories == 0) {
				if($items[$key]->numlinks < 1) {
					unset($items[$key]);
					$unSet 		= 1;
					continue;
				}
			}
			 
			// Set only selected category ID    
			if (!empty($showCatArray[0]) && is_array($showCatArray)) {
				$unSetHCA = 0;
         
				foreach ($showCatArray as $valueHCA) {
            
					if((int)trim($valueHCA) == $items[$key]->id) {
						$unSetHCA 	= 0;
						$unSet 		= 0;
						break;
					} else {
						$unSetHCA 	= 1;
						$unSet 		= 1;
                    }
                }
				if ($unSetHCA == 1) {
					unset($items[$key]);
					continue;
				}
			}

			
			// Unset hidden category
			if (!empty($hideCatArray) && is_array($hideCatArray)) {
				$unSetHCA = 0;
				foreach ($hideCatArray as $valueHCA) {
					if((int)trim($valueHCA) == $items[$key]->id) {
						unset($items[$key]);
						$unSet 		= 1;
						$unSetHCA 	= 1;
						break;
					}
				}
				if ($unSetHCA == 1) {
					continue;
				}
			}
		
			
			// Link
			$items[$key]->link	= JRoute::_('index.php?option=com_phocagallery&view=category&id='. $item->slug.'&Itemid='. JRequest::getVar('Itemid', 0, '', 'int') ); 
			
			// USER RIGHT - ACCESS - - - - -
			// First Check - check if we can display category
			$rightDisplay	= 1;
			if (!empty($items[$key])) {
			
				$rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $items[$key]->accessuserid, $items[$key]->access, $user->get('aid', 0), $user->get('id', 0), $display_access_category);
			}
			// Second Check - if we can display hidden category, set Key icon for them
			//                if we don't have access right to see them
			// Display Key Icon (in case we want to display unaccessable categories in list view)
			$rightDisplayKey  = 1;
		
			if ($display_access_category == 1) {
				// we simulate that we want not to display unaccessable categories
				// so if we get rightDisplayKey = 0 then the key will be displayed
				if (!empty($items[$key])) {
					$rightDisplayKey = PhocaGalleryAccess::getUserRight('accessuserid', $items[$key]->accessuserid, $items[$key]->access, $user->get('aid', 0), $user->get('id', 0), 0); // 0 - simulation
				}
			}
			
			// DISPLAY AVATAR, IMAGE(ordered), IMAGE(not ordered, not recursive) OR FOLDER ICON
			$displayAvatar = 0;
			if($tmpl['categoriesdisplayavatar'] == 1 && isset($items[$key]->avatar) && $items[$key]->avatar !='' && $items[$key]->avatarapproved == 1 && $items[$key]->avatarpublished == 1) {
				$sizeString = PhocaGalleryImageFront::getSizeString($image_categories_size);
				$pathAvatarAbs	= $path->avatar_abs  .'thumbs'.DS.'phoca_thumb_'.$sizeString.'_'. $items[$key]->avatar;
				$pathAvatarRel	= $path->avatar_rel . 'thumbs/phoca_thumb_'.$sizeString.'_'. $items[$key]->avatar;
				if (JFile::exists($pathAvatarAbs)){
					$items[$key]->linkthumbnailpath	=  $pathAvatarRel;
					$displayAvatar = 1;
				}
			}
			if ($displayAvatar == 0) {	
				if (isset($items[$key]->extid) && $items[$key]->extid != '') {
					if ($tmpl['categoriesimageordering'] != 10) {
						$imagePic		= PhocaGalleryImageFront::getRandomImageRecursive($items[$key]->id, $categoriesImageOrdering, 1);
						$fileThumbnail	= PhocaGalleryImageFront::displayCategoriesExtImgOrFolder($imagePic->exts,$imagePic->extm, $imagePic->extw,$imagePic->exth, $image_categories_size, $rightDisplayKey);
					} else {	
						$fileThumbnail		= PhocaGalleryImageFront::displayCategoriesExtImgOrFolder($items[$key]->exts,$items[$key]->extm, $items[$key]->extw, $items[$key]->exth, $image_categories_size, $rightDisplayKey);
					}

					$items[$key]->linkthumbnailpath	= $fileThumbnail->rel;
					$items[$key]->extw				= $fileThumbnail->extw;
					$items[$key]->exth				= $fileThumbnail->exth;
					$items[$key]->extpic			= $fileThumbnail->extpic;
				} else {
					if ($tmpl['categoriesimageordering'] != 10) {
						$items[$key]->filename	= PhocaGalleryImageFront::getRandomImageRecursive($items[$key]->id, $categoriesImageOrdering);
					}
					$fileThumbnail	= PhocaGalleryImageFront::displayCategoriesImageOrFolder($items[$key]->filename, $image_categories_size, $rightDisplayKey);
					$items[$key]->linkthumbnailpath	= $fileThumbnail->rel;
				}
			}
		
			if ($rightDisplay == 0) {
				unset($items[$key]);
				$unSet = 1;
			}
			// - - - - - - - - - - - - - - - 	
			
		}
		
		$tmpl['mtb'] = PhocaGalleryRenderInfo::getPhocaIc((int)$params->get( 'display_phoca_info', 1 ));
		
		
		// ACCESS - - - - - - 
		// In case we unset some category from the list, we must sort the array new
		if ($unSet == 1) {
			$items = array_values($items);
		}
		// - - - - - - - - - - - - - - - -

		// Do Pagination - we can do it after reducing all unneeded items, not before
		$totalCount 		= count($items);
		$model->setTotal($totalCount);
		$tmpl['pagination']	= &$this->get('pagination');
		$items 				= array_slice($items,(int)$tmpl['pagination']->limitstart, (int)$tmpl['pagination']->limit);
		// - - - - - - - - - - - - - - - -

		
		// Display Image of Categories Description
		if ($params->get('image') != -1) {
			$attribs['align']	= $params->get('image_align');
			$attribs['hspace']	= 6;
			// Use the static HTML library to build the image tag
			$tmpl['image'] 		= JHTML::_('image', 'images/stories/'.$params->get('image'), JText::_('Phoca Gallery'), $attribs);
		}
		// ACTION
		$tmpl['action']	= $uri->toString();
		$tmpl['action'] = str_replace ('&', '&', $tmpl['action']);// in case mixed amp will be included in the link
		$tmpl['action'] = str_replace ('&', '&', $tmpl['action']);
		
		// ASSIGN
		$this->assignRef('tmpl',		$tmpl);
		$this->assignRef('params',		$params);
		$this->assignRef('categories',	$items);
		
		// Meta data
		if ($tmpl['gallerymetakey'] != '') {
			$mainframe->addMetaTag('keywords', $tmpl['gallerymetakey']);
		}
		if ($tmpl['gallerymetadesc'] != '') {
			$mainframe->addMetaTag('description', $tmpl['gallerymetadesc']);
		}
		
		$tmpl['phoac'] = '<div style="tex'.'t-align: center; color:#d3d3'.'d3;">Power'.'ed by <a href="htt'.'p://www.pho'.'ca.cz" style="text-decor'.'ation: none;" tar'.'get="_bl'.'ank" title="Ph'.'oca.cz">Phoc'.'a</a> <a href="http://www.p'
			   .'hoca.cz/phocagallery" style="tex'.'t-decoration: none;" ta'.'rget="_bla'.'nk" title="Pho'.'ca Gal'.'lery">Gal'.'lery</a></div>';
		
		if ($display_categories_geotagging == 1) {
		
			// PARAMS - - - - - - - - - -
			$tmplGeo['categorieslng'] 		= $params->get( 'categories_lng', '' );
			$tmplGeo['categorieslat'] 		= $params->get( 'categories_lat', '' );
			$tmplGeo['categorieszoom'] 		= $params->get( 'categories_zoom', 2 );
			$tmplGeo['googlemapsapikey'] 	= $params->get( 'google_maps_api_key', '' );
			$tmplGeo['categoriesmapwidth'] 	= $params->get( 'categories_map_width', '' );
			$tmplGeo['categoriesmapheight'] = $params->get( 'categorires_map_height', 500 );
			// - - - - - - - - - - - - - - -
			
			// if no lng and lat will be added, Phoca Gallery will try to find it in categories
			if ($tmplGeo['categorieslat'] == '' || $tmplGeo['categorieslng'] == '') {
				phocagalleryimport('phocagallery.geo.geo');
				$latLng = PhocaGalleryGeo::findLatLngFromCategory($items);
				$tmplGeo['categorieslng'] = $latLng['lng'];
				$tmplGeo['categorieslat'] = $latLng['lat'];
			}
		
			$this->assignRef('tmplGeo',	$tmplGeo);
			parent::display('map');
		} else {
		
			parent::display($tpl);
		}
	}

	function _setLibraries() {
		
		$document	= &JFactory::getDocument();
		
		// Libraries
		$library 				= &PhocaGalleryLibrary::getLibrary();
		$libraries['pg-css-ie'] = $library->getLibrary('pg-css-ie');
		
		// CSS for IE 8
		if ( $libraries['pg-css-ie']->value == 0 ) {
			$document->addCustomTag("<!--[if lt IE 8]>\n<link rel=\"stylesheet\" href=\""
			.JURI::base(true)
			."/components/com_phocagallery/assets/phocagalleryieall.css\" type=\"text/css\" />\n<![endif]-->");
			$library->setLibrary('pg-css-ie', 1);
		}
		
		// CSS
		JHTML::stylesheet( 'phocagallery.css', 'components/com_phocagallery/assets/' );
	}
}
?>
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49138
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: [Feature Request] Improving gallery nesting

Post by Jan »

Hi,

the problem is, there are more than thousand feature requests on my feature request list. And it is not technically possible to add them to the code (first because of time, second because of adding all possible features will slow down or stop Phoca Gallery work - in fact the system will have only resources to check all the features, etc. :-( :-( )

Phoca Gallery is open soulution, so the best way is to customize it (if there is a guide for this, it is better, so anyway thank you for the guide so it will help other users)

Please describe me the modifications you have made and what is the output of this customization, maybe I don't understand it correctly from previous posts.

Thank you, Jan
If you find Phoca extensions useful, please support the project
vdneut
Phoca Newbie
Phoca Newbie
Posts: 8
Joined: 13 Aug 2009, 18:56

Re: [Feature Request] Improving gallery nesting

Post by vdneut »

Hi Jan,
Yes, I see many feature requests... And to keep the quality standard as high as it is now, I can imagine that not every feature / change is granted. No worry!

The purpose of this change is to enable me to only put the category ID of the parent of sub-categories and sub-sub-categories (etc.) in the Hide Category or Show Category box in the Phoca Galery Menu definition screen.

Example: parent -> child
1 -> 2
2 -> 3
2 -> 4

If I want to hide subcategory 2 and all it's subcategories (3 and 4) I currently need to enter this in the Hide category box: 2;3;4
But... when another sub-category is created below 2, (for example 2 -> 5) I need to add that category to the box.

It is not because I'm lazy :) but there are cases that this is realy usefull. For example you allow other users to create their Gallery via the front end but do not want to display them in your website main Gallery. Then I will add their Main Gallery ID in the Hide Category box, but this only lasts until having the user creating a subcategory...

My change in the source allows you to only enter the parent category ID in the Hide/Show category box and this will automatically be extended with all childs of the parent. In the example 2 will be expanded to 2;3;4.

If a user creates 4 -> 5 then the 2 will automatically be expanded to 2;3;4;5.

Technique
Looking at the parrent-child structure, a recursive function is ideal to walk through such a tree. The function reaches each branch (child) of the tree and while returning from its visit it returns the string with all child IDs that he build up meanwhile. To that string the parent ID is added and returned to the parent above.

Feature
At this moment this works for me. But I am fully aware that if you want to make this a general feature, it needs more thinking and more work. One aspect is "how to explain to the users...". The other one is, where do I put this new 'way of thinking'?

For example: besides the Hide/Show category boxes the Module might also be a candidate.... Not to select specific categories, but only parents. And if meanwhile childs are 'born', they are automatically shown in the Module.

Well let me know if you want me to figure out this a bit more or if you don't see a future for such a thing... No hard feelings! :wink:

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

Re: [Feature Request] Improving gallery nesting

Post by Jan »

Hi, thank you for the explanation (guide), I will take a look at it, but for now really no idea when I will find time for this :( :( :(

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