Source for file utils.php
Documentation is available at utils.php
 * @package     FrameworkOnFramework  
 * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.  
 * @license     GNU General Public License version 2 or later; see LICENSE.txt  
// Protect from unauthorized access  
 * A utility class to load view templates, media files and modules.  
 * @package  FrameworkOnFramework  
     * Add a CSS file to the page generated by the CMS  
     * @param   string  $path  A fancy path definition understood by parsePath  
     * @see FOFTemplateUtils::parsePath  
    public static function addCSS($path)  
                $url = 
self::parsePath($path);  
                $document->addStyleSheet($url);  
     * Add a JS script file to the page generated by the CMS.  
     * There are three combinations of defer and async (see http://www.w3schools.com/tags/att_script_defer.asp):  
     * * $defer false, $async true: The script is executed asynchronously with the rest of the page  
     *   (the script will be executed while the page continues the parsing)  
     * * $defer true, $async false: The script is executed when the page has finished parsing.  
     * * $defer false, $async false. (default) The script is loaded and executed immediately. When it finishes  
     *   loading the browser continues parsing the rest of the page.  
     * When you are using $defer = true there is no guarantee about the load order of the scripts. Whichever  
     * script loads first will be executed first. The order they appear on the page is completely irrelevant.  
     * @param   string   $path   A fancy path definition understood by parsePath  
     * @param   boolean  $defer  Adds the defer attribute, meaning that your script  
     *                            will only load after the page has finished parsing.  
     * @param   boolean  $async  Adds the async attribute, meaning that your script  
     *                            will be executed while the resto of the page  
     * @see FOFTemplateUtils::parsePath  
    public static function addJS($path, $defer = 
false, $async = 
false)  
                $url = 
self::parsePath($path);  
                $document->addScript($url, "text/javascript", $defer, $async);  
     * Compile a LESS file into CSS and add it to the page generated by the CMS.  
     * This method has integrated cache support. The compiled LESS files will be  
     * written to the media/lib_fof/compiled directory of your site. If the file  
     * cannot be written we will use the $altPath, if specified  
     * @param   string   $path        A fancy path definition understood by parsePath pointing to the source LESS file  
     * @param   string   $altPath     A fancy path definition understood by parsePath pointing to a precompiled CSS file,  
     *                                 used when we can't write the generated file to the output directory  
     * @param   boolean  $returnPath  Return the URL of the generated CSS file but do not include it. If it can't be  
     *                                 generated, false is returned and the alt files are not included  
     * @see FOFTemplateUtils::parsePath  
     * @return  mixed  True = successfully included generated CSS, False = the alternate CSS file was used, null = the source file does not exist  
    public static function addLESS($path, $altPath = 
null, $returnPath = 
false)  
        // Does the cache directory exists and is writeable  
        static $sanityCheck = 
null;  
        // Get the local LESS file  
        $localFile = 
self::parsePath($path, true);  
            // Make sure the cache directory exists  
        // No point continuing if the source file is not there or we can't write to the cache  
        if (!$sanityCheck || 
!is_file($localFile))  
                    foreach ($altPath as $anAltPath)  
                        self::addCSS($anAltPath);  
        // Get the source file's unique ID  
        // Get the cached file path  
        $cachedPath = 
JPATH_SITE . 
'/media/lib_fof/compiled/' . 
$id . 
'.css';  
        $lessCompiler->formatterName = 
'compressed';  
        // Should I add an alternative import path?  
        $altFiles = 
self::getAltPaths($path);  
        if (isset
($altFiles['alternate']))  
            if ($currentLocation == 
$normalLocation)  
                $lessCompiler->importDir = 
array($alternateLocation, $currentLocation);  
                $lessCompiler->importDir = 
array($currentLocation, $normalLocation);  
        $lessCompiler->checkedCompile($localFile, $cachedPath);  
        // Add the compiled CSS to the page  
        if (substr($base_url, -
14) == 
'/administrator')  
            $base_url = 
substr($base_url, 0, -
14);  
        $url = 
$base_url . 
'/media/lib_fof/compiled/' . 
$id . 
'.css';  
                    $document->addStyleSheet($url);  
     * Creates a SEF compatible sort header. Standard Joomla function will add a href="#" tag, so with SEF  
     * enabled, the browser will follow the fake link instead of processing the onSubmit event; so we  
     * @param   string   $text   Header text  
     * @param   string   $field  Field used for sorting  
     * @param   JObject  $list   Object holding the direction and the ordering field  
     * @return  string  HTML code for sorting  
    public static function sefSort($text, $field, $list)  
        $sort = 
JHTML::_('grid.sort', JText::_(strtoupper($text)) . 
' ', $field, $list->order_Dir, $list->order);  
        return str_replace('href="#"', 'href="javascript:void(0);"', $sort);  
     * Parse a fancy path definition into a path relative to the site's root,  
     * respecting template overrides, suitable for inclusion of media files.  
     * For example, media://com_foobar/css/test.css is parsed into  
     * media/com_foobar/css/test.css if no override is found, or  
     * templates/mytemplate/media/com_foobar/css/test.css if the current  
     * template is called mytemplate and there's a media override for it.  
     * The valid protocols are:  
     * media://        The media directory or a media override  
     * admin://        Path relative to administrator directory (no overrides)  
     * site://        Path relative to site's root (no overrides)  
     * @param   string   $path       Fancy path  
     * @param   boolean  $localFile  When true, it returns the local path, not the URL  
     * @return  string  Parsed path  
    public static function parsePath($path, $localFile = 
false)  
        $altPaths = 
self::getAltPaths($path);  
        $filePath = 
$altPaths['normal'];  
        // If JDEBUG is enabled, prefer that path, else prefer an alternate path if present  
                $filePath = 
$altPaths['debug'];  
        elseif (isset
($altPaths['alternate']))  
                $filePath = 
$altPaths['alternate'];  
     * Parse a fancy path definition into a path relative to the site's root.  
     * It returns both the normal and alternative (template media override) path.  
     * For example, media://com_foobar/css/test.css is parsed into  
     *   'normal' => 'media/com_foobar/css/test.css',  
     *   'alternate' => 'templates/mytemplate/media/com_foobar/css//test.css'  
     * The valid protocols are:  
     * media://        The media directory or a media override  
     * admin://        Path relative to administrator directory (no alternate)  
     * site://        Path relative to site's root (no alternate)  
     * @param   string  $path  Fancy path  
     * @return  array  Array of normal and alternate parsed path  
        $protoAndPath = 
explode('://', $path, 2);  
        if (count($protoAndPath) < 
2)  
            $protocol = 
$protoAndPath[0];  
            $path = 
$protoAndPath[1];  
        $path = 
ltrim($path, '/' . 
DIRECTORY_SEPARATOR);  
                // Do we have a media override in the template?  
                $pathAndParams = 
explode('?', $path, 2);  
                    'normal'     => 
'media/' . 
$pathAndParams[0],  
                    'normal' => 
'administrator/' . 
$path  
        // For CSS and JS files, add a debug path if the supplied file is compressed  
             * Detect if we received a file in the format name.min.ext  
             * If so, strip the .min part out, otherwise append -uncompressed  
                $position = 
strrpos($file, '.min', '-4');  
                $filename = 
str_replace('.min', '.', $file, $position);  
                $filename = 
$file . 
'-uncompressed.' . 
$ext;  
            // Clone the $ret array so we can manipulate the 'normal' path a bit  
            $temp = (array) 
(clone (object) 
$ret);  
            $normalPath = 
explode('/', $temp['normal']);  
            $normalPath[] = 
$filename;  
            $ret['debug'] = 
implode('/', $normalPath);  
     * Returns the contents of a module position  
     * @param   string  $position  The position name, e.g. "position-1"  
     * @param   int     $style     Rendering style; please refer to Joomla!'s code for more information  
     * @return  string  The contents of the module position  
            $renderer = 
$document->loadRenderer('module');  
        $params = 
array('style' => 
$style);  
            $contents .= 
$renderer->render($mod, $params);  
     * Merges the current url with new or changed parameters.  
     * This method merges the route string with the url parameters defined  
     * in current url. The parameters defined in current url, but not given  
     * in route string, will automatically reused in the resulting url.  
     * But only these following parameters will be reused:  
     * option, view, layout, format  
     * Assuming that current url is:  
     * http://fobar.com/index.php?option=com_foo&view=cpanel  
     * <?php echo FOFTemplateutils::route('view=categories&layout=tree'); ?>  
     * http://fobar.com/index.php?option=com_foo&view=categories&layout=tree  
     * @param   string  $route  The parameters string  
     * @return  string  The human readable, complete url  
    public static function route($route = 
'')  
        if ($route == 
'index.php' || 
$route == 
'index.php?')  
        elseif (substr($route, 0, 1) == 
'&')  
            $url = 
JURI::getInstance();  
            $url->setQuery(array_merge($url->getQuery(true), $vars));  
            $result = 
'index.php?' . 
$url->getQuery();  
            $url = 
JURI::getInstance();  
            $props = 
$url->getQuery(true);  
            if (substr($route, 0, 10) == 
'index.php?')  
            // Check to see if there is component information in the route if not add it  
            if (!isset
($parts['option']) && isset
($props['option']))  
                $result[] = 
'option=' . 
$props['option'];  
            // Add the layout information to the route only if it's not 'default'  
            if (!isset
($parts['view']) && isset
($props['view']))  
                $result[] = 
'view=' . 
$props['view'];  
                if (!isset
($parts['layout']) && isset
($props['layout']))  
                    $result[] = 
'layout=' . 
$props['layout'];  
            // Add the format information to the URL only if it's not 'html'  
            if (!isset
($parts['format']) && isset
($props['format']) && 
$props['format'] != 
'html')  
                $result[] = 
'format=' . 
$props['format'];  
            $result = 
'index.php?' . 
implode('&', $result);  
 
 
	
		Documentation generated on Tue, 19 Nov 2013 15:16:44 +0100 by phpDocumentor 1.4.3