FOF30\Template\Template::getAltPaths PHP Method

getAltPaths() public method

It returns both the normal and alternative (template media override) path. For example, media://com_foobar/css/test.css is parsed into array( '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) auto:// Automatically guess if it should be site:// or admin:// plugin:// The plugin directory or a template override (must be plugin://pluginType/pluginName/templateName)
public getAltPaths ( string $path ) : array
$path string Fancy path
return array Array of normal and alternate parsed path
    public function getAltPaths($path)
    {
        $protoAndPath = explode('://', $path, 2);
        if (count($protoAndPath) < 2) {
            $protocol = 'media';
        } else {
            $protocol = $protoAndPath[0];
            $path = $protoAndPath[1];
        }
        if ($protocol == 'auto') {
            $protocol = $this->container->platform->isBackend() ? 'admin' : 'site';
        }
        $path = ltrim($path, '/' . DIRECTORY_SEPARATOR);
        switch ($protocol) {
            case 'media':
                // Do we have a media override in the template?
                $pathAndParams = explode('?', $path, 2);
                $ret = array('normal' => 'media/' . $pathAndParams[0], 'alternate' => $this->container->platform->getTemplateOverridePath('media:/' . $pathAndParams[0], false));
                break;
            case 'plugin':
                // The path is pluginType/pluginName/viewTemplate
                $pathInfo = explode('/', $path);
                $pluginType = isset($pathInfo[0]) ? $pathInfo[0] : 'system';
                $pluginName = isset($pathInfo[1]) ? $pathInfo[1] : 'foobar';
                $viewTemplate = isset($pathInfo[2]) ? $pathInfo[2] : 'default';
                $pluginSystemName = 'plg_' . $pluginType . '_' . $pluginName;
                $ret = array('normal' => 'plugins/' . $pluginType . '/' . $pluginName . '/tmpl/' . $viewTemplate, 'alternate' => $this->container->platform->getTemplateOverridePath('auto:/' . $pluginSystemName . '/' . $viewTemplate, false));
                break;
            case 'admin':
                $ret = array('normal' => 'administrator/' . $path);
                break;
            default:
            case 'site':
                $ret = array('normal' => $path);
                break;
        }
        // For CSS and JS files, add a debug path if the supplied file is compressed
        $filesystem = $this->container->filesystem;
        $ext = $filesystem->getExt($ret['normal']);
        if (in_array($ext, array('css', 'js'))) {
            $file = basename($filesystem->stripExt($ret['normal']));
            /*
             * Detect if we received a file in the format name.min.ext
             * If so, strip the .min part out, otherwise append -uncompressed
             */
            if (strlen($file) > 4 && strrpos($file, '.min', '-4')) {
                $position = strrpos($file, '.min', '-4');
                $filename = str_replace('.min', '.', $file, $position) . $ext;
            } else {
                $filename = $file . '-uncompressed.' . $ext;
            }
            // Clone the $ret array so we can manipulate the 'normal' path a bit
            $t1 = (object) $ret;
            $temp = clone $t1;
            unset($t1);
            $temp = (array) $temp;
            $normalPath = explode('/', $temp['normal']);
            array_pop($normalPath);
            $normalPath[] = $filename;
            $ret['debug'] = implode('/', $normalPath);
        }
        return $ret;
    }