Location: PHPKode > scripts > XMap > xmap/smarty-function.xmap.php
<?PHP
/**
  * XMap Plugin to Smarty
  *
  *
  * Open a Map.xml file and use XPATH to access it contents.
  * We can make an analogy to explain this plugin. See first:
  * {@link http://www.w3.org/Style/XSL/WhatIsXSL.html WhatIsXSL}
  * xmap is the function that parser the "The XML file" and
  * Smarty Template is the "StyleSheet" and HTML is the "Rendering"
  * part of W3C - WhatIsXSL document.
  *
  * Conclusion: xmap function get values from a XML
  * file and return in an array to be used inside Smarty Template.
  *
  * xmap have two requiriments: PHP compiled with XML and the
  * <phpXML/> XPath parser that you can get from
  * {@link http://www.phpclasses.org/browse.html/package/180.html PHPXML Lastest Dist}
  *
  * @package    xmap
  * @version    1.0
  * @author     Roberto Bertó - darkelder (inside) users (dot) sourceforge (dot) net
  * @copyright  {@link http://www.gnu.org/copyleft/lesser.html LGPL}
  * @param      string          $file           required - MAP.xml file
  * @param      string          $id             optional - The element id you want to work - only rule all or similar do not require $id
  * @param      string          $rule           require this os $path - Use a prefinied path (is required or $rule or $path be set)
  * @param      string          $path           require this or $rule - Use a userdefinied path
  * @param      bool            $invert         optional - Reverse the array before return
  * @param      string          $assign         required - Assign is required
  * @param      bool            $debug          optional - Want debug?
  *
  *
  * INSTALL INSTRUCTIONS
  * You must download the following files, and rename them to shared.xmap.php and shared.xml.php:
  * - http://www.phpclasses.org/browse.html/package/581.html - get everything and rename class.xmap.php to shared.xmap.php
  * - http://www.phpclasses.org/browse.html/package/180.html - get only xml.php rename to shared.xml.php
  * Note the only files you should put on plugins dir is shared.xmap.php and shared.xml.php
  *
  * @author             Roberto Bertó           darkelder (inside) users (dot) sourceforge (dot) net
  * @copyright          {@link http://www.gnu.org/copyleft/lesser.html LGPL}
  * @version            0.1
  */

function smarty_function_xmap ($params,&$smarty)
{
        $file           = $params['file'];
        $assign         = $params['assign'];
        $rule           = $params['rule'];
        $path           = $params['path'];
        $debug          = $params['debug'];
        $id             = $params['id'];
        $invert         = $params['invert'];

        // assign not null
        if (empty($assign))
        {
                $smarty->_trigger_plugin_error("parameter 'assign' cannot be empty");
                return;
        }

        //security check
        require_once SMARTY_DIR . $smarty->plugins_dir . '/shared.secure_file.php';
        if (smarty_secure_file($file,$smarty) == FALSE)
        {
                return;
        }

        // rule or path
        if (empty($rule) && empty($path))
        {
                $smarty->_trigger_plugin_error("parameter 'rule' or 'path' need be filled");
                return;
        }

        // require the libraries
        require_once SMARTY_DIR . $smarty->plugins_dir . '/shared.xmap.php';
        $XMap = new XMap($file,SMARTY_DIR . $smarty->plugins_dir . '/shared.xml.php');

        // debug on?
        if ($debug == TRUE)
        {
                $XMap->debug = TRUE;
        }

        // user definied path
        if (!empty($path))
        {
                $rule = "__userDefinied__";
                $XMap->xpathRules["$rule"] = $path;
        }

        // getting
        $sitemap = $XMap->Get($rule,$id,$invert);
        // assiging
        $smarty->assign($assign,$sitemap);

}

?>
Return current item: XMap