public function fallbackUrl($path)
    {
        $this->fireEvent('onPageFallBackUrl');

        /** @var Uri $uri */
        $uri = $this['uri'];

        /** @var Config $config */
        $config = $this['config'];

        $uri_extension = strtolower($uri->extension());
        $fallback_types = $config->get('system.media.allowed_fallback_types', null);
        $supported_types = $config->get('media.types');

        // Check whitelist first, then ensure extension is a valid media type
        if (!empty($fallback_types) && !\in_array($uri_extension, $fallback_types, true)) {
            return false;
        }
        if (!array_key_exists($uri_extension, $supported_types)) {
            return false;
        }

        $path_parts = pathinfo($path);

        /** @var PageInterface $page */
        $page = $this['pages']->dispatch($path_parts['dirname'], true);

        if ($page) {
            $media = $page->media()->all();
            $parsed_url = parse_url(rawurldecode($uri->basename()));
            $media_file = $parsed_url['path'];

            // if this is a media object, try actions first
            if (isset($media[$media_file])) {
                /** @var Medium $medium */
                $medium = $media[$media_file];
                foreach ($uri->query(null, true) as $action => $params) {
                    if (\in_array($action, ImageMedium::$magic_actions, true)) {
                        \call_user_func_array([&$medium, $action], explode(',', $params));
                    }
                }
                Utils::download($medium->path(), false);
            }

            // unsupported media type, try to download it...
            if ($uri_extension) {
                $extension = $uri_extension;
            } else {
                if (isset($path_parts['extension'])) {
                    $extension = $path_parts['extension'];
                } else {
                    $extension = null;
                }
            }

            if ($extension) {
                $download = true;
                if (\in_array(ltrim($extension, '.'), $config->get('system.media.unsupported_inline_types', []), true)) {
                    $download = false;
                }
                Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
            }

            // Nothing found
            return false;
        }

        return $page;
    }
public function fallbackUrl($path)
    {
        $this->fireEvent('onPageFallBackUrl');

        /** @var Uri $uri */
        $uri = $this['uri'];

        /** @var Config $config */
        $config = $this['config'];

        $uri_extension = strtolower($uri->extension());
        $fallback_types = $config->get('system.media.allowed_fallback_types', null);
        $supported_types = $config->get('media.types');

        // Check whitelist first, then ensure extension is a valid media type
        if (!empty($fallback_types) && !\in_array($uri_extension, $fallback_types, true)) {
            return false;
        }
        if (!array_key_exists($uri_extension, $supported_types)) {
            return false;
        }

        $path_parts = pathinfo($path);

        /** @var PageInterface $page */
        $page = $this['pages']->dispatch($path_parts['dirname'], true);

        if ($page) {
            $media = $page->media()->all();
            $parsed_url = parse_url(rawurldecode($uri->basename()));
            $media_file = $parsed_url['path'];

            // if this is a media object, try actions first
            if (isset($media[$media_file])) {
                /** @var Medium $medium */
                $medium = $media[$media_file];
                foreach ($uri->query(null, true) as $action => $params) {
                    if (\in_array($action, ImageMedium::$magic_actions, true)) {
                        \call_user_func_array([&$medium, $action], explode(',', $params));
                    }
                }
                Utils::download($medium->path(), false);
            }

            // unsupported media type, try to download it...
            if ($uri_extension) {
                $extension = $uri_extension;
            } else {
                if (isset($path_parts['extension'])) {
                    $extension = $path_parts['extension'];
                } else {
                    $extension = null;
                }
            }

            if ($extension) {
                $download = true;
                if (\in_array(ltrim($extension, '.'), $config->get('system.media.unsupported_inline_types', []), true)) {
                    $download = false;
                }
                Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
            }

            // Nothing found
            return false;
        }

        return $page;
    }
public function fallbackUrl ( $ path ) { $ this -> fireEvent ( 'onPageFallBackUrl' ) ; /** @var Uri $uri */ $ uri = $ this [ 'uri' ] ; /** @var Config $config */ $ config = $ this [ 'config' ] ; $ uri_extension = strtolower ( $ uri -> extension ( ) ) ; $ fallback_types = $ config -> get ( 'system.media.allowed_fallback_types' , null ) ; $ supported_types = $ config -> get ( 'media.types' ) ; // Check whitelist first, then ensure extension is a valid media type if ( ! empty ( $ fallback_types ) && ! \ in_array ( $ uri_extension , $ fallback_types , true ) ) { return false ; } if ( ! array_key_exists ( $ uri_extension , $ supported_types ) ) { return false ; } $ path_parts = pathinfo ( $ path ) ; /** @var PageInterface $page */ $ page = $ this [ 'pages' ] -> dispatch ( $ path_parts [ 'dirname' ] , true ) ; if ( $ page ) { $ media = $ page -> media ( ) -> all ( ) ; $ parsed_url = parse_url ( rawurldecode ( $ uri -> basename ( ) ) ) ; $ media_file = $ parsed_url [ 'path' ] ; // if this is a media object, try actions first if ( isset ( $ media [ $ media_file ] ) ) { /** @var Medium $medium */ $ medium = $ media [ $ media_file ] ; foreach ( $ uri -> query ( null , true ) as $ action => $ params ) { if ( \ in_array ( $ action , ImageMedium :: $ magic_actions , true ) ) { \ call_user_func_array ( [ & $ medium , $ action ] , explode ( ',' , $ params ) ) ; } } Utils :: download ( $ medium -> path ( ) , false ) ; } // unsupported media type, try to download it... if ( $ uri_extension ) { $ extension = $ uri_extension ; } else { if ( isset ( $ path_parts [ 'extension' ] ) ) { $ extension = $ path_parts [ 'extension' ] ; } else { $ extension = null ; } } if ( $ extension ) { $ download = true ; if ( \ in_array ( ltrim ( $ extension , '.' ) , $ config -> get ( 'system.media.unsupported_inline_types' , [ ] ) , true ) ) { $ download = false ; } Utils :: download ( $ page -> path ( ) . DIRECTORY_SEPARATOR . $ uri -> basename ( ) , $ download ) ; } // Nothing found return false ; } return $ page ; }
This attempts to find media, other files, and download them

@param string $path
This attempts to find media other files and download them