Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 07-27-2005, 04:14 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default CODERS PLEASE DISCUSS!!! Pre-Datastore modifications with XML-files (UPDATE 28-7)

Coding in this thread should be considered a Proof of Concept, not to be used outside testboards!!!!!

Alternative 2 presented

Ok now i have got your attention, please read the following. I really want this to become a combined effort of the vbulletin.org community. If we can pull this of in a good way we could try to either convince Jelsoft that this should be standard (i doubt they will do this in 3.5, but worth a try), or we could use it as a standard extension that can be used by many coders. Or everybody will just shoot me for this idea.

We got all these nice plugins etc, but there is still something that can not be done without file edits:
Adding datastore items ($specialtemplates)

Before it also seemed impossible to touch prefetching templates ($globaltemplates & $actiontemplates) or new Phrasegroups ($phrasegroups), although i think most of these could be done with a plugin nowadays

The datastore seems untouchable because it gets loaded before the plugin system gets active.

Alternative 1

See file: Pre-Datastore using XML-files - v1.00.zip

I made 1 modification to ./includes/init.php that could solve this problem. What it does is give you the chance to create a XML-file for your hack that will be loaded before the datastore gets build.

To use this a 1 time modfication to init.php would be needed (unless Jelsoft wants to use it in the standard product), that could be shared by all hacks.

It let's you add in a controled way entries to the following vars:
- $phrasegroups
- $specialtemplates
- $globaltemplates
- $actiontemplates (not working in this version, would have to do some small changes for it)

I have been testing it on my localhost and it doesn't add much to the pageloads (important, it would be executed on each page load).

Please all coders have a look at this modification and give feedback (positive/negative or improvements)

In ./includes/init.php find:
PHP Code:
 $db->timer_start('Datastore Setup');

Add after:
PHP Code:
// #############################################################################
// Start Hack: Pre-Datastore Plugin (MarcoH64)
// Optional TODO: Check $xml['product'] is active
// Not sure if this would be needed in this situation, it can't harm much if it is always active, unless a lot of removed plugins
// But in that case loading might get slow also
// Reading the product table for now to see if active, this extra query will slow down things, so maybe just remove
// We might also want to store in teh $vbulletin object, so it won't need to be queried later again
// Retrieve active products
$actproducts $db->query_read("SELECT productid FROM " TABLE_PREFIX "product WHERE active = 1");
$actprods = array();
while (
$actproduct $db->fetch_array($actproducts))
{
$actprods[] = $actproduct['productid'];
}
unset(
$actproducts);
// / Optional TODO: Check $xml['product'] is active
require_once(DIR '/includes/class_xml.php');
// Maybe seperated directories for the different types of xml-files could speed up processing of the 
// list of files. List might get long with a lot of hacks installed. Example:
// ./includes/xml/cpnav <- Only ACP navigation
// ./includes/xml/preds <- Only Pre-Datastore
$handle opendir(DIR '/includes/xml/');
while ((
$file readdir($handle)) !== false)
{
if (!
preg_match('#^preds_(.*).xml$#i'$file$matches))
{
continue;
}
$preds_file $matches[1];
$xmlobj = new XMLparser(falseDIR "/includes/xml/$file");
$xml =& $xmlobj->parse();
// Optional TODO: Check $xml['product'] is active
// Always allow product 'vbulletin' :))))))))))))
if ($xml['product'] != 'vbulletin'
AND !in_array($xml['product'], $actprods))
{
continue;
}
// / Optional TODO: Check $xml['product'] is active
 
if (!is_array($xml['predsgroup'][0]))
{
$xml['predsgroup'] = array($xml['predsgroup']);
}
 
foreach (
$xml['predsgroup'] AS $predsgroup)
{
// Check if we should handle this entry for the current script
// If the entry is marked with script=global, then always include
// If no script is given, this entry is poorly written and should be distrusted and skipped
// If vb_area is not set in xml-file, or no match, skip. This is done to protect from running while in ACP if lazy coders ommit the area
if ((trim($predsgroup['script']) != 'global' AND trim($predsgroup['script']) != THIS_SCRIPT)
    OR (
trim($predsgroup['vb_area']) != VB_AREA))
{
continue;
}
 
// Handle adding to $specialtemplates
if ($predsgroup['specialtemplates'])
{
if (!
is_array($predsgroup['specialtemplates'][0]))
{
    
$predsgroup['specialtemplates'] = array($predsgroup['specialtemplates']);
}
$specialtemplates = (is_array($specialtemplates) ? array_merge($specialtemplates$predsgroup['specialtemplates'][0]) : array_merge(array($specialtemplates), $predsgroup['specialtemplates'][0]));
}
 
// Handle adding to $phrasegroups
if ($predsgroup['phrasegroups'])
{
if (!
is_array($predsgroup['phrasegroups'][0]))
{
    
$predsgroup['phrasegroups'] = array($predsgroup['phrasegroups']);
}
$phrasegroups = (is_array($phrasegroups) ? array_merge($phrasegroups$predsgroup['phrasegroups'][0]) : array_merge(array($phrasegroups), $predsgroup['phrasegroups'][0]));
}
 
// Handle adding to $globaltemplates 
if ($predsgroup['globaltemplates'])
{
if (!
is_array($predsgroup['globaltemplates'][0]))
{
    
$predsgroup['globaltemplates'] = array($predsgroup['globaltemplates']);
}
$globaltemplates = (is_array($globaltemplates ) ? array_merge($globaltemplates $predsgroup['globaltemplates'][0]) : array_merge(array($globaltemplates ), $predsgroup['globaltemplates'][0]));
}
 
// Handle adding to $actiontemplates
if ($predsgroup['actiontemplates'])
{
if (!
is_array($predsgroup['actiontemplates'][0]))
{
    
$predsgroup['actiontemplates'] = array($predsgroup['actiontemplates']);
}
$actiontemplates = (is_array($actiontemplates) ? array_merge($actiontemplates$predsgroup['actiontemplates'][0]) : array_merge(array($actiontemplates), $predsgroup['actiontemplates'][0]));
}
}
$xmlobj null;
unset(
$xml);
}
// End Hack: Pre-Datastore Plugin (MarcoH64)
// ############################################################################# 
Save and upload init.php.

That is all.

How to use this?

As said before you can now use a XML-file uploaded to the ./includes/xml' directory to control things.

XML-File naming: ./includes/xml/preds_<productid>.xml
Replace the <productid> preferable with the productid you assigned to your hack, but any other unique name should also work.

Now the content of the file:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<predsgroups product="productid">
<predsgroup script="global" vb_area="AdminCP">
<phrasegroups>phrasegroup</phrasegroups>
<specialtemplates>datastoreitem</specialtemplates>
<globaltemplates>globaltemplate</globaltemplates>
<actiontemplates>actiontemplate</actiontemplates>
</predsgroup>
<predsgroup script="showthread" vb_area="Forum">
<phrasegroups>phrasegroup</phrasegroups>
<specialtemplates>datastoreitem</specialtemplates>
<globaltemplates>globaltemplate</globaltemplates>
<actiontemplates>actiontemplate</actiontemplates>
</predsgroup>
</predsgroups>
Note: Like said before actiontemplates don't work yet, so don't even try to use them.

- You must set a product! (if your product is not enabled, code will not run from this file.
- script must contain the name of the file for which this group should be loaded, or 'global' to always load.
- vb_area MUST be set. Default vB has 1 areas 'Forum' and 'AdminCP'
- You can have as many predsgroup's as you need.
- Within each group you can have as many lines as you need. Only the above tags are supported, all other will be ignored.


Please all have a look at this 'proof of concept' and give feedback.

If we think this would be a nice way of standarization with only once a code edit (unless.....) then i will release this to use for all hacks released here on vb.org, if the coder wants to use it.


Alternative 2

See for details file: Proof of Concept Pre-Datastore for plugins - Alternative 2 Version 1.00.zip

Description:
Proof of Concept Pre-Datastore for plugins - Alternative 2 Version 1.00
This code is part of a proof of concept discussion at vbulletin.org. Goal of this discussion is to create a way
to add new datastore items in hacks without having to modify source code for each hack.
Unless Jelsoft decide to incorporate one of the presented alternatives this goal will never be met. At least there would be needed
a one time code modification for all hacks:
Thread: https://vborg.vbsupport.ru/showthread.php?t=93007
Author: MarcoH64
This code might NOT be used as a whole or a part without authors permission.
*** THIS CODE IS STRICTLY TO BE USED FOR CONCEPTUAL TESTING, AND NOT TO BE USED OUTSIDE A TESTBOARD ***
================================================== ================================================== =
Alternative 2:
Add a new table that will store information of datastore items needed for any script.
Merge the info of that table with the standard vB datastore items that are retrieved in unmodified code.
The idea of this alternative was presented by different members on vb.org and vb.com.
Pro in this solution:
- No need to parse XML-files for each pageload (compaired to Alternative 1)
- Should probably be faster because of this.
- Table can be loaded together with the default Product XML-file
Con's in this alternative:
- Will also execute if Plugin System is globally disabled (chicken and egg problem, or extra queries needed)
- A lot more file modifications needed
- Script to maintain the information stored in the table not written (yet?).
Should anyway only be available in debug mode?
- Need to create a new table
- Query to use when loading the datastore on each page load might be slowed down considerably. This should be tested
in a representable environment. Same goes for alternative 1.
- This alternative only handles new datastore items, not template caching like alternative 1
Closed Thread


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:05 PM.


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.09168 seconds
  • Memory Usage 2,359KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (2)postbit_attachment
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete