vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.8 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=235)
-   -   BB Code Enhancements - Cel PHP in Custom BBCode (https://vborg.vbsupport.ru/showthread.php?t=264898)

cellarius 06-07-2011 10:00 PM

Cel PHP in Custom BBCode
 
1 Attachment(s)
This addon allows for PHP-Code to be used in Custom BBCodes

It offers a framework for the easy integration and sharing of custom BBCodes that are based on PHP processing of the data entered by the user. It could, for example, be used to develop BBCodes that work with multiple options or to poll database information. It does allow for the Admin to use PHP in the Backend - it does, of course, not allow this to forum visitors.

You need to know PHP to use this Addon to develop your own PHP based bbcodes, however it would be possible to share them as an extension to this addon.


Installation:
- install the product file - done.


Using PHP in Custom BBCodes:
Create your Custom BBCode as always, and just put your PHP into the Replacement box (where the HTML used to go).
Just remember two things:
  • Your code needs to start with <?php
  • You need to return the result of your code.
If you're unsure what that means, read the php manual on eval() and look at the evaltest example in the second post.


For coders: include instead of eval
If you'd rather store the PHP for your new BBCodes in the file system for ease of development, that's possible, too:
  • create a folder called "custombbcodes" in your forum root
  • in that folder, create a php file that copies your BBCode Tag Name (ie. if your tag name is "includetest", the file needs to be called "includetest.php"). That's where your PHP goes.
  • in the Replacement box in the Custom BBCode Dialog, just put the word "include", nothing else
  • Since there's no eval() here, no need to return the result. Instead, it needs to go into $parsed.There's also an includetest example in the second post.
No Support for your PHP-Code!

### See the example BBCodes in the second post (Click)! ###


### Don't forget to click install! ###
(No support if you don't)

cellarius 06-08-2011 02:06 PM

PHP BBCode Examples:

To test them, go to AdminCP->Custom BB Codes->Add new BB Code and fill in the form:

--------------------------------------------------------------------
  • Title: evaltest
  • BBCode Tag Name: evaltest
  • Replacement:
PHP Code:

<?php
/* 
Please note: 
  
- available variables: 
    param => $value, option => $option
    remember: [bbcode=option]param[/bbcode] 

- pass your result via return (as needed for PHP eval)
    so end your code with return $my_result */

$my_result "Test per eval (here no option was used):  "
$my_result .= "Parameter: <strong>" $value "</strong>";

return 
$my_result?>

  • Example: [evaltest]Hello World![/evaltest]
  • Use {option}: No
--------------------------------------------------------------------
  • Title: includetest
  • BBCode Tag Name: includetest
  • Replacement:
[code]include[code]
  • Example: [includetest="World!"]Hello![/includetest]
  • Use {option}: Yes
Additionally, you need to create a directory called custombbcodes, and in it create a file called includetest.php with the following code:
PHP Code:

<?php
    
/* 
Please note:
   
- available variables: 
    param => $value, option => $option
    remember: [bbcode=option]param[/bbcode] 
- all output needs to go to $parsed
    no return statement needed (different from direct eval method)
    so don't use echo "Hello World", but $parsed = "Hello World"
*/

$parsed "Test per include (here option was used): ";
$parsed .= "Parameter = <strong>" $value "</strong>, ";
$parsed .= "Option = <strong>" $option "</strong>";

--------------------------------------------------------------------

troyuncucom 06-09-2011 11:37 AM

i want to include, xx.txt.

Code:

    <?php include("{param}.txt"); ?>
it's not work. How can i do that?

cellarius 06-09-2011 11:55 AM

Please have a look at the examples in the second post, and mark the mod as installed.

What's {param} supposed to be? You want to use $value for what I think you meant to achieve:
PHP Code:

<?php include($value ".txt"); ?>

As explained in the examples: The variables {option} maps to $option, {param} maps to $value.

cellarius 06-09-2011 12:52 PM

Been in further contact with troyuncucom. If you want to use include in your PHP code, make sure there is PHP Code in the file you include. Because of how vB works it is not possible to just throw text in there and have it printed to the screen. This will cause a cookie error/header already sent.

You need to make sure that you don't print to the screen directly; all output needs to go to a variable and needs to be correctly returned/passed. Please look at the examples in second post!

troyuncucom 06-09-2011 01:07 PM

I did it all, firstly thanks very much.

But 2 errors for this plugin.

1) if i use bbcode, sending the message twice.

2) if i modify my txt file. the message does not change

cellarius 06-09-2011 01:14 PM

Those are not errors caused by this plugin, but by the code you're trying to run. What you can do and can't do is subject to the same limits as general vB plugin coding, since you're acting within the same framework.
Your first point I don't understand, and regarding your second point: Edit and save the message once again. Post output is cached.

MoMan 06-09-2011 05:44 PM

Isn't parsed BBcode in posts cached if you enable the vb post cache? If so, that would mean that writing custom code to hide things from guests wouldn't be of much help, right?

cellarius 06-09-2011 06:48 PM

Not bbcodes are cached, but the entire post (as I wrote in the post above). Hiding things would have to be done at runtime, like the existing hide hacks do. This is not something this framework provides, you would have to do that yourself.

Edit: Thinking about it - you could clear the post from postcache at runtime using something like this:
PHP Code:

delete from postparsed where postid=

One would have to test if this could be of use in the environment my addon creates, or whether a seperate plugin could be created that deletes a post from postcache when a certain custom bbcode is present, or a plugin that keeps a post from being entered into postcache in the firstplace if a certain custom bbcode is present.

kpmedia 01-28-2013 05:41 AM

This just does not work. It loads once, then disappears.
I've tried to alter it, my code, etc ...

..


All times are GMT. The time now is 07:06 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01839 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete