Nicolas phpBB SEO Team


Inscrit le: 25 Aoû 2006 Messages: 120
|
Posté le: Jeu Nov 16, 2006 9:36 pm Sujet du message: [MOD] Resume and Bookmark mod |
|
|
Voici un mod que j'ai crée pour ne plus perdre le fil d'un topic.
Il a été créé l'année dernière car il m'arrivait souvent de me connecter au forum sans forcément lire tous les sujets. Le problème étant qu'après plusieurs connexions au forum, il faut, pour ces sujets, partir à la recherche du dernier message réellement non lu.
C'est ce que fait automatiquement le mod lorsque vous cliquez sur l'icône "Resume".
Je viens tout juste de l'optimiser pour diminuer au strict minimum le nombre de requêtes.
Le mod est disponible en anglais et français. Si vous décidez de l'installer, n'hésitez pas à donner vos remarques.
Le lien pour le télécharger:
http://www.vag-forum.com/mods/resume_0.9.2.zip
Et les instructions du mod:
| Code: | ##############################################################
## MOD Title: Resume and Bookmark MOD
## MOD Author: vag-forum <webmaster> (Nicolas) http://www.VAG-Forum.com
## MOD Description:
## When you follow one or more topics and you connect or disconnect several times from your forum, if any new messages are posted you can no longer tell which was the last message that you actually read.
## The phpBB shows the new messages only since you last connected, so you have to go back in each topic to find the last message actually read.
## So this mod allows you to get rid of this annoying chore by clicking on the "Resume" icon
## It stores the information in the new phpbb_resume table.
## The bookmark feature comes as an extra bonus, because it also uses the phpbb_resume table by adding only one tiny column - smallint(1) - to manage the members' bookmarks.
## So the "Bookmark" icon adds or removes the topic from the list of the bookmarked topics.
## The users can view the bookmarked topics by clicking on the link added on the index page.
## MOD Version: 0.9.2
##
## Installation Level: (Intermediate)
## Installation Time: 20 Minutes
## Files To Edit:
## includes/constants.php,
## includes/page_header.php,
## language/lang_english/lang_main.php,
## templates/subSilver/index_body.tpl,
## templates/subSilver/search_results_topics.tpl,
## templates/subSilver/subSilver.cfg,
## templates/subSilver/overall_footer.tpl,
## templates/subSilver/viewforum_body.tpl,
## templates/subSilver/viewtopic_body.tpl,
## search.php,
## viewforum.php,
## viewtopic.php
## Included Files:
## phpbb_root/templates/subSilver/images/icon_bookmark_in.gif,
## phpbb_root/templates/subSilver/images/icon_bookmark_out.gif,
## phpbb_root/templates/subSilver/images/icon_resume.gif
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## Author Notes: You need to create a new table in the phpbb database (phpbb_resume, if necessary replace the prefix phpbb_) in order to store the user data.
## Do not hesitate to post your comments either in english or french on the topic as follows :
## http://www.vag-forum.com/forum/resume-and-bookmark-mod-vt116.html
##############################################################
## MOD History:
##
## 2006-11-11 - Version 0.9.2
## - optimizations
## 2005-09-23 - Version 0.9.1
## - initial release
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ SQL ]---------------------------------
#
CREATE TABLE `phpbb_resume` (
`user_id` mediumint(8) NOT NULL default '0',
`topic_id` mediumint(8) unsigned NOT NULL default '0',
`post_id` mediumint(8) unsigned NOT NULL default '0',
`bookmark` smallint(1) default '0',
KEY `user_id` (`user_id`,`topic_id`)
);
#
#-----[ COPY ]------------------------------------------
#
copy phpbb_root/templates/subSilver/images/*.gif to templates/subSilver/images/*.gif
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]---------------------------------
#
?>
#
#-----[ BEFORE, ADD ]---------------------------------------
#
define('RESUME_TABLE', $table_prefix.'resume');
#
#-----[ OPEN ]------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]---------------------------------
#
'L_SEARCH_SELF' => $lang['Search_your_posts'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
'L_SEARCH_BOOKMARK' => $lang['Search_bookmark'],
#
#-----[ FIND ]---------------------------------
#
'U_SEARCH_NEW' => append_sid('search.'.$phpEx.'?search_id=newposts'),
#
#-----[ AFTER, ADD ]------------------------------------------
#
'U_SEARCH_BOOKMARK' => append_sid('search.'.$phpEx.'?search_id=bookmark'),
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]---------------------------------
#
//
// That's all, Folks!
// -------------------------------------------------
#
#-----[ BEFORE, ADD ]---------------------------------------
#
$lang['Resume_topic'] = 'View topic resume';
$lang['Resume_bookmark_in'] = 'Add the topic to the bookmarks';
$lang['Resume_bookmark_out'] = 'Remove the topic from the bookmarks';
$lang['Search_bookmark'] = 'See the favorite topics';
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]---------------------------------
#
<a>{L_SEARCH_UNANSWERED}</a></td>
#
#-----[ REPLACE WITH ]---------------------------------------------------------------
#
<a>{L_SEARCH_UNANSWERED}</a><br>
<a>{L_SEARCH_BOOKMARK}</a></td>
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/search_results_topics.tpl
#
#-----[ FIND ]---------------------------------
#
<td><span>{searchresults.NEWEST_POST_IMG}{searchresults.TOPIC_TYPE}<a>{searchresults.TOPIC_TITLE}</a></span><br><span>{searchresults.GOTO_PAGE}</span></td>
#
#-----[ IN-LINE FIND ]---------------------------------
#
{searchresults.TOPIC_TITLE}</a>
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------
#
{searchresults.RESUME}
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/subSilver.cfg
#
#-----[ FIND ]---------------------------------
#
?>
#
#-----[ BEFORE, ADD ]---------------------------------------
#
$images['icon_resume'] = "$current_template_images/icon_resume.gif";
$images['icon_bookmark_in'] = "$current_template_images/icon_bookmark_in.gif";
$images['icon_bookmark_out'] = "$current_template_images/icon_bookmark_out.gif";
#
#-----[ OPEN ]------------------------------------------
# Note : the modification in overall_footer.tpl is not mandatory, so apply it only if you want to thank me ;)
templates/subSilver/overall_footer.tpl
#
#-----[ FIND ]---------------------------------
#
Powered by <a>phpBB</a> © 2001, 2005 phpBB Group<br>
#
#-----[ IN-LINE FIND ]---------------------------------
#
<br>
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------------
#
<a>Resume Mod</a> by <a>VAG-Forum</a><br>
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewforum_body.tpl
#
#-----[ FIND ]---------------------------------
# Line containing this code
<a>{topicrow.TOPIC_TITLE}</a></span>
#
#-----[ IN-LINE FIND ]---------------------------------
#
</span>
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------
#
{topicrow.RESUME}
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewtopic_body.tpl
#
#-----[ FIND ]---------------------------------
#
<td><a>{TOPIC_TITLE}</a><br>
#
#-----[ IN-LINE FIND ]---------------------------------
#
</a>
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------
#
{BOOKMARK_IMG}
#
#-----[ OPEN ]------------------------------------------
#
search.php
#
#-----[ FIND ]---------------------------------
#
if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
#
#-----[ IN-LINE FIND ]---------------------------------
#
$search_author != ''
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------
#
|| $search_id == 'bookmark'
#
#-----[ FIND ]---------------------------------
#
if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) )
#
#-----[ IN-LINE FIND ]---------------------------------
#
( $search_author != '' && $search_keywords == '' )
#
#-----[ IN-LINE AFTER, ADD ]---------------------------------
#
|| $search_id == 'bookmark'
#
#-----[ FIND ]---------------------------------
#
else
{
redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=egosearch", true));
}
$show_results = 'topics';
$sort_by = 0;
$sort_dir = 'DESC';
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
else if ( $search_id == 'bookmark' )
{
if ( $userdata['session_logged_in'] )
{
$sql = "SELECT post_id
FROM " . RESUME_TABLE . "
WHERE user_id = " . $userdata['user_id'] . "
AND bookmark = 1";
}
else
{
redirect(append_sid("login.$phpEx?redirect=search.$phpEx&search_id=bookmark", true));
}
$show_results = 'topics';
$sort_by = 0;
$sort_dir = 'DESC';
}
#
#-----[ FIND ]---------------------------------
#
else
{
$goto_page = '';
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ($userdata['session_logged_in']) {
$resume = '<a><img></a>';
}
#
#-----[ FIND ]---------------------------------
#
'GOTO_PAGE' => $goto_page,
#
#-----[ AFTER, ADD ]------------------------------------------
#
'RESUME' => $resume,
#
#-----[ OPEN ]------------------------------------------
#
viewforum.php
#
#-----[ FIND ]---------------------------------
#
$view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ($userdata['session_logged_in']) {
$resume_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&view=resume");
$resume = '<a><img></a>';
}
#
#-----[ FIND ]---------------------------------
#
'GOTO_PAGE' => $goto_page,
#
#-----[ AFTER, ADD ]------------------------------------------
#
'RESUME' => $resume,
#
#-----[ OPEN ]------------------------------------------
#
viewtopic.php
#
#-----[ FIND ]---------------------------------
#
if ( isset($HTTP_GET_VARS[POST_POST_URL]))
{
$post_id = intval($HTTP_GET_VARS[POST_POST_URL]);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( isset($HTTP_GET_VARS['bookmark']))
{
$bookmark = intval($HTTP_GET_VARS['bookmark']);
}
#
#-----[ FIND ]---------------------------------
#
else
{
$message = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'No_newer_topics' : 'No_older_topics';
message_die(GENERAL_MESSAGE, $message);
}
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Resume Mod BEGIN
else if ( $HTTP_GET_VARS['view'] == 'resume' )
{
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) || isset($HTTP_GET_VARS['sid']) )
{
$session_id = isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid']) ? $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_sid'] : $HTTP_GET_VARS['sid'];
if (!preg_match('/^[A-Za-z0-9]*$/', $session_id))
{
$session_id = '';
}
if ( $session_id )
{
$sql = "SELECT post_id FROM " . RESUME_TABLE . " r, " . SESSIONS_TABLE . " s
WHERE s.session_id = '$session_id'
AND r.user_id = s.session_user_id
AND topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain resume information', '', __LINE__, __FILE__, $sql);
}
if ( ($row = $db->sql_fetchrow($result)) ) {
// Is the post_id exist ?
$post_id = $row['post_id'];
$sql = "SELECT post_id FROM " . POSTS_TABLE . "
WHERE post_id = $post_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain posts information', '', __LINE__, __FILE__, $sql);
}
// Is the post_id deleted ?
if (!($row = $db->sql_fetchrow($result))) {
// Yes, so select the previous post_id
$sql = "SELECT post_id FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id
AND post_id < $post_id
ORDER BY post_id DESC";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain posts information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
if ($row) {
$post_id = $row['post_id'];
} else {
$post_id = '';
}
}
if (isset($HTTP_GET_VARS['sid']))
{
redirect("viewtopic.$phpEx?sid=$session_id&" . POST_POST_URL . "=$post_id#$post_id");
}
else
{
redirect("viewtopic.$phpEx?" . POST_POST_URL . "=$post_id#$post_id");
}
}
}
}
}
// Resume Mod END
#
#-----[ FIND ]---------------------------------
#
$pagination = ( $highlight != '' ) ? generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order&highlight=$highlight", $total_replies, $board_config['posts_per_page'], $start) : generate_pagination("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&postdays=$post_days&postorder=$post_order", $total_replies, $board_config['posts_per_page'], $start);
#
#-----[ AFTER, ADD ]------------------------------------------
#
// Update the resume and bookmark table BEGIN
if ($userdata['session_logged_in']) {
$resume = $postrow[$total_posts-1]['post_id'];
$sql = "SELECT post_id,bookmark from " . RESUME_TABLE . "
WHERE user_id = " . $userdata['user_id'] . " AND topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain resume information', '', __LINE__, __FILE__, $sql);
}
if ( ($row = $db->sql_fetchrow($result)) )
{
if ($resume > $row['post_id'] || isset($bookmark)) {
if ($resume > $row['post_id']) $resume_sql = " post_id = $resume";
if (isset($bookmark))
{
$bookmark_sql = ($resume_sql ? ", ":"") . "bookmark = $bookmark";
}
$sql = "UPDATE " . RESUME_TABLE . "
SET $resume_sql $bookmark_sql
WHERE user_id = " . $userdata['user_id'] . " AND topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Could not update resume.", '', __LINE__, __FILE__, $sql);
}
}
if (!isset($bookmark))
{
$bookmark = $row['bookmark'];
}
} else {
$sql = "INSERT INTO " . RESUME_TABLE . "
(post_id, user_id, topic_id, bookmark) VALUES($resume," . $userdata['user_id'] . ", $topic_id, 0)";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Could not insert resume.", '', __LINE__, __FILE__, $sql);
}
}
// Bookmark
$bookmark_value = ($bookmark == 1 )? 0:1;
$bookmark_icon = ($bookmark == 1 )? "out":"in";
$bookmark_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&bookmark=" . $bookmark_value);
$bookmark_img = '<a><img></a>';
}
// Update the resume and bookmark table END
#
#-----[ FIND ]---------------------------------
#
'U_VIEW_FORUM' => $view_forum_url,
#
#-----[ AFTER, ADD ]------------------------------------------
#
'BOOKMARK_IMG' => $bookmark_img,
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM |
|
_________________ http://www.VAG-Forum.com |
|