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

Source for file extmenu.php

Documentation is available at extmenu.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  * @copyright (c) 2001, Zikula Development Team
  5.  * @link http://www.zikula.org
  6.  * @version $Id: extmenu.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.  * @author Frank Schummertz [landseer]
  11.  */
  12.  
  13. /**
  14.  * initialise block
  15.  *
  16.  * @author       The Zikula Development Team
  17.  */
  18. {
  19.     // Security
  20.     pnSecAddSchema('ExtendedMenublock::''Block ID:Link ID:');
  21. }
  22.  
  23.  
  24. /**
  25.  * get information on block
  26.  *
  27.  * @author       The Zikula Development Team
  28.  * @return       array       The block information
  29.  */
  30. {
  31.     return array('text_type' => 'Extended Menu',
  32.                  'module' => 'Blocks',
  33.                  'text_type_long' => 'Extended Menu block',
  34.                  'allow_multiple' => true,
  35.                  'form_content' => false,
  36.                  'form_refresh' => false,
  37.                  'show_preview' => true,
  38.                  'admin_tableless' => true);
  39. }
  40.  
  41. /**
  42.  * display block
  43.  *
  44.  * @author       The Zikula Development Team
  45.  * @param        array       $blockinfo     a blockinfo structure
  46.  * @return       output      the rendered bock
  47.  */
  48. function Blocks_extmenublock_display($blockinfo)
  49. {
  50.     // security check
  51.     if (!Securityutil::checkPermission('ExtendedMenublock::'$blockinfo['bid''::'ACCESS_READ)) {
  52.         return;
  53.     }
  54.  
  55.     // Create output object
  56.     $pnRender pnRender::getInstance('Blocks');
  57.  
  58.     // Set the cache id
  59.     $pnRender->cache_id $blockinfo['bid'].':'.pnUserGetVar('uid');
  60.  
  61.     // Break out options from our content field
  62.     $vars pnBlockVarsFromContent($blockinfo['content']);
  63.  
  64.     // template to use
  65.     if (empty($vars['template'])) {
  66.         $vars['template''blocks_block_extmenu.htm';
  67.     }
  68.     // template to use
  69.     if (empty($vars['stylesheet'])) {
  70.         $vars['stylesheet''extmenu.css';
  71.     }
  72.  
  73.     // check out if the contents are cached.
  74.     if ($pnRender->is_cached($vars['template'])) {
  75.         // Populate block info and pass to theme
  76.         $blockinfo['content'$pnRender->fetch($vars['template']);
  77.         return pnBlockThemeBlock($blockinfo);
  78.     }
  79.  
  80.     // create default block variables
  81.     if (!isset($vars['blocktitles'])) {
  82.         $vars['blocktitles'array();
  83.     }
  84.     if (!isset($vars['links'])) {
  85.         $vars['links'array();
  86.     }
  87.     if (!isset($vars['stylesheet'])) {
  88.         $vars['stylesheet''';
  89.     }
  90.     if (!isset($vars['menuid'])) {
  91.         $vars['menuid'0;
  92.     }
  93.  
  94.     // get language and default to eng
  95.     $thislang pnUserGetLang();
  96.     if (!array_key_exists($thislang$vars['links'])) {
  97.         $thislang 'eng';
  98.     }
  99.  
  100.     // block title: copy the ml blocktitle to the original block title
  101.     if (array_key_exists($thislang$vars['blocktitles'])) {
  102.         $blockinfo['title'$vars['blocktitles'][$thislang];
  103.     }
  104.  
  105.     // Content
  106.     $menuitems =array();
  107.     if (!empty($vars['links'][$thislang])) {
  108.         foreach ($vars['links'][$thislangas $linkid => $link{
  109.             if (($link['active']==1&& SecurityUtil::checkPermission('ExtendedMenublock::'$blockinfo['bid'':' $linkid ':'ACCESS_READ)) {
  110.                 $link['url'buildURL($link['url']);
  111.                 // check for multiple options in image
  112.                 extmenu_check_image($link);
  113.                 $menuitems[$link;
  114.             }
  115.         }
  116.     }
  117.  
  118.     // Modules
  119.     if (!empty($vars['displaymodules'])) {
  120.         $mods pnModGetUserMods();
  121.  
  122.         // Separate from current content, if any
  123.         if (count($menuitems0{
  124.            $menuitems[array('name'   => '&nbsp;',
  125.                                 'url'    => '',
  126.                                 'title'  => '',
  127.                                 'level'  => 0,
  128.                                 'parent' => 0,
  129.                                 'image'  => ''
  130.                                 );
  131.         }
  132.  
  133.         foreach($mods as $mod{
  134.             // prepare image
  135.             
  136.             if (SecurityUtil::checkPermission("$mod[name]::"'::'ACCESS_OVERVIEW)) {
  137.                 switch($mod['type']{
  138.                     case 1:
  139.                         $menuitems[array('name'   => $mod['displayname'],
  140.                                              'url'    => pnConfigGetVar('entrypoint''index.php''?name=' DataUtil::formatForDisplay($mod['directory']),
  141.                                              'title'  => $mod['description'],
  142.                                              'level'  => 0,
  143.                                              'parent' => 0,
  144.                                              'image'  => ''
  145.                                              );
  146.                         break;
  147.                     case 2:
  148.                     case 3:
  149.                         $menuitems[array('name'   => $mod['displayname'],
  150.                                              'url'    => DataUtil::formatForDisplay(pnModURL($mod['name']'user''main')),
  151.                                              'title'  => $mod['description'],
  152.                                              'level'  => 0,
  153.                                              'parent' => 0,
  154.                                              'image'  => ''
  155.                                              );
  156.                         break;
  157.                 }
  158.             }
  159.         }
  160.     }
  161.  
  162.     // check for any empty result set
  163.     if (empty($menuitems)) {
  164.         return;
  165.     }
  166.  
  167.     $currenturi urlencode(str_replace(pnGetBaseURI('/'''pnGetCurrentURI()));
  168.  
  169.     // assign the items
  170.     $pnRender->assign('menuitems'$menuitems);
  171.     $pnRender->assign('blockinfo'$blockinfo);
  172.     $pnRender->assign('currenturi'$currenturi);
  173.     $pnRender->assign('access_edit'Securityutil::checkPermission('ExtendedMenublock::'$blockinfo['bid''::'ACCESS_EDIT));
  174.  
  175.     // get the block content
  176.     $blockinfo['content'$pnRender->fetch($vars['template']);
  177.  
  178.     // add the stylesheet to the header
  179.     PageUtil::addVar('stylesheet'ThemeUtil::getModuleStylesheet('Blocks'$vars['stylesheet']));
  180.  
  181.     // pass the block array back to the theme for display
  182.     return pnBlockThemeBlock($blockinfo);
  183. }
  184.  
  185. /**
  186.  * do a simple check .. to see if the current URL is the menu item
  187.  *
  188.  * @param none 
  189.  * @return boolean 
  190.  */
  191. function is_recent_page($url)
  192. {
  193.     if (!empty($url)) {
  194.         $uri pnGetCurrentURI();
  195.         if (is_integer(strpos($uri$url))) {
  196.             return true;
  197.         }
  198.     }
  199.     return false;
  200. }
  201.  
  202. /**
  203.  * Prepare a menu item url
  204.  *
  205.  * @param         url            menu item url
  206.  */
  207. function buildURL($url)
  208. {
  209.     // allow a simple portable way to link to the home page of the site
  210.     if ($url == '{homepage}'{
  211.         $url pnGetBaseURL();
  212.     elseif (!empty($url)) {
  213.         switch ($url[0]// Used to allow support for linking to modules with the use of bracket
  214.         {
  215.             case '['// old style module link
  216.             {
  217.                 $url explode(':'substr($url1,  1));
  218.                 $url pnConfigGetVar('entrypoint''index.php''?name='.$url[0].(isset($url[1]'&file='.$url[1]:'');
  219.                 break;
  220.             }
  221.             case '{'// new module link
  222.             {
  223.                 $url explode(':'substr($url1,  1));
  224.                 // url[0] should be the module name
  225.                 if (isset($url[0]&& !empty($url[0])) 
  226.                     $modname $url[0];
  227.                     // default for params
  228.                     $params array();
  229.                     // url[1] can be a function or function&param=value
  230.                     if (isset($url[1]&& !empty($url[1])) {
  231.                         $urlparts explode('&'$url[1])
  232.                         $func $urlparts[0];
  233.                         unset($urlparts[0]);
  234.                         if (count($urlparts0{
  235.                             foreach ($urlparts as $urlpart{
  236.                                 $part explode('='$urlpart);
  237.                                 $params[trim($part[0])trim($part[1]);
  238.                             }
  239.                         }
  240.                     else {
  241.                         $func 'main';
  242.                     
  243.                     // addon: url[2] can be the type parameter, default 'user'
  244.                     $type (isset($url[2]&&!empty($url[2])) $url[2'user'
  245.                     //  build the url  
  246.                     $url pnModURL($modname$type$func$params);
  247.                 else {
  248.                     $url pnConfigGetVar('entrypoint''index.php');
  249.                 }
  250.                 break;
  251.             }
  252.         }  // End Bracket Linking
  253.     }
  254.  
  255.     return $url;
  256. }
  257.  
  258.  
  259. /**
  260.  * modify block settings
  261.  *
  262.  * @author       The Zikula Development Team
  263.  * @param        array       $blockinfo     a blockinfo structure
  264.  * @return       output      the bock form
  265.  */
  266. function Blocks_extmenublock_modify($blockinfo)
  267. {
  268.     // Break out options from our content field
  269.     $vars pnBlockVarsFromContent($blockinfo['content']);
  270.     $blockinfo['content''';
  271.  
  272.  
  273.     // Defaults
  274.     if (empty($vars['displaymodules'])) {
  275.         $vars['displaymodules'0;
  276.     }
  277.  
  278.     // template to use
  279.     if (empty($vars['template'])) {
  280.         $vars['template''blocks_block_extmenu.htm';
  281.     }
  282.  
  283.     // Create output object - this object will store all of our output so that
  284.     // we can return it easily when required
  285.     $pnRender pnRender::getInstance('Blocks'false);
  286.  
  287.     Loader::loadClass('LanguageUtil');
  288.     $languages LanguageUtil::getLanguages();
  289.     $userlanguage pnUserGetLang();
  290.  
  291.     // create default block variables
  292.     if (!isset($vars['blocktitles'])) {
  293.         $vars['blocktitles'array();
  294.     }
  295.     if (!isset($vars['links'])) {
  296.         $vars['links'array();
  297.     }
  298.     if (!isset($vars['stylesheet'])) {
  299.         $vars['stylesheet''';
  300.     }
  301.     if (!isset($vars['menuid'])) {
  302.         $vars['menuid'0;
  303.     }
  304.  
  305.     // check if the users wants to add a new link via the "Add current url" link in the block
  306.     $addurl FormUtil::getPassedValue('addurl'0'GET');
  307.     // or if we come from the normal "edit this block" link
  308.     $fromblock FormUtil::getPassedValue('fromblock'null'GET');
  309.  
  310.     $redirect '';
  311.     if ($addurl == 1{
  312.         // set a marker for redirection later on
  313.         $newurl pnServerGetVar('HTTP_REFERER')
  314.         $redirect urlencode($newurl);
  315.         $newurl str_replace(pnGetBaseURL()''$newurl)
  316.         if (empty($newurl)) {
  317.             $newurl pnConfigGetVar('entrypoint''index.php');
  318.         }
  319.         foreach($languages as $singlelanguage{
  320.             $vars['links'][$singlelanguage][array('name'   => _EMENU_NEWLINK,
  321.                                                       'url'    => $newurl,
  322.                                                       'title'  => _EMENU_NEWLINK,
  323.                                                       'level'  => 0,
  324.                                                       'parent' => 0,
  325.                                                       'image'  => '',
  326.                                                       'active' => 1);
  327.         }
  328.     elseif (isset($fromblock)) {
  329.         $redirect urlencode(pnServerGetVar('HTTP_REFERER'))
  330.     }
  331.  
  332.     // add new languages to the blocktitles and link arrays
  333.  
  334.     // we need to know which language has the most links, this language will be the "master"
  335.     // for new languages to be added. this ensures that all links for the new language 
  336.     // are prepared.
  337.     $link_master array();
  338.     foreach($languages as $lang{
  339.         if(count($link_mastercount($vars['links'][$lang])) {
  340.             $link_master $vars['links'][$lang];
  341.         }   
  342.     }
  343.         
  344.     foreach($languages as $lang{
  345.         // create an empty blocktitle string
  346.         if (!array_key_exists($lang$vars['blocktitles'])) {
  347.             $vars['blocktitles'][$lang'';
  348.         }
  349.         if (!array_key_exists($lang$vars['links'])) {
  350.             $vars['links'][$lang$link_master;
  351.         }
  352.     }
  353.  
  354.     // menuitems are sorted by language per default for easier
  355.     // access when showing them (which is more often necessary than
  356.     // editing them), but for editing them we need them sorted by id
  357.     $menuitems array();
  358.     foreach ($vars['links'as $lang => $langlinks{
  359.         // langlinks now contains an array of links for a certain language
  360.         // sorted by key=id
  361.         foreach ($langlinks as $linkid => $link{
  362.             $link['errors'array();
  363.             extmenu_check_image($link);
  364.             $menuitems[$linkid][$lang$link;
  365.         }
  366.     }
  367.  
  368.     // assign the vars
  369.     $pnRender->assign($vars);
  370.     $pnRender->assign('languages'$languages);
  371.     $pnRender->assign('userlanguage'$userlanguage);
  372.     $pnRender->assign('redirect'$redirect);
  373.  
  374.     $pnRender->assign('menuitems'$menuitems);
  375.     $pnRender->assign('blockinfo'$blockinfo);
  376.  
  377.     // return the output
  378.     return $pnRender->fetch('blocks_block_extmenu_modify.htm');
  379. }
  380.  
  381. /**
  382.  * update block settings
  383.  *
  384.  * @author       The Zikula Development Team
  385.  * @param        array       $blockinfo     a blockinfo structure
  386.  * @return       $blockinfo  the modified blockinfo structure
  387.  */
  388. function Blocks_extmenublock_update($blockinfo)
  389. {
  390.  
  391.     $vars['displaymodules'FormUtil::getPassedValue('displaymodules');
  392.     $vars['stylesheet']     FormUtil::getPassedValue('stylesheet');
  393.     $vars['template']       FormUtil::getPassedValue('template');
  394.     $vars['blocktitles']    FormUtil::getPassedValue('blocktitles');
  395.  
  396.     // Defaults
  397.     if (empty($vars['displaymodules'])) {
  398.         $vars['displaymodules'0;
  399.     }
  400.  
  401.     if (empty($vars['template'])) {
  402.         $vars['template''blocks_block_extmenu.htm';
  403.     }
  404.  
  405.     if (empty($vars['stylesheet'])) {
  406.         $vars['stylesheet''extmenu.css';
  407.     }
  408.  
  409.     // User links
  410.     $content array();
  411.  
  412.     $linkids     FormUtil::getPassedValue('linkids');
  413.     $linkname    FormUtil::getPassedValue('linkname');
  414.     $linkurl     FormUtil::getPassedValue('linkurl');
  415.     $linktitle   FormUtil::getPassedValue('linktitle');
  416.     $linkimage   FormUtil::getPassedValue('linkimage');
  417.     $linkactive  FormUtil::getPassedValue('linkactive');
  418.  
  419.     // fake some data we will implement later
  420.     $linklevel  array();
  421.     $linkparent array();
  422.  
  423.     $linkarray array();
  424.  
  425.     Loader::loadClass('LanguageUtil');
  426.     $languages LanguageUtil::getLanguages();
  427.  
  428.     // rebuild the arrays: we need one entry per link
  429.     foreach($linkids as $linkid{
  430.         foreach($languages as $lang{
  431.             $linkarray[$lang][array('name'   => $linkname[$linkid][$lang],
  432.                                         'url'    => $linkurl[$linkid][$lang],
  433.                                         'title'  => $linktitle[$linkid][$lang],
  434.                                         'level'  => 0,
  435.                                         'parent' => 0,
  436.                                         'image'  => $linkimage[$linkid][$lang],
  437.                                         'active' => $linkactive[$linkid][$lang]
  438.                                         );
  439.         }
  440.     }
  441.  
  442.     $vars['links'$linkarray;
  443.     $vars['blockversion'1;
  444.  
  445.     $blockinfo['content'pnBlockVarsToContent($vars);
  446.  
  447.     // clear the block cache
  448.     $pnRender pnRender::getInstance('Blocks'false);
  449.     $pnRender->clear_all_cache();
  450.  
  451.     return($blockinfo);
  452. }
  453.  
  454. function extmenu_check_image(&$link)
  455. {
  456.     if (!empty($link['image'])) {
  457.         if (file_exists($osimg=DataUtil::formatForOS($link['image'])) && is_readable($osimg)) {
  458.             $link['image'$osimg;
  459.             $link['imagedata'@getimagesize($osimg);
  460.         else {
  461.             $link['error'][DataUtil::formatForDisplay($link['image']': invalid image data';
  462.             $link['image''';
  463.             $link['imagedata'false;
  464.         }
  465.     }
  466.     return;
  467. }

Documentation generated on Fri, 18 Jul 2008 21:44:59 +0200 by phpDocumentor 1.4.1