]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/MOBIClass/PreprocessedArticle.php
4 * Description of OnlineArticle
8 class PreprocessedArticle
extends ContentProvider
{
11 private $metadata = array();
12 private $imgCounter = 0;
14 public function __construct($textData, $imageLinks, $metadata) {
15 $this->text
= $textData;
16 $this->metadata
= $metadata;
18 $this->images
= $this->downloadImages($imageLinks);
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"}}
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
30 static public function CreateFromJson($json){
31 $data = json_decode($json);
32 return new PreprocessedArticle($data["text"], $data["images"], $data["metadata"]);
36 * Get the text data to be integrated in the MOBI file
39 public function getTextData(){
43 * Get the images (an array containing the jpeg data). Array entry 0 will
44 * correspond to image record 0.
47 public function getImages(){
51 * Get the metadata in the form of a hashtable (for example, title or author).
54 public function getMetaData(){
55 return $this->metadata
;
59 * @param DOMElement $dom
62 private function downloadImages($links){
64 foreach($links as $link) {
65 $imgFile = @imagecreatefromstring(Http
::Request($link));
67 if($imgFile === false){
68 $imgFile = @imagecreate(1, 1);
69 $black = @imagecolorallocate($imgFile, 255, 255, 255);
71 if($imgFile !== false){
72 @imagefilter($imgFile, IMG_FILTER_GRAYSCALE
);
76 $image = ob_get_contents();
79 $images[$this->imgCounter
] = new FileRecord(new Record($image));
80 imagedestroy($imgFile);