Back to vBulletin 4.x Add-ons

[previewbreak] for blog posts
Mod Version: 1.00, by xorlof

vB Version: 4.2.2 Rating: (0 vote - 0 average) Installs: 5
Released: 04 Feb 2015 Last Update: Never Downloads: 0
Not Supported Code Changes Re-usable Code  

This is my first attempt at making something for VB4, so be kind. Tips/tricks on how I could have done this better are most welcome...

The CMS has the code [prbreak] which allows you to specify exactly where you want the shortened version of an article to stop, after which you can hit the "read more" link to see the rest. The blog system doesn't have this functionality, so I hacked it in. There are two steps needed to make this work:

STEP ONE: CREATE A [PREVIEWBREAK] BB CODE
a) Goto Admin CP -> Custom BB Code -> BB Code Manager -> Add New BB Code
b) Fill out the form as follows:
Title: Preview Break (blog only)
Tag name: previewbreak
Replacement: <!-- preview break -->
Example: [previewbreak][/previewbreak]
Description: Include an empty [previewbreak] tag ( [previewbreak][/previewbreak] ) to force a blog preview to end at that point instead of after a certain number of characters (the default behavior).
STEP TWO: EDIT THE BLOG BBCODE PARSER
Sorry--I couldn't figure out a way to do this without editing source code. Anyway, we have to edit class_bbcode_blog.php (from the vBulletin "includes" directory) in three places:

Edit #1: Find:
PHP Code:
                if ($this->parse_userinfo['permissions']['vbblog_entry_permissions'] & $this->registry->bf_ugp_vbblog_entry_permissions['blog_allowhtml'])
                {
                        
$input_text strip_tags($input_text'<br>');
                } 
and on new lines after the closing curly brace add this:
PHP Code:
                // NON-STANDARD CODE - If present, we will break at [previewbreak] instead of after a certain number of characters
                
if (stripos($input_text''))
                {
                        
$this->snippet_length strlen($input_text);
                }
                
// END OF NON-STANDARD CODE 
Edit #2: Repeat edit #1 in the other spot the find text occurs in the same file.

Edit #3: Find:
PHP Code:
                                if ($token['type'] == 'tag')
                                { 
and on new lines after that opening curly brace add this:
PHP Code:
                                        // NON-STANDARD CODE - If we have a prbreak we are done.
                                        
if (($token['name'] == 'previewbreak') AND isset($tokens[intval($tokenid) + 1])
                                                AND (
$tokens[intval($tokenid) + 1]['name'] == 'previewbreak')
                                                AND (
$tokens[intval($tokenid) + 1]['closing']))
                                        {
                                                
$over_threshold == true;
                                                break;
                                        }
                                        
// END OF NON-STANDARD CODE 
That's it! Now you can insert [previewbreak][/previewbreak] anywhere within your blog post to force the break at that spot. It even works if the forced spot occurs after the regular (non-forced) break would occur (i.e., you can lengthen a preview using this code).

And with a little bit of reworking, it would be pretty straightforward to allow you to put text between the opening and closing previewbreak tags that is only shown on the preview page (e.g., "[previewbreak]Read on to find out why [subject of blog post] is so great.[/previewbreak]"). Since I doubt this will be a popular mod (I'll consider 2 installs, including me to be a huge success), and I have no use for that, I'll leave that to someone else.

Download

No files for download.

Similar Mods

Add-On Releases dmActivityStream - Blog Posts and Blog Comments vBulletin 4.x Add-ons

vblts.ru supports vBulletin®, 2022-2024