Hello,
Sorry for my English.
I'm using phoca from some time and like it.
This is my first "contact' with php.
My gallery structure:
CAT1
---CAT1.1
------Image 1.1.1
------Image 1.1.2
---CAT1.2
------Image 1.2.1
------Image 1.2.2
CAT2
---CAT2.1
------Image 2.1.1
------Image 2.1.2
---CAT2.2
------Image 2.2.1
------Image 2.2.2
CAT3
---CAT3.1
------Image 3.1.1
------Image 3.1.2
---CAT3.2
------Image 3.2.1
------Image 3.2.2
---CAT3.3
------Image 3.3.1
------Image 3.3.2
Problem:
Phoca uses wrong image for "Categories View" - it is always first image from the last subcategory).
My setting for "Cattegories Image Ordering"=Ordering Ascending
Phoca uses following images for "Categories View" categories on top level:
CAT1-Image1.2.1
CAT2-Image2.2.1
CAT3-Image3.3.2
I analyzed PhocaGalleryImageFront::getRandomImageRecursive function, and I found bug.
Loop "foreach ($subCategories as $subCategory)" should be interrupted when image is found, but isn't because:
1. getRandomImageRecursive sometime returns class with atribute filename and sometime string
- return $image->filename
- return $image
2. condition in loop expects wrong types:
if (isset($image->filename) && $image->filename != '')
- here $image contains string not object
Where can I submit 'code'?
Phoca 3.2.3 - Invalid Category View Image
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Phoca 3.2.3 - Invalid Category View Image
Last edited by jkowal on 16 May 2013, 17:02, edited 1 time in total.
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Re: Phoca 3.2.3 - Invalid Category View Image
Funcion getRandomImageRecursive
/*
* RANDOM IMAGE OR IMAGE ORDERED BY PARAM - CATEGORIES VIEW, CATEGORY VIEW
* $extImage - for example Picasa image
* $extImageSize - 1 - small, 2 - medium, 3 - large
* Is called random but the ordering can be set
*/
function getRandomImageRecursive($categoryid, $categoryImageOrdering = '', $extImage = 0, $extImageSize = 1)
{
$image = PhocaGalleryImageFront::getRandomImageRecursiveInternal($categoryid, $categoryImageOrdering, $extImage, $extImageSize, 0);
if (isset($image))
{
return $image->filename;
}
else
{
return null;
}
}
/*
* RANDOM IMAGE OR IMAGE ORDERED BY PARAM - CATEGORIES VIEW, CATEGORY VIEW
* $extImage - for example Picasa image
* $extImageSize - 1 - small, 2 - medium, 3 - large
* Is called random but the ordering can be set
*/
function getRandomImageRecursive($categoryid, $categoryImageOrdering = '', $extImage = 0, $extImageSize = 1)
{
$image = PhocaGalleryImageFront::getRandomImageRecursiveInternal($categoryid, $categoryImageOrdering, $extImage, $extImageSize, 0);
if (isset($image))
{
return $image->filename;
}
else
{
return null;
}
}
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Re: Phoca 3.2.3 - Invalid Category View Image
private function getRandomImageRecursiveInternal($categoryid, $categoryImageOrdering = '', $extImage = 0, $extImageSize = 1, $level = 0)
{
$db = &JFactory::getDBO();
$user = JFactory::getUser();
//$image = new stdClass();
// We need to get a list of all subcategories in the given category
if ($categoryImageOrdering['column'] == '')
{
$imageOrdering = $categoryOrdering = ' ORDER BY RAND()';
}
else
{
// This is special case where we change category to image
$imageOrdering = ' ORDER BY a.'.$categoryImageOrdering['column'] . ' ' .$categoryImageOrdering['sort'];
$categoryOrdering = ' ORDER BY a.'.$categoryImageOrdering['column'] . ' '.$categoryImageOrdering['sort'];
}
$query = 'SELECT a.id, a.filename, a.exts, a.extm, a.extw, a.exth, a.extid, c.accessuserid as cataccessuserid, c.access as cataccess' .
' FROM #__phocagallery AS a' .
' LEFT JOIN #__phocagallery_categories AS c ON a.catid = c.id'.
' WHERE a.catid = '.(int) $categoryid.
' AND a.published = 1'.
$imageOrdering.
' LIMIT 0,1';
$db->setQuery($query);
$images = $db->loadObjectList();
// Test the user rights to display random image as category image
$rightDisplay = 1;//default is set to 1 (all users can see the category)
if (isset($images[0]->cataccessuserid) && isset($images[0]->cataccess)) {
$rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $images[0]->cataccessuserid, $images[0]->cataccess, $user->authorisedLevels(), $user->get('id', 0), 0);
}
if ($rightDisplay == 0) {
$images = 0;
}
if (count($images) == 0) {
// TODO, if we find no image in subcategory we look at its subcategory (subcategory of subcategory)
// no to look if there is some subcategory on the same level
$subCategories = PhocaGalleryImageFront::getRandomCategory($categoryid, $categoryOrdering);
foreach ($subCategories as $subCategory) {
$image = PhocaGalleryImageFront::getRandomImageRecursiveInternal($subCategory->id, $categoryImageOrdering, $extImage, $extImageSize,$level+1);
if (isset($image)){
// external image - e.g. Picasa
if ($extImage == 1)
{
if ($extImageSize == 2)
{
if (isset($image->extm) && $image->extm != '') {
break;
}
} else {
if (isset($image->exts) && $image->exts != '') {
break;
}
}
} else
{
if (isset($image->filename) && $image->filename != '')
{
break;
}
}
}
}
}
else
{
$image = $images[0];
}
return $image;
}
{
$db = &JFactory::getDBO();
$user = JFactory::getUser();
//$image = new stdClass();
// We need to get a list of all subcategories in the given category
if ($categoryImageOrdering['column'] == '')
{
$imageOrdering = $categoryOrdering = ' ORDER BY RAND()';
}
else
{
// This is special case where we change category to image
$imageOrdering = ' ORDER BY a.'.$categoryImageOrdering['column'] . ' ' .$categoryImageOrdering['sort'];
$categoryOrdering = ' ORDER BY a.'.$categoryImageOrdering['column'] . ' '.$categoryImageOrdering['sort'];
}
$query = 'SELECT a.id, a.filename, a.exts, a.extm, a.extw, a.exth, a.extid, c.accessuserid as cataccessuserid, c.access as cataccess' .
' FROM #__phocagallery AS a' .
' LEFT JOIN #__phocagallery_categories AS c ON a.catid = c.id'.
' WHERE a.catid = '.(int) $categoryid.
' AND a.published = 1'.
$imageOrdering.
' LIMIT 0,1';
$db->setQuery($query);
$images = $db->loadObjectList();
// Test the user rights to display random image as category image
$rightDisplay = 1;//default is set to 1 (all users can see the category)
if (isset($images[0]->cataccessuserid) && isset($images[0]->cataccess)) {
$rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $images[0]->cataccessuserid, $images[0]->cataccess, $user->authorisedLevels(), $user->get('id', 0), 0);
}
if ($rightDisplay == 0) {
$images = 0;
}
if (count($images) == 0) {
// TODO, if we find no image in subcategory we look at its subcategory (subcategory of subcategory)
// no to look if there is some subcategory on the same level
$subCategories = PhocaGalleryImageFront::getRandomCategory($categoryid, $categoryOrdering);
foreach ($subCategories as $subCategory) {
$image = PhocaGalleryImageFront::getRandomImageRecursiveInternal($subCategory->id, $categoryImageOrdering, $extImage, $extImageSize,$level+1);
if (isset($image)){
// external image - e.g. Picasa
if ($extImage == 1)
{
if ($extImageSize == 2)
{
if (isset($image->extm) && $image->extm != '') {
break;
}
} else {
if (isset($image->exts) && $image->exts != '') {
break;
}
}
} else
{
if (isset($image->filename) && $image->filename != '')
{
break;
}
}
}
}
}
else
{
$image = $images[0];
}
return $image;
}
- Jan
- Phoca Hero
- Posts: 48416
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Phoca 3.2.3 - Invalid Category View Image
Hi, the returning of string or object is all right (this is needed to differentiate in the recursive function) and at the end it will be counted:
If there is object, use object, if not (in case there is a string) return string.
Jan
Code: Select all
if(isset($image->filename)) {
return $image->filename;
} else {
return $image;
}
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Re: Phoca 3.2.3 - Invalid Category View Image
Effect is as i wrote.
Real problem is here:
Loop "foreach ($subCategories as $subCategory)" should be interrupted when image is found, but isn't.
Loop is "always" processed until the end, because break expression expects something other than getting.
Real problem is here:
Loop "foreach ($subCategories as $subCategory)" should be interrupted when image is found, but isn't.
Loop is "always" processed until the end, because break expression expects something other than getting.
- Jan
- Phoca Hero
- Posts: 48416
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Phoca 3.2.3 - Invalid Category View Image
Hi, I will take a closer look to it. The problem is, you are in recursive function so you cannot break the function but return some value so e.g. the foreach is broken if image found but still you need to return some value.
Jan
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Re: Phoca 3.2.3 - Invalid Category View Image
I'm not php expert. My proposition was to use two functions, one recursive returns object, second string. It's working. Parameter $level is for testing purpose only.
-
- Phoca Member
- Posts: 10
- Joined: 26 Jul 2009, 00:27
Re: Phoca 3.2.3 - Invalid Category View Image
I made some changes to selve this problem (for versions 3.2.6 and 4.0.4).
If you interested tell me where send php source.
If you interested tell me where send php source.