i'm still trying to figure out how to export this entire thing (with all my crons/ phrases etc) but no one is helping me out on .com
http://www.vbulletin.com/forum/showthread.php?t=274552
otherwise, i'd just post my entire product.
basically, this is what i did.
1) I made a cron job to populate a table from live post/thread table data. (Perhaps this table is useless now altogether, but i like having a table i can reference during testing. next version probably won't include this cache_ table at all)
Code:
<?php
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
//clean up...
$vbulletin->db->query_write('TRUNCATE TABLE ' . TABLE_PREFIX . 'cache_activetopics');
$vbulletin->db->query_write('insert into ' . TABLE_PREFIX . 'cache_activetopics
/// my big select query here
');
// now, this loads that new data into an array, which is then shoved into the build datastore function:
$query = $vbulletin->db->query_read('SELECT * from ' . TABLE_PREFIX . 'cache_activetopics');
while ($variable = $vbulletin->db->fetch_array($query))
{
$variable_array[] = $variable;
}
build_datastore('skm_active_cache', serialize($variable_array), true);
log_cron_action('', $nextitem, 1);
?>
Again, you can skip truncating and building the table... just run the big query here as the $query = part to get your array/data.
Set up the cron job to run this script as you like.
Run it once manually to make sure you have data in the datastore row.
there will actually be a row with the name skm_active_cache in the datastore table.
2) from there, i have 4 plugins in my product
Quote:
Product : SKM - Active threads from past 24 hours
SKM Active Threads - Cache output templates cache_templates
SKM Active Threads - Cache Special Templates (datastore row) init_startup
SKM Active Threads - Parse and Print forumhome_complete
SKM Active Threads - Template Group template_groups
|
a) cache_templates hook : contains the simple caching of my custom template which prints 1 row of data (ie, <tr><td>1</td><td>2</td></tr> ) similar to the 'threadbits' template
it contains a simple line:
Code:
$globaltemplates[] = 'skm_activethreads24_forumhome';
b) init_startup hook : special templates is probably a mis-nomer at this point, as i'm NOT using the special templates array merge style.
This file pulls the datastore row into memory:
Code:
$datastore_fetch[] = "'skm_active_cache'";
note the quotes are important. This name should match what you ran in your cron under the build_datastore() function.
c) forumhome_complete hook : parse the data and print it to the template step. obviously, forumhome_complete should match the area you are trying to hook into. in my case, it was on the forum home.
Code:
foreach ($vbulletin->skm_active_cache AS $mycache)
{
$output['threadid'] = $mycache['tid'];
eval("\$mythreadbits .= \"".fetch_template('skm_activethreads24_forumhome')."\";");
}
d) the template will look for the $output array to print, ala:
Code:
<a href="showthread.php?t=$output[threadid]&goto=newpost">
e) the template group is not required... just makes things easier to group when you have a lot of templates.
That's about it.
basically, you need to fill the datastore with your query, and pull with a foreach of the array once the data has been initialized.