shopware5 / shopware

Shopware 5 core
https://shopware.com
Other
1.32k stars 804 forks source link

Question: Incorrect path generated for SMARTY-function "{link"? #74

Closed OliverZachau closed 11 years ago

OliverZachau commented 11 years ago

Hello all,

i was trying to setup a new shopware installation and run into some problems. After Installation the html pages were having the full path to the local file:

http://domain/path/to/htdocs/shopware/templates/_default/frontend/_resources/styles/framework.css

what i would have wanted was something like: http://domain/shopware/templates/_default/frontend/_resources/styles/framework.css

i found that this error did come from the link() inside compiler.link.php (showare/engine/Library/Enlight/Template/Plugins).

Did i miss something during setup which caused this kind of problem or is there a issue with the function? My Current Fix:

 /**
     * @param $params
     * @param $template
     * @return mixed|string
     */
    public static function link($params, $template)
    {
        $file = $params['file'];

        /** @var $front Enlight_Controller_Front */
        $front = Enlight_Application::Instance()->Front();
        $request = $front->Request();

        // check if we got an URI or a local link
        if (!empty($file) && strpos($file, '/') !== 0 && strpos($file, '://') === false) {

            $useIncludePath = $template->smarty->getUseIncludePath();

            // try to find the file on the filesystem
            foreach ($template->smarty->getTemplateDir() as $dir) {
                if (file_exists($dir . $file)) {
                    $file = realpath($dir) . DS . str_replace('/', DS, $file);
                    break;
                }
                if ($useIncludePath) {
                    if ($dir === '.' . DS) {
                        $dir = '';
                    }
                    if (($result = Enlight_Loader::isReadable($dir . $file)) !== false) {
                        $file = $result;
                        break;
                    }
                }
            }

            if (method_exists(Enlight_Application::Instance(), 'DocPath')) {
                $docPath = Enlight_Application::Instance()->DocPath();
            } else {
                $docPath = getcwd() . DIRECTORY_SEPARATOR;
            }

            // some clean up code
            if (strpos($file, $docPath) === 0) {
                $file = substr($file, strlen($docPath));
            }
            // make sure we have the right separator for the web context
            if (DIRECTORY_SEPARATOR !== '/') {
                $file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
            }
            if (strpos($file, './') === 0) {
                $file = substr($file, 2);
            }
            // if we did not find the file, we are returning a false
            if (strpos($file, '/') !== 0) {
                if (!file_exists($docPath . $file)) {
                    //return false;
                }
                $file = $request->getBasePath() . '/' . $file;
            }
        }

        if (empty($file)) {
            $file = $request->getBasePath() . '/';
        }

        if (strpos($file, '/') === 0 && !empty($params['fullPath'])) {
            $file = $request->getScheme() . '://' . $request->getHttpHost() . $file;
        }

        //replace the file system folders with nothing to make sure the path is correct
        return str_ireplace(Enlight_Application::Instance()->DocPath(), "", $file);
    }
dnoegel commented 11 years ago

Hi @OliverZachau,

do you have an example for us in order to reproduce the problem?

Thanks,

Daniel

dnoegel commented 11 years ago

Hi,

as we want to close out GitHub issue tracker in favor of out jira.shopware.de-tracker, I'll close this issue.

Please use jira.shopware.de if the problem still exists - as there was no activity here for about a month, I'll guess you've solved the problem.