代碼: 選擇全部
########################################################################################
## MOD Title: Smartor Album Add-On: Next/Previous Fix
## MOD Author: PenP
## MOD Description: This mod fixes the "next pic does not exsist" when you
## click "next" on the last picture in the current category.
## With this mod you will be redirected to the "first" picture
## of the current category, when you click "next" on the
## last picture in the current category.
## It will also redirected you to the "last" pic when you
## click previous on the first picture.
##
## MOD Version: 1.0.0
##
## * NOTE: This mod only works for Smartor's excellent "Photo Album Addon v2"
## Download here - http://smartor.is-root.com/viewtopic.php?t=2473
##
## Installation Level: easy
## Installation Time: 3 Minutes
## Files To Edit: 1
## Included Files: album_page.php
##
#########################################################################################
#
#-----[ OPEN ]------------------------------------------
#
album_page.php
#
#-----[ FIND ]------------------------------------------
#
// ------------------------------------
// PREVIOUS & NEXT
// ------------------------------------
if( isset($HTTP_GET_VARS['mode']) )
{
if( ($HTTP_GET_VARS['mode'] == 'next') or ($HTTP_GET_VARS['mode'] == 'previous') )
{
$sql = "SELECT pic_id, pic_cat_id, pic_user_id
FROM ". ALBUM_TABLE ."
WHERE pic_id = $pic_id";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if( empty($row) )
{
message_die(GENERAL_ERROR, 'Bad pic_id');
}
$sql = "SELECT new.pic_id, new.pic_time
FROM ". ALBUM_TABLE ." AS new, ". ALBUM_TABLE ." AS cur
WHERE cur.pic_id = $pic_id
AND new.pic_id <> cur.pic_id
AND new.pic_cat_id = cur.pic_cat_id";
$sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " AND new.pic_time >= cur.pic_time" : " AND new.pic_time <= cur.pic_time";
$sql .= ($row['pic_cat_id'] == PERSONAL_GALLERY) ? " AND new.pic_user_id = cur.pic_user_id" : "";
$sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " ORDER BY pic_time ASC LIMIT 1" : " ORDER BY pic_time DESC LIMIT 1";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if( empty($row) )
{
message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
}
$pic_id = $row['pic_id']; // NEW pic_id
}
}
#
#-----[ REPLACE WITH ]------------------------------------------
#
// ------------------------------------
// PREVIOUS & NEXT
// ------------------------------------
if( isset($HTTP_GET_VARS['mode']) )
{
if( ($HTTP_GET_VARS['mode'] == 'next') or ($HTTP_GET_VARS['mode'] == 'previous') )
{
$sql = "SELECT pic_id, pic_cat_id, pic_user_id
FROM ". ALBUM_TABLE ."
WHERE pic_id = $pic_id";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$cur_pic_cat = $row['pic_cat_id'];
if( empty($row) )
{
message_die(GENERAL_ERROR, 'Bad pic_id');
}
$sql = "SELECT new.pic_id, new.pic_time
FROM ". ALBUM_TABLE ." AS new, ". ALBUM_TABLE ." AS cur
WHERE cur.pic_id = $pic_id
AND new.pic_id <> cur.pic_id
AND new.pic_cat_id = cur.pic_cat_id";
$sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " AND new.pic_time >= cur.pic_time" : " AND new.pic_time <= cur.pic_time";
$sql .= ($row['pic_cat_id'] == PERSONAL_GALLERY) ? " AND new.pic_user_id = cur.pic_user_id" : "";
$sql .= ($HTTP_GET_VARS['mode'] == 'next') ? " ORDER BY pic_time ASC LIMIT 1" : " ORDER BY pic_time DESC LIMIT 1";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$sql = "SELECT min(pic_id), max(pic_id)
FROM ". ALBUM_TABLE ."
WHERE pic_cat_id = $cur_pic_cat";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query pic information', '', __LINE__, __FILE__, $sql);
}
$next = $db->sql_fetchrow($result);
$first_pic = $next['min(pic_id)'];
$last_pic = $next['max(pic_id)'];
if( empty($row) AND ($HTTP_GET_VARS['mode'] == 'next'))
{
redirect(append_sid("album_page.$phpEx?pic_id=$first_pic"));
}
if( empty($row) AND ($HTTP_GET_VARS['mode'] == 'previous'))
{
redirect(append_sid("album_page.$phpEx?pic_id=$last_pic"));
}
$pic_id = $row['pic_id']; // NEW pic_id
}
}
#
#-----[ SAVE/CLOSE THE FILE ]------------------------------------------
#
# End