Xaraya / Postnuke CVS Notices - Message

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 Notice

Directory filter : [ all ] / postnuke_official / html / modules / hitcount [ view in CVS ]


Deprecated: Function gmstrftime() is deprecated in /home/mikespub/www/list.php on line 509
Date Directory [filter] File(s) [view] Author [filter]
10 Aug 2002 17:44:58postnuke_official/html/modules/hitcountpnadminapi.php,NONE,1.1Mike
 move userapi_hit to adminapi_update, introduce item create/delete hooks, and category delete hook

Update of /home/cvsroot/postnuke_official/html/modules/hitcount
In directory ns7.hostnuke.net:/tmp/cvs-serv1262

Added Files:
	pnadminapi.php 
Log Message:
move userapi_hit to adminapi_update, introduce item create/delete hooks, and category delete hook


--- NEW FILE: pnadminapi.php ---
<?php // $Id: pnadminapi.php,v 1.1 2002/08/10 17:44:56 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 administration API
// ----------------------------------------------------------------------

/**
 * create a new hitcount item (= create hook for type 'item')
 *
 * @param $args['objectid'] ID of the object
 * @param $args['extrainfo'] extra information
 * @param $args['modname'] name of the calling module (not used in hook calls)
 * @param $args['hits'] optional hit count for the item (not used in hook calls)
 * @returns int
 * @return hitcount item ID on success, void on failure
 * @raise BAD_PARAM, NO_PERMISSION, DATABASE_ERROR
 */
function hitcount_adminapi_create($args)
{
    extract($args);

    if (!isset($objectid) || !is_numeric($objectid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'object ID', 'admin', 'create', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return;
    }

    // When called via hooks, modname wil be empty, but we get it from the
    // current module
    if (empty($modname)) {
        $modname = pnModGetName();
    }
    $modid = pnModGetIDFromName($modname);
    if (empty($modid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'module name', 'admin', 'create', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return;
    }

// TODO: re-evaluate this for hook calls !!
    // Security check - important to do this as early on as possible to
    // avoid potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_ADD)) {
        $msg = pnML('Not authorized to add #(1) items',
                    'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'NO_PERMISSION',
                       new SystemException($msg));
        return;
    }

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $hitcounttable = $pntable['hitcount'];

    // Get a new hitcount ID
    $nextId = $dbconn->GenId($hitcounttable);
    // Create new hitcount
    if (!isset($hits) || !is_numeric($hits)) {
         $hits = 0;
    }
    $sql = "INSERT INTO $hitcounttable(pn_hitcountid,
                                       pn_moduleid,
                                       pn_itemid,
                                       pn_hits)
            VALUES ($nextId,
                    '" . pnVarPrepForStore($modid) . "',
                    '" . pnVarPrepForStore($objectid) . "',
                    '" . pnVarPrepForStore($hits) . "')";

    $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() != 0) {
        $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
                    'admin', 'create', 'Hitcount');
        pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
                       new SystemException($msg));
        return;
    }

    $hcid = $dbconn->PO_Insert_ID($hitcounttable, 'pn_hitcountid');

    // hmmm, I think we'll skip calling more hooks here... :-)
    //pnModCallHooks('item', 'create', $hcid, 'hitcountid');

    // Return the id of the newly created item to the calling process
    // (not that this will be of any used when called via hooks, but
    // who knows where else this might be used)
    return $hcid;
}

/**
 * delete a hitcount item (delete hook for type 'item')
 *
 * @param $args['objectid'] ID of the object
 * @param $args['extrainfo'] extra information
 * @param $args['modname'] name of the calling module (not used in hook calls)
 * @returns bool
 * @return true on success, false on failure
 * @raise BAD_PARAM, NO_PERMISSION, DATABASE_ERROR
 */
function hitcount_adminapi_delete($args)
{
    extract($args);

    if (!isset($objectid) || !is_numeric($objectid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'object ID', 'admin', 'delete', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return false;
    }

    // When called via hooks, modname wil be empty, but we get it from the
    // current module
    if (empty($modname)) {
        $modname = pnModGetName();
    }
    $modid = pnModGetIDFromName($modname);
    if (empty($modid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'module name', 'admin', 'delete', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return false;
    }

// TODO: re-evaluate this for hook calls !!
    // Security check - important to do this as early on as possible to
    // avoid potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_DELETE)) {
        $msg = pnML('Not authorized to delete #(1) items',
                    'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'NO_PERMISSION',
                       new SystemException($msg));
        return false;
    }

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $hitcounttable = $pntable['hitcount'];

    // Don't bother looking if the item exists here...

    $sql = "DELETE FROM $hitcounttable
            WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
              AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
    $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() != 0) {
        $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
                    'admin', 'delete', 'Hitcount');
        pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
                       new SystemException($msg));
        return false;
    }

    // hmmm, I think we'll skip calling more hooks here... :-)
    //pnModCallHooks('item', 'delete', $exid, '');

    // Let the calling process know that we have finished successfully
    return true;
}

/**
 * update a hitcount item (used by display hook hitcount_user_display)
 *
 * @param $args['modname'] name of the calling module (see _user_display)
 * @param $args['objectid'] ID of the object
 * @param $args['extrainfo'] extra information (unused here)
 * @param $args['hits'] (optional) hit count for the item
 * @returns int
 * @return the new hitcount for this item, or void on failure
 * @raise BAD_PARAM, NO_PERMISSION, DATABASE_ERROR
 */
function hitcount_adminapi_update($args)
{
    extract($args);

    if (!isset($objectid) || !is_numeric($objectid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'object ID', 'admin', 'update', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return;
    }

    // When called via hooks, modname wil be empty, but we get it from the
    // current module
    if (empty($modname)) {
        $modname = pnModGetName();
    }
    $modid = pnModGetIDFromName($modname);
    if (empty($modid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'module name', 'admin', 'update', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return;
    }

// TODO: re-evaluate this for hook calls !!
    // Security check - important to do this as early on as possible to
    // avoid potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Hitcount::', "$modname::$objectid", ACCESS_EDIT)) {
        $msg = pnML('Not authorized to add #(1) items',
                    'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'NO_PERMISSION',
                       new SystemException($msg));
        return;
    }

    if (!pnModAPILoad('hitcount', 'user')) {
        $msg = pnML('Unable to load #(1) #(2) API',
                    'Hitcount','user');
        pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
                       new SystemException($msg));
        return;
    }

    // get current hit count
    $oldhits = pnModAPIFunc('hitcount',
                            'user',
                            'get',
                            array('objectid' => $objectid,
                                  'modname' => $modname));

    // create the item if necessary
    if (!isset($oldhits)) {
        $hcid = pnModAPIFunc('hitcount','admin','create',
                             array('objectid' => $objectid,
                                   'modname' => $modname));
        if (!isset($hcid)) {
            return; // throw back whatever it was that failed
        }
    }

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $hitcounttable = $pntable['hitcount'];

    // set to the new hit count
    if (!empty($hits) && is_numeric($hits)) {
        $sql = "UPDATE $hitcounttable
                SET pn_hits = '" . pnVarPrepForStore($hits) . "'
                WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
                  AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
    } else {
        $sql = "UPDATE $hitcounttable
                SET pn_hits = pn_hits + 1
                WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'
                  AND pn_itemid = '" . pnVarPrepForStore($objectid) . "'";
        $hits = $oldhits + 1;
    }
    $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() != 0) {
        $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
                    'admin', 'update', 'Hitcount');
        pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
                       new SystemException($msg));
        return;
    }

    // Return the new hitcount (give or take a few other hits in the meantime)
    return $hits;
}

/**
 * delete all hitcount items for a module (delete hook for type 'category')
 *
 * @param $args['objectid'] ID of the object (must be the module name here !!)
 * @param $args['extrainfo'] extra information
 * @returns bool
 * @return true on success, false on failure
 * @raise BAD_PARAM, NO_PERMISSION, DATABASE_ERROR
 */
function hitcount_adminapi_deleteall($args)
{
    extract($args);

    // When called via hooks, we should get the real module name from objectid
    // here, because the current module is probably going to be 'modules' !!!
    if (!isset($objectid) || !is_string($objectid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'object ID (= module name)', 'admin', 'deleteall', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return false;
    }

    $modid = pnModGetIDFromName($objectid);
    if (empty($modid)) {
        $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
                    'module ID', 'admin', 'deleteall', 'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                       new SystemException($msg));
        return false;
    }

// TODO: re-evaluate this for hook calls !!
    // Security check - important to do this as early on as possible to
    // avoid potential security holes or just too much wasted processing
    if (!pnSecAuthAction(0, 'Hitcount::', "$objectid::", ACCESS_DELETE)) {
        $msg = pnML('Not authorized to delete #(1) items',
                    'Hitcount');
        pnExceptionSet(PN_USER_EXCEPTION, 'NO_PERMISSION',
                       new SystemException($msg));
        return false;
    }

    list($dbconn) = pnDBGetConn();
    $pntable = pnDBGetTables();
    $hitcounttable = $pntable['hitcount'];

    $sql = "DELETE FROM $hitcounttable
            WHERE pn_moduleid = '" . pnVarPrepForStore($modid) . "'";
    $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() != 0) {
        $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
                    'admin', 'deleteall', 'Hitcount');
        pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
                       new SystemException($msg));
        return false;
    }

    // hmmm, I think we'll skip calling more hooks here... :-)
    //pnModCallHooks('item', 'delete', '', '');

    // Let the calling process know that we have finished successfully
    return true;
}

?>


Directory filter : [ all ] / postnuke_official / html / modules / hitcount [ view in CVS ]

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