$result->fetchRow(true);
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
FROM {$CONFIG['TABLE_COMMENTS']} AS c
INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND r.approved = 'YES'
AND c.approval = 'YES'
ORDER BY msg_id $DESC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_COMMENTS']} AS c
INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND author_id = '$uid'
AND r.approved = 'YES'
AND c.approval = 'YES'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
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
FROM {$CONFIG['TABLE_COMMENTS']} AS c
INNER JOIN {$CONFIG['TABLE_PICTURES']} AS r ON r.pid = c.pid
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND author_id = '$uid'
AND r.approved = 'YES'
AND c.approval = 'YES'
ORDER BY msg_id $DESC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
ORDER BY ctime $DESC, pid $DESC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND r.owner_id = '$uid'
AND approved = 'YES'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND r.owner_id = '$uid'
AND approved = 'YES'
ORDER BY ctime $DESC, pid $DESC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND hits > 0";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND hits > 0
ORDER BY hits $DESC, pid $ASC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND r.votes >= '{$CONFIG['min_votes_for_rating']}'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND r.votes >= '{$CONFIG['min_votes_for_rating']}'
ORDER BY pic_rating $DESC, r.votes $DESC, pid $DESC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND hits > 0";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
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
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND hits > 0
ORDER BY mtime $DESC, pid $ASC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
$query = "SELECT pid
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
ORDER BY RAND()
$limit";
$result = cpg_db_query($query);
$pidlist = array();
while ($row = $result->fetchAssoc()) {
$pidlist[] = $row['pid'];
}
$result->free();
if (count($pidlist)) {
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
WHERE pid IN (" . implode(', ', $pidlist) . ")";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
GROUP BY r.aid";
$result = cpg_db_query($query);
$count = $result->numRows();
$result->free();
$query = "SELECT $select_columns_albums
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
GROUP BY r.aid
ORDER BY ctime DESC
$limit";
$result = cpg_db_query($query);
$rowset_aid = cpg_db_fetch_rowset($result, true);
// 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 = $result->fetchAssoc()) {
$rowset_available_pids[] = $row['pid'];
}
$result->free();
}
$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) = $result->fetchRow(true);
$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) = $result->fetchRow(true);
$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
FROM {$CONFIG['TABLE_PICTURES']} AS r
WHERE approved = 'YES'
AND r.pid IN ($album_thumbs_set)";
$result = cpg_db_query($query);
$rowset_pid = cpg_db_fetch_rowset($result, true);
$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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND pid IN ($favs)";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND pid IN ($favs)
ORDER BY pid ASC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
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(*)
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "'";
$result = cpg_db_query($query);
list($count) = $result->fetchRow(true);
list($ASC, $DESC, $limit, $flipped) = get_pic_data_ordering($count, $limit1, $limit2);
$select_columns = implode(', ', $select_column_list);
$query = "SELECT $select_columns
FROM {$CONFIG['TABLE_PICTURES']} AS r
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "'
ORDER BY ctime $ASC, pid $ASC
$limit";
$result = cpg_db_query($query);
$rowset = cpg_db_fetch_rowset($result, true);
if ($flipped) {
$rowset = array_reverse($rowset);
}
if ($set_caption) {
build_caption($rowset, array('ctime'));
}
return $rowset;
break;
} // switch
} // function get_pic_data
// Copy of get_pic_data, created to obtain position for the given pid in the given album
function get_pic_pos($album, $pid)
{
global $USER, $CONFIG, $CURRENT_ALBUM_KEYWORD, $FORBIDDEN_SET_DATA, $USER_DATA;
global $RESTRICTEDWHERE, $FORBIDDEN_SET;
global $lang_errors;
// Regular albums
if (is_numeric($album)) {
if (count($FORBIDDEN_SET_DATA) > 0) {
$forbidden_set_string = ' AND aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')';
} else {
$forbidden_set_string = '';
}
$album_name_keyword = get_album_name($album);
//$album_name = $album_name_keyword['title'];
$album_keyword = $album_name_keyword['keyword'] ? addslashes($album_name_keyword['keyword']) : '';
if (!empty($album_keyword)) {
$keyword = "OR (keywords like '%$album_keyword%' $forbidden_set_string )";
} else {
$keyword = '';
}
$approved = GALLERY_ADMIN_MODE ? '' : 'AND approved=\'YES\'';
$result = cpg_db_query("SELECT filename, title, pid, position, ctime FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid");
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
$pic = $result->fetchAssoc(true);
$pic['title'] = cpg_db_escape_string($pic['title']);
$sort_array = array(
'na' => "(filename < '{$pic['filename']}' OR filename = '{$pic['filename']}' AND pid < {$pic['pid']})",
'nd' => "(filename > '{$pic['filename']}' OR filename = '{$pic['filename']}' AND pid > {$pic['pid']})",
'ta' => "(title < '{$pic['title']}' OR title = '{$pic['title']}' AND pid < {$pic['pid']})",
'td' => "(title > '{$pic['title']}' OR title = '{$pic['title']}' AND pid > {$pic['pid']})",
'da' => "(ctime < '{$pic['ctime']}' OR ctime = '{$pic['ctime']}' AND pid < {$pic['pid']})",
'dd' => "(ctime > '{$pic['ctime']}' OR ctime = '{$pic['ctime']}' AND pid > {$pic['pid']})",
'pa' => "(position < {$pic['position']} OR position = {$pic['position']} AND pid < {$pic['pid']})",
'pd' => "(position > {$pic['position']} OR position = {$pic['position']} AND pid > {$pic['pid']})",
);
list($sort_array) = CPGPluginAPI::filter('pic_pos_sort_array', array($sort_array, $pid));
$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']];
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']}
WHERE ((aid='$album' $forbidden_set_string) $keyword) $approved
AND $sort_order";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
}
// Meta albums
switch($album) {
case 'lastcom': // Latest comments
$superCage = Inspekt::makeSuperCage();
if (!$superCage->get->getInt('msg_id')) {
cpg_die(ERROR, $lang_errors['param_missing'], __FILE__, __LINE__);
}
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
INNER JOIN {$CONFIG['TABLE_COMMENTS']} AS c ON c.pid = p.pid
$RESTRICTEDWHERE
AND approved = 'YES'
AND approval = 'YES'
AND msg_id > ".$superCage->get->getInt('msg_id');
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'lastcomby': // Latest comments by a specific user
if (isset($USER['uid'])) {
$uid = (int) $USER['uid'];
} else {
$uid = -1;
}
$superCage = Inspekt::makeSuperCage();
if (!$superCage->get->getInt('msg_id')) {
cpg_die(ERROR, $lang_errors['param_missing'], __FILE__, __LINE__);
}
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
INNER JOIN {$CONFIG['TABLE_COMMENTS']} AS c ON c.pid = p.pid
$RESTRICTEDWHERE
AND author_id = $uid
AND approved = 'YES'
AND approval = 'YES'
AND msg_id > ".$superCage->get->getInt('msg_id');
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'lastup': // Latest (most recent) uploads
$query = "SELECT ctime FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid";
$result = cpg_db_query($query);
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
$ctime = $result->result(0, 0, true);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND (ctime > $ctime
OR ctime = $ctime AND pid > $pid)";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'lastupby': // Latest (most recent) uploads by a specific user
if (isset($USER['uid'])) {
$uid = (int) $USER['uid'];
} else {
$uid = -1;
}
$query = "SELECT ctime FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid";
$result = cpg_db_query($query);
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
$ctime = $result->result(0, 0, true);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND p.owner_id = $uid
AND approved = 'YES'
AND (ctime > $ctime
OR ctime = $ctime AND pid > $pid)";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'topn': // Most viewed files
$query = "SELECT hits FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid";
$result = cpg_db_query($query);
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
$hits = $result->result(0, 0, true);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND (hits > $hits
OR hits = $hits AND pid < $pid)";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'toprated': // Top rated pictures
$query = "SELECT pic_rating, votes FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid";
$result = cpg_db_query($query);
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
list($pic_rating, $votes) = $result->fetchRow(true);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND p.votes >= '{$CONFIG['min_votes_for_rating']}'
AND (pic_rating > $pic_rating
OR (pic_rating = $pic_rating AND p.votes > $votes)
OR (pic_rating = $pic_rating AND p.votes = $votes AND pid > $pid))";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'lasthits': // Last viewed files (most recently-viewed files)
$query = "SELECT mtime FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = $pid";
$result = cpg_db_query($query);
if (!$result->numRows()) cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
$mtime = $result->result(0, 0, true);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND hits > 0
AND (mtime > '$mtime'
OR mtime = '$mtime' AND pid < $pid)";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'search': // Search results
$superCage = Inspekt::makeSuperCage();
if (isset($USER['search']['search'])) {
$search_string = $USER['search']['search'];
} else {
$search_string = '';
}
$get_pic_pos = true;
include 'include/search.inc.php';
return $pos;
break;
case 'favpics': // Favorite Files
global $FAVPICS;
if (empty($FAVPICS)) {
return 0;
}
$favs = implode(', ', $FAVPICS);
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND pid IN ($favs)
AND pid < $pid";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
case 'datebrowse': // Browsing by uploading date
$superCage = Inspekt::makeSuperCage();
// Using getRaw(): The date is sanitized in the called function
$date = $superCage->get->keyExists('date') ? cpgValidateDate($superCage->get->getRaw('date')) : null;
$query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
$RESTRICTEDWHERE
AND approved = 'YES'
AND substring(from_unixtime(ctime),1,10) = '" . substr($date, 0, 10) . "'
AND pid < $pid";
$result = cpg_db_query($query);
list($pos) = $result->fetchRow(true);
return $pos;
break;
default : // Invalid/custom meta album
$pos = CPGPluginAPI::filter('meta_album_get_pic_pos', $album);
if (is_numeric($pos)) {
return $pos; // Custom meta album
} else {
return FALSE; // Invalid meta album
}
} // switch
} // function get_pic_pos
// Get the name of an album
/**
* get_album_name()
*
* @param $aid
* @return
**/
function get_album_name($aid)
{
global $CONFIG;
global $lang_errors;
$result = cpg_db_query("SELECT title, keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = $aid");
$count = $result->numRows();
if ($count > 0) {
$row = $result->fetchAssoc(true);
return $row;
} else {
cpg_die(ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
}
} // function get_album_name
// Return the name of a user
/**
* get_username()
*
* @param $uid
* @return
**/
function get_username($uid)
{
global $cpg_udb;
$uid = (int) $uid;
if (!$uid) {
return 'Anonymous';
} elseif (defined('UDB_INTEGRATION')) {
return $cpg_udb->get_user_name($uid);
}
} // function get_username
// Return the ID of a user
/**
* get_userid()
*
* @param $username
* @return
**/
function get_userid($username)
{
global $cpg_udb;
$username = addslashes($username);
if (!$username) {
return 0;
} elseif (defined('UDB_INTEGRATION')) {
return $cpg_udb->get_user_id($username);
}
}
// get number of pending approvals
/**
* cpg_get_pending_approvals()
*
* @return
**/
function cpg_get_pending_approvals()
{
global $CONFIG;
$result = cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'NO'");
list($count) = $result->fetchRow(true);
return $count;
}
// Return the total number of comments for a certain picture
/**
* count_pic_comments()
*
* @param $pid
* @param integer $skip
* @return
**/
function count_pic_comments($pid, $skip = 0)
{
global $CONFIG;
$sql = "SELECT COUNT(*) FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid = $pid";
if ($skip) {
$sql .= " AND msg_id != $skip";
}
$result = cpg_db_query($sql);
list($count) = $result->fetchRow(true);
return $count;
}
/******************
/**
* cpg_determine_client()
*
* @param
* @return $return_array
**/
function cpg_determine_client()
{
//Making Cage
$superCage = Inspekt::makeSuperCage();
/**
* Populate the client stats
*/
// Get the details of user browser, IP, OS, etc
$server_agent = $superCage->server->getRaw('HTTP_USER_AGENT');
$os = 'Unknown';
if (preg_match('#Ubuntu#i', $server_agent)) {
$os = 'Linux Ubuntu';
} elseif (preg_match('#Debian#i', $server_agent)) {
$os = 'Linux Debian';
} elseif (preg_match('#CentOS#i', $server_agent)) {
$os = 'Linux CentOS';
} elseif (preg_match('#Fedora#i', $server_agent)) {
$os = 'Linux Fedora';
} elseif (preg_match('#Mandrake#i', $server_agent)) {
$os = 'Linux Mandrake';
} elseif (preg_match('#RedHat#i', $server_agent)) {
$os = 'Linux RedHat';
} elseif (preg_match('#Suse#i', $server_agent)) {
$os = 'Linux Suse';
} elseif (preg_match('#Linux#i', $server_agent)) {
$os = 'Linux';
} elseif (preg_match('#Windows NT 5.0#i', $server_agent)) {
$os = 'Windows 2000';
} elseif (preg_match('#win98|Windows 98#i', $server_agent)) {
$os = 'Windows 98';
} elseif (preg_match('#Windows NT 5\.1#i', $server_agent)) {
$os = 'Windows XP';
} elseif (preg_match('#Windows NT 5\.2#i', $server_agent)) {
$os = 'Windows 2003 Server';
} elseif (preg_match('#Windows NT 6\.0#i', $server_agent)) {
$os = 'Windows Vista';
} elseif (preg_match('#Windows NT 6\.1#i', $server_agent)) {
$os = 'Windows 7';
} elseif (preg_match('#Windows NT 6\.2#i', $server_agent)) {
$os = 'Windows 8';
} elseif (preg_match('#Windows CE#i', $server_agent)) {
$os = 'Windows CE';
} elseif (preg_match('#Windows#i', $server_agent)) {
$os = 'Windows';
} elseif (preg_match('#SunOS#i', $server_agent)) {
$os = 'Sun OS';
} elseif (preg_match('#Macintosh#i', $server_agent)) {
$os = 'Macintosh';
} elseif (preg_match('#Mac_PowerPC#i', $server_agent)) {
$os = 'Mac OS';
} elseif (preg_match('#Mac_PPC#i', $server_agent)) {
$os = 'Macintosh';
} elseif (preg_match('#OS/2#i', $server_agent)) {
$os = 'OS/2';
} elseif (preg_match('#aix#i', $server_agent)) {
$os = 'aix';
} elseif (preg_match('#FreeBSD#i', $server_agent)) {
$os = 'BSD FreeBSD';
} elseif (preg_match('#Unix#i', $server_agent)) {
$os = 'Unix';
} elseif (preg_match('#iphone#i', $server_agent)) {
$os = 'iPhone';
} elseif (preg_match('#Nintendo Wii#i', $server_agent)) {
$os = 'Nintendo Wii';
} elseif (preg_match('#PalmOS#i', $server_agent)) {
$os = 'PalmOS';
} elseif (preg_match('#Symbian#i', $server_agent)) {
$os = 'Symbian';
} elseif (preg_match('#PLAYSTATION 3#i', $server_agent)) {
$os = 'Playstation 3';
} elseif (preg_match('#PlayStation Portable#i', $server_agent)) {
$os = 'Playstation Portable';
} elseif (preg_match('#Playstation#i', $server_agent)) {
$os = 'Playstation';
} elseif (preg_match('#Inferno#i', $server_agent)) {
$os = 'Inferno';
} elseif (preg_match('#BeOS#i', $server_agent)) {
$os = 'beOS';
}
$browser = 'Unknown';
if (preg_match('#MSIE#i', $server_agent)) {
if (preg_match('#MSIE 10\.0#i', $server_agent)) {
$browser = 'IE10';
} elseif (preg_match('#MSIE 9\.0#i', $server_agent)) {
$browser = 'IE9';
} elseif (preg_match('#MSIE 8\.0#i', $server_agent)) {
$browser = 'IE8';
} elseif (preg_match('#MSIE 7\.0#i', $server_agent)) {
$browser = 'IE7';
} elseif (preg_match('#MSIE 6\.0#i', $server_agent)) {
$browser = 'IE6';
} elseif (preg_match('#MSIE 5\.5#i', $server_agent)) {
$browser = 'IE5.5';
} elseif (preg_match('#MSIE 5\.0#i', $server_agent)) {
$browser = 'IE5.0';
} elseif (preg_match('#MSIE 4\.0#i', $server_agent)) {
$browser = 'IE4';
} elseif (preg_match('#MSIE 3\.0#i', $server_agent)) {
$browser = 'IE3';
} else {
$browser = 'IE';
}
} elseif (preg_match('#Nitro#i', $server_agent)) {
$browser = 'Nintendo DS';
} elseif (preg_match('#Nokia#i', $server_agent)) {
$browser = 'Nokia';
} elseif (preg_match('#iPhone#i', $server_agent)) {
$browser = 'iPhone';
} elseif (preg_match('#Epiphany#i', $server_agent)) {
$browser = 'Epiphany';
} elseif (preg_match('#Flock#i', $server_agent)) {
$browser = 'Flock';
} elseif (preg_match('#SeaMonkey#i', $server_agent)) {
$browser = 'SeaMonkey';
} elseif (preg_match('#Phoenix#i', $server_agent)) {
$browser = 'Phoenix';
} elseif (preg_match('#Firebird#i', $server_agent)) {
$browser = 'Mozilla Firebird';
} elseif (preg_match('#NetSurf#i', $server_agent)) {
$browser = 'NetSurf';
} elseif (preg_match('#netscape#i', $server_agent)) {
$browser = 'Netscape';
} elseif (preg_match('#Chrome#i', $server_agent)) {
$browser = 'Chrome';
} elseif (preg_match('#Firefox#i', $server_agent)) {
$browser = 'Firefox';
} elseif (preg_match('#Galeon#i', $server_agent)) {
$browser = 'Galeon';
} elseif (preg_match('#Camino#i', $server_agent)) {
$browser = 'Camino';
} elseif (preg_match('#Konqueror#i', $server_agent)) {
$browser = 'Konqueror';
} elseif (preg_match('#Cheshire#i', $server_agent)) {
$browser = 'AOL';
} elseif (preg_match('#Safari#i', $server_agent)) {
$browser = 'Safari';
} elseif (preg_match('#OmniWeb#i', $server_agent)) {
$browser = 'OmniWeb';
} elseif (preg_match('#Opera#i', $server_agent)) {
$browser = 'Opera';
} elseif (preg_match('#HTTrack#i', $server_agent)) {
$browser = 'HTTrack';
} elseif (preg_match('#OffByOne#i', $server_agent)) {
$browser = 'Off By One';
} elseif (preg_match('#amaya#i', $server_agent)) {
$browser = 'Amaya';
} elseif (preg_match('#iCab#i', $server_agent)) {
$browser = 'iCab';
} elseif (preg_match('#Lynx#i', $server_agent)) {
$browser = 'Lynx';
} elseif (preg_match('#Googlebot#i', $server_agent)) {
$browser = 'Googlebot';
} elseif (preg_match('#Lycos_Spider#i', $server_agent)) {
$browser = 'Lycos Spider';
} elseif (preg_match('#Firefly#i', $server_agent)) {
$browser = 'Fireball Spider';
} elseif (preg_match('#Amiga-AWeb#i', $server_agent)) {
$browser = 'AWeb';
} elseif (preg_match('#Cyberdog#i', $server_agent)) {
$browser = 'Cyberdog';
} elseif (preg_match('#Dillo#i', $server_agent)) {
$browser = 'Dillo';
} elseif (preg_match('#DreamPassport#i', $server_agent)) {
$browser = 'DreamCast';
} elseif (preg_match('#eCatch#i', $server_agent)) {
$browser = 'eCatch';
} elseif (preg_match('#ANTFresco#i', $server_agent)) {
$browser = 'Fresco';
} elseif (preg_match('#RSS#i', $server_agent)) {
$browser = 'RSS';
} elseif (preg_match('#Avant#i', $server_agent)) {
$browser = 'Avant';
} elseif (preg_match('#HotJava#i', $server_agent)) {
$browser = 'HotJava';
} elseif (preg_match('#W3C-checklink|W3C_Validator|Jigsaw#i', $server_agent)) {
$browser = 'W3C';
} elseif (preg_match('#K-Meleon#i', $server_agent)) {
$browser = 'K-Meleon';
} elseif (preg_match('#Iceape#i', $server_agent)) {
$browser = 'Iceape';
} elseif (preg_match('#Iceweasel#i', $server_agent)) {
$browser = 'Iceweasel';
} elseif (preg_match('#Kazehakase#i', $server_agent)) {
$browser = 'Kazehakase';
} elseif (preg_match('#Minefield#i', $server_agent)) {
$browser = 'Firefox';
} elseif (preg_match('#Namoroka#i', $server_agent)) {
$browser = 'Firefox';
} elseif (preg_match('#MC680x0#i', $server_agent)) {
$browser = 'Amiga Voyager';
} elseif (preg_match('#AOL #i', $server_agent)) {
$browser = 'AOL';
} elseif (preg_match('#Beonex#i', $server_agent)) {
$browser = 'Beonex';
} elseif (preg_match('#BonEcho#i', $server_agent)) {
$browser = 'Mozilla';
} elseif (preg_match('#Charon#i', $server_agent)) {
$browser = 'Charon';
} elseif (preg_match('#Chimera#i', $server_agent)) {
$browser = 'Chimera';
} elseif (preg_match('#Crazy Browser#i', $server_agent)) {
$browser = 'Crazy Browser';
} elseif (preg_match('#Fennec#i', $server_agent)) {
$browser = 'Firefox';
} elseif (preg_match('#iNet Browser#i', $server_agent)) {
$browser = 'iNet';
} elseif (preg_match('#iSonyEricsson#i', $server_agent)) {
$browser = 'Sony Ericsson';
} elseif (preg_match('#MAXTHON#i', $server_agent)) {
$browser = 'Maxthon';
} elseif (preg_match('#NCSA Mosaic#i', $server_agent)) {
$browser = 'Mosaic';
} elseif (preg_match('#NetNewsWire#i', $server_agent)) {
$browser = 'NetNewsWire';
} elseif (preg_match('#NetPositive#i', $server_agent)) {
$browser = 'NetPositive';
} elseif (preg_match('#Shiira#i', $server_agent)) {
$browser = 'Shiira';
} elseif (preg_match('#Shiretoko#i', $server_agent)) {
$browser = 'Firefox';
} elseif (preg_match('#Sleipnir#i', $server_agent)) {
$browser = 'Sleipnir';
} elseif (preg_match('#Stainless#i', $server_agent)) {
$browser = 'Stainless';
} elseif (preg_match('#Sunrise#i', $server_agent)) {
$browser = 'Sunrise';
}
// Information partially taken from http://www.useragentstring.com/
//Code to get the search string if the referrer is any of the following
$search_engines = array(
'google',
'lycos',
'yahoo'
);
$query_array = array();
foreach ($search_engines as $engine) {
if (is_referer_search_engine($engine)) {
$query_array = get_search_query_terms($engine);
break;
}
}
$query_terms = is_array($query_array) ? implode(',', $query_array) : '';
$return_array = array(
'os' => $os,
'browser' => $browser,
'query_terms' => $query_terms
);
return $return_array;
}
// Add 1 everytime a picture is viewed.
/**
* add_hit()
*
* @param $pid
* @return
**/
function add_hit($pid)
{
global $CONFIG, $raw_ip;
if ($CONFIG['count_file_hits']) {
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET hits = hits + 1, lasthit_ip = '$raw_ip', mtime = CURRENT_TIMESTAMP WHERE pid = $pid");
}
/**
* Code to record the details of hits for the picture, if the option is set in CONFIG
*/
if ($CONFIG['hit_details']) {
// Get the details of user browser, IP, OS, etc
$client_details = cpg_determine_client();
$search_phrase = addslashes($client_details['query_terms']);
//Making Cage
$superCage = Inspekt::makeSuperCage();
$time = time();
//Sanitize the referer
if ($superCage->server->keyExists('HTTP_REFERER')) {
$referer = $superCage->server->getEscaped('HTTP_REFERER');
} else {
$referer = '';
}
$hitUserId = USER_ID;
// Insert the record in database
$query = "INSERT INTO {$CONFIG['TABLE_HIT_STATS']} SET"
." pid = $pid,"
." search_phrase = '$search_phrase',"
." Ip = '$raw_ip',"
." sdate = '$time',"
." referer='$referer',"
." browser = '{$client_details['browser']}',"
." os = '{$client_details['os']}',"
." uid ='$hitUserId'";
cpg_db_query($query);
}
}
/**
* add_album_hit()
* Add a hit to the album.
* @param $pid
* @return
**/
function add_album_hit($aid)
{
global $CONFIG;
if ($CONFIG['count_album_hits']) {
$aid = (int) $aid;
cpg_db_query("UPDATE {$CONFIG['TABLE_ALBUMS']} SET alb_hits = alb_hits + 1 WHERE aid = $aid");
}
}
/**
* breadcrumb()
*
* Build the breadcrumb navigation
*
* @param integer $cat
* @param string $breadcrumb
* @param string $BREADCRUMB_TEXT
* @return
**/
function breadcrumb($cat, &$breadcrumb, &$BREADCRUMB_TEXT)
{
global $lang_list_categories, $lang_common;
global $CONFIG,$CURRENT_ALBUM_DATA, $CURRENT_CAT_NAME;
$category_array = array();
// first we build the category path: names and id
if ($cat != 0) { //Categories other than 0 need to be selected
if ($cat >= FIRST_USER_CAT) {
$result = cpg_db_query("SELECT name FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = " . USER_GAL_CAT);
$row = $result->fetchAssoc(true);
$category_array[] = array(USER_GAL_CAT, $row['name']);
$user_name = get_username($cat - FIRST_USER_CAT);
if (!$user_name) {
$user_name = $lang_common['username_if_blank'];
}
$category_array[] = array($cat, $user_name);
$CURRENT_CAT_NAME = sprintf($lang_list_categories['xx_s_gallery'], $user_name);
$row['parent'] = 1;
} else {
$result = cpg_db_query("SELECT p.cid, p.name FROM {$CONFIG['TABLE_CATEGORIES']} AS c,
{$CONFIG['TABLE_CATEGORIES']} AS p
WHERE c.lft BETWEEN p.lft AND p.rgt
AND c.cid = $cat
ORDER BY p.lft");
while ( ($row = $result->fetchAssoc()) ) {
$category_array[] = array($row['cid'], $row['name']);
$CURRENT_CAT_NAME = $row['name'];
}
$result->free();
}
}
$breadcrumb_links = array();
$BREADCRUMB_TEXTS = array();
// Add the Home link to breadcrumb
$breadcrumb_links[0] = ''.$lang_list_categories['home'].'';
$BREADCRUMB_TEXTS[0] = $lang_list_categories['home'];
$cat_order = 1;
foreach ($category_array as $category) {
$breadcrumb_links[$cat_order] = "{$category[1]}";
$BREADCRUMB_TEXTS[$cat_order] = $category[1];
$cat_order += 1;
}
//Add Link for album if aid is set
if (isset($CURRENT_ALBUM_DATA['aid'])) {
$breadcrumb_links[$cat_order] = "".$CURRENT_ALBUM_DATA['title']."";
$BREADCRUMB_TEXTS[$cat_order] = $CURRENT_ALBUM_DATA['title'];
}
// Build $breadcrumb,$BREADCRUMB_TEXT from _links and _TEXTS
theme_breadcrumb($breadcrumb_links, $BREADCRUMB_TEXTS, $breadcrumb, $BREADCRUMB_TEXT);
} // function breadcrumb
/**************************************************************************
**************************************************************************/
// Get the configured/available image tool class
function getImageTool ()
{
global $CONFIG;
if ($CONFIG['thumb_method'] == 'imx') {
require_once 'include/imageobject_imx.class.php';
} elseif ($CONFIG['thumb_method'] == 'im') {
require_once 'include/imageobject_im.class.php';
} else {
require_once 'include/imageobject_gd.class.php';
}
}
// Compute image geometry based on max width / height
/**
* compute_img_size()
*
* Compute image geometry based on max, width / height
*
* @param integer $width
* @param integer $height
* @param integer $max
* @return array
**/
function compute_img_size($width, $height, $max, $system_icon = false, $normal = false)
{
global $CONFIG;
$thumb_use = $CONFIG['thumb_use'];
if ($thumb_use == 'ht') {
$ratio = $height / $max;
} elseif ($thumb_use == 'wd') {
$ratio = $width / $max;
} else {
$ratio = max($width, $height) / $max;
}
if ($ratio > 1) {
$image_size['reduced'] = true;
}
$ratio = max($ratio, 1);
$image_size['width'] = (int) ($width / $ratio);
$image_size['height'] = (int) ($height / $ratio);
$image_size['whole'] = 'width="' . $image_size['width'] . '" height="' . $image_size['height'] . '"';
if ($thumb_use == 'ht') {
$image_size['geom'] = ' height="' . $image_size['height'] . '"';
} elseif ($thumb_use == 'wd') {
$image_size['geom'] = 'width="' . $image_size['width'] . '"';
//thumb cropping
} elseif ($thumb_use == 'ex') {
if ($normal == 'normal') {
$image_size['geom'] = 'width="' . $image_size['width'] . '" height="' . $image_size['height'] . '"';
} elseif ($normal == 'cat_thumb') {
$image_size['geom'] = 'width="' . $max . '" height="' . ($CONFIG['thumb_height'] * $max / $CONFIG['thumb_width']) . '"';
} else {
$image_size['geom'] = 'width="' . $CONFIG['thumb_width'] . '" height="' . $CONFIG['thumb_height'] . '"';
}
//if we have a system icon we override the previous calculation and take 'any' as base for the calc
if ($system_icon) {
$image_size['geom'] = 'width="' . $image_size['width'] . '" height="' . $image_size['height'] . '"';
}
} else {
$image_size['geom'] = 'width="' . $image_size['width'] . '" height="' . $image_size['height'] . '"';
}
return $image_size;
} // function compute_img_size
// Prints thumbnails of pictures in an album
/**
* display_thumbnails()
*
* Generates data to display thumbnails of pictures in an album
*
* @param mixed $album Either the album ID or the meta album name
* @param integer $cat Either the category ID or album ID if negative
* @param integer $page Page number to display
* @param integer $thumbcols
* @param integer $thumbrows
* @param boolean $display_tabs
**/
function display_thumbnails($album, $cat, $page, $thumbcols, $thumbrows, $display_tabs)
{
global $CONFIG, $USER, $LINEBREAK;
global $lang_date, $lang_display_thumbnails, $lang_byte_units, $lang_common, $valid_meta_albums;
$superCage = Inspekt::makeSuperCage();
$thumb_per_page = $thumbcols * $thumbrows;
$lower_limit = ($page - 1) * $thumb_per_page;
$pic_data = get_pic_data($album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);
$total_pages = ceil($thumb_count / $thumb_per_page);
$i = 0;
if (is_array($pic_data) && $pic_data) {
foreach ($pic_data as $key => $row) {
$i++;
$pic_title = $lang_common['filename'] . '=' . $row['filename'] . $LINEBREAK .
$lang_common['filesize'] . '=' . ($row['filesize'] >> 10) . $lang_byte_units[1] . $LINEBREAK .
$lang_display_thumbnails['dimensions'] . $row['pwidth'] . "x" . $row['pheight'] . $LINEBREAK .
$lang_display_thumbnails['date_added'] . localised_date($row['ctime'], $lang_date['album']);
list($pic_title) = CPGPluginAPI::filter('thumb_html_title', array($pic_title, $row));
$pic_url = get_pic_url($row, 'thumb');
if (!is_image($row['filename'])) {
$image_info = cpg_getimagesize(urldecode($pic_url));
$row['pwidth'] = $image_info[0];
$row['pheight'] = $image_info[1];
}
// thumb cropping - if we display a system thumb we calculate the dimension by any and not ex
if (array_key_exists('system_icon', $row) && ($row['system_icon'] == true)) {
$image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width'], true);
} else {
$image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
}
$thumb_list[$i]['pos'] = $key < 0 ? $key : $i - 1 + $lower_limit;
$thumb_list[$i]['pid'] = $row['pid'];
$thumb_list[$i]['image'] = '';
$thumb_list[$i]['caption'] = bb_decode($row['caption_text']);
$thumb_list[$i]['admin_menu'] = '';
$thumb_list[$i]['aid'] = $row['aid'];
$thumb_list[$i]['pwidth'] = $row['pwidth'];
$thumb_list[$i]['pheight'] = $row['pheight'];
// cpg1.5: new thumb fields below
$thumb_list[$i]['title'] = $row['title'];
$thumb_list[$i]['description'] = $row['caption'];
$thumb_list[$i]['filepath'] = $row['filepath'];
$thumb_list[$i]['filename'] = $row['filename'];
$thumb_list[$i]['filesize'] = $row['filesize'];
$thumb_list[$i]['msg_id'] = isset($row['msg_id']) ? $row['msg_id'] : ''; // needed for get_pic_pos()
}
// Add a hit to album counter if it is a numeric album
if (is_numeric($album)) {
// Create an array to hold the album id for hits (if not created)
if (!isset($USER['liv_a']) || !is_array($USER['liv_a'])) {
$USER['liv_a'] = array();
}
// Add 1 to album hit counter
if ((!USER_IS_ADMIN && $CONFIG['count_admin_hits'] == 0 || $CONFIG['count_admin_hits'] == 1) && !in_array($album, $USER['liv_a']) && $superCage->cookie->keyExists($CONFIG['cookie_name'] . '_data')) {
add_album_hit($album);
if (count($USER['liv_a']) > 4) {
array_shift($USER['liv_a']);
}
array_push($USER['liv_a'], $album);
user_save_profile();
}
}
//Using getRaw(). The date is sanitized in the called function.
$date = $superCage->get->keyExists('date') ? cpgValidateDate($superCage->get->getRaw('date')) : null;
theme_display_thumbnails($thumb_list, $thumb_count, $album_name, $album, $cat, $page, $total_pages, is_numeric($album), $display_tabs, 'thumb', $date);
} elseif (is_numeric($album) || in_array($album, $valid_meta_albums)) {
theme_no_img_to_display($album_name);
}
}
/**
* cpg_get_system_thumb_list()
*
* Return an array containing the system thumbs in a directory
* @param string $search_folder
* @return array
**/
function cpg_get_system_thumb_list($search_folder = 'images/')
{
global $CONFIG;
static $thumbs = array();
$folder = 'images/thumbs/';
$thumb_pfx =& $CONFIG['thumb_pfx'];
// If thumb array is empty get list from coppermine 'images' folder
if ((count($thumbs) == 0) && ($folder == $search_folder)) {
$dir = opendir($folder);
while (($file = readdir($dir)) !== false) {
if (is_file($folder . $file) && strpos($file, $thumb_pfx) === 0) {
// Store filenames in an array
$thumbs[] = array('filename' => $file);
}
}
closedir($dir);
return $thumbs;
} elseif ($folder == $search_folder) {
// Search folder is the same as coppermine images folder; just return the array
return $thumbs;
} else {
// Search folder is different; check for files in the given folder
$results = array();
foreach ($thumbs as $thumb) {
if (is_file($search_folder . $thumb['filename'])) {
$results[] = array('filename' => $thumb['filename']);
}
}
return $results;
}
}
/**
* cpg_get_system_thumb()
*
* Gets data for system thumbs
*
* @param string $filename
* @param integer $user
* @return array
**/
function& cpg_get_system_thumb($filename, $user = FIRST_USER_CAT)
{
global $CONFIG;
// Correct user_id
if ($user < FIRST_USER_CAT) {
$user += FIRST_USER_CAT;
}
if ($user == FIRST_USER_CAT) {
$user = FIRST_USER_CAT + 1;
}
// Get image data for thumb
$picdata = array(
'filename' => $filename,
'filepath' => $CONFIG['userpics'] . $user . '/',
'url_prefix' => 0,
);
$pic_url = get_pic_url($picdata, 'thumb', true);
$picdata['thumb'] = $pic_url;
$image_info = cpg_getimagesize(urldecode($pic_url));
$picdata['pwidth'] = $image_info[0];
$picdata['pheight'] = $image_info[1];
$image_size = compute_img_size($picdata['pwidth'], $picdata['pheight'], $CONFIG['alb_list_thumb_size']);
$picdata['whole'] = $image_size['whole'];
$picdata['reduced'] = (isset($image_size['reduced']) && $image_size['reduced']);
return $picdata;
} // function cpg_get_system_thumb
/**
* display_film_strip()
*
* gets data for thumbnails in an album for the film strip
*
* @param integer $album
* @param integer $cat
* @param integer $pos
**/
function display_film_strip($album, $cat, $pos,$ajax_call)
{
global $CONFIG, $LINEBREAK;
global $lang_date, $lang_display_thumbnails, $lang_byte_units, $lang_common, $pic_count,$ajax_call,$pos;
$superCage = Inspekt::makeSuperCage();
$max_item = $CONFIG['max_film_strip_items'];
$thumb_width = $CONFIG['thumb_width'];
/** set to variable with to javascript*/
set_js_var('thumb_width', $thumb_width);
set_js_var('thumb_use', $CONFIG['thumb_use']);
if ($CONFIG['max_film_strip_items'] % 2 == 0) {
$max_item = $CONFIG['max_film_strip_items'] + 1;
$pic_count = $pic_count + 1;
}
$max_item_real = $max_item;
/** check the thumb_per_page variable valid to query database*/
if ($pic_count < $max_item_real) {
$max_item_real = $pic_count;
}
/** pass the max_items to the dispalyimage.js file */
set_js_var('max_item', $max_item_real);
$max_block_items = $CONFIG['max_film_strip_items'];
$thumb_per_page = $max_item_real;
/** assign the varible $l_limit diffen */
$l_limit = (int) ($max_item_real / 2);
$l_limit = max(0, $pos - $l_limit);
/** set $l_limit to last images */
if ($l_limit > ($pic_count - $max_item_real)) {
$l_limit = $pic_count - $max_item_real;
}
$pic_data = get_pic_data($album, $thumb_count, $album_name, $l_limit, $thumb_per_page, false, 'filmstrip');
if (count($pic_data) < $max_item) {
$max_item = count($pic_data);
}
$lower_limit = 0;
if ($ajax_call == 2) {
$lower_limit = $max_item_real -1;
$max_item = 1;
} elseif ($ajax_call == 1) {
$lower_limit = 0;
$max_item = 1;
}
$pic_data = array_slice($pic_data, $lower_limit, $max_item);
$i = $l_limit;
set_js_var('count', $pic_count);
$cat_link = is_numeric($album) ? '' : '&cat=' . $cat;
//FIXME: Where does this '$date' come from?
if (isset($date) && $date != '') {
$date_link = '&date=' . $date;
} else {
$date_link = '';
}
if ($superCage->get->getInt('uid')) {
$uid_link = '&uid=' . $superCage->get->getInt('uid');
} else {
$uid_link = '';
}
if (count($pic_data) > 0) {
foreach ($pic_data as $key => $row) {
//$hi is never used
//$hi = (($pos == ($i + $lower_limit)) ? '1': '');
$i++;
$pic_alt = $row['filename'];
$pic_title = $lang_common['filename'] . '=' . $row['filename'] . $LINEBREAK .
$lang_common['filesize'] . '=' . ($row['filesize'] >> 10) . $lang_byte_units[1] . $LINEBREAK .
$lang_display_thumbnails['dimensions'] . $row['pwidth'] . "x" . $row['pheight'] . $LINEBREAK .
$lang_display_thumbnails['date_added'] . localised_date($row['ctime'], $lang_date['album']);
list($pic_title) = CPGPluginAPI::filter('thumb_strip_html_title', array($pic_title, $row));
$pic_url = get_pic_url($row, 'thumb');
/*if (!is_image($row['filename'])) {
$image_info = cpg_getimagesize(urldecode($pic_url));
$row['pwidth'] = $image_info[0];
$row['pheight'] = $image_info[1];
}
//thumb cropping
/*if (array_key_exists('system_icon', $row) && ($row['system_icon'] == true)) {
$image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width'], true);
} else {
$image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
}*/ // values never used
$p = $i - 1 + $lower_limit;
$p = ($p < 0 ? 0 : $p);
$thumb_list[$i]['pos'] = $key < 0 ? $key : $p;
$thumb_list[$i]['image'] = '
';
$thumb_list[$i]['admin_menu'] = '';
$thumb_list[$i]['pid'] = $row['pid'];
$thumb_list[$i]['msg_id'] = isset($row['msg_id']) ? $row['msg_id'] : ''; // needed for get_pic_pos()
$msg_id = isset($row['msg_id']) ? '&msg_id='.$row['msg_id'] : '';
$page = isset($row['msg_id']) ? '&page='.cpg_get_comment_page_number($row['msg_id']) : '';
$hash = isset($row['msg_id']) ? '#comment'.$row['msg_id'] : '#top_display_media';
$target = "displayimage.php?album=$album$cat_link$date_link&pid={$row['pid']}$msg_id$page$uid_link$hash";
}
// Get the pos for next and prev links in filmstrip navigation
$filmstrip_next_pos = $pos + 1;
$filmstrip_prev_pos = $pos - 1;
// If next pos is greater then total pics then make it pic_count - 1
$filmstrip_next_pos = $filmstrip_next_pos >= $pic_count ? $pic_count - 1 : $filmstrip_next_pos;
// If prev pos is less than 0 then make it 0
$filmstrip_prev_pos = $filmstrip_prev_pos < 0 ? 0 : $filmstrip_prev_pos;
//Using getRaw(). The date is sanitized in the called function.
$date = $superCage->get->keyExists('date') ? cpgValidateDate($superCage->get->getRaw('date')) : null;
if ($ajax_call == 2 || $ajax_call == 1) {
$setArray = array(
'url' => $pic_url,
'target' => $target,
'alt' => $pic_alt,
'title' => $pic_title,
);
header("Content-Type: text/plain");
echo json_encode($setArray);
} else {
return theme_display_film_strip($thumb_list, $thumb_count, $album_name, $album, $cat, $pos, is_numeric($album), 'thumb', $date, $filmstrip_prev_pos, $filmstrip_next_pos, $max_block_items, $thumb_width);
}
} else {
if ($ajax_call == 2 || $ajax_call == 1) {
$setArray = array(
'url' => 'images/stamp.png',
'target' => 'images/stamp.png',
'alt' => 'stamp.png',
'title' => '',
);
header("Content-Type: text/plain");
echo json_encode($setArray);
} else {
theme_no_img_to_display($album_name);
}
}
}
/**
* display_slideshow()
*
* gets data for thumbnails in an album for the film stript using Ajax call
*
* this added by Nuwan Sameera Hettiarachchi
*
* @param integer $album
* @param integer $cat
* @param integer $pos
**/
function display_slideshow($pos, $ajax_show = 0)
{
global $CONFIG, $album, $pid, $slideshow, $USER;
$superCage = Inspekt::makeSuperCage();
$Pic = array();
$Pid = array();
$Title = array();
$i = 0;
$j = 0;
/** get the pic details by querying database*/
$pic_data = get_pic_data($album, $pic_count, $album_name, $pos, 1, false);
/** calculate total amount of pic a perticular album */
if ($ajax_show == 0) {
set_js_var('Pic_count', $pic_count);
}
foreach ($pic_data as $picture) {
if (is_image($picture['filename'])) {
if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($picture['pwidth'], $picture['pheight'])) {
$picture_url = get_pic_url($picture, 'normal');
} else {
$picture_url = get_pic_url($picture, 'fullsize');
}
$Pic[$i] = htmlspecialchars($picture_url, ENT_QUOTES);
/*if ($picture['pid'] == $pid) {
$j = $i;
$start_img = $picture_url;
}*/ //$j and $start_img are never used
} else {
$pic_url = get_pic_url($picture, 'thumb');
$Pic[$i] = htmlspecialchars($pic_url);
}
$Pid[$i] = $picture['pid'];
$Title[$i] = $picture['title'] ? $picture['title'] : $picture['filename'];
$i++;
}
/** set variables to jquery.slideshow.js */
set_js_var('Time', $slideshow);
set_js_var('Pid', $pid);
/*if (!$i) {
$Pic[0] = 'images/thumb_document.jpg';
}*/
// Add the hit if slideshow hits are enabled in config
if ((!USER_IS_ADMIN && $CONFIG['count_admin_hits'] == 0 || $CONFIG['count_admin_hits'] == 1) && $CONFIG['slideshow_hits'] != 0) {
// Add 1 to hit counter
if (!in_array($Pid['0'], $USER['liv']) && $superCage->cookie->keyExists($CONFIG['cookie_name'] . '_data')) {
add_hit($Pid['0']);
if (count($USER['liv']) > 4) {
array_shift($USER['liv']);
}
array_push($USER['liv'], $Pid['0']);
user_save_profile();
}
}
/** show slide show on first time*/
if ($ajax_show == 0) {
theme_slideshow($Pic['0'], $Title['0']);
}
/** now we make a array to encode*/
$dataArray = array(
'url' => $Pic['0'],
'title' => $Title['0'],
'pid' => $Pid['0'],
);
$dataJson = json_encode($dataArray);
/** send variable to javascript script*/
if ($ajax_show == 1) {
header("Content-Type: text/plain");
echo $dataJson;
}
}
// Return the url for a picture, allows to have pictures spreaded over multiple servers
/**
* get_pic_url()
*
* Return the url for a picture
*
* @param array $pic_row
* @param string $mode
* @param boolean $system_pic
* @return string
**/
function& get_pic_url(&$pic_row, $mode, $system_pic = false)
{
global $CONFIG, $THEME_DIR;
static $pic_prefix = array();
static $url_prefix = array();
if (!count($pic_prefix)) {
$pic_prefix = array(
'thumb' => $CONFIG['thumb_pfx'],
'normal' => $CONFIG['normal_pfx'],
'orig' => $CONFIG['orig_pfx'],
'fullsize' => '',
);
$url_prefix = array(
0 => $CONFIG['fullpath'],
);
}
$mime_content = cpg_get_type($pic_row['filename']);
// If $mime_content is empty there will be errors, so only perform the array_merge if $mime_content is actually an array
if (is_array($mime_content)) {
$pic_row = array_merge($pic_row, $mime_content);
}
$filepathname = null;
// Code to handle custom thumbnails
// If fullsize or normal mode use regular file
if ($mime_content['content'] != 'image' && $mode == 'normal') {
$mode = 'fullsize';
} elseif (($mime_content['content'] != 'image' && $mode == 'thumb') || $system_pic) {
$thumb_extensions = array(
'.gif',
'.png',
'.jpg'
);
// Check for user-level custom thumbnails
// Create custom thumb path and erase extension using filename; Erase filename's extension
if (array_key_exists('url_prefix', $pic_row)) {
$custom_thumb_path = $url_prefix[$pic_row['url_prefix']];
} else {
$custom_thumb_path = '';
}
$custom_thumb_path .= $pic_row['filepath'] . (array_key_exists($mode, $pic_prefix) ? $pic_prefix[$mode] : '');
$file_base_name = str_ireplace('.' . $mime_content['extension'], '', basename($pic_row['filename']));
// Check for file-specific thumbs
foreach ($thumb_extensions as $extension) {
if (file_exists($custom_thumb_path . $file_base_name . $extension)) {
$filepathname = $custom_thumb_path . $file_base_name . $extension;
break;
}
}
if (!$system_pic) {
// Check for extension-specific thumbs
if (is_null($filepathname)) {
foreach ($thumb_extensions as $extension) {
if (file_exists($custom_thumb_path . $mime_content['extension'] . $extension)) {
$filepathname = $custom_thumb_path . $mime_content['extension'] . $extension;
break;
}
}
}
// Check for content-specific thumbs
if (is_null($filepathname)) {
foreach ($thumb_extensions as $extension) {
if (file_exists($custom_thumb_path . $mime_content['content'] . $extension)) {
$filepathname = $custom_thumb_path . $mime_content['content'] . $extension;
break;
}
}
}
}
// Use default thumbs
if (is_null($filepathname)) {
// Check for default theme- and global-level thumbs
$thumb_paths[] = $THEME_DIR.'images/'; // Used for custom theme thumbs
$thumb_paths[] = 'images/thumbs/'; // Default Coppermine thumbs
foreach ($thumb_paths as $default_thumb_path) {
if (is_dir($default_thumb_path)) {
if (!$system_pic) {
foreach ($thumb_extensions as $extension) {
// Check for extension-specific thumbs
if (file_exists($default_thumb_path . $CONFIG['thumb_pfx'] . $mime_content['extension'] . $extension)) {
$filepathname = $default_thumb_path . $CONFIG['thumb_pfx'] . $mime_content['extension'] . $extension;
//thumb cropping - if we display a system thumb we calculate the dimension by any and not ex
$pic_row['system_icon'] = true;
break 2;
}
}
foreach ($thumb_extensions as $extension) {
// Check for media-specific thumbs (movie,document,audio)
if (file_exists($default_thumb_path . $CONFIG['thumb_pfx'] . $mime_content['content'] . $extension)) {
$filepathname = $default_thumb_path . $CONFIG['thumb_pfx'] . $mime_content['content'] . $extension;
//thumb cropping
$pic_row['system_icon'] = true;
break 2;
}
}
} else {
// Check for file-specific thumbs for system files
foreach ($thumb_extensions as $extension) {
if (file_exists($default_thumb_path . $CONFIG['thumb_pfx'] . $file_base_name . $extension)) {
$filepathname = $default_thumb_path . $CONFIG['thumb_pfx'] . $file_base_name . $extension;
//thumb cropping
$pic_row['system_icon'] = true;
break 2;
}
} // foreach $thumb_extensions
} // else $system_pic
} // if is_dir($default_thumb_path)
} // foreach $thumbpaths
} // if is_null($filepathname)
if ($filepathname) {
$filepathname = path2url($filepathname);
}
}
if (is_null($filepathname)) {
$localpath = $pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename'];
// Check here that the filename we are going to return exists
// If it doesn't exist we return a placeholder image
// We then log the missing file for the admin's attention
if (file_exists($url_prefix[$pic_row['url_prefix']] . $localpath)) {
$filepathname = $url_prefix[$pic_row['url_prefix']] . path2url($localpath);
} else {
$filepathname = 'images/thumbs/thumb_nopic.png';
$pic_row['system_icon'] = true;
if ($CONFIG['log_mode'] != 0) {
log_write("File {$url_prefix[$pic_row['url_prefix']]}$localpath is missing.");
}
}
}
// Added hack: "&& !isset($pic_row['mode'])" thumb_data filter isn't executed for the fullsize image
if ($mode == 'thumb' && !isset($pic_row['mode'])) {
$pic_row['url'] = $filepathname;
$pic_row['mode'] = $mode;
$pic_row = CPGPluginAPI::filter('thumb_data', $pic_row);
} elseif ($mode != 'thumb') {
$pic_row['url'] = $filepathname;
$pic_row['mode'] = $mode;
} else {
$pic_row['url'] = $filepathname;
}
$pic_row = CPGPluginAPI::filter('picture_url', $pic_row);
return $pic_row['url'];
} // function get_pic_url
/**
* cpg_get_default_lang_var()
*
* Return a variable from the default language file
*
* @param $language_var_name
* @param unknown $override_language
* @return
**/
function& cpg_get_default_lang_var($language_var_name, $override_language = null)
{
global $CONFIG;
if (is_null($override_language)) {
if (isset($CONFIG['default_lang'])) {
$language = $CONFIG['default_lang'];
} else {
global $$language_var_name;
return $$language_var_name;
}
} else {
$language = $override_language;
}
include 'lang/english.php';
include 'lang/'.$language.'.php';
return $$language_var_name;
} // function cpg_get_default_lang_var
// Returns a variable from the current language file
// If variable doesn't exists gets value from english_us lang file
/**
* cpg_lang_var()
*
* @param $varname
* @param unknown $index
* @return
**/
function& cpg_lang_var($varname, $index = null)
{
global $$varname;
$lang_var =& $$varname;
if (isset($lang_var)) {
if (!is_null($index) && !isset($lang_var[$index])) {
include 'lang/english.php';
return $lang_var[$index];
} elseif (is_null($index)) {
return $lang_var;
} else {
return $lang_var[$index];
}
} else {
include 'lang/english.php';
return $lang_var;
}
} // function cpg_lang_var
/**
* cpg_debug_output()
*
* defined new debug_output function here in functions.inc.php instead of theme.php with different function names to avoid incompatibilities with users not updating their themes as required. Advanced info is only output if (GALLERY_ADMIN_MODE == TRUE)
*
**/
function cpg_debug_output()
{
global $USER, $USER_DATA, $CONFIG, $cpg_time_start, $query_stats, $queries, $lang_cpg_debug_output, $CPG_PHP_SELF, $superCage, $CPG_PLUGINS, $LINEBREAK;
if ($CONFIG['performance_timestamp'] == 0 || (date('Y-m-d', $CONFIG['performance_timestamp']) < date('Y-m-d'))) {
// The metering data in the config table are outdated, let's write fresh values.
// Currently happens each day. To extend the metering period to a whole week,
// use 'Y-m-W' for both date functions above. Use 'Y-m' to extend the period over
// one month and subsequently 'Y' for an entire year.
$CONFIG['performance_timestamp'] = time();
cpg_config_set('performance_timestamp', $CONFIG['performance_timestamp']);
$CONFIG['performance_page_generation_time'] = 0;
$CONFIG['performance_page_query_time'] = 0;
$CONFIG['performance_page_query_count'] = 0;
}
$time_end = cpgGetMicroTime();
$time = round(($time_end - $cpg_time_start) * 1000, 2);
if ($CONFIG['performance_page_generation_time'] < $time) {
$CONFIG['performance_page_generation_time'] = $time;
cpg_config_set('performance_page_generation_time', $CONFIG['performance_page_generation_time']);
}
$query_count = count($query_stats);
$total_query_time = round(array_sum($query_stats), 2);
if ($CONFIG['performance_page_query_time'] < $total_query_time) {
$CONFIG['performance_page_query_time'] = $total_query_time;
cpg_config_set('performance_page_query_time', $CONFIG['performance_page_query_time']);
}
if ($CONFIG['performance_page_query_count'] < $query_count) {
$CONFIG['performance_page_query_count'] = $query_count;
cpg_config_set('performance_page_query_count', $CONFIG['performance_page_query_count']);
}
$debug_underline = '
------------------
';
$debug_separate = '
==========================
';
$debug_toggle_link = $lang_cpg_debug_output['debug_output'] . ': '. $lang_cpg_debug_output['show_hide'].'';
$debug_help = ' '. cpg_display_help('f=empty.htm&h=lang_cpg_debug_output%5Bdebug_output_explain%5D&t=lang_cpg_debug_output%5Bcopy_and_paste_instructions%5D', 470, 245);
$debug_phpinfo_link = GALLERY_ADMIN_MODE ? '' . cpg_fetch_icon('phpinfo', 1) . $lang_cpg_debug_output['phpinfo'] . ' ' : '';
echo <<< EOT