PDA

View Full Version : Which hook to use?


Infoman4ever
12-17-2011, 07:32 PM
Hi,
I added a new column to "thread" table and performed a plugin to fill it with a particular data relative to each thread and everything went well, but what I'm stacking on is Where to show this column on "showthread.php", I used this tag:
{vb:raw threadinfo.my_new_column}
I copy-pasted it manually on "showthread" template and it worked but not in where I want, I want to show it near to date of publication on the "posthead" above the first post of the thread, what I'm looking for is which hook should I use to display my data on the proper area?

Regards.

kh99
12-18-2011, 03:25 AM
I'm not sure I understand what you mean. If you pasted it in the SHOWTHREAD template and it works, why not just paste it where you want it? If you mean that you want it to be inserted by your plugin code so that you don't have to edit the template manually, then it can be done but it gets a little tricky. You basically need to do a str_replace() on the cached template before it's used. Also you can't put in template "curly brace" tags that way, you would need to insert a string.

Infoman4ever
12-18-2011, 12:23 PM
If you pasted it in the SHOWTHREAD template and it works, why not just paste it where you want it?
I tried in couple places but did not get it where I want, I want it to be displayed here (attached), that I should know the hook corresponding to this place, right?


If you mean that you want it to be inserted by your plugin code so that you don't have to edit the template manually

Yep, here we are.


You basically need to do a str_replace() on the cached template before it's used. Also you can't put in template "curly brace" tags that way, you would need to insert a string.
Well, not really clear, what is "cached template"? the one I create manually or what? please give me -such a beginner :rolleyes: - more details.
Thank you kh99, waiting forward...

kh99
12-18-2011, 12:42 PM
Well, not really clear, what is "cached template"? the one I create manually or what? please give me -such a beginner :rolleyes: - more details.
Thank you kh99, waiting forward...


Unfortunately it's difficult, I could write pages and still not explain everything (partly because I don't fully understand it myself). But in this case I happen to have a mod that changes the SHOWTHREAD template. It uses the showthread_getinfo hook location and has code like this
$find = "some string";
$replace = "other string";
$vbulletin->templatecache['SHOWTHREAD'] = str_replace($find, $replace, $vbulletin->templatecache['SHOWTHREAD']);


but, $vbulletin->templatecache contains compiled templates so it doesn't look like what you see in the template editor. That makes it tricky to know what you can search for and match. You could look in the template table in the database, the "template" column shows the compiled template. Or what I usually do is put in temporary code to write the cached template string to a file, like

$fp = fopen("showthread.txt", "wb");
fwrite($fp, $vbulletin->templatecache['SHOWTHREAD']);


Then I open that file in my editor so I can refer to it.

I hope that makes some sense.

Infoman4ever
12-18-2011, 04:34 PM
Well, where to put these lines please?
And, why would it be difficult? if I could do it with a hook 'showthread_getinfo', I thought I can do it with another, I just don't know what is it, I saw couple of products with double of what I want, so I still believe it's not that difficult ;) Thanks deeply Mr kh99.

kh99
12-18-2011, 04:47 PM
Put those lines in a plugin using hook location 'showthread_getinfo'.

Maybe 'difficult' is the wrong word, maybe 'tricky' is better. Because like I said you might look at the template and try to match a certain string, but that string might not exist in the compiled template so you need to look at the compiled string to be sure.

Infoman4ever
12-18-2011, 04:58 PM
We did a good progress till now, just one thing to know is where are they these compiled strings?

kh99
12-18-2011, 05:13 PM
The compiled string in the "template" database table, in the "template" column. The fopen and fwrite lines above are meant to be a "one-time" thing to print the compiled string to a file so you could look at it more easily.

--------------- Added 1324244228 at 1324244228 ---------------

OK, based on the PM you sent me, I guess I misunderstood and your problem is that you can't find the place in the template to insert your change. So I looked but the problem is that I can't find anything that looks like your picture. What version of vb are you running, and what style are you using?

Infoman4ever
12-18-2011, 08:54 PM
Well, it's not exactly alike, I just put the image to make you know the place (the date and time above the post like the first post: "Yesterday, 21:32" and above any other post also).
I'm using (vBulletin 4.1.5), and the basic style.
Regards.

kh99
12-18-2011, 09:02 PM
Oh..lol, I see now, it's actually *this* site. But if you want to put it there, the reason you can't find it in SHOWTHREAD is because that's part of the postbit template (or maybe postbit_legacy if you're using that). So look at postbit, and if you want it to only be in the fist post you can use a condition like:

<vb:if condition="$post['isfirstshown']">your html</vb:if>

Infoman4ever
12-18-2011, 10:20 PM
Wow, it worked perfectly, but I copy-pasted it manually to "postbit_legacy", so that is not a permanent solution, I need either to use a hook, so which one? or to create a template and place it within "postbit_legacy", so how to do so? I use the str_replace or what? (well, I'm asking and testing in the same time, if I got it work I'll post) we almost did it, great work Mr kh99.

kh99
12-18-2011, 11:30 PM
The thing that you're adding, is it always the same or does it change for each user?

Infoman4ever
12-19-2011, 10:43 AM
No it's the same for all users. what about the plugin? still with no solution yet.

--------------- Added 1324327701 at 1324327701 ---------------

[Sighing] At loooong last it worked, I replaced the "postbit_legacy" with another containing my new code all within a plugin, the problem was in the hook, I tried and I tried till got the appropriate one, it was the "showthread_postbit_create", I used this code:

$find = 'find';
$replace = 'replace by';
$vbulletin->templatecache['postbit_legacy'] = str_replace($find, $replace, $vbulletin->templatecache['postbit_legacy']);

And that's it, thanks ma fiend kh99, you been such a useful and a patient advisor, really +1.