AJAX print stats in a block.
easy but slow way
stats.php
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$block = module_invoke('statistics', 'block', 'view', 0);
print $block['content'];
put in a block
<div id="stats">
</div>
<script>
$('#stats').load('/stats.php');
</script>
Harder to do, but faster
Coming soon.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | boost-503628.patch | 11.16 KB | mikeytown2 |
| #13 | boost-503628.patch | 9.21 KB | mikeytown2 |
| #7 | boost-503628-1.patch | 14.87 KB | mikeytown2 |
| #6 | boost-503628.patch | 13.04 KB | mikeytown2 |
Comments
Comment #1
mikeytown2 commentedSave stats block in a cron run; cron would need to be run often to make this effective.
put this at the top of boost_stats.php; before everything else.
Have cron run this
Put this in a block
Be sure to set the correct path, if your in a subdir.
Comment #2
brianmercer commentedIf I do not copy boost_stats.php to my document root, I get a disturbing yellow bar on my status page. If I do copy it to my document root, I get a php call with every load of my static file, which somewhat mitigates the scalability of using a static file cache. Should there be a setting to turn off the warning if I don't want the stats, or maybe move the warning to red text on the performance page?
Comment #3
mikeytown2 commentedDisable the stats module, and the yellow bar goes away.
Comment #4
mikeytown2 commentedCouple of changes to do:
Check that the statistics module is enabled, not just it's values stored in the variables table.
SELECT 'status' FROM 'system' WHERE 'name' = 'statistics'EDIT: http://api.drupal.org/api/function/module_exists
Break boost_stats.php into functions and allow for a single ajax transaction when updating stats and getting the stats html.
Comment #5
mikeytown2 commentedUse $delta value for boost_block(); add #1 to boost_cron().
http://api.drupal.org/api/function/hook_block
Use jquery if/else in drupal_add_js() with
$preprocess = FALSEfor page specific javascript variables.Get rid of boost_footer().
Comment #6
mikeytown2 commentedFirst try at rewrite... it still needs work.
Comment #7
mikeytown2 commentedI'm happy with this patch. A new block controls stats.
Comment #8
mikeytown2 commentedNeed to change code on status page.
Comment #9
mikeytown2 commentedmake the html the same, thus controlling the display is done entirely in boost_stats.php
Comment #10
mikeytown2 commentedin JS if boost_stats.php doesn't exits, fall back to a boost/ajax menu hook that does what I need.
Comment #11
mikeytown2 commentedcommitted patch, still need to do other changes
Comment #12
mikeytown2 commentedStep 1: JS that sends info & updates multiple div's.
Step 2: boost_stats.php does a full drupal bootstrap or not, depending on the settings.
Boot up DB & variable_get('throttle_level', 0) among others. If 1 then use cached html for output, if 0 then do a full bootstrap and return current html for the block(s).
Step 3: Fall back code
Create a menu hook called boost_stats.php that returns the current html for the block(s).
Setp 4: Smarter status page.
Comment #13
mikeytown2 commentedSteps 1 & 2 done
Comment #14
mikeytown2 commentedcommitted
Comment #15
mikeytown2 commentedStep 2.5: Hide Block
Hide the block if show stats is set to false, via reply from AJAX. JSON returns ID & NULL.
Step 3: Fall back code
Create a menu hook called boost_stats.php that returns the current html for the block(s).
Setp 4: Smarter status page.
Comment #16
mikeytown2 commenteduse jQuery to hide block.
Comment #17
mikeytown2 commentedability for boost_stats.php to handle old (load HTML) and new (JSON) via
js=2vsjs=1. Allows for sites that upgrade to not have flush the cache for boost stats to work.Comment #18
mikeytown2 commentedPatch includes Everything:
Ability for boost_stats.php to handle old (load HTML) and new (JSON) via js=2 vs js=1.
Hides the block if show stats is set to false, via reply from AJAX.
Menu hook called boost_stats.php that returns the current html for the block(s).
Got rid of status page warning.
Comment #19
mikeytown2 commentedcommitted