Skip to content

Commit bd3c166

Browse files
authored
Merge pull request #326 from cosmocode/fixSmileysToLocal
Fix text replacement images (eg. smileys or FIXME)
2 parents df7cdd8 + dd38f5b commit bd3c166

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

DokuImageProcessorDecorator.class.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class DokuImageProcessorDecorator extends \Mpdf\Image\ImageProcessor {
1111
* takes care of checking image ACls.
1212
*/
1313
public function getImage (&$file, $firsttime = true, $allowvector = true, $orig_srcpath = false, $interpolation = false) {
14+
list($file, $orig_srcpath) = self::adjustGetImageLinks($file, $orig_srcpath);
15+
16+
return parent::getImage($file, $firsttime, $allowvector, $orig_srcpath, $interpolation);
17+
}
18+
19+
20+
public static function adjustGetImageLinks($file, $orig_srcpath) {
1421
global $conf;
1522

1623
// build regex to parse URL back to media info
@@ -67,7 +74,7 @@ public function getImage (&$file, $firsttime = true, $allowvector = true, $orig_
6774
$local = media_resize_image($local, $ext, $w, $h);
6875
}
6976
}
70-
} elseif(media_isexternal($file)) { // fixed external URLs
77+
} elseif(!file_exists($local) && media_isexternal($file)) { // fixed external URLs
7178
$local = media_get_from_URL($file, $ext, $conf['cachetime']);
7279
}
7380

@@ -77,6 +84,6 @@ public function getImage (&$file, $firsttime = true, $allowvector = true, $orig_
7784
}
7885
}
7986

80-
return parent::getImage($file, $firsttime, $allowvector, $orig_srcpath, $interpolation);
87+
return [$file, $orig_srcpath];
8188
}
8289
}

_test/DokuImageProcessor.test.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
require __DIR__ . '/../DokuImageProcessorDecorator.class.php';
5+
6+
/**
7+
* General tests for the imagemap plugin
8+
*
9+
* @group plugin_dw2pdf
10+
* @group plugins
11+
*/
12+
class dw2pdf_getImage_test extends DokuWikiTest
13+
{
14+
15+
/**
16+
* @return array the Testdata
17+
*/
18+
public function provideGetImageTestdata() {
19+
global $conf;
20+
$conf['mediadir'];
21+
return [
22+
[
23+
DOKU_URL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
24+
DOKU_REL . 'lib/exe/fetch.php?tok=b0b7a3&media=http%3A%2F%2Fphp.net%2Fimages%2Fphp.gif',
25+
'http://php.net/images/php.gif',
26+
'http://php.net/images/php.gif',
27+
'external image',
28+
],
29+
[
30+
DOKU_URL . 'lib/images/smileys/fixme.gif',
31+
DOKU_REL . 'lib/images/smileys/fixme.gif',
32+
DOKU_INC . 'lib/images/smileys/fixme.gif',
33+
DOKU_INC . 'lib/images/smileys/fixme.gif',
34+
'Replacement image / smiley',
35+
],
36+
[
37+
DOKU_URL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
38+
DOKU_REL . 'lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
39+
$conf['mediadir'] . '/wiki/dokuwiki-128.png',
40+
$conf['mediadir'] . '/wiki/dokuwiki-128.png',
41+
'Internal image',
42+
],
43+
];
44+
}
45+
46+
/**
47+
* @dataProvider provideGetImageTestdata
48+
*
49+
* @param $input_file
50+
* @param $input_orig_srcpath
51+
* @param $expected_file
52+
* @param $expected_orig_srcpath
53+
* @param $msg
54+
*/
55+
public function testGetImage($input_file, $input_orig_srcpath, $expected_file, $expected_orig_srcpath, $msg)
56+
{
57+
58+
list($actual_file, $actual_orig_srcpath) = \DokuImageProcessorDecorator::adjustGetImageLinks($input_file,
59+
$input_orig_srcpath);
60+
61+
$this->assertEquals($expected_file, $actual_file, '$file ' . $msg);
62+
$this->assertEquals($expected_orig_srcpath, $actual_orig_srcpath, '$orig_srcpath ' . $msg);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)