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

Source for file pninit.php

Documentation is available at pninit.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: pninit.php 24444 2008-07-04 11:03:47Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Value_Addons
  10.  * @subpackage Feeds
  11.  */
  12.  
  13. /**
  14.  * initialise the RSS module
  15.  * This function is only ever called once during the lifetime of a particular
  16.  * module instance
  17.  */
  18. function feeds_init()
  19. {
  20.     // create table
  21.     if (!DBUtil::createTable('feeds')) {
  22.         return false;
  23.     }
  24.  
  25.     // Set up an initial value for a module variables.
  26.     pnModSetVar('Feeds''bold'0);
  27.     pnModSetVar('Feeds''openinnewwindow'0);
  28.     pnModSetVar('Feeds''itemsperpage'10);
  29.     pnModSetVar('Feeds''cachedirectory''feeds');
  30.     pnModSetVar('Feeds''cacheinterval'180);
  31.     pnModSetVar('Feeds''enablecategorization'true);
  32.  
  33.     // create cache directory
  34.     if (!is_dir(pnConfigGetVar('temp').'/feeds')) {
  35.          mkdir(pnConfigGetVar('temp').'/feeds');
  36.          // add index.html file
  37.         fclose(fopen(pnConfigGetVar('temp''/feeds/index.html''w'));
  38.     }
  39.  
  40.     // create our default category
  41.     if (!_feeds_createdefaultcategory()) {
  42.         return LogUtil::registerError (_CREATEFAILED);
  43.     }
  44.     
  45.     // Initialisation successful
  46.     return true;
  47. }
  48.  
  49. /**
  50.  * upgrade the RSS module from an old version
  51.  * This function can be called multiple times
  52.  */
  53. function feeds_upgrade($oldversion)
  54. {
  55.     switch($oldversion{
  56.         // version 1.0 shipped with PN .7x
  57.         case 1.0:
  58.             // rename table if upgrading from an earlier version
  59.             if (in_array(DBUtil::getLimitedTablename('RSS')DBUtil::MetaTables())) {
  60.                 DBUtil::renameTable('RSS''feeds');
  61.             }
  62.             if (in_array(DBUtil::getLimitedTablename('rss')DBUtil::MetaTables())) {
  63.                 DBUtil::renameTable('rss''feeds');
  64.             }
  65.  
  66.             // create cache directory
  67.             if (!is_dir(pnConfigGetVar('temp').'/feeds')) {
  68.                  mkdir(pnConfigGetVar('temp').'/feeds');
  69.                  // add index.html file
  70.                 fclose(fopen(pnConfigGetVar('temp''/feeds/index.html''w'));
  71.             }
  72.  
  73.             // migrate module vars
  74.             $tables pnDBGetTables();
  75.             $sql  "UPDATE $tables[module_vars] SET pn_modname = 'Feeds' WHERE pn_modname = 'RSS'";
  76.             if (!DBUtil::executeSQL($sql)) {
  77.                 return LogUtil::registerError (_UPDATETABLEFAILED);
  78.             }
  79.  
  80.             // create our default category
  81.             pnModSetVar('Feeds''enablecategorization'true);
  82.             if (!_feeds_createdefaultcategory()) {
  83.                 return LogUtil::registerError (_UPDATEFAILED);
  84.             }
  85.  
  86.             // update table
  87.             if (!DBUtil::changeTable('feeds')) {
  88.                 return false;
  89.             }
  90.  
  91.             // update the permalinks
  92.             $shorturlsep pnConfigGetVar('shorturlsseparator');            
  93.             $sql  "UPDATE $tables[feeds] SET pn_urltitle = REPLACE(pn_name, ' ', '{$shorturlsep}')";
  94.             if (!DBUtil::executeSQL($sql)) {
  95.                 return LogUtil::registerError (_UPDATETABLEFAILED);
  96.             }
  97.             return Feeds_upgrade(2.1);
  98.             break;
  99.     }
  100.  
  101.     // Update successful
  102.     return true;
  103. }
  104.  
  105. /**
  106.  * delete the RSS module
  107.  * This function is only ever called once during the lifetime of a particular
  108.  * module instance
  109.  */
  110. function feeds_delete()
  111. {
  112.     if (!DBUtil::dropTable('feeds')) {
  113.         return false;
  114.     }
  115.  
  116.     // remove cache directory incl. content
  117.     if (is_dir(pnConfigGetVar('temp').'/feeds')) {
  118.         Loader::loadClass('FileUtil');
  119.         FileUtil::deldir(pnConfigGetVar('temp').'/feeds');
  120.     }
  121.  
  122.     // Delete any module variables
  123.     pnModDelVar('Feeds');
  124.  
  125.     // Deletion successful
  126.     return true;
  127. }
  128.  
  129. /**
  130.  * create placeholder for categories
  131.  */
  132. function _feeds_createdefaultcategory($regpath '/__SYSTEM__/Modules/Global')
  133. {
  134.     // load necessary classes
  135.     Loader::loadClass('CategoryUtil');
  136.     Loader::loadClassFromModule('Categories''Category');
  137.     Loader::loadClassFromModule('Categories''CategoryRegistry');
  138.  
  139.     // get the language file
  140.     $lang pnUserGetLang();
  141.  
  142.     // get the category path for which we're going to insert our place holder category
  143.     $rootcat CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
  144.     $fCat    CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Feeds');
  145.  
  146.     if (!$fCat{
  147.         // create placeholder for all the module categories
  148.         $cat new PNCategory ();
  149.         $cat->setDataField('parent_id'$rootcat['id']);
  150.         $cat->setDataField('name''Feeds');
  151.         $cat->setDataField('display_name'array($lang => _FEEDS_DISPLAYNAME));
  152.         $cat->setDataField('display_desc'array($lang => _FEEDS_DESCRIPTION));
  153.         if (!$cat->validate('admin')) {
  154.             return false;
  155.         }
  156.         $cat->insert();
  157.         $cat->update();
  158.     }
  159.  
  160.     // get the category path for which the feeds will be classified
  161.     $rootcat CategoryUtil::getCategoryByPath($regpath);
  162.     if ($rootcat{
  163.         // create an entry in the categories registry
  164.         $registry new PNCategoryRegistry();
  165.         $registry->setDataField('modname''Feeds');
  166.         $registry->setDataField('table''feeds');
  167.         $registry->setDataField('property''Main');
  168.         $registry->setDataField('category_id'$rootcat['id']);
  169.         $registry->insert();
  170.     else {
  171.         return false;
  172.     }
  173.  
  174.     return true;
  175. }

Documentation generated on Fri, 18 Jul 2008 21:53:24 +0200 by phpDocumentor 1.4.1