Extending Site Statistics with your plugin
This section will describe and document how to enable your plugin to return statistics back to Geeklog when the site stats page is requested. There are two main sections to the site stats page. The first is a block at the top of the stats pages used for the site summary. The rest of the stats page is a more detailed report for each Geeklog component. Your plugin can be written to return results for both or just one of these sections.
The site statistics summary block at the top may have one line for your plugin as an overall summary counter. This may be the number of contacts in your contact plugin, number of files in your FileMgmt or some other overall event counter for your plugin. This will be a straight forward database query to return the count and description.
The detail stats section allows you to have a block on the stats page for your plugin in which you can report as many lines of detail you want. For example: the staticpage plugin and filemgmt plugin report respectfully, the top 10 pages and files.
There is just one (1) plugin function that you need for your plugin project to support reporting stats back to Geeklog. The example function that is used for explanation in this section and included in this kit should be provide enough details. You can also review the following plugins which have this function implemented:
Staticpages 1.2 | Reports summary and detail |
FileMgmt v1.2 | Reports summary and detail |
Contact Manager v1.0 | Reports summary only - Total number of contacts |
Chatterblock 3.0 | Reports summary only - Total number of chat records |
Function | Description of Function | |
---|---|---|
1 | plugin_showstats_{plugin} | This function expands the site stats reporting and is called with a parameter to indicate to get the plugin summary or detail stats. You can return a blank ' ' if there is nothing to report |
The Plugin API call PLG_getPluginStats() is called twice in stats.php and with each call, all the enabled plugins will return their statistics which are then formatted into the final page.
You may decide to only return a result for one of the stats features. Chatterblock for example only returns a summary stat result.
Plugin database changes
There are no required database changes or plugin table requirements for this API.
Function details and examples
function</b> plugin_showstats_filemgmt(</font>$showsitestats) {
<b> <p style="margin-top: 0; margin-bottom: 4">global</b> <p style="margin-top: 0; margin-bottom: 4"> $total_pages=DB_count($_FM_TABLES['filemgmt_filedetail']); <p style="margin-top: 0; margin-bottom: 4"> $total_downloads=DB_getItem($_FM_TABLES['filemgmt_filedetail'], 'SUM(hits)',""); <p style="margin-top: 0; margin-bottom: 4"> $retval = "<table border = '0' width='100%' cellspacing='0' cellpadding='0'>"; <p style="margin-top: 0; margin-bottom: 4"> $retval .= "<tr><td>" . $LANG_FILEMGMT['nofiles'] . "</td>"; <p style="margin-top: 0; margin-bottom: 4"> $retval .= "<td align='right'>" . $total_pages . " (" .$total_downloads <p style="margin-top: 0; margin-bottom: 4"> .") </td></tr></table>"; </blockquote> <p style="margin-top: 0; margin-bottom: 4">} <b>else</b> {<p style="margin-top: 0; margin-bottom: 4"> $result = DB_query("SELECT lid, title, hits from {<b>$_FM_TABLES</b>['filemgmt_filedetail']} WHERE hits > 0 ORDER BY hits desc LIMIT 10"); <p style="margin-top: 0; margin-bottom: 4"> $nrows = DB_numRows($result); <p style="margin-top: 0; margin-bottom: 4"> $retval .= COM_startBlock($LANG_FILEMGMT['StatsMsg1']); <p style="margin-top: 0; margin-bottom: 4"><b>if</b> ($nrows > 0) {<p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>set_var('item_label',"Page Title"); <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>set_var('stat_name',"Hits"); <p style="margin-top: 0; margin-bottom: 4"><b>for</b> ($i = 0; $i < $nrows && $i < 10; $i++) {<p style="margin-top: 0; margin-bottom: 4">list (</font>$lid, $title,$hits) = DB_fetchARRAY($result); <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>set_var('item_url', $_CONF[site_url]. "/filemgmt/singlefile.php?lid=".$lid); <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>set_var('item_text', $title); <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>set_var('item_stat', $hits); <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>parse('stat_row','statrow',<b>true</b>); </blockquote> <p style="margin-top: 0; margin-bottom: 4">} <p style="margin-top: 0; margin-bottom: 4"> $stat_templates<b>-></b>parse('output','itemstats'); <p style="margin-top: 0; margin-bottom: 4"> $retval .= $stat_templates<b>-></b>finish($stat_templates<b>-></b>get_var('output')); </blockquote> <p style="margin-top: 0; margin-bottom: 4">} <b>else</b> {<p style="margin-top: 0; margin-bottom: 4"> $retval .= $LANG_FILEMGMT['StatsMsg2'];
|