View Full Version : Messing with $post[message] in functions_newpost.php-The quest continues! Form vars?
MTGDarkness
02-27-2009, 08:48 AM
I want to add a snippet of code to each $post[message]. It's for a modification I'm working on. How can I add, say, a conditional clause to it? I tried editing the postbit template and it didn't work...
Dismounted
02-27-2009, 08:58 AM
As you mentioned, editing the postbit(_legacy) template should be sufficient. What exactly did you do?
MTGDarkness
02-27-2009, 08:58 AM
What I'm trying to do is, again, set up this automatic BBCode thing that I've been looking for.
I tried setting it up like this:
<if condition="$post[field11] AND $post[field12]">$post[field11]</if>
$post[message]
<if condition="$post[field11] AND $post[field12]">$post[field12]</if>
Where field 11 and 12 are single line text fields asking for BBCode beginning and end tags, respectively, but this basically just adds the content to the beginning and end of each post, and if it's BBCode (which it's supposed to be), it doesn't parse. I also have the feeling that this is a security risk.
Dismounted
02-27-2009, 09:01 AM
You need to convert the BB Code into HTML (called "parsing"). This needs to be done inside a plugin. (There are articles describing how to parse BB code.)
MTGDarkness
02-27-2009, 09:09 AM
https://vborg.vbsupport.ru/showthread.php?t=82693&highlight=bbcode
I'm not quite sure what I'm doing here. I started out on this code:
<if condition="$post[field11] AND $post[field12]">
$text = $post[field11] $post[field12]
$do_html = false
$do_smilies = true
$do_bbcode = true
$do_imgcode = true
$do_nl2br = true
$cachable = false
</if>
$parsed_text
$post[message]
<if condition="$post[field11] AND $post[field12]">$post[field12]</if>
It's not finished yet, because I realized that I'm going to have a hell of a time trying to get the parser to parse half of the bbcode, then the other half. And I'm not sure how to make it parse both.
--------------- Added 1235735146 at 1235735146 ---------------
Is there any way to just modify what goes in to $post[message]?
Lynne
02-27-2009, 03:03 PM
You cannot do php in a template. You will have to write a plugin to do that.
MTGDarkness
02-27-2009, 03:23 PM
Can't I just fiddle with the $post[message] instead? Wouldn't that be simpler?
Lynne
02-27-2009, 03:39 PM
If you are going to 'fiddle' with $post[message] before it is spit out in the template, you must do so using a plugin.
MTGDarkness
02-27-2009, 03:44 PM
Oooh... I see. And which plugin hook? I'm guessing Postdata_Start, but I really don't know where all these hooks go to.
Lynne
02-27-2009, 05:37 PM
If you are in debug mode, there is a list of all the plugins called for the page on the bottom. I think I usually use postbit_display_start when I want to change something that is going into the postbit. But, you can certainly try different locations.
MTGDarkness
02-28-2009, 07:43 AM
When I try to put something into postbit_display_start, like, say
echo "this is a test statement";
What happens is, it gets put at the top of the page before the doctype declaration. I'm kind of stumbling around in the dark here.
--------------- Added 1235820573 at 1235820573 ---------------
Okay...
I wrote this plugin:
Postdata_start
if ($post[field11] && $post[field12])
{
require_once(DIR . '/includes/class_bbcode.php');
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$parsed_text = $parser->do_parse($text, $do_html, $do_smilies, $do_bbcode, $do_imgcode, $do_nl2br, $cachable);
$text = $post[field11].$message.$post[field12];
}
And this in postbit_legacy: <if condition="$post[field11] AND $post[field12]">$parsed_text
<else /> $post[message]</if>
(replaces $post[message])
But when I tried it out, no HTML was outputted. And this is probably a serious security risk, seeing as people can type in PHP code for the fields and have it execute. How can I change that?
BigJohnny
02-28-2009, 11:07 AM
one way to find out where to execute your code is to look in tje php files themselves. for instance, showthread.php for stuff dealing with posts.
If you look through the code you will see the hook locations. Basically you can find out what hook is being called where. Once you know where it is being called in the code, you can go back to your plugin manager and write your code for the hook that will execute where you want it to.
for instance, on line 1078 of showthread.php i see
[code]
($hook = vBulletinHook::fetch_hook('showthread_postbit_crea te')) ? eval($hook) : false;
[/hide]
so if i were to make a plugin inside that hook it know it will be executed when that hook is called in the php file.
I dont really know if its the best way to find out which hook is t he right one for your needs, but it works for me quite often :D
MTGDarkness
02-28-2009, 09:59 PM
Come on... Can't anyone help me out here? :(
MTGDarkness
03-02-2009, 04:49 PM
Which file processes the form from replies? Which actual PHP file in vBulletin?
Lynne
03-02-2009, 04:58 PM
Go to the page and look in the page source. You will find some line like this (this is from somewhere else, it's not it):
<form action="newthread.php?do=postthread&f=11" method="post" name="vbform" onsubmit="return vB_Editor['vB_Editor_001'].prepare_submit(this.subject.value, 5)">
That tells you the form and do value that will be submitted.
MTGDarkness
03-03-2009, 06:16 PM
One final question, and then I think I'll FINALLY have this stupid issue! (Breakthrough was reached by just scanning all the files that seemed relevant for a comment telling me about "this is where we process posts).
What I did was this:
In file: functions_newpost.php
Find:
$post['emailupdate'] = intval($post['emailupdate']);
$post['rating'] = intval($post['rating']);
$post['podcastsize'] = intval($post['podcastsize']);
Add under:
$post['message'] = "<stuff>" .$post['message']. "<stuff>";
And if you put bbcode in there... it will parse! Hallelujah!
As to my questions...
1. Will a variable that works well in the template (in this case, the aforementioned field variables) work as they are there in the files? Like say I put this string in functions_newpost.php (where I put the last string I mentioned):
$post['message'] = $post['field11'].$post['message'].$post['field12'];
How can I make that work in the file itself?
MTGDarkness
03-05-2009, 03:41 AM
Bump?
Dismounted
03-05-2009, 04:51 AM
If you are talking about the build_new_post() function, no, it will not work.
User info is not available there.
If it did exist, when the user changes the field, it will not be reflected in their posts.
MTGDarkness
03-05-2009, 10:47 AM
GAAAAAAAAAAAAAAAH
So it's also impossible to get the info to there? How about setting a plugin that way? The guys over at MTGSalvation and MTGNews figured it out somehow!
Sorry if I sound a little hysterical; I am.
Dismounted
03-05-2009, 11:19 AM
postbit_display_complete ;)
MTGDarkness
03-05-2009, 05:31 PM
Neither adds the info to the post nor parses it. :(
Dismounted
03-06-2009, 03:58 AM
Actually, just add it to postbit_display_start instead. The parser is run just after that.
MTGDarkness
03-06-2009, 04:03 AM
I tried that, then it just does nothing. It doesn't even add it to the html code.
Dismounted
03-06-2009, 06:00 AM
And the code you are using is?
MTGDarkness
03-06-2009, 11:27 AM
$post['message'] = $post['field11'].$post['message'].$post['field12'];
Message shows up, the fields don't.
Dismounted
03-07-2009, 10:34 AM
$this->post['pagetext'] = $this->post['field11'] . $this->post['pagetext'] . $this->post['field12'];
$post['message'] is only created when BB code is parsed.
MTGDarkness
03-07-2009, 08:35 PM
That worked! OMG Thanks! :D
One question though-what's $this?
Lynne
03-07-2009, 08:46 PM
Object Oriented PHP :)
MTGDarkness
03-07-2009, 09:14 PM
I'm just gonna stop asking there, because I'm 99% sure that I'll never get it. Ever. :D
Dismounted
03-08-2009, 04:44 AM
That worked! OMG Thanks! :D
One question though-what's $this?
$this is a variable that only exists in a class/object. It refers to the current object (i.e. the object where you are running the code). In your case, using $this->post and $post would not make a difference, they are the same (assigned by reference):
$this->post =& $post;
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.