Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Nette a TinyMCE - nekompatibilita/něco dělám špatně?

Aktivity
Avatar
Michael Kufner:14.7.2016 23:53

dravím,
mám problém. Koupil jsem si plugin TinyMCE image manager a úspěšně ho zprovoznil.
Vše funguje jak má, jediná věc je náhled obrázku před vložením -> nezobrazuje se.
TinyMCE volá pro náhled následující URL:
http://localhost/…timthumb.php?…

Ta URL hlásí:
A TimThumb error has occured

The following error(s) occured:
Could not find the internal image you specified.

Query String : src=http://lo­calhost/CMS/u­ploads/articles_con­tent/FILE-20160714-2350ZUQ3URDNU2QE­.jpg&w=130&h=90
TimThumb version : 2.8.10

Ten obrázek je normálně přístupný, když nechám cestu http://localhost/…URDNU2QE.jpg , tak se zobrazí normálně. Z nějakého důvodu, při volání z pluginu je chyba.

Proč to souvisí s nette - myslím si to, protože když jsem měl soubor v localhost/tinyM­CE_TEST/, načítalo se to normálně. Je nějaký problém s routováním, nebo htaccess?

Tato funkce vrací lokální cestu k souboru.

protected function getLocalImagePath($src){
                $src = ltrim($src, '/'); //strip off the leading '/'
                if(! $this->docRoot){
                        $this->debug(3, "We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.");
                        //We don't support serving images outside the current dir if we don't have a doc root for security reasons.
                        $file = preg_replace('/^.*?([^\/\\\\]+)$/', '$1', $src); //strip off any path info and just leave the filename.
                        if(is_file($file)){
                                return $this->realpath($file);
                        }
                        return $this->error("Could not find your website document root and the file specified doesn't exist in timthumbs directory. We don't support serving files outside timthumb's directory without a document root for security reasons.");
                } //Do not go past this point without docRoot set

                //Try src under docRoot
                if(file_exists ($this->docRoot . '/' . $src)) {
                        $this->debug(3, "Found file as " . $this->docRoot . '/' . $src);
                        $real = $this->realpath($this->docRoot . '/' . $src);
                        if(stripos($real, $this->docRoot) === 0){
                                return $real;
                        } else {
                                $this->debug(1, "Security block: The file specified occurs outside the document root.");
                                //allow search to continue
                        }
                }
                //Check absolute paths and then verify the real path is under doc root
                $absolute = $this->realpath('/' . $src);
                if($absolute && file_exists($absolute)){ //realpath does file_exists check, so can probably skip the exists check here
                        $this->debug(3, "Found absolute path: $absolute");
                        if(! $this->docRoot){ $this->sanityFail("docRoot not set when checking absolute path."); }
                        if(stripos($absolute, $this->docRoot) === 0){
                                return $absolute;
                        } else {
                                $this->debug(1, "Security block: The file specified occurs outside the document root.");
                                //and continue search
                        }
                }

                $base = $this->docRoot;

                // account for Windows directory structure
                if (strstr($_SERVER['SCRIPT_FILENAME'],':')) {
                        $sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
                } else {
                        $sub_directories = explode('/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
                }

                foreach ($sub_directories as $sub){
                        $base .= $sub . '/';
                        $this->debug(3, "Trying file as: " . $base . $src);
                        if(file_exists($base . $src)){
                                $this->debug(3, "Found file as: " . $base . $src);
                                $real = $this->realpath($base . $src);
                                if(stripos($real, $this->realpath($this->docRoot)) === 0){
                                        return $real;
                                } else {
                                        $this->debug(1, "Security block: The file specified occurs outside the document root.");
                                        //And continue search
                                }
                        }
                }

Routování:

public static function createRouter()
        {
                $router = new RouteList;
                $router[] = new Route('admin/<presenter>/<action>/<id>', array(
                        'module' => 'Core',
                        'presenter' => 'Homepage',
                        'action' => 'default',
                        'id' => NULL,
                ));
                $router[] = new Route('<category>', array(
                        'module' => 'Front',
                        'presenter' => 'Homepage',
                        'action' => 'category'
                ));
                $router[] = new Route('<category>/<article>', array(
                        'module' => 'Front',
                        'presenter' => 'Article',
                        'action' => 'view'
                ));
                $router[] = new Route('[<presenter>]', array(
                        'module' => 'Front',
                        'presenter' => 'Homepage',
                        'action' => 'default'
                ));
                return $router;
        }

Htaccess v rootu (asi k ničemuú

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)(\.)?(.*)?$
RewriteRule ^$ www/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)(\.)?(.*)?$
RewriteRule (.*) www/$1 [L]

Htaccess ve www

# Apache configuration file (see httpd.apache.org/docs/current/mod/quickreference.html)

# disable directory listing
<IfModule mod_autoindex.c>
        Options -Indexes
</IfModule>

# enable cool URL
<IfModule mod_rewrite.c>
        RewriteEngine On
        # RewriteBase /

        # prevents files starting with dot to be viewed by browser
        RewriteRule /\.|^\.(?!well-known/) - [F]

        # front controller
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz|map)$ index.php [L]
</IfModule>

# enable gzip compression
<IfModule mod_deflate.c>
        <IfModule mod_filter.c>
                AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json application/xml image/svg+xml
        </IfModule>
</IfModule>

Psal jsem na více fór, opravdu si s tímhle nevím rady.
Budu vděčný za jakoukoli pomoc, díky

 
Odpovědět
14.7.2016 23:53
Avatar
Michael Kufner:15.7.2016 0:06
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\.(?!well-known/) - [F]

Htaccess nerozumím ani za mák, ale zde by mohl být zakopaný pes (chápu to správně, že toto má zakázat zobrazování prohlížečům, tedy i scriptům) nebo ne?

 
Nahoru Odpovědět
15.7.2016 0:06
Avatar
Odpovídá na Michael Kufner
Josef Kuchař - Pepa489:15.7.2016 0:32

Ne tohle zabraňuje, aby jsi mohl zobrazit soubor, jehož název začíná tečkou ;)

Editováno 15.7.2016 0:33
Nahoru Odpovědět
15.7.2016 0:32
2x piš, jednou debuguj
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 3 zpráv z 3.