MOD: Topic Preview

A forum for my MODS, tricks, & tips.

MOD: Topic Preview

Postby paul » Sun Jan 27, 2008 12:46 pm

MOD Title: Topic Preview
MOD Description: It shows a short preview of the first or last post's text when you hover over the topic title. It is admin configurable and can be user configurable (if admin allows). It works in searches as well as regular topic pages.
MOD Version: 0.7.0a
phpBB.com MOD Development Thread:
http://www.phpbb.com/community/viewtopic.php?f=70&t=794905

Notes: I am now the official maintainer/developer of this mod. I am the third developer of the mod. I took it over between version 0.5.4 and 0.5.5.

MOD Download: http://www.paulgarvin.net/code/topic_preview_0.7.0a.zip

Demo Board: Here

Changes in 0.7.0a:
  • Fixed an edit location in search.php.
  • Replaced all occurrences of document with this.topiclink in showpreview and hide preview methods in topic_preview.html.


Changes in 0.7.0:
  • Re-wrote Javascript to fix Internet Explorer flicker and mouseover issues.
  • Revised the way the text is passed to the template engine due to the Javascript changes.
  • Removed the call-time pass-by-reference from viewforum.php and search.php that caused a warning on some PHP installations.

Changes in 0.6.1:
  • Updated for phpBB 3.0.1

Changes in 0.6.0:
  • Added Topic Preview to search results.
  • Can now preview first or last post.
  • Most code moved out of viewforum.php and into the TopicPreview class.
  • Code to determine if Topic Preview is to be displayed rewritten.
  • Code to strip out bbcodes & magic links revised. Now leaves all urls, emails, smilie text in preview (except urls inside the url bbcode).

Changes in 0.5.5:
  • Fixed issues with line wraps in the preview text.
  • Fixed some template variable assignments.
  • Improved (in my mind) the look of the box that contains the preview. The original design mimics the look of the prosilver index page and topic list with the rounded corners and thick borders. My version uses a thin 1px rectangular border and a light background.

Previous Versions Development Threads:
Last edited by paul on Fri Jun 27, 2008 6:32 pm, edited 5 times in total.
Reason: 0.7.0 Release
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Mon Feb 18, 2008 8:59 pm

I made a typo concerning the 1st edit of viewforum_body.html. This typo results in a fatal error when viewforum_body.html is loaded. Make sure that you have version 0.5.5 release "a". ( topic_preview_0.5.5a.zip )
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Tue Feb 26, 2008 10:55 pm

I have taken over as developer/maintainer of this mod.

I have also released another bugfix via version 0.5.5b. The edit to includes/functions_display.php where a line was commented out was removed. The comment prevented the NEW POSTS, NO NEW POSTS, TOPIC MOVED hints from being displayed.

Look for a version 0.6.0 in a few weeks. The plan is to remove some functions that do not make sense (like Topic Preview for Bots), to look into showing bbcodes and smilies, and to figure out how to make the mod on by default for both new users and existing users upon install.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Sun Mar 09, 2008 11:43 pm

Issue with flicker and the preview window getting caught under the mouse in IE 6 & 7 (and probably 5) may be related to making the text wrap in the preview box. If that is so I consider it an IE bug b/c it works flawlessly in Firefox. I've tried moving the preview div to after the topic list, using cancelBubble and moving the snapdiv function to after assigning the text to the div and making it visible. No help. I have been attempting to clean and tidy up the javascript code. It seems the original author had some checks and conditionals that did not need to be in there but maybe he knew something I don't. The modified code still works in FF and IE7. I have considered making the preview box showup and stay just under the topic link on IE browsers and move with the mouse in others.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Mon Mar 10, 2008 12:14 am

A big feature asked for was for topic preview to work in search result pages. This looks do-able. I just have to figure out how to make the first_post_ids[] array. The search results for topic searches is a nested array, $rowset[], where each row is an array with all the normal topic data plus a few forum data points. Luckily the query that grabs all this grabs all rows from the topics table. And I need to figure out where to do the query that pulls the first post text. And where to strip the bbcode & smilies. This situation makes a case for making that into a function. We'll see. There is a functions_topicpreview.php present in the current incarnation of the mod, that has a topicpreview class in it. But I've proven that it does nothing and is not needed. I don't want to do any unnecessary includes. The file was included in every page, not just viewforum.php. :roll:
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Tue Mar 11, 2008 10:40 am

Worked on making topic preview work in searches last night. I'm leaning towards making a series of functions or a class to use vs. pasting the same code in viewforum.php & search.php. But I'm not sure to use functions & an array for config vars or a class.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Sun Mar 23, 2008 1:37 pm

I have decided to go with the class instead of putting the code in both files (viewtopic.php & search.php). Before I upload the changes to this board to test it out I want to address another issue of parsing smilies. Some had asked for full bbcode parsing. But things like images & flash would either stretch the box or get cut off, but would certainly increase page load times. And there is no easy way to only parse text bbcodes like bold, italics, colors. So well just leave those out. At this point I am not sure if the mod leaves the smiliey code in place or strips it all together. So the next post in this thread will be a test for how all that stuff is stored. The other problem I have with parsing smilies is that it will interfere with the word count. But I figure most smiley codes aren't that long so if I can get them back to the original form, strip out the bbcode, then check for length, and then pass the text through the parser I'll be OK. We'll see.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

BBCode & Smiliy Test Post

Postby paul » Sun Mar 23, 2008 1:54 pm

Part of this sentence is bold.

Part of this sentence is italic.

Part of this sentence is colored text.

Here is an image:
Image

Here is a bbcode url.

A magic url:
http://www.amagicurl.com

Oh, and :lol: some :? smilies 8-)

A custom bbcode!

irene wrote:Quoting some text that someone else said.


Code: Select all
            $value = preg_replace('/\[.+:.+\]/iU', '', $value);
            $value = preg_replace('/<!-- s(.+?) -->.*?<!-- s\1 -->/i', '$1', $value);
            $value = preg_replace('/<!-- (.+?) -->.*?<!-- \1 -->/i', '', $value);
            $value = strip_tags($value);


And last, some youtube:
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Wed Apr 02, 2008 8:55 pm

Wow, that took a lot of development. But it's working. A large rewrite of the code. And I still have a few things left to test and write before I can call version 0.6.0 done. But the core is working.
Improvements:
  • The TopicPreview class was rewritten from scratch. The old one wasn't even used. Maybe the author planned on using it. The logic to figure out if topic preview is "on" is done when the class is instantiated. It also sets the other config vars as class properties.
  • The database query of post text is done in the object now as is the formatting of the text to strip out bbcodes & magic urls/emails/smilies.
  • Said formatting was re-written so that it leaves urls (except for bbcode urls which leaves whatever is in between the tags), image urls, email addresses, and the raw smilie codes.
  • There is now an option to preview the first -or- last post of a thread. :)
  • The ACP options were re-vamped. Gone are is the option to allow previews for bots (they aren't looking in the javascript embedded an anchor tag). Gone are the options to parse bbcodes, images & smilies. I wrestled with optionally parsing smilies but decided against it because there is no easy way to not count the smilie img tag in the character count. And I didn't want to create something complex that is going to further slow down the script.
  • Added to the ACP is an option for the guest or all users if not 'UCP enabled' to view the first or last post. I had to learn how to create custom 'module template vars' for that one.
  • I also hit up the UCP interface to make it so if Topic Preview is not enabled board wide, or is not enabled in the UCP the options do not show up. :)
  • And last but not least I wrote it up so topic previews can be shown in searches. I don't know if that one works or not yet b/c I forgot to create the code to place in the search_results.html template.

Besides coding the search results template I have to create the code for subsilver2 templates or I think I'm gonna get lynched.

A couple of php lessons learned from this exercise.
  1. You have to globalize any global vars you want to use in a function, even if they were globalized in the file bout outside the function.
  2. You can't globalize vars for a whole class. The only things that can go in a class are var definitions and functions. Globalized vars must be done in the functions themselves.
  3. When doing foreach loops on an array using the "as $value" syntax, whatever you do to value does not affect the original array value. $value is a local copy. Apparently in PHP5 you can pass by reference: "as &$value". But since I still have to account for PHP4 on this project I had to do
    Code: Select all
    foreach ($array as $key => $value) {
        // Do stuff to value
        $array[$key] = $value;
    }
  4. The ternary operator is ? : and not : ? . I made that mistake in a couple of places.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Fri Apr 18, 2008 6:23 pm

Version 0.6.1 was released with just a few changes necessary for phpBB version 3.0.1.
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby stauffie » Wed May 28, 2008 8:39 am

hi there paul i did installed your mod and get this error when i click on some links in my board


General Error
SQL ERROR [ mysql4 ]

[0]

SQL

No values specified for SQL IN comparison

BACKTRACE

FILE: includes/db/dbal.php
LINE: 385
CALL: dbal_mysql->sql_error()

FILE: includes/functions_topic_preview.php
LINE: 50
CALL: dbal_mysql->sql_in_set()

FILE: viewforum.php
LINE: 599
CALL: topicpreview->get_preview_text()



pleas cann you tell me where i did go wrong
regards stauffie
stauffie
 
Posts: 7
Joined: Wed May 28, 2008 8:35 am

Re: MOD: Topic Preview

Postby paul » Wed May 28, 2008 9:10 am

So I don't forget, this is the code Prototype uses to get mouse coords.
Code: Select all
    pointer: function(event) {
      return {
        x: event.pageX || (event.clientX +
          (document.documentElement.scrollLeft || document.body.scrollLeft)),
        y: event.pageY || (event.clientY +
          (document.documentElement.scrollTop || document.body.scrollTop))
      };


prototype-1.6.0.2.js line 3787
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby paul » Wed May 28, 2008 9:31 am

stauffie wrote:No values specified for SQL IN comparison

I have a feeling you may be clicking on forums that have no topics in them? Either that or the $preview_post_ids array is not being populated correctly. Double check your edits in viewforum.php. There is a section in that file that looks close to the actual spot where an edit should be made. Also what version of phpBB are you on? 3.0.0 or 3.0.1?
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Re: MOD: Topic Preview

Postby stauffie » Wed May 28, 2008 5:00 pm

hello paul i did check my lines in view forum and you are right one line is comming up twice
Code: Select all
$rowset[$row['topic_id']] = $row;

one time on line 476
and one time on line 372
now all is working fine
regards stauffie
stauffie
 
Posts: 7
Joined: Wed May 28, 2008 8:35 am

Re: MOD: Topic Preview

Postby paul » Thu May 29, 2008 3:51 pm

Code for viewforum.php

Before:
Code: Select all
unset($rowset[$topic_id]);


Add:
Code: Select all
$template->assign_block_vars('topicpreview', array(
    'TOPIC_ID' => $topic_id,
    'PREVIEW_TEXT' => ($topic_preview->enabled) ? $topic_preview_posts[$topic_id] : '',
    'ALT_TEXT' => $user->lang[$folder_alt])
    );
paul
Site Admin
Site Admin
 
Posts: 86
Joined: Wed Sep 12, 2007 9:31 pm
Location: Plymouth Meeting, PA

Next

Return to phpBB v3 Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron