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

Source for file pninit.php

Documentation is available at pninit.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  * @copyright (c) 2001, Zikula Development Team
  5.  * @link http://www.zikula.org
  6.  * @version $Id: pninit.php 24342 2008-06-06 12:03:14Z markwest $
  7.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  8.  * @package Zikula_System_Modules
  9.  * @subpackage Blocks
  10.  */
  11.  
  12. /**
  13.  * initialise the blocks module
  14.  *
  15.  * This function is only ever called once during the lifetime of a particular
  16.  * module instance.
  17.  * This function MUST exist in the pninit file for a module
  18.  *
  19.  * @author       Mark West
  20.  * @return       bool       true on success, false otherwise
  21.  */
  22. function blocks_init()
  23. {
  24.     // create blocks table
  25.     // appropriate error message and return
  26.     if (!DBUtil::createTable('blocks')) {
  27.         return false;
  28.     }
  29.  
  30.     // create userblocks table
  31.     if (!DBUtil::createTable('userblocks')) {
  32.         return false;
  33.     }
  34.  
  35.     // create block positions table
  36.     if (!DBUtil::changeTable('block_positions')) {
  37.         return false;
  38.     }
  39.  
  40.     // create block placements table
  41.     if (!DBUtil::changeTable('block_placements')) {
  42.         return false;
  43.     }
  44.  
  45.     // Set a default value for a module variable
  46.     pnModSetVar('Blocks''collapseable'0);
  47.  
  48.     // Initialisation successful
  49.     return true;
  50. }
  51.  
  52. /**
  53.  * upgrade the blocks module from an old version
  54.  *
  55.  * This function can be called multiple times
  56.  * This function MUST exist in the pninit file for a module
  57.  *
  58.  * @author       Mark West
  59.  * @return       bool       true on success, false otherwise
  60.  */
  61. function blocks_upgrade($oldversion)
  62. {
  63.     // update blocks table
  64.     if (!DBUtil::changeTable('blocks')) {
  65.         return false;
  66.     }
  67.     // update userblocks table
  68.     if (!DBUtil::changeTable('userblocks')) {
  69.         return false;
  70.     }
  71.     // update block positions table
  72.     if (!DBUtil::changeTable('block_positions')) {
  73.         return false;
  74.     }
  75.     // update block placements table
  76.     if (!DBUtil::changeTable('block_placements')) {
  77.         return false;
  78.     }
  79.  
  80.  
  81.     // Upgrade dependent on old version number
  82.     switch($oldversion{
  83.         // version 2.2 was supplied with all .76x versions of PN
  84.         case 2.2// upgrade from 76x
  85.             // create the default block positions
  86.             // force load the API since it's not available until the module is activated
  87.             pnModAPILoad('Blocks''admin'true);
  88.             pnModAPIFunc('Blocks''admin''createposition'array('name' => 'left''description' => _BLOCKS_LEFTBLOCKS));
  89.             pnModAPIFunc('Blocks''admin''createposition'array('name' => 'right''description' => _BLOCKS_RIGHTBLOCKS));
  90.             pnModAPIFunc('Blocks''admin''createposition'array('name' => 'center''description' => _BLOCKS_CENTERBLOCKS));
  91.  
  92.             $prefix pnDBGetTablePrefix('blocks');
  93.             $fields array($prefix.'_position',
  94.                             $prefix.'_weight');
  95.             DBUtil::dropColumn('blocks'$fields);
  96.             DBUtil::dropIndex('bid_idx''blocks');
  97.             break;
  98.     }
  99.  
  100.     // Update successful
  101.     return true;
  102. }
  103.  
  104. /**
  105.  * delete the blocks module
  106.  *
  107.  * This function is only ever called once during the lifetime of a particular
  108.  * module instance
  109.  * This function MUST exist in the pninit file for a module
  110.  *
  111.  * Since the blocks module should never be deleted we'all always return false here
  112.  * @author       Mark West
  113.  * @return       bool       false
  114.  */
  115. function blocks_delete()
  116. {
  117.     // Deletion not allowed
  118.     return false;
  119. }
  120.  
  121.  
  122. /**
  123.  * Add default block data for new installs
  124.  * This is called after a complete pn installation since the blocks
  125.  * need to be populated with module id's which are only available
  126.  * once the install has been completed
  127.  *
  128.  */
  129. function blocks_defaultdata()
  130. {
  131.     // create the default block positions - left, right and center for the traditional 3 column layout
  132.     pnModAPILoad('Blocks''admin'true);
  133.     // load language file
  134.     pnModLangLoad('Blocks''init');
  135.  
  136.     // sanity check - truncate existing tables to ensure a clean blocks setup
  137.     DBUtil::truncateTable('blocks');
  138.     DBUtil::truncateTable('block_positions');
  139.     DBUtil::truncateTable('block_placements');
  140.  
  141.     //pnModLoad('Blocks', 'admin', true);
  142.     $left   pnModAPIFunc('Blocks''admin''createposition'array('name' => 'left''description' => _BLOCKS_LEFTBLOCKS));
  143.     $right  pnModAPIFunc('Blocks''admin''createposition'array('name' => 'right''description' => _BLOCKS_RIGHTBLOCKS));
  144.     $center pnModAPIFunc('Blocks''admin''createposition'array('name' => 'center''description' => _BLOCKS_CENTERBLOCKS));
  145.  
  146.     // define an array of the default blocks
  147.     $blocks array();
  148.     // build the menu content
  149.     $lang pnUserGetLang();
  150.     $menucontent array();
  151.     $menucontent['displaymodules''1';
  152.     $menucontent['stylesheet']     'extmenu.css';
  153.     $menucontent['template']       'blocks_block_extmenu.htm';
  154.     $menucontent['blocktitles']    array("$lang=> _BLOCKS_MENU_TITLE);
  155.     // insert the links
  156.     $menucontent['links'][$lang][array('name'   => _BLOCKS_MENU_1LINK,
  157.                                            'url'    => '{homepage}',
  158.                                            'title'  => _BLOCKS_MENU_1TITLE,
  159.                                            'level'  => 0,
  160.                                            'parent' => 0,
  161.                                            'image'  => '',
  162.                                            'active' => '1');
  163.     $menucontent['links'][$lang][array('name'   => _BLOCKS_MENU_2LINK,
  164.                                            'url'    => '{Profile}',
  165.                                            'title'  => _BLOCKS_MENU_2TITLE,
  166.                                            'level'  => 0,
  167.                                            'parent' => 0,
  168.                                            'image'  => '',
  169.                                            'active' => '1');
  170.     $menucontent['links'][$lang][array('name'   => _BLOCKS_MENU_3LINK,
  171.                                            'url'    => '{Admin:adminpanel:admin}',
  172.                                            'title'  => _BLOCKS_MENU_3TITLE,
  173.                                            'level'  => 0,
  174.                                            'parent' => 0,
  175.                                            'image'  => '',
  176.                                            'active' => '1');
  177.     $menucontent['links'][$lang][array('name'   => _BLOCKS_MENU_4LINK,
  178.                                            'url'    => '{Users:logout}',
  179.                                            'title'  => _BLOCKS_MENU_4TITLE,
  180.                                            'level'  => 0,
  181.                                            'parent' => 0,
  182.                                            'image'  => '',
  183.                                            'active' => '1');
  184.     $menucontent serialize($menucontent);
  185.     $blocks[array('bkey' => 'extmenu''collapsable' => 1'defaultstate' => 1'language' => '',
  186.                       'mid' => pnModGetIDFromName('Blocks')'title' => _BLOCKS_MENU_TITLE'content' => $menucontent'positions' => array($left));
  187.     $blocks[array('bkey' => 'thelang''collapsable' => 1'defaultstate' => 1'language' => '',
  188.                       'mid' => pnModGetIDFromName('Blocks')'title' => _BLOCKS_LANG_TITLE'content' => '''positions' => array($left));
  189.     $blocks[array('bkey' => 'login''collapsable' => 1'defaultstate' => 1'language' => '',
  190.                       'mid' => pnModGetIDFromName('Users')'title' => _BLOCKS_LOGIN_TITLE'positions' => array($right));
  191.     $blocks[array('bkey' => 'online''collapsable' => 1'defaultstate' => 1'language' => '',
  192.                       'mid' => pnModGetIDFromName('Users')'title' => _BLOCKS_ONLINE_TITLE'positions' => array($right));
  193.     $blocks[array('bkey' => 'messages''collapsable' => 1'defaultstate' => 1'language' => '',
  194.                       'mid' => pnModGetIDFromName('Admin_Messages')'title' => _BLOCKS_MESSAGES_TITLE'positions' => array($center));
  195.  
  196.     // create each block and then update the block
  197.     // the create creates the initiial block record, the update sets the block placments
  198.     foreach ($blocks as $position => $block{
  199.         $block['bid'pnModAPIFunc('Blocks''admin''create'$block);
  200.         pnModAPIFunc('Blocks''admin''update'$block);
  201.     }
  202.     return;
  203. }
  204.  
  205.  
  206. /**
  207.  * Upgrade for blocks tables data from 0.76x to 0.8+
  208.  *
  209.  * This function is called prior to the system upgrade
  210.  */
  211. {
  212.     // we need to get the blocks table prior to the update otherwise the position field get dropped
  213.     // and we lose the data needed to rewrite any block positions
  214.  
  215.     // get site prefix - the old way....
  216.     $prefix pnConfigGetVar('prefix');
  217.  
  218.     // get the values from the blocks table
  219.     $sql "SELECT pn_bid, pn_position, pn_weight FROM {$prefix}_blocks";
  220.     $result DBUtil::executeSQL($sql);
  221.  
  222.     // format a result array in the correct format for the block placements table
  223.     for (!$result->EOF$result->MoveNext()) {
  224.         list($bid$position$weight$result->fields;
  225.         // manually map the position id
  226.         switch ($position{
  227.             case 'l'$pid 1break;
  228.             case 'r'$pid 2break;
  229.             case 'c'$pid 3break;
  230.         }
  231.         // only add blocks that are in one of the core positions
  232.         if (isset($pid)) {
  233.             $_SESSION['_PNUpgrader']['blocks'][array('pid' => $pid,
  234.                                                          'bid' => $bid,
  235.                                                          'order' => (int)$weight);
  236.             unset($pid);                                                         
  237.         }
  238.     }
  239.     $result->Close();
  240. }
  241.  
  242. /**
  243.  * Upgrade for blocks tables data from 0.76x to 0.8+
  244.  *
  245.  * This function is called after the system upgrade is complete
  246.  */
  247. {
  248.     // now insert the backed up block positions into the placements table
  249.     DBUtil::insertObjectArray($_SESSION['_PNUpgrader']['blocks']'block_placements');
  250.  
  251.     // get site prefix - the old way....
  252.     $prefix pnConfigGetVar('prefix');
  253.  
  254.     // fix some block module id's
  255.     $sqls array();
  256.     $blocksmodid pnModGetIDFromName('Blocks');
  257.     if ($blocksmodid{
  258.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$blocksmodid}  WHERE pn_mid = 0 AND pn_bkey IN ('html','finclude','menu','text','thelang')";
  259.     }
  260.     $usersmodid pnModGetIDFromName('Users');
  261.     if ($usersmodid{
  262.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$usersmodid}   WHERE pn_mid = 0 AND pn_bkey IN ('login','online','user')";
  263.     }
  264.     $pollsmodid pnModGetIDFromName('Polls');
  265.     if ($pollsmodid{
  266.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$pollsmodid}   WHERE pn_mid = 0 AND pn_bkey IN ('poll')";
  267.     }
  268.     $bannersmodid pnModGetIDFromName('Banners');
  269.     if ($bannersmodid{
  270.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$bannersmodid} WHERE pn_mid = 0 AND pn_bkey IN ('banners')";
  271.     }
  272.     $newsmodid pnModGetIDFromName('News');
  273.     if ($newsmodid{
  274.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$newsmodid}    WHERE pn_mid = 0 AND pn_bkey IN ('big','past','stories')";
  275.     }
  276.     $searchmodid pnModGetIDFromName('Search');
  277.     if ($searchmodid{
  278.         $sqls["UPDATE {$prefix}_blocks SET pn_mid = {$searchmodid}  WHERE pn_mid = 0 AND pn_bkey IN ('search')";
  279.     }
  280.  
  281.     foreach ($sqls as $sql{
  282.         DBUtil::executeSQL($sql);
  283.     }
  284. }

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