/** * album_adm_menu() * * This has been added to keep the list_albums() function clean. * * @param integer $aid Album id * @param integer $cat Category id * * @return html_albummenu($aid) Administration menu */ function album_adm_menu($aid, $cat, $owner) { global $CONFIG, $USER_DATA, $lang_album_admin_menu; if (GALLERY_ADMIN_MODE) { return html_albummenu($aid); } static $public_album_uploads = null; if ($public_album_uploads === null) { $public_album_uploads = array(); $result = cpg_db_query("SELECT a.aid FROM {$CONFIG['TABLE_ALBUMS']} AS a INNER JOIN {$CONFIG['TABLE_PICTURES']} as p ON p.aid = a.aid WHERE uploads = 'YES' AND category < " . FIRST_USER_CAT . " AND (visibility = '0' OR visibility IN " . USER_GROUP_SET . " OR alb_password != '') AND owner_id = " . USER_ID); while ($row = $result->fetchAssoc()) { $public_album_uploads[] = $row['aid']; } $result->free(); } if (USER_ADMIN_MODE) { if ($cat == USER_ID + FIRST_USER_CAT) { return html_albummenu($aid); } if ($owner == USER_ID) { if ($CONFIG['allow_user_edit_after_cat_close'] == 0) { $result = cpg_db_query("SELECT DISTINCT alb.category FROM {$CONFIG['TABLE_ALBUMS']} AS alb INNER JOIN {$CONFIG['TABLE_CATMAP']} AS catm ON alb.category=catm.cid WHERE alb.owner = '" . $USER_DATA['user_id'] . "' AND alb.aid='{$aid}' AND catm.group_id IN (" . implode(', ', $USER_DATA['groups']) . ")"); $allowed_albums = cpg_db_fetch_rowset($result, true); if (!$allowed_albums || $allowed_albums[0]['category'] == '') { if ($CONFIG['users_can_edit_pics'] && in_array($aid, $public_album_uploads)) { return html_albummenu2($aid); } else { return "<strong>" . $lang_album_admin_menu['cat_locked'] . "</strong>"; } } } if (!$CONFIG['users_can_edit_pics']) { return html_albummenu3($aid); } else { return html_albummenu($aid); } } } if (MODERATOR_MODE && in_array($aid, $USER_DATA['allowed_albums'])) { return html_albummenu2($aid); } if (USER_CAN_UPLOAD_PICTURES && $CONFIG['users_can_edit_pics'] && in_array($aid, $public_album_uploads)) { return html_albummenu2($aid); } return ''; }
/** * album_adm_menu() * * This has been added to keep the list_albums() function clean. * * @param integer $aid Album id * @param integer $cat Category id * * @return html_albummenu($aid) Administration menu */ function album_adm_menu($aid, $cat) { global $CONFIG, $USER_DATA, $lang_album_admin_menu; //check if user is allowed to edit album if (USER_ADMIN_MODE) { //check if it is the user's gallery if ($cat == USER_ID + FIRST_USER_CAT) { return html_albummenu($aid); } //check if the user is the owner of the album $sql = "SELECT * FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid='{$aid}' AND owner='" . $USER_DATA['user_id'] . "'"; $result = cpg_db_query($sql); $check = cpg_db_fetch_rowset($result); if ($check[0] != '') { //check if admin allows editing after closing category if ($CONFIG['allow_user_edit_after_cat_close'] == 0) { //Disallowed -> Check if albums is in such a category $result = cpg_db_query("SELECT DISTINCT alb.category FROM {$CONFIG['TABLE_ALBUMS']} AS alb INNER JOIN {$CONFIG['TABLE_CATMAP']} AS catm ON alb.category=catm.cid WHERE alb.owner = '" . $USER_DATA['user_id'] . "' AND alb.aid='{$aid}' AND catm.group_id='" . $USER_DATA['group_id'] . "'"); $allowed_albums = cpg_db_fetch_rowset($result); if ($allowed_albums[0]['category'] == '') { return "<b>" . $lang_album_admin_menu['cat_locked'] . "</b>"; } } if (!$CONFIG['users_can_edit_pics']) { //return menu without edit pics button return html_albummenu3($aid); } else { //return whole menu return html_albummenu($aid); } } else { return ''; } } else { if (GALLERY_ADMIN_MODE) { return html_albummenu($aid); } else { if (in_array($alb_thumb['aid'], $USER_DATA['allowed_albums'])) { //check for moderator rights return html_albummenu2($aid); } else { return ''; } } } }
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); } }
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_cat_albums($cat = 0) { global $CONFIG, $USER, $lastup_date_fmt, $HTTP_GET_VARS, $USER_DATA, $FORBIDDEN_SET; global $lang_list_albums, $lang_errors, $cpg_show_private_album; $PAGE = 1; if ($cat == 0) { return ''; } $alb_per_page = $CONFIG['albums_per_page']; $maxTab = $CONFIG['max_tabs']; $album_filter = ''; $pic_filter = ''; if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) { $album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET); $pic_filter = ' and ' . $FORBIDDEN_SET; } $sql = "SELECT count(*) FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category = '{$cat}'" . $album_filter; $result = db_query($sql); $nbEnr = mysql_fetch_array($result); $nbAlb = $nbEnr[0]; mysql_free_result($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, 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 ORDER BY a.pos ".$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) { // test for visibility 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_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']) { $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']) : ''; } } ob_start(); theme_display_album_list_cat($alb_list, $nbAlb, $cat, $PAGE, $totalPages); $cat_albums = ob_get_contents(); ob_end_clean(); return $cat_albums; }