Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/html/toolbar.php

Documentation is available at toolbar.php

  1. <?php
  2. /**
  3. @version        $Id: toolbar.php 6638 2007-02-15 20:58:23Z Jinx $
  4. @package        Joomla.Framework
  5. @subpackage    HTML
  6. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7. @license        GNU/GPL, see LICENSE.php
  8. *  Joomla! is free software. This version may have been modified pursuant
  9. *  to the GNU General Public License, and as distributed it includes or
  10. *  is derivative of works licensed under the GNU General Public License or
  11. *  other free or open source software licenses.
  12. *  See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * ToolBar handler
  20.  *
  21.  * @author         Louis Landry <[email protected]>
  22.  * @package     Joomla.Framework
  23.  * @subpackage    HTML
  24.  * @since        1.5
  25.  */
  26. class JToolBar extends JObject
  27. {
  28.     /**
  29.      * Toolbar name
  30.      *
  31.      * @access    private
  32.      * @var        string 
  33.      */
  34.     var $_name array ();
  35.  
  36.     /**
  37.      * Toolbar array
  38.      *
  39.      * @access    private
  40.      * @var        array 
  41.      */
  42.     var $_bar array ();
  43.  
  44.     /**
  45.      * Loaded buttons
  46.      *
  47.      * @access    private
  48.      * @var        array 
  49.      */
  50.     var $_buttons array ();
  51.  
  52.     /**
  53.      * Directories, where button types can be stored
  54.      *
  55.      * @access    private
  56.      * @var        array 
  57.      */
  58.     var $_buttonDirs array ();
  59.  
  60.     /**
  61.      * Constructor
  62.      *
  63.      * @access protected
  64.      * @param string The toolbar name
  65.      * @var string The type of setup file
  66.      */
  67.     function __construct($name 'toolbar')
  68.     {
  69.         $this->_name $name;
  70.  
  71.         jimport('joomla.html.toolbar.button');
  72.         if (!defined('JBUTTON_INCLUDE_PATH')) {
  73.             define('JBUTTON_INCLUDE_PATH'dirname(__FILE__).DS.'toolbar'.DS.'button');
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Returns a reference to a global JToolBar object, only creating it if it
  79.      * doesn't already exist.
  80.      *
  81.      * This method must be invoked as:
  82.      *         <pre>  $toolbar = & JToolBar::getInstance( $name );</pre>
  83.      *
  84.      * @access    public
  85.      * @param    string        $name  The name of the toolbar.
  86.      * @return    JToolBar    The JToolBar object.
  87.      */
  88.     function getInstance($name)
  89.     {
  90.         static $instances;
  91.  
  92.         if (!isset ($instances)) {
  93.             $instances array ();
  94.         }
  95.  
  96.         if (empty ($instances[$name])) {
  97.             $instances[$namenew JToolBar();
  98.         }
  99.  
  100.         return $instances[$name];
  101.     }
  102.  
  103.     /**
  104.      * Set a value
  105.      *
  106.      * @access public
  107.      * @param string The name of the param
  108.      * @param string The value of the parameter
  109.      * @return string The set value
  110.      */
  111.     function appendButton()
  112.     {
  113.         // Push button onto the end of the toolbar array
  114.         $btn func_get_args();
  115.         array_push($this->_bar$btn);
  116.         return true;
  117.     }
  118.  
  119.     /**
  120.      * Get a value
  121.      *
  122.      * @access public
  123.      * @param string The name of the param
  124.      * @param mixed The default value if not found
  125.      * @return string 
  126.      */
  127.     function prependButton()
  128.     {
  129.         // Insert button into the front of the toolbar array
  130.         $btn func_get_args();
  131.         array_unshift($this->_bar$btn);
  132.         return true;
  133.     }
  134.  
  135.     /**
  136.      * Render
  137.      *
  138.      * @access public
  139.      * @param string The name of the control, or the default text area if a setup file is not found
  140.      * @return string HTML
  141.      */
  142.     function render()
  143.     {
  144.         /*
  145.          * Initialize variables
  146.          */
  147.         $html array ();
  148.  
  149.         // Start toolbar div
  150.         $html['<div class="toolbar" id="'.$this->_name.'">';
  151.         $html['<table class="toolbar"><tr>';
  152.  
  153.         // Render each button in the toolbar
  154.         foreach ($this->_bar as $button)
  155.         {
  156.             $html[$this->renderButton($button);
  157.         }
  158.  
  159.         // End toolbar div
  160.         $html['</tr></table>';
  161.         $html['</div>';
  162.  
  163.         return implode("\n"$html);
  164.     }
  165.  
  166.     /**
  167.      * Render a parameter type
  168.      *
  169.      * @param object param tag node
  170.      * @param string The control name
  171.      * @return array Any array of the label, the form element and the tooltip
  172.      */
  173.     function renderButton&$node )
  174.     {
  175.         // Get the button type
  176.         $type $node[0];
  177.  
  178.         $button $this->loadButtonType($type);
  179.  
  180.         /**
  181.          * Error Occurred
  182.          */
  183.         if ($button === false)
  184.         {
  185.             return JText::_('Button not defined for type').' = '.$type;
  186.         }
  187.         return $button->render($node);
  188.     }
  189.  
  190.     /**
  191.      * Loads a button type
  192.      *
  193.      * @access    public
  194.      * @param    string    buttonType
  195.      * @return    object 
  196.      * @since 1.5
  197.      */
  198.     function loadButtonType($type$new false)
  199.     {
  200.         $signature md5($type);
  201.         if (isset ($this->_buttons[$signature]&& $new === false{
  202.             return $this->_buttons[$signature];
  203.         }
  204.  
  205.         if (!class_exists('JButton'))
  206.         {
  207.             JError::raiseWarning'SOME_ERROR_CODE''Could not load button base class.' );
  208.             return false;
  209.         }
  210.  
  211.         $buttonClass 'JButton'.$type;
  212.         if (!class_exists($buttonClass))
  213.         {
  214.             if (isset ($this->_buttonDirs))
  215.                 $dirs $this->_buttonDirs;
  216.             else
  217.                 $dirs array ();
  218.  
  219.             array_push($dirs$this->getIncludePath());
  220.  
  221.             $found false;
  222.             foreach ($dirs as $dir)
  223.             {
  224.                 $buttonFile sprintf('%s'.DS.'%s.php'$dirstr_replace('_'DSstrtolower($type)));
  225.                 if (include_once $buttonFile)
  226.                 {
  227.                     $found true;
  228.                     break;
  229.                 }
  230.             }
  231.  
  232.             if (!$found)
  233.             {
  234.                 JError::raiseWarning'SOME_ERROR_CODE'"Could not load module $buttonClass ($buttonFile).);
  235.                 return false;
  236.             }
  237.         }
  238.  
  239.         if (!class_exists($buttonClass))
  240.         {
  241.             //return    JError::raiseError( 'SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass." );
  242.             return false;
  243.         }
  244.         $this->_buttons[$signaturenew $buttonClass($this);
  245.  
  246.         return $this->_buttons[$signature];
  247.     }
  248.  
  249.     /**
  250.      * Add a directory where JToolBar should search for button types
  251.      *
  252.      * You may either pass a string or an array of directories.
  253.      *
  254.      * {@link JParameter} will be searching for an element type in the same order you
  255.      * added them. If the parameter type cannot be found in the custom folders,
  256.      * it will look in JParameter/types.
  257.      *
  258.      * @access    public
  259.      * @param    string|array   directory or directories to search.
  260.      * @since    1.5
  261.      */
  262.     function addButtonDir($dir)
  263.     {
  264.         if (is_array($dir)) {
  265.             $this->_buttonDirs array_merge($this->_buttonDirs$dir);
  266.         else {
  267.             array_push($this->_buttonDirs$dir);
  268.         }
  269.     }
  270.  
  271.     /**
  272.      * Get the include path
  273.      *
  274.      * @access    public
  275.      * @return    string 
  276.      * @since    1.5
  277.      */
  278.     function getIncludePath({
  279.         return JBUTTON_INCLUDE_PATH;
  280.     }
  281. }
  282. ?>

Documentation generated on Mon, 05 Mar 2007 21:29:36 +0000 by phpDocumentor 1.3.1