Modifying list_albums() Modifying list_albums()
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Modifying list_albums()

Started by spacebass5000, December 23, 2005, 07:08:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

spacebass5000

I am attempting to associate two thumbnails with each album. So far, I have successfully added a field in cm_albums and have altered modifyalb.php and db_input.php such that the user can update the appropriate record/field in the database.

I have now turned my attention to list_albums() found in the main index.php file. I have been beating my head on this part for a day now and am growing increasingly frustrated. Can anyone help me alter this code such that it allows me to associate two thumbs with an album?

The new field I added to cm_albums was named simply "thumb2".

Any help will be GREATLY appreciated...

spacebass5000

here is the manner in which I am trying to go about it. feel free to constructively criticize me as you see fit...

I am Wendell btw.

/**
* list_albums()
*
* Get a list of albums
*/
function list_albums()
{
    global $CONFIG, $USER, $USER_DATA, $PAGE, $lastup_date_fmt, $FORBIDDEN_SET, $FORBIDDEN_SET_DATA;
    global $cat;
    global $lang_list_albums, $lang_errors, $cpg_show_private_album;

    $alb_per_page = $CONFIG['albums_per_page'];
    $maxTab = $CONFIG['max_tabs'];

    $album_filter = '';
    $pic_filter = '';
    $pic_subquery = '';

    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album)
{
        $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        $pic_filter = ' and ' . $FORBIDDEN_SET;
    }

    $result = cpg_db_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '$cat'" . $album_filter);
    $nbEnr = mysql_fetch_array($result);
    $nbAlb = $nbEnr[0];
    mysql_free_result($result);

    if (!$nbAlb) return;

    $totalPages = ceil($nbAlb / $alb_per_page);

    if ($PAGE > $totalPages) $PAGE = 1;
    $lower_limit = ($PAGE-1) * $alb_per_page;
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
    $limit = "LIMIT " . $lower_limit . "," . ($upper_limit - $lower_limit);

$sql = 'SELECT a.aid, a.title, a.description, category, visibility, filepath, ' . 'filename, url_prefix, pwidth, pheight ' . 'FROM ' . $CONFIG['TABLE_ALBUMS'] . ' as a ' . 'LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' as p ' . 'ON a.thumb=p.pid ' . 'WHERE category=' . $cat . $album_filter . ' ORDER BY a.pos ' . $limit;

    $alb_thumbs_q = cpg_db_query($sql);
    $alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q);
    mysql_free_result($alb_thumbs_q);

        // Added by Wendell
$sql = 'SELECT filepath, ' . 'filename, url_prefix, pwidth, pheight ' . 'FROM ' . $CONFIG['TABLE_ALBUMS'] . ' as a ' . 'LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' as p ' . 'ON a.thumb2=p.pid ' . 'WHERE category=' . $cat . $album_filter . ' ORDER BY a.pos ' . $limit;

    $alb_thumbs_q = cpg_db_query($sql);
    $alb_thumbs_2 = cpg_db_fetch_rowset($alb_thumbs_q);
    mysql_free_result($alb_thumbs_q);

    $disp_album_count = count($alb_thumbs);
$disp_album_count_2 = count($alb_thumbs_2);

//echo "<p>count = ".$disp_album_count."</p>";
//echo "<p>count 2 = ".$disp_album_count_2."</p>";

    $album_set = '';

    foreach($alb_thumbs as $value)
{
        $album_set .= $value['aid'] . ', ';
    }

    $album_set = '(' . substr($album_set, 0, -2) . ')';

    //This query will fetch album stats and keyword for the albums
    $sql = "SELECT a.aid, count( p.pid )  AS pic_count, max( p.pid )  AS last_pid, max( p.ctime )  AS last_upload, a.keyword" .
            " FROM {$CONFIG['TABLE_ALBUMS']} AS a " .
            " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved =  'YES' ".
            "WHERE a.aid IN $album_set" . "GROUP BY a.aid";

    $alb_stats_q = cpg_db_query($sql);
    $alb_stats = cpg_db_fetch_rowset($alb_stats_q);
    mysql_free_result($alb_stats_q);

    foreach($alb_stats as $key => $value)
{
        $cross_ref[$value['aid']] = &$alb_stats[$key];
        if ($CONFIG['link_pic_count'] == 1)
{
          if (!empty($value['keyword']))
  {
            $value['keyword'] = addslashes($value['keyword']);
            $query = "SELECT count(pid) AS link_pic_count
                      FROM {$CONFIG['TABLE_PICTURES']}
                        WHERE aid != {$value['aid']} AND
                        keywords LIKE '%{$value['keyword']}%' AND
                        approved = 'YES'";
            $result = cpg_db_query($query);
            $link_stat = mysql_fetch_array ($result);
            mysql_free_result($result);
            $alb_stats[$key]['link_pic_count'] = $link_stat['link_pic_count'];
          }
       }
    }

    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++)
{
        $alb_thumb = &$alb_thumbs[$alb_idx];
$alb_thumb_2 = &alb_thumbs_2[$alb_idx];

        $aid = $alb_thumb['aid'];

        if (isset($cross_ref[$aid]))
{
            $alb_stat = $cross_ref[$aid];
            $count = $alb_stat['pic_count'];
        }
else
{
            $alb_stat = array();
            $count = 0;
        }

        // Inserts a thumbnail if the album contains 1 or more images
        $visibility = $alb_thumb['visibility'];

if (!in_array($aid,$FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0)
{
if ($count > 0)
{
if ($alb_thumb['filename'])
{
$picture = &$alb_thumb;
}
else
{
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
$result = cpg_db_query($sql);
$picture = mysql_fetch_array($result);
mysql_free_result($result);
}

                                // Added by Wendell
if ($alb_thumb_2['filename'])
{
//echo "<p>".print_r(array_values($alb_thumb_2))."</p>";
$picture_2 = &$alb_thumb_2;
}
else
{
$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
$result = cpg_db_query($sql);
$picture_2 = mysql_fetch_array($result);
mysql_free_result($result);
}

//$pic_url = get_pic_url($picture, 'thumb');
$pic_url = get_pic_url($picture);
$pic_url_2 = get_pic_url($picture_2);

if (!is_image($picture['filename']))
{
$image_info = getimagesize(urldecode($pic_url));
$picture['pwidth'] = $image_info[0];
$picture['pheight'] = $image_info[1];
}

// Added by Wendell
if (!is_image($picture_2['filename']))
{
$image_info_2 = getimagesize(urldecode($pic_url_2));
$picture_2['pwidth'] = $image_info_2[0];
$picture_2['pheight'] = $image_info_2[1];
}


$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
$alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";

// Added by Wendell
$image_size_2 = compute_img_size($picture_2['pwidth'], $picture_2['pheight'], $CONFIG['alb_list_thumb_size']);
$alb_list[$alb_idx]['thumb_pic_2'] = "<img src=\"" . $pic_url_2 . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture_2['filename']}\" />";
//echo $alb_list[$alb_idx]['thumb_pic_2'];
}
else
{ // Inserts an empty thumbnail if the album contains 0 images
                // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $alb_thumb['category']);
                $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_nopic_data['thumb'] . '" ' . $cpg_nopic_data['whole'] . ' class="image" border="0" alt="" />';

// Added by Wendell
$cpg_nopic_data = cpg_get_system_thumb('nopic.jpg', $alb_thumb['category']);
$alb_list[$alb_idx]['thumb_pic_2'] = '<img src="' . $cpg_nopic_data['thumb2'] . '" ' . $cpg_nopic_data['whole'] . ' class="image" border="0" alt="" />';
            }
        }
elseif ($CONFIG['show_private'])
{
            // $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $alb_thumb['category']);
            $alb_list[$alb_idx]['thumb_pic'] = '<img src="' . $cpg_privatepic_data['thumb'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image" border="0" alt="" />';
// Added by Wendell
$cpg_privatepic_data = cpg_get_system_thumb('private.jpg', $alb_thumb['category']);
$alb_list[$alb_idx]['thumb_pic_2'] = '<img src="' . $cpg_privatepic_data['thumb2'] . '" ' . $cpg_privatepic_data['whole'] . ' class="image" border="0" alt="" />';
        }

        // Prepare everything
        if (!in_array($aid,$FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0)
{
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
        }
elseif ($CONFIG['show_private'])
{ // uncomment this else block to show private album description
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
            $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
            $alb_list[$alb_idx]['album_desc'] = bb_decode($alb_thumb['description']);
            $alb_list[$alb_idx]['pic_count'] = $count;
            $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
            $alb_list[$alb_idx]['link_pic_count'] = $link_pic_count;
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},   {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
            $alb_list[$alb_idx]['album_adm_menu'] = (GALLERY_ADMIN_MODE || (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT)) ? html_albummenu($alb_thumb['aid']) : ' ';
        }
    }

    theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
}

spacebass5000

so I have figured out that the piece of code stopping this from working is $alb_thumb_2 = &alb_thumbs_2[$alb_idx];

why is this?

donnoman


I'm not sure why you need to pass it by reference, but even when passing by reference you need the leading $

This is what you have:

$alb_thumb_2 = &alb_thumbs_2[$alb_idx];


my guess is it should be this

$alb_thumb_2 = &$alb_thumbs_2[$alb_idx];

spacebass5000

omg... *sigh*

thanks man!

I dunno why it was passed by reference either. I was simply coppying what was there and modifying it. I thought the exact same thing...

* spacebass5000 shrugs

donnoman

No worries man, I've done the EXACT same thing when passing by reference. Looked at the line 20 thousand times, was pulling my hair out, ready to throw the computer out the second story window...

Sometimes you just need a second set of unbiased eyes.