$query = "SELECT {$criteria} FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = {$pid}"; $result = cpg_db_query($query); $criteria_pid = mysql_result($result, 0); mysql_free_result($result); if ($direction == "ASC") { $direction = "<"; } elseif ($direction == "DESC") { $direction = ">"; } else { $direction = ""; } $sort_order = "{$criteria} {$direction} '{$criteria_pid}' OR {$criteria} = '{$criteria_pid}' AND pid < {$pid}"; $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p\n {$join_user_table}\n WHERE {$sql}\n AND ({$sort_order})"; $result = cpg_db_query($query); list($pos) = mysql_fetch_row($result); mysql_free_result($result); } else { $query = "SELECT p.*{$user_column} FROM {$CONFIG['TABLE_PICTURES']} AS p\n {$join_user_table}\n WHERE " . $sql; $temp = str_replace("SELECT p.*{$user_column}", 'SELECT COUNT(*)', $query); $result = cpg_db_query($temp); $row = mysql_fetch_row($result); $count = $row[0]; $query .= " ORDER BY {$sort_order} {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset); } } }
/** * get_pic_data() * * @param $album * @param $count * @param $album_name * @param integer $limit1 * @param integer $limit2 * @param boolean $set_caption * @return **/ function get_pic_data($album, &$count, &$album_name, $limit1 = -1, $limit2 = -1, $set_caption = true) { global $USER, $CONFIG, $ALBUM_SET, $META_ALBUM_SET, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $HTML_SUBST, $THEME_DIR, $FAVPICS, $FORBIDDEN_SET_DATA, $USER_DATA, $lang_common; global $album_date_fmt, $lastcom_date_fmt, $lastup_date_fmt, $lasthit_date_fmt, $cat; global $lang_get_pic_data, $lang_meta_album_names, $lang_errors; $sort_array = array('na' => 'filename ASC', 'nd' => 'filename DESC', 'ta' => 'title ASC', 'td' => 'title DESC', 'da' => 'pid ASC', 'dd' => 'pid DESC', 'pa' => 'position ASC', 'pd' => 'position 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']]; $limit = $limit1 != -1 ? ' LIMIT ' . $limit1 : ''; $limit .= $limit2 != -1 ? ' ,' . $limit2 : ''; if ($limit2 == 1) { $select_columns = '*'; } else { $select_columns = 'pid, filepath, filename, url_prefix, filesize, pwidth, pheight, ctime, aid, keywords, title'; } if (count($FORBIDDEN_SET_DATA) > 0) { $forbidden_set_string = " AND aid NOT IN (" . implode(",", $FORBIDDEN_SET_DATA) . ")"; } else { $forbidden_set_string = ''; } // Keyword if (!empty($CURRENT_ALBUM_KEYWORD)) { $keyword = "OR (keywords like '%{$CURRENT_ALBUM_KEYWORD}%' {$forbidden_set_string} )"; } else { $keyword = ''; } // Regular albums if (is_numeric($album)) { $album_name_keyword = get_album_name($album); $album_name = $album_name_keyword['title']; $album_keyword = addslashes($album_name_keyword['keyword']); if (!empty($album_keyword)) { $keyword = "OR (keywords like '%{$album_keyword}%' {$forbidden_set_string} )"; } else { $keyword = ''; } if (is_array($USER_DATA['allowed_albums']) && in_array($album, $USER_DATA['allowed_albums'])) { $approved = ''; } else { $approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\''; } $approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\''; $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE ((aid='{$album}' {$forbidden_set_string} ) {$keyword}) {$approved} {$ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); if ($select_columns != '*') { $select_columns .= ', title, caption,hits,owner_id,owner_name,pic_rating,votes'; } $query = "SELECT {$select_columns} from {$CONFIG['TABLE_PICTURES']} WHERE ((aid='{$album}' {$forbidden_set_string} ) {$keyword}) {$approved} {$ALBUM_SET} ORDER BY {$sort_order} {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); // Set picture caption if ($CONFIG['display_thumbnail_rating'] == 1) { if ($set_caption) { build_caption($rowset, array('pic_rating')); } } else { if ($set_caption) { build_caption($rowset); } } $rowset = CPGPluginAPI::filter('thumb_caption_regular', $rowset); return $rowset; } // Meta albums switch ($album) { case 'lastcom': // Last comments if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $album_name = $lang_meta_album_names['lastcom'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['lastcom']; } // Replacing the AND in ALBUM_SET with AND ( if ($META_ALBUM_SET) { $TMP_SET = "AND (" . substr($META_ALBUM_SET, 3); } else { $TMP_SET = "AND (1"; } $query = "SELECT COUNT({$CONFIG['TABLE_PICTURES']}.pid) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']} WHERE {$CONFIG['TABLE_PICTURES']}.approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid AND {$CONFIG['TABLE_COMMENTS']}.approval = 'YES' {$TMP_SET} {$keyword})"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); $select_columns = '*'; //allows building any data into any thumbnail caption if ($select_columns == '*') { $select_columns = 'p.*, msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid'; } else { $select_columns = str_replace('pid', 'c.pid', $select_columns) . ', msg_id, author_id, msg_author, UNIX_TIMESTAMP(msg_date) as msg_date, msg_body, aid'; } $TMP_SET = str_replace($CONFIG['TABLE_PICTURES'], 'p', $TMP_SET); $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid AND c.approval = 'YES' {$TMP_SET} {$keyword}) ORDER by msg_id DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('msg_body', 'msg_date')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastcom', $rowset); return $rowset; break; case 'lastcomby': // Last comments by a specific user if (isset($USER['uid'])) { $uid = (int) $USER['uid']; } else { $uid = -1; } $user_name = get_username($uid); if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $album_name = $lang_meta_album_names['lastcom'] . ' - ' . $CURRENT_CAT_NAME . ' - ' . $user_name; } else { $album_name = $lang_meta_album_names['lastcom'] . ' - ' . $user_name; } $query = "SELECT COUNT({$CONFIG['TABLE_PICTURES']}.pid) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND author_id = '{$uid}' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); $select_columns = '*, UNIX_TIMESTAMP(msg_date) AS msg_date'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND author_id = '{$uid}' AND c.pid = p.pid {$META_ALBUM_SET} ORDER by msg_id DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('msg_body', 'msg_date')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastcomby', $rowset); return $rowset; break; case 'lastup': // Last uploads if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['lastup'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['lastup']; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*' ) $select_columns .= ',title, caption, owner_id, owner_name, aid'; $select_columns = '*'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' {$META_ALBUM_SET} ORDER BY pid DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastup', $rowset); return $rowset; break; case 'lastupby': // Last uploads by a specific user if (isset($USER['uid'])) { $uid = (int) $USER['uid']; } else { $uid = -1; } $user_name = get_username($uid); if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['lastup'] . ' - ' . $CURRENT_CAT_NAME . ' - ' . $user_name; } else { $album_name = $lang_meta_album_names['lastup'] . ' - ' . $user_name; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND owner_id = '{$uid}' {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*' ) $select_columns .= ', owner_id, owner_name, aid'; $select_columns = '*'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND owner_id = '{$uid}' {$META_ALBUM_SET} ORDER BY pid DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastupby', $rowset); return $rowset; break; case 'topn': // Most viewed pictures if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['topn'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['topn']; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND hits > 0 {$META_ALBUM_SET} {$keyword}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*') $select_columns .= ', hits, aid, filename, owner_id, owner_name'; $select_columns = '*'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'AND hits > 0 {$META_ALBUM_SET} {$keyword} ORDER BY hits DESC, filename {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('hits')); } $rowset = CPGPluginAPI::filter('thumb_caption_topn', $rowset); return $rowset; break; case 'toprated': // Top rated pictures if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['toprated'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['toprated']; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*') $select_columns .= ', pic_rating, votes, aid, owner_id, owner_name'; $select_columns = '*'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' {$META_ALBUM_SET} ORDER BY pic_rating DESC, votes DESC, pid DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('pic_rating')); } $rowset = CPGPluginAPI::filter('thumb_caption_toprated', $rowset); return $rowset; break; case 'lasthits': // Last viewed pictures if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['lasthits'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['lasthits']; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' and hits > 0 {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*') $select_columns .= ', UNIX_TIMESTAMP(mtime) as mtime, aid, hits, lasthit_ip, owner_id, owner_name'; $select_columns = '*, UNIX_TIMESTAMP(mtime) as mtime'; //allows building any data into any thumbnail caption $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' and hits > 0 {$META_ALBUM_SET} ORDER BY mtime DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('mtime', 'hits')); } $rowset = CPGPluginAPI::filter('thumb_caption_lasthits', $rowset); return $rowset; break; case 'random': // Random pictures if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['random'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['random']; } $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $pic_count = $nbEnr[0]; mysql_free_result($result); //if($select_columns != '*') $select_columns .= ', aid, owner_id, owner_name'; $select_columns = '*'; //allows building any data into any thumbnail caption // if we have more than 1000 pictures, we limit the number of picture returned // by the SELECT statement as ORDER BY RAND() is time consuming /* Commented out due to image not found bug if ($pic_count > 1000) { $result = cpg_db_query("SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES'"); $nbEnr = mysql_fetch_array($result); $total_count = $nbEnr[0]; mysql_free_result($result); $granularity = floor($total_count / RANDPOS_MAX_PIC); $cor_gran = ceil($total_count / $pic_count); srand(time()); for ($i=1; $i<= $cor_gran; $i++) $random_num_set =rand(0, $granularity).', '; $random_num_set = substr($random_num_set,0, -2); $result = cpg_db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE randpos IN ($random_num_set) AND approved = 'YES' $ALBUM_SET ORDER BY RAND() LIMIT $limit2"); } else { */ $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' {$META_ALBUM_SET} ORDER BY RAND() LIMIT {$limit2}"; $result = cpg_db_query($query); $rowset = array(); while ($row = mysql_fetch_array($result)) { $rowset[-$row['pid']] = $row; } mysql_free_result($result); if ($set_caption) { build_caption($rowset); } $rowset = CPGPluginAPI::filter('thumb_caption_random', $rowset); return $rowset; break; case 'search': // Search results if (isset($USER['search']['search'])) { $search_string = $USER['search']['search']; } else { $search_string = ''; } if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['search'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['search'] . ' - "' . strtr($search_string, $HTML_SUBST) . '"'; } include 'include/search.inc.php'; $rowset = CPGPluginAPI::filter('thumb_caption_search', $rowset); return $rowset; break; case 'lastalb': // Last albums to which uploads if ($META_ALBUM_SET && $CURRENT_CAT_NAME) { $album_name = $lang_meta_album_names['lastalb'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = $lang_meta_album_names['lastalb']; } $META_ALBUM_SET = str_replace("aid", $CONFIG['TABLE_PICTURES'] . ".aid", $META_ALBUM_SET); $query = "SELECT count({$CONFIG['TABLE_ALBUMS']}.aid) FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' {$META_ALBUM_SET} GROUP BY {$CONFIG['TABLE_PICTURES']}.aid"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); $query = "SELECT *,{$CONFIG['TABLE_ALBUMS']}.title AS title,{$CONFIG['TABLE_ALBUMS']}.aid AS aid FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' {$META_ALBUM_SET} GROUP BY {$CONFIG['TABLE_PICTURES']}.aid ORDER BY {$CONFIG['TABLE_PICTURES']}.ctime DESC {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastalb', $rowset); return $rowset; break; case 'favpics': // Favourite Pictures $album_name = $lang_meta_album_names['favpics']; $rowset = array(); if (count($FAVPICS) > 0) { $favs = implode(",", $FAVPICS); $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND pid IN ({$favs}) {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); $select_columns = '*'; $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND pid IN ({$favs}) {$META_ALBUM_SET} {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } } $rowset = CPGPluginAPI::filter('thumb_caption_favpics', $rowset); return $rowset; break; case 'datebrowse': // Browsing by uploading date $date = isset($_GET['date']) ? cpgValidateDate($_GET['date']) : null; $album_name = $lang_common['date'] . ': ' . $date; $rowset = array(); $query = "SELECT COUNT(pid) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "' {$META_ALBUM_SET}"; $result = cpg_db_query($query); $nbEnr = mysql_fetch_array($result); $count = $nbEnr[0]; mysql_free_result($result); $select_columns = '*'; $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "' {$META_ALBUM_SET} {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } return $rowset; break; default: // Invalid meta album cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__); } }
function annotate_meta_album($meta) { global $CONFIG, $CURRENT_CAT_NAME, $RESTRICTEDWHERE, $lang_plugin_annotate; require_once './plugins/annotate/init.inc.php'; $annotate_init_array = annotate_initialize(); $lang_plugin_annotate = $annotate_init_array['language']; $annotate_icon_array = $annotate_init_array['icon']; switch ($meta['album']) { case 'lastnotes': $album_name = $annotate_icon_array['annotate'] . ' ' . $lang_plugin_annotate['lastnotes']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT DISTINCT n.pid \n FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate AS n \n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON n.pid = p.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); $query = "SELECT MAX(nid) AS nid\n FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate AS n \n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON n.pid = p.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}\n GROUP BY n.pid \n ORDER BY n.nid DESC {$meta['limit']}"; $result = cpg_db_query($query); $latest_nids_array = array(); while ($row = mysql_fetch_assoc($result)) { $latest_nids_array[] = $row['nid']; } mysql_free_result($result); $query = "SELECT *, user_time AS msg_date\n FROM {$CONFIG['TABLE_PICTURES']} AS p\n INNER JOIN {$CONFIG['TABLE_PREFIX']}plugin_annotate AS n ON p.pid = n.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND n.nid IN (" . implode(', ', $latest_nids_array) . ")\n ORDER BY n.nid DESC"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('msg_date')); break; case 'shownotes': if (annotate_get_level('permissions') < 1) { global $lang_errors; cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__); } $superCage = Inspekt::makeSuperCage(); $note = $superCage->get->keyExists('note') ? $superCage->get->getRaw('note') : $superCage->cookie->getRaw($CONFIG['cookie_name'] . 'note'); setcookie($CONFIG['cookie_name'] . 'note', $note); $album_name = cpg_fetch_icon('search', 2) . ' ' . $lang_plugin_annotate['shownotes'] . " '{$note}'"; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $note = addslashes(addslashes($note)); $query = "SELECT p.pid FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON p.aid = r.aid INNER JOIN {$CONFIG['TABLE_PREFIX']}plugin_annotate n ON p.pid = n.pid {$RESTRICTEDWHERE} AND approved = 'YES' AND n.note = '{$note}' GROUP BY p.pid"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); $query = "SELECT p.*, r.title FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON p.aid = r.aid INNER JOIN {$CONFIG['TABLE_PREFIX']}plugin_annotate n ON p.pid = n.pid {$RESTRICTEDWHERE} AND approved = 'YES' AND n.note = '{$note}' GROUP BY p.pid ORDER BY p.pid DESC {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset); break; default: return $meta; } $meta['album_name'] = $album_name; $meta['count'] = $count; $meta['rowset'] = $rowset; return $meta; }
/** * get_pic_data() * * @param $album * @param $count * @param $album_name * @param integer $limit1 * @param integer $limit2 * @param boolean $set_caption * @return **/ function get_pic_data($album, &$count, &$album_name, $limit1 = -1, $limit2 = -1, $set_caption = true, $mode = '') { global $USER, $CONFIG, $CURRENT_CAT_NAME, $CURRENT_ALBUM_KEYWORD, $FAVPICS, $FORBIDDEN_SET_DATA, $FORBIDDEN_SET, $USER_DATA; global $cat; global $lang_common, $lang_meta_album_names, $lang_errors; global $RESTRICTEDWHERE; static $album_name_keyword = '', $pic_count = null; $superCage = Inspekt::makeSuperCage(); $limit = $limit1 != -1 ? ' LIMIT ' . $limit1 : ''; $limit .= $limit2 != -1 ? ' ,' . $limit2 : ''; if ($mode == 'pidonly') { $select_column_list = array('r.pid'); } elseif ($mode == 'filmstrip') { $select_column_list = array('r.pid', 'r.aid', 'filepath', 'filename', 'url_prefix', 'pwidth', 'pheight', 'filesize', 'ctime', 'r.title'); } else { $select_column_list = array('r.pid', 'r.aid', 'filepath', 'filename', 'url_prefix', 'pwidth', 'pheight', 'filesize', 'ctime', 'r.title', 'r.keywords', 'r.votes', 'pic_rating'); //if ($CONFIG['views_in_thumbview']) { $select_column_list[] = 'hits'; //} //if ($CONFIG['caption_in_thumbview']) { $select_column_list[] = 'caption'; //} //if ($CONFIG['display_uploader']) { $select_column_list[] = 'r.owner_id'; //} if (GALLERY_ADMIN_MODE) { $select_column_list[] = 'pic_raw_ip'; $select_column_list[] = 'pic_hdr_ip'; } for ($i = 1; $i <= 4; $i++) { if ($CONFIG['user_field' . $i . '_name']) { $select_column_list[] = 'user' . $i; } } } if (count($FORBIDDEN_SET_DATA) > 0) { $forbidden_set_string = ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')'; } else { $forbidden_set_string = ''; } // Keyword if (!empty($CURRENT_ALBUM_KEYWORD)) { $keyword = "OR (keywords like '%{$CURRENT_ALBUM_KEYWORD}%' {$forbidden_set_string} )"; } else { $keyword = ''; } // Regular albums if (is_numeric($album)) { if (!$album_name_keyword) { $album_name_keyword = get_album_name($album); } $album_name = $album_name_keyword['title']; $album_keyword = addslashes($album_name_keyword['keyword']); if (!empty($album_keyword)) { $keyword = "OR (keywords like '%{$album_keyword}%' {$forbidden_set_string} )"; } else { $keyword = ''; } if (array_key_exists('allowed_albums', $USER_DATA) && is_array($USER_DATA['allowed_albums']) && in_array($album, $USER_DATA['allowed_albums'])) { $approved = ''; } else { $approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\''; } $approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\''; // Note: Use a second variable, $pic_count, since $count is passed by reference // and having it defined as static in the function may be problematic if (is_null($pic_count)) { $result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid='{$album}' {$forbidden_set_string} ) {$keyword}) {$approved}"); list($count) = mysql_fetch_row($result); mysql_free_result($result); $pic_count = $count; } else { $count = $pic_count; } list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $sort_array = array('na' => "filename {$ASC}, pid {$ASC}", 'nd' => "filename {$DESC}, pid {$DESC}", 'ta' => "title {$ASC}, pid {$ASC}", 'td' => "title {$DESC}, pid {$DESC}", 'da' => "ctime {$ASC}, pid {$ASC}", 'dd' => "ctime {$DESC}, pid {$DESC}", 'pa' => "position {$ASC}, pid {$ASC}", 'pd' => "position {$DESC}, pid {$DESC}"); $sort_code = isset($USER['sort']) && $CONFIG['custom_sortorder_thumbs'] ? $USER['sort'] : $CONFIG['default_sort_order']; $sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['default_sort_order']]; $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns} FROM {$CONFIG['TABLE_PICTURES']} AS r\n WHERE ((aid = {$album} {$forbidden_set_string} ) {$keyword}){$approved}\n ORDER BY {$sort_order}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } // Set picture caption if ($set_caption) { if ($CONFIG['display_thumbnail_rating'] == 1) { build_caption($rowset, array('pic_rating')); } else { build_caption($rowset); } } $rowset = CPGPluginAPI::filter('thumb_caption_regular', $rowset); return $rowset; } $meta_album_passto = array('album' => $album, 'limit' => $limit, 'set_caption' => $set_caption); $meta_album_params = CPGPluginAPI::filter('meta_album', $meta_album_passto); if (array_key_exists('album_name', $meta_album_params) && $meta_album_params['album_name']) { $album_name = $meta_album_params['album_name']; $count = $meta_album_params['count']; $rowset = $meta_album_params['rowset']; return $rowset; } // Meta albums switch ($album) { case 'lastcom': // Latest comments if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('comment', 2) . ($album_name = $lang_meta_album_names['lastcom'] . ' - ' . $CURRENT_CAT_NAME); } else { $album_name = cpg_fetch_icon('comment', 2) . $lang_meta_album_names['lastcom']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_COMMENTS']} AS c\n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND r.approved = 'YES'\n AND c.approval = 'YES'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_column_list[] = 'UNIX_TIMESTAMP(msg_date) AS msg_date'; $select_column_list[] = 'msg_body'; $select_column_list[] = 'author_id'; $select_column_list[] = 'msg_author'; $select_column_list[] = 'msg_id'; // needed for get_pic_pos() $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_COMMENTS']} AS c\n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND r.approved = 'YES'\n AND c.approval = 'YES'\n ORDER BY msg_id {$DESC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('msg_body', 'msg_date')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastcom', $rowset); return $rowset; break; case 'lastcomby': // Latest comments by a specific user if (isset($USER['uid'])) { $uid = (int) $USER['uid']; } else { $uid = -1; } $user_name = get_username($uid); if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('comment', 2) . ($album_name = $lang_meta_album_names['lastcom'] . ' - ' . $CURRENT_CAT_NAME . ' - ' . $user_name); } else { $album_name = cpg_fetch_icon('comment', 2) . $lang_meta_album_names['lastcom'] . ' - ' . $user_name; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_COMMENTS']} AS c\n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND author_id = '{$uid}'\n AND r.approved = 'YES'\n AND c.approval = 'YES'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_column_list[] = 'UNIX_TIMESTAMP(msg_date) AS msg_date'; $select_column_list[] = 'msg_body'; $select_column_list[] = 'author_id'; $select_column_list[] = 'msg_author'; $select_column_list[] = 'msg_id'; // needed for get_pic_pos() $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_COMMENTS']} AS c\n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND author_id = '{$uid}'\n AND r.approved = 'YES'\n AND c.approval = 'YES'\n ORDER BY msg_id {$DESC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('msg_body', 'msg_date')); } if ($flipped) { $rowset = array_reverse($rowset); } $rowset = CPGPluginAPI::filter('thumb_caption_lastcomby', $rowset); return $rowset; break; case 'lastup': // Latest (most recent) uploads if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('last_uploads', 2) . $lang_meta_album_names['lastup'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('last_uploads', 2) . $lang_meta_album_names['lastup']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n ORDER BY ctime {$DESC}, pid {$DESC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('ctime')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastup', $rowset); return $rowset; break; case 'lastupby': // Latest (most recent) uploads by a specific user if (isset($USER['uid'])) { $uid = (int) $USER['uid']; } else { $uid = -1; } $user_name = get_username($uid); if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('last_uploads', 2) . $lang_meta_album_names['lastup'] . ' - ' . $CURRENT_CAT_NAME . ' - ' . $user_name; } else { $album_name = cpg_fetch_icon('last_uploads', 2) . $lang_meta_album_names['lastup'] . ' - ' . $user_name; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND r.owner_id = '{$uid}'\n AND approved = 'YES'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND r.owner_id = '{$uid}'\n AND approved = 'YES'\n ORDER BY ctime {$DESC}, pid {$DESC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('ctime')); } $rowset = CPGPluginAPI::filter('thumb_caption_lastupby', $rowset); return $rowset; break; case 'topn': // Most viewed files if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('most_viewed', 2) . $lang_meta_album_names['topn'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('most_viewed', 2) . $lang_meta_album_names['topn']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND hits > 0"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND hits > 0\n ORDER BY hits {$DESC}, pid {$ASC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('hits')); } $rowset = CPGPluginAPI::filter('thumb_caption_topn', $rowset); return $rowset; break; case 'toprated': // Top rated pictures if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('top_rated', 2) . $lang_meta_album_names['toprated'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('top_rated', 2) . $lang_meta_album_names['toprated']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND r.votes >= '{$CONFIG['min_votes_for_rating']}'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND r.votes >= '{$CONFIG['min_votes_for_rating']}'\n ORDER BY pic_rating {$DESC}, r.votes {$DESC}, pid {$DESC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('pic_rating')); } $rowset = CPGPluginAPI::filter('thumb_caption_toprated', $rowset); return $rowset; break; case 'lasthits': // Last viewed files (most recently-viewed files) if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('last_viewed', 2) . $lang_meta_album_names['lasthits'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('last_viewed', 2) . $lang_meta_album_names['lasthits']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND hits > 0"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_column_list[] = 'UNIX_TIMESTAMP(mtime) AS mtime'; if (GALLERY_ADMIN_MODE) { $select_column_list[] = 'lasthit_ip'; } $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND hits > 0\n ORDER BY mtime {$DESC}, pid {$ASC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('mtime', 'hits')); } $rowset = CPGPluginAPI::filter('thumb_caption_lasthits', $rowset); return $rowset; break; case 'random': // Random files if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random']; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); $query = "SELECT pid\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n ORDER BY RAND()\n {$limit}"; $result = cpg_db_query($query); $pidlist = array(); while ($row = mysql_fetch_assoc($result)) { $pidlist[] = $row['pid']; } mysql_free_result($result); if (count($pidlist)) { $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n WHERE pid IN (" . implode(', ', $pidlist) . ")"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); shuffle($rowset); } else { $rowset = array(); } if ($set_caption) { build_caption($rowset); } $rowset = CPGPluginAPI::filter('thumb_caption_random', $rowset); return $rowset; break; case 'search': // Search results if (isset($USER['search']['search'])) { $search_string = $USER['search']['search']; } else { $search_string = ''; } if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('search', 2) . $lang_meta_album_names['search'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('search', 2) . $lang_meta_album_names['search'] . ' - "' . strip_tags($search_string) . '"'; } include 'include/search.inc.php'; $rowset = CPGPluginAPI::filter('thumb_caption_search', $rowset); return $rowset; break; case 'lastalb': // Last albums to which files have been uploaded if ($cat && $CURRENT_CAT_NAME) { $album_name = cpg_fetch_icon('last_created', 2) . $lang_meta_album_names['lastalb'] . ' - ' . $CURRENT_CAT_NAME; } else { $album_name = cpg_fetch_icon('last_created', 2) . $lang_meta_album_names['lastalb']; } // If $select_column_list includes an 'a.' field, split off into album query and remove from file query $select_column_list_files = $select_column_list; $select_column_list_albums = array('r.aid', 'a.thumb', 'a.keyword', 'a.alb_hits', 'a.title', 'ctime'); foreach ($select_column_list_files as $key => $value) { if (strpos($value, 'a.') === 0) { $select_column_list_albums[] = $value; unset($select_column_list_files[$key]); } } $select_columns_files = implode(', ', $select_column_list_files); $select_columns_albums = str_replace('ctime', 'MAX(ctime) AS ctime', implode(', ', $select_column_list_albums)); // Keyword-linked files are not included; only native files are checked for last-updated albums $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n GROUP BY r.aid"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); $query = "SELECT {$select_columns_albums}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n GROUP BY r.aid\n ORDER BY ctime DESC\n {$limit}"; $result = cpg_db_query($query); $rowset_aid = cpg_db_fetch_rowset($result); mysql_free_result($result); // For 'lastalb' album, only use approved photos for album thumbnails $approved = 'AND approved=\'YES\''; // Preparation for check if album thumbnail exists $album_thumbs = array(); foreach ($rowset_aid as $index => $row) { if ($row['thumb'] > 0) { $album_thumbs[] = $row['thumb']; } } if (count($album_thumbs)) { $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (" . implode(',', $album_thumbs) . ")"; $result = cpg_db_query($query); while ($row = mysql_fetch_assoc($result)) { $rowset_available_pids[] = $row['pid']; } mysql_free_result($result); } $album_thumbs = array(); foreach ($rowset_aid as $index => $row) { // Check if album thumbnail exists, if not, set to last uploaded if ($row['thumb'] > 0 && !in_array($row['thumb'], $rowset_available_pids)) { $row['thumb'] = 0; } if ($row['thumb'] > 0) { $album_thumbs[] = $row['thumb']; } elseif ($row['thumb'] < 0) { // random file from album $keyword = $row['keyword'] ? "OR (keywords like '%" . addslashes($row['keyword']) . "%' {$forbidden_set_string} )" : ''; $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$row['aid']}' {$forbidden_set_string}) {$keyword}) {$approved} ORDER BY RAND() LIMIT 0,1"; $result = cpg_db_query($query); list($pid_random) = mysql_fetch_row($result); mysql_free_result($result); $album_thumbs[] = $pid_random; $rowset_aid[$index]['thumb'] = $pid_random; } else { // thumb = 0 // last uploaded file from album $keyword = $row['keyword'] ? "OR (keywords like '%" . addslashes($row['keyword']) . "%' {$forbidden_set_string} )" : ''; $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$row['aid']}' {$forbidden_set_string}) {$keyword}) {$approved} ORDER BY ctime DESC LIMIT 0,1"; $result = cpg_db_query($query); list($pid_lastup) = mysql_fetch_row($result); mysql_free_result($result); $album_thumbs[] = $pid_lastup; $rowset_aid[$index]['thumb'] = $pid_lastup; } } if (!$album_thumbs) { $rowset = array(); } else { $album_thumbs_set = implode(',', array_unique($album_thumbs)); $query = "SELECT {$select_columns_files}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n WHERE approved = 'YES'\n AND r.pid IN ({$album_thumbs_set})"; $result = cpg_db_query($query); $rowset_pid = cpg_db_fetch_rowset($result); mysql_free_result($result); $rowset_pid_indexed = array(); foreach ($rowset_pid as $row) { $rowset_pid_indexed[$row['pid']] = $row; } $rowset = array(); foreach ($rowset_aid as $row) { $rowset[] = is_array($rowset_pid_indexed[$row['thumb']]) ? array_merge($rowset_pid_indexed[$row['thumb']], $row) : $row; } if ($set_caption) { build_caption($rowset, array('ctime'), 'albums'); } } $rowset = CPGPluginAPI::filter('thumb_caption_lastalb', $rowset); return $rowset; break; case 'favpics': // Favorite Files $album_name = cpg_fetch_icon('favorites', 2) . $lang_meta_album_names['favpics']; $rowset = array(); if (count($FAVPICS) > 0) { $favs = implode(', ', $FAVPICS); $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND pid IN ({$favs})"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND pid IN ({$favs})\n ORDER BY pid ASC\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($set_caption) { build_caption($rowset, array('ctime')); } } $rowset = CPGPluginAPI::filter('thumb_caption_favpics', $rowset); return $rowset; break; case 'datebrowse': // Browsing by uploading date // Using getRaw(): The date is sanitized in the called function $date = $superCage->get->keyExists('date') ? cpgValidateDate($superCage->get->getRaw('date')) : null; $album_name = cpg_fetch_icon('calendar', 2) . $lang_common['date'] . ': ' . $date; $rowset = array(); $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "'"; $result = cpg_db_query($query); list($count) = mysql_fetch_row($result); mysql_free_result($result); list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2); $select_columns = implode(', ', $select_column_list); $query = "SELECT {$select_columns}\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "'\n ORDER BY ctime {$ASC}, pid {$ASC}\n {$limit}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); if ($flipped) { $rowset = array_reverse($rowset); } if ($set_caption) { build_caption($rowset, array('ctime')); } return $rowset; break; } // switch }
function hot_pictures_meta_album($meta) { global $CONFIG, $CURRENT_CAT_NAME, $RESTRICTEDWHERE, $lang_plugin_hot_pictures; switch ($meta['album']) { case 'hotpics': $album_name = cpg_fetch_icon('top_rated', 2) . " " . $lang_plugin_hot_pictures['hot_pictures']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $timestamp = time(); $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.hot_expire > {$timestamp}"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.* FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.hot_expire > {$timestamp}\n ORDER BY p.hot_expire ASC, pid ASC\n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset); break; default: return $meta; } $meta['album_name'] = $album_name; $meta['count'] = $count; $meta['rowset'] = $rowset; return $meta; }
function mma_meta_album($meta) { global $CONFIG, $CURRENT_CAT_NAME, $RESTRICTEDWHERE, $lang_plugin_more_meta_albums; switch ($meta['album']) { case 'image': // All pictures // All pictures case 'movie': // All videos // All videos case 'audio': // All audio files // All audio files case 'document': // All documents $icons = array('image' => 'picture_sort', 'movie' => 'slideshow', 'audio' => 'announcement', 'document' => 'documentation'); $album_name = cpg_fetch_icon($icons[$meta['album']], 2) . " " . $lang_plugin_more_meta_albums[$meta['album'] . '_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $filetypes = array(); $filetypes_sql = ""; $result = cpg_db_query("SELECT extension FROM {$CONFIG['TABLE_FILETYPES']} WHERE content = '{$meta['album']}'"); while ($row = mysql_fetch_assoc($result)) { $filetypes[] = $row['extension']; } foreach ($filetypes as $filetype) { $filetypes_sql .= "filename LIKE '%.{$filetype}' OR "; } $filetypes_sql .= "0"; $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND ({$filetypes_sql})"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.* FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND ({$filetypes_sql})\n ORDER BY pid ASC \n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset); break; case 'landscape': // Landscape format (height < width) // Landscape format (height < width) case 'portrait': // Portrait format (width < height) // Portrait format (width < height) case 'panorama': // Panorama format (width < height*2) $icons = array('landscape' => 'searchnew', 'portrait' => 'user_mgr', 'panorama' => 'searchnew'); $condition = array('landscape' => 'AND pwidth > pheight', 'portrait' => 'AND pwidth < pheight', 'panorama' => 'AND pwidth > pheight * 2'); $album_name = cpg_fetch_icon($icons[$meta['album']], 2) . " " . $lang_plugin_more_meta_albums[$meta['album'] . '_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND pwidth > 0\n AND pheight > 0\n {$condition[$meta['album']]}"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.* FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND pwidth > 0\n AND pheight > 0\n {$condition[$meta['album']]}\n ORDER BY pid ASC \n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset); break; case 'mostcom': // Most commented files $album_name = cpg_fetch_icon('comment', 2) . " " . $lang_plugin_more_meta_albums['mostcom_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT DISTINCT c.pid FROM {$CONFIG['TABLE_COMMENTS']} AS c \n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON c.pid = p.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND approval = 'YES'"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.*, COUNT(c.pid) AS count FROM {$CONFIG['TABLE_COMMENTS']} c \n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = c.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND approval = 'YES'\n GROUP BY p.pid \n ORDER BY count DESC, p.pid ASC \n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); $preVal = $CONFIG['display_comment_count']; $CONFIG['display_comment_count'] = 1; build_caption($rowset); $CONFIG['display_comment_count'] = $preVal; break; case 'mostvot': // Most voted files $album_name = cpg_fetch_icon('top_rated', 2) . " " . $lang_plugin_more_meta_albums['mostvot_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.votes > 0"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.* FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.votes > 0\n ORDER BY p.votes DESC, pid ASC\n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('pic_rating')); break; case 'lastcommented': // Last commented files $album_name = cpg_fetch_icon('comment', 2) . " " . $lang_plugin_more_meta_albums['lastcommented_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT DISTINCT c.pid FROM {$CONFIG['TABLE_COMMENTS']} AS c \n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON c.pid = p.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n AND approval = 'YES'"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.*, com1.*, UNIX_TIMESTAMP(com1.msg_date) AS msg_date FROM {$CONFIG['TABLE_COMMENTS']} AS com1 \n LEFT JOIN {$CONFIG['TABLE_COMMENTS']} AS com2 ON (com2.pid = com1.pid AND com2.msg_date > com1.msg_date)\n INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.pid = com1.pid \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND com1.approval = 'YES'\n AND com2.pid IS NULL\n ORDER BY msg_date DESC \n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('msg_date')); break; case 'toprateda': // Top rated pictures (accumulated) $album_name = cpg_fetch_icon('top_rated', 2) . " " . $lang_plugin_more_meta_albums['toprateda_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.votes >= {$CONFIG['min_votes_for_rating']}"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT MAX(p.votes * p.pic_rating) FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.votes >= {$CONFIG['min_votes_for_rating']}"; $result = cpg_db_query($query); $max_rating_points = mysql_result($result, 0); mysql_free_result($result); $query = "SELECT p.*, (p.votes * p.pic_rating / {$max_rating_points} * 10000) AS pic_rating FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.votes >= {$CONFIG['min_votes_for_rating']}\n ORDER BY pic_rating DESC, pid ASC\n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('pic_rating')); break; case 'newalb': // New albums $album_name = cpg_fetch_icon('last_created', 2) . " " . $lang_plugin_more_meta_albums['newalb_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES'\n AND p.pid = r.thumb "; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.*, alb_hits AS hits FROM {$CONFIG['TABLE_PICTURES']} AS p \n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid \n {$RESTRICTEDWHERE} \n AND approved = 'YES' \n AND p.pid = r.thumb \n ORDER BY ctime DESC\n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('ctime')); break; case 'randalb': // Random albums // Random albums case 'randuseralb': // Random albums in user categories // Random albums in user categories case 'randpublicalb': // Random albums in public categories $condition = array('randalb' => '', 'randuseralb' => 'AND r.category > ' . FIRST_USER_CAT, 'randpublicalb' => 'AND r.category < ' . FIRST_USER_CAT); $album_name = cpg_fetch_icon('alb_mgr', 2) . " " . $lang_plugin_more_meta_albums[$meta['album'] . '_title']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT COUNT(*)\n FROM {$CONFIG['TABLE_PICTURES']} AS p\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n {$condition[$meta['album']]}\n GROUP BY p.aid\n HAVING COUNT(p.pid) > 0\n ORDER BY RAND()"; $result = cpg_db_query($query); $count = mysql_num_rows($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } $query = "SELECT p.*, r.title\n FROM {$CONFIG['TABLE_PICTURES']} AS p\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid\n {$RESTRICTEDWHERE}\n AND approved = 'YES'\n {$condition[$meta['album']]}\n GROUP BY p.aid\n HAVING COUNT(p.pid) > 0\n ORDER BY RAND()\n {$meta['limit']}"; $result = cpg_db_query($query); $rowset = cpg_db_fetch_rowset($result); mysql_free_result($result); build_caption($rowset, array('ctime')); break; default: return $meta; } $meta['album_name'] = $album_name; $meta['count'] = $count; $meta['rowset'] = $rowset; return $meta; }
function advcap_simplify($rowset) { build_caption($rowset); return $rowset; }
function album_voting_meta_album($meta) { global $CONFIG, $CURRENT_CAT_NAME, $RESTRICTEDWHERE, $lang_plugin_album_voting; switch ($meta['album']) { case 'mostvotalb': $album_name = cpg_fetch_icon('top_rated', 2) . " " . $lang_plugin_album_voting['mostvotalb']; if ($CURRENT_CAT_NAME) { $album_name .= " - {$CURRENT_CAT_NAME}"; } $query = "SELECT *, COUNT(v.aid) AS album_votes FROM {$CONFIG['TABLE_PREFIX']}album_votes AS v\n INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = v.aid \n {$RESTRICTEDWHERE} \n AND r.aid IN (SELECT DISTINCT aid FROM {$CONFIG['TABLE_PICTURES']})\n GROUP BY v.aid\n ORDER BY album_votes DESC, v.aid DESC\n {$meta['limit']}"; $result = cpg_db_query($query); $count = mysql_num_rows($result); $rowset_aid = cpg_db_fetch_rowset($result); mysql_free_result($result); if (!$count) { $rowset = array(); break; } // Get album thumbnails // Copied from include/functions.inc.php 'lastalb' meta album code -- START $album_thumbs = array(); foreach ($rowset_aid as $index => $row) { if ($row['thumb'] > 0) { $album_thumbs[] = $row['thumb']; } } if (count($album_thumbs)) { $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE pid IN (" . implode(',', $album_thumbs) . ")"; $result = cpg_db_query($query); while ($row = mysql_fetch_assoc($result)) { $rowset_available_pids[] = $row['pid']; } mysql_free_result($result); } $album_thumbs = array(); foreach ($rowset_aid as $index => $row) { // Check if album thumbnail exists, if not, set to last uploaded if ($row['thumb'] > 0 && !in_array($row['thumb'], $rowset_available_pids)) { $row['thumb'] = 0; } if ($row['thumb'] > 0) { $album_thumbs[] = $row['thumb']; } elseif ($row['thumb'] < 0) { // random file from album $keyword = $row['keyword'] ? "OR (keywords like '%" . addslashes($row['keyword']) . "%' {$forbidden_set_string} )" : ''; $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$row['aid']}' {$forbidden_set_string}) {$keyword}) {$approved} ORDER BY RAND() LIMIT 0,1"; $result = cpg_db_query($query); list($pid_random) = mysql_fetch_row($result); mysql_free_result($result); $album_thumbs[] = $pid_random; $rowset_aid[$index]['thumb'] = $pid_random; } else { // thumb = 0 // last uploaded file from album $keyword = $row['keyword'] ? "OR (keywords like '%" . addslashes($row['keyword']) . "%' {$forbidden_set_string} )" : ''; $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} WHERE ((aid = '{$row['aid']}' {$forbidden_set_string}) {$keyword}) {$approved} ORDER BY ctime DESC LIMIT 0,1"; $result = cpg_db_query($query); list($pid_lastup) = mysql_fetch_row($result); mysql_free_result($result); $album_thumbs[] = $pid_lastup; $rowset_aid[$index]['thumb'] = $pid_lastup; } } if (!$album_thumbs) { $rowset = array(); } else { $album_thumbs_set = implode(',', array_unique($album_thumbs)); $query = "SELECT *\n FROM {$CONFIG['TABLE_PICTURES']} AS r\n WHERE approved = 'YES'\n AND r.pid IN ({$album_thumbs_set})"; $result = cpg_db_query($query); $rowset_pid = cpg_db_fetch_rowset($result); mysql_free_result($result); $rowset_pid_indexed = array(); foreach ($rowset_pid as $row) { $rowset_pid_indexed[$row['pid']] = $row; } $rowset = array(); foreach ($rowset_aid as $row) { $rowset[] = is_array($rowset_pid_indexed[$row['thumb']]) ? array_merge($rowset_pid_indexed[$row['thumb']], $row) : $row; } if ($set_caption) { build_caption($rowset, array('ctime'), 'albums'); } } // Copied from include/functions.inc.php 'lastalb' meta album code -- START build_caption($rowset); foreach ($rowset as $key => $row) { $rowset[$key]['caption_text'] .= "<span class=\"thumb_title\">{$lang_plugin_album_voting['votes']} {$row['album_votes']}</span>"; } break; default: return $meta; } $meta['album_name'] = $album_name; $meta['count'] = $count; $meta['rowset'] = $rowset; return $meta; }