vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   BB Code Functions (https://vborg.vbsupport.ru/showthread.php?t=63113)

Velocd 03-28-2004 10:00 PM

BB Code Functions
 
http://www.animesystem.com/temp/bbcf1.0.jpg


As requested by mudpyr8:
https://vborg.vbsupport.ru/showthread.php?t=62933


Features
  • Manage BB Code functions from your AdminCP. These can be internal PHP functions, or custom (derived from a specified PHP file).
  • Apply a BB Code function to a custom BB Code tag, and you can use it (when the correct arguments are provided) in posts, etc.
  • You may choose for a function to be static, or update everytime upon page refresh. If it's static, the first time a function is called the value returned will be replaced with the tag in the post (hard-coded).

Known bugs
  • One must have posted in the WYSIWYG editor in order for function tags that are unchecked for "update upon page refresh" to work correctly. This is an annoying bug I discovered an hour from releasing this hack, and it will prevent functions tags from being replaced with their return values (hard-coded) in the post. It's only significant if you are using a function that returns a random/dynamic value, and wish not for the value to be updated upon page refresh, but stay unique. I will be looking into a solution when I have the time.
  • Know of another? Please PM me of it, or post it in the thread.

Notes
  • This script can only be maliciously taken advantage of if you provide functions that access your server. For example, don't create a custom function that queries your database and returns something. A user could place 100 of these tags into a post, and it would make 100 queries. Even worse, if the "update upon refresh" is enabled, it'll call 100 queries for every view of the page. Especially don't create functions that manipulate data on your server or in your database!

    Everything is at your risk, but I implore you to stick with simple functions.
  • More important notes inside install.html.

Screenshots
See attachments.

Enjoy. Remember to click install if you do use this hack. ;)

Velocd 03-29-2004 04:35 AM

Have a custom function that is useful?

Just send me a link to a file with the function, or PM me the working code, and I'll display it in this post.


1. Evaluate mathematical expression
Here is a useful function that will take a mathematical expression and return the answer for it. Valid operators include plus + minus - multiply * divide / modulus % carrot/power ^ and parentheses ().

When used in BB Code, have one argument and it should function like so:

[math]5*6%3+((45/5)/4)[/math]

5*6%3 = 0
(45/5)/4 = 2.25
= 2.25

Here is the function:
PHP Code:

function arithmetic($expression)
{
    
$expression preg_replace('([^0-9\+\-*\/%\^\(\)])'''trim($expression));

    eval(
'$answer ='.$expression.';');
    
    return 
$answer;


Careful with parentheses. If you have (5/5)5 it will result in an error, and nothing will be returned.

Boofo 03-29-2004 05:27 AM

Sorry to sound so deft here, but what does this actually do and how would we use it?

Also, I have to know. How did you do that with that screenshot at the top of the post? That is wild. ;)

xware 03-29-2004 09:02 AM

Sorry to sound so deft here, but what does this actually do and how would we use it?

lasto 03-29-2004 09:15 AM

Quote:

Originally Posted by xware
Sorry to sound so deft here, but what does this actually do and how would we use it?


ditto LOL im confused as well

Boofo 03-29-2004 09:29 AM

Quote:

Originally Posted by xware
Sorry to sound so deft here, but what does this actually do and how would we use it?

Just curious here ... was there a reason you didn't quote the message instead of just repeating it? ;)

Charlie Argueta 03-29-2004 10:41 AM

This is amazing, but some of them are too hardcored, may be I will use some of them.

See Ya

Velocd 03-29-2004 02:48 PM

I thought the attached screenshots would be enough of an explanation.

This hack allows you to give bb code PHP functions (internal or custom).

For example, if I assigned the PHP function rand() to a tag called [rand], it would generate a random value.

[rand="0"]100[/rand]

Would generate a random value from 0 - 100.

Dean C 03-29-2004 03:13 PM

This looks great - could be used to resize an image right? And all sorts ....

Btw love that image at the top ;)

Bad Bunny 03-29-2004 04:00 PM

Quote:

Originally Posted by Velocd
I thought the attached screenshots would be enough of an explanation.

This hack allows you to give bb code PHP functions (internal or custom).

For example, if I assigned the PHP function rand() to a tag called [rand], it would generate a random value.

[rand="0"]100[/rand]

Would generate a random value from 0 - 100.

Wow. So it is possibly to simulate dice with this (amongst many other things)?! That's pretty hardcore!

Velocd 03-29-2004 08:21 PM

Quote:

Also, I have to know. How did you do that with that screenshot at the top of the post? That is wild.
Although it wouldn't be too hard to do in photoshop, it's made through a German site called LetterJames, which allows you to add your own captions to signs, etc.

Quote:

Wow. So it is possibly to simulate dice with this (amongst many other things)?! That's pretty hardcore!
Yes, but at the moment there is a bug requiring you to use the WYSIWYG editor when posting, if you want a random generated value by the function to be hard-coded into that post (replaced with its bbcode tag). Otherwise, you could keep refreshing the page and a new random value would show.

Quote:

could be used to resize an image right?
I imagine you could do something like that with this, by passing a image URL and using the GD2 library.

Velocd 03-29-2004 10:38 PM

So..

If anyone has this installed and working, could you let me know? It's a sort of long (although quick) hack to install, so I just want to confirm everything is in place. ;)

Link14716 03-29-2004 10:44 PM

Wow, kickass hack. I won't install it just yet (trying to find a good file comparison program for Linux to upgrade to vB3 Gold - and I'm not digging myself into a bigger hole before I upgrade (31 modified files is enough for RC3, thank you very much) ;) Well definately install it when I finally get vB3 Gold up and running. :)

[high]* Link14716 clicks install anyways. :)[/high]

Velocd 03-30-2004 12:01 AM

The following is a useful function I made that evaluates a mathematical expression.
https://vborg.vbsupport.ru/showpost....02&postcount=2

Boofo 03-30-2004 12:08 AM

Quote:

Originally Posted by Velocd
Although it wouldn't be too hard to do in photoshop, it's made through a German site called LetterJames, which allows you to add your own captions to signs, etc.

Thank you, sir. Although I can't read ANY German, once you figure things out at that site, It's pretty impressive. ;)

AlexanderT 03-30-2004 10:26 AM

Quote:

Originally Posted by Dean C
Btw love that image at the top ;)

It's from Frankfurt Airport/Germany - I knew I've seen that sign before :)

mudpyr8 03-31-2004 01:05 AM

Big kudos to VeloCD for doing this hack. He was willing to write the code after an initial request I made for my dice roller. I like to have the ability for members to roll dice in my forums, but I didn't want to have to hack up the bbcode parser to do it. I thought it would be great to have an adminCP that would allow for php functions to be called by bbcodes, but had NO idea how to do it.

Luckily VeloCD saw my post and said he knew how to do it and here it is.

BIG BIG THANKS.

I will be posting my dice roller soon. If you'd like to see it in action, here you go:
http://www.tekhed.com/dice/

Feel free to email me with game system support requests.

wcbryant 03-31-2004 09:39 AM

I'm going to have to add a line of credit to my site just to cover you Velocd. I don't go looking for your hacks specifically, but it seems you're often behind the ones I end up on when I have a focused need. Great work, again.

Now that I've blown a little sunshine, I have a "clueless" question to ask. I need to figure out some method of allowing users to make text in their post 'secure'. 'Secure' in the sense that other users can't just highlight, right click, copy, and then paste elsewhere. I know nothing is entirely safe (they could simply just View Source), but the primary goal is to prevent someone from absentmindedly cutting and pasting something sensitive into an email to someone else. I could just do it for all my pages, but in many cases the content my site covers needs to be able to be copied and pasted into other posts, so that's no good. Needs to be only there when people want it so.

I've found JavaScript that can accomplish this (I'll quote below in case this is a bad way to do it (it did come from someone named Bart with an AOL account after all), and someone can recommend better -- or in case I haven't expressed my desire well enough), but no PHP. PHP *seems* to be what your hack speaks to though. So my question, and it's coming from a layman to be sure, is can I accomplish what I want with your hack?

HTML Code:

<SCRIPT language=JavaScript>
<!--
/*
No rightclick script v.2.5
(c) 1998 barts1000
[email]barts1000@aol.com[/email]
Don't delete this header!
*/

var message="Oops, that function is disabled.";

// Don't edit below!

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->


</SCRIPT>


mudpyr8 03-31-2004 11:41 AM

One control that might be necessary is the ability to prohibit the use of a particular code in a signature. BBCodes are normally allowed in signatures, but someone who puts [power] into their sig, or [roll]50d1000[/roll] could generate a lot of server activity. If this isn't possible, the admin will just have to watch for such sigs, but it is important to note that. 100 people with factorials in their sigs is gonna be bad.

mudpyr8 03-31-2004 11:44 AM

wcbryant: I think you can. You would just have to write a php function that wraps the bbcode param in the javascript:

[secure]insert message here[/secure] would then wrap "insert message here" in the javascript.

Velocd 04-01-2004 04:35 AM

wcbryant, I understand what you're trying to do, but I don't think this hack serves the purpose. (unless my interpretation is wrong, and mudpyr8 is closer to your question)

Quote:

One control that might be necessary is the ability to prohibit the use of a particular code in a signature. BBCodes are normally allowed in signatures, but someone who puts [power] into their sig, or [roll]50d1000[/roll] could generate a lot of server activity. If this isn't possible, the admin will just have to watch for such sigs, but it is important to note that. 100 people with factorials in their sigs is gonna be bad.
In the case you have a server-extensive function, it would. If you have the feature for not calling a function every time upon page refresh (although there is a bug right now where you must post in the WYSIWYG editor for this to apply) then it wouldn't be that big of a deal.

I will look into disabling it for signatures, as well fixing that bug, over the weekend. ;)

wcbryant 04-01-2004 09:18 AM

Quote:

Originally Posted by Velocd
wcbryant, I understand what you're trying to do, but I don't think this hack serves the purpose. (unless my interpretation is wrong, and mudpyr8 is closer to your question)

My explanation was convoluted at best, but despite that I think you both understood. I've looked at the hack some more, and while I think it walks a line very near to what I want to do -- may even be able to function loosely in that capacity in the manner mudpyr8 suggested -- it's probably not the 'right' approach. Which might be somehow just adding a 'no text copy' flag to the Additional Options field when posting.

You can turn off 'email to a friend' or 'printer friendly format' in threads, all I want to be able to do is turn off user's ability to copy and paste. Disable text highlighting (not that I think the JS I found does that), and disable right clicking. Again, I understand people can always just view source, but my goal is the prevention of accidental leaks, rather than intentional/malicious ones.

Anyway, thanks to you both for the responses.

mudpyr8 04-13-2004 03:08 PM

VeloCD, thanks. I got it working and it is superb. A couple of things:

1. In your install notes, steps 49 & 50 refer to 'allowsmilie". It should be 'allowsmilies'.

2. It reevaluates on edit of the message. It would be nice if this could be disabled. For my dice roller, I only want it to roll once. Not a big deal since when rolling dice it is a faux pas to edit your post anyway.

3. It only accepts one instance of the code (the last one). If I put two [roll] tags in one message, it only evaluates the last one.

Again, thanks a lot. This rocks.

Velocd 04-13-2004 04:15 PM

1. Thanks, will correct. ;)

2. If you are using the WYSIWYG editor and have the update option disabled, it shouldn't do so, since the return value of the function is hard-coded into the post. But, I haven't had time to look into making the update work for non-WYSIWYG.

3. That's odd. I'll check this out, although it should evaluate all tags. If you place two custom BB Code function tags that aren't your roll function, say maybe [random], does this generate two random values?

Sven 06-21-2004 12:38 PM

I have installed this hack so far since I was looking for something that enables me to use php functions in bbcodes...
But I'm fiddling around and it's not working....
Here's the function to include:
PHP Code:

<?php
// ###################### Start fetch_countdown_timer ###################### 
// returns the time left untill $dateline 
function fetch_countdown_timer($dateline) { 

    global 
$vboptions

    
$diff $dateline - (time() - $vboptions['hourdiff']); 

    
$days = ($diff - ($diff 86400)) / 86400
    
$diff $diff - ($days 86400); 
    
$hours = ($diff - ($diff 3600)) / 3600
    
$diff $diff - ($hours 3600); 
    
$minutes = ($diff - ($diff 60)) / 60
    
$diff $diff - ($minutes 60); 
    
$seconds = ($diff - ($diff 1)) / 1

    return 
iif($days 0$days.'d ''').iif("$hours > 0 && $days != 0"$hours.'h ''').$minutes.'m'


?>

Now I added a function like this:
Title: countdown
Handle: fetch_countdown_timer
Include File: countdown.php (containing above code)

Also I added a bbcode 'countdown' and have choosen the function in there....
It's just not working, what am I doing wrong?
As an example I used
[countdown]03, July 2004[/countdown] and the function returns something like -13h -40m instead of 11d and something....

How do I pass the date of interest to the function?

Sven 06-22-2004 08:40 AM

sorry for double posting but I didn't want to edit in case someone read my previous posting and wouldn't recognize this posting then.

I think I found out what's going wrong, it's because If I'm trying to pass a date it will be passed as Unix Timestamp.

Is there any way to pass the variable to the function as formatted date?

Sven 06-25-2004 08:24 AM

^bump^

Wasser 07-15-2004 03:36 AM

it would be perfect to have a countdown timer intergrated with the calendar. =)

KW802 08-03-2004 08:29 PM

OK, I'm those of those guys that hated math classes in school.... besides the mathematical functions, what are some other uses that you guys have come up with?

Borisch 09-12-2004 07:40 PM

From the description...this hack is the King!
Installing and testing tomorrow.

Sven 09-30-2004 10:09 AM

After the upgrade to 3.03 I had to re-install this hack and, as an outcome, here are the instructions for the countdown:

Install the hack
Add the following code to includes/functions.php:
Code:

// ###################### Start fetch_countdown_timer ######################
// returns the time left untill $dateline
function fetch_countdown_timer($dateline) {

    global $vboptions;

    $diff = $dateline - (time() - $vboptions['hourdiff']);

    $days = ($diff - ($diff % 86400)) / 86400;
    $diff = $diff - ($days * 86400);
    $hours = ($diff - ($diff % 3600)) / 3600;
    $diff = $diff - ($hours * 3600);
    $minutes = ($diff - ($diff % 60)) / 60;
    $diff = $diff - ($minutes * 60);
    $seconds = ($diff - ($diff % 1)) / 1;

    return iif($days > 0, $days.'d ', '').iif("$hours > 0 && $days != 0", $hours.'h ', '').$minutes.'m';

}

Create a custom bb code function like this:
title: countdown
handle: fetch_countdown_timer
description: whatever you want
include file: [leave blank]
Update upon page refresh?: yes

Then create a custom bb code:
title: countdown
tag: countdown
function: countdown
replacement: [leave blank]
example: [countdown]1088859600[/countdown] (choose any unix timestamp here)
description: [whatever you want]
use parameter: no
button image: [any image you want]

Now, to make this usable to your users:
Add a link to a calculation script like this one (I did this on the editor toolbars):
http://www.php4scripte.de/umrechner/
it converts a real time into a unix timestamp which can then be used within the BB Code.

I'd really appreciate if one could help me to avoid the conversion between realtime and unix timestamp... so the function can work with realtime formats

Sven 11-18-2004 08:08 AM

I just tried to add a new cutom bbcode to our forums - well, that worked - but the new created code won't show up in the bbcode manager.

I edited all the files, according to the install.html, once again - with no effect at all.

Any help on what's wrong here?
Can anyone, who has this hack properly installed, send me this three files:
bbcode.php
adminfunctions.php
functions_bbcodeparse.php
??

Send them to sven@cncforen.de

TCM 01-16-2005 09:26 PM

Does anyone yet know if this hack is compatiable with .5? It looks like a great hack, but I don't want to install it if it won't work yet, or will cause errors.

thamyeuvn 02-09-2005 04:24 PM

I need Flash BB code, can anyone here help me?
I need to import flash in to my forum but I dont know how to do that.
Thanks.

TCM 02-12-2005 04:48 PM

Hey. I'm trying to get this hack installed, but I don't understand how to run the queries from PHPMyAdmin. I go to my database, select Querey, but I don't know where to enter it. Entering it in the box labeled "SQL-query on database tcmutt_Source" just gives me the error "You have to choose at least one Column to display". =/ Can anyone tell me what I'm doing wrong?

EDIT: Whoops. My mistake. I think I found out where to do it.

EDIT2: Alright, it's installed correctly now. Thanks for making this, it should prove very useful. :D

smju 04-01-2005 12:48 PM

Are the instructions for installation still valid with 3.0.7?

TCM 04-01-2005 07:46 PM

Quote:

Originally Posted by smju
Are the instructions for installation still valid with 3.0.7?

Yup. I've got vB 3.0.7 and this works great on mine. :)

smju 04-12-2005 02:32 PM

Well, I did everything the instructions said and I got an error, so backed it all out.

The error was in the functions_bbcodeparse file. The error message was "unexpected $ at line 1767" (which is the line with the ?>).

I have checked all the hacks and they seem correct.

Here is the final code you can find all the changes and the step numbers by finding "SMJU001"

I tried pasting the code in here BUT it made the message too big. Thus you can find it [Removed by moderator]** Here **

Marco van Herwaarden 04-12-2005 06:24 PM

Quote:

Originally Posted by smju
Well, I did everything the instructions said and I got an error, so backed it all out.

The error was in the functions_bbcodeparse file. The error message was "unexpected $ at line 1767" (which is the line with the ?>).

I have checked all the hacks and they seem correct.

Here is the final code you can find all the changes and the step numbers by finding "SMJU001"

I tried pasting the code in here BUT it made the message too big. Thus you can find it ** Here **

You should immediate remove that file. It is against your license agreement and our Forum Rules to paste significant parts of vB files, or vB files in whole.

smju 04-12-2005 08:51 PM

Whoops.

Consider it removed.

How then do I get help, because I am convinced that I made the hack changes correctly.


All times are GMT. The time now is 05:17 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.01413 seconds
  • Memory Usage 1,868KB
  • 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
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete