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] |
| 08 Aug 2002 23:00:21 | postnuke_official/html/modules/hitcount | pninit.php,1.1,1.2 pnuser.php,1.1,1.2 pnuserapi.php,1.1,1.2 pnversion.php,1.1,1.2 | Mike |
| use CreateTable, change table design + configurable output/saving to var cache of hitcount | |||
Update of /home/cvsroot/postnuke_official/html/modules/hitcount
In directory ns7.hostnuke.net:/tmp/cvs-serv15055
Modified Files:
pninit.php pnuser.php pnuserapi.php pnversion.php
Log Message:
use CreateTable, change table design + configurable output/saving to var cache of hitcount
Index: pninit.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pninit.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pninit.php 8 Aug 2002 00:53:55 -0000 1.1
--- pninit.php 8 Aug 2002 23:00:19 -0000 1.2
***************
*** 32,51 ****
$pntable = pnDBGetTables();
// Create tables
! $hitcounttable = $pntable['hitcount'];
! $sql = "CREATE TABLE $hitcounttable (
! pn_hcid int(11) NOT NULL auto_increment,
! pn_module varchar(32) NOT NULL default '',
! pn_itemid varchar(64) NOT NULL default '',
! pn_hits int(14) NOT NULL default 1,
! PRIMARY KEY(pn_hcid),
! KEY pn_find (pn_module,pn_itemid),
! KEY pn_sort (pn_hits))";
! $dbconn->Execute($sql);
! // Check database result
if ($dbconn->ErrorNo() != 0) {
! // Report failed initialisation attempt
! return false;
}
--- 32,113 ----
$pntable = pnDBGetTables();
+ // adodb does not provide the functionality to abstract CREATE TABLE
+ // across multiple databases. Postnuke offers the pnDBCreateTable function
+ // contained in the following file to provide this functionality.
+ include_once('pnadodb/pnTableDDL.php');
+
// Create tables
! $query = pnDBCreateTable($pntable['hitcount'],
! array('pn_hitcountid' => array('type' => 'integer',
! 'null' => false,
! 'default' => '0',
! 'increment' => true,
! 'primary_key' => true),
! 'pn_moduleid' => array('type' => 'integer',
! 'unsigned' => true,
! 'null' => false,
! 'default' => '0'),
! 'pn_itemid' => array('type' => 'integer',
! 'unsigned' => true,
! 'null' => false,
! 'default' => '0'),
! 'pn_hits' => array('type' => 'integer',
! 'null' => false,
! 'size' => 'big',
! 'default' => '0')));
! $dbconn->Execute($query);
!
! // Check for db errors
if ($dbconn->ErrorNo() != 0) {
! $msg = pnMLByKey('DATABASE_ERROR', $dbconn->ErrorMsg(), $query);
! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
! new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
! return NULL;
! }
!
! $query = pnDBCreateIndex($pntable['hitcount'],
! array('name' => 'pn_moduleid',
! 'fields' => array('pn_moduleid'),
! 'unique' => false));
!
! $dbconn->Execute($query);
!
! // Check for db errors
! if ($dbconn->ErrorNo() != 0) {
! $msg = pnMLByKey('DATABASE_ERROR', $dbconn->ErrorMsg(), $query);
! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
! new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
! return NULL;
! }
!
! $query = pnDBCreateIndex($pntable['hitcount'],
! array('name' => 'pn_itemid',
! 'fields' => array('pn_itemid'),
! 'unique' => false));
!
! $dbconn->Execute($query);
!
! // Check for db errors
! if ($dbconn->ErrorNo() != 0) {
! $msg = pnMLByKey('DATABASE_ERROR', $dbconn->ErrorMsg(), $query);
! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
! new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
! return NULL;
! }
!
! $query = pnDBCreateIndex($pntable['hitcount'],
! array('name' => 'pn_hits',
! 'fields' => array('pn_hits'),
! 'unique' => false));
!
! $dbconn->Execute($query);
!
! // Check for db errors
! if ($dbconn->ErrorNo() != 0) {
! $msg = pnMLByKey('DATABASE_ERROR', $dbconn->ErrorMsg(), $query);
! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
! new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
! return NULL;
}
***************
*** 69,72 ****
--- 131,139 ----
function hitcount_upgrade($oldversion)
{
+ // adodb does not provide the functionality to abstract ALTER TABLE
+ // across multiple databases. Postnuke offers the pnDBAlterTable function
+ // contained in the following file to provide this functionality.
+ include ('pnadodb/pnTableDDL.php');
+
// Upgrade dependent on old version number
switch($oldversion) {
***************
*** 102,112 ****
$pntable = pnDBGetTables();
// Delete tables
! $sql = "DROP TABLE $pntable[hitcount]";
! $dbconn->Execute($sql);
! // Check database result
if ($dbconn->ErrorNo() != 0) {
! // Report failed deletion attempt
return false;
}
--- 169,187 ----
$pntable = pnDBGetTables();
+ // adodb does not provide the functionality to abstract DROP TABLE
+ // across multiple databases. Postnuke offers the pnDBDropTable function
+ // contained in the following file to provide this functionality.
+ include ('pnadodb/pnTableDDL.php');
+
// Delete tables
! $query = pnDBDropTable($pntable['hitcount']);
! $dbconn->Execute($query);
!
! // Check for db errors
if ($dbconn->ErrorNo() != 0) {
! $msg = pnMLByKey('DATABASE_ERROR', $dbconn->ErrorMsg(), $query);
! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
! new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
return false;
}
Index: pnuser.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pnuser.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pnuser.php 8 Aug 2002 00:53:55 -0000 1.1
--- pnuser.php 8 Aug 2002 23:00:19 -0000 1.2
***************
*** 28,50 ****
function hitcount_user_main()
{
- // Create output object
- $output = new pnHTML();
-
// Security check
if (!pnSecAuthAction(0, 'Hitcount::', '::', ACCESS_OVERVIEW)) {
! $output->Text(pnML('Not authorised'));
! return $output->GetOutput();
}
- $output->Text('// TODO: show overview of hooked modules ?');
-
// Return output
! return $output->GetOutput();
}
/**
! * display hitcount for a specific item, and request hitcount
* @param $args['objectid'] ID of the item this hitcount is for
! * @param $args['extrainfo'] URL to return to if user chooses to rate
* @returns output
* @return output with hitcount information
--- 28,46 ----
function hitcount_user_main()
{
// Security check
if (!pnSecAuthAction(0, 'Hitcount::', '::', ACCESS_OVERVIEW)) {
! return pnML('Not authorised');
}
// Return output
! return pnML('// TODO: show overview of hooked modules ?');
}
/**
! * add a hit for a specific item, and display the hitcount (or save the
! * hit count in the variable cache 'Hooks.hitcount', variable 'value')
! *
* @param $args['objectid'] ID of the item this hitcount is for
! * @param $args['extrainfo'] not particularly relevant here
* @returns output
* @return output with hitcount information
***************
*** 52,57 ****
function hitcount_user_display($args)
{
- // Create new output object
- $output = new pnHTML();
extract($args);
--- 48,51 ----
***************
*** 59,64 ****
// Load API
if (!pnModAPILoad('hitcount', 'user')) {
! $output->Text(_LOADFAILED);
! return $output->GetOutput();
}
--- 53,57 ----
// Load API
if (!pnModAPILoad('hitcount', 'user')) {
! return _LOADFAILED;
}
***************
*** 71,79 ****
if (isset($hitcount)) {
! // Display current hitcount
! $output->Text($hitcount . ' ' . pnML('reads'));
}
! return $output->GetOutput();
}
--- 64,77 ----
if (isset($hitcount)) {
! // Display current hitcount or set the cached variable
! if (!pnVarIsCached('Hooks.hitcount','save') ||
! pnVarGetCached('Hooks.hitcount','save') == false ) {
! return '(' . $hitcount . ' ' . pnML('Reads') . ')';
! } else {
! pnVarSetCached('Hooks.hitcount','value',$hitcount - 1);
! }
}
! return '';
}
Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pnuserapi.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pnuserapi.php 8 Aug 2002 00:53:55 -0000 1.1
--- pnuserapi.php 8 Aug 2002 23:00:19 -0000 1.2
***************
*** 42,46 ****
// Security check
! if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_READ)) {
return;
}
--- 42,52 ----
// Security check
! if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_OVERVIEW)) {
! return;
! }
!
! $modid = pnModGetIDFromName($modname);
! if (empty($modid)) {
! pnSessionSetVar('errormsg', _MODARGSERROR);
return;
}
***************
*** 54,58 ****
$sql = "SELECT pn_hits
FROM $hitcounttable
! WHERE pn_module = '" . pnVarPrepForStore($modname) . "'
AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
$result = $dbconn->Execute($sql);
--- 60,64 ----
$sql = "SELECT pn_hits
FROM $hitcounttable
! WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
$result = $dbconn->Execute($sql);
***************
*** 73,76 ****
--- 79,83 ----
* @param $args['modname'] module name of the item to hit
* @param $args['objectid'] ID of the item to hit
+ * @param $args['hits'] (optional) number of current hits
* @returns int
* @return the new hitcount for this item
***************
*** 78,82 ****
function hitcount_userapi_hit($args)
{
-
// Get arguments from argument array
extract($args);
--- 85,88 ----
***************
*** 89,97 ****
}
if (!isset($hits)) {
! $hits = 1;
}
// Security check
! if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_COMMENT)) {
return;
}
--- 95,109 ----
}
if (!isset($hits)) {
! $hits = 0;
}
// Security check
! if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_OVERVIEW)) {
! return;
! }
!
! $modid = pnModGetIDFromName($modname);
! if (empty($modid)) {
! pnSessionSetVar('errormsg', _MODARGSERROR);
return;
}
***************
*** 105,112 ****
// Get current information on hits
! $sql = "SELECT pn_hcid,
pn_hits
FROM $hitcounttable
! WHERE pn_module = '" . pnVarPrepForStore($modname) . "'
AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
$result = $dbconn->Execute($sql);
--- 117,124 ----
// Get current information on hits
! $sql = "SELECT pn_hitcountid,
pn_hits
FROM $hitcounttable
! WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
$result = $dbconn->Execute($sql);
***************
*** 119,131 ****
if (!$result->EOF) {
// Update current hitcount
! list($hcid, $hits) = $result->fields;
$result->close();
! $newhits = $hits + 1;
// Insert new hitcount
$sql = "UPDATE $hitcounttable
SET pn_hits = " . pnVarPrepForStore($newhits) . "
! WHERE pn_hcid = $hcid";
$dbconn->Execute($sql);
--- 131,147 ----
if (!$result->EOF) {
// Update current hitcount
! list($hcid, $oldhits) = $result->fields;
$result->close();
! if ($oldhits > $hits) {
! $newhits = $oldhits + 1;
! } else {
! $newhits = $hits + 1;
! }
// Insert new hitcount
$sql = "UPDATE $hitcounttable
SET pn_hits = " . pnVarPrepForStore($newhits) . "
! WHERE pn_hitcountid = $hcid";
$dbconn->Execute($sql);
***************
*** 137,151 ****
$result->close();
// Get a new hitcount ID
$hcid = $dbconn->GenId($hitcounttable);
// Create new hitcount
! $sql = "INSERT INTO $hitcounttable(pn_hcid,
! pn_module,
pn_itemid,
pn_hits)
VALUES ($hcid,
! '" . pnVarPrepForStore($modname) . "',
'" . pnVarPrepForStore($objectid) . "',
! 1)";
$dbconn->Execute($sql);
--- 153,169 ----
$result->close();
+ $newhits = $hits + 1;
+
// Get a new hitcount ID
$hcid = $dbconn->GenId($hitcounttable);
// Create new hitcount
! $sql = "INSERT INTO $hitcounttable(pn_hitcountid,
! pn_moduleid,
pn_itemid,
pn_hits)
VALUES ($hcid,
! '" . pnVarPrepForStore($modid) . "',
'" . pnVarPrepForStore($objectid) . "',
! '" . pnVarPrepForStore($newhits) . "')";
$dbconn->Execute($sql);
***************
*** 155,163 ****
return;
}
-
- $newhits = $hits;
}
return $newhits;
}
--- 173,350 ----
return;
}
}
return $newhits;
+ }
+
+ /**
+ * get a hitcount for a list of items
+ * @param $args['modname'] name of the module you want items from
+ * @param $args['itemids'] array of item IDs
+ * @returns array
+ * @return $array[$itemid] = $hits;
+ */
+ function hitcount_userapi_gethits($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;
+ }
+
+ if (!isset($itemids)) {
+ $itemids = array();
+ }
+
+ // Security check
+ if (count($itemids) > 0) {
+ foreach ($itemids as $itemid) {
+ if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$itemid", ACCESS_OVERVIEW)) {
+ return;
+ }
+ }
+ } else {
+ 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) . "'";
+ if (count($itemids) > 0) {
+ $allids = join(', ',$itemids);
+ $sql .= " AND pn_itemid IN ('" . pnVarPrepForStore($allids) . "')";
+ }
+ $result = $dbconn->Execute($sql);
+
+ if ($dbconn->ErrorNo() != 0) {
+ pnSessionSetVar('errormsg', 'SQL Error');
+ return;
+ }
+
+ $hitlist = array();
+ while (!$result->EOF) {
+ list($id,$hits) = $result->fields;
+ $hitlist[$id] = $hits;
+ $result->MoveNext();
+ }
+ $result->close();
+
+ return $hitlist;
+ }
+
+ /**
+ * return the field names and correct values for joining on hitcount table
+ * example : SELECT ..., $moduleid, $itemid, $hits,...
+ * FROM ...
+ * LEFT JOIN $table
+ * ON $field = <name of itemid field>
+ * WHERE ...
+ * AND $hits > 1000
+ * AND $where
+ *
+ * @param $args['modname'] name of the module you want items from, or
+ * @param $args['modid'] ID of the module you want items from
+ * @param $args['itemids'] optional array of itemids that we are selecting on
+ * @returns array
+ * @return array('table' => 'nuke_hitcount',
+ * 'field' => 'nuke_hitcount.pn_itemid',
+ * 'where' => 'nuke_hitcount.pn_itemid IN (...)
+ * AND nuke_hitcount.pn_moduleid = 123',
+ * 'moduleid' => 'nuke_hitcount.pn_moduleid',
+ * ...
+ * 'hits' => 'nuke_hitcount.pn_hits')
+ */
+ function hitcount_userapi_leftjoin($args)
+ {
+ // Get arguments from argument array
+ extract($args);
+
+ // Optional argument
+ if (!isset($modname)) {
+ $modname = '';
+ } else {
+ $modid = pnModGetIDFromName($modname);
+ }
+ if (!isset($modid)) {
+ $modid = '';
+ }
+ if (!isset($itemids)) {
+ $itemids = array();
+ }
+
+ // Security check
+ if (count($itemids) > 0) {
+ foreach ($itemids as $itemid) {
+ if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$itemid", ACCESS_OVERVIEW)) {
+ return;
+ }
+ }
+ } else {
+ if (!pnSecAuthAction(0, 'Hitcount::', "$modname::", ACCESS_OVERVIEW)) {
+ return;
+ }
+ }
+
+ // Table definition
+ $pntable = pnDBGetTables();
+ $userstable = $pntable['hitcount'];
+
+ $leftjoin = array();
+
+ // Specify LEFT JOIN ... ON ... [WHERE ...] parts
+ $leftjoin['table'] = $pntable['hitcount'];
+ if (!empty($modid)) {
+ $leftjoin['field'] = $pntable['hitcount'] . '.pn_moduleid = ' . $modid;
+ $leftjoin['field'] .= ' AND ' . $pntable['hitcount'] . '.pn_itemid';
+ } else {
+ $leftjoin['field'] = $pntable['hitcount'] . '.pn_itemid';
+ }
+
+ if (count($itemids) > 0) {
+ $allids = join(', ', $itemids);
+ $leftjoin['where'] = $pntable['hitcount'] . '.pn_itemid IN (' .
+ pnVarPrepForStore($allids) . ')';
+ /*
+ if (!empty($modid)) {
+ $leftjoin['where'] .= ' AND ' .
+ $pntable['hitcount'] . '.pn_moduleid = ' .
+ $modid;
+ }
+ */
+ } else {
+ /*
+ if (!empty($modid)) {
+ $leftjoin['where'] = $pntable['hitcount'] . '.pn_moduleid = ' .
+ $modid;
+ } else {
+ $leftjoin['where'] = '';
+ }
+ */
+ $leftjoin['where'] = '';
+ }
+
+ // Add available columns in the hitcount table
+ $columns = array('moduleid','itemid','hits');
+ foreach ($columns as $column) {
+ $leftjoin[$column] = $pntable['hitcount'] . '.pn_' . $column;
+ }
+
+ return $leftjoin;
}
Index: pnversion.php
===================================================================
RCS file: /home/cvsroot/postnuke_official/html/modules/hitcount/pnversion.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pnversion.php 8 Aug 2002 00:53:55 -0000 1.1
--- pnversion.php 8 Aug 2002 23:00:19 -0000 1.2
***************
*** 4,8 ****
$modversion['id'] = '177';
$modversion['version'] = '1.0';
! $modversion['description'] = 'Count number of displays of module items';
$modversion['credits'] = 'pndocs/credits.txt';
$modversion['help'] = 'pndocs/help.txt';
--- 4,8 ----
$modversion['id'] = '177';
$modversion['version'] = '1.0';
! $modversion['description'] = 'Count displays of module items';
$modversion['credits'] = 'pndocs/credits.txt';
$modversion['help'] = 'pndocs/help.txt';
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 |