Skip to content

Resizer does not work when wCMS is in a subdirectory #119

@bugzbrown

Description

@bugzbrown
  • Winter CMS Build: 1.1.3
  • PHP Version:
  • Database Engine: mysql
  • Plugins Installed:

Description:

When Winter is installed as a subdirectory and you try to use resizer to resize images in your theme or component, you get a 404 because it tries to find the URL /resizer/d2...cf1/%252Fstorage%252Fapp%252....

Steps To Reproduce:

  1. install wintercms as a subdirectory of a site.
  2. try to resize an image on the theme using the <img src="{{ 'image.jpg' | media | resize(300,300) }}" />

Suggested Fix:

I identified that modules/system/classes/imageResizer.php has two points where it returns an URL without adding the app path:

in public function getResizerUrl (line ~502)
and sequentially where it returns an already resized image in public function getResizedUrl() (line ~532)

/**
     * Get the URL to the system resizer route for this instance's configuration
     *
     * @return string $url
     */
    public function getResizerUrl()
    {
        // Slashes in URL params have to be double encoded to survive Laravel's router
        // @see https://github.com/octobercms/october/issues/3592#issuecomment-671017380
        $resizedUrl = rawurlencode(rawurlencode($this->getResizedUrl()));

        // Get the current configuration's identifier
        $identifier = $this->getIdentifier();

        // Store the current configuration
        $this->storeConfig();

        // IF YOU ADD THE CONFIG::GET APP.URL IT WORKS
        $url = Config::get('app.url','')."/resizer/$identifier/$resizedUrl";

        if (Config::get('cms.linkPolicy', 'detect') === 'force') {
            $url = Url::to($url);
        }

        return $url;
    }

    /**
     * Get the URL to the resized image
     *
     * @return string
     */
    public function getResizedUrl()
    {
        $url = '';

        if ($this->image['source'] === 'filemodel') {
            $model = $this->getFileModel();
            $thumbFile = $model->getThumbFilename($this->width, $this->height, $this->options);
            $url = $model->getPath($thumbFile);
        } else {
            $resizedDisk = Storage::disk(Config::get('cms.storage.resized.disk', 'local'));
            $url = $resizedDisk->url($this->getPathToResizedImage());
        }

        // Ensure that a properly encoded URL is returned
        $segments = explode('/', $url);
        $lastSegment = array_pop($segments);

        // AGAIN HERE - ADDING THE APPURL WORKS TOO
        $url = Config::get('app.url','').implode('/', $segments) . '/' . rawurlencode(rawurldecode($lastSegment));

        if (Config::get('cms.linkPolicy', 'detect') === 'force') {
            $url = Url::to($url);
        }

        return $url;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions