From fb9df0c269f36703909b8b259abbdbed29881ecd Mon Sep 17 00:00:00 2001
From: tcit ".$data." Para 1 Para 2 Para 1 Para 2 The story begins...".$this->settings["title"]."
";
+
+ list($text, $entries) = $this->generateText();
+
+ if($this->settings["toc"]) {
+ $toc = $this->generateTOC($entries); //Generate TOC to get the right length
+ $toc = $this->generateTOC($entries, strlen($prefix)+strlen($toc)+strlen($title)); //Generate the real TOC
+ }
+
+ $suffix = "";
+
+ return $prefix.$toc.$title.$text.$suffix;
+ }
+
+ /**
+ * Generate the body's text and the chapter entries
+ * @return array($string, $entries) $string is the html data, $entries
+ * contains the level, the title and the position of the titles.
+ */
+ public function generateText(){
+ $str = "";
+ $entries = array();
+
+ for($i = 0; $i < sizeof($this->parts); $i++){
+ list($type, $data) = $this->parts[$i];
+ $id = "title_".$i;
+ switch($type){
+ case self::PARAGRAPH:
+ $str .= "".$data."
";
+ break;
+ case self::H3:
+ $entries[] = array("level" => 3, "position" => strlen($str), "title" => $data, "id" => $id);
+ $str .= "".$data."
";
+ break;
+ case self::IMAGE:
+ $str .= "";
+ break;
+ }
+ }
+ return array($str, $entries);
+ }
+
+ /**
+ * Generate a TOC
+ * @param $entries The entries array generated by generateText
+ * @param $base The zero position
+ */
+ public function generateTOC($entries, $base = 0){
+ $toc = "
Contents
";
+ $toc .= " ";
+ }
+ return $toc."".$entry["title"]." Contents
";
+ $toc .= "
";
+
+ return $toc;
+ }
+ /**
+ * Get the images (an array containing the jpeg data). Array entry 0 will
+ * correspond to image record 0.
+ * @return array
+ */
+ public function getImages(){
+ return $this->images;
+ }
+
+ /**
+ * Get the metadata in the form of a hashtable (for example, title or author).
+ * @return array
+ */
+ public function getMetaData(){
+ return $this->metadata;
+ }
+
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php b/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php
new file mode 100644
index 00000000..ec3182fe
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/OnlineArticle.php
@@ -0,0 +1,116 @@
+init();
+ if(!isset($this->metadata["title"])){
+ $this->metadata["title"] = CharacterEntities::convert(strip_tags($r->getTitle()->innerHTML));
+ }
+ if(!isset($this->metadata["author"])){
+ $parts = parse_url($url);
+ $this->metadata["author"] = $parts["host"];
+ }
+
+ $article = $r->getContent()->innerHTML;
+ if(substr($article, 0, 5) == "".$article."";
+ }else{
+ $article = "".$article."";
+ }
+ $doc = new DOMDocument();
+ @$doc->loadHTML($article) or die($article);
+ $doc->normalizeDocument();
+
+ $this->images = $this->handleImages($doc, $url);
+ $this->text = $doc->saveHTML();
+ }
+
+ /**
+ * Get the text data to be integrated in the MOBI file
+ * @return string
+ */
+ public function getTextData(){
+ return $this->text;
+ }
+ /**
+ * Get the images (an array containing the jpeg data). Array entry 0 will
+ * correspond to image record 0.
+ * @return array
+ */
+ public function getImages(){
+ return $this->images;
+ }
+ /**
+ * Get the metadata in the form of a hashtable (for example, title or author).
+ * @return array
+ */
+ public function getMetaData(){
+ return $this->metadata;
+ }
+ /**
+ *
+ * @param DOMElement $dom
+ * @return array
+ */
+ private function handleImages($dom, $url){
+ $images = array();
+
+ $parts = parse_url($url);
+
+ $savedImages = array();
+
+ $imgElements = $dom->getElementsByTagName('img');
+ foreach($imgElements as $img) {
+ $src = $img->getAttribute("src");
+
+ $is_root = false;
+ if(substr($src, 0, 1) == "/"){
+ $is_root = true;
+ }
+
+ $parsed = parse_url($src);
+
+ if(!isset($parsed["host"])){
+ if($is_root){
+ $src = http_build_url($url, $parsed, HTTP_URL_REPLACE);
+ }else{
+ $src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH);
+ }
+ }
+ $img->setAttribute("src", "");
+ if(isset($savedImages[$src])){
+ $img->setAttribute("recindex", $savedImages[$src]);
+ }else{
+ $image = ImageHandler::DownloadImage($src);
+
+ if($image !== false){
+ $images[$this->imgCounter] = new FileRecord(new Record($image));
+
+ $img->setAttribute("recindex", $this->imgCounter);
+ $savedImages[$src] = $this->imgCounter;
+ $this->imgCounter++;
+ }
+ }
+ }
+
+ return $images;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/PalmRecord.php b/inc/3rdparty/libraries/MOBIClass/PalmRecord.php
new file mode 100644
index 00000000..d0de8dfe
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/PalmRecord.php
@@ -0,0 +1,136 @@
+elements = new FileElement(array(
+ "compression"=>new FileShort(),
+ "unused"=>new FileShort(),
+ "textLength"=>new FileInt(),
+ "recordCount"=>new FileShort(),
+ "recordSize"=>new FileShort(),
+ "encryptionType"=>new FileShort(),
+ "unused2"=>new FileShort(),
+ //MOBI Header
+ "mobiIdentifier"=>new FileString("MOBI", 4),
+ "mobiHeaderLength"=>new FileInt(),
+ "mobiType"=>new FileInt(),
+ "textEncoding"=>new FileInt(),
+ "uniqueID"=>new FileInt(),
+ "fileVersion"=>new FileInt(),
+ "reserved"=>new FileString(40),
+ "firstNonBookIndex"=>new FileInt(),
+ "fullNameOffset"=>new FileInt(),
+ "fullNameLength"=>new FileInt(),
+ "locale"=>new FileInt(),
+ "inputLanguage"=>new FileInt(),
+ "outputLanguage"=>new FileInt(),
+ "minimumVersion"=>new FileInt(),
+ "firstImageIndex"=>new FileInt(),
+ "huffmanRecordOffset"=>new FileInt(),
+ "huffmanRecordCount"=>new FileInt(),
+ "unused3"=>new FileString(8),
+ "exthFlags"=>new FileInt(0x40),
+ "unknown"=>new FileString(32),
+ "drmOffset"=>new FileInt(0xFFFFFFFF),
+ "drmCount"=>new FileShort(0xFFFFFFFF),
+ "drmSize"=>new FileShort(),
+ "drmFlags"=>new FileInt(),
+ "mobiFiller"=>new FileString(72),
+ //EXTH Header
+ "exthIdentifier"=>new FileString("EXTH", 4),
+ "exthHeaderLength"=>new FileInt(),
+ "exthRecordCount"=>new FileInt(),
+ "exthRecords"=>new FileElement(),
+ "exthPadding"=>new FileString(),
+ //"fullNamePadding"=>new FileString(100),
+ "fullName"=>new FileString()
+ ));
+
+ //Set values from the info block
+ foreach($settings->values as $name => $val){
+ //echo $name.", ";
+ if($this->elements->exists($name)){
+ $this->elements->get($name)->set($settings->get($name));
+ }
+ }
+
+ $els = $settings->values;
+
+ $exthElems = new FileElement();
+ $i = 0;
+ $l = 0;
+ foreach($els as $name=>$val){
+ $type = EXTHHelper::textToType($name);
+ if($type !== false){
+ $type = new FileInt($type);
+ $length = new FileInt(8+strlen($val));
+ $data = new FileString($val);
+ $l += 8+strlen($val);
+ $exthElems->add("type".$i, $type);
+ $exthElems->add("length".$i, $length);
+ $exthElems->add("data".$i, $data);
+ $i++;
+ }
+ }
+
+ if($images > 0){
+ $this->elements->get("firstImageIndex")->set($textRecords+1);
+ }
+ $this->elements->get("firstNonBookIndex")->set($textRecords+2+$images);
+ $this->elements->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT));
+ $this->elements->get("exthRecordCount")->set($i);
+ $this->elements->set("exthRecords", $exthElems);
+ $pad = $l%4;
+ $pad = (4-$pad)%4;
+ $this->elements->get("exthPadding")->set(str_pad("", $pad, "\0", STR_PAD_RIGHT));
+ $this->elements->get("exthHeaderLength")->set(12+$l+$pad);
+
+
+ $this->elements->get("recordCount")->set($textRecords);
+
+ $this->elements->get("fullNameOffset")->set($this->elements->offsetToEntry("fullName"));
+ $this->elements->get("fullNameLength")->set(strlen($settings->get("title")));
+ $this->elements->get("fullName")->set($settings->get("title"));
+ $this->elements->get("textLength")->set($textLength);
+ }
+
+ public function getByteLength(){
+ return $this->getLength();
+ }
+
+ public function getLength(){
+ return $this->elements->getByteLength();
+ }
+
+ public function get(){
+ return $this;
+ }
+
+ public function set($elements){
+ throw new Exception("Unallowed set");
+ }
+
+ public function serialize() {
+ return $this->elements->serialize();
+ }
+
+ public function unserialize($data) {
+ $this->elements->unserialize($data);
+ }
+
+ public function __toString(){
+ $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
+ $output .= $this->elements;
+ return $output;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/Prc.php b/inc/3rdparty/libraries/MOBIClass/Prc.php
new file mode 100644
index 00000000..c40b5805
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/Prc.php
@@ -0,0 +1,97 @@
+new FileString(32),
+ "attributes"=>new FileShort(),
+ "version"=>new FileShort(),
+ "creationTime"=>new FileDate(),
+ "modificationTime"=>new FileDate(),
+ "backupTime"=>new FileDate(),
+ "modificationNumber"=>new FileInt(),
+ "appInfoID"=>new FileInt(),
+ "sortInfoID"=>new FileInt(),
+ "prcType"=>new FileString(4),
+ "creator"=>new FileString(4),
+ "uniqueIDSeed"=>new FileInt(),
+ "nextRecordListID"=>new FileInt(),
+ "numberRecords"=>new FileShort(),
+ "recordList"=>new FileElement(),
+ "filler"=>new FileShort(),
+ "records"=>new FileElement()
+ ));
+
+ //Set values from the info block
+ foreach($this->elements as $name => $val){
+ if($settings->exists($name)){
+ $this->get($name)->set($settings->get($name));
+ }
+ }
+
+ $this->get("numberRecords")->set(sizeof($records));
+
+ $i = 0;
+ foreach($records as $record){
+ $offset = new FileInt();
+ $attr = new FileByte();
+ $uniqueID = new FileTri($i);
+
+ $this->elements["recordList"]->add("Rec".$i, new FileElement(array(
+ "offset"=>$offset,
+ "attribute"=>$attr,
+ "uniqueID"=>$uniqueID
+ )));
+
+ $this->elements["records"]->add("Rec".$i, $record);
+ $i++;
+ }
+
+ $this->updateOffsets($records);
+ }
+
+ public function getByteLength(){
+ throw new Exception("Test");
+ }
+
+ public function updateOffsets($records){
+ $base = $this->offsetToEntry("records");
+
+ $i = 0;
+
+ foreach($records as $record){
+ $el = $this->elements["recordList"]->get("Rec".$i);
+
+ $local = $this->elements["records"]->offsetToEntry("Rec".$i);
+
+ $el->get("offset")->set($base+$local);
+
+ $i++;
+ }
+ }
+
+ public function save($file){
+ $handle = fopen($file, "w");
+ fwrite($handle, $this->serialize());
+ fclose($handle);
+ }
+
+ public function output(){
+ echo $this->serialize();
+ }
+
+ public function __toString(){
+ $output = "Prc (".$this->getByteLength()." bytes): {\n";
+ foreach($this->elements as $key=>$value){
+ $output .= "\t".$key.": ".$value."\n";
+ }
+ $output .= "}";
+ return $output;
+ }
+}
+?>
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 @@
+text = $textData;
+ $this->metadata = $metadata;
+
+ $this->images = $this->downloadImages($imageLinks);
+ }
+
+ /**
+ * Create a Preprocessed article from a json string
+ * @param string $json JSON data. Should be of the following format:
+ * {"text": "TEXT", "images: ["imageURL1", "imageURL2"], "metadata": {"key": "value"}}
+ *
+ * Note: Any image tags should have the recindex attribute set to the appropriate index (the
+ * same index as the image in the array)
+ * @return PreprocessedArticle The generated preprocessed array
+ */
+ static public function CreateFromJson($json){
+ $data = json_decode($json);
+ return new PreprocessedArticle($data["text"], $data["images"], $data["metadata"]);
+ }
+
+ /**
+ * Get the text data to be integrated in the MOBI file
+ * @return string
+ */
+ public function getTextData(){
+ return $this->text;
+ }
+ /**
+ * Get the images (an array containing the jpeg data). Array entry 0 will
+ * correspond to image record 0.
+ * @return array
+ */
+ public function getImages(){
+ return $this->images;
+ }
+ /**
+ * Get the metadata in the form of a hashtable (for example, title or author).
+ * @return array
+ */
+ public function getMetaData(){
+ return $this->metadata;
+ }
+ /**
+ *
+ * @param DOMElement $dom
+ * @return array
+ */
+ private function downloadImages($links){
+ $images = array();
+ foreach($links as $link) {
+ $imgFile = @imagecreatefromstring(Http::Request($link));
+
+ if($imgFile === false){
+ $imgFile = @imagecreate(1, 1);
+ $black = @imagecolorallocate($imgFile, 255, 255, 255);
+ }
+ if($imgFile !== false){
+ @imagefilter($imgFile, IMG_FILTER_GRAYSCALE);
+
+ ob_start();
+ @imagejpeg($imgFile);
+ $image = ob_get_contents();
+ ob_end_clean();
+
+ $images[$this->imgCounter] = new FileRecord(new Record($image));
+ imagedestroy($imgFile);
+
+ $this->imgCounter++;
+ }
+ }
+
+ return $images;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php b/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php
new file mode 100644
index 00000000..6319ed57
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/RecognizeURL.php
@@ -0,0 +1,16 @@
+
diff --git a/inc/3rdparty/libraries/MOBIClass/Record.php b/inc/3rdparty/libraries/MOBIClass/Record.php
new file mode 100644
index 00000000..3cb39582
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/Record.php
@@ -0,0 +1,96 @@
+data = $data;
+ if($length >= 0){
+ $this->length = $length;
+ }else{
+ $this->length = strlen($data);
+ }
+ }
+
+ public function compress($compression_method){
+ switch($compression_method){
+ case NO_COMPRESSION:
+ //Finished!
+ break;
+ case PALMDOC_COMPRESSION:
+ throw new Exception("Not implemented yet");
+ break;
+ case HUFF:
+ throw new Exception("Not implemented yet");
+ break;
+ default:
+ throw new Exception("Invalid argument");
+ }
+ }
+
+ public function getByteLength(){
+ return $this->getLength();
+ }
+
+ /**
+ * Get the length of the record
+ * @return int Length of the data
+ */
+ public function getLength(){
+ return $this->length;
+ }
+
+ /**
+ * Get the data contained in the record
+ * @return string Data contained in the record
+ */
+ public function get(){
+ return $this->data;
+ }
+
+ /**
+ * Set the data contained in the record
+ * @param string $value Data contained in the record
+ */
+ public function set($value){
+ $this->data = $value;
+ }
+
+ public function serialize(){
+ return $this->data;
+ }
+ public function unserialize($data){
+ __construct($data);
+ }
+
+ public function __toString() {
+ $toShow = $this->data;
+ if(strlen($this->data) > 103){
+ $toShow = substr($this->data, 0, 100)."...";
+ }
+ $out = "Record: {\n";
+ $out .= "\t".htmlspecialchars($toShow)."\n";
+ $out .= "}";
+ return $out;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/RecordFactory.php b/inc/3rdparty/libraries/MOBIClass/RecordFactory.php
new file mode 100644
index 00000000..12806fe3
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/RecordFactory.php
@@ -0,0 +1,115 @@
+settings = $settings;
+ }
+
+ /**
+ * Create records from a data string
+ * @param string $data
+ * @return array(Record)
+ */
+ public function createRecords($data){
+ $records = array();
+ $size = $this->settings->get("recordSize");
+ $compression = $this->settings->get("compression");
+
+ $dataEntries = mb_str_split($data, $size);
+
+ for($i = 0, $len = sizeof($dataEntries); $i < $len; $i++){
+ $records[$i] = new Record($dataEntries[$i]);
+ $records[$i]->compress($compression);
+ }
+
+ return $records;
+ }
+
+ public function createEOFRecord(){
+ return new Record(0xe98e0d0a);
+ }
+
+ public function createFCISRecord($textLength){
+ $r = "FCIS";
+ $r .= $this->asString(20, 4);
+ $r .= $this->asString(16, 4);
+ $r .= $this->asString(1, 4);
+ $r .= $this->asString(0, 4);
+ $r .= $this->asString($textLength, 4);
+ $r .= $this->asString(0, 4);
+ $r .= $this->asString(32, 4);
+ $r .= $this->asString(8, 4);
+ $r .= $this->asString(1, 2);
+ $r .= $this->asString(1, 2);
+ $r .= $this->asString(0, 4);
+ return new Record($r);
+ }
+
+ public function createFLISRecord(){
+ $r = "FLIS";
+ $r .= $this->asString(8, 4);
+ $r .= $this->asString(65, 2);
+ $r .= $this->asString(0, 2);
+ $r .= $this->asString(0, 4);
+ $r .= $this->asString(-1, 4);
+ $r .= $this->asString(1, 2);
+ $r .= $this->asString(3, 2);
+ $r .= $this->asString(3, 4);
+ $r .= $this->asString(1, 4);
+ $r .= $this->asString(-1, 4);
+ return new Record($r);
+ }
+
+ private function asString($int, $size){
+ $out = "";
+ for($i = 0; $i < $size; $i++){
+ if($i > 0) $out = " ".$out;
+ $byte = dechex($int & 0xFF);
+ if(strlen($byte) == 1) $byte = "0".$byte;
+ $out = $byte.$out;
+ $int = $int >> 8;
+ }
+ return $out;
+ }
+
+ public function __toString() {
+ $out = "Record Factory: {\n";
+ $out .= "\tRecord Size: ".$this->settings->get("recordSize")."\n";
+ $out .= "\tCompression: ".$this->settings->get("compression")."\n";
+ $out .= "}";
+ return $out;
+ }
+}
+function mb_str_split($string, $split_length = 1){
+ mb_internal_encoding('UTF-8');
+ mb_regex_encoding('UTF-8');
+
+ $split_length = ($split_length <= 0) ? 1 : $split_length;
+
+ $mb_strlen = mb_strlen($string, 'utf-8');
+
+ $array = array();
+
+ for($i = 0; $i < $mb_strlen; $i += $split_length){
+ $array[] = mb_substr($string, $i, $split_length);
+ }
+
+ return $array;
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/Settings.php b/inc/3rdparty/libraries/MOBIClass/Settings.php
new file mode 100644
index 00000000..ddcf2054
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/Settings.php
@@ -0,0 +1,97 @@
+values = array(
+ "attributes"=>0,
+ "version"=>0,
+ "creationTime"=>time()+94694400,
+ "modificationTime"=>time()+94694400,
+ "backupTime"=>0,
+ "modificationNumber"=>0,
+ "appInfoID"=>0,
+ "sortInfoID"=>0,
+ "prcType"=>"BOOK",
+ "creator"=>"MOBI",
+ "uniqueIDSeed"=>rand(),
+ "nextRecordListID"=>0,
+ "recordAttributes"=>0,
+ "compression"=>NO_COMPRESSION,
+ "recordSize"=>RECORD_SIZE,
+ "encryptionType"=>NO_ENCRYPTION,
+ "mobiIdentifier"=>"MOBI",
+ "mobiHeaderLength"=>0xe8,
+ "mobiType"=>MOBIPOCKET_BOOK,
+ "textEncoding"=>UTF8,
+ "uniqueID"=>rand(),
+ "fileVersion"=>6,
+ "locale"=>0x09,
+ "inputLanguage"=>0,
+ "outputLanguage"=>0,
+ "minimumVersion"=>6,
+ "huffmanRecordOffset"=>0,
+ "huffmanRecordCount"=>0,
+ "exthFlags"=>0x40,
+ "drmOffset"=>0xFFFFFFFF,
+ "drmCount"=>0,
+ "drmSize"=>0,
+ "drmFlags"=>0,
+ "extraDataFlags"=>0,
+ "exthIdentifier"=>"EXTH",
+ // These can be changed without any risk
+ "title"=>"Unknown title",
+ "author"=>"Unknown author",
+ "subject"=>"Unknown subject"
+ );
+
+ foreach($additionalSettings as $key=>$value){
+ $this->values[$key] = $value;
+ }
+ }
+
+ /**
+ * Get a value from the settings
+ * @param string $key Key of the setting
+ * @return mixed The value of the setting
+ */
+ public function get($key){
+ return $this->values[$key];
+ }
+
+ /**
+ * Checks if a value is set
+ * @param string $key Key of the setting
+ * @return bool True if the value exists
+ */
+ public function exists($key){
+ return isset($this->values[$key]);
+ }
+
+ public function __toString() {
+ $out = "Settings: {\n";
+ foreach($this->values as $key=>$value){
+ $out .= "\t".$key.": ".$value."\n";
+ }
+ $out .= "}";
+ return $out;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/constants.php b/inc/3rdparty/libraries/MOBIClass/constants.php
new file mode 100644
index 00000000..bd363118
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/constants.php
@@ -0,0 +1,11 @@
+id = intval(substr($ending, 0, strpos($ending, "/")));
+
+ for($i = 1; $i <= max(1, $this->chapterCount); $i++){
+ $this->addChapter($i);
+ }
+ }
+
+ private function addChapter($n){
+ $doc = new DOMDocument();
+ $file = Http::Request(self::$prefix.$this->id."/".$n."/");
+ @$doc->loadHTML($file) or die($file);
+
+ if(!$this->downloadedMetadata){
+ $this->loadMetadata($doc);
+ $this->downloadedMetadata = true;
+ }
+ if($this->chapterCount < 0){
+ $this->chapterCount = $this->getNumberChapters($doc);
+
+ if($this->chapterCount > 4){
+ die("Too many files to download, don't use php for this!");
+ }
+ }
+
+ $textEl = $doc->getElementById("storytext");
+ if($textEl == null) die("Error: ".$doc->saveHTML());
+ $horizontalRulebars = $doc->getElementsByTagName('hr');
+ /**
+ * @var DOMNode
+ */
+ $hr;
+ foreach($horizontalRulebars as $hr) {
+ $hr->setAttribute("size", null);
+ $hr->setAttribute("noshade", null);
+ }
+ $text = $this->innerHtml($textEl);
+
+ $title = "";
+ $selects = $doc->getElementsByTagName('select');
+ foreach($selects as $select) {
+ if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){
+ $options = $select->getElementsByTagName("option");
+
+ $test = $n.". ";
+ foreach($options as $option){
+ $val = $option->nodeValue;
+ if(substr($val, 0, strlen($test)) == $test){
+ $title = substr($val, strlen($test));
+ break;
+ }
+ }
+ break;
+ }
+ }
+ $this->addPage($text, $title);
+ }
+
+ private function getNumberChapters($doc){
+ $selects = $doc->getElementsByTagName('select');
+ foreach($selects as $select) {
+ if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){
+ $options = $select->getElementsByTagName("option");
+
+ $count = $options->length;
+ return $count;
+ }
+ }
+ }
+
+ private function loadMetadata($doc){
+ //Author
+ $links = $doc->getElementsByTagName('a');
+ foreach($links as $link) {
+ if($link == null){
+ var_dump($link);
+ }
+ if($link->hasAttribute("href") && substr($link->getAttribute("href"), 0, 3) == "/u/"){
+ $this->setMetadata("author", $link->nodeValue);
+ }
+ }
+ //Title
+ /*
+ $links = $doc->getElementsByTagName('link');
+ foreach($links as $link) {
+ if($link->hasAttribute("rel") && $link->getAttribute("rel") == "canonical"){
+ $url = $link->getAttribute("href");
+ $title = str_replace("_", " ", substr($url, strrpos($url, "/")+1));
+ $this->setMetadata("title", $title);
+ }
+ }*/
+
+ //TODO: Find a more reliable way to extract the title
+ $title = $doc->getElementsByTagName("b")->item(0)->nodeValue;
+ $this->setMetadata("title", $title);
+ }
+
+ private function innerHtml($node){
+ $doc = new DOMDocument();
+ foreach ($node->childNodes as $child)
+ $doc->appendChild($doc->importNode($child, true));
+
+ return $doc->saveHTML();
+ }
+
+ public static function Matches($url){
+ //TODO: Implement with regex
+ return strpos($url, self::$prefix) !== false;
+ }
+}
+?>
diff --git a/inc/3rdparty/libraries/MOBIClass/http_build_url.php b/inc/3rdparty/libraries/MOBIClass/http_build_url.php
new file mode 100644
index 00000000..b475edb0
--- /dev/null
+++ b/inc/3rdparty/libraries/MOBIClass/http_build_url.php
@@ -0,0 +1,94 @@
+registerNodeClass('DOMElement', 'JSLikeHTMLElement');
+* $doc->loadHTML(' ";
+ }
+ $toc .= "".($i+1).". ".$entry["title"]." Chapter 2
]*>[ \n\r\t]*){2,}/i',
+ 'replaceFonts' => '/<(\/?)font[^>]*>/i',
+ // 'trimRe' => '/^\s+|\s+$/g', // PHP has trim()
+ 'normalize' => '/\s{2,}/',
+ 'killBreaks' => '/(
(\s| ?)*){1,}/',
+ 'video' => '/http:\/\/(www\.)?(youtube|vimeo)\.com/i',
+ 'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i'
+ );
+
+ /* constants */
+ const FLAG_STRIP_UNLIKELYS = 1;
+ const FLAG_WEIGHT_CLASSES = 2;
+ const FLAG_CLEAN_CONDITIONALLY = 4;
+
+ /**
+ * Create instance of Readability
+ * @param string UTF-8 encoded string
+ * @param string (optional) URL associated with HTML (used for footnotes)
+ */
+ function __construct($html, $url=null)
+ {
+ /* Turn all double br's into p's */
+ /* Note, this is pretty costly as far as processing goes. Maybe optimize later. */
+ $html = preg_replace($this->regexps['replaceBrs'], '
', $html); + $html = preg_replace($this->regexps['replaceFonts'], '<$1span>', $html); + $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); + $this->dom = new DOMDocument(); + $this->dom->preserveWhiteSpace = false; + $this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); + @$this->dom->loadHTML($html); + $this->url = $url; + } + + /** + * Get article title element + * @return DOMElement + */ + public function getTitle() { + return $this->articleTitle; + } + + /** + * Get article content element + * @return DOMElement + */ + public function getContent() { + return $this->articleContent; + } + + /** + * Runs readability. + * + * Workflow: + * 1. Prep the document by removing script tags, css, etc. + * 2. Build readability's DOM tree. + * 3. Grab the article content from the current dom tree. + * 4. Replace the current DOM tree with the new one. + * 5. Read peacefully. + * + * @return boolean true if we found content, false otherwise + **/ + public function init() + { + $this->removeScripts($this->dom); + + // Assume successful outcome + $this->success = true; + + $bodyElems = $this->dom->getElementsByTagName('body'); + if ($bodyElems->length > 0) { + if ($this->bodyCache == null) { + $this->bodyCache = $bodyElems->item(0)->innerHTML; + } + if ($this->body == null) { + $this->body = $bodyElems->item(0); + } + } + + $this->prepDocument(); + + //die($this->dom->documentElement->parentNode->nodeType); + //$this->setInnerHTML($this->dom->documentElement, $this->getInnerHTML($this->dom->documentElement)); + //die($this->getInnerHTML($this->dom->documentElement)); + + /* Build readability's DOM tree */ + $overlay = $this->dom->createElement('div'); + $innerDiv = $this->dom->createElement('div'); + $articleTitle = $this->getArticleTitle(); + $articleContent = $this->grabArticle(); + + if (!$articleContent) { + $this->success = false; + $articleContent = $this->dom->createElement('div'); + $articleContent->setAttribute('id', 'readability-content'); + $articleContent->innerHTML = '
Sorry, Readability was unable to parse this page for content.
'; + } + + $overlay->setAttribute('id', 'readOverlay'); + $innerDiv->setAttribute('id', 'readInner'); + + /* Glue the structure of our document together. */ + $innerDiv->appendChild($articleTitle); + $innerDiv->appendChild($articleContent); + $overlay->appendChild($innerDiv); + + /* Clear the old HTML, insert the new content. */ + $this->body->innerHTML = ''; + $this->body->appendChild($overlay); + //document.body.insertBefore(overlay, document.body.firstChild); + $this->body->removeAttribute('style'); + + $this->postProcessContent($articleContent); + + // Set title and content instance variables + $this->articleTitle = $articleTitle; + $this->articleContent = $articleContent; + + return $this->success; + } + + /** + * Debug + */ + protected function dbg($msg) { + if ($this->debug) echo '* ',$msg, '').replace(readability.regexps.replaceFonts, '<$1span>'); + // We do this in the constructor for PHP as that's when we have raw HTML - before parsing it into a DOM tree. + // Manipulating innerHTML as it's done in JS is not possible in PHP. + } + + /** + * For easier reading, convert this document to have footnotes at the bottom rather than inline links. + * @see http://www.roughtype.com/archives/2010/05/experiments_in.php + * + * @return void + **/ + public function addFootnotes($articleContent) { + $footnotesWrapper = $this->dom->createElement('div'); + $footnotesWrapper->setAttribute('id', 'readability-footnotes'); + $footnotesWrapper->innerHTML = '
tags, etc.
+ *
+ * @param DOMElement
+ * @return void
+ */
+ function prepArticle($articleContent) {
+ $this->cleanStyles($articleContent);
+ $this->killBreaks($articleContent);
+ if ($this->revertForcedParagraphElements) {
+ $this->revertReadabilityStyledElements($articleContent);
+ }
+
+ /* Clean out junk from the article content */
+ $this->cleanConditionally($articleContent, 'form');
+ $this->clean($articleContent, 'object');
+ $this->clean($articleContent, 'h1');
+
+ /**
+ * If there is only one h2, they are probably using it
+ * as a header and not a subheader, so remove it since we already have a header.
+ ***/
+ if ($articleContent->getElementsByTagName('h2')->length == 1) {
+ $this->clean($articleContent, 'h2');
+ }
+ $this->clean($articleContent, 'iframe');
+
+ $this->cleanHeaders($articleContent);
+
+ /* Do these last as the previous stuff may have removed junk that will affect these */
+ $this->cleanConditionally($articleContent, 'table');
+ $this->cleanConditionally($articleContent, 'ul');
+ $this->cleanConditionally($articleContent, 'div');
+
+ /* Remove extra paragraphs */
+ $articleParagraphs = $articleContent->getElementsByTagName('p');
+ for ($i = $articleParagraphs->length-1; $i >= 0; $i--)
+ {
+ $imgCount = $articleParagraphs->item($i)->getElementsByTagName('img')->length;
+ $embedCount = $articleParagraphs->item($i)->getElementsByTagName('embed')->length;
+ $objectCount = $articleParagraphs->item($i)->getElementsByTagName('object')->length;
+
+ if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '')
+ {
+ $articleParagraphs->item($i)->parentNode->removeChild($articleParagraphs->item($i));
+ }
+ }
+
+ try {
+ $articleContent->innerHTML = preg_replace('/
]*>\s*
innerHTML);
+ //articleContent.innerHTML = articleContent.innerHTML.replace(/
]*>\s*
dbg("Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring.: " . $e);
+ }
+ }
+
+ /**
+ * Initialize a node with the readability object. Also checks the
+ * className/id for special names to add to its score.
+ *
+ * @param Element
+ * @return void
+ **/
+ protected function initializeNode($node) {
+ $readability = $this->dom->createAttribute('readability');
+ $readability->value = 0; // this is our contentScore
+ $node->setAttributeNode($readability);
+
+ switch (strtoupper($node->tagName)) { // unsure if strtoupper is needed, but using it just in case
+ case 'DIV':
+ $readability->value += 5;
+ break;
+
+ case 'PRE':
+ case 'TD':
+ case 'BLOCKQUOTE':
+ $readability->value += 3;
+ break;
+
+ case 'ADDRESS':
+ case 'OL':
+ case 'UL':
+ case 'DL':
+ case 'DD':
+ case 'DT':
+ case 'LI':
+ case 'FORM':
+ $readability->value -= 3;
+ break;
+
+ case 'H1':
+ case 'H2':
+ case 'H3':
+ case 'H4':
+ case 'H5':
+ case 'H6':
+ case 'TH':
+ $readability->value -= 5;
+ break;
+ }
+ $readability->value += $this->getClassWeight($node);
+ }
+
+ /***
+ * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is
+ * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
+ *
+ * @return DOMElement
+ **/
+ protected function grabArticle($page=null) {
+ $stripUnlikelyCandidates = $this->flagIsActive(self::FLAG_STRIP_UNLIKELYS);
+ if (!$page) $page = $this->dom;
+ $allElements = $page->getElementsByTagName('*');
+ /**
+ * First, node prepping. Trash nodes that look cruddy (like ones with the class name "comment", etc), and turn divs
+ * into P tags where they have been used inappropriately (as in, where they contain no other block level elements.)
+ *
+ * Note: Assignment from index for performance. See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5
+ * TODO: Shouldn't this be a reverse traversal?
+ **/
+ $node = null;
+ $nodesToScore = array();
+ for ($nodeIndex = 0; ($node = $allElements->item($nodeIndex)); $nodeIndex++) {
+ //for ($nodeIndex=$targetList->length-1; $nodeIndex >= 0; $nodeIndex--) {
+ //$node = $targetList->item($nodeIndex);
+ $tagName = strtoupper($node->tagName);
+ /* Remove unlikely candidates */
+ if ($stripUnlikelyCandidates) {
+ $unlikelyMatchString = $node->getAttribute('class') . $node->getAttribute('id');
+ if (
+ preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) &&
+ !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString) &&
+ $tagName != 'BODY'
+ )
+ {
+ $this->dbg('Removing unlikely candidate - ' . $unlikelyMatchString);
+ //$nodesToRemove[] = $node;
+ $node->parentNode->removeChild($node);
+ $nodeIndex--;
+ continue;
+ }
+ }
+
+ if ($tagName == 'P' || $tagName == 'TD' || $tagName == 'PRE') {
+ $nodesToScore[] = $node;
+ }
+
+ /* Turn all divs that don't have children block level elements into p's */
+ if ($tagName == 'DIV') {
+ if (!preg_match($this->regexps['divToPElements'], $node->innerHTML)) {
+ //$this->dbg('Altering div to p');
+ $newNode = $this->dom->createElement('p');
+ try {
+ $newNode->innerHTML = $node->innerHTML;
+ //$nodesToReplace[] = array('new'=>$newNode, 'old'=>$node);
+ $node->parentNode->replaceChild($newNode, $node);
+ $nodeIndex--;
+ $nodesToScore[] = $node; // or $newNode?
+ }
+ catch(Exception $e) {
+ $this->dbg('Could not alter div to p, reverting back to div.: ' . $e);
+ }
+ }
+ else
+ {
+ /* EXPERIMENTAL */
+ // TODO: change these p elements back to text nodes after processing
+ for ($i = 0, $il = $node->childNodes->length; $i < $il; $i++) {
+ $childNode = $node->childNodes->item($i);
+ if ($childNode->nodeType == 3) { // XML_TEXT_NODE
+ //$this->dbg('replacing text node with a p tag with the same content.');
+ $p = $this->dom->createElement('p');
+ $p->innerHTML = $childNode->nodeValue;
+ $p->setAttribute('style', 'display: inline;');
+ $p->setAttribute('class', 'readability-styled');
+ $childNode->parentNode->replaceChild($p, $childNode);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Loop through all paragraphs, and assign a score to them based on how content-y they look.
+ * Then add their score to their parent node.
+ *
+ * A score is determined by things like number of commas, class names, etc. Maybe eventually link density.
+ **/
+ $candidates = array();
+ for ($pt=0; $pt < count($nodesToScore); $pt++) {
+ $parentNode = $nodesToScore[$pt]->parentNode;
+ // $grandParentNode = $parentNode ? $parentNode->parentNode : null;
+ $grandParentNode = !$parentNode ? null : (($parentNode->parentNode instanceof DOMElement) ? $parentNode->parentNode : null);
+ $innerText = $this->getInnerText($nodesToScore[$pt]);
+
+ if (!$parentNode || !isset($parentNode->tagName)) {
+ continue;
+ }
+
+ /* If this paragraph is less than 25 characters, don't even count it. */
+ if(strlen($innerText) < 25) {
+ continue;
+ }
+
+ /* Initialize readability data for the parent. */
+ if (!$parentNode->hasAttribute('readability'))
+ {
+ $this->initializeNode($parentNode);
+ $candidates[] = $parentNode;
+ }
+
+ /* Initialize readability data for the grandparent. */
+ if ($grandParentNode && !$grandParentNode->hasAttribute('readability') && isset($grandParentNode->tagName))
+ {
+ $this->initializeNode($grandParentNode);
+ $candidates[] = $grandParentNode;
+ }
+
+ $contentScore = 0;
+
+ /* Add a point for the paragraph itself as a base. */
+ $contentScore++;
+
+ /* Add points for any commas within this paragraph */
+ $contentScore += count(explode(',', $innerText));
+
+ /* For every 100 characters in this paragraph, add another point. Up to 3 points. */
+ $contentScore += min(floor(strlen($innerText) / 100), 3);
+
+ /* Add the score to the parent. The grandparent gets half. */
+ $parentNode->getAttributeNode('readability')->value += $contentScore;
+
+ if ($grandParentNode) {
+ $grandParentNode->getAttributeNode('readability')->value += $contentScore/2;
+ }
+ }
+
+ /**
+ * After we've calculated scores, loop through all of the possible candidate nodes we found
+ * and find the one with the highest score.
+ **/
+ $topCandidate = null;
+ for ($c=0, $cl=count($candidates); $c < $cl; $c++)
+ {
+ /**
+ * Scale the final candidates score based on link density. Good content should have a
+ * relatively small link density (5% or less) and be mostly unaffected by this operation.
+ **/
+ $readability = $candidates[$c]->getAttributeNode('readability');
+ $readability->value = $readability->value * (1-$this->getLinkDensity($candidates[$c]));
+
+ $this->dbg('Candidate: ' . $candidates[$c]->tagName . ' (' . $candidates[$c]->getAttribute('class') . ':' . $candidates[$c]->getAttribute('id') . ') with score ' . $readability->value);
+
+ if (!$topCandidate || $readability->value > (int)$topCandidate->getAttribute('readability')) {
+ $topCandidate = $candidates[$c];
+ }
+ }
+
+ /**
+ * If we still have no top candidate, just use the body as a last resort.
+ * We also have to copy the body node so it is something we can modify.
+ **/
+ if ($topCandidate === null || strtoupper($topCandidate->tagName) == 'BODY')
+ {
+ $topCandidate = $this->dom->createElement('div');
+ $topCandidate->innerHTML = ($page instanceof DOMDocument) ? $page->saveXML($page->documentElement) : $page->innerHTML;
+ $page->innerHTML = '';
+ $page->appendChild($topCandidate);
+ $this->initializeNode($topCandidate);
+ }
+
+ /**
+ * Now that we have the top candidate, look through its siblings for content that might also be related.
+ * Things like preambles, content split by ads that we removed, etc.
+ **/
+ $articleContent = $this->dom->createElement('div');
+ $articleContent->setAttribute('id', 'readability-content');
+ $siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2);
+ $siblingNodes = $topCandidate->parentNode->childNodes;
+
+ for ($s=0, $sl=$siblingNodes->length; $s < $sl; $s++)
+ {
+ $siblingNode = $siblingNodes->item($s);
+ $append = false;
+
+ $this->dbg('Looking at sibling node: ' . $siblingNode->nodeName . (($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability')) ? (' with score ' . $siblingNode->getAttribute('readability')) : ''));
+
+ //dbg('Sibling has score ' . ($siblingNode->readability ? siblingNode.readability.contentScore : 'Unknown'));
+
+ if ($siblingNode === $topCandidate)
+ // or if ($siblingNode->isSameNode($topCandidate))
+ {
+ $append = true;
+ }
+
+ $contentBonus = 0;
+ /* Give a bonus if sibling nodes and top candidates have the example same classname */
+ if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') == $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') != '') {
+ $contentBonus += ((int)$topCandidate->getAttribute('readability')) * 0.2;
+ }
+
+ if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability') && (((int)$siblingNode->getAttribute('readability')) + $contentBonus) >= $siblingScoreThreshold)
+ {
+ $append = true;
+ }
+
+ if (strtoupper($siblingNode->nodeName) == 'P') {
+ $linkDensity = $this->getLinkDensity($siblingNode);
+ $nodeContent = $this->getInnerText($siblingNode);
+ $nodeLength = strlen($nodeContent);
+
+ if ($nodeLength > 80 && $linkDensity < 0.25)
+ {
+ $append = true;
+ }
+ else if ($nodeLength < 80 && $linkDensity === 0 && preg_match('/\.( |$)/', $nodeContent))
+ {
+ $append = true;
+ }
+ }
+
+ if ($append)
+ {
+ $this->dbg('Appending node: ' . $siblingNode->nodeName);
+
+ $nodeToAppend = null;
+ $sibNodeName = strtoupper($siblingNode->nodeName);
+ if ($sibNodeName != 'DIV' && $sibNodeName != 'P') {
+ /* We have a node that isn't a common block level element, like a form or td tag. Turn it into a div so it doesn't get filtered out later by accident. */
+
+ $this->dbg('Altering siblingNode of ' . $sibNodeName . ' to div.');
+ $nodeToAppend = $this->dom->createElement('div');
+ try {
+ $nodeToAppend->setAttribute('id', $siblingNode->getAttribute('id'));
+ $nodeToAppend->innerHTML = $siblingNode->innerHTML;
+ }
+ catch(Exception $e)
+ {
+ $this->dbg('Could not alter siblingNode to div, reverting back to original.');
+ $nodeToAppend = $siblingNode;
+ $s--;
+ $sl--;
+ }
+ } else {
+ $nodeToAppend = $siblingNode;
+ $s--;
+ $sl--;
+ }
+
+ /* To ensure a node does not interfere with readability styles, remove its classnames */
+ $nodeToAppend->removeAttribute('class');
+
+ /* Append sibling and subtract from our list because it removes the node when you append to another node */
+ $articleContent->appendChild($nodeToAppend);
+ }
+ }
+
+ /**
+ * So we have all of the content that we need. Now we clean it up for presentation.
+ **/
+ $this->prepArticle($articleContent);
+
+ /**
+ * Now that we've gone through the full algorithm, check to see if we got any meaningful content.
+ * If we didn't, we may need to re-run grabArticle with different flags set. This gives us a higher
+ * likelihood of finding the content, and the sieve approach gives us a higher likelihood of
+ * finding the -right- content.
+ **/
+ if (strlen($this->getInnerText($articleContent, false)) < 250)
+ {
+ $this->body->innerHTML = $this->bodyCache;
+
+ if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) {
+ $this->removeFlag(self::FLAG_STRIP_UNLIKELYS);
+ return $this->grabArticle($this->body);
+ }
+ else if ($this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) {
+ $this->removeFlag(self::FLAG_WEIGHT_CLASSES);
+ return $this->grabArticle($this->body);
+ }
+ else if ($this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
+ $this->removeFlag(self::FLAG_CLEAN_CONDITIONALLY);
+ return $this->grabArticle($this->body);
+ }
+ else {
+ return false;
+ }
+ }
+ return $articleContent;
+ }
+
+ /**
+ * Remove script tags from document
+ *
+ * @param DOMElement
+ * @return void
+ */
+ public function removeScripts($doc) {
+ $scripts = $doc->getElementsByTagName('script');
+ for($i = $scripts->length-1; $i >= 0; $i--)
+ {
+ $scripts->item($i)->parentNode->removeChild($scripts->item($i));
+ }
+ }
+
+ /**
+ * Get the inner text of a node.
+ * This also strips out any excess whitespace to be found.
+ *
+ * @param DOMElement $
+ * @param boolean $normalizeSpaces (default: true)
+ * @return string
+ **/
+ public function getInnerText($e, $normalizeSpaces=true) {
+ $textContent = '';
+
+ if (!isset($e->textContent) || $e->textContent == '') {
+ return '';
+ }
+
+ $textContent = trim($e->textContent);
+
+ if ($normalizeSpaces) {
+ return preg_replace($this->regexps['normalize'], ' ', $textContent);
+ } else {
+ return $textContent;
+ }
+ }
+
+ /**
+ * Get the number of times a string $s appears in the node $e.
+ *
+ * @param DOMElement $e
+ * @param string - what to count. Default is ","
+ * @return number (integer)
+ **/
+ public function getCharCount($e, $s=',') {
+ return substr_count($this->getInnerText($e), $s);
+ }
+
+ /**
+ * Remove the style attribute on every $e and under.
+ *
+ * @param DOMElement $e
+ * @return void
+ */
+ public function cleanStyles($e) {
+ $elems = $e->getElementsByTagName('*');
+ foreach ($elems as $elem) {
+ $elem->removeAttribute('style');
+ }
+ }
+
+ /**
+ * Get the density of links as a percentage of the content
+ * This is the amount of text that is inside a link divided by the total text in the node.
+ *
+ * @param DOMElement $e
+ * @return number (float)
+ */
+ public function getLinkDensity($e) {
+ $links = $e->getElementsByTagName('a');
+ $textLength = strlen($this->getInnerText($e));
+ $linkLength = 0;
+ for ($i=0, $il=$links->length; $i < $il; $i++)
+ {
+ $linkLength += strlen($this->getInnerText($links->item($i)));
+ }
+ if ($textLength > 0) {
+ return $linkLength / $textLength;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Get an elements class/id weight. Uses regular expressions to tell if this
+ * element looks good or bad.
+ *
+ * @param DOMElement $e
+ * @return number (Integer)
+ */
+ public function getClassWeight($e) {
+ if(!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) {
+ return 0;
+ }
+
+ $weight = 0;
+
+ /* Look for a special classname */
+ if ($e->hasAttribute('class') && $e->getAttribute('class') != '')
+ {
+ if (preg_match($this->regexps['negative'], $e->getAttribute('class'))) {
+ $weight -= 25;
+ }
+ if (preg_match($this->regexps['positive'], $e->getAttribute('class'))) {
+ $weight += 25;
+ }
+ }
+
+ /* Look for a special ID */
+ if ($e->hasAttribute('id') && $e->getAttribute('id') != '')
+ {
+ if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) {
+ $weight -= 25;
+ }
+ if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) {
+ $weight += 25;
+ }
+ }
+ return $weight;
+ }
+
+ /**
+ * Remove extraneous break tags from a node.
+ *
+ * @param DOMElement $node
+ * @return void
+ */
+ public function killBreaks($node) {
+ $html = $node->innerHTML;
+ $html = preg_replace($this->regexps['killBreaks'], ' Para 1 Para 2 Para 1 Para 2 The story begins...
', $html);
+ $node->innerHTML = $html;
+ }
+
+ /**
+ * Clean a node of all elements of type "tag".
+ * (Unless it's a youtube/vimeo video. People love movies.)
+ *
+ * @param DOMElement $e
+ * @param string $tag
+ * @return void
+ */
+ public function clean($e, $tag) {
+ $targetList = $e->getElementsByTagName($tag);
+ $isEmbed = ($tag == 'object' || $tag == 'embed');
+
+ for ($y=$targetList->length-1; $y >= 0; $y--) {
+ /* Allow youtube and vimeo videos through as people usually want to see those. */
+ if ($isEmbed) {
+ $attributeValues = '';
+ for ($i=0, $il=$targetList->item($y)->attributes->length; $i < $il; $i++) {
+ $attributeValues .= $targetList->item($y)->attributes->item($i)->value . '|'; // DOMAttr? (TODO: test)
+ }
+
+ /* First, check the elements attributes to see if any of them contain youtube or vimeo */
+ if (preg_match($this->regexps['video'], $attributeValues)) {
+ continue;
+ }
+
+ /* Then check the elements inside this element for the same. */
+ if (preg_match($this->regexps['video'], $targetList->item($y)->innerHTML)) {
+ continue;
+ }
+ }
+ $targetList->item($y)->parentNode->removeChild($targetList->item($y));
+ }
+ }
+
+ /**
+ * Clean an element of all tags of type "tag" if they look fishy.
+ * "Fishy" is an algorithm based on content length, classnames,
+ * link density, number of images & embeds, etc.
+ *
+ * @param DOMElement $e
+ * @param string $tag
+ * @return void
+ */
+ public function cleanConditionally($e, $tag) {
+ if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
+ return;
+ }
+
+ $tagsList = $e->getElementsByTagName($tag);
+ $curTagsLength = $tagsList->length;
+
+ /**
+ * Gather counts for other typical elements embedded within.
+ * Traverse backwards so we can remove nodes at the same time without effecting the traversal.
+ *
+ * TODO: Consider taking into account original contentScore here.
+ */
+ for ($i=$curTagsLength-1; $i >= 0; $i--) {
+ $weight = $this->getClassWeight($tagsList->item($i));
+ $contentScore = ($tagsList->item($i)->hasAttribute('readability')) ? (int)$tagsList->item($i)->getAttribute('readability') : 0;
+
+ $this->dbg('Cleaning Conditionally ' . $tagsList->item($i)->tagName . ' (' . $tagsList->item($i)->getAttribute('class') . ':' . $tagsList->item($i)->getAttribute('id') . ')' . (($tagsList->item($i)->hasAttribute('readability')) ? (' with score ' . $tagsList->item($i)->getAttribute('readability')) : ''));
+
+ if ($weight + $contentScore < 0) {
+ $tagsList->item($i)->parentNode->removeChild($tagsList->item($i));
+ }
+ else if ( $this->getCharCount($tagsList->item($i), ',') < 10) {
+ /**
+ * If there are not very many commas, and the number of
+ * non-paragraph elements is more than paragraphs or other ominous signs, remove the element.
+ **/
+ $p = $tagsList->item($i)->getElementsByTagName('p')->length;
+ $img = $tagsList->item($i)->getElementsByTagName('img')->length;
+ $li = $tagsList->item($i)->getElementsByTagName('li')->length-100;
+ $input = $tagsList->item($i)->getElementsByTagName('input')->length;
+
+ $embedCount = 0;
+ $embeds = $tagsList->item($i)->getElementsByTagName('embed');
+ for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) {
+ if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) {
+ $embedCount++;
+ }
+ }
+
+ $linkDensity = $this->getLinkDensity($tagsList->item($i));
+ $contentLength = strlen($this->getInnerText($tagsList->item($i)));
+ $toRemove = false;
+
+ if ( $img > $p ) {
+ $toRemove = true;
+ } else if ($li > $p && $tag != 'ul' && $tag != 'ol') {
+ $toRemove = true;
+ } else if ( $input > floor($p/3) ) {
+ $toRemove = true;
+ } else if ($contentLength < 25 && ($img === 0 || $img > 2) ) {
+ $toRemove = true;
+ } else if($weight < 25 && $linkDensity > 0.2) {
+ $toRemove = true;
+ } else if($weight >= 25 && $linkDensity > 0.5) {
+ $toRemove = true;
+ } else if(($embedCount == 1 && $contentLength < 75) || $embedCount > 1) {
+ $toRemove = true;
+ }
+
+ if ($toRemove) {
+ $tagsList->item($i)->parentNode->removeChild($tagsList->item($i));
+ }
+ }
+ }
+ }
+
+ /**
+ * Clean out spurious headers from an Element. Checks things like classnames and link density.
+ *
+ * @param DOMElement $e
+ * @return void
+ */
+ public function cleanHeaders($e) {
+ for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) {
+ $headers = $e->getElementsByTagName('h' . $headerIndex);
+ for ($i=$headers->length-1; $i >=0; $i--) {
+ if ($this->getClassWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) {
+ $headers->item($i)->parentNode->removeChild($headers->item($i));
+ }
+ }
+ }
+ }
+
+ public function flagIsActive($flag) {
+ return ($this->flags & $flag) > 0;
+ }
+
+ public function addFlag($flag) {
+ $this->flags = $this->flags | $flag;
+ }
+
+ public function removeFlag($flag) {
+ $this->flags = $this->flags & ~$flag;
+ }
+}
+?>
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/mpdf/mpdf.php b/inc/3rdparty/libraries/mpdf/mpdf.php
index dbe16fef..f12dfec0 100644
--- a/inc/3rdparty/libraries/mpdf/mpdf.php
+++ b/inc/3rdparty/libraries/mpdf/mpdf.php
@@ -7451,7 +7451,7 @@ function Output($name='',$dest='')
// don't use length if server using compression
header('Content-Length: '.strlen($this->buffer));
}
- header('Content-disposition: inline; filename="'.$name.'"');
+ header('Content-disposition: attachment; filename="'.$name.'"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/CharacterEntities.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/CharacterEntities.php
deleted file mode 100644
index de896f87..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/CharacterEntities.php
+++ /dev/null
@@ -1,413 +0,0 @@
- output is UTF-8
- return $str;
- //return utf8_encode($str);
- //Convert to CP1252
- list($from, $to) = CharacterEntities::generateTables();
- return str_replace($from, $to, $str);
- }
-
- private static function generateTables(){
- $from = array();
- $to = array();
-
- for($i = 0; $i < 256; $i++){
- $from[$i] = $to[$i] = chr($i);
- }
-
- $from[0x80] = "€";
- $from[0x82] = "‚";
- $from[0x83] = "ƒ";
- $from[0x84] = "„";
- $from[0x85] = "…";
- $from[0x86] = "†";
- $from[0x87] = "‡";
- $from[0x88] = "ˆ";
- $from[0x89] = "‰";
- $from[0x8A] = "Š";
- $from[0x8B] = "‹";
- $from[0x8C] = "Œ";
- $from[0x8E] = "Ž";
-
- $from[0x91] = "‘";
- $from[0x92] = "’";
- $from[0x93] = "“";
- $from[0x94] = "”";
- $from[0x95] = "•";
- $from[0x96] = "–";
- $from[0x97] = "—";
- $from[0x98] = "˜";
- $from[0x99] = "™";
- $from[0x9A] = "š";
- $from[0x9B] = "›";
- $from[0x9C] = "œ";
- $from[0x9E] = "ž";
- $from[0x9F] = "Ÿ";
-
- $from[0xA1] = "¡";
- $from[0xA2] = "¢";
- $from[0xA3] = "£";
- $from[0xA4] = "¤";
- $from[0xA5] = "¥";
- $from[0xA6] = "¦";
- $from[0xA7] = "§";
- $from[0xA8] = "¨";
- $from[0xA9] = "©";
- $from[0xAA] = "ª";
- $from[0xAB] = "«";
- $from[0xAC] = "¬";
- $from[0xAE] = "®";
- $from[0xAF] = "¯";
-
- $from[0xB0] = "°";
- $from[0xB1] = "±";
- $from[0xB2] = "²";
- $from[0xB3] = "³";
- $from[0xB4] = "´";
- $from[0xB5] = "µ";
- $from[0xB6] = "¶";
- $from[0xB7] = "·";
- $from[0xB8] = "¸";
- $from[0xB9] = "¹";
- $from[0xBA] = "º";
- $from[0xBB] = "»";
- $from[0xBC] = "¼";
- $from[0xBD] = "½";
- $from[0xBE] = "¾";
- $from[0xBF] = "¿";
-
- $from[0xC0] = "À";
- $from[0xC1] = "Á";
- $from[0xC2] = "Â";
- $from[0xC3] = "Ã";
- $from[0xC4] = "Ä";
- $from[0xC5] = "Å";
- $from[0xC6] = "Æ";
- $from[0xC7] = "Ç";
- $from[0xC8] = "È";
- $from[0xC9] = "É";
- $from[0xCA] = "Ê";
- $from[0xCB] = "Ë";
- $from[0xCC] = "Ì";
- $from[0xCD] = "Í";
- $from[0xCE] = "Î";
- $from[0xCF] = "Ï";
-
- $from[0xD0] = "Ð";
- $from[0xD1] = "Ñ";
- $from[0xD2] = "Ò";
- $from[0xD3] = "Ó";
- $from[0xD4] = "Ô";
- $from[0xD5] = "Õ";
- $from[0xD6] = "Ö";
- $from[0xD7] = "×";
- $from[0xD8] = "Ø";
- $from[0xD9] = "Ù";
- $from[0xDA] = "Ú";
- $from[0xDB] = "Û";
- $from[0xDC] = "Ü";
- $from[0xDD] = "Ý";
- $from[0xDE] = "Þ";
- $from[0xDF] = "ß";
-
- $from[0xE0] = "à";
- $from[0xE1] = "á";
- $from[0xE2] = "â";
- $from[0xE3] = "ã";
- $from[0xE4] = "ä";
- $from[0xE5] = "å";
- $from[0xE6] = "æ";
- $from[0xE7] = "ç";
- $from[0xE8] = "è";
- $from[0xE9] = "é";
- $from[0xEA] = "ê";
- $from[0xEB] = "ë";
- $from[0xEC] = "ì";
- $from[0xED] = "í";
- $from[0xEE] = "î";
- $from[0xEF] = "ï";
-
- $from[0xF0] = "ð";
- $from[0xF1] = "ñ";
- $from[0xF2] = "ò";
- $from[0xF3] = "ó";
- $from[0xF4] = "ô";
- $from[0xF5] = "õ";
- $from[0xF6] = "ö";
- $from[0xF7] = "÷";
- $from[0xF8] = "ø";
- $from[0xF9] = "ù";
- $from[0xFA] = "ú";
- $from[0xFB] = "û";
- $from[0xFC] = "ü";
- $from[0xFD] = "ý";
- $from[0xFE] = "þ";
- $from[0xFF] = "ÿ";
-
-
- return array($from, $to);
- }
- /*
- 00 = U+0000 : NULL
-01 = U+0001 : START OF HEADING
-02 = U+0002 : START OF TEXT
-03 = U+0003 : END OF TEXT
-04 = U+0004 : END OF TRANSMISSION
-05 = U+0005 : ENQUIRY
-06 = U+0006 : ACKNOWLEDGE
-07 = U+0007 : BELL
-08 = U+0008 : BACKSPACE
-09 = U+0009 : HORIZONTAL TABULATION
-0A = U+000A : LINE FEED
-0B = U+000B : VERTICAL TABULATION
-0C = U+000C : FORM FEED
-0D = U+000D : CARRIAGE RETURN
-0E = U+000E : SHIFT OUT
-0F = U+000F : SHIFT IN
-10 = U+0010 : DATA LINK ESCAPE
-11 = U+0011 : DEVICE CONTROL ONE
-12 = U+0012 : DEVICE CONTROL TWO
-13 = U+0013 : DEVICE CONTROL THREE
-14 = U+0014 : DEVICE CONTROL FOUR
-15 = U+0015 : NEGATIVE ACKNOWLEDGE
-16 = U+0016 : SYNCHRONOUS IDLE
-17 = U+0017 : END OF TRANSMISSION BLOCK
-18 = U+0018 : CANCEL
-19 = U+0019 : END OF MEDIUM
-1A = U+001A : SUBSTITUTE
-1B = U+001B : ESCAPE
-1C = U+001C : FILE SEPARATOR
-1D = U+001D : GROUP SEPARATOR
-1E = U+001E : RECORD SEPARATOR
-1F = U+001F : UNIT SEPARATOR
-20 = U+0020 : SPACE
-21 = U+0021 : EXCLAMATION MARK
-22 = U+0022 : QUOTATION MARK
-23 = U+0023 : NUMBER SIGN
-24 = U+0024 : DOLLAR SIGN
-25 = U+0025 : PERCENT SIGN
-26 = U+0026 : AMPERSAND
-27 = U+0027 : APOSTROPHE
-28 = U+0028 : LEFT PARENTHESIS
-29 = U+0029 : RIGHT PARENTHESIS
-2A = U+002A : ASTERISK
-2B = U+002B : PLUS SIGN
-2C = U+002C : COMMA
-2D = U+002D : HYPHEN-MINUS
-2E = U+002E : FULL STOP
-2F = U+002F : SOLIDUS
-30 = U+0030 : DIGIT ZERO
-31 = U+0031 : DIGIT ONE
-32 = U+0032 : DIGIT TWO
-33 = U+0033 : DIGIT THREE
-34 = U+0034 : DIGIT FOUR
-35 = U+0035 : DIGIT FIVE
-36 = U+0036 : DIGIT SIX
-37 = U+0037 : DIGIT SEVEN
-38 = U+0038 : DIGIT EIGHT
-39 = U+0039 : DIGIT NINE
-3A = U+003A : COLON
-3B = U+003B : SEMICOLON
-3C = U+003C : LESS-THAN SIGN
-3D = U+003D : EQUALS SIGN
-3E = U+003E : GREATER-THAN SIGN
-3F = U+003F : QUESTION MARK
-40 = U+0040 : COMMERCIAL AT
-41 = U+0041 : LATIN CAPITAL LETTER A
-42 = U+0042 : LATIN CAPITAL LETTER B
-43 = U+0043 : LATIN CAPITAL LETTER C
-44 = U+0044 : LATIN CAPITAL LETTER D
-45 = U+0045 : LATIN CAPITAL LETTER E
-46 = U+0046 : LATIN CAPITAL LETTER F
-47 = U+0047 : LATIN CAPITAL LETTER G
-48 = U+0048 : LATIN CAPITAL LETTER H
-49 = U+0049 : LATIN CAPITAL LETTER I
-4A = U+004A : LATIN CAPITAL LETTER J
-4B = U+004B : LATIN CAPITAL LETTER K
-4C = U+004C : LATIN CAPITAL LETTER L
-4D = U+004D : LATIN CAPITAL LETTER M
-4E = U+004E : LATIN CAPITAL LETTER N
-4F = U+004F : LATIN CAPITAL LETTER O
-50 = U+0050 : LATIN CAPITAL LETTER P
-51 = U+0051 : LATIN CAPITAL LETTER Q
-52 = U+0052 : LATIN CAPITAL LETTER R
-53 = U+0053 : LATIN CAPITAL LETTER S
-54 = U+0054 : LATIN CAPITAL LETTER T
-55 = U+0055 : LATIN CAPITAL LETTER U
-56 = U+0056 : LATIN CAPITAL LETTER V
-57 = U+0057 : LATIN CAPITAL LETTER W
-58 = U+0058 : LATIN CAPITAL LETTER X
-59 = U+0059 : LATIN CAPITAL LETTER Y
-5A = U+005A : LATIN CAPITAL LETTER Z
-5B = U+005B : LEFT SQUARE BRACKET
-5C = U+005C : REVERSE SOLIDUS
-5D = U+005D : RIGHT SQUARE BRACKET
-5E = U+005E : CIRCUMFLEX ACCENT
-5F = U+005F : LOW LINE
-60 = U+0060 : GRAVE ACCENT
-61 = U+0061 : LATIN SMALL LETTER A
-62 = U+0062 : LATIN SMALL LETTER B
-63 = U+0063 : LATIN SMALL LETTER C
-64 = U+0064 : LATIN SMALL LETTER D
-65 = U+0065 : LATIN SMALL LETTER E
-66 = U+0066 : LATIN SMALL LETTER F
-67 = U+0067 : LATIN SMALL LETTER G
-68 = U+0068 : LATIN SMALL LETTER H
-69 = U+0069 : LATIN SMALL LETTER I
-6A = U+006A : LATIN SMALL LETTER J
-6B = U+006B : LATIN SMALL LETTER K
-6C = U+006C : LATIN SMALL LETTER L
-6D = U+006D : LATIN SMALL LETTER M
-6E = U+006E : LATIN SMALL LETTER N
-6F = U+006F : LATIN SMALL LETTER O
-70 = U+0070 : LATIN SMALL LETTER P
-71 = U+0071 : LATIN SMALL LETTER Q
-72 = U+0072 : LATIN SMALL LETTER R
-73 = U+0073 : LATIN SMALL LETTER S
-74 = U+0074 : LATIN SMALL LETTER T
-75 = U+0075 : LATIN SMALL LETTER U
-76 = U+0076 : LATIN SMALL LETTER V
-77 = U+0077 : LATIN SMALL LETTER W
-78 = U+0078 : LATIN SMALL LETTER X
-79 = U+0079 : LATIN SMALL LETTER Y
-7A = U+007A : LATIN SMALL LETTER Z
-7B = U+007B : LEFT CURLY BRACKET
-7C = U+007C : VERTICAL LINE
-7D = U+007D : RIGHT CURLY BRACKET
-7E = U+007E : TILDE
-7F = U+007F : DELETE
-80 = U+20AC : EURO SIGN
-82 = U+201A : SINGLE LOW-9 QUOTATION MARK
-83 = U+0192 : LATIN SMALL LETTER F WITH HOOK
-84 = U+201E : DOUBLE LOW-9 QUOTATION MARK
-85 = U+2026 : HORIZONTAL ELLIPSIS
-86 = U+2020 : DAGGER
-87 = U+2021 : DOUBLE DAGGER
-88 = U+02C6 : MODIFIER LETTER CIRCUMFLEX ACCENT
-89 = U+2030 : PER MILLE SIGN
-8A = U+0160 : LATIN CAPITAL LETTER S WITH CARON
-8B = U+2039 : SINGLE LEFT-POINTING ANGLE QUOTATION MARK
-8C = U+0152 : LATIN CAPITAL LIGATURE OE
-8E = U+017D : LATIN CAPITAL LETTER Z WITH CARON
-91 = U+2018 : LEFT SINGLE QUOTATION MARK
-92 = U+2019 : RIGHT SINGLE QUOTATION MARK
-93 = U+201C : LEFT DOUBLE QUOTATION MARK
-94 = U+201D : RIGHT DOUBLE QUOTATION MARK
-95 = U+2022 : BULLET
-96 = U+2013 : EN DASH
-97 = U+2014 : EM DASH
-98 = U+02DC : SMALL TILDE
-99 = U+2122 : TRADE MARK SIGN
-9A = U+0161 : LATIN SMALL LETTER S WITH CARON
-9B = U+203A : SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
-9C = U+0153 : LATIN SMALL LIGATURE OE
-9E = U+017E : LATIN SMALL LETTER Z WITH CARON
-9F = U+0178 : LATIN CAPITAL LETTER Y WITH DIAERESIS
-A0 = U+00A0 : NO-BREAK SPACE
-A1 = U+00A1 : INVERTED EXCLAMATION MARK
-A2 = U+00A2 : CENT SIGN
-A3 = U+00A3 : POUND SIGN
-A4 = U+00A4 : CURRENCY SIGN
-A5 = U+00A5 : YEN SIGN
-A6 = U+00A6 : BROKEN BAR
-A7 = U+00A7 : SECTION SIGN
-A8 = U+00A8 : DIAERESIS
-A9 = U+00A9 : COPYRIGHT SIGN
-AA = U+00AA : FEMININE ORDINAL INDICATOR
-AB = U+00AB : LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
-AC = U+00AC : NOT SIGN
-AD = U+00AD : SOFT HYPHEN
-AE = U+00AE : REGISTERED SIGN
-AF = U+00AF : MACRON
-B0 = U+00B0 : DEGREE SIGN
-B1 = U+00B1 : PLUS-MINUS SIGN
-B2 = U+00B2 : SUPERSCRIPT TWO
-B3 = U+00B3 : SUPERSCRIPT THREE
-B4 = U+00B4 : ACUTE ACCENT
-B5 = U+00B5 : MICRO SIGN
-B6 = U+00B6 : PILCROW SIGN
-B7 = U+00B7 : MIDDLE DOT
-B8 = U+00B8 : CEDILLA
-B9 = U+00B9 : SUPERSCRIPT ONE
-BA = U+00BA : MASCULINE ORDINAL INDICATOR
-BB = U+00BB : RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
-BC = U+00BC : VULGAR FRACTION ONE QUARTER
-BD = U+00BD : VULGAR FRACTION ONE HALF
-BE = U+00BE : VULGAR FRACTION THREE QUARTERS
-BF = U+00BF : INVERTED QUESTION MARK
-C0 = U+00C0 : LATIN CAPITAL LETTER A WITH GRAVE
-C1 = U+00C1 : LATIN CAPITAL LETTER A WITH ACUTE
-C2 = U+00C2 : LATIN CAPITAL LETTER A WITH CIRCUMFLEX
-C3 = U+00C3 : LATIN CAPITAL LETTER A WITH TILDE
-C4 = U+00C4 : LATIN CAPITAL LETTER A WITH DIAERESIS
-C5 = U+00C5 : LATIN CAPITAL LETTER A WITH RING ABOVE
-C6 = U+00C6 : LATIN CAPITAL LETTER AE
-C7 = U+00C7 : LATIN CAPITAL LETTER C WITH CEDILLA
-C8 = U+00C8 : LATIN CAPITAL LETTER E WITH GRAVE
-C9 = U+00C9 : LATIN CAPITAL LETTER E WITH ACUTE
-CA = U+00CA : LATIN CAPITAL LETTER E WITH CIRCUMFLEX
-CB = U+00CB : LATIN CAPITAL LETTER E WITH DIAERESIS
-CC = U+00CC : LATIN CAPITAL LETTER I WITH GRAVE
-CD = U+00CD : LATIN CAPITAL LETTER I WITH ACUTE
-CE = U+00CE : LATIN CAPITAL LETTER I WITH CIRCUMFLEX
-CF = U+00CF : LATIN CAPITAL LETTER I WITH DIAERESIS
-D0 = U+00D0 : LATIN CAPITAL LETTER ETH
-D1 = U+00D1 : LATIN CAPITAL LETTER N WITH TILDE
-D2 = U+00D2 : LATIN CAPITAL LETTER O WITH GRAVE
-D3 = U+00D3 : LATIN CAPITAL LETTER O WITH ACUTE
-D4 = U+00D4 : LATIN CAPITAL LETTER O WITH CIRCUMFLEX
-D5 = U+00D5 : LATIN CAPITAL LETTER O WITH TILDE
-D6 = U+00D6 : LATIN CAPITAL LETTER O WITH DIAERESIS
-D7 = U+00D7 : MULTIPLICATION SIGN
-D8 = U+00D8 : LATIN CAPITAL LETTER O WITH STROKE
-D9 = U+00D9 : LATIN CAPITAL LETTER U WITH GRAVE
-DA = U+00DA : LATIN CAPITAL LETTER U WITH ACUTE
-DB = U+00DB : LATIN CAPITAL LETTER U WITH CIRCUMFLEX
-DC = U+00DC : LATIN CAPITAL LETTER U WITH DIAERESIS
-DD = U+00DD : LATIN CAPITAL LETTER Y WITH ACUTE
-DE = U+00DE : LATIN CAPITAL LETTER THORN
-DF = U+00DF : LATIN SMALL LETTER SHARP S
-E0 = U+00E0 : LATIN SMALL LETTER A WITH GRAVE
-E1 = U+00E1 : LATIN SMALL LETTER A WITH ACUTE
-E2 = U+00E2 : LATIN SMALL LETTER A WITH CIRCUMFLEX
-E3 = U+00E3 : LATIN SMALL LETTER A WITH TILDE
-E4 = U+00E4 : LATIN SMALL LETTER A WITH DIAERESIS
-E5 = U+00E5 : LATIN SMALL LETTER A WITH RING ABOVE
-E6 = U+00E6 : LATIN SMALL LETTER AE
-E7 = U+00E7 : LATIN SMALL LETTER C WITH CEDILLA
-E8 = U+00E8 : LATIN SMALL LETTER E WITH GRAVE
-E9 = U+00E9 : LATIN SMALL LETTER E WITH ACUTE
-EA = U+00EA : LATIN SMALL LETTER E WITH CIRCUMFLEX
-EB = U+00EB : LATIN SMALL LETTER E WITH DIAERESIS
-EC = U+00EC : LATIN SMALL LETTER I WITH GRAVE
-ED = U+00ED : LATIN SMALL LETTER I WITH ACUTE
-EE = U+00EE : LATIN SMALL LETTER I WITH CIRCUMFLEX
-EF = U+00EF : LATIN SMALL LETTER I WITH DIAERESIS
-F0 = U+00F0 : LATIN SMALL LETTER ETH
-F1 = U+00F1 : LATIN SMALL LETTER N WITH TILDE
-F2 = U+00F2 : LATIN SMALL LETTER O WITH GRAVE
-F3 = U+00F3 : LATIN SMALL LETTER O WITH ACUTE
-F4 = U+00F4 : LATIN SMALL LETTER O WITH CIRCUMFLEX
-F5 = U+00F5 : LATIN SMALL LETTER O WITH TILDE
-F6 = U+00F6 : LATIN SMALL LETTER O WITH DIAERESIS
-F7 = U+00F7 : DIVISION SIGN
-F8 = U+00F8 : LATIN SMALL LETTER O WITH STROKE
-F9 = U+00F9 : LATIN SMALL LETTER U WITH GRAVE
-FA = U+00FA : LATIN SMALL LETTER U WITH ACUTE
-FB = U+00FB : LATIN SMALL LETTER U WITH CIRCUMFLEX
-FC = U+00FC : LATIN SMALL LETTER U WITH DIAERESIS
-FD = U+00FD : LATIN SMALL LETTER Y WITH ACUTE
-FE = U+00FE : LATIN SMALL LETTER THORN
-FF = U+00FF : LATIN SMALL LETTER Y WITH DIAERESIS
- *
- */
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/ContentProvider.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/ContentProvider.php
deleted file mode 100644
index dcf9c4de..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/ContentProvider.php
+++ /dev/null
@@ -1,22 +0,0 @@
-
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/EXTHHelper.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/EXTHHelper.php
deleted file mode 100644
index 275142bf..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/EXTHHelper.php
+++ /dev/null
@@ -1,132 +0,0 @@
-> (8*$i)).$out;
- $mask = $mask << 8;
- }
- return $out;
- }
-
- static function getRightRepresentation($type, $value){
- if($type >= 100 && $type < 200){
- return $value;
- }else{
- return self::toHex($value);
- }
- }
-
- static function toHex($value){
- $out = "";
- for($i = 0, $len = strlen($value); $i < $len; $i++){
- if($i > 0) $out .= " ";
- $hex = dechex(ord($value[$i]));
- if(strlen($hex) < 2) $hex = "0".$hex;
- $out .= $hex;
- }
- return $out;
- }
-
-
- static private $types = array(
- 1 => "drm server id",
- 2 => "drm commerce id",
- 3 => "drm ebookbase book id",
- 100 => "author",
- 101 => "publisher",
- 102 => "imprint",
- 103 => "description",
- 104 => "isbn",
- 105 => "subject",
- 106 => "publishingdate",
- 107 => "review",
- 108 => "contributor",
- 109 => "rights",
- 110 => "subjectcode",
- 111 => "type",
- 112 => "source",
- 113 => "asin",
- 114 => "versionnumber",
- 115 => "sample",
- 116 => "startreading",
- 118 => "retail price",
- 119 => "retail price currency",
- 201 => "coveroffset",
- 202 => "thumboffset",
- 203 => "hasfakecover",
- 204 => "Creator Software",
- 205 => "Creator Major Version",
- 206 => "Creator Minor Version",
- 207 => "Creator Build Number",
- 208 => "watermark",
- 209 => "tamper proof keys",
- 300 => "fontsignature",
- 401 => "clippinglimit",
- 402 => "publisherlimit",
- 403 => "403",
- 404 => "ttsflag",
- 501 => "cdetype",
- 502 => "lastupdatetime",
- 503 => "updatedtitle"
- );
- static private $flippedTypes = array(
- "drm server id" => 1,
- "drm commerce id" => 2,
- "drm ebookbase book id" => 3,
- "author" => 100,
- "publisher" => 101,
- "imprint" => 102,
- "description" => 103,
- "isbn" => 104,
- "subject" => 105,
- "publishingdate" => 106,
- "review" => 107,
- "contributor" => 108,
- "rights" => 109,
- "subjectcode" => 110,
- "type" => 111,
- "source" => 112,
- "asin" => 113,
- "versionnumber" => 114,
- "sample" => 115,
- "startreading" => 116,
- "retail price" => 118,
- "retail price currency" => 119,
- "coveroffset" => 201,
- "thumboffset" => 202,
- "hasfakecover" => 203,
- "Creator Software" => 204,
- "Creator Major Version" => 205,
- "Creator Minor Version" => 206,
- "Creator Build Number" => 207,
- "watermark" => 208,
- "tamper proof keys" => 209,
- "fontsignature" => 300,
- "clippinglimit" => 401,
- "publisherlimit" => 402,
- "403" => 403,
- "ttsflag" => 404,
- "cdetype" => 501,
- "lastupdatetime" => 502,
- "updatedtitle" => 503
- );
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileByte.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileByte.php
deleted file mode 100644
index 05fc7d04..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileByte.php
+++ /dev/null
@@ -1,41 +0,0 @@
-set($n);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = intval($value) & 0xFF;
- }
-
- public function serialize() {
- return $this->byteToString($this->data);
- }
-
- public function unserialize($data) {
- __construct($this->toInt($data));
- }
-
-
- public function __toString(){
- return "FileByte: {".$this->byteAsString($this->data)."}";
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileDate.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileDate.php
deleted file mode 100644
index 2284eba2..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileDate.php
+++ /dev/null
@@ -1,40 +0,0 @@
-set($n);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = intval($value);
- }
-
- public function serialize() {
- return $this->intToString($this->data);
- }
-
- public function unserialize($data) {
- __construct($this->toInt($data));
- }
-
- public function __toString(){
- return "FileDate: {".(date("r", $this->data-94694400))."}";
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileElement.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileElement.php
deleted file mode 100644
index 552d04a8..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileElement.php
+++ /dev/null
@@ -1,89 +0,0 @@
-elements = $elements;
- }
-
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- $total = 0;
- foreach($this->elements as $val){
- $total += $val->getByteLength();
- }
- return $total;
- }
-
- public function offsetToEntry($name){
- $pos = 0;
- foreach($this->elements as $key=>$value){
- if($name == $key){
- break;
- }
- $pos += $value->getByteLength();
- }
- return $pos;
- }
-
- public function exists($key){
- return isset($this->elements[$key]);
- }
- /**
- * @param string $key
- * @return FileObject
- */
- public function get($key){
- return $this->elements[$key];
- }
-
- /**
- * @param string $key
- * @param FileObject $value
- */
- public function set($key, $value){
- $this->elements[$key] = $value;
- }
-
- public function add($key, $value){
- $this->elements[$key] = $value;
- }
-
- public function serialize() {
- $result = "";
- foreach($this->elements as $val){
- $result .= $val->serialize();
- }
- return $result;
- }
-
- public function unserialize($data) {
- //TODO: If reading is needed -> way more complex
- }
-
- public function __toString(){
- $output = "FileElement (".$this->getByteLength()." bytes): {\n";
- foreach($this->elements as $key=>$value){
- $output .= "\t".$key.": ".$value."\n";
- }
- $output .= "}";
- return $output;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileInt.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileInt.php
deleted file mode 100644
index ebe86f86..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileInt.php
+++ /dev/null
@@ -1,40 +0,0 @@
-set($n);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = intval($value);
- }
-
- public function serialize() {
- return $this->intToString($this->data);
- }
-
- public function unserialize($data) {
- __construct($this->toInt($data));
- }
-
- public function __toString(){
- return "FileInt: {".$this->intAsString($this->data)."}";
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileObject.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileObject.php
deleted file mode 100644
index 0df17df1..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileObject.php
+++ /dev/null
@@ -1,168 +0,0 @@
-byteLength = $byteLength;
- }
-
- public function getByteLength(){
- if($this->byteLength >= 0){
- return $this->byteLength;
- }
- return $this->getLength();
- }
-
- public function getLength(){
- throw new Exception("Sub-class needs to implement this if it doesn't have a fixed length");
- }
-
- /**
- * Convert a string to byte format (maximum 4 bytes)
- * @param string $string Input string
- * @return int Output integer
- */
- public function toInt($string){
- $out = 0;
- for($i = 0, $len = min(4, strlen($string)); $i < $len; $i++){
- $out = $out | (ord($string[$i]) << (($len-$i-1)*8));
- }
- return $out;
- }
-
- /**
- * Convert a byte (stored in an integer) to a string
- * @param byte $int
- * @return string
- */
- public function byteToString($int){
- return $this->toString($int, 1);
- }
-
- /**
- * Convert a byte (stored in an integer) to a string
- * @param byte $int
- * @return string
- */
- public function byteAsString($int){
- return $this->asString($int, 1);
- }
-
- /**
- * Convert a short (stored in an integer) to a string
- * @param short $int
- * @return string
- */
- public function shortToString($int){
- return $this->toString($int, 2);
- }
-
- /**
- * Convert a short (stored in an integer) to a string
- * @param short $int
- * @return string
- */
- public function shortAsString($int){
- return $this->asString($int, 2);
- }
-
- /**
- * Convert a tri-byte (stored in an integer) to a string
- * @param tri-byte $int
- * @return string
- */
- public function triToString($int){
- return $this->toString($int, 3);
- }
-
- /**
- * Convert a tri-byte (stored in an integer) to a string
- * @param tri-byte $int
- * @return string
- */
- public function triAsString($int){
- return $this->asString($int, 3);
- }
-
- /**
- * Convert an integer to a string
- * @param int $int
- * @return string
- */
- public function intToString($int){
- return $this->toString($int, 4);
- }
-
- /**
- * Convert an integer to a string
- * @param int $int
- * @return string
- */
- public function intAsString($int){
- return $this->asString($int, 4);
- }
-
- /**
- * Convert a number of n bytes to a string
- * @param int $int Number that should be converted
- * @param int $size Number of bytes to convert
- * @return string Output string
- */
- private function toString($int, $size){
- $out = "";
- for($i = 0; $i < $size; $i++){
- $out = chr($int & 0xFF).$out;
- $int = $int >> 8;
- }
- return $out;
- }
-
- /**
- * Convert a number of n bytes to a string
- * @param int $int Number that should be converted
- * @param int $size Number of bytes to convert
- * @return string Output string
- */
- private function asString($int, $size){
- $out = "";
- for($i = 0; $i < $size; $i++){
- if($i > 0) $out = " ".$out;
- $byte = dechex($int & 0xFF);
- if(strlen($byte) == 1) $byte = "0".$byte;
- $out = $byte.$out;
- $int = $int >> 8;
- }
- return $out;
- }
-
- /**
- * Get the value
- * @return mixed Value to get
- */
- abstract public function get();
-
- /**
- * Set the value
- * @return mixed Value to set
- */
- abstract public function set($value);
-
- /**
- * Serialize the object
- * @return string String representation
- */
- abstract public function serialize();
-
- /**
- * Unserialize the object
- * @param string $data String representation
- */
- abstract public function unserialize($data);
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileRecord.php
deleted file mode 100644
index 494a72e4..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileRecord.php
+++ /dev/null
@@ -1,46 +0,0 @@
-record = $record;
- }
-
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- return $this->record->getLength();
- }
-
- public function get(){
- return $this->record;
- }
-
- public function set($record){
- $this->record = $record;
- }
-
- public function serialize() {
- return $this->record->serialize();
- }
-
- public function unserialize($data) {
- __construct($this->record->unserialize($data));
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileShort.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileShort.php
deleted file mode 100644
index 9921ea82..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileShort.php
+++ /dev/null
@@ -1,41 +0,0 @@
-set($n);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = intval($value) & 0xFFFF;
- }
-
- public function serialize() {
- return $this->shortToString($this->data);
- }
-
- public function unserialize($data) {
- __construct($this->toInt($data));
- }
-
-
- public function __toString(){
- return "FileShort: {".$this->shortAsString($this->data)."}";
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileString.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileString.php
deleted file mode 100644
index 16e906a6..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileString.php
+++ /dev/null
@@ -1,83 +0,0 @@
-forcedLength = -1;
- $this->data = "";
-
- if($second != null){
- $this->data = $first;
- $this->forcedLength = $second;
- }else if($first != null){
- if(is_string($first)){
- $this->data = $first;
- }else{
- $this->forcedLength = $first;
- }
- }
- }
-
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- if($this->forcedLength >= 0){
- return $this->forcedLength;
- }
- return strlen($this->data);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = $value;
- }
-
- public function serialize() {
- $output = $this->data;
- $curLength = strlen($output);
-
- if($this->forcedLength >= 0){
- if($this->forcedLength > $curLength){
- return str_pad($output, $this->forcedLength, "\0", STR_PAD_RIGHT);
- }elseif($this->forcedLength == $curLength){
- return $output;
- }else{
- return substr($output, 0, $this->forcedLength);
- }
- }
- return $output;
- }
-
- public function unserialize($data) {
- __construct($data);
- }
-
- public function __toString(){
- $out = "FileString";
- if($this->forcedLength >= 0){
- $out .= " ".$this->forcedLength;
- }
- $out .= ": {\"".str_replace(array(" ", "\0"), " ", $this->serialize())."\"}";
- return $out;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileTri.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/FileTri.php
deleted file mode 100644
index 6cacc0b0..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/FileTri.php
+++ /dev/null
@@ -1,41 +0,0 @@
-set($n);
- }
-
- public function get(){
- return $this->data;
- }
-
- public function set($value){
- $this->data = intval($value) & 0xFFFFFF;
- }
-
- public function serialize() {
- return $this->triToString($this->data);
- }
-
- public function unserialize($data) {
- __construct($this->toInt($data));
- }
-
-
- public function __toString(){
- return "FileTri: {".$this->triAsString($this->data)."}";
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Http.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Http.php
deleted file mode 100644
index 9e5852e3..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/Http.php
+++ /dev/null
@@ -1,171 +0,0 @@
- 'val1', 'var2' => 'val2') */
- $postdata = array(), /* HTTP POST Data ie. array('var1' => 'val1', 'var2' => 'val2') */
- $cookie = array(), /* HTTP Cookie Data ie. array('var1' => 'val1', 'var2' => 'val2') */
- $custom_headers = array(), /* Custom HTTP headers ie. array('Referer: http://localhost/ */
- $timeout = 1000, /* Socket timeout in milliseconds */
- $req_hdr = false, /* Include HTTP request headers */
- $res_hdr = false, /* Include HTTP response headers */
- $depth = 4 /* Depth of the iteration left (to avoid redirection loops) */
- )
- {
- if(self::$cache){
- $cacheFile = "cache/".$ip."/".str_replace("/", "...", $uri);
-
- if(is_file($cacheFile)){
- $data = file_get_contents($cacheFile);
-
- return self::resolveTruncated($data);
- }
- }
- $ret = '';
- $verb = strtoupper($verb);
- $cookie_str = '';
- $getdata_str = count($getdata) ? '?' : '';
- $postdata_str = '';
-
- foreach ($getdata as $k => $v)
- $getdata_str .= urlencode($k) .'='. urlencode($v);
-
- foreach ($postdata as $k => $v)
- $postdata_str .= urlencode($k) .'='. urlencode($v) .'&';
-
- foreach ($cookie as $k => $v)
- $cookie_str .= urlencode($k) .'='. urlencode($v) .'; ';
-
- $crlf = "\r\n";
- $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf;
- $req .= 'Host: '. $ip . $crlf;
- $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf;
- $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf;
- $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf;
- $req .= 'Accept-Encoding: deflate' . $crlf;
- $req .= 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' . $crlf;
-
-
- foreach ($custom_headers as $k => $v)
- $req .= $k .': '. $v . $crlf;
-
- if (!empty($cookie_str))
- $req .= 'Cookie: '. substr($cookie_str, 0, -2) . $crlf;
-
- if ($verb == 'POST' && !empty($postdata_str))
- {
- $postdata_str = substr($postdata_str, 0, -1);
- $req .= 'Content-Type: application/x-www-form-urlencoded' . $crlf;
- $req .= 'Content-Length: '. strlen($postdata_str) . $crlf . $crlf;
- $req .= $postdata_str;
- }
- else $req .= $crlf;
-
- if ($req_hdr)
- $ret .= $req;
-
- if (($fp = @fsockopen($ip, $port, $errno, $errstr)) == false)
- return "Error $errno: $errstr\n";
-
- stream_set_timeout($fp, 0, $timeout * 1000);
-
- fputs($fp, $req);
- $ret .= stream_get_contents($fp);
- fclose($fp);
-
- $headerSplit = strpos($ret, "\r\n\r\n");
- $header = substr($ret, 0, $headerSplit);
-
- $redirectURL = self::CheckForRedirect($header);
-
- if($redirectURL !== false){
- if($depth > 0){
- $url_parts = parse_url($redirectURL);
- $url_parts["port"] = isset($url_parts["port"]) ? $url_parts["port"] : 80;
- $url_parts["path"] = isset($url_parts["path"]) ? $url_parts["path"] : "/";
-
- return self::FullRequest($verb, $url_parts["host"], $url_parts["port"], $url_parts["path"], $getdata, $postdata, $cookie, $custom_headers, $timeout, $req_hdr, $res_hdr, $depth-1);
- }else{
- return "Redirect loop, stopping...";
- }
- }
-
- $truncated = false;
- $headerLines = explode("\r\n", $header);
- foreach($headerLines as $line){
- list($name, $value) = explode(":", $line);
- $name = trim($name);
- $value = trim($value);
-
- if(strtolower($name) == "transfer-encoding" && strtolower($value) == "chunked"){ //TODO: Put right values!
- $truncated = true;
- }
- }
-
- if (!$res_hdr)
- $ret = substr($ret, $headerSplit + 4);
-
- if($truncated){
- $ret = self::resolveTruncated($ret);
- }
- if(self::$cache){
- if(!is_dir("cache")){
- mkdir("cache");
- }
- if(!is_dir("cache/".$ip)){
- mkdir("cache/".$ip);
- }
- if(!is_file("cache/".$ip."/".str_replace("/", "...", $uri))){
- $h = fopen("cache/".$ip."/".str_replace("/", "...", $uri), "w");
- fwrite($h, $ret);
- fclose($h);
- }
- }
-
- return $ret;
- }
-
- private static function resolveTruncated($data){
- $pos = 0;
- $end = strlen($data);
- $out = "";
-
- while($pos < $end){
- $endVal = strpos($data, "\r\n", $pos);
- $value = hexdec(substr($data, $pos, $endVal-$pos));
- $out .= substr($data, $endVal+2, $value);
- $pos = $endVal+2+$value;
- }
-
- return $out;
- }
-
- private static function CheckForRedirect($header){
- $firstLine = substr($header, 0, strpos($header, "\r\n"));
- list($httpVersion, $statusCode, $message) = explode(" ", $firstLine);
-
- if(substr($statusCode, 0, 1) == "3"){
- $part = substr($header, strpos(strtolower($header), "location: ")+strlen("location: "));
- $location = trim(substr($part, 0, strpos($part, "\r\n")));
-
- if(strlen($location) > 0){
- return $location;
- }
- }
- return false;
- }
-}
-?>
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/ImageHandler.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/ImageHandler.php
deleted file mode 100644
index f620fc1f..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/ImageHandler.php
+++ /dev/null
@@ -1,28 +0,0 @@
-
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php
deleted file mode 100644
index 9532bbf1..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/MOBI.php
+++ /dev/null
@@ -1,205 +0,0 @@
-setInternetSource($url); //Load URL, the result will be cleaned using a Readability port
- * $mobi->setFileSource($file); //Load a local file without any extra changes
- * $mobi->setData($data); //Load data
- *
- * //If you want, you can set some optional settings
- * $options = array(
- * "title"=>"Insert title here",
- * "author"=>"Author"
- * );
- * $mobi->setOptions($options);
- *
- * //Then there are two ways to output it:
- * $mobi->save($file); //Save the file locally
- * $mobi->download($name); //Let the client download the file, make sure the page
- * //that calls it doesn't output anything, otherwise it might
- * //conflict with the download. $name contains the file name,
- * //usually something like "title.mobi" (where the title should
- * //be cleaned so as not to contain illegal characters).
- *
- *
- * @author Sander Kromwijk
- */
-class MOBI {
- private $source = false;
- private $images = array();
- private $optional = array();
- private $imgCounter = 0;
- private $debug = false;
- private $prc = false;
-
- public function __construct(){
-
- }
-
- public function getTitle(){
- if(isset($this->optional["title"])){
- return $this->optional["title"];
- }
- return false;
- }
-
- /**
- * Set a content provider as source
- * @param ContentProvider $content Content Provider to use
- */
- public function setContentProvider($content){
- $this->setOptions($content->getMetaData());
- $this->images = $content->getImages();
- $this->setData($content->getTextData());
- }
-
- /**
- * Set a local file as source
- * @param string $file Path to the file
- */
- public function setFileSource($file){
- $this->setData(file_get_contents($file));
- }
-
- /**
- * Set the data to use
- * @param string $data Data to put in the file
- */
- public function setData($data){
- //$data = utf8_encode($data);
- $data = CharacterEntities::convert($data);
- //$data = utf8_decode($data);
- //$this->source = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data);
- $this->source = $data;
- $this->prc = false;
- }
-
- /**
- * Set the images to use
- * @param array $data Data to put in the file
- */
- public function setImages($data){
- $this->images = $data;
- $this->prc = false;
- }
-
- /**
- * Set options, usually for things like titles, authors, etc...
- * @param array $options Options to set
- */
- public function setOptions($options){
- $this->optional = $options;
- $this->prc = false;
- }
-
- /**
- * Prepare the prc file
- * @return Prc The file that can be used to be saved/downloaded
- */
- private function preparePRC(){
- if($this->source === false){
- throw new Exception("No data set");
- }
- if($this->prc !== false) return $this->prc;
-
- $data = $this->source;
- $len = strlen($data);
-
- $settings = new Settings($this->optional);
- $rec = new RecordFactory($settings);
- $dataRecords = $rec->createRecords($data);
- $nRecords = sizeof($dataRecords);
- $mobiHeader = new PalmRecord($settings, $dataRecords, $nRecords, $len, sizeof($this->images));
- array_unshift($dataRecords, $mobiHeader);
- $dataRecords = array_merge($dataRecords, $this->images);
- $mobiFooter1 = new PFLISRecord($len);
- $mobiFooter2 = new PFCISRecord($len);
- $mobiFooter3 = new PEOFRecord($len);
- $dataRecords[] = $mobiFooter1;
- $dataRecords[] = $mobiFooter2;
- $dataRecords[] = $mobiFooter3;
- /*$dataRecords = array_merge($dataRecords, $mobiFooter);
- *$dataRecords[] = $rec->createFLISRecord();*
- $dataRecords[] = $rec->createFCISRecord($len);
- $dataRecords[] = $rec->createEOFRecord();*/
- $this->prc = new Prc($settings, $dataRecords);
- return $this->prc;
- }
-
- /**
- * Save the file locally
- * @param string $filename Path to save the file
- */
- public function save($filename){
- $prc = $this->preparePRC();
- $prc->save($filename);
- }
-
- /**
- * Let the client download the file. Warning! No data should be
- * outputted before or after.
- * @param string $name Name used for download, usually "title.mobi"
- */
- public function download($name){
- $prc = $this->preparePRC();
- $data = $prc->serialize();
- $length = strlen($data);
-
- if($this->debug) return; //In debug mode, don't start the download
-/*
- header("Content-Type: application/x-mobipocket-ebook");
- header("Content-Disposition: attachment; filename=\"".$name."\"");
- header("Content-Transfer-Encoding: binary");
- header("Accept-Ranges: bytes");
- header("Cache-control: private");
- header('Pragma: private');
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Content-Length: ".$length);
- echo $data;*/
-
-
- $hh = fopen("D:\hakuna.mobi", "w");
- fwrite($hh, $data);
- fclose($hh);
- //Finished!
- }
-
-}
-?>
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/MultipleFileHandler.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/MultipleFileHandler.php
deleted file mode 100644
index e9792816..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/MultipleFileHandler.php
+++ /dev/null
@@ -1,136 +0,0 @@
-".$title."".$contents."Contents
";
- $toc .= "
";
-
- return $toc;
- }
- /**
- * Get the images (an array containing the jpeg data). Array entry 0 will
- * correspond to image record 0.
- * @return array
- */
- public function getImages(){
- return $this->images;
- }
-
- /**
- * Get the metadata in the form of a hashtable (for example, title or author).
- * @return array
- */
- public function getMetaData(){
- return $this->metadata;
- }
-
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/OnlineArticle.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/OnlineArticle.php
deleted file mode 100644
index ec3182fe..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/OnlineArticle.php
+++ /dev/null
@@ -1,116 +0,0 @@
-init();
- if(!isset($this->metadata["title"])){
- $this->metadata["title"] = CharacterEntities::convert(strip_tags($r->getTitle()->innerHTML));
- }
- if(!isset($this->metadata["author"])){
- $parts = parse_url($url);
- $this->metadata["author"] = $parts["host"];
- }
-
- $article = $r->getContent()->innerHTML;
- if(substr($article, 0, 5) == "".$article."";
- }else{
- $article = "".$article."";
- }
- $doc = new DOMDocument();
- @$doc->loadHTML($article) or die($article);
- $doc->normalizeDocument();
-
- $this->images = $this->handleImages($doc, $url);
- $this->text = $doc->saveHTML();
- }
-
- /**
- * Get the text data to be integrated in the MOBI file
- * @return string
- */
- public function getTextData(){
- return $this->text;
- }
- /**
- * Get the images (an array containing the jpeg data). Array entry 0 will
- * correspond to image record 0.
- * @return array
- */
- public function getImages(){
- return $this->images;
- }
- /**
- * Get the metadata in the form of a hashtable (for example, title or author).
- * @return array
- */
- public function getMetaData(){
- return $this->metadata;
- }
- /**
- *
- * @param DOMElement $dom
- * @return array
- */
- private function handleImages($dom, $url){
- $images = array();
-
- $parts = parse_url($url);
-
- $savedImages = array();
-
- $imgElements = $dom->getElementsByTagName('img');
- foreach($imgElements as $img) {
- $src = $img->getAttribute("src");
-
- $is_root = false;
- if(substr($src, 0, 1) == "/"){
- $is_root = true;
- }
-
- $parsed = parse_url($src);
-
- if(!isset($parsed["host"])){
- if($is_root){
- $src = http_build_url($url, $parsed, HTTP_URL_REPLACE);
- }else{
- $src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH);
- }
- }
- $img->setAttribute("src", "");
- if(isset($savedImages[$src])){
- $img->setAttribute("recindex", $savedImages[$src]);
- }else{
- $image = ImageHandler::DownloadImage($src);
-
- if($image !== false){
- $images[$this->imgCounter] = new FileRecord(new Record($image));
-
- $img->setAttribute("recindex", $this->imgCounter);
- $savedImages[$src] = $this->imgCounter;
- $this->imgCounter++;
- }
- }
- }
-
- return $images;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PEOFRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PEOFRecord.php
deleted file mode 100644
index a2b0fee8..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PEOFRecord.php
+++ /dev/null
@@ -1,49 +0,0 @@
-elements = new FileElement(array(
-
- "offset44"=>new FileInt(0xe98e0d0a)
- ));
- }
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- return $this->elements->getByteLength();
- }
-
- public function get(){
- return $this;
- }
-
- public function set($elements){
- throw new Exception("Unallowed set");
- }
-
- public function serialize() {
- return $this->elements->serialize();
- }
-
- public function unserialize($data) {
- $this->elements->unserialize($data);
- }
-
- public function __toString(){
- $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
- $output .= $this->elements;
- return $output;
- }
-
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php
deleted file mode 100644
index 9e72cc1c..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFCISRecord.php
+++ /dev/null
@@ -1,59 +0,0 @@
-elements = new FileElement(array(
- "offset0"=>new FileString("FCIS", 4), //FCIS
- "offset4"=>new FileInt(0x014),
- "offset8"=>new FileInt(0x10),
- "offset12"=>new FileInt(0x01),
- "offset16"=>new FileInt(),
- "offset20"=>new FileInt($leng),
- "offset24"=>new FileInt(),
- "offset28"=>new FileInt(0x20),
- "offset32"=>new FileInt(0x08),
- "offset36"=>new FileShort(0x01),
- "offset38"=>new FileShort(0x01),
- "offset40"=>new FileInt()
- ));
- }
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- return $this->elements->getByteLength();
- }
-
- public function get(){
- return $this;
- }
-
- public function set($elements){
- throw new Exception("Unallowed set");
- }
-
- public function serialize() {
- return $this->elements->serialize();
- }
-
- public function unserialize($data) {
- $this->elements->unserialize($data);
- }
-
- public function __toString(){
- $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
- $output .= $this->elements;
- return $output;
- }
-
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php
deleted file mode 100644
index dbd8ecf5..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PFLISRecord.php
+++ /dev/null
@@ -1,58 +0,0 @@
-elements = new FileElement(array(
- "offsetL0"=>new FileString("FLIS", 4), //FLIS
- "offsetL4"=>new FileInt(0x08),
- "offsetL8"=>new FileShort(0x41),
- "offsetL10"=>new FileString(6),
- "offsetL16"=>new FileInt(0xFFFFFFFF),
- "offsetL20"=>new FileShort(0x01),
- "offsetL22"=>new FileShort(0x03),
- "offsetL24"=>new FileInt(0x03),
- "offsetL28"=>new FileInt(0x01),
- "offsetL32"=>new FileInt(0xFFFFFFFF)
-
- ));
- }
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- return $this->elements->getByteLength();
- }
-
- public function get(){
- return $this;
- }
-
- public function set($elements){
- throw new Exception("Unallowed set");
- }
-
- public function serialize() {
- return $this->elements->serialize();
- }
-
- public function unserialize($data) {
- $this->elements->unserialize($data);
- }
-
- public function __toString(){
- $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
- $output .= $this->elements;
- return $output;
- }
-
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php
deleted file mode 100644
index 29dc978a..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PalmRecord.php
+++ /dev/null
@@ -1,154 +0,0 @@
-elements = new FileElement(array(
- "compression"=>new FileShort(),
- "unused"=>new FileShort(),
- "textLength"=>new FileInt(),
- "recordCount"=>new FileShort(),
- "recordSize"=>new FileShort(),
- "encryptionType"=>new FileShort(),
- "unused2"=>new FileShort(),
- //MOBI Header
- "mobiIdentifier"=>new FileString("MOBI", 4),
- "mobiHeaderLength"=>new FileInt(),
- "mobiType"=>new FileInt(),
- "textEncoding"=>new FileInt(),
- "uniqueID"=>new FileInt(),
- "fileVersion"=>new FileInt(),
- "reserved"=>new FileString(40),
- "firstNonBookIndex"=>new FileInt(),
- "fullNameOffset"=>new FileInt(),
- "fullNameLength"=>new FileInt(),
- "locale"=>new FileInt(),
- "inputLanguage"=>new FileInt(),
- "outputLanguage"=>new FileInt(),
- "minimumVersion"=>new FileInt(),
- "firstImageIndex"=>new FileInt(),
- "huffmanRecordOffset"=>new FileInt(),
- "huffmanRecordCount"=>new FileInt(),
- "unused3"=>new FileString(8),
- "exthFlags"=>new FileInt(0x50),
- "unknown"=>new FileString(32),
- "drmOffset"=>new FileInt(0xFFFFFFFF),
- "drmCount"=>new FileInt(0xFFFFFFFF),
- "drmSize"=>new FileInt(),
- "drmFlags"=>new FileInt(),
- "mobiFiller"=>new FileString(12),
- "offset192"=>new FileShort(0x01),
- "offset194"=>new FileShort(),
- "offset196"=>new FileInt(0x01),
- "offset200"=>new FileInt(),
- "offset204"=>new FileInt(0x01),
- "offset208"=>new FileInt(),
- "offset212"=>new FileInt(0x01),
- "offset216"=>new FileString(8),
- "offset224"=>new FileInt(0xFFFFFFFF),
- "offset228"=>new FileInt(),
- "offset232"=>new FileString(8),
- "offset240"=>new FileInt(0x01),
- "offset244"=>new FileInt(0xFFFFFFFF),
- //EXTH Header
- "exthIdentifier"=>new FileString("EXTH", 4),
- "exthHeaderLength"=>new FileInt(),
- "exthRecordCount"=>new FileInt(),
- "exthRecords"=>new FileElement(),
- "exthPadding"=>new FileString(),//added the 2 extra pad bytes that comes before name/title
- //"fullNamePadding"=>new FileString(100),
- "fullName"=>new FileString()
- ));
-
- //Set values from the info block
- foreach($settings->values as $name => $val){
- //echo $name.", ";
- if($this->elements->exists($name)){
- $this->elements->get($name)->set($settings->get($name));
- }
- }
-
- $els = $settings->values;
-
- $exthElems = new FileElement();
- $i = 0;
- $l = 0;
- foreach($els as $name=>$val){
- $type = EXTHHelper::textToType($name);
- if($type !== false){
- $type = new FileInt($type);
- $length = new FileInt(8+strlen($val));
- $data = new FileString($val);
- $l += 8+strlen($val);
- $exthElems->add("type".$i, $type);
- $exthElems->add("length".$i, $length);
- $exthElems->add("data".$i, $data);
- $i++;
- }
- }
-
- if($images > 0){
- $this->elements->get("firstImageIndex")->set($textRecords+2);
- }
- $this->elements->get("firstNonBookIndex")->set($textRecords+2+$images);
- $this->elements->get("reserved")->set(str_pad("", 40, chr(255), STR_PAD_RIGHT));
- $this->elements->get("exthRecordCount")->set($i);
- $this->elements->set("exthRecords", $exthElems);
- $pad = $l%4;
- $pad = (4-$pad)%4;
- $this->elements->get("exthPadding")->set(str_pad("", $pad+2, "\0", STR_PAD_RIGHT));
- $this->elements->get("exthHeaderLength")->set(12+$l+$pad);
-
-
- $this->elements->get("recordCount")->set($textRecords);
-
- $this->elements->get("fullNameOffset")->set($this->elements->offsetToEntry("fullName"));//need to be checked
- $this->elements->get("fullNameLength")->set(strlen($settings->get("title")));
- $this->elements->get("fullName")->set($settings->get("title"));
- $this->elements->get("textLength")->set($textLength);
-
- $this->elements->get("offset194")->set($textRecords+2+$images);
- $this->elements->get("offset200")->set($textRecords+4+$images);
- $this->elements->get("offset208")->set($textRecords+3+$images);
- $this->elements->get("offset232")->set(str_pad("", 8, chr(255), STR_PAD_RIGHT));
- }
-
- public function getByteLength(){
- return $this->getLength();
- }
-
- public function getLength(){
- return $this->elements->getByteLength();
- }
-
- public function get(){
- return $this;
- }
-
- public function set($elements){
- throw new Exception("Unallowed set");
- }
-
- public function serialize() {
- return $this->elements->serialize();
- }
-
- public function unserialize($data) {
- $this->elements->unserialize($data);
- }
-
- public function __toString(){
- $output = "PalmDoc Record (".$this->getByteLength()." bytes):\n";
- $output .= $this->elements;
- return $output;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Prc.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Prc.php
deleted file mode 100644
index 1507e24b..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/Prc.php
+++ /dev/null
@@ -1,97 +0,0 @@
-new FileString(32),
- "attributes"=>new FileShort(),
- "version"=>new FileShort(),
- "creationTime"=>new FileDate(),
- "modificationTime"=>new FileDate(),
- "backupTime"=>new FileDate(),
- "modificationNumber"=>new FileInt(),
- "appInfoID"=>new FileInt(),
- "sortInfoID"=>new FileInt(),
- "prcType"=>new FileString(4),
- "creator"=>new FileString(4),
- "uniqueIDSeed"=>new FileInt(),
- "nextRecordListID"=>new FileInt(),
- "numberRecords"=>new FileShort(),
- "recordList"=>new FileElement(),
- "filler"=>new FileShort(),
- "records"=>new FileElement()
- ));
-
- //Set values from the info block
- foreach($this->elements as $name => $val){
- if($settings->exists($name)){
- $this->get($name)->set($settings->get($name));
- }
- }
-
- $this->get("numberRecords")->set(sizeof($records));
-
- $i = 0;
- foreach($records as $record){
- $offset = new FileInt();
- $attr = new FileByte();
- $uniqueID = new FileTri(2*$i);
-
- $this->elements["recordList"]->add("Rec".$i, new FileElement(array(
- "offset"=>$offset,
- "attribute"=>$attr,
- "uniqueID"=>$uniqueID
- )));
-
- $this->elements["records"]->add("Rec".$i, $record);
- $i+=1;
- }
-
- $this->updateOffsets($records);
- }
-
- public function getByteLength(){
- throw new Exception("Test");
- }
-
- public function updateOffsets($records){
- $base = $this->offsetToEntry("records");
-
- $i = 0;
-
- foreach($records as $record){
- $el = $this->elements["recordList"]->get("Rec".$i);
-
- $local = $this->elements["records"]->offsetToEntry("Rec".$i);
-
- $el->get("offset")->set($base+$local);
-
- $i++;
- }
- }
-
- public function save($file){
- $handle = fopen($file, "w");
- fwrite($handle, $this->serialize());
- fclose($handle);
- }
-
- public function output(){
- echo $this->serialize();
- }
-
- public function __toString(){
- $output = "Prc (".$this->getByteLength()." bytes): {\n";
- foreach($this->elements as $key=>$value){
- $output .= "\t".$key.": ".$value."\n";
- }
- $output .= "}";
- return $output;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/PreprocessedArticle.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/PreprocessedArticle.php
deleted file mode 100644
index 2e992404..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/PreprocessedArticle.php
+++ /dev/null
@@ -1,89 +0,0 @@
-text = $textData;
- $this->metadata = $metadata;
-
- $this->images = $this->downloadImages($imageLinks);
- }
-
- /**
- * Create a Preprocessed article from a json string
- * @param string $json JSON data. Should be of the following format:
- * {"text": "TEXT", "images: ["imageURL1", "imageURL2"], "metadata": {"key": "value"}}
- *
- * Note: Any image tags should have the recindex attribute set to the appropriate index (the
- * same index as the image in the array)
- * @return PreprocessedArticle The generated preprocessed array
- */
- static public function CreateFromJson($json){
- $data = json_decode($json);
- return new PreprocessedArticle($data["text"], $data["images"], $data["metadata"]);
- }
-
- /**
- * Get the text data to be integrated in the MOBI file
- * @return string
- */
- public function getTextData(){
- return $this->text;
- }
- /**
- * Get the images (an array containing the jpeg data). Array entry 0 will
- * correspond to image record 0.
- * @return array
- */
- public function getImages(){
- return $this->images;
- }
- /**
- * Get the metadata in the form of a hashtable (for example, title or author).
- * @return array
- */
- public function getMetaData(){
- return $this->metadata;
- }
- /**
- *
- * @param DOMElement $dom
- * @return array
- */
- private function downloadImages($links){
- $images = array();
- foreach($links as $link) {
- $imgFile = @imagecreatefromstring(Http::Request($link));
-
- if($imgFile === false){
- $imgFile = @imagecreate(1, 1);
- $black = @imagecolorallocate($imgFile, 255, 255, 255);
- }
- if($imgFile !== false){
- @imagefilter($imgFile, IMG_FILTER_GRAYSCALE);
-
- ob_start();
- @imagejpeg($imgFile);
- $image = ob_get_contents();
- ob_end_clean();
-
- $images[$this->imgCounter] = new FileRecord(new Record($image));
- imagedestroy($imgFile);
-
- $this->imgCounter++;
- }
- }
-
- return $images;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/RecognizeURL.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/RecognizeURL.php
deleted file mode 100644
index 6319ed57..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/RecognizeURL.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Record.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Record.php
deleted file mode 100644
index 3cb39582..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/Record.php
+++ /dev/null
@@ -1,96 +0,0 @@
-data = $data;
- if($length >= 0){
- $this->length = $length;
- }else{
- $this->length = strlen($data);
- }
- }
-
- public function compress($compression_method){
- switch($compression_method){
- case NO_COMPRESSION:
- //Finished!
- break;
- case PALMDOC_COMPRESSION:
- throw new Exception("Not implemented yet");
- break;
- case HUFF:
- throw new Exception("Not implemented yet");
- break;
- default:
- throw new Exception("Invalid argument");
- }
- }
-
- public function getByteLength(){
- return $this->getLength();
- }
-
- /**
- * Get the length of the record
- * @return int Length of the data
- */
- public function getLength(){
- return $this->length;
- }
-
- /**
- * Get the data contained in the record
- * @return string Data contained in the record
- */
- public function get(){
- return $this->data;
- }
-
- /**
- * Set the data contained in the record
- * @param string $value Data contained in the record
- */
- public function set($value){
- $this->data = $value;
- }
-
- public function serialize(){
- return $this->data;
- }
- public function unserialize($data){
- __construct($data);
- }
-
- public function __toString() {
- $toShow = $this->data;
- if(strlen($this->data) > 103){
- $toShow = substr($this->data, 0, 100)."...";
- }
- $out = "Record: {\n";
- $out .= "\t".htmlspecialchars($toShow)."\n";
- $out .= "}";
- return $out;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php
deleted file mode 100644
index 8bf0c97d..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/RecordFactory.php
+++ /dev/null
@@ -1,129 +0,0 @@
-settings = $settings;
- }
-
- /**
- * Create records from a data string
- * @param string $data
- * @return array(Record)
- */
- public function createRecords($data){
- $records = array();
- $size = $this->settings->get("recordSize");
- $compression = $this->settings->get("compression");
-
- $dataEntries = mb_str_split($data, $size);
-
- for($i = 0, $len = sizeof($dataEntries); $i < $len; $i++){
- $records[$i] = new Record($dataEntries[$i]);
- $records[$i]->compress($compression);
- }
-
- return $records;
- }
-
- public function createEOFRecord(){
- return new Record(0xe98e0d0a);
- }
-
- public function createFCISRecord($textLength){
- $r = "FCIS";
- $r .= $this->asString(20, 4);
- $r .= $this->asString(16, 4);
- $r .= $this->asString(1, 4);
- $r .= $this->asString(0, 4);
- $r .= $this->asString($textLength, 4);
- $r .= $this->asString(0, 4);
- $r .= $this->asString(32, 4);
- $r .= $this->asString(8, 4);
- $r .= $this->asString(1, 2);
- $r .= $this->asString(1, 2);
- $r .= $this->asString(0, 4);
- return new Record($r);
- }
-
- public function createFLISRecord(){
-
- $this->elements = new FileElement(array(
- "offsetL0"=>new FileString("FLIS", 4), //FLIS
- "offsetL4"=>new FileInt(0x08),
- "offsetL8"=>new FileShort(0x41),
- "offsetL10"=>new FileTri(),
- "offsetL16"=>new FileInt(0xFFFFFFFF),
- "offsetL20"=>new FileShort(0x01),
- "offsetL22"=>new FileShort(0x03),
- "offsetL24"=>new FileInt(0x03),
- "offsetL28"=>new FileInt(0x01),
- "offsetL32"=>new FileInt(0xFFFFFFFF)
- ));
-
- /*$r = "FLIS";
- $r .= $this->asString(8, 4);
- $r .= $this->asString(65, 2);
- $r .= $this->asString(0, 2);
- $r .= $this->asString(0, 4);
- $r .= $this->asString(-1, 4);
- $r .= $this->asString(1, 2);
- $r .= $this->asString(3, 2);
- $r .= $this->asString(3, 4);
- $r .= $this->asString(1, 4);
- $r .= $this->asString(-1, 4);
- return new Record($r);*/
- }
-
- private function asString($int, $size){
- $out = "";
- for($i = 0; $i < $size; $i++){
- if($i > 0) $out = " ".$out;
- $byte = dechex($int & 0xFF);
- if(strlen($byte) == 1) $byte = "0".$byte;
- $out = $byte.$out;
- $int = $int >> 8;
- }
- return $out;
- }
-
- public function __toString() {
- $out = "Record Factory: {\n";
- $out .= "\tRecord Size: ".$this->settings->get("recordSize")."\n";
- $out .= "\tCompression: ".$this->settings->get("compression")."\n";
- $out .= "}";
- return $out;
- }
-}
-function mb_str_split($string, $split_length = 1){
- mb_internal_encoding('UTF-8');
- mb_regex_encoding('UTF-8');
-
- $split_length = ($split_length <= 0) ? 1 : $split_length;
-
- $mb_strlen = mb_strlen($string, 'utf-8');
-
- $array = array();
-
- for($i = 0; $i < $mb_strlen; $i += $split_length){
- $array[] = mb_substr($string, $i, $split_length);
- }
-
- return $array;
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php
deleted file mode 100644
index 6bde0ba9..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/Settings.php
+++ /dev/null
@@ -1,95 +0,0 @@
-values = array(
- "attributes"=>0,
- "version"=>0,
- "creationTime"=>time()+94694400,
- "modificationTime"=>time()+94694400,
- "backupTime"=>0,
- "modificationNumber"=>0,
- "appInfoID"=>0,
- "sortInfoID"=>0,
- "prcType"=>"BOOK",
- "creator"=>"MOBI",
- "uniqueIDSeed"=>rand(),
- "nextRecordListID"=>0,
- "recordAttributes"=>0,
- "compression"=>NO_COMPRESSION,
- "recordSize"=>RECORD_SIZE,
- "encryptionType"=>NO_ENCRYPTION,
- "mobiIdentifier"=>"MOBI",
- "mobiHeaderLength"=>0xe8,
- "mobiType"=>MOBIPOCKET_BOOK,
- "textEncoding"=>UTF8,
- "uniqueID"=>rand(),
- "fileVersion"=>6,
- "locale"=>0x09,
- "inputLanguage"=>0,
- "outputLanguage"=>0,
- "minimumVersion"=>6,
- "huffmanRecordOffset"=>0,
- "huffmanRecordCount"=>0,
- "exthFlags"=>0x50,
- "drmOffset"=>0xFFFFFFFF,
- "drmCount"=>0xFFFFFFFF,
- "drmSize"=>0,
- "drmFlags"=>0,
- "extraDataFlags"=>0,
- "exthIdentifier"=>"EXTH",
- "title"=>"Unknown title",
- "author"=>"Unknown author",
- "subject"=>"Unknown subject"
- );
-
- foreach($additionalSettings as $key=>$value){
- $this->values[$key] = $value;
- }
- }
-
- /**
- * Get a value from the settings
- * @param string $key Key of the setting
- * @return mixed The value of the setting
- */
- public function get($key){
- return $this->values[$key];
- }
-
- /**
- * Checks if a value is set
- * @param string $key Key of the setting
- * @return bool True if the value exists
- */
- public function exists($key){
- return isset($this->values[$key]);
- }
-
- public function __toString() {
- $out = "Settings: {\n";
- foreach($this->values as $key=>$value){
- $out .= "\t".$key.": ".$value."\n";
- }
- $out .= "}";
- return $out;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/constants.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/constants.php
deleted file mode 100644
index bd363118..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/constants.php
+++ /dev/null
@@ -1,11 +0,0 @@
-id = intval(substr($ending, 0, strpos($ending, "/")));
-
- for($i = 1; $i <= max(1, $this->chapterCount); $i++){
- $this->addChapter($i);
- }
- }
-
- private function addChapter($n){
- $doc = new DOMDocument();
- $file = Http::Request(self::$prefix.$this->id."/".$n."/");
- @$doc->loadHTML($file) or die($file);
-
- if(!$this->downloadedMetadata){
- $this->loadMetadata($doc);
- $this->downloadedMetadata = true;
- }
- if($this->chapterCount < 0){
- $this->chapterCount = $this->getNumberChapters($doc);
-
- if($this->chapterCount > 4){
- die("Too many files to download, don't use php for this!");
- }
- }
-
- $textEl = $doc->getElementById("storytext");
- if($textEl == null) die("Error: ".$doc->saveHTML());
- $horizontalRulebars = $doc->getElementsByTagName('hr');
- /**
- * @var DOMNode
- */
- $hr;
- foreach($horizontalRulebars as $hr) {
- $hr->setAttribute("size", null);
- $hr->setAttribute("noshade", null);
- }
- $text = $this->innerHtml($textEl);
-
- $title = "";
- $selects = $doc->getElementsByTagName('select');
- foreach($selects as $select) {
- if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){
- $options = $select->getElementsByTagName("option");
-
- $test = $n.". ";
- foreach($options as $option){
- $val = $option->nodeValue;
- if(substr($val, 0, strlen($test)) == $test){
- $title = substr($val, strlen($test));
- break;
- }
- }
- break;
- }
- }
- $this->addPage($text, $title);
- }
-
- private function getNumberChapters($doc){
- $selects = $doc->getElementsByTagName('select');
- foreach($selects as $select) {
- if($select->hasAttribute("name") && $select->getAttribute("name") == "chapter"){
- $options = $select->getElementsByTagName("option");
-
- $count = $options->length;
- return $count;
- }
- }
- }
-
- private function loadMetadata($doc){
- //Author
- $links = $doc->getElementsByTagName('a');
- foreach($links as $link) {
- if($link == null){
- var_dump($link);
- }
- if($link->hasAttribute("href") && substr($link->getAttribute("href"), 0, 3) == "/u/"){
- $this->setMetadata("author", $link->nodeValue);
- }
- }
- //Title
- /*
- $links = $doc->getElementsByTagName('link');
- foreach($links as $link) {
- if($link->hasAttribute("rel") && $link->getAttribute("rel") == "canonical"){
- $url = $link->getAttribute("href");
- $title = str_replace("_", " ", substr($url, strrpos($url, "/")+1));
- $this->setMetadata("title", $title);
- }
- }*/
-
- //TODO: Find a more reliable way to extract the title
- $title = $doc->getElementsByTagName("b")->item(0)->nodeValue;
- $this->setMetadata("title", $title);
- }
-
- private function innerHtml($node){
- $doc = new DOMDocument();
- foreach ($node->childNodes as $child)
- $doc->appendChild($doc->importNode($child, true));
-
- return $doc->saveHTML();
- }
-
- public static function Matches($url){
- //TODO: Implement with regex
- return strpos($url, self::$prefix) !== false;
- }
-}
-?>
diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/http_build_url.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/http_build_url.php
deleted file mode 100644
index b475edb0..00000000
--- a/inc/3rdparty/libraries/send2kindle/MOBIClass/http_build_url.php
+++ /dev/null
@@ -1,94 +0,0 @@
-registerNodeClass('DOMElement', 'JSLikeHTMLElement');
-* $doc->loadHTML(' ";
- }
- $toc .= "".($i+1).". ".$entry["title"]." Chapter 2
]*>[ \n\r\t]*){2,}/i',
- 'replaceFonts' => '/<(\/?)font[^>]*>/i',
- // 'trimRe' => '/^\s+|\s+$/g', // PHP has trim()
- 'normalize' => '/\s{2,}/',
- 'killBreaks' => '/(
(\s| ?)*){1,}/',
- 'video' => '/http:\/\/(www\.)?(youtube|vimeo)\.com/i',
- 'skipFootnoteLink' => '/^\s*(\[?[a-z0-9]{1,2}\]?|^|edit|citation needed)\s*$/i'
- );
-
- /* constants */
- const FLAG_STRIP_UNLIKELYS = 1;
- const FLAG_WEIGHT_CLASSES = 2;
- const FLAG_CLEAN_CONDITIONALLY = 4;
-
- /**
- * Create instance of Readability
- * @param string UTF-8 encoded string
- * @param string (optional) URL associated with HTML (used for footnotes)
- */
- function __construct($html, $url=null)
- {
- /* Turn all double br's into p's */
- /* Note, this is pretty costly as far as processing goes. Maybe optimize later. */
- $html = preg_replace($this->regexps['replaceBrs'], '
', $html); - $html = preg_replace($this->regexps['replaceFonts'], '<$1span>', $html); - $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); - $this->dom = new DOMDocument(); - $this->dom->preserveWhiteSpace = false; - $this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); - @$this->dom->loadHTML($html); - $this->url = $url; - } - - /** - * Get article title element - * @return DOMElement - */ - public function getTitle() { - return $this->articleTitle; - } - - /** - * Get article content element - * @return DOMElement - */ - public function getContent() { - return $this->articleContent; - } - - /** - * Runs readability. - * - * Workflow: - * 1. Prep the document by removing script tags, css, etc. - * 2. Build readability's DOM tree. - * 3. Grab the article content from the current dom tree. - * 4. Replace the current DOM tree with the new one. - * 5. Read peacefully. - * - * @return boolean true if we found content, false otherwise - **/ - public function init() - { - $this->removeScripts($this->dom); - - // Assume successful outcome - $this->success = true; - - $bodyElems = $this->dom->getElementsByTagName('body'); - if ($bodyElems->length > 0) { - if ($this->bodyCache == null) { - $this->bodyCache = $bodyElems->item(0)->innerHTML; - } - if ($this->body == null) { - $this->body = $bodyElems->item(0); - } - } - - $this->prepDocument(); - - //die($this->dom->documentElement->parentNode->nodeType); - //$this->setInnerHTML($this->dom->documentElement, $this->getInnerHTML($this->dom->documentElement)); - //die($this->getInnerHTML($this->dom->documentElement)); - - /* Build readability's DOM tree */ - $overlay = $this->dom->createElement('div'); - $innerDiv = $this->dom->createElement('div'); - $articleTitle = $this->getArticleTitle(); - $articleContent = $this->grabArticle(); - - if (!$articleContent) { - $this->success = false; - $articleContent = $this->dom->createElement('div'); - $articleContent->setAttribute('id', 'readability-content'); - $articleContent->innerHTML = '
Sorry, Readability was unable to parse this page for content.
'; - } - - $overlay->setAttribute('id', 'readOverlay'); - $innerDiv->setAttribute('id', 'readInner'); - - /* Glue the structure of our document together. */ - $innerDiv->appendChild($articleTitle); - $innerDiv->appendChild($articleContent); - $overlay->appendChild($innerDiv); - - /* Clear the old HTML, insert the new content. */ - $this->body->innerHTML = ''; - $this->body->appendChild($overlay); - //document.body.insertBefore(overlay, document.body.firstChild); - $this->body->removeAttribute('style'); - - $this->postProcessContent($articleContent); - - // Set title and content instance variables - $this->articleTitle = $articleTitle; - $this->articleContent = $articleContent; - - return $this->success; - } - - /** - * Debug - */ - protected function dbg($msg) { - if ($this->debug) echo '* ',$msg, '').replace(readability.regexps.replaceFonts, '<$1span>'); - // We do this in the constructor for PHP as that's when we have raw HTML - before parsing it into a DOM tree. - // Manipulating innerHTML as it's done in JS is not possible in PHP. - } - - /** - * For easier reading, convert this document to have footnotes at the bottom rather than inline links. - * @see http://www.roughtype.com/archives/2010/05/experiments_in.php - * - * @return void - **/ - public function addFootnotes($articleContent) { - $footnotesWrapper = $this->dom->createElement('div'); - $footnotesWrapper->setAttribute('id', 'readability-footnotes'); - $footnotesWrapper->innerHTML = '
tags, etc.
- *
- * @param DOMElement
- * @return void
- */
- function prepArticle($articleContent) {
- $this->cleanStyles($articleContent);
- $this->killBreaks($articleContent);
- if ($this->revertForcedParagraphElements) {
- $this->revertReadabilityStyledElements($articleContent);
- }
-
- /* Clean out junk from the article content */
- $this->cleanConditionally($articleContent, 'form');
- $this->clean($articleContent, 'object');
- $this->clean($articleContent, 'h1');
-
- /**
- * If there is only one h2, they are probably using it
- * as a header and not a subheader, so remove it since we already have a header.
- ***/
- if ($articleContent->getElementsByTagName('h2')->length == 1) {
- $this->clean($articleContent, 'h2');
- }
- $this->clean($articleContent, 'iframe');
-
- $this->cleanHeaders($articleContent);
-
- /* Do these last as the previous stuff may have removed junk that will affect these */
- $this->cleanConditionally($articleContent, 'table');
- $this->cleanConditionally($articleContent, 'ul');
- $this->cleanConditionally($articleContent, 'div');
-
- /* Remove extra paragraphs */
- $articleParagraphs = $articleContent->getElementsByTagName('p');
- for ($i = $articleParagraphs->length-1; $i >= 0; $i--)
- {
- $imgCount = $articleParagraphs->item($i)->getElementsByTagName('img')->length;
- $embedCount = $articleParagraphs->item($i)->getElementsByTagName('embed')->length;
- $objectCount = $articleParagraphs->item($i)->getElementsByTagName('object')->length;
-
- if ($imgCount === 0 && $embedCount === 0 && $objectCount === 0 && $this->getInnerText($articleParagraphs->item($i), false) == '')
- {
- $articleParagraphs->item($i)->parentNode->removeChild($articleParagraphs->item($i));
- }
- }
-
- try {
- $articleContent->innerHTML = preg_replace('/
]*>\s*
innerHTML);
- //articleContent.innerHTML = articleContent.innerHTML.replace(/
]*>\s*
dbg("Cleaning innerHTML of breaks failed. This is an IE strict-block-elements bug. Ignoring.: " . $e);
- }
- }
-
- /**
- * Initialize a node with the readability object. Also checks the
- * className/id for special names to add to its score.
- *
- * @param Element
- * @return void
- **/
- protected function initializeNode($node) {
- $readability = $this->dom->createAttribute('readability');
- $readability->value = 0; // this is our contentScore
- $node->setAttributeNode($readability);
-
- switch (strtoupper($node->tagName)) { // unsure if strtoupper is needed, but using it just in case
- case 'DIV':
- $readability->value += 5;
- break;
-
- case 'PRE':
- case 'TD':
- case 'BLOCKQUOTE':
- $readability->value += 3;
- break;
-
- case 'ADDRESS':
- case 'OL':
- case 'UL':
- case 'DL':
- case 'DD':
- case 'DT':
- case 'LI':
- case 'FORM':
- $readability->value -= 3;
- break;
-
- case 'H1':
- case 'H2':
- case 'H3':
- case 'H4':
- case 'H5':
- case 'H6':
- case 'TH':
- $readability->value -= 5;
- break;
- }
- $readability->value += $this->getClassWeight($node);
- }
-
- /***
- * grabArticle - Using a variety of metrics (content score, classname, element types), find the content that is
- * most likely to be the stuff a user wants to read. Then return it wrapped up in a div.
- *
- * @return DOMElement
- **/
- protected function grabArticle($page=null) {
- $stripUnlikelyCandidates = $this->flagIsActive(self::FLAG_STRIP_UNLIKELYS);
- if (!$page) $page = $this->dom;
- $allElements = $page->getElementsByTagName('*');
- /**
- * First, node prepping. Trash nodes that look cruddy (like ones with the class name "comment", etc), and turn divs
- * into P tags where they have been used inappropriately (as in, where they contain no other block level elements.)
- *
- * Note: Assignment from index for performance. See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5
- * TODO: Shouldn't this be a reverse traversal?
- **/
- $node = null;
- $nodesToScore = array();
- for ($nodeIndex = 0; ($node = $allElements->item($nodeIndex)); $nodeIndex++) {
- //for ($nodeIndex=$targetList->length-1; $nodeIndex >= 0; $nodeIndex--) {
- //$node = $targetList->item($nodeIndex);
- $tagName = strtoupper($node->tagName);
- /* Remove unlikely candidates */
- if ($stripUnlikelyCandidates) {
- $unlikelyMatchString = $node->getAttribute('class') . $node->getAttribute('id');
- if (
- preg_match($this->regexps['unlikelyCandidates'], $unlikelyMatchString) &&
- !preg_match($this->regexps['okMaybeItsACandidate'], $unlikelyMatchString) &&
- $tagName != 'BODY'
- )
- {
- $this->dbg('Removing unlikely candidate - ' . $unlikelyMatchString);
- //$nodesToRemove[] = $node;
- $node->parentNode->removeChild($node);
- $nodeIndex--;
- continue;
- }
- }
-
- if ($tagName == 'P' || $tagName == 'TD' || $tagName == 'PRE') {
- $nodesToScore[] = $node;
- }
-
- /* Turn all divs that don't have children block level elements into p's */
- if ($tagName == 'DIV') {
- if (!preg_match($this->regexps['divToPElements'], $node->innerHTML)) {
- //$this->dbg('Altering div to p');
- $newNode = $this->dom->createElement('p');
- try {
- $newNode->innerHTML = $node->innerHTML;
- //$nodesToReplace[] = array('new'=>$newNode, 'old'=>$node);
- $node->parentNode->replaceChild($newNode, $node);
- $nodeIndex--;
- $nodesToScore[] = $node; // or $newNode?
- }
- catch(Exception $e) {
- $this->dbg('Could not alter div to p, reverting back to div.: ' . $e);
- }
- }
- else
- {
- /* EXPERIMENTAL */
- // TODO: change these p elements back to text nodes after processing
- for ($i = 0, $il = $node->childNodes->length; $i < $il; $i++) {
- $childNode = $node->childNodes->item($i);
- if ($childNode->nodeType == 3) { // XML_TEXT_NODE
- //$this->dbg('replacing text node with a p tag with the same content.');
- $p = $this->dom->createElement('p');
- $p->innerHTML = $childNode->nodeValue;
- $p->setAttribute('style', 'display: inline;');
- $p->setAttribute('class', 'readability-styled');
- $childNode->parentNode->replaceChild($p, $childNode);
- }
- }
- }
- }
- }
-
- /**
- * Loop through all paragraphs, and assign a score to them based on how content-y they look.
- * Then add their score to their parent node.
- *
- * A score is determined by things like number of commas, class names, etc. Maybe eventually link density.
- **/
- $candidates = array();
- for ($pt=0; $pt < count($nodesToScore); $pt++) {
- $parentNode = $nodesToScore[$pt]->parentNode;
- // $grandParentNode = $parentNode ? $parentNode->parentNode : null;
- $grandParentNode = !$parentNode ? null : (($parentNode->parentNode instanceof DOMElement) ? $parentNode->parentNode : null);
- $innerText = $this->getInnerText($nodesToScore[$pt]);
-
- if (!$parentNode || !isset($parentNode->tagName)) {
- continue;
- }
-
- /* If this paragraph is less than 25 characters, don't even count it. */
- if(strlen($innerText) < 25) {
- continue;
- }
-
- /* Initialize readability data for the parent. */
- if (!$parentNode->hasAttribute('readability'))
- {
- $this->initializeNode($parentNode);
- $candidates[] = $parentNode;
- }
-
- /* Initialize readability data for the grandparent. */
- if ($grandParentNode && !$grandParentNode->hasAttribute('readability') && isset($grandParentNode->tagName))
- {
- $this->initializeNode($grandParentNode);
- $candidates[] = $grandParentNode;
- }
-
- $contentScore = 0;
-
- /* Add a point for the paragraph itself as a base. */
- $contentScore++;
-
- /* Add points for any commas within this paragraph */
- $contentScore += count(explode(',', $innerText));
-
- /* For every 100 characters in this paragraph, add another point. Up to 3 points. */
- $contentScore += min(floor(strlen($innerText) / 100), 3);
-
- /* Add the score to the parent. The grandparent gets half. */
- $parentNode->getAttributeNode('readability')->value += $contentScore;
-
- if ($grandParentNode) {
- $grandParentNode->getAttributeNode('readability')->value += $contentScore/2;
- }
- }
-
- /**
- * After we've calculated scores, loop through all of the possible candidate nodes we found
- * and find the one with the highest score.
- **/
- $topCandidate = null;
- for ($c=0, $cl=count($candidates); $c < $cl; $c++)
- {
- /**
- * Scale the final candidates score based on link density. Good content should have a
- * relatively small link density (5% or less) and be mostly unaffected by this operation.
- **/
- $readability = $candidates[$c]->getAttributeNode('readability');
- $readability->value = $readability->value * (1-$this->getLinkDensity($candidates[$c]));
-
- $this->dbg('Candidate: ' . $candidates[$c]->tagName . ' (' . $candidates[$c]->getAttribute('class') . ':' . $candidates[$c]->getAttribute('id') . ') with score ' . $readability->value);
-
- if (!$topCandidate || $readability->value > (int)$topCandidate->getAttribute('readability')) {
- $topCandidate = $candidates[$c];
- }
- }
-
- /**
- * If we still have no top candidate, just use the body as a last resort.
- * We also have to copy the body node so it is something we can modify.
- **/
- if ($topCandidate === null || strtoupper($topCandidate->tagName) == 'BODY')
- {
- $topCandidate = $this->dom->createElement('div');
- $topCandidate->innerHTML = ($page instanceof DOMDocument) ? $page->saveXML($page->documentElement) : $page->innerHTML;
- $page->innerHTML = '';
- $page->appendChild($topCandidate);
- $this->initializeNode($topCandidate);
- }
-
- /**
- * Now that we have the top candidate, look through its siblings for content that might also be related.
- * Things like preambles, content split by ads that we removed, etc.
- **/
- $articleContent = $this->dom->createElement('div');
- $articleContent->setAttribute('id', 'readability-content');
- $siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2);
- $siblingNodes = $topCandidate->parentNode->childNodes;
-
- for ($s=0, $sl=$siblingNodes->length; $s < $sl; $s++)
- {
- $siblingNode = $siblingNodes->item($s);
- $append = false;
-
- $this->dbg('Looking at sibling node: ' . $siblingNode->nodeName . (($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability')) ? (' with score ' . $siblingNode->getAttribute('readability')) : ''));
-
- //dbg('Sibling has score ' . ($siblingNode->readability ? siblingNode.readability.contentScore : 'Unknown'));
-
- if ($siblingNode === $topCandidate)
- // or if ($siblingNode->isSameNode($topCandidate))
- {
- $append = true;
- }
-
- $contentBonus = 0;
- /* Give a bonus if sibling nodes and top candidates have the example same classname */
- if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->getAttribute('class') == $topCandidate->getAttribute('class') && $topCandidate->getAttribute('class') != '') {
- $contentBonus += ((int)$topCandidate->getAttribute('readability')) * 0.2;
- }
-
- if ($siblingNode->nodeType === XML_ELEMENT_NODE && $siblingNode->hasAttribute('readability') && (((int)$siblingNode->getAttribute('readability')) + $contentBonus) >= $siblingScoreThreshold)
- {
- $append = true;
- }
-
- if (strtoupper($siblingNode->nodeName) == 'P') {
- $linkDensity = $this->getLinkDensity($siblingNode);
- $nodeContent = $this->getInnerText($siblingNode);
- $nodeLength = strlen($nodeContent);
-
- if ($nodeLength > 80 && $linkDensity < 0.25)
- {
- $append = true;
- }
- else if ($nodeLength < 80 && $linkDensity === 0 && preg_match('/\.( |$)/', $nodeContent))
- {
- $append = true;
- }
- }
-
- if ($append)
- {
- $this->dbg('Appending node: ' . $siblingNode->nodeName);
-
- $nodeToAppend = null;
- $sibNodeName = strtoupper($siblingNode->nodeName);
- if ($sibNodeName != 'DIV' && $sibNodeName != 'P') {
- /* We have a node that isn't a common block level element, like a form or td tag. Turn it into a div so it doesn't get filtered out later by accident. */
-
- $this->dbg('Altering siblingNode of ' . $sibNodeName . ' to div.');
- $nodeToAppend = $this->dom->createElement('div');
- try {
- $nodeToAppend->setAttribute('id', $siblingNode->getAttribute('id'));
- $nodeToAppend->innerHTML = $siblingNode->innerHTML;
- }
- catch(Exception $e)
- {
- $this->dbg('Could not alter siblingNode to div, reverting back to original.');
- $nodeToAppend = $siblingNode;
- $s--;
- $sl--;
- }
- } else {
- $nodeToAppend = $siblingNode;
- $s--;
- $sl--;
- }
-
- /* To ensure a node does not interfere with readability styles, remove its classnames */
- $nodeToAppend->removeAttribute('class');
-
- /* Append sibling and subtract from our list because it removes the node when you append to another node */
- $articleContent->appendChild($nodeToAppend);
- }
- }
-
- /**
- * So we have all of the content that we need. Now we clean it up for presentation.
- **/
- $this->prepArticle($articleContent);
-
- /**
- * Now that we've gone through the full algorithm, check to see if we got any meaningful content.
- * If we didn't, we may need to re-run grabArticle with different flags set. This gives us a higher
- * likelihood of finding the content, and the sieve approach gives us a higher likelihood of
- * finding the -right- content.
- **/
- if (strlen($this->getInnerText($articleContent, false)) < 250)
- {
- $this->body->innerHTML = $this->bodyCache;
-
- if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) {
- $this->removeFlag(self::FLAG_STRIP_UNLIKELYS);
- return $this->grabArticle($this->body);
- }
- else if ($this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) {
- $this->removeFlag(self::FLAG_WEIGHT_CLASSES);
- return $this->grabArticle($this->body);
- }
- else if ($this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
- $this->removeFlag(self::FLAG_CLEAN_CONDITIONALLY);
- return $this->grabArticle($this->body);
- }
- else {
- return false;
- }
- }
- return $articleContent;
- }
-
- /**
- * Remove script tags from document
- *
- * @param DOMElement
- * @return void
- */
- public function removeScripts($doc) {
- $scripts = $doc->getElementsByTagName('script');
- for($i = $scripts->length-1; $i >= 0; $i--)
- {
- $scripts->item($i)->parentNode->removeChild($scripts->item($i));
- }
- }
-
- /**
- * Get the inner text of a node.
- * This also strips out any excess whitespace to be found.
- *
- * @param DOMElement $
- * @param boolean $normalizeSpaces (default: true)
- * @return string
- **/
- public function getInnerText($e, $normalizeSpaces=true) {
- $textContent = '';
-
- if (!isset($e->textContent) || $e->textContent == '') {
- return '';
- }
-
- $textContent = trim($e->textContent);
-
- if ($normalizeSpaces) {
- return preg_replace($this->regexps['normalize'], ' ', $textContent);
- } else {
- return $textContent;
- }
- }
-
- /**
- * Get the number of times a string $s appears in the node $e.
- *
- * @param DOMElement $e
- * @param string - what to count. Default is ","
- * @return number (integer)
- **/
- public function getCharCount($e, $s=',') {
- return substr_count($this->getInnerText($e), $s);
- }
-
- /**
- * Remove the style attribute on every $e and under.
- *
- * @param DOMElement $e
- * @return void
- */
- public function cleanStyles($e) {
- $elems = $e->getElementsByTagName('*');
- foreach ($elems as $elem) {
- $elem->removeAttribute('style');
- }
- }
-
- /**
- * Get the density of links as a percentage of the content
- * This is the amount of text that is inside a link divided by the total text in the node.
- *
- * @param DOMElement $e
- * @return number (float)
- */
- public function getLinkDensity($e) {
- $links = $e->getElementsByTagName('a');
- $textLength = strlen($this->getInnerText($e));
- $linkLength = 0;
- for ($i=0, $il=$links->length; $i < $il; $i++)
- {
- $linkLength += strlen($this->getInnerText($links->item($i)));
- }
- if ($textLength > 0) {
- return $linkLength / $textLength;
- } else {
- return 0;
- }
- }
-
- /**
- * Get an elements class/id weight. Uses regular expressions to tell if this
- * element looks good or bad.
- *
- * @param DOMElement $e
- * @return number (Integer)
- */
- public function getClassWeight($e) {
- if(!$this->flagIsActive(self::FLAG_WEIGHT_CLASSES)) {
- return 0;
- }
-
- $weight = 0;
-
- /* Look for a special classname */
- if ($e->hasAttribute('class') && $e->getAttribute('class') != '')
- {
- if (preg_match($this->regexps['negative'], $e->getAttribute('class'))) {
- $weight -= 25;
- }
- if (preg_match($this->regexps['positive'], $e->getAttribute('class'))) {
- $weight += 25;
- }
- }
-
- /* Look for a special ID */
- if ($e->hasAttribute('id') && $e->getAttribute('id') != '')
- {
- if (preg_match($this->regexps['negative'], $e->getAttribute('id'))) {
- $weight -= 25;
- }
- if (preg_match($this->regexps['positive'], $e->getAttribute('id'))) {
- $weight += 25;
- }
- }
- return $weight;
- }
-
- /**
- * Remove extraneous break tags from a node.
- *
- * @param DOMElement $node
- * @return void
- */
- public function killBreaks($node) {
- $html = $node->innerHTML;
- $html = preg_replace($this->regexps['killBreaks'], '
', $html);
- $node->innerHTML = $html;
- }
-
- /**
- * Clean a node of all elements of type "tag".
- * (Unless it's a youtube/vimeo video. People love movies.)
- *
- * @param DOMElement $e
- * @param string $tag
- * @return void
- */
- public function clean($e, $tag) {
- $targetList = $e->getElementsByTagName($tag);
- $isEmbed = ($tag == 'object' || $tag == 'embed');
-
- for ($y=$targetList->length-1; $y >= 0; $y--) {
- /* Allow youtube and vimeo videos through as people usually want to see those. */
- if ($isEmbed) {
- $attributeValues = '';
- for ($i=0, $il=$targetList->item($y)->attributes->length; $i < $il; $i++) {
- $attributeValues .= $targetList->item($y)->attributes->item($i)->value . '|'; // DOMAttr? (TODO: test)
- }
-
- /* First, check the elements attributes to see if any of them contain youtube or vimeo */
- if (preg_match($this->regexps['video'], $attributeValues)) {
- continue;
- }
-
- /* Then check the elements inside this element for the same. */
- if (preg_match($this->regexps['video'], $targetList->item($y)->innerHTML)) {
- continue;
- }
- }
- $targetList->item($y)->parentNode->removeChild($targetList->item($y));
- }
- }
-
- /**
- * Clean an element of all tags of type "tag" if they look fishy.
- * "Fishy" is an algorithm based on content length, classnames,
- * link density, number of images & embeds, etc.
- *
- * @param DOMElement $e
- * @param string $tag
- * @return void
- */
- public function cleanConditionally($e, $tag) {
- if (!$this->flagIsActive(self::FLAG_CLEAN_CONDITIONALLY)) {
- return;
- }
-
- $tagsList = $e->getElementsByTagName($tag);
- $curTagsLength = $tagsList->length;
-
- /**
- * Gather counts for other typical elements embedded within.
- * Traverse backwards so we can remove nodes at the same time without effecting the traversal.
- *
- * TODO: Consider taking into account original contentScore here.
- */
- for ($i=$curTagsLength-1; $i >= 0; $i--) {
- $weight = $this->getClassWeight($tagsList->item($i));
- $contentScore = ($tagsList->item($i)->hasAttribute('readability')) ? (int)$tagsList->item($i)->getAttribute('readability') : 0;
-
- $this->dbg('Cleaning Conditionally ' . $tagsList->item($i)->tagName . ' (' . $tagsList->item($i)->getAttribute('class') . ':' . $tagsList->item($i)->getAttribute('id') . ')' . (($tagsList->item($i)->hasAttribute('readability')) ? (' with score ' . $tagsList->item($i)->getAttribute('readability')) : ''));
-
- if ($weight + $contentScore < 0) {
- $tagsList->item($i)->parentNode->removeChild($tagsList->item($i));
- }
- else if ( $this->getCharCount($tagsList->item($i), ',') < 10) {
- /**
- * If there are not very many commas, and the number of
- * non-paragraph elements is more than paragraphs or other ominous signs, remove the element.
- **/
- $p = $tagsList->item($i)->getElementsByTagName('p')->length;
- $img = $tagsList->item($i)->getElementsByTagName('img')->length;
- $li = $tagsList->item($i)->getElementsByTagName('li')->length-100;
- $input = $tagsList->item($i)->getElementsByTagName('input')->length;
-
- $embedCount = 0;
- $embeds = $tagsList->item($i)->getElementsByTagName('embed');
- for ($ei=0, $il=$embeds->length; $ei < $il; $ei++) {
- if (preg_match($this->regexps['video'], $embeds->item($ei)->getAttribute('src'))) {
- $embedCount++;
- }
- }
-
- $linkDensity = $this->getLinkDensity($tagsList->item($i));
- $contentLength = strlen($this->getInnerText($tagsList->item($i)));
- $toRemove = false;
-
- if ( $img > $p ) {
- $toRemove = true;
- } else if ($li > $p && $tag != 'ul' && $tag != 'ol') {
- $toRemove = true;
- } else if ( $input > floor($p/3) ) {
- $toRemove = true;
- } else if ($contentLength < 25 && ($img === 0 || $img > 2) ) {
- $toRemove = true;
- } else if($weight < 25 && $linkDensity > 0.2) {
- $toRemove = true;
- } else if($weight >= 25 && $linkDensity > 0.5) {
- $toRemove = true;
- } else if(($embedCount == 1 && $contentLength < 75) || $embedCount > 1) {
- $toRemove = true;
- }
-
- if ($toRemove) {
- $tagsList->item($i)->parentNode->removeChild($tagsList->item($i));
- }
- }
- }
- }
-
- /**
- * Clean out spurious headers from an Element. Checks things like classnames and link density.
- *
- * @param DOMElement $e
- * @return void
- */
- public function cleanHeaders($e) {
- for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) {
- $headers = $e->getElementsByTagName('h' . $headerIndex);
- for ($i=$headers->length-1; $i >=0; $i--) {
- if ($this->getClassWeight($headers->item($i)) < 0 || $this->getLinkDensity($headers->item($i)) > 0.33) {
- $headers->item($i)->parentNode->removeChild($headers->item($i));
- }
- }
- }
- }
-
- public function flagIsActive($flag) {
- return ($this->flags & $flag) > 0;
- }
-
- public function addFlag($flag) {
- $this->flags = $this->flags | $flag;
- }
-
- public function removeFlag($flag) {
- $this->flags = $this->flags & ~$flag;
- }
-}
-?>
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/api.php b/inc/3rdparty/libraries/send2kindle/api.php
deleted file mode 100644
index 564c171c..00000000
--- a/inc/3rdparty/libraries/send2kindle/api.php
+++ /dev/null
@@ -1,234 +0,0 @@
- service = $service;
- }
- /* if ( isset($_SESSION[ $this -> session_var_auth_name ] ) ){
- $this -> auth = $_SESSION[ $this -> session_var_auth_name ];
- echo "Loading";
- } else { */
- $this -> clientLogin( $email, $password );
- $this -> get_token();
- /* } */
- }
-
-
- private function request( $url, $type = 'get', $headers = false, $fields = false, $cookie = false){
-
- $curl = curl_init();
-
- if ( $fields ){
- if ($type == 'get'){
- $url .= '?'.http_build_query( $fields );
- } else {
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields) );
- }
- }
- if ( $headers ){
- curl_setopt($curl, CURLOPT_HEADER, true);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- }
- if ( $cookie ){
- curl_setopt($curl, CURLOPT_COOKIE, $cookie);
- }
-
- curl_setopt($curl, CURLOPT_URL, $url);
- if (strpos($url, 'https://') !== false){
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
-
- $response = array();
- $response['text'] = curl_exec($curl);
- $response['info'] = curl_getinfo( $curl);
- $response['code'] = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
- $response['body'] = substr( $response['text'], $response['info']['header_size'] );
-
- curl_close( $curl );
- return $response;
- }
-
- private function request2google( $url, $type = 'get', $headers = false, $fields = false ){
- if ( $this -> auth ){
- $headers[] = 'Content-type: application/x-www-form-urlencoded';
- $headers[] = 'Authorization: GoogleLogin auth='.$this -> auth;
-
- if ( strpos( $url, 'http://') === false && strpos( $url, 'https://' ) === false ){
- $url = $this -> reader_api_url.$url;
- }
-
- $response = $this -> request( $url, $type, $headers, $fields);
- if ( $response['code'] == 200 ){
- if ( isset( $fields['output'] ) ){
- switch ($fields['output']){
- case 'xml':
- return (new SimpleXMLElement( $response['body'] ) );
- break;
- case 'json':
- default:
- return json_decode( $response['body'] );
- break;
- }
- } else {
- return $response['body'];
- }
- } else {
- Throw new AutentificationException('Auth error: server response '.$response['code'] );
- }
-
- } else {
- Throw new AutentificationException('Auth error: not finded Auth token');
- }
- }
-
- public function get_tag_list( $output = 'json' ){
- return $this -> request2google('tag/list', "get", false, array(
- 'output' => $output,
- 'ck' => time(),
- 'client' => $this -> client,
- ));
- }
- public function get_subscription_list( $output = 'json' ){
- return $this -> request2google('subscription/list', "get", false, array(
- 'output' => $output,
- 'ck' => time(),
- 'client' => $this -> client,
- ));
- }
- public function get_preference_list( $output = 'json' ){
- return $this -> request2google('preference/list', "get", false, array(
- 'output' => $output,
- 'ck' => time(),
- 'client' => $this -> client,
- ));
- }
- public function get_unread_count( $output = 'json' ){
- return $this -> request2google('unread-count', "get", false, array(
- 'all' => true,
- 'output' => $output,
- 'ck' => time(),
- 'client' => $this -> client,
- ));
- }
- public function get_user_info( $output = 'json' ){
- return $this -> request2google('user-info', "get", false, array(
- 'output' => $output,
- 'ck' => time(),
- 'client' => $this -> client,
- ));
- }
- private function get_token(){
- $this -> token = $this -> request2google('token');
- }
-
- //get contents functions
- /*
- r - order
- r = n - new items
- r = o - old items
- r = a - auto sort
-
- */
- private function get_content( $content_url = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){
- $fields = array(
- 'ck' => time(),
- 'client' => $this -> client,
- 'n' => $number,
- 'r' => $order,
- 'output' => 'json',
- );
- if ( !empty($exclude_target) ){$fields['xt'] = $exclude_target;}
- if ( !empty($start_time) ){$fields['ot'] = $start_time;}
- if ( !empty($continuation) ){$fields['c'] = $continuation;}
-
- return $this -> request2google('stream/contents/'.Utils::urlencode( $content_url ), 'get', false, $fields);
- }
-
- public function get_content_feed( $feed_url = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){
- return $this -> get_content( $feed_url, $number, $order, $exclude_target, $start_time, $continuation );
- }
- public function get_content_by_label( $label = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){
- return $this -> get_content( (strpos($label, '/') === false?'user/-/label/':'').$label, $number, $order, $exclude_target, $start_time, $continuation );
- }
- public function get_content_by_state( $state = '', $number = 20, $order = 'n', $exclude_target = '', $start_time = '', $continuation = ''){
- return $this -> get_content( (strpos($state, '/') === false?'user/-/state/com.google/':'').$state, $number, $order, $exclude_target, $start_time, $continuation );
- }
-
- public function get_unread( $number = 20, $order = 'n' ){
- return $this ->get_content_by_state('reading-list', $number, $order, 'user/-/state/com.google/read');
- }
-
- public function get_starred($number = 20, $order = 'n'){
- return $this ->get_content_by_state('starred', $number, $order);
- }
-
- /*
- Edit functions
- */
- private function edit_do( $api_function , $post_fields ){
- $post_fields['T'] = $this -> token;
- if ( $this -> request2google( $api_function, "post", false, $post_fields ) == "OK"){
- return true;
- } else {
- return false;
- }
- }
-
- /* public function edit_subscription(
- s return $this -> edit_do( 'subscription/edit',
- } */
- public function set_state( $itemId, $state = 'read'){
- $post_fields = array(
- "i" => $itemId,
- "a" => 'user/-/state/com.google/'.$state,
- );
- //print_r( $post_fields );
- return $this ->edit_do('edit-tag?client='.$this -> client, $post_fields);
- }
-
- private function clientLogin( $email, $password ){
-
- $response = $this -> request( $this -> clientlogin_url, 'post', false, array(
- "accountType" => $this -> account_type,
- "Email" => $email,
- "Passwd" => $password,
- "service" => $this -> service,
- "source" => $this -> source,
- ));
-
- if ( $response['code'] == 200) {
- preg_match("/Auth=([a-z0-9_\-]+)/i", $response['body'], $matches_auth);
- if ($matches_auth[1]){
- $this -> auth = $matches_auth[1];
- $_SESSION[ $this -> session_var_auth_name ] = $this -> auth;
- return true;
- } else {
- Throw new AutentificationException('Auth error: not finded Auth token in response');
- }
- } else {
- Throw new AutentificationException('Auth error: server response '.$response['code'] );
- }
- }
-}
-
-//Exceptions
-class AutentificationException extends Exception {}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/images.php b/inc/3rdparty/libraries/send2kindle/images.php
deleted file mode 100644
index 63f0562a..00000000
--- a/inc/3rdparty/libraries/send2kindle/images.php
+++ /dev/null
@@ -1,136 +0,0 @@
-_storage = $storage;
- $this->_content = $article_content;
- $this->_images_from_content = $this->_get_images_from_content($article_content);
- }
-
- /**
- * get images from url
- * @param string $content
- * @return array images hashtable
- */
- private function _get_images_from_content($content)
- {
- $result = array();
- preg_match_all('/src=\"([a-zA-Z0-9\.\/\-\_\?\+\%\~\&\;\=\:]+)\"/i', $content, $result);
-
- return $result[1];
- }
-
- /**
- * Start conversion
- * @return string converted content
- */
- public function convert()
- {
- foreach ( $this->_images_from_content as $n => $image_url )
- {
- $image = $this->_get_image($image_url);
- $this->_content = str_replace($image_url, '" recindex="'.(int)basename($image), $this->_content);
- }
-
- return $this->_content;
- }
-
- /**
- * Resize image
- * @param string $file path
- * @param int $new_width max width
- */
- private function _resize($file, $new_width = 500)
- {
- list($width, $height) = getimagesize($file);
-
- $new_height = 0;
-
- //setup the new size of the image
- if( $width > $new_width )
- {
- $ratio = $height/$width;
- $new_height = $new_width * $ratio;
- }
- else
- {
- $new_width = $width;
- $new_height = $height;
- }
-
- // resample the image
- $new_image = imagecreatetruecolor($new_width, $new_height);
-
- $type = exif_imagetype ( $file );
-
- switch ( $type )
- {
- case IMAGETYPE_JPEG:
- $old_image = imagecreatefromjpeg($file);
- imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
- imagejpeg($new_image, $file, self::JPEG_QUALITY);
- break;
- case IMAGETYPE_PNG:
- $old_image = imagecreatefrompng($file);
- imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
- imagepng($new_image, $file);
- break;
- case IMAGETYPE_GIF:
- $old_image = imagecreatefromgif($file);
- imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
- imagegif($new_image, $file);
- break;
- }
- }
-
- /**
- * Resize image
- * @return string image path
- */
- private function _get_image($url)
- {
- $image_data = @file_get_contents($url);
-
- if ( $image_data !== false )
- {
- $image_name = $this->_storage->save_image($image_data);
- $this->_resize($image_name);
-
- return $image_name;
- }
- }
-
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/io.php b/inc/3rdparty/libraries/send2kindle/io.php
deleted file mode 100644
index 284c08cc..00000000
--- a/inc/3rdparty/libraries/send2kindle/io.php
+++ /dev/null
@@ -1,250 +0,0 @@
-
- */
-class IO {
-
- /**
- * Max line height
- */
- const COMMAND_LENGTH = 50;
-
- /**
- * args for run screen
- * @var array
- */
- protected static $_args = array
- (
- 'help' => array('value' => FALSE, 'description' => 'show help for news2kindle'),
- 'grab' => array('value' => FALSE, 'description' => 'grab articles from google reader'),
- 'mobi' => array('value' => FALSE, 'description' => 'prepare mobi format'),
- 'send' => array('value' => FALSE, 'description' => 'send articles to kindle'),
- 'login' => array('value' => NULL, 'description' => 'your login to google account *requred'),
- 'password' => array('value' => NULL, 'description' => 'your password to google account *required'),
- 'kindle' => array('value' => NULL, 'description' => 'your kindle email *required'),
- 'items' => array('value' => 100, 'description' => 'max items to grab in run'),
- 'render' => array('value' => 'std', 'description' => 'name of html template for newspapper'),
- //'timeout' => array('value' => FALSE, 'description' => 'timeout is most important than items count'),
- );
-
- /**
- * Write on screen text line
- * @param string $message
- * @param bool $broken_line
- */
- public static function msg($message, $broken_line = TRUE)
- {
- echo ( $broken_line ? "\n" : "" ) . $message;
- }
-
- /**
- * Write command for status
- * @param string $message
- */
- public static function command($message)
- {
- $output_whitespaces = '';
-
- for ($i = strlen($message); $i <= self::COMMAND_LENGTH; ++$i )
- {
- $output_whitespaces .= '-';
- }
-
- self::msg( $message . ' ' . $output_whitespaces.' ' );
- }
-
- /**
- * Status - OK
- */
- public static function ok()
- {
- $colored_string = "\033[1;37m" . "\033[42m" . ' OK ' . "\033[0m";
- self::msg( $colored_string, FALSE );
- }
-
- /**
- * Status - Error
- */
- public static function error($message = NULL)
- {
- $colored_string = "\033[1;37m" . "\033[41m" . ' ERROR ' . "\033[0m";
- self::msg( $colored_string, FALSE );
-
- if ( $message !== NULL )
- {
- self::msg( ' - ' . $message );
- }
- }
-
- /**
- * Get run args
- * @param string $name key config
- * @return mixed config value
- */
- public static function arg($name)
- {
- return self::$_args[$name]['value'];
- }
-
- /**
- * Get config from ini
- * @param string $path
- * @return void
- */
- protected static function _get_config($path)
- {
- $config = parse_ini_file( $path . 'config.ini' );
-
- foreach($config as $key => $value)
- {
- self::$_args[$key]['value'] = $value;
- }
- }
-
- /**
- * Prepare args for script
- * (from http://php.net/manual/en/features.commandline.php)
- * @param array $argv array
- * @param string $path
- * @return bool success or error
- */
- public static function prepare_args($argv, $path)
- {
- self::command('Parse args');
-
- self::_get_config($path);
-
- array_shift($argv);
- $out = array();
-
- foreach ( $argv as $arg )
- {
- if ( substr($arg,0,2) == '--' )
- {
- $eqPos = strpos($arg,'=');
-
- if ( $eqPos === false )
- {
- $key = substr($arg,2);
- $out[$key] = isset($out[$key]) ? $out[$key] : true;
- }
- else
- {
- $key = substr($arg,2,$eqPos-2);
- $out[$key] = substr($arg,$eqPos+1);
- }
-
- }
- else if ( substr($arg,0,1) == '-' )
- {
- if ( substr($arg,2,1) == '=' )
- {
- $key = substr($arg,1,1);
- $out[$key] = substr($arg,3);
- }
- else
- {
- $chars = str_split(substr($arg,1));
-
- foreach ( $chars as $char )
- {
- $key = $char;
- $out[$key] = isset($out[$key]) ? $out[$key] : true;
- }
- }
- }
- else
- {
- $out[] = $arg;
- }
- }
-
- try
- {
- $args = self::_validate_args($out);
-
- foreach ( $args as $key => $value )
- {
- self::$_args[$key]['value'] = $value;
- }
- }
- catch(Exception $e)
- {
- self::error($e->getMessage());
- return false;
- }
-
- self::ok();
-
- return true;
- }
-
- /**
- * Validate args for script
- * (from http://php.net/manual/en/features.commandline.php)
- * @param array $argv array
- * @return array args
- */
- private static function _validate_args($args)
- {
- if( array_key_exists('help', $args) OR array_key_exists('h', $args) )
- {
- $args['grab'] = false;
- $args['mobi'] = false;
- $args['send'] = false;
- $args['login'] = false;
- $args['password'] = false;
- $args['kindle'] = false;
- }
-
- foreach ( $args as $key => $arg )
- {
- if ( strlen($key) === 1 )
- {
- foreach ( self::$_args as $keyA => $argA )
- {
- if($keyA[0] === $key )
- {
- unset( $args[$key] );
- $args[$keyA] = $arg;
- $key = $keyA;
- }
- }
- }
-
- if ( ! array_key_exists($key, self::$_args) )
- {
- throw new Exception('Param "'.$key.'" is invalid!');
- }
- }
-
- foreach ( self::$_args as $key => $arg )
- {
- if( self::$_args[$key]['value'] === NULL AND !array_key_exists($key, $args) )
- {
- throw new Exception('Param "'.$key.'" must be declared!');
- }
- }
-
- return $args;
- }
-
- /**
- * Prepare help
- * @return array
- */
- public static function get_help()
- {
- $output = array();
-
- foreach ( self::$_args as $arg => $item )
- {
- $output[$arg] = $item['description'];
- }
-
- return $output;
- }
-
-}
\ No newline at end of file
diff --git a/inc/3rdparty/libraries/send2kindle/readability.php b/inc/3rdparty/libraries/send2kindle/readability.php
deleted file mode 100644
index 18c2dbde..00000000
--- a/inc/3rdparty/libraries/send2kindle/readability.php
+++ /dev/null
@@ -1,249 +0,0 @@
-
- * @date 2011-02-17
- * @link http://www.gracecode.com/
- */
-
-define("READABILITY_VERSION", 0.12);
-
-class Readability2 {
- // 保存判定结果的标记位名称
- const ATTR_CONTENT_SCORE = "contentScore";
-
- // DOM 解析类目前只支持 UTF-8 编码
- const DOM_DEFAULT_CHARSET = "utf-8";
-
- // 当判定失败时显示的内容
- const MESSAGE_CAN_NOT_GET = "Sorry, readability was unable to parse this page for content. \n
- If you feel like it should have been able to,
- please let me know by mail: lucky[at]gracecode.com";
-
- // DOM 解析类(PHP5 已内置)
- protected $DOM = null;
-
- // 需要解析的源代码
- protected $source = "";
-
- // 章节的父元素列表
- private $parentNodes = array();
-
- // 需要删除的标签
- private $junkTags = Array("style", "form", "iframe", "script", "button", "input", "textarea");
-
- // 需要删除的属性
- private $junkAttrs = Array("style", "class", "onclick", "onmouseover", "align", "border", "margin");
-
-
- /**
- * 构造函数
- * @param $input_char 字符串的编码。默认 utf-8,可以省略
- */
- function __construct($source, $input_char = "utf-8") {
- $this->source = $source;
-
- // DOM 解析类只能处理 UTF-8 格式的字符
- $source = mb_convert_encoding($source, 'HTML-ENTITIES', $input_char);
-
- // 预处理 HTML 标签,剔除冗余的标签等
- $source = $this->preparSource($source);
-
- // 生成 DOM 解析类
- $this->DOM = new DOMDocument('1.0', $input_char);
- try {
- //libxml_use_internal_errors(true);
- // 会有些错误信息,不过不要紧 :^)
- if (!@$this->DOM->loadHTML(''.$source)) {
- throw new Exception("Parse HTML Error!");
- }
-
- foreach ($this->DOM->childNodes as $item) {
- if ($item->nodeType == XML_PI_NODE) {
- $this->DOM->removeChild($item); // remove hack
- }
- }
-
- // insert proper
- $this->DOM->encoding = Readability2::DOM_DEFAULT_CHARSET;
- } catch (Exception $e) {
- // ...
- }
- }
-
-
- /**
- * 预处理 HTML 标签,使其能够准确被 DOM 解析类处理
- *
- * @return String
- */
- private function preparSource($string) {
- // 剔除多余的 HTML 编码标记,避免解析出错
- preg_match("/charset=([\w|\-]+);?/", $string, $match);
- if (isset($match[1])) {
- $string = preg_replace("/charset=([\w|\-]+);?/", "", $string, 1);
- }
-
- // Replace all doubled-up
tags with
tags, and remove fonts.
- $string = preg_replace("/
[ \r\n\s]*
/i", "
", $string); - $string = preg_replace("/<\/?font[^>]*>/i", "", $string); - - return trim($string); - } - - - /** - * 删除 DOM 元素中所有的 $TagName 标签 - * - * @return DOMDocument - */ - private function removeJunkTag($RootNode, $TagName) { - $Tags = $RootNode->getElementsByTagName($TagName); - - $i = 0; - while($Tag = $Tags->item($i++)) { - $parentNode = $Tag->parentNode; - $parentNode->removeChild($Tag); - } - - return $RootNode; - } - - /** - * 删除元素中所有不需要的属性 - */ - private function removeJunkAttr($RootNode, $Attr) { - $Tags = $RootNode->getElementsByTagName("*"); - - $i = 0; - while($Tag = $Tags->item($i++)) { - $Tag->removeAttribute($Attr); - } - - return $RootNode; - } - - /** - * 根据评分获取页面主要内容的盒模型 - * 判定算法来自:http://code.google.com/p/arc90labs-readability/ - * - * @return DOMNode - */ - private function getTopBox() { - // 获得页面所有的章节 - $allParagraphs = $this->DOM->getElementsByTagName("p"); - - // Study all the paragraphs and find the chunk that has the best score. - // A score is determined by things like: Number of
's, commas, special classes, etc. - $i = 0; - while($paragraph = $allParagraphs->item($i++)) { - $parentNode = $paragraph->parentNode; - $contentScore = intval($parentNode->getAttribute(Readability2::ATTR_CONTENT_SCORE)); - $className = $parentNode->getAttribute("class"); - $id = $parentNode->getAttribute("id"); - - // Look for a special classname - if (preg_match("/(comment|meta|footer|footnote)/i", $className)) { - $contentScore -= 50; - } else if(preg_match( - "/((^|\\s)(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)(\\s|$))/i", - $className)) { - $contentScore += 25; - } - - // Look for a special ID - if (preg_match("/(comment|meta|footer|footnote)/i", $id)) { - $contentScore -= 50; - } else if (preg_match( - "/^(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)$/i", - $id)) { - $contentScore += 25; - } - - // Add a point for the paragraph found - // Add points for any commas within this paragraph - if (strlen($paragraph->nodeValue) > 10) { - $contentScore += strlen($paragraph->nodeValue); - } - - // 保存父元素的判定得分 - $parentNode->setAttribute(Readability2::ATTR_CONTENT_SCORE, $contentScore); - - // 保存章节的父元素,以便下次快速获取 - array_push($this->parentNodes, $parentNode); - } - - $topBox = $this->DOM->createElement('div', Readability2::MESSAGE_CAN_NOT_GET); - // Assignment from index for performance. - // See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5 - for ($i = 0, $len = sizeof($this->parentNodes); $i < $len; $i++) { - $parentNode = $this->parentNodes[$i]; - $contentScore = intval($parentNode->getAttribute(Readability2::ATTR_CONTENT_SCORE)); - $orgContentScore = intval($topBox->getAttribute(Readability2::ATTR_CONTENT_SCORE)); - - if ($contentScore && $contentScore > $orgContentScore) { - $topBox = $parentNode; - } - } - - // 此时,$topBox 应为已经判定后的页面内容主元素 - return $topBox; - } - - - /** - * 获取 HTML 页面标题 - * - * @return String - */ - public function getTitle() { - $title = $this->DOM->getElementsByTagName("title"); - return $title->item(0); - } - - - /** - * 获取页面的主要内容(Readability 以后的内容) - * - * @return Array - */ - public function getContent() { - if (!$this->DOM) return false; - - // 获取页面标题 - $ContentTitle = $this->getTitle(); - - // 获取页面主内容 - $ContentBox = $this->getTopBox(); - - // 复制内容到新的 DOMDocument - $Target = new DOMDocument; - $Target->appendChild($Target->importNode($ContentBox, true)); - - // 删除不需要的标签 - foreach ($this->junkTags as $tag) { - $Target = $this->removeJunkTag($Target, $tag); - } - - // 删除不需要的属性 - foreach ($this->junkAttrs as $attr) { - $Target = $this->removeJunkAttr($Target, $attr); - } - - // 多个数据,以数组的形式返回 - return Array( - 'title' => $ContentTitle ? $ContentTitle->nodeValue : "", - 'content' => $Target->saveHTML() - ); - } - - function __destruct() { } -} diff --git a/inc/3rdparty/libraries/send2kindle/send.php b/inc/3rdparty/libraries/send2kindle/send.php deleted file mode 100644 index a4861d30..00000000 --- a/inc/3rdparty/libraries/send2kindle/send.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ -class Send { - - /** - * Your kindle email - * @var string - */ - private $_kindle_email; - - /** - * Your email (must be added on amazon) - * @var string - */ - private $_email; - - /** - * Prepare mail - * @param string $kindle_email your kindle email - * @param string $email email for send to kindle - */ - public function __construct($kindle_email, $email) - { - $this->_kindle_email = $kindle_email; - $this->_email = $email; - } - - /** - * Send file - * @param string $file path to file - * @return bool - */ - public function send($file) - { - //prepare file - $file_size = filesize($file); - $filename = basename($file); - $handle = fopen($file, "r"); - $content = fread($handle, $file_size); - fclose($handle); - $content = chunk_split(base64_encode($content)); - - $uid = md5(uniqid(time())); - - //generate header for mail - $header = "From: News2Kindle <".$this->_email.">\r\n"; - $header .= "MIME-Version: 1.0\r\n"; - $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; - $header .= "This is a multi-part message in MIME format.\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; - $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; - $header .= "send via News2Kindle script\r\n\r\n"; - $header .= "--".$uid."\r\n"; - $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n"; - $header .= "Content-Transfer-Encoding: base64\r\n"; - $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; - $header .= $content."\r\n\r\n"; - $header .= "--".$uid."--"; - - //send mail - return mail( $this->_kindle_email, '[newsToKindle] ' . $filename, "", $header ); - } -} - -?> \ No newline at end of file diff --git a/inc/3rdparty/libraries/send2kindle/storage.php b/inc/3rdparty/libraries/send2kindle/storage.php deleted file mode 100644 index 5c38ce80..00000000 --- a/inc/3rdparty/libraries/send2kindle/storage.php +++ /dev/null @@ -1,230 +0,0 @@ - - */ -class Storage { - - /** - * Newspapper name - * @var string - */ - private $_name; - - /** - * Default dir - * @var string - */ - private $_default_dir = 'data/'; - - /** - * Info about newspapper - * @var array - */ - private $_info; - - /** - * Prepare storage - * @param string $newspapper - * @param string $default_dir - */ - public function __construct($newspapper, $default_dir = NULL) - { - $this->_name = $newspapper; - - if ( $default_dir !== NULL ) - { - $this->_default_dir = $default_dir; - } - - $this->_info = $this->_get_info(); - } - - /** - * save info before exit from script - */ - public function __destruct() - { - $this->_save_info($this->_info); - } - - /** - * Get path - * @param bool $newspapper path to newspapper - * @return string path to repository - */ - public function get_path($newspapper = true) - { - $path = $this->_default_dir; - - if ( $newspapper ) - { - $path .= $this->_name . '/'; - } - - return $path; - } - - /** - * Get info about newspapper - * @return array newspapper info - */ - private function _get_info() - { - $content = unserialize( $this->_get_file('info.dat') ); - - if( $content === FALSE ) - { - $content = (object) array - ( - 'images_count' => 0, - 'articles_count' => 0, - 'images' => array(), - ); - - $this->_save_info($content); - } - - return $content; - } - - /** - * Get info key - * @param $key - * @return mixed - */ - public function info($key) - { - return $this->_info->$key; - } - - /** - * Save info - * @param array $info info from class - */ - private function _save_info($info) - { - $this->_save_file( 'info.dat', serialize($info) ); - } - - /** - * Save image in storage - * @param resource $image - * @param string $name image name, if null create auto name - * @return string image name - */ - public function save_image($image, $name = NULL) - { - if ( $name === NULL ) - { - $image_name = (string) $this->_info->images_count; - - for ($i=strlen($image_name); $i<6; $i++) - { - $image_name = '0'.$image_name; - } - - $this->_info->images_count++; - $this->_info->images[$this->_info->images_count] = $image_name; - - $name = $image_name; - } - - $this->_save_file($name, $image); - - return $this->_default_dir . $this->_name . '/' . $name; - } - - /** - * Get image - * @param string $name image name - * @return resource - */ - public function get_image($name) - { - return $this->_get_file($name); - } - - /** - * Put article contents - * @param string $id unique id for article - * @param string $title - * @param string $content article content - * @param string $url url for article - * @param object $website - */ - public function add_content($id, $title, $content, $url, $website) - { - $articles = unserialize( $this->_get_file('articles.dat') ); - - $articles[$id] = (object) array - ( - 'id' => $id, - 'title' => $title, - 'content' => $content, - 'url' => $url, - 'website' => $website, - ); - - $this->_save_file( 'articles.dat', serialize($articles) ); - } - - /** - * Get articles contents - * @param string $file_name - * @param string $file_content - */ - public function get_contents() - { - return unserialize( $this->_get_file( 'articles.dat' ) ); - } - - /** - * Get file content - * @param string $file_name - * @param string $file_content - */ - private function _save_file($file_name, $file_content) - { - if( ! file_exists( $this->_default_dir . $this->_name ) ) - { - mkdir( $this->_default_dir . $this->_name, 0777, TRUE ); - } - - file_put_contents($this->_default_dir . $this->_name . '/' . $file_name, $file_content); - } - - /** - * Get file content - * @param string $file_name - * @param string $default_file_content (if file not exists) - * @return string file content - */ - private function _get_file($file_name, $default_file_content = NULL) - { - $content = @file_get_contents($this->_default_dir . $this->_name . '/' . $file_name); - - if ($content === FALSE) - { - return $default_file_content; - } - - return $content; - } - - /** - * Clean newspapper after convert to mobi - */ - public function clean() - { - $files_to_remove = glob($this->_default_dir . $this->_name . '/*'); - - foreach ( $files_to_remove as $file ) - { - unlink( $file ); - } - - rmdir( $this->_default_dir . $this->_name ); - } - -} \ No newline at end of file diff --git a/inc/3rdparty/libraries/send2kindle/utils.php b/inc/3rdparty/libraries/send2kindle/utils.php deleted file mode 100644 index 87cc3de0..00000000 --- a/inc/3rdparty/libraries/send2kindle/utils.php +++ /dev/null @@ -1,37 +0,0 @@ - - */ -class Utils -{ - /** - * URL encode - * @param string $url - * @return string $ar_url - */ - public static function urlencode( $url ) - { - $ar_url = explode( '/', $url ); - - foreach ( $ar_url as $key => $val ) - { - $ar_url[ $key ] = urlencode( $val ); - } - - return implode('/', $ar_url ); - } - - /** - * Prepare ID for google rss article - * @param string $id - * @return string - */ - public static function prepare_id($id) - { - $char_in = array('/', '.', ',', ':'); - $id = str_replace($char_in, '-', $id); - - return $id; - } -} \ No newline at end of file -- cgit v1.2.3