Skip to content

Commit 4fc9a03

Browse files
committed
Force encoding
Before, there was some characters that were incorrectly processed. Thus the output was filled with rubish symbols. Now, every output is processed with a specific encoding to avoid that issue. Fix #7
1 parent 8c27c57 commit 4fc9a03

5 files changed

+10
-10
lines changed

Content.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public function __construct($content) {
1616
$this->content = $content;
1717
$this->raw = $content;
1818

19-
$this->dom = new \DomDocument();
20-
$this->dom->loadHTML($content, LIBXML_NOERROR);
19+
$this->dom = new \DomDocument('1.0', 'UTF-8');
20+
$this->dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
2121

2222
$this->splitContent();
2323
$this->extractMetadata();
@@ -127,4 +127,4 @@ private function extractReal() {
127127
$this->real = $this->dom->saveHTML($node);
128128
}
129129
}
130-
}
130+
}

Transformer/AbstractTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function getOriginComment($origin) {
3535
* @return \DomDocument
3636
*/
3737
protected function generateDom($origin, $media = []) {
38-
$dom = new \DomDocument();
38+
$dom = new \DomDocument('1.0', 'UTF-8');
3939

4040
$div = $dom->appendChild($dom->createElement('div'));
4141
$div->setAttribute('class', 'reddit-image figure');

Transformer/DisplayTransformer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ private function getPreprocessedContent($content) {
6161
return $preprocessed;
6262
}
6363

64-
$dom = new \DomDocument();
65-
$dom->loadHTML($preprocessed, LIBXML_NOERROR);
64+
$dom = new \DomDocument('1.0', 'UTF-8');
65+
$dom->loadHTML(mc_convert_encoding($preprocessed, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
6666

6767
$videos = $dom->getElementsByTagName('video');
6868
foreach ($videos as $video) {
@@ -164,7 +164,7 @@ private function isAccessible($href) {
164164
* @return string
165165
*/
166166
private function getNewLinkContent($href) {
167-
$dom = new \DomDocument();
167+
$dom = new \DomDocument('1.0', 'UTF-8');
168168

169169
$p = $dom->appendChild($dom->createElement('p'));
170170
$a = $p->appendChild($dom->createElement('a'));

Transformer/InsertTransformer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public function transform($entry) {
130130
$dom = $this->generateDom('Imgur gallery with API token', $media);
131131
$entry->_content("{$dom->saveHTML()}{$content->getRaw()}");
132132
} else {
133-
$galleryDom = new \DomDocument();
134-
$galleryDom->loadHTML(file_get_contents($href), LIBXML_NOERROR);
133+
$galleryDom = new \DomDocument('1.0', 'UTF-8');
134+
$galleryDom->loadHTML(mb_convert_encoding(file_get_contents($href), 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
135135
$galleryXpath = new \DomXpath($galleryDom);
136136
$images = $galleryXpath->query("//meta[@name='twitter:image']");
137137
foreach ($images as $image) {

metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Reddit Image",
33
"author": "Alexis Degrugillier",
44
"description": "Modify reddit entries by displaying known medias and easing access to the linked resource",
5-
"version": "0.12.2",
5+
"version": "0.12.3",
66
"entrypoint": "RedditImage",
77
"type": "user"
88
}

0 commit comments

Comments
 (0)