mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
various improvements to image handling .. still some places to fix
This commit is contained in:
parent
3541ea8ec8
commit
c4e72819a6
|
|
@ -255,7 +255,7 @@ trait ParsedownGravTrait
|
|||
$medium->urlHash($url['fragment']);
|
||||
}
|
||||
|
||||
$excerpt['element'] = $medium->parseDownElement($title, $alt, $class);
|
||||
$excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true);
|
||||
|
||||
} else {
|
||||
// not a current page media file, see if it needs converting to relative
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace Grav\Common\Page\Medium;
|
||||
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Data\Blueprint;
|
||||
|
||||
class ImageMedium extends Medium
|
||||
|
|
@ -136,7 +137,15 @@ class ImageMedium extends Medium
|
|||
*/
|
||||
public function url($reset = true)
|
||||
{
|
||||
$output = preg_replace('|^' . preg_quote(GRAV_ROOT) . '|', '', $this->saveImage());
|
||||
$pages_dir = self::$grav['locator']->findResource('page://');
|
||||
$image_path = self::$grav['locator']->findResource('cache://images', true);
|
||||
$image_dir = self::$grav['locator']->findResource('cache://images', false);
|
||||
|
||||
$output = preg_replace('|^' . preg_quote($pages_dir) . '|', '', $this->saveImage());
|
||||
|
||||
if (Utils::startsWith($output, $image_path)) {
|
||||
$output = '/' . $image_dir . preg_replace('|^' . preg_quote($image_path) . '|', '', $output);
|
||||
}
|
||||
|
||||
if ($reset) {
|
||||
$this->reset();
|
||||
|
|
@ -155,6 +164,7 @@ class ImageMedium extends Medium
|
|||
if (!$this->image) {
|
||||
$this->image();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -261,6 +271,7 @@ class ImageMedium extends Medium
|
|||
if ($this->image) {
|
||||
$this->image();
|
||||
$this->image->clearOperations(); // Clear previously applied operations
|
||||
$this->querystring('');
|
||||
$this->filter();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class Medium extends Data implements RenderableInterface
|
|||
*/
|
||||
public function querystring($querystring = null, $withQuestionmark = true)
|
||||
{
|
||||
if ($querystring) {
|
||||
if (!is_null($querystring)) {
|
||||
$this->set('querystring', ltrim($querystring, '?&'));
|
||||
|
||||
foreach ($this->alternatives as $alt) {
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 153 KiB After Width: | Height: | Size: 153 KiB |
BIN
tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg
Normal file
BIN
tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
|
|
@ -71,19 +71,63 @@ class MarkdownTest extends \Codeception\TestCase\Test
|
|||
{
|
||||
}
|
||||
|
||||
public function testSlugRelativeImages()
|
||||
public function testImages()
|
||||
{
|
||||
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
|
||||
|
||||
// * up and down with anchor 
|
||||
// * up more and down more 
|
||||
// * just down 
|
||||
// * down more 
|
||||
$this->assertSame('<p><img src="/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testImagesSubDir()
|
||||
{
|
||||
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
|
||||
|
||||
$this->assertSame('<p><img src="/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testImagesAbsoluteUrls()
|
||||
{
|
||||
$this->config->set('system.absolute_urls', true);
|
||||
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
|
||||
|
||||
// $this->assertSame('<p><img src="http://testing.dev/images/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
// $this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testImagesSubDirAbsoluteUrls()
|
||||
{
|
||||
$this->config->set('system.absolute_urls', true);
|
||||
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
|
||||
|
||||
// $this->assertSame('<p><img src="http://testing.dev/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
// $this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-sample-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
|
||||
|
||||
$this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
|
||||
$this->parsedown->text('[cnn.com](http://www.cnn.com)'));
|
||||
$this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
|
||||
$this->parsedown->text('[google.com](https://www.google.com)'));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user