diff options
author | Thomas Citharel <tcit@tcit.fr> | 2014-12-14 00:16:39 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2014-12-14 00:16:39 +0100 |
commit | 1256e4c645c86f4165d052bf8116b957b373b837 (patch) | |
tree | 3cc3bd960df403a6e0645afcd9e4f5bbb68bfc0e /inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php | |
parent | 9c55ed0923273da886497cb62302a79622e34a74 (diff) | |
parent | dc69d3e8d895c87f9d26c2d1309e40d6090d4c8d (diff) | |
download | wallabag-1256e4c645c86f4165d052bf8116b957b373b837.tar.gz wallabag-1256e4c645c86f4165d052bf8116b957b373b837.tar.zst wallabag-1256e4c645c86f4165d052bf8116b957b373b837.zip |
Merge branch 'tcitworld-ebook' into dev
Diffstat (limited to 'inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php')
-rw-r--r-- | inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php b/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php new file mode 100644 index 00000000..2e992404 --- /dev/null +++ b/inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php | |||
@@ -0,0 +1,89 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of OnlineArticle | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class PreprocessedArticle extends ContentProvider { | ||
9 | private $text; | ||
10 | private $images; | ||
11 | private $metadata = array(); | ||
12 | private $imgCounter = 0; | ||
13 | |||
14 | public function __construct($textData, $imageLinks, $metadata) { | ||
15 | $this->text = $textData; | ||
16 | $this->metadata = $metadata; | ||
17 | |||
18 | $this->images = $this->downloadImages($imageLinks); | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * Create a Preprocessed article from a json string | ||
23 | * @param string $json JSON data. Should be of the following format: | ||
24 | * {"text": "TEXT", "images: ["imageURL1", "imageURL2"], "metadata": {"key": "value"}} | ||
25 | * | ||
26 | * Note: Any image tags should have the recindex attribute set to the appropriate index (the | ||
27 | * same index as the image in the array) | ||
28 | * @return PreprocessedArticle The generated preprocessed array | ||
29 | */ | ||
30 | static public function CreateFromJson($json){ | ||
31 | $data = json_decode($json); | ||
32 | return new PreprocessedArticle($data["text"], $data["images"], $data["metadata"]); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Get the text data to be integrated in the MOBI file | ||
37 | * @return string | ||
38 | */ | ||
39 | public function getTextData(){ | ||
40 | return $this->text; | ||
41 | } | ||
42 | /** | ||
43 | * Get the images (an array containing the jpeg data). Array entry 0 will | ||
44 | * correspond to image record 0. | ||
45 | * @return array | ||
46 | */ | ||
47 | public function getImages(){ | ||
48 | return $this->images; | ||
49 | } | ||
50 | /** | ||
51 | * Get the metadata in the form of a hashtable (for example, title or author). | ||
52 | * @return array | ||
53 | */ | ||
54 | public function getMetaData(){ | ||
55 | return $this->metadata; | ||
56 | } | ||
57 | /** | ||
58 | * | ||
59 | * @param DOMElement $dom | ||
60 | * @return array | ||
61 | */ | ||
62 | private function downloadImages($links){ | ||
63 | $images = array(); | ||
64 | foreach($links as $link) { | ||
65 | $imgFile = @imagecreatefromstring(Http::Request($link)); | ||
66 | |||
67 | if($imgFile === false){ | ||
68 | $imgFile = @imagecreate(1, 1); | ||
69 | $black = @imagecolorallocate($imgFile, 255, 255, 255); | ||
70 | } | ||
71 | if($imgFile !== false){ | ||
72 | @imagefilter($imgFile, IMG_FILTER_GRAYSCALE); | ||
73 | |||
74 | ob_start(); | ||
75 | @imagejpeg($imgFile); | ||
76 | $image = ob_get_contents(); | ||
77 | ob_end_clean(); | ||
78 | |||
79 | $images[$this->imgCounter] = new FileRecord(new Record($image)); | ||
80 | imagedestroy($imgFile); | ||
81 | |||
82 | $this->imgCounter++; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return $images; | ||
87 | } | ||
88 | } | ||
89 | ?> | ||