Example #1
0
/**
* list_albums()
*
* Get a list of albums
*/
function list_albums()
{
    global $CONFIG, $USER_DATA, $PAGE, $lang_date, $FORBIDDEN_SET, $FORBIDDEN_SET_DATA;
    global $cat;
    global $lang_list_albums, $cpg_show_private_album;
    $alb_per_page = $CONFIG['albums_per_page'];
    $album_filter = '';
    //unused code {SaWey}
    /*
    $maxTab = $CONFIG['max_tabs'];
    $pic_filter = '';
    $pic_subquery = '';
    */
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
        $album_filter = ' ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        //unused code {SaWey}
        //$pic_filter = ' ' . $FORBIDDEN_SET;
    }
    if (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) {
        $result = cpg_db_query("SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE owner = '" . $USER_DATA['user_id'] . "' " . $album_filter);
    } else {
        $result = cpg_db_query("SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '{$cat}' " . $album_filter);
    }
    $nbEnr = $result->fetchRow(true);
    $nbAlb = $nbEnr[0];
    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);
    if (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) {
        $sql = 'SELECT a.aid, a.title, a.description, a.thumb, a.keyword, category, visibility, filepath, filename, url_prefix, pwidth, pheight, a.owner FROM ' . $CONFIG['TABLE_ALBUMS'] . ' AS a LEFT JOIN ' . $CONFIG['TABLE_PICTURES'] . ' AS p ON a.thumb=p.pid WHERE a.owner=' . $USER_DATA['user_id'] . $album_filter . ' ORDER BY a.category DESC , a.pos ' . $limit;
        $alb_thumbs_q = cpg_db_query($sql);
        $alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q, true);
        //query for the category names
        $cat_name_sql = "SELECT CONCAT(a.title, '" . $lang_list_albums['from_category'] . "<i>', c.name, '</i>') AS cat_name FROM " . $CONFIG['TABLE_ALBUMS'] . " AS a LEFT JOIN " . $CONFIG['TABLE_CATEGORIES'] . " AS c ON a.category=c.cid WHERE a.owner=" . $USER_DATA['user_id'] . " ORDER BY a.category DESC , a.pos " . $limit;
        $cat_name_q = cpg_db_query($cat_name_sql);
        $cat_names = cpg_db_fetch_rowset($cat_name_q, true);
        //replace names in $alb_thumbs array
        foreach ($alb_thumbs as $key => $value) {
            if ($cat_names[$key]['cat_name'] != '') {
                $alb_thumbs[$key]['title'] = $cat_names[$key]['cat_name'];
            }
            $current_albums[] = $value['aid'];
        }
        //This query will fetch album stats and keywords 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, a.alb_hits" . " FROM {$CONFIG['TABLE_ALBUMS']} AS a " . " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved = 'YES' " . " WHERE a.owner = {$USER_DATA['user_id']} {$album_filter} AND a.aid IN (" . implode(', ', $current_albums) . ") GROUP BY a.aid";
        $alb_stats_q = cpg_db_query($sql);
        $alb_stats = cpg_db_fetch_rowset($alb_stats_q, true);
    } else {
        $sort_order = cpg_album_sort_order('a.');
        $sql = "SELECT a.aid, a.title, a.description, a.thumb, a.keyword, category, visibility, filepath, filename, url_prefix, pwidth, pheight, a.owner " . " FROM {$CONFIG['TABLE_ALBUMS']} AS a " . " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.thumb=p.pid " . " WHERE a.category = {$cat} {$album_filter} " . " ORDER BY {$sort_order} {$limit}";
        $alb_thumbs_q = cpg_db_query($sql);
        $alb_thumbs = cpg_db_fetch_rowset($alb_thumbs_q, true);
        //This query will fetch album stats and keywords 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, a.alb_hits" . " FROM {$CONFIG['TABLE_ALBUMS']} AS a " . " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.aid = p.aid AND p.approved = 'YES' " . " WHERE a.category = {$cat} {$album_filter} GROUP BY a.aid " . " ORDER BY {$sort_order} {$limit}";
        $alb_stats_q = cpg_db_query($sql);
        $alb_stats = cpg_db_fetch_rowset($alb_stats_q, true);
    }
    $disp_album_count = count($alb_thumbs);
    $approved = 'AND approved=\'YES\'';
    $forbidden_set_string = count($FORBIDDEN_SET_DATA) > 0 ? ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')' : '';
    $last_pids = array();
    $last_pid_data = array();
    foreach ($alb_stats as $key => $value) {
        $cross_ref[$value['aid']] =& $alb_stats[$key];
        if ($CONFIG['link_pic_count'] == 1 || $value['pic_count'] == 0) {
            if (!empty($value['keyword'])) {
                $keyword = $value['keyword'] ? "AND (keywords like '%" . addslashes($value['keyword']) . "%' {$forbidden_set_string} )" : '';
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload " . " FROM {$CONFIG['TABLE_PICTURES']} " . " WHERE ((aid != '{$value['aid']}' {$forbidden_set_string}) {$keyword}) {$approved}";
                $result = cpg_db_query($query);
                $link_stat = $result->fetchAssoc(true);
                $alb_stats[$key]['link_pic_count'] = $link_stat['link_pic_count'];
                $alb_stats[$key]['last_pid'] = $alb_stats[$key]['last_pid'] > $link_stat['link_last_pid'] ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
                if ($CONFIG['link_last_upload'] && $link_stat['link_pic_count'] > 0) {
                    $alb_stats[$key]['last_upload'] = $alb_stats[$key]['last_upload'] > $link_stat['link_last_upload'] ? $alb_stats[$key]['last_upload'] : $link_stat['link_last_upload'];
                }
            }
        }
        if ($alb_stats[$key]['last_pid']) {
            $last_pids[] = $alb_stats[$key]['last_pid'];
        }
    }
    if (count($last_pids)) {
        $result = cpg_db_query("SELECT pid, filepath, filename, url_prefix, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (" . implode(',', $last_pids) . ")");
        while ($row = $result->fetchAssoc()) {
            $last_pid_data[$row['pid']] = $row;
            unset($last_pid_data[$row['pid']]['pid']);
        }
        $result->free();
    }
    unset($last_pids);
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$alb_idx];
        $aid = $alb_thumb['aid'];
        if (isset($cross_ref[$aid])) {
            $alb_stat = $cross_ref[$aid];
            $count = $alb_stat['pic_count'];
            $alb_hits = $alb_stat['alb_hits'];
        } else {
            $alb_stat = array();
            $count = 0;
            $alb_hits = 0;
        }
        // Inserts a thumbnail if the album contains 1 or more images
        //unused code {SaWey}
        //$visibility = $alb_thumb['visibility'];
        $keyword = $alb_thumb['keyword'] ? "OR (keywords like '%" . addslashes($alb_thumb['keyword']) . "%' {$forbidden_set_string} )" : '';
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            if ($count > 0 || !empty($alb_stats[$alb_idx]['link_pic_count'])) {
                if (!empty($alb_thumb['filename'])) {
                    $picture =& $alb_thumb;
                } elseif ($alb_thumb['thumb'] < 0) {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE ((aid = '{$alb_thumb['aid']}' {$forbidden_set_string}) {$keyword}) {$approved} " . "ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = $result->fetchAssoc(true);
                } else {
                    $picture = $last_pid_data[$alb_stat['last_pid']];
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                //$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
                if (array_key_exists('system_icon', $picture) && $picture['system_icon'] == true) {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image thumbnail\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } 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 thumbnail" 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 thumbnail" border="0" alt="" />';
        }
        // Prepare everything
        if (!in_array($aid, $FORBIDDEN_SET_DATA) || $CONFIG['allow_private_albums'] == 0) {
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $last_upload_date = $count || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
            $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]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = theme_album_info($count, $link_pic_count, $last_upload_date);
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat, $alb_thumb['owner']);
        } elseif ($CONFIG['show_private']) {
            // uncomment this else block to show private album description
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $last_upload_date = $count || $CONFIG['link_pic_count'] && $link_pic_count > 0 ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
            $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]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $alb_list[$alb_idx]['album_info'] = theme_album_info($count, $link_pic_count, $last_upload_date);
            $alb_list[$alb_idx]['album_adm_menu'] = album_adm_menu($alb_thumb['aid'], $cat, $alb_thumb['owner']);
        }
    }
    theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
}
Example #2
0
/**
* 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;
    if (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) {
        $result = cpg_db_query("SELECT count(aid) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE owner = '" . $USER_DATA['user_id'] . "'" . $album_filter);
    } else {
        $result = cpg_db_query("SELECT count(aid) 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;
    if (USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT) {
        $sql = 'SELECT a.aid, a.title, a.description, a.thumb, 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 a.owner=' . $USER_DATA['user_id'] . $album_filter . ' ORDER BY a.category DESC , 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);
        //query for the category names
        $cat_name_sql = "SELECT CONCAT(a.title, '" . $lang_list_albums['from_categorie'] . "<i>', c.name, '</i>') FROM " . $CONFIG['TABLE_ALBUMS'] . " AS a LEFT JOIN " . $CONFIG['TABLE_CATEGORIES'] . " AS c ON a.category=c.cid WHERE a.owner=" . $USER_DATA['user_id'] . " ORDER BY a.category DESC , a.pos " . $limit;
        $cat_name_q = cpg_db_query($cat_name_sql);
        $cat_names = cpg_db_fetch_rowset($cat_name_q);
        mysql_free_result($cat_name_q);
        //replace names in $alb_thumbs array
        foreach ($alb_thumbs as $key => $value) {
            if ($cat_names[$key][0] != "") {
                $alb_thumbs[$key]['title'] = $cat_names[$key][0];
            }
        }
    } else {
        $sql = 'SELECT a.aid, a.title, a.description, a.thumb, 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 a.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);
    }
    $disp_album_count = count($alb_thumbs);
    $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, a.alb_hits" . " 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, max(pid) AS link_last_pid\n                      FROM {$CONFIG['TABLE_PICTURES']}\n                        WHERE aid != {$value['aid']} AND\n                        keywords LIKE '%{$value['keyword']}%' AND\n                        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'];
                $alb_stats[$key]['last_pid'] = $alb_stats[$key]['last_pid'] ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
            }
        }
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$alb_idx];
        $aid = $alb_thumb['aid'];
        if (isset($cross_ref[$aid])) {
            $alb_stat = $cross_ref[$aid];
            $count = $alb_stat['pic_count'];
            $alb_hits = $alb_stat['alb_hits'];
        } else {
            $alb_stat = array();
            $count = 0;
            $alb_hits = 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 || $alb_stats[$alb_idx]['link_pic_count'] > 0) {
                if ($alb_thumb['filename']) {
                    $picture =& $alb_thumb;
                } elseif ($alb_thumb['thumb'] < 0) {
                    //$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '{$alb_thumb['aid']}' ORDER BY RAND() LIMIT 0,1";
                    // OVI
                    $sql = "SELECT pid, filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '{$alb_thumb['aid']}' ORDER BY RAND() LIMIT 0,1";
                    $result = cpg_db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                } else {
                    //$sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE pid='{$alb_stat['last_pid']}'";
                    // OVI
                    $sql = "SELECT pid, 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);
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = cpg_getimagesize(urldecode($pic_url));
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[1];
                }
                //thumb cropping
                //$image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
                if ($picture['system_icon'] == 'true') {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], true, 'cat_thumb');
                } else {
                    $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], false, 'cat_thumb');
                }
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . $pic_url . "\" class=\"image\" {$image_size['geom']} border=\"0\" alt=\"{$picture['filename']}\" />";
            } 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="" />';
            }
        } 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="" />';
        }
        // 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]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $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'] = album_adm_menu($alb_thumb['aid'], $cat);
        } 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]['alb_hits'] = sprintf($lang_list_albums['alb_hits'], $alb_hits);
            $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'] = album_adm_menu($alb_thumb['aid'], $cat);
        }
    }
    theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
}
Example #3
0
function list_cat_albums($cat = 0, $buffer = true)
{
    global $db, $CONFIG, $USER, $PAGE, $USER_DATA, $CPG_M_DIR;
    if ($cat == 0 && $buffer) {
        return '';
    }
    $cat = intval($cat);
    $alb_per_page = $CONFIG['albums_per_page'];
    $maxTab = $CONFIG['max_tabs'];
    $visible = '';
    if (!USER_IS_ADMIN && !$CONFIG['show_private']) {
        $visible = "AND " . VIS_GROUPS;
        // NEW gtroll
        $tmpvis = explode(',', USER_IN_GROUPS);
        $vis[0] = 0;
        foreach ($tmpvis as $dummy => $group) {
            $vis[$group] = $group;
        }
        unset($tmpvis);
    }
    /*
    $result = $db->sql_query("SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cat $visible",false,__FILE__,__LINE__);
    $nbEnr = $db->sql_fetchrow($result);
    $nbAlb = $nbEnr[0];
    $db->sql_freeresult($result);
    */
    //$nbAlb = cpg_tablecount($CONFIG['TABLE_ALBUMS']." WHERE category = $cat $visible", 'count(*)',__FILE__, __LINE__);
    $nbAlb = 0;
    foreach (get_albums_data() as $row) {
        if ($row['category'] != $cat) {
            continue;
        }
        if (isset($vis) && !isset($vis[$row['visibility']])) {
            continue;
        }
        $nbAlb++;
    }
    if (!$nbAlb) {
        return '';
    }
    $totalPages = ceil($nbAlb / $alb_per_page);
    if (isset($_GET['page'])) {
        $PAGE = max(intval($_GET['page']), 1);
    }
    //if ($PAGE > $totalPages || $cat != $_GET['cat']) $PAGE = 1;
    if ($PAGE > $totalPages) {
        $PAGE = 1;
    }
    $lower_limit = ($PAGE - 1) * $alb_per_page;
    $upper_limit = min($nbAlb, $PAGE * $alb_per_page);
    $sql = "SELECT a.aid, a.title, a.description, visibility, filepath, " . "filename, url_prefix, pwidth, pheight " . "FROM {$CONFIG['TABLE_ALBUMS']} as a " . "LEFT JOIN {$CONFIG['TABLE_PICTURES']} as p ON thumb=pid " . "WHERE category = '{$cat}' {$visible} ORDER BY pos " . "LIMIT " . ($upper_limit - $lower_limit) . " OFFSET " . $lower_limit;
    $alb_thumbs = $db->sql_ufetchrowset($sql, SQL_BOTH, __FILE__, __LINE__);
    $disp_album_count = count($alb_thumbs);
    $album_set = '';
    foreach ($alb_thumbs as $value) {
        $album_set .= $value['aid'] . ', ';
    }
    $album_set = '(' . substr($album_set, 0, -2) . ')';
    $sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE aid IN {$album_set} AND approved = '1' " . "GROUP BY aid";
    if ($alb_stats = $db->sql_ufetchrowset($sql, SQL_BOTH)) {
        foreach ($alb_stats as $key => $value) {
            $cross_ref[$value['aid']] =& $alb_stats[$key];
        }
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$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 ($visibility == '0' || $visibility == FIRST_USER_CAT + USER_ID || $visibility == $USER_DATA['group_id'] || USER_IS_ADMIN || user_ingroup($visibility, $USER_DATA['user_group_list_cp'])) {
            if ($count > 0) {
                // Inserts a thumbnail if the album contains 1 or more images
                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 = $db->sql_query($sql, false, __FILE__, __LINE__);
                    $picture = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                }
                $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . get_pic_url($picture, 'thumb') . "\" {$image_size['geom']} title=\"" . $alb_thumb['title'] . "\" alt=\"" . $alb_thumb['title'] . "\" border=\"0\" class=\"image\" />";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"{$CPG_M_DIR}/images/nopic.jpg\" {$image_size['geom']} alt=\"" . NO_IMG_TO_DISPLAY . "\" title=\"" . NO_IMG_TO_DISPLAY . "\" border=\"0\" class=\"image\" />";
            }
        } elseif ($CONFIG['show_private']) {
            $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"{$CPG_M_DIR}/images/private.jpg\" {$image_size['geom']} alt=\"" . MEMBERS_ONLY . "\" title=\"" . MEMBERS_ONLY . "\" border=\"0\" class=\"image\" />";
        }
        // Prepare everything
        $last_upload_date = $count ? localised_date($alb_stat['last_upload'], LASTUP_DATE_FMT) : '';
        $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
        $alb_list[$alb_idx]['album_title'] = $alb_thumb['title'];
        $alb_list[$alb_idx]['album_desc'] = decode_bbcode($alb_thumb['description']);
        $alb_list[$alb_idx]['pic_count'] = $count;
        $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
        $alb_list[$alb_idx]['album_info'] = sprintf(N_PICTURES, $count) . ($count ? sprintf(LAST_ADDED, $last_upload_date) : "");
        $alb_list[$alb_idx]['album_adm_menu'] = GALLERY_ADMIN_MODE || USER_ADMIN_MODE && $cat == USER_ID + FIRST_USER_CAT ? html_albummenu($alb_thumb['aid']) : '';
    }
    if ($buffer) {
        ob_start();
        theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
        $cat_albums = ob_get_contents();
        ob_end_clean();
        return $cat_albums;
    } else {
        theme_display_album_list($alb_list, $nbAlb, $cat, $PAGE, $totalPages);
    }
}
Example #4
0
function list_albums()
{
    global $xoopsModuleConfig, $USER, $PAGE, $lastup_date_fmt, $_GET, $USER_DATA;
    global $xoopsDB;
    $myts =& MyTextSanitizer::getInstance();
    // MyTextSanitizer object
    $cat = isset($_GET['cat']) ? $_GET['cat'] : 0;
    $alb_per_page = $xoopsModuleConfig['albums_per_page'];
    $maxTab = $xoopsModuleConfig['max_tabs'];
    $result = $xoopsDB->query("SELECT count(*) FROM " . $xoopsDB->prefix("xcgal_albums") . " WHERE category = '{$cat}'");
    $nbEnr = $xoopsDB->fetchArray($result);
    $nbAlb = $nbEnr['count(*)'];
    $xoopsDB->freeRecordSet($result);
    if ($nbAlb == 0) {
        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, description, visibility, filepath, " . "                filename, url_prefix, pwidth, pheight " . "FROM " . $xoopsDB->prefix("xcgal_albums") . " as a " . "LEFT JOIN " . $xoopsDB->prefix("xcgal_pictures") . " as p ON thumb=pid " . "WHERE category = '{$cat}' ORDER BY pos " . "{$limit}";
    $alb_thumbs_q = $xoopsDB->query($sql);
    $alb_thumbs = db_fetch_rowset($alb_thumbs_q);
    $xoopsDB->freeRecordSet($alb_thumbs_q);
    $disp_album_count = count($alb_thumbs);
    $album_set = '';
    foreach ($alb_thumbs as $value) {
        $album_set .= $value['aid'] . ', ';
    }
    $album_set = '(' . substr($album_set, 0, -2) . ')';
    $sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload " . "FROM " . $xoopsDB->prefix("xcgal_pictures") . " " . "WHERE aid IN {$album_set} AND approved = 'YES' " . "GROUP BY aid";
    $alb_stats_q = $xoopsDB->query($sql);
    $alb_stats = db_fetch_rowset($alb_stats_q);
    $xoopsDB->freeRecordSet($alb_stats_q);
    foreach ($alb_stats as $key => $value) {
        $cross_ref[$value['aid']] =& $alb_stats[$key];
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$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
        if ($count > 0) {
            $visibility = $alb_thumb['visibility'];
            if ($visibility == '0' || $visibility == FIRST_USER_CAT + USER_ID || is_array($USER_DATA['group_id']) && in_array($visibility, $USER_DATA['group_id'])) {
                if ($alb_thumb['filename']) {
                    $picture =& $alb_thumb;
                } else {
                    $sql = "SELECT filepath, filename, url_prefix, pwidth, pheight " . "FROM " . $xoopsDB->prefix("xcgal_pictures") . " " . "WHERE pid='{$alb_stat['last_pid']}'";
                    $result = $xoopsDB->query($sql);
                    $picture = $xoopsDB->fetchArray($result);
                    $xoopsDB->freeRecordSet($result);
                }
                $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $xoopsModuleConfig['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"" . get_pic_url($picture, 'thumb') . "\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
            } else {
                $image_size = compute_img_size(100, 75, $xoopsModuleConfig['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/private.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
            }
        } else {
            $image_size = compute_img_size(100, 75, $xoopsModuleConfig['alb_list_thumb_size']);
            $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/nopic.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
        }
        // Prepare everything
        $last_upload_date = $count ? formatTimestamp($alb_stat['last_upload'], 'm') : '';
        $alb_list[$alb_idx]['aid'] = $alb_thumb['aid'];
        $alb_list[$alb_idx]['album_title'] = $myts->makeTboxData4Show($alb_thumb['title']);
        $alb_list[$alb_idx]['album_desc'] = $myts->makeTareaData4Show($alb_thumb['description'], 1);
        $alb_list[$alb_idx]['pic_count'] = $count;
        $alb_list[$alb_idx]['last_upl'] = $last_upload_date;
        #                $alb_list[$alb_idx]['album_info']     = sprintf(_MD_NPICS, $count).($count ? sprintf(_MD_INDEX_LASTADD, $last_upload_date) : "" );
        $alb_list[$alb_idx]['album_info'] = sprintf(_MD_NPICS, $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);
}
function list_albums()
{
    global $CONFIG, $USER, $USER_DATA, $PAGE, $lastup_date_fmt, $FORBIDDEN_SET;
    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 = 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, 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 = db_query($sql);
    $alb_thumbs = db_fetch_rowset($alb_thumbs_q);
    mysql_free_result($alb_thumbs_q);
    $disp_album_count = count($alb_thumbs);
    $album_set = '';
    foreach ($alb_thumbs as $value) {
        $album_set .= $value['aid'] . ', ';
    }
    $album_set = '(' . substr($album_set, 0, -2) . ')';
    $sql = "SELECT aid, count(pid) as pic_count, max(pid) as last_pid, max(ctime) as last_upload " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE aid IN {$album_set} AND approved = 'YES' " . "GROUP BY aid";
    $alb_stats_q = db_query($sql);
    $alb_stats = 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];
    }
    for ($alb_idx = 0; $alb_idx < $disp_album_count; $alb_idx++) {
        $alb_thumb =& $alb_thumbs[$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 ($visibility == '0' || $visibility == FIRST_USER_CAT + USER_ID || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums'] || $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 = db_query($sql);
                    $picture = mysql_fetch_array($result);
                    mysql_free_result($result);
                }
                $pic_url = get_pic_url($picture, 'thumb');
                if (!is_image($picture['filename'])) {
                    $image_info = getimagesize($pic_url);
                    $picture['pwidth'] = $image_info[0];
                    $picture['pheight'] = $image_info[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']}\">";
            } else {
                // Inserts an empty thumbnail if the album contains 0 images
                $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
                $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/nopic.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
            }
        } elseif ($CONFIG['show_private']) {
            $image_size = compute_img_size(100, 75, $CONFIG['alb_list_thumb_size']);
            $alb_list[$alb_idx]['thumb_pic'] = "<img src=\"images/private.jpg\" {$image_size['geom']} alt=\"\" border=\"0\" class=\"image\" />";
        }
        // Prepare everything
        if ($visibility == '0' || $visibility == FIRST_USER_CAT + USER_ID || in_array($visibility, $USER_DATA['groups']) || $USER_DATA['can_see_all_albums'] || $CONFIG['allow_private_albums'] == 0) {
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lastup_date_fmt) : '';
            $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]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
            $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) : '';
            $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]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");
            $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);
}