[ABD] Topic preview [/]

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Emanuele
Registered User
Posts: 9
Joined: Wed Jun 02, 2004 10:29 pm
Location: Italy

Post by Emanuele » Sun Jun 06, 2004 10:14 am

XSportSeeker wrote: So.. I´ve just tested this, it looks great buuut....
From what I´ve understood... there´s only preview when the topic is less or equal to 255 characters length?
At least this is how it seemed to work...
Is there an easy way to just don´t mind the length of the text and just put up the 255 first characters with the (...) in the end?


You were right XSportSeeker, it was a bug!
Probably I made an error while transcribing the code.
The variable $sumslash must not be used! It must be $summary. So you need simply to change, in this:

Code: Select all

      if (strlen($summary) > 252) { 
         $summary=substr($sumslash,0,252); 
         $tronca = true; 
      } 
Change:

Code: Select all

$summary=substr($sumslash,0,252); 
With:

Code: Select all

$summary=substr($summary,0,252); 
As for the alt/title version of the preview, I already knew it but my forum uses a lot of HTML and I would like to preview it. Besides, I think that the alt/title version is slower because it requires to open the POST_TEXT db during the forum view and get data from it.

Thanks XSportSeeker, now I will submit my MOD in the MOD Database.
Here is the final version attached:

Code: Select all

############################################################## 
## MOD Title: Topic preview
## MOD Author: Emanuele < manu75@libero.it > (Emanuele Iannone) n/a
## MOD Description: This mod adds a pop-up window that shows the first 255 characters
##							of a topic message when user moves the cursor over the title on the forum view
## MOD Version: 1.0.0
## 
## Installation Level: Easy
## Installation Time: ~5 Minutes 
## Files To Edit:
##					/includes/functions_post.php,
##					/viewforum.php,
##					/templates/subSilver/viewforum_body.tpl,
##
## Included Files: n/a
##
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: 
##   NOTE: The preview will appear only for topics posted/edited AFTER the mod installation
############################################################## 
## MOD History: 
## 
##   2004-06-06 - Version 1.0.0
##      - First release
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 
#
#-----[ SQL ]-------------------------------------------------
#
ALTER TABLE phpbb_topics ADD summary VARCHAR(255);
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : topic preview ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id, &$topic_type, &$bbcode_on, &$html_on, &$smilies_on, &$attach_sig, &$bbcode_uid, &$post_username, &$post_subject, &$post_message, &$poll_title, &$poll_options, &$poll_length)
{
	global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
	global $userdata, $user_ip;
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : topic preview ---------------------------------------------------------------------------
//-- add
	global $bbcode_tpl;
//-- end mod : topic preview -----------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
	if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post']))
	{
		$topic_vote = (!empty($poll_title) && count($poll_options) >= 2) ? 1 : 0;
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : topic preview ---------------------------------------------------------------------------
//-- add
		//
		// Generate summary from message
		//
		$summary=substr(str_replace("''", "\'", $post_message),0,1024);
		
		// Remove last incomplete word
		if (strlen($summary) == 1024) $summary = preg_replace("/[\s][\S]+$/"," ",$summary);

		// If the board has HTML off but the post has HTML on then we process it, else leave it alone
		if ( !$board_config['allow_html'] && $html_on )
		{
			$summary = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $summary);
		}
	
		// Parse message and/or sig for BBCode if reqd
		if ( $board_config['allow_bbcode'] && $bbcode_uid != '' )
		{
			$summary = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($summary, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $summary);
		}
	
		// Parse smilies
		if ( $board_config['allow_smilies'] && $smilies_on )
		{
			$summary = smilies_pass($summary);
		}
	
		// Replace naughty words
		$orig_word = array();
		$replacement_word = array();
		obtain_word_list($orig_word, $replacement_word);
		if (count($orig_word))
		{
			$summary = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $summary . '<'), 1, -1));
		}
	
		// Replace newlines (we use this rather than nl2br because till recently it wasn't XHTML compliant)
		$summary = str_replace("\n", "\n<br />\n", $summary);
			
		// Remove newlines and quotes (for javascript)
		$cerca=array("/(\r|\n)/","/\"/","/[`‘’´]/"); $sost=array("",""","'");
		$summary=preg_replace($cerca,$sost,$summary);
		
		$summary=addslashes(addslashes($summary));
		if (strlen($summary) > 252) {
			$summary=substr($summary,0,252);
			$tronca = true;
		}
		
		// Remove last word if incomplete
		if (strlen($summary)==252) {
			$summary=preg_replace("/[\s][\S]+$/","",$summary);
			while (preg_match("/<[^>]+$/",$summary)) $summary=preg_replace("/[\s]*<[^>]+$/","",$summary);
		}
		
		if (strlen($post_message) > 1024 || $tronca) $summary.="...";
//-- end mod : topic preview -----------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
		$sql  = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . " WHERE topic_id = $topic_id";
#
#-----[ REPLACE WITH ]---------------------------------------- 
#
//-- mod : topic preview ---------------------------------------------------------------------------
//-- del
//		$sql  = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . " WHERE topic_id = $topic_id";
//-- add:
		$sql  = ($mode != "editpost") ? "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote, summary) VALUES ('$post_subject', " . $userdata['user_id'] . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote, '".str_replace("\'", "''", $summary)."')" : "UPDATE " . TOPICS_TABLE . " SET topic_title = '$post_subject', topic_type = $topic_type " . (($post_data['edit_vote'] || !empty($poll_title)) ? ", topic_vote = " . $topic_vote : "") . ", summary = '".str_replace("\'", "''", $summary)."' WHERE topic_id = $topic_id";
//-- end mod : topic preview -----------------------------------------------------------------------
#-----[ OPEN ]------------------------------------------------
#
viewforum.php
#
#-----[ FIND ]------------------------------------------------
#
<?php
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : topic preview ---------------------------------------------------------------------------
#
#-----[ FIND ]------------------------------------------------
#
			'TOPIC_TITLE' => $topic_title,
			'TOPIC_TYPE' => $topic_type,
#
#-----[ AFTER, ADD ]------------------------------------------
#
//-- mod : topic preview ---------------------------------------------------------------------------
//-- add
			'TOPIC_SUMMARY' => $topic_rowset[$i]['summary'],
//-- end mod : topic preview -----------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/viewforum_body.tpl
#
#-----[ FIND ]------------------------------------------------
#
# at top of the file
#
<form method="post" action="{S_POST_DAYS_ACTION}">
#
#-----[ BEFORE, ADD ]-----------------------------------------
#
<!-- mod : topic preview -->
<DIV ID=dek style="position: absolute; visibility: hidden; Z-INDEX:200; top: 0px; left: 0px"></DIV>
<SCRIPT TYPE="text/javascript"><!--
var old,yyy=-1000,Xoffset=-60,Yoffset= 20;
if (!document.getElementById) old=true;
else {
	var skn=document.getElementById('dek');
	if(!document.all) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=get_mouse;
}
function popup(msg,bak){
	var content="<TABLE  WIDTH=350 BORDER=1 BORDERCOLOR=#664500 CELLPADDING=2 CELLSPACING=0 "+"BGCOLOR="+bak+"><tr><TD><FONT COLOR=black SIZE=2 face=verdana>"+msg+"</FONT></TD></tr></TABLE>";
	if(!old){ yyy=Yoffset; skn.innerHTML=content; skn.style.visibility="visible"}
}
function get_mouse(e){
	var x=(document.all)?event.x+document.body.scrollLeft:e.pageX;
	var y=(document.all)?event.y+document.body.scrollTop:e.pageY;
	skn.style.left=x+Xoffset; skn.style.top=y+yyy;
}
function kill(){ if(!old){yyy=-1000;skn.style.visibility="hidden";} }
//--></SCRIPT>
#
#-----[ FIND ]------------------------------------------------
#
	  <td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />
#
#-----[ IN-LINE FIND ]---------------------------------------- 
#
<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle"
#
#-----[ IN-LINE AFTER, ADD ]--------------------------------
#
 ONMOUSEOVER="popup('{topicrow.TOPIC_SUMMARY}','#FFCC66')" ONMOUSEOUT="kill()"
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------------
#
# EoM

User avatar
anor
Registered User
Posts: 48
Joined: Mon Apr 29, 2002 11:18 pm
Location: The Netherlands

Re: Here ya go!

Post by anor » Sun Jun 06, 2004 11:31 am

addit wrote: You betta be darned happy anor!!! I made this just for you hehehe. Doesn't need to change db or use javascript. It will work on ALL posts.

Enjoy!

Code: Select all

############################################################## 
## MOD Title: Topic Preview 
## MOD Author: Addit < adam_marcus@btinternet.com > (Adam Marcus) N/A 
## MOD Description: This mod adds an alt that shows the first 255 characters of a topic 
##                  when user moves the cursor over the topic title in forum view.
## MOD Version: 1
## 
## Installation Level: Easy 
## Installation Time: ~5 Minutes 
## Files To Edit: 
##               /viewforum.php, 
##               /templates/subSilver/viewforum_body.tpl
## 
## Included Files: N/A
## 
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: 
##    A simple solution without reverting to javascript.
############################################################## 
## MOD History: 
## 
##   2004-06-05 - Version 1
##      - First release 
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################
#
#----------[ OPEN ]-------------------------------------------
#
viewforum.php
#
#----------[ FIND ]-------------------------------------------
#
		$views = $topic_rowset[$i]['topic_views'];
#---------[ BEFORE, ADD ]-------------------------------------
		// topic preview mod start -------->

		// get first post of topic
		$sql = "SELECT post_text FROM " . POSTS_TEXT_TABLE . " WHERE post_id=" . $topic_rowset[$i]['topic_first_post_id'];
		$post_result = $db->sql_query($sql);
		$post_row = $db->sql_fetchrow($post_result); 
		$db->sql_freeresult($post_result);

		// replace html tags and trim length to 255
		$summary = $post_row['post_text'];
		if (strlen($summary) > 252) $summary=substr($summary,0,252) . "...";
		$summary = preg_replace("/\[.+\]/iU",'',$summary); 
		$summary = htmlspecialchars(strip_tags($summary));

		// <--------- topic preview mod end

#
#----------[ FIND ]-------------------------------------------
#
        		 'TOPIC_TITLE' => $topic_title, 
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
         		'TOPIC_SUMMARY' => $summary, 
#
#----------[ OPEN ]-------------------------------------------
#
templates/subSilver/viewforum_body.tpl 
# 
#-----[ FIND ]------------------------------------------------ 
# 
     <td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />
# 
#-----[ REPLACE WITH ]---------------------------------------- 
# 
     <td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" title="{topicrow.TOPIC_SUMMARY}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />
# 
#-----[ SAVE/CLOSE ALL FILES ]-------------------------------- 
# 
# EoM
Ow, hands hurting... :lol: try it and tell em if it works or not lol. Also, you think I should submit this?

Adam


Works like a charm :) Yeah submit this it is great 8)

XSportSeeker
Registered User
Posts: 39
Joined: Fri May 28, 2004 10:04 pm

Post by XSportSeeker » Sun Jun 06, 2004 7:08 pm

So, we have here two different codes that seems to be working fine and they both do the same thing.
I think both are valid, an both should be submitted.
Addit's code doen't require any DB changes.
Emanuele's code is fast as it retrieves the preview directly from the database instead of processing the original message.

Both has good points, and I think different users will choose different codes, so you both can submitt it! :)

Thankz for your mods and good work!

User avatar
amedee
Registered User
Posts: 12
Joined: Sat Jun 05, 2004 5:49 pm
Location: Paris, France

Post by amedee » Mon Jun 07, 2004 8:43 pm

In some systems and browsers (MacOSX with Safari for instance), the preview in the little yello box doesn't work. For those who want to see the preview displayed below the title, I've amended anor's MOD :

I took this code

Code: Select all

<td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" title="{topicrow.TOPIC_SUMMARY}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />{topicrow.GOTO_PAGE}</span></td>
And changed it into :

Code: Select all

<td class="row1" width="100%"><span class="topictitle">{topicrow.NEWEST_POST_IMG}{topicrow.TOPIC_TYPE}<a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a></span><span class="gensmall"><br />{topicrow.GOTO_PAGE}</span><br><span class="copyright">{topicrow.TOPIC_SUMMARY}</span></td>
I've used the "span class=copyright" font size so it's not too big (looks like the footer on every page).

My next ambition would be to hide this preview when the topic has been read by the member...

Thanks for you help!

2thumbsup
Registered User
Posts: 33
Joined: Mon Aug 25, 2003 12:54 pm
Contact:

Post by 2thumbsup » Sat Jun 26, 2004 2:49 am

I tried both, and I like Addicts better.

XSportSeeker
Registered User
Posts: 39
Joined: Fri May 28, 2004 10:04 pm

Post by XSportSeeker » Sat Jun 26, 2004 10:51 pm

Ok, I came up with a way to prevent topic preview from retrieving stuff that's on Spoiler bbCode tags.
Have to admit that it wasn't very easy to learn how to use those damm regular expressions...
Ok, for Emmanuele's Topic Preview you have to do this before putting the summary on DB, and for Anor's, you have to do this right after retrieving the text message from DB to the $summary variable (before stripping html tags and reducing the string to 252 characters).

Basically, you have to use a preg_replace function (which I really would appreciate if people who understand regular expressions evaluated it, to see if it will work in all cases)... something like this:

Code: Select all

$summary = preg_replace("/(\[spoiler.*\])(.*)(\[\/spoiler.*\])/",'',$summary);
I made some tests and it seems to work. I had to add .* inside spoiler tags because when the post message is stored, spoiler bbCodes changes to something like [spoiler:88skds] [/spoiler:88skds].. probably to have some control over multiple spoilers on the same message.
That's it. If the mod makers want to add this to their codes, no problems...
Any doubts, pm me, or reply to this message!

quick5pnt0
Registered User
Posts: 1083
Joined: Sun May 16, 2004 1:16 am
Contact:

Post by quick5pnt0 » Mon Sep 20, 2004 8:19 am

I don't mean to bring a topic back from the dead, but i just wanted to thank you for this mod, i just tried it on 2.0.10 and it works like a charm. I used addit's version.
Thanks again
Mike

TamaraHerself
Registered User
Posts: 1
Joined: Mon Sep 27, 2004 8:36 pm

Post by TamaraHerself » Mon Sep 27, 2004 8:42 pm

Hate to drag this here, but I was hoping someone would help, as I'm a bit new to all of this, and the MOD Support forum is closed.

I'm working with Emanuele's version, and I'm getting this:


Image

See the \ every time there's an ' ? What did I do wrong? I keep looking at the different bits of code, and I can't figure it out... did I jack something up?

~Tamara

Emanuele
Registered User
Posts: 9
Joined: Wed Jun 02, 2004 10:29 pm
Location: Italy

Post by Emanuele » Mon Sep 27, 2004 9:12 pm

Tamara wrote: See the \ every time there's an ' ? What did I do wrong? I keep looking at the different bits of code, and I can't figure it out... did I jack something up?


Ok Tamara, it was another bug. Now is corrected.
Simply open includes/functions_post.php, find this line:

Code: Select all

$summary=substr(str_replace("''", "\'", $post_message),0,1024);
and replace it with:

Code: Select all

$summary=substr(str_replace("''", "'", $post_message),0,1024);
It should work.
Now I updated firs message in this topic with the new 1.0.1 version of the MOD.

shipupride
Registered User
Posts: 13
Joined: Fri Jul 18, 2003 2:37 pm

Re: Here ya go!

Post by shipupride » Wed Sep 29, 2004 6:17 pm

addit wrote: You betta be darned happy anor!!! I made this just for you hehehe. Doesn't need to change db or use javascript. It will work on ALL posts.

Enjoy!

Adam


I couldnt get this to work... can anyone help?

[Cyanide]
Registered User
Posts: 14
Joined: Tue Oct 05, 2004 7:04 am
Location: Buffalo, NY
Contact:

Post by [Cyanide] » Mon Oct 11, 2004 8:04 am

Hey sorry to bring this thread back from the dead again, but I have a question.

I have addit's mod on 2 of the forums I run, and it works great. But I also want the thread preview to work when I click on "View posts since last visit".

Is there an easy way to do this?

XSportSeeker
Registered User
Posts: 39
Joined: Fri May 28, 2004 10:04 pm

Post by XSportSeeker » Mon Oct 11, 2004 6:18 pm

Shouldn't be too hard...
You just have to find the right file and place to put the mod, but remember that every "preview" you put on your forum will result in DB queries, thus making your server work extra-time. :P
I'll take a look at the code here, and give you an answer later... but won't promise when because I'm very busy right now. :D

[Cyanide]
Registered User
Posts: 14
Joined: Tue Oct 05, 2004 7:04 am
Location: Buffalo, NY
Contact:

Post by [Cyanide] » Mon Oct 11, 2004 6:37 pm

Thanks man :)

User avatar
rastus
Registered User
Posts: 15
Joined: Fri Dec 27, 2002 5:26 am
Location: San Antonio, Texas
Contact:

Post by rastus » Fri Oct 22, 2004 6:30 pm

thanks Addit :D :D
Never be afraid to try something new. Remember, a lone amateur built the Ark and a large group of professionals built the Titanic.

surfrider1
Registered User
Posts: 9
Joined: Thu Mar 18, 2004 7:44 pm

Post by surfrider1 » Sun Oct 31, 2004 10:05 am

I am trying to make my Forum more search engine friendly. I think this mod could really help. Here is what I have in mind. Search engines seem to always grab information from the header and show it on search results which usually doesn't accurately reflect what is available in the topic. I would like to take the first 200 words from the post and insert it into the meta description.

<meta name="description" content="{TOPIC_SUMMARY}">

Locked

Return to “[2.0.x] MODs in Development”