Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2009, 02:47 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How do you script BB Code?

Okay... lets say I want to make a bbcode... [VIDEO]536[/VIDEO]

I want to parse some PHP code on this code. How would I handle this?

PHP Code:
function fetch_bbcode_video($videoid)
{
 require_once(
DIR '/includes/class_videosharingservice.php');
 global 
$vbphrase$vbulletin$show$stylevar;
 if (!
$videoinfo $vbulletin->db->query_first("
  SELECT video.* 
  FROM " 
TABLE_PREFIX "video AS video 
  WHERE video.videoid = '" 
$videoid "'")
 )
 {
  return 
false;
 }
 
$classname "vB_VideoSharingService_$video[videoservice]";
 
$obj = new $classname($vbulletin);
 
$embedcode $obj->fetch_embedcode($videoinfo['videoidservice']);
 
$video['cattitle'] =& $vbulletin->videocats["$video[videocategoryid]"]['title'];
 
$video['caturl'] = construct_category_url($vbulletin->videocats["$video[videocategoryid]"]);
 
$video['url'] = construct_video_url($video);
 
$video['userurl'] = construct_user_url($video);
 if (
$video['timelength'] == 0)
 {
  
$video['timelength'] = "???";
 }
 else
 {
  
$duration $video['timelength'];
  
$minutes floor($duration 60);
  
$seconds $duration 60;
  
$seconds str_pad($seconds2"0"STR_PAD_LEFT); 
  
$video['timelength'] = "$minutes:$seconds";
 }
 eval(
'$html = "' fetch_template('bbcode_video') . '";');
 return 
$html;

Reply With Quote
  #2  
Old 01-07-2009, 10:04 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay... since no one knows how to script BB code... how about something different...

How would I make a script that examines a new post and preg_matches a thread and replaces it with content? So if someone made a post and it had:
[VIDEO]536[/VIDEO]
I would want it to preg_match it with:
\[(VIDEO|video)](\d*)\[/(VIDEO|video)]
Then of course, I would run some PHP code on the preg_match[2] returned as 536.

Would this be possible?
Reply With Quote
  #3  
Old 01-07-2009, 10:14 PM
Bellardia Bellardia is offline
 
Join Date: Jul 2007
Location: Hamilton, Ontario
Posts: 378
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaxel View Post
Okay... since no one knows how to script BB code... how about something different...

How would I make a script that examines a new post and preg_matches a thread and replaces it with content? So if someone made a post and it had:
[VIDEO]536[/VIDEO]
I would want it to preg_match it with:
\[(VIDEO|video)]([\d]*)\[/(VIDEO|video)]
Then of course, I would run some PHP code on the preg_match[2] returned as 536.

Would this be possible?
I posted this in another thread a bit earlier, it should help you out

You'll require two plugins for this. I posted their source as xml just because it included everything. Just pay particular attention to the hook location and the basic functions I included.

This one will take the text to be posted, and submit it to a function so can it can be run through a preg_replace or similar function.
Code:
<plugin active="1" executionorder="5">

			<title>Title Of Mod</title>

			<hookname>postbit_display_complete</hookname>

			<phpcode><![CDATA[global $vbulletin;

			$this->post['message'] = Function_Name($this->post['message']);

			]]></phpcode>

</plugin>
Another code in the global_start hook can be used to hold the source of the link replacement, modify the post and return it however you want.
Code:
<title>Plugin Title</title>
<hookname>global_start</hookname>
<phpcode><![CDATA[
            function Function_Name($post) {
				global $vbulletin;
                //Preg_replace + other Functions
                return $post;
             }
]]></phpcode>
Reply With Quote
  #4  
Old 01-08-2009, 02:12 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That is not adding another BB code. You can add a proper BB code (using PHP processing) by adding your tag to the processing array and setting the callback as the external callback function. Look at the bottom of class_bbcode.php.
Reply With Quote
  #5  
Old 01-10-2009, 12:36 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Huh? I'm confused... is there a guide somewhere?

All I want to do is have a BB Code, with a PHP function run on it.
Reply With Quote
  #6  
Old 01-11-2009, 04:15 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dismounted View Post
That is not adding another BB code. You can add a proper BB code (using PHP processing) by adding your tag to the processing array and setting the callback as the external callback function. Look at the bottom of class_bbcode.php.
All the information you need is in that post.
Reply With Quote
  #7  
Old 01-12-2009, 05:09 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there any way of doing this WITHOUT editing VB files? And I dont know what I am supposed to be looking at in class_bbcode.php.
Reply With Quote
  #8  
Old 01-13-2009, 04:41 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaxel View Post
Is there any way of doing this WITHOUT editing VB files?
Yes, and that is what I'm telling you.
Quote:
Originally Posted by Jaxel View Post
And I dont know what I am supposed to be looking at in class_bbcode.php.
You will see how tags are defined. Define your own tag and callback.
Reply With Quote
  #9  
Old 01-14-2009, 04:35 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you mind actually explaining what needs to be done? Because I still dont see what I'm supposed to be looking at.

*EDIT* ah... I think I get it now, you wanted me to see: ($hook = vBulletinHook::fetch_hook('bbcode_fetch_tags')) ? eval($hook) : false;

I tried doing this...

Code:
// [VIDEO]
require_once(DIR . '/includes/functions_videodirectory.php');

$tag_list['no_option']['video'] = array(
	'callback' => 'handle_external',
	'external_callback' => 'handle_bbcode_video',
	'strip_empty' => true
);
But I get an error:
Fatal error: Call to undefined method vB_BbCodeParser::handle_bbcode_video() in /home/eightway/public_html/includes/class_bbcode.php on line 1143

How do I get it to call handle_bbcode_video in functions_videodirectory.php?

--------------- Added [DATE]1231967882[/DATE] at [TIME]1231967882[/TIME] ---------------

Well I figured to just use the function in the plugin itself, instead of calling a file... But I'm having trouble passing the parameter data...

Code:
// [VIDEO]
$tag_list['no_option']['video'] = array(
	'callback' => 'handle_external',
	'external_callback' => 'handle_bbcode_video',
	'strip_empty' => true
);

function handle_bbcode_video($videoid)
{
	global $vbulletin;

	if (!$videoinfo = $vbulletin->db->query_first("
		SELECT video.*
		FROM " . TABLE_PREFIX . "video AS video
		WHERE video.videoid = '" . $videoid . "'")
	)
	{
		return 'This video does not exist';
	}

	require_once(DIR . '/includes/class_videosharingservice.php');
	require_once(DIR . '/includes/videoserviceapi/class_' . strtolower($videoinfo['videoservice']) . '.php');

	$classname = 'vB_VideoSharingService_' . $videoinfo['videoservice'];
	$obj = new $classname($vbulletin);

	$embedhtml = $obj->fetch_embedcode($videoinfo['videoidservice']);

	return $embedhtml;
}
For some reason, $videoid is always empty. Why is this? It ALWAYS returns 'This video does not exist'.

--------------- Added [DATE]1231974120[/DATE] at [TIME]1231974120[/TIME] ---------------

Is there a guide or something that explains what all the array options in $tag_list do?
Reply With Quote
  #10  
Old 01-15-2009, 04:23 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jaxel View Post
Do you mind actually explaining what needs to be done?
You've done a lot of work - and it shows, because you're nearly there. I'm going to give you the rest of it, because unlike a lot of people, you've actually tried doing it yourself.

Hook: bbcode_fetch_tags
PHP Code:
// [VIDEO]
$tag_list['no_option']['video'] = array(
    
'callback' => 'handle_external',
    
'external_callback' => 'handle_bbcode_video',
    
'strip_empty' => true
); 
Hook: bbcode_create
PHP Code:
// include our custom functions
require_once(DIR '/includes/functions_videodirectory.php');
require_once(
DIR '/includes/class_videosharingservice.php'); 
Function: handle_bbcode_video (/includes/functions_videodirectory.php)
PHP Code:
function handle_bbcode_video(&$parser$value$option)
{
        global 
$vbulletin;

        
// clean video id
        
$videoid intval($value);

        
// fetch video information -- this is costly, it is run every time the bb code tag is used
        
$videoinfo $vbulletin->db->query_first("
                SELECT *
                FROM " 
TABLE_PREFIX "video
                WHERE video.videoid = " 
$videoid "
                LIMIT 1
        "
);

        
// check video exists
        
if (empty($videoinfo))
        {
                
// this will show up on posts -- make sure this is what you want
                
return 'This video does not exist.';
        }

        
// instantiate our video class
        
require_once(DIR '/includes/videoserviceapi/class_' strtolower($videoinfo['videoservice']) . '.php');
        
$classname 'vB_VideoSharingService_' $videoinfo['videoservice'];
        
$obj = new $classname($vbulletin);

        
// return embed code
        
return $obj->fetch_embedcode($videoinfo['videoidservice']);

I've cleaned up and commented the function for you - you should read some of the comments.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04448 seconds
  • Memory Usage 2,302KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (4)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete