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 00:53:57 | postnuke_official/html/modules/hitcount | pninit.php,NONE,1.1 pntables.php,NONE,1.1 pnuser.php,NONE,1.1 pnuserapi.php,NONE,1.1 pnversion.php,NONE,1.1 | Mike |
hitcount utility module |
Update of /home/cvsroot/postnuke_official/html/modules/hitcount In directory ns7.hostnuke.net:/tmp/cvs-serv4832 Added Files: pninit.php pntables.php pnuser.php pnuserapi.php pnversion.php Log Message: hitcount utility module --- NEW FILE: pninit.php --- <?php // $Id: pninit.php,v 1.1 2002/08/08 00:53:55 mikespub Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2002 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Jim McDonald // Purpose of file: Initialisation functions for hitcount // ---------------------------------------------------------------------- /** * initialise the hitcount module */ function hitcount_init() { // Get database information list($dbconn) = pnDBGetConn(); $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; } // Set up module hooks if (!pnModRegisterHook('item', 'display', 'GUI', 'hitcount', 'user', 'display')) { return false; } // Initialisation successful return true; } /** * upgrade the hitcount module from an old version */ function hitcount_upgrade($oldversion) { // Upgrade dependent on old version number switch($oldversion) { case 1.0: // Code to upgrade from version 1.0 goes here break; case 1.1: // Code to upgrade from version 1.1 goes here break; } return true; } /** * delete the hitcount module */ function hitcount_delete() { // Remove module hooks if (!pnModUnregisterHook('item', 'display', 'GUI', 'hitcount', 'user', 'display')) { pnSessionSetVar('errormsg', pnML('Could not unregister hook')); // return false; } // Get database information list($dbconn) = pnDBGetConn(); $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; } // Deletion successful return true; } ?> --- NEW FILE: pntables.php --- <?php // $Id: pntables.php,v 1.1 2002/08/08 00:53:55 mikespub Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2002 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Jim McDonald // Purpose of file: Table information for hitcount module // ---------------------------------------------------------------------- function hitcount_pntables() { // Initialise table array $pntable = array(); // Name for hitcount database entities $hitcount = pnConfigGetVar('prefix') . '_hitcount'; // Table name $pntable['hitcount'] = $hitcount; // Return table information return $pntable; } ?> --- NEW FILE: pnuser.php --- <?php // $Id: pnuser.php,v 1.1 2002/08/08 00:53:55 mikespub Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2002 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Jim McDonald // Purpose of file: hitcount user display functions // ---------------------------------------------------------------------- /** * the main user function */ 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 */ function hitcount_user_display($args) { // Create new output object $output = new pnHTML(); extract($args); // Load API if (!pnModAPILoad('hitcount', 'user')) { $output->Text(_LOADFAILED); return $output->GetOutput(); } // Run API function $args['modname'] = pnModGetName(); $hitcount = pnModAPIFunc('hitcount', 'user', 'hit', $args); if (isset($hitcount)) { // Display current hitcount $output->Text($hitcount . ' ' . pnML('reads')); } return $output->GetOutput(); } ?> --- NEW FILE: pnuserapi.php --- <?php // $Id: pnuserapi.php,v 1.1 2002/08/08 00:53:55 mikespub Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2002 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Jim McDonald // Purpose of file: Hitcount Hook User API // ---------------------------------------------------------------------- /** * get a hitcount for a specific item * @param $args['modname'] name of the module this hitcount is for * @param $args['objectid'] ID of the item this hitcount is for * @returns int * @return hits the corresponding hit count, or boid if no hit exists */ function hitcount_userapi_get($args) { // Get arguments from argument array extract($args); // Argument check if ((!isset($modname)) || (!isset($objectid))) { pnSessionSetVar('errormsg', _MODARGSERROR); return; } // Security check if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_READ)) { return; } // Database information list($dbconn) = pnDBGetConn(); $pntable = pnDBGetTables(); $hitcounttable = $pntable['hitcount']; // Get items $sql = "SELECT pn_hits FROM $hitcounttable WHERE pn_module = '" . pnVarPrepForStore($modname) . "' AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'"; $result = $dbconn->Execute($sql); if ($dbconn->ErrorNo() != 0) { pnSessionSetVar('errormsg', 'SQL Error'); return; } $hits = $result->fields[0]; $result->close(); return $hits; } /** * hit an item * @param $args['modname'] module name of the item to hit * @param $args['objectid'] ID of the item to hit * @returns int * @return the new hitcount for this item */ function hitcount_userapi_hit($args) { // Get arguments from argument array extract($args); // Argument check if ((!isset($modname)) || (!isset($objectid))) { pnSessionSetVar('errormsg', _MODARGSERROR); return; } if (!isset($hits)) { $hits = 1; } // Security check if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_COMMENT)) { return; } // TODO: yeah, this is just a quick & dirty adaptation from ratings for now :-) // Database information list($dbconn) = pnDBGetConn(); $pntable = pnDBGetTables(); $hitcounttable = $pntable['hitcount']; // 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); if ($dbconn->ErrorNo() != 0) { pnSessionSetVar('errormsg', 'SQL Error'); return; } 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); if ($dbconn->ErrorNo() != 0) { pnSessionSetVar('errormsg', 'SQL Error'); return; } } else { $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); if ($dbconn->ErrorNo() != 0) { pnSessionSetVar('errormsg', 'SQL Error'); return; } $newhits = $hits; } return $newhits; } // TODO: add function to get top N items per module etc. ?> --- NEW FILE: pnversion.php --- <?php // $Id: pnversion.php,v 1.1 2002/08/08 00:53:55 mikespub Exp $ $modversion['name'] = 'Hitcount'; $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'; $modversion['changelog'] = 'pndocs/changelog.txt'; $modversion['license'] = 'pndocs/license.txt'; $modversion['coding'] = 'pndocs/coding.txt'; $modversion['official'] = 1; $modversion['author'] = 'Jim McDonald'; $modversion['contact'] = 'http://www.mcdee.net/'; $modversion['admin'] = 0; $modversion['securityschema'] = array('Hitcount::' => 'Module name::Item ID'); $modversion['class'] = 'Core Utility'; $modversion['category'] = 'Content'; ?>
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 |