Expecting unmodified functions, find
if (is_array($alb_list)) {
foreach($alb_list as $album) {
$count ++;
$params = array('{COL_WIDTH}' => $column_width,
'{ALBUM_TITLE}' => $album['album_title'],
'{THUMB_CELL_WIDTH}' => $thumb_cell_width,
'{ALB_LINK_TGT}' => "thumbnails.php?album={$album['aid']}",
'{ALB_LINK_PIC}' => $album['thumb_pic'],
'{ADMIN_MENU}' => $album['album_adm_menu'],
'{ALB_DESC}' => $album['album_desc'],
'{ALB_INFOS}' => $album['album_info'],
'{ALB_HITS}' => $album['alb_hits'],
);
echo template_eval($album_cell, $params);
if ($count % $columns == 0 && $count < count($alb_list)) {
echo $rows_separator;
}
}
}
and replace with
global $USER;
$sort_array = array(
'na' => "filename $ASC, pid $ASC",
'nd' => "filename $DESC, pid $DESC",
'ta' => "title $ASC, pid $ASC",
'td' => "title $DESC, pid $DESC",
'da' => "pid $ASC",
'dd' => "pid $DESC",
'pa' => "position $ASC, pid $ASC",
'pd' => "position $DESC, pid $DESC",
);
$sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['default_sort_order'];
$sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['default_sort_order']];
if (is_array($alb_list)) {
foreach($alb_list as $album) {
$count ++;
$pid = mysql_result(cpg_db_query("SELECT thumb FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '{$album['aid']}' LIMIT 1"), 0);
if ($pid < 1) {
$pid = mysql_result(cpg_db_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '{$album['aid']}' ORDER BY {$sort_order} LIMIT 1"), 0);
}
$params = array('{COL_WIDTH}' => $column_width,
'{ALBUM_TITLE}' => $album['album_title'],
'{THUMB_CELL_WIDTH}' => $thumb_cell_width,
'{ALB_LINK_TGT}' => "displayimage.php?album={$album['aid']}&pid={$pid}",
'{ALB_LINK_PIC}' => $album['thumb_pic'],
'{ADMIN_MENU}' => $album['album_adm_menu'],
'{ALB_DESC}' => $album['album_desc'],
'{ALB_INFOS}' => $album['album_info'],
'{ALB_HITS}' => $album['alb_hits'],
);
echo template_eval($album_cell, $params);
if ($count % $columns == 0 && $count < count($alb_list)) {
echo $rows_separator;
}
}
}