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

Source for file pnadmin.php

Documentation is available at pnadmin.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: pnadmin.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 Feeds
  11.  */
  12.  
  13. /**
  14.  * the main administration function
  15.  */
  16. function feeds_admin_main()
  17. {
  18.     // Security check
  19.     if (!SecurityUtil::checkPermission'Feeds::Item''::'ACCESS_EDIT)) {
  20.         return LogUtil::registerPermissionError();
  21.     }
  22.  
  23.     // Create output object
  24.     $pnRender pnRender::getInstance('Feeds'false);
  25.  
  26.     // Return the output that has been generated by this function
  27.     return $pnRender->fetch('feeds_admin_main.htm');
  28. }
  29.  
  30. /**
  31.  * add new item
  32.  * This is a standard function that is called whenever an administrator
  33.  * wishes to create a new module item
  34.  */
  35. function feeds_admin_new()
  36. {
  37.     // Security check
  38.     if (!SecurityUtil::checkPermission'Feeds::Item''::'ACCESS_ADD)) {
  39.         return LogUtil::registerPermissionError();
  40.     }
  41.  
  42.     // load the categories system
  43.     if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  44.         pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  45.     }
  46.     $categories CategoryRegistryUtil::getRegisteredModuleCategories ('Feeds''feeds');
  47.  
  48.     // Create output object
  49.     $pnRender pnRender::getInstance('Feeds'false);
  50.         
  51.     $pnRender->assign('categories'$categories);
  52.  
  53.     $pnRender->assign('enablecategorization'pnModGetVar('Feeds''enablecategorization'));
  54.  
  55.     // Return the output that has been generated by this function
  56.     return $pnRender->fetch('feeds_admin_new.htm');
  57. }
  58.  
  59. /**
  60.  * This is a standard function that is called with the results of the
  61.  * form supplied by feeds_admin_new() to create a new item
  62.  * @param 'feedname' the name of the item to be created
  63.  * @param 'url' the url of the item to be created
  64.  */
  65. function feeds_admin_create($args)
  66. {
  67.     // Get parameters from whatever input we need
  68.     $feed FormUtil::getPassedValue('feed'isset($args['feed']$args['feed'null'POST');
  69.  
  70.     // Confirm authorisation code
  71.     if (!SecurityUtil::confirmAuthKey()) {
  72.         return LogUtil::registerAuthidError (pnModURL('Feeds''admin''view'));
  73.     }
  74.  
  75.     // Notable by its absence there is no security check here.
  76.  
  77.     // Create the feed
  78.     $fid pnModAPIFunc('Feeds''admin''create'$feed);
  79.  
  80.     if ($fid != false{
  81.         // Success
  82.     }
  83.  
  84.     return pnRedirect(pnModURL('Feeds''admin''view'));
  85. }
  86.  
  87. /**
  88.  * modify an item
  89.  * This is a standard function that is called whenever an administrator
  90.  * wishes to modify a current module item
  91.  * @param 'fid' the id of the item to be modified
  92.  */
  93. function feeds_admin_modify($args)
  94. {
  95.     $fid FormUtil::getPassedValue('fid'isset($args['fid']$args['fid'null'GET');
  96.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'GET');
  97.  
  98.     if (!empty($objectid)) {
  99.         $fid $objectid;
  100.     }
  101.  
  102.     // Get the feeds feed
  103.     $item pnModAPIFunc('Feeds''user''get'array('fid' => $fid));
  104.  
  105.     if ($item == false{
  106.         return LogUtil::registerError (_NOSUCHITEM404);
  107.     }
  108.  
  109.     // Security check
  110.     if (!SecurityUtil::checkPermission'Feeds::Item'"$item[name]::$fid"ACCESS_EDIT)) {
  111.         return LogUtil::registerPermissionError();
  112.     }
  113.  
  114.     // load the categories system
  115.     if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  116.         pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  117.     }
  118.     $categories CategoryRegistryUtil::getRegisteredModuleCategories ('Feeds''feeds');
  119.  
  120.     // Create output object
  121.     $pnRender pnRender::getInstance('Feeds'false);
  122.  
  123.     $pnRender->assign('categories'$categories);
  124.  
  125.     // Assign the item
  126.     $pnRender->assign($item);
  127.  
  128.     $pnRender->assign('enablecategorization'pnModGetVar('Feeds''enablecategorization'));
  129.  
  130.     // Return the output that has been generated by this function
  131.     return $pnRender->fetch('feeds_admin_modify.htm');
  132. }
  133.  
  134. /**
  135.  * This is a standard function that is called with the results of the
  136.  * form supplied by RSS_admin_modify() to update a current item
  137.  * @param 'fid' the id of the item to be updated
  138.  * @param 'feedname' the name of the item to be updated
  139.  * @param 'url' the url of the item to be updated
  140.  */
  141. function feeds_admin_update($args)
  142. {
  143.     $feed FormUtil::getPassedValue('feed'isset($args['feed']$args['feed'null'POST');
  144.     if (!empty($feed['objectid'])) {
  145.         $feed['fid'$feed['objectid'];
  146.     }
  147.  
  148.     // Confirm authorisation code
  149.     if (!SecurityUtil::confirmAuthKey()) {
  150.         return LogUtil::registerAuthidError (pnModURL('Feeds''admin''view'));
  151.     }
  152.  
  153.     // Notable by its absence there is no security check here
  154.  
  155.     // Update the feeds feed
  156.     if (pnModAPIFunc('Feeds''admin''update'$feed)) {
  157.         // Success
  158.     }
  159.  
  160.     return pnRedirect(pnModURL('Feeds''admin''view'));
  161. }
  162.  
  163. /**
  164.  * delete item
  165.  * This is a standard function that is called whenever an administrator
  166.  * wishes to delete a current module item.  Note that this function is
  167.  * the equivalent of both of the modify() and update() functions above as
  168.  * it both creates a form and processes its output.  This is fine for
  169.  * simpler functions, but for more complex operations such as creation and
  170.  * modification it is generally easier to separate them into separate
  171.  * functions.  There is no requirement in the Zikula MDG to do one or the
  172.  * other, so either or both can be used as seen appropriate by the module
  173.  * developer
  174.  * @param 'fid' the id of the item to be deleted
  175.  * @param 'confirmation' confirmation that this item can be deleted
  176.  */
  177. function feeds_admin_delete($args)
  178. {
  179.     $fid FormUtil::getPassedValue('fid'isset($args['fid']$args['fid'null'REQUEST');
  180.     $objectid FormUtil::getPassedValue('objectid'isset($args['objectid']$args['objectid'null'REQUEST');
  181.     $confirmation FormUtil::getPassedValue('confirmation'null'POST');
  182.     if (!empty($objectid)) {
  183.         $fid $objectid;
  184.     }
  185.  
  186.     // Get the feed
  187.     $item pnModAPIFunc('Feeds''user''get'array('fid' => $fid));
  188.  
  189.     if ($item == false{
  190.         return LogUtil::registerError (_NOSUCHITEM404);
  191.     }
  192.  
  193.     // Security check
  194.     if (!SecurityUtil::checkPermission'Feeds::Item'"$item[name]::$fid"ACCESS_DELETE)) {
  195.         return LogUtil::registerPermissionError();
  196.     }
  197.  
  198.     // Check for confirmation.
  199.     if (empty($confirmation)) {
  200.         // No confirmation yet
  201.  
  202.         // Create output object
  203.         $pnRender pnRender::getInstance('Feeds'false);
  204.  
  205.         // assign the item id.
  206.         $pnRender->assign('fid'$fid);
  207.  
  208.         // Return the output that has been generated by this function
  209.         return $pnRender->fetch('feeds_admin_delete.htm');
  210.     }
  211.  
  212.     // If we get here it means that the user has confirmed the action
  213.  
  214.     // Confirm authorisation code
  215.     if (!SecurityUtil::confirmAuthKey()) {
  216.         return LogUtil::registerAuthidError (pnModURL('Feeds''admin''view'));
  217.     }
  218.  
  219.     // Delete the feed
  220.     if (pnModAPIFunc('Feeds''admin''delete',
  221.                      array('fid' => $fid))) {
  222.         // Success
  223.     }
  224.  
  225.     return pnRedirect(pnModURL('Feeds''admin''view'));
  226. }
  227.  
  228. /**
  229.  * view items
  230.  */
  231. function feeds_admin_view($args)
  232. {
  233.     // Security check
  234.     if (!SecurityUtil::checkPermission'Feeds::''::'ACCESS_EDIT)) {
  235.         return LogUtil::registerPermissionError();
  236.     }
  237.  
  238.     $startnum FormUtil::getPassedValue('startnum'isset($args['startnum']$args['startnum'null'GET');
  239.     $property FormUtil::getPassedValue('feeds_property'isset($args['feeds_property']$args['feeds_property'null'POST');
  240.     $category FormUtil::getPassedValue("feeds_{$property}_category"isset($args["feeds_{$property}_category"]$args["feeds_{$property}_category"null'POST');
  241.     $clear    FormUtil::getPassedValue('clear'false'POST');
  242.     if ($clear{
  243.         $property null;
  244.         $category null;
  245.     }
  246.  
  247.     // get module vars for later use
  248.     $modvars pnModGetVar('Feeds');
  249.  
  250.     if ($modvars['enablecategorization']{
  251.         // load the category registry util
  252.         if (!($class Loader::loadClass('CategoryRegistryUtil'))) {
  253.             pn_exit (pnML('_UNABLETOLOADCLASS'array('s' => 'CategoryRegistryUtil')));
  254.         }
  255.         $catregistry  CategoryRegistryUtil::getRegisteredModuleCategories('Feeds''feeds');
  256.         $properties array_keys($catregistry);
  257.  
  258.         // Validate and build the category filter - mateo
  259.         if (!empty($property&& in_array($property$properties&& !empty($category)) {
  260.             $catFilter array($property => $category);
  261.         }
  262.  
  263.         // Assign a default property - mateo
  264.         if (empty($property|| !in_array($property$properties)) {
  265.             $property $properties[0];
  266.         }
  267.  
  268.         // plan ahead for ML features
  269.         $propArray array();
  270.         foreach ($properties as $prop{
  271.             $propArray[$prop$prop;
  272.         }
  273.     }
  274.  
  275.     // Get all the feeds
  276.     $items pnModAPIFunc('Feeds''user''getall',
  277.                           array('startnum' => $startnum,
  278.                                 'numitems' => $modvars['itemsperpage'],
  279.                                 'order'    => 'fid',
  280.                                 'category' => isset($catFilter$catFilter null,
  281.                                 'catregistry'  => isset($catregistry$catregistry null));
  282.  
  283.     $feedsitems array();
  284.     foreach ($items as $item{
  285.         if (SecurityUtil::checkPermission('Feeds::'"$item[name]::$item[fid]"ACCESS_READ)) {
  286.             // Options for the item
  287.             $options array();
  288.             if (SecurityUtil::checkPermission'Feeds::'"$item[name]::$item[fid]"ACCESS_EDIT)) {
  289.                 $options[array('url' => pnModURL('Feeds''admin''modify'array('fid' => $item['fid'])),
  290.                                    'image' => 'xedit.gif',
  291.                                    'title' => _EDIT);
  292.                 if (SecurityUtil::checkPermission'Feeds::'"$item[name]::$item[fid]"ACCESS_DELETE)) {
  293.                     $options[array('url' => pnModURL('Feeds''admin''delete'array('fid' => $item['fid'])),
  294.                                        'image' => '14_layer_deletelayer.gif',
  295.                                        'title' => _DELETE);
  296.                 }
  297.             }
  298.             $item['options'$options;
  299.             $feedsitems[$item;
  300.         }
  301.     }
  302.  
  303.     // Create output object
  304.     $pnRender pnRender::getInstance('Feeds'false);
  305.  
  306.     // Assign the items and modvars to the template
  307.     $pnRender->assign('feedsitems'$feedsitems);
  308.     $pnRender->assign($modvars);
  309.  
  310.     // Assign the default language
  311.     $pnRender->assign('lang'pnUserGetLang());
  312.  
  313.     // Assign the categories information if enabled
  314.     if ($modvars['enablecategorization']{
  315.         $pnRender->assign('catregistry'$catregistry);
  316.         $pnRender->assign('numproperties'count($propArray));
  317.         $pnRender->assign('properties'$propArray);
  318.         $pnRender->assign('property'$property);
  319.         $pnRender->assign("category"$category);
  320.     }
  321.  
  322.     // Assign the values for the smarty plugin to produce a pager
  323.     $pnRender->assign('pager'array('numitems' => pnModAPIFunc('Feeds''user''countitems'array('category' => isset($catFilter$catFilter null)),
  324.                                      'itemsperpage' => $modvars['itemsperpage']));
  325.  
  326.     // Return the output that has been generated by this function
  327.     return $pnRender->fetch('feeds_admin_view.htm');
  328. }
  329.  
  330. /**
  331.  * This is a standard function to modify the configuration parameters of the
  332.  * module
  333.  */
  334. {
  335.     // Security check
  336.     if (!SecurityUtil::checkPermission'Feeds::''::'ACCESS_ADMIN)) {
  337.         return LogUtil::registerPermissionError();
  338.     }
  339.  
  340.     // Create output object
  341.     $pnRender pnRender::getInstance('Feeds'false);
  342.  
  343.     // Assign all module vars
  344.     $pnRender->assign(pnModGetVar('Feeds'));
  345.  
  346.     // Return the output that has been generated by this function
  347.     return $pnRender->fetch('feeds_admin_modifyconfig.htm');
  348. }
  349.  
  350. /**
  351.  * This is a standard function to update the configuration parameters of the
  352.  * module given the information passed back by the modification form
  353.  */
  354. {
  355.     // Security check
  356.     if (!SecurityUtil::checkPermission'Feeds::''::'ACCESS_ADMIN)) {
  357.         return LogUtil::registerPermissionError();
  358.     }
  359.  
  360.     // Confirm authorisation code
  361.     if (!SecurityUtil::confirmAuthKey()) {
  362.         return LogUtil::registerAuthidError (pnModURL('Feeds''admin''view'));
  363.     }
  364.  
  365.     // Update module variables
  366.     $enablecategorization = (bool)FormUtil::getPassedValue('enablecategorization'false'POST');
  367.     pnModSetVar('Feeds''enablecategorization'$enablecategorization);
  368.  
  369.     $bold = (bool)FormUtil::getPassedValue('bold'0'POST');
  370.     pnModSetVar('Feeds''bold'$bold);
  371.  
  372.     $openinnewwindow = (bool)FormUtil::getPassedValue('openinnewwindow'0'POST');
  373.     pnModSetVar('Feeds''openinnewwindow'$openinnewwindow);
  374.  
  375.     $itemsperpage = (int)FormUtil::getPassedValue('itemsperpage'10'POST');
  376.     pnModSetVar('Feeds''itemsperpage'$itemsperpage);
  377.  
  378.     $cacheinterval = (int)FormUtil::getPassedValue('cacheinterval'180'POST');
  379.     pnModSetVar('Feeds''cacheinterval'$cacheinterval);
  380.  
  381.     $cachedirectory = (string)FormUtil::getPassedValue('cachedirectory''feeds''POST');
  382.     pnModSetVar('Feeds''cachedirectory'$cachedirectory);
  383.  
  384.     // Let any other modules know that the modules configuration has been updated
  385.     pnModCallHooks('module','updateconfig','Feeds'array('module' => 'Feeds'));
  386.  
  387.     // the module configuration has been updated successfuly
  388.  
  389.     return pnRedirect(pnModURL('Feeds''admin''view'));
  390. }

Documentation generated on Fri, 18 Jul 2008 21:50:47 +0200 by phpDocumentor 1.4.1