Note: this list is kept only as a demonstration for CVSNotice. For the latest CVS notices, see the Xaraya and Postnuke sites
View Statistics - Next Notice - Previous NoticeDirectory filter : [ all ] / postnuke_official / html / modules / hitcount [ view in CVS ]
| Date | Directory [filter] | File(s) [view] | Author [filter] |
| 11 Aug 2002 17:41:17 | postnuke_official/html/modules/hitcount | pnuser.php,1.3,1.4 pnuserapi.php,1.3,1.4 | Mike |
| API to retrieve top N items (+ test) | |||
Update of /home/cvsroot/postnuke_official/html/modules/hitcount
In directory ns7.hostnuke.net:/tmp/cvs-serv12021
Modified Files:
pnuser.php pnuserapi.php
Log Message:
API to retrieve top N items (+ test)
Index: pnuser.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pnuser.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pnuser.php 10 Aug 2002 17:45:51 -0000 1.3
--- pnuser.php 11 Aug 2002 17:41:15 -0000 1.4
***************
*** 33,38 ****
}
// Return output
! return pnML('// TODO: show overview of hooked modules ?');
}
--- 33,58 ----
}
+ // Load API
+ if (!pnModAPILoad('hitcount', 'user')) {
+ return _LOADFAILED;
+ }
+
+ $modlist = pnModAPIFunc('hitcount','user','getmodules');
+ $out = "Modules we're currently counting display hits for : (test only)<br><ul>";
+ foreach ($modlist as $modid => $numitems) {
+ $modinfo = pnModGetInfo($modid);
+ $out .= "<li>$modinfo[name] => $numitems</li>\n<ul>\n";
+ $toplist = pnModAPIFunc('hitcount','user','tophits',
+ array('modname' => $modinfo['name']));
+ foreach ($toplist as $topitem) {
+ $out .= "<li>$topitem[itemid] => $topitem[hits]</li>\n";
+ }
+ $out .= "</ul>\n";
+ }
+ $out .= "</ul>\n";
+
// Return output
! //return pnML('// TODO: show overview of hooked modules ?');
! return $out;
}
Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pnuserapi.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pnuserapi.php 10 Aug 2002 17:45:51 -0000 1.3
--- pnuserapi.php 11 Aug 2002 17:41:15 -0000 1.4
***************
*** 148,151 ****
--- 148,259 ----
/**
+ * get the list of items with top N hits for a module
+ *
+ * @param $args['modname'] name of the module you want items from
+ * @param $args['numitems'] number of items to return
+ * @param $args['startnum'] start at this number (1-based)
+ * @returns array
+ * @return array of array('itemid' => $itemid, 'hits' => $hits)
+ */
+ function hitcount_userapi_tophits($args)
+ {
+ // Get arguments from argument array
+ extract($args);
+
+ // Argument check
+ if (!isset($modname)) {
+ pnSessionSetVar('errormsg', _MODARGSERROR);
+ return;
+ }
+ $modid = pnModGetIDFromName($modname);
+ if (empty($modid)) {
+ pnSessionSetVar('errormsg', _MODARGSERROR);
+ return;
+ }
+
+ // Security check
+ if (!pnSecAuthAction(0, 'Hitcount::', "$modname::", ACCESS_OVERVIEW)) {
+ return;
+ }
+
+ // Database information
+ list($dbconn) = pnDBGetConn();
+ $pntable = pnDBGetTables();
+ $hitcounttable = $pntable['hitcount'];
+
+ // Get items
+ $sql = "SELECT pn_itemid, pn_hits
+ FROM $hitcounttable
+ WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
+ ORDER BY pn_hits DESC";
+
+ if (!isset($numitems) || !is_numeric($numitems)) {
+ $numitems = 10;
+ }
+ if (!isset($startnum) || !is_numeric($startnum)) {
+ $startnum = 1;
+ }
+
+ //$result = $dbconn->Execute($sql);
+ $result = $dbconn->SelectLimit($sql, $numitems, $startnum - 1);
+
+ if ($dbconn->ErrorNo() != 0) {
+ pnSessionSetVar('errormsg', 'SQL Error');
+ return;
+ }
+
+ $toplist = array();
+ while (!$result->EOF) {
+ list($id,$hits) = $result->fields;
+ $toplist[] = array('itemid' => $id, 'hits' => $hits);
+ $result->MoveNext();
+ }
+ $result->close();
+
+ return $toplist;
+ }
+
+ /**
+ * get the list of modules for which we're counting items
+ *
+ * @returns array
+ * @return $array[$modid] = $numitems
+ */
+ function hitcount_userapi_getmodules($args)
+ {
+ // Security check
+ if (!pnSecAuthAction(0, 'Hitcount::', "::", ACCESS_OVERVIEW)) {
+ return;
+ }
+
+ // Database information
+ list($dbconn) = pnDBGetConn();
+ $pntable = pnDBGetTables();
+ $hitcounttable = $pntable['hitcount'];
+
+ // Get items
+ $sql = "SELECT pn_moduleid, COUNT(pn_itemid)
+ FROM $hitcounttable
+ GROUP BY pn_moduleid";
+
+ $result = $dbconn->Execute($sql);
+
+ if ($dbconn->ErrorNo() != 0) {
+ pnSessionSetVar('errormsg', 'SQL Error');
+ return;
+ }
+
+ $modlist = array();
+ while (!$result->EOF) {
+ list($modid,$numitems) = $result->fields;
+ $modlist[$modid] = $numitems;
+ $result->MoveNext();
+ }
+ $result->close();
+
+ return $modlist;
+ }
+
+ /**
* return the field names and correct values for joining on hitcount table
* example : SELECT ..., $moduleid, $itemid, $hits,...
***************
*** 246,251 ****
return $leftjoin;
}
-
- // TODO: add function to get top N items per module etc.
?>
--- 354,357 ----
View Statistics - Next Notice - Previous Notice
| Visit Developer Site - Browse CVS Repository |
Syndicate via backend.rss (max. once per hour please) | Powered by CVSNotice 0.1.3 |