From 4188f38ad56d7ba2ea46e94403f305243514f80c Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 15:49:36 +0200 Subject: add pdf and mobi libraries --- .../MOBIClass/readability/JSLikeHTMLElement.php | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php (limited to 'inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php') diff --git a/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php b/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php new file mode 100644 index 00000000..1a8ec88c --- /dev/null +++ b/inc/3rdparty/libraries/send2kindle/MOBIClass/readability/JSLikeHTMLElement.php @@ -0,0 +1,110 @@ +registerNodeClass('DOMElement', 'JSLikeHTMLElement'); +* $doc->loadHTML('

Para 1

Para 2

'); +* $elem = $doc->getElementsByTagName('div')->item(0); +* +* // print innerHTML +* echo $elem->innerHTML; // prints '

Para 1

Para 2

' +* echo "\n\n"; +* +* // set innerHTML +* $elem->innerHTML = 'FiveFilters.org'; +* echo $elem->innerHTML; // prints 'FiveFilters.org' +* echo "\n\n"; +* +* // print document (with our changes) +* echo $doc->saveXML(); +* @endcode +* +* @author Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net +* @see http://fivefilters.org (the project this was written for) +*/ +class JSLikeHTMLElement extends DOMElement +{ + /** + * Used for setting innerHTML like it's done in JavaScript: + * @code + * $div->innerHTML = '

Chapter 2

The story begins...

'; + * @endcode + */ + public function __set($name, $value) { + if ($name == 'innerHTML') { + // first, empty the element + for ($x=$this->childNodes->length-1; $x>=0; $x--) { + $this->removeChild($this->childNodes->item($x)); + } + // $value holds our new inner HTML + if ($value != '') { + $f = $this->ownerDocument->createDocumentFragment(); + // appendXML() expects well-formed markup (XHTML) + $result = @$f->appendXML($value); // @ to suppress PHP warnings + if ($result) { + if ($f->hasChildNodes()) $this->appendChild($f); + } else { + // $value is probably ill-formed + $f = new DOMDocument(); + $value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); + // Using will generate a warning, but so will bad HTML + // (and by this point, bad HTML is what we've got). + // We use it (and suppress the warning) because an HTML fragment will + // be wrapped around tags which we don't really want to keep. + // Note: despite the warning, if loadHTML succeeds it will return true. + $result = @$f->loadHTML(''.$value.''); + if ($result) { + $import = $f->getElementsByTagName('htmlfragment')->item(0); + foreach ($import->childNodes as $child) { + $importedNode = $this->ownerDocument->importNode($child, true); + $this->appendChild($importedNode); + } + } else { + // oh well, we tried, we really did. :( + // this element is now empty + } + } + } + } else { + $trace = debug_backtrace(); + trigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE); + } + } + + /** + * Used for getting innerHTML like it's done in JavaScript: + * @code + * $string = $div->innerHTML; + * @endcode + */ + public function __get($name) + { + if ($name == 'innerHTML') { + $inner = ''; + foreach ($this->childNodes as $child) { + $inner .= $this->ownerDocument->saveXML($child); + } + return $inner; + } + + $trace = debug_backtrace(); + trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE); + return null; + } + + public function __toString() + { + return '['.$this->tagName.']'; + } +} +?> \ No newline at end of file -- cgit v1.2.3