The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Cache System Explanation (datastore)
I'm going to try and explain the datastore system used in vBulltin. This tutorial is based around users who are already familar with PHP and MySQL. What is Cache? I'll show you way using the datastore is a better solution for you and the users who will use your hacks. Attachment 44423 Now everytime you add, edit, or delete your information, it will be changed in the database. Here is an example of the database tree. We have 3 rows of information. Attachment 44424 PHP Code:
Then you need to use the function called build_datastore(). This function requires the following. build_datastore(1, 2). #1 is the name of your datastore item, and number two is the serialize information to store. This function will create a new datastore item with the name and all your info. The serialize info will look like this... Code:
a:3:{i:0;a:3:{s:2:"id";s:1:"1";s:4:"name";s:3:"Dog";s:5:"value";s:3:"Dog";}i:1;a:3:{s:2:"id";s:1:"2";s:4:"name";s:3:"Cat";s:5:"value";s:3:"Cat";}i:2;a:3:{s:2:"id";s:1:"3";s:4:"name";s:3:"Cow";s:5:"value";s:3:"Cow";}} Attachment 44425 Don't let the serialize data freak you out. You don't really NEED to read that data. Though I kinda like doing it, so I'll break it down alittle for you. Here is a tree of the serialize data. Code:
a:3:{ i:0; a:3:{ s:2:"id";s:1:"1"; s:4:"name";s:3:"Dog"; s:5:"value";s:3:"Dog"; } i:1; a:3:{ s:2:"id";s:1:"2"; s:4:"name";s:3:"Cat"; s:5:"value";s:3:"Cat"; } i:2; a:3:{ s:2:"id";s:1:"3"; s:4:"name";s:3:"Cow"; s:5:"value";s:3:"Cow"; } } PHP Code:
PHP Code:
(ID: 1) (Title: Dog) (Value: Dog) (ID: 2) (Title: Cat) (Value: Cat) (ID: 3) (Title: Cow) (Value: Cow) What your doing is simple. The variable $vbulletin->dropmenu holds the information though it's still serialize. The reason why $vbulletin->dropmenu is the variable is because you need to tell vBulletin which datastore row to get. In this case it is dropmenu because remember we stored it in there like this: build_datastore('dropmenu', serialize($variable_array)); Now in order for vBulletin to know about that specific row, you need to add it to the $specialtemplates array. Example: PHP Code:
So $vbulletin->dropmenu = unserialize($vbulletin->dropmenu); baiscly gets the serialize info and unserialize's it using the function called unserialize() Once that is finished you want to loop the info using a foreach() function. foreach ($vbulletin->dropmenu AS $dropmenu). Doing that is storing the array info into $dropmenu and you can get each one by using the following vaiables. $dropmenu['id'], $dropmenu['title'], and $dropmenu['value']. The reason why this is better is because vBulletin allready runs one global query to get all the datatore information. So instead of running a query everytime you want to get the drop down information, you just get it from the datastore and save that query. Some may think this is kinda extreme when you can just run a query, though as your site grows; you want to save as many queires as possiable. If your interested in saving queries and bandwidth. I would suggest taking a look at Trigunflames profile. He has released many hacks to help in these areas. Copyright ?2004-2006 vBHackers.com All Rights Reserved. This tutorial may not be redistributed in whole or significant part. |
#12
|
|||
|
|||
Read beginning from words
Now in order for vBulletin to know about that specific row, you need to add it to the $specialtemplates array. Try parse_templates hook. |
#13
|
|||
|
|||
LOL
I'd already added it to $specialtemplates, as stated in my original post Thank you very much for your help, the parse_templates hook worked a treat. The problem I have now, is having to manually add 'cachestats' to the special templates array of every single page. Is there a way to maybe add to this array from within global.php or something? Thanks again Simon aah.. answered my own question (wonders will never cease!) I've added : $specialtemplates[] = 'cachestats'; to the top of the global.php file which works. So will play around to find the right hook to put it in. -- additional : It seems that there isn't a hook early enough in global.php I'm really playing around in the dark here, so if anyone knows of a hook which runs early enough, could you please let me know? Cheers Simon |
#14
|
|||
|
|||
Hook global_start for $specialtempates[] .=
and parse_templates (and later called specific hooks) for unserialize and other jobs |
#15
|
|||
|
|||
LOL
what a muppet.. thanks mate correction.. global_start appears to be way too late. There are two that seem to run earlier than this, and neither of those are early enough either. ok.. I've whacked the $specialtemplates[] = ... into global_start.. but the variable is empty when the header template is built. when I had identical set-up, but instead of global_start, I hacked the line into the start of the global.php file it worked fine. |
#16
|
|||
|
|||
Sorry, this my tip was for custom stand-alone scripts like this :
PHP Code:
|
#17
|
|||
|
|||
ok.
Thanks a lot for your help netwind, it got me working anyway, with only one file edit. If anyone else knows a hook I can use, it would be great. Thanks Simon |
#18
|
|||
|
|||
I have another related problem: build html in admincp/ not work,
since style not selected. I need example code which build all special vars for function fetch_template() in default style. |
#19
|
||||
|
||||
I must say this is a GREAT article, but I need a little help building the forumcache. If I do as this article says, it just f*cks up my forum and its unable to load correctly
|
#20
|
|||
|
|||
Quote:
Like build_options(), build_datastore(), build_birthdays(), build_maxloggedin(), perhaps build_forumcache() ? I think this thread only applies to datastore objects you have created yourself. |
#21
|
||||
|
||||
I can't find any similar functions that work for the forumcache. Actually build_datastore() works fine saving the data, but I think the input is wrong
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|