Needs review
Project:
IMCE_Gallery
Version:
5.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Jul 2007 at 09:39 UTC
Updated:
15 Oct 2007 at 18:36 UTC
Hi,
I have succesfully installed the IMCE module and it works great. I've also installed the IMCE_Gallery module which enables me to create galleries and add images to them. Whe it comes to viewing the images in the galleries, i get the following warning and hence am not able to view the images from the galleries.
warning: Invalid argument supplied for foreach() in j:\program files\apache group\Apache\htdocs\drupaltest4\modules\imce_gallery\imce_gallery.module on line 365.
I really need it working, please help me out.
Thanks.
Comments
Comment #1
landryj commentedi've looked through it a little bit and it seems that this error is because foreach() requires an array as its first input and it is recieving a regular number. This means that the variable is being set improperly where the function is called. I've looked but i'm not sure where functions are called so i've posted to the forums about it. If anyone knows where the functions are called for this module let me know and it should not be hard to find out why the array is not being set. thanks.
Comment #2
landryj commenteduntil my previous comment is answered I cannot supply a good fix, but this works (it's just messy and kind of stupid because it changes the incorrect inputs for the function). I modified the theme_gallery_items function in imce_gallery.module to look as follows:
function theme_gallery_items($rows, $folder) {
global $base_path;
$output = '';
$img_num=0;
$a = 0;
$rows = array();
$i = 0;
$gid = arg(3);
$sql_select = "SELECT `g_file_name` FROM `imce_gallery_items` WHERE `gid` = '$gid'";
while ($result = db_fetch_array($query)) {
$rows[$i] = $result['g_file_name'];
$i++;
}
$folder = 'files/u1';
foreach($rows as $filename) {
$path = $folder . '/' . $filename;
$attributes = array("width" => '110', 'border' => '1', 'id' => 'img_'.$img_num, 'name' => 'gallery_images');
$img = theme('image', $path, '', '', $attributes, 0);
$link_attributes = array('onClick' => 'get_orig("'.$base_path.$path.'", '.$img_num.');return false;');
$img_array[$a] = l($img, '', $link_attributes, '', '', '', 1);
$a++;
if($a >= 5) {
$rows_img[] = $img_array;
$img_array = array();
$a = 0;
}
$img_num++;
}
if($a > 0) {
$rows_img[] = $img_array;
}
$header = array();
$back_url = request_uri();
$c_url = count($back_url);
$pos = strrpos($back_url, "/");
$back_url = substr($back_url, 1, ($pos-$c_url+1));
$back_url = preg_replace("/(\?q\=)/", "", $back_url);
$output = l(t('Back to Gallery list'), $back_url);
$output .= theme('table', $header, $rows_img, array('id' => 'imce_gallery_table'));
return $output;
}
the new code is near the top:
$rows = array();
$i = 0;
$gid = arg(3);
$sql_select = "SELECT `g_file_name` FROM `imce_gallery_items` WHERE `gid` = '$gid'";
while ($result = db_fetch_array($query)) {
$rows[$i] = $result['g_file_name'];
$i++;
}
$folder = 'files/u1';
what this does is creates an array and fills it with the images in the database. it also fixes the folder declaration which for some reason goes to files/1 instead of the files/u1 that is automatically created by imce. it would be better if we could fix the actual inputs for the function, but until i figure out how to do that, this quick fix works. There is just one little problem where it seems to echo out some sort of error. I'm looking into this and i'll repost soon about that. let me know if this is confusing or if you have any questions.
Comment #3
landryj commentedalready found the fix: this is the working code.
function theme_gallery_items($rows, $folder) {
global $base_path;
$output = '';
$img_num=0;
$a = 0;
$rows = array();
$i = 0;
$gid = arg(3);
$sql_select = "SELECT `g_file_name` FROM `imce_gallery_items` WHERE `gid` = '$gid'";
$query = _db_query($sql_select);
while ($result = db_fetch_array($query)) {
$rows[$i] = $result['g_file_name'];
$i++;
}
$folder = 'files/u1';
foreach($rows as $filename) {
$path = $folder . '/' . $filename;
$attributes = array("width" => '110', 'border' => '1', 'id' => 'img_'.$img_num, 'name' => 'gallery_images');
$img = theme('image', $path, '', '', $attributes, 0);
$link_attributes = array('onClick' => 'get_orig("'.$base_path.$path.'", '.$img_num.');return false;');
$img_array[$a] = l($img, '', $link_attributes, '', '', '', 1);
$a++;
if($a >= 5) {
$rows_img[] = $img_array;
$img_array = array();
$a = 0;
}
$img_num++;
}
if($a > 0) {
$rows_img[] = $img_array;
}
$header = array();
$back_url = request_uri();
$c_url = count($back_url);
$pos = strrpos($back_url, "/");
$back_url = substr($back_url, 1, ($pos-$c_url+1));
$back_url = preg_replace("/(\?q\=)/", "", $back_url);
$output = l(t('Back to Gallery list'), $back_url);
$output .= theme('table', $header, $rows_img, array('id' => 'imce_gallery_table'));
return $output;
}
Comment #4
landryj commentedwith the other fixes I suggested it seems to make the javascript file stop working, so here is a fix for that and i think everything to do with this problem should be working. Like i said before, there's is probably a more efficient and cleaner way to solve this problem, but the one i provided at least works, so if anyone can think of a cleaner way please post and/or let me know.
in function: get_img (around line 109)
change:
host = "http://"+window.location.hostname;
to:
host = "http://"+window.location.hostname.port;
and it fixes the javascript problem that seemed to invent itself after my last fix. hope this helps everyone.