Zikula_Value_Addons
[ class tree: Zikula_Value_Addons ] [ index: Zikula_Value_Addons ] [ all elements ]

Source for file pnadminapi.php

Documentation is available at pnadminapi.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2002, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnadminapi.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Value_Addons
  10.  * @subpackage HitCount
  11.  */
  12.  
  13. /**
  14.  * create a new hitcount item (= create hook for type 'item')
  15.  *
  16.  * @param $args['objectid'] ID of the object
  17.  * @param $args['extrainfo'] extra information
  18.  * @param $args['modname'] name of the calling module (not used in hook calls)
  19.  * @param $args['hits'] optional hit count for the item (not used in hook calls)
  20.  * @return mixed hitcount item ID on success, void on failure
  21.  */
  22. function hitcount_adminapi_create($args)
  23. {
  24.     if (!isset($args['objectid']|| !is_numeric($args['objectid'])) {
  25.         return LogUtil::registerError (_MODARGSERROR);
  26.     }
  27.  
  28.     // When called via hooks, modname wil be empty, but we get it from the
  29.     // current module
  30.     if (empty($args['modname'])) {
  31.         $args['modname'pnModGetName();
  32.     }
  33.     $modid pnModGetIDFromName($args['modname']);
  34.     if (empty($modid)) {
  35.         return LogUtil::registerError (_MODARGSERROR);
  36.     }
  37.  
  38.     // TODO: re-evaluate this for hook calls !!
  39.     // Security check - important to do this as early on as possible to
  40.     // avoid potential security holes or just too much wasted processing
  41.     if (!SecurityUtil::checkPermission'Hitcount::'"$args[modname]::$args[objectid]"ACCESS_READ)) {
  42.         return LogUtil::registerPermissionError();
  43.     }
  44.  
  45.     // Create new hitcount
  46.     if (!isset($args['hits']|| !is_numeric($args['hits'])) {
  47.          $args['hits'0;
  48.     }
  49.  
  50.     $hitcount array();
  51.     $hitcount['moduleid'= (int)$modid;
  52.     $hitcount['itemid']   = (int)$args['objectid'];
  53.     $hitcount['hits']     = (int)$args['hits'];
  54.     $res DBUtil::insertObject ($hitcount'hitcount''hitcountid');
  55.     if ($res === false{
  56.         return LogUtil::registerError (_CREATEFAILED);
  57.     }
  58.  
  59.     // hmmm, I think we'll skip calling more hooks here... :-)
  60.     //pnModCallHooks('item', 'create', $hcid, 'hitcountid');
  61.  
  62.     // Return the id of the newly created item to the calling process
  63.     // (not that this will be of any used when called via hooks, but
  64.     // who knows where else this might be used)
  65.     return $hitcount['hitcountid'];
  66. }
  67.  
  68. /**
  69.  * delete a hitcount item (delete hook for type 'item')
  70.  *
  71.  * @param $args['objectid'] ID of the object
  72.  * @param $args['extrainfo'] extra information
  73.  * @param $args['modname'] name of the calling module (not used in hook calls)
  74.  * @return bool true on success, false on failure
  75.  */
  76. function hitcount_adminapi_delete($args)
  77. {
  78.     if (!isset($args['objectid']|| !is_numeric($args['objectid'])) {
  79.         return LogUtil::registerError (_MODARGSERROR);
  80.     }
  81.  
  82.     // When called via hooks, modname wil be empty, but we get it from the
  83.     // current module
  84.     if (empty($args['modname'])) {
  85.         $args['modname'pnModGetName();
  86.     }
  87.     $modid pnModGetIDFromName($args['modname']);
  88.     if (empty($modid)) {
  89.         return LogUtil::registerError (_MODARGSERROR);
  90.     }
  91.  
  92.     // TODO: re-evaluate this for hook calls !!
  93.     // Security check - important to do this as early on as possible to
  94.     // avoid potential security holes or just too much wasted processing
  95.     if (!SecurityUtil::checkPermission'Hitcount::'"$args[modname]::$args[objectid]"ACCESS_DELETE)) {
  96.         return LogUtil::registerPermissionError();
  97.     }
  98.  
  99.     $where "WHERE pn_moduleid = '" . (int)DataUtil::formatForStore($modid"'
  100.                 AND pn_itemid = '" . (int)DataUtil::formatForStore($args['objectid']"'";
  101.     $res DBUtil::deleteWhere ('hitcount'$where);
  102.     if ($res === false{
  103.         return LogUtil::registerError (_DELETEFAILED);
  104.     }
  105.  
  106.     // hmmm, I think we'll skip calling more hooks here... :-)
  107.     //pnModCallHooks('item', 'delete', $exid, '');
  108.  
  109.     // Let the calling process know that we have finished successfully
  110.     return true;
  111. }
  112.  
  113. /**
  114.  * update a hitcount item (used by display hook hitcount_user_display)
  115.  *
  116.  * @param $args['modname'] name of the calling module (see _user_display)
  117.  * @param $args['objectid'] ID of the object
  118.  * @param $args['extrainfo'] extra information (unused here)
  119.  * @param $args['hits'] (optional) hit count for the item
  120.  * @return mixed the new hitcount for this item, or void on failure
  121.  */
  122. function hitcount_adminapi_update($args)
  123. {
  124.     if (!isset($args['objectid']|| !is_numeric($args['objectid'])) {
  125.         return LogUtil::registerError (_MODARGSERROR);
  126.     }
  127.  
  128.     // When called via hooks, modname wil be empty, but we get it from the
  129.     // current module
  130.     if (empty($args['modname'])) {
  131.         $args['modname'pnModGetName();
  132.     }
  133.     $modid pnModGetIDFromName($args['modname']);
  134.     if (empty($modid)) {
  135.         return LogUtil::registerError (_MODARGSERROR);
  136.     }
  137.  
  138.     // TODO: re-evaluate this for hook calls !!
  139.     // Security check - important to do this as early on as possible to
  140.     // avoid potential security holes or just too much wasted processing
  141.     if (!SecurityUtil::checkPermission'Hitcount::'"$args[modname]::$args[objectid]"ACCESS_READ)) {
  142.         return LogUtil::registerPermissionError();
  143.     }
  144.  
  145.     // get current hit count
  146.     $result pnModAPIFunc('hitcount''user''get',
  147.                            array('objectid' => $args['objectid'],
  148.                                  'modname' => $args['modname']));
  149.  
  150.     // create the item if necessary
  151.     if (!$result{
  152.         $hcid pnModAPIFunc('hitcount','admin','create',
  153.                              array('objectid' => $args['objectid'],
  154.                                    'modname' => $args['modname']));
  155.         if (!isset($hcid)) {
  156.             return// throw back whatever it was that failed
  157.         }
  158.         $oldhits 0;
  159.     else {
  160.         $oldhits $result['hits'];
  161.     }
  162.  
  163.     $pntable pnDBGetTables();
  164.     $hitcounttable $pntable['hitcount'];
  165.  
  166.     // set to the new hit count
  167.     if (!empty($args['hits']&& is_numeric($args['hits'])) {
  168.         $sql "UPDATE $hitcounttable
  169.                 SET pn_hits = '. (int)DataUtil::formatForStore($args['hits']"'
  170.                 WHERE pn_moduleid = '" . (int)DataUtil::formatForStore($modid"'
  171.                   AND pn_itemid = '" . (int)DataUtil::formatForStore($args['objectid']"'";
  172.     else {
  173.         $sql "UPDATE $hitcounttable
  174.                 SET pn_hits = pn_hits + 1
  175.                 WHERE pn_moduleid = '. (int)DataUtil::formatForStore($modid"'
  176.                   AND pn_itemid = '" . (int)DataUtil::formatForStore($args['objectid']"'";
  177.         $args['hits'$oldhits 1;
  178.     }
  179.     $res DBUtil::executeSQL ($sql);
  180.     if ($res === false{
  181.         return LogUtil::registerError (_CREATEFAILED);
  182.     }
  183.  
  184.     // Return the new hitcount (give or take a few other hits in the meantime)
  185.     return $args['hits'];
  186. }
  187.  
  188. /**
  189.  * clean up hits for a removed module
  190.  *
  191.  * @param    $args['extrainfo']   array extrainfo array
  192.  * @return   array extrainfo array
  193.  */
  194. function HitCount_adminapi_remove($args)
  195. {
  196.     // optional arguments
  197.     if (!isset($args['extrainfo'])) {
  198.         $args['extrainfo'array();
  199.     }
  200.  
  201.     // When called via hooks, the module name may be empty, so we get it from
  202.     // the current module
  203.     if (empty($args['extrainfo']['module'])) {
  204.         $modname pnModGetName();
  205.     else {
  206.         $modname $args['extrainfo']['module'];
  207.     }
  208.  
  209.     // Database information
  210.     $dbconn pnDBGetConn(true);
  211.     $pntable pnDBGetTables();
  212.     $hitcounttable $pntable['hitcount'];
  213.  
  214.     // Get items
  215.     $res DBUtil::deleteObjectByID ('hitcount'pnModGetIDFromName($modname)'moduleid');
  216.     if ($res === false{
  217.         return LogUtil::registerError (_DELETEFAILED);
  218.     }
  219.  
  220.     return $args['extrainfo'];
  221. }

Documentation generated on Fri, 18 Jul 2008 21:51:40 +0200 by phpDocumentor 1.4.1