[TASK] Initial upload 90/32990/2 master
authorDaniel Minder <typo3@minder.de>
Sat, 27 Sep 2014 08:12:28 +0000 (10:12 +0200)
committerDaniel Minder <typo3@minder.de>
Sat, 27 Sep 2014 08:17:11 +0000 (10:17 +0200)
Initial upload

Resolves:
Releases: master
Change-Id: I4070d63cd534790c6860c186f407108483599ea8
Reviewed-on: http://review.typo3.org/32990
Reviewed-by: Daniel Minder <typo3@minder.de>
Tested-by: Daniel Minder <typo3@minder.de>
Classes/Task/StoreTask.php [new file with mode: 0644]
Classes/Task/StoreTaskAdditionalFieldProvider.php [new file with mode: 0644]
Classes/Utility/simple_html_dom.php [new file with mode: 0644]
ext_emconf.php [new file with mode: 0644]
ext_icon.gif [new file with mode: 0644]
ext_localconf.php [new file with mode: 0644]
ext_tables.php [new file with mode: 0644]

diff --git a/Classes/Task/StoreTask.php b/Classes/Task/StoreTask.php
new file mode 100644 (file)
index 0000000..2080f70
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+namespace DANNYM\StoreUrl\Task;
+class StoreTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
+    public function execute() {
+       // check UID
+               $recData = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tt_content', $this->storeuid, 'CType, pid');
+               if (!is_array($recData) || $recData['CType'] != 'html') {
+                       throw new \TYPO3\CMS\Scheduler\FailedExecutionException('Angegebene UID ist kein HTML Element');
+        }
+       
+       // get the URL
+       $data = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($this->url);
+       if ($data === FALSE || empty($data)) {
+               throw new \TYPO3\CMS\Scheduler\FailedExecutionException('Konnte URL nicht laden.');
+       }
+       if (strlen($data) > 100000) {  // security...
+               throw new \TYPO3\CMS\Scheduler\FailedExecutionException('Geladene URL ist zu groƟ.');
+       }
+       
+               // parse the HTML to dom
+               $html = new \DANNYM\StoreUrl\Utility\simple_html_dom(null);
+               $html->load($data);
+
+               // get the relevant part
+               $content = $html->find($this->contentElement,0);
+
+               // Replace attributes
+               $repAttributesSelector = explode("\n",$this->attr_queries);
+               $repAttr = explode("\n",$this->attributes);
+               $repWith = explode("\n",$this->attr_replace_with);
+               for ($i=0; $i<sizeof($repAttributesSelector); $i++) {
+                       if (isset($repAttr[$i]) && $repAttr[$i] != '') {
+                               foreach ($content->find($repAttributesSelector[$i]) as $tag) {
+                                       if (isset($repWith[$i]) && $repWith[$i] != '' ){
+                                               $tag->setAttribute($repAttr[$i],$repWith[$i]);
+                                       }
+                                       else {
+                                               $tag->removeAttribute($repAttr[$i]);
+                                       }
+                               }
+                       }
+               }
+               
+               // Replace content
+               $replaceContSelector = explode("\n",$this->tags_to_replace_content);
+               $replaceContWith = explode("\n",$this->content_replace_with);
+               for ($i=0; $i<sizeof($replaceContSelector); $i++){
+                       foreach ($content->find($replaceContSelector[$i]) as $tag) {
+                               if (isset($replaceContWith[$i]) && $replaceContWith[$i] != '') {
+                                       $tag->innertext = $replaceContWith[$i];
+                               }
+                               else {
+                                       $tag->innertext = '';
+                               }
+                       }
+               }
+               
+               // Replace tags
+               $replaceTagSelector = explode("\n",$this->tags_to_replace);
+               $replaceTagWith = explode("\n",$this->tags_replace_with);
+               for ($i=0; $i<sizeof($replaceTagSelector); $i++) {
+                       foreach ($content->find($replaceTagSelector[$i]) as $tag) {
+                               if (isset($replaceTagWith[$i])) {
+                                       $tag->outertext = $replaceTagWith[$i];
+                               }
+                       }
+               }
+               
+               // Get content
+               if (!$this->includeContainerTag){
+                       $content = $content->innertext;
+               }
+
+               // Update time
+               if ($this->timeMarker != '') {
+                       $content = $content . strftime($this->timeMarker);
+               }
+                               
+               // Wrapper
+               if ($this->wrapper != '') {
+                       $wrapParts = explode('|', $this->wrapper, 2);
+                       $content = $wrapParts[0] . $content . $wrapParts[1];
+               }
+               else {
+                       $content = '<div>' . $content . '</div>';
+               }
+                       
+       // store it
+       if ($GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid='.$this->storeuid, array('bodytext'=>$content)) === FALSE) {
+               throw new \TYPO3\CMS\Scheduler\FailedExecutionException('Konnte HTML nicht abspeichern: '.$GLOBALS['TYPO3_DB']->sql_error());
+       }
+       // and clear the cache of the page where the content element is located
+       $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+               $tce->start(array(), array());
+               $tce->clear_cacheCmd($recData['pid']);
+       
+        return true;
+    }
+
+    public function getAdditionalInformation() {
+        return 'Speichere "'.$this->url.'" in UID '.$this->storeuid.'.';
+    }
+}
+?>
diff --git a/Classes/Task/StoreTaskAdditionalFieldProvider.php b/Classes/Task/StoreTaskAdditionalFieldProvider.php
new file mode 100644 (file)
index 0000000..86a8794
--- /dev/null
@@ -0,0 +1,278 @@
+<?php
+namespace DANNYM\StoreUrl\Task;
+
+class StoreTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
+       public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
+               $additionalFields = array();
+
+        // URL to download
+               if (empty($taskInfo['url'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['url'] = $task->url;
+                       } else {
+                               $taskInfo['url'] = '';
+                       }
+               }
+               $fieldID = 'task_url';
+               $fieldCode = '<input type="text" name="tx_scheduler[url]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['url']) . '" size="50" />';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'URL'
+               );
+
+        // storeuid where to store the HTML
+               if (empty($taskInfo['storeuid'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['storeuid'] = $task->storeuid;
+                       } else {
+                               $taskInfo['storeuid'] = '';
+                       }
+               }
+               $fieldID = 'task_storeuid';
+               $fieldCode = '<input type="text" name="tx_scheduler[storeuid]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['storeuid']) . '" size="5" />';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'UID des Ziel-HTML-Elements'
+               );
+
+        // Content Element which should be extracted
+               if (empty($taskInfo['contentElement'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['contentElement'] = 'body';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['contentElement'] = $task->contentElement;
+                       } else {
+                               $taskInfo['contentElement'] = '';
+                       }
+               }
+               $fieldID = 'task_contentElement';
+               $fieldCode = '<input type="text" name="tx_scheduler[contentElement]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['contentElement']) . '" size="30" />';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Content Element (xpath queries allowed)'
+               );
+
+        // Include Container Tag
+               if (empty($taskInfo['includeContainerTag'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['includeContainerTag'] = $task->includeContainerTag;
+                       } else {
+                               $taskInfo['includeContainerTag'] = false;
+                       }
+               }
+               $fieldID = 'task_includeContainerTag';
+               $fieldCode = '<input type="checkbox" name="tx_scheduler[includeContainerTag]" id="' . $fieldID . '" value="1" ' . ($taskInfo['includeContainerTag'] ? 'checked="checked"' : '') . '/>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Include Container Tag'
+               );
+
+        // Line at the end to include the current time
+               if (empty($taskInfo['timeMarker'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['timeMarker'] = '<p>(Stand: %d.%m.%Y %H:%M)</p>';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['timeMarker'] = $task->timeMarker;
+                       } else {
+                               $taskInfo['timeMarker'] = '';
+                       }
+               }
+               $fieldID = 'task_timeMarker';
+               $fieldCode = '<input type="text" name="tx_scheduler[timeMarker]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['timeMarker']) . '" size="50" />';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Marker to include update time'
+               );
+
+        // Wrapper for complete content
+               if (empty($taskInfo['wrapper'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['wrapper'] = $task->wrapper;
+                       } else {
+                               $taskInfo['wrapper'] = '';
+                       }
+               }
+               $fieldID = 'task_wrapper';
+               $fieldCode = '<input type="text" name="tx_scheduler[wrapper]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['wrapper']) . '" size="50" />';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Wrapper for output (separate with |)'
+               );
+
+        // Replace attributes in Tags
+               if (empty($taskInfo['attr_queries'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['attr_queries'] = '//*';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['attr_queries'] = $task->attr_queries;
+                       } else {
+                               $taskInfo['attr_queries'] = '';
+                       }
+               }
+               $fieldID = 'task_attr_queries';
+               $fieldCode = '<textarea name="tx_scheduler[attr_queries]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['attr_queries']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Replace attributes in Tags (xpath queries allowed, one per line)'
+               );
+
+        // Names of attributes to replace
+               if (empty($taskInfo['attributes'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['attributes'] = 'style';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['attributes'] = $task->attributes;
+                       } else {
+                               $taskInfo['attributes'] = '';
+                       }
+               }
+               $fieldID = 'task_attributes';
+               $fieldCode = '<textarea name="tx_scheduler[attributes]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['attributes']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Names of attributes to replace (one per line)'
+               );
+
+        // Values to replace with
+               if (empty($taskInfo['attr_replace_with'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['attr_replace_with'] = $task->attr_replace_with;
+                       } else {
+                               $taskInfo['attr_replace_with'] = '';
+                       }
+               }
+               $fieldID = 'task_attr_replace_with';
+               $fieldCode = '<textarea name="tx_scheduler[attr_replace_with]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['attr_replace_with']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Values to replace with (one per line) (if empty, attribute will be completely removed)'
+               );
+
+
+        // Replace content of the following tags
+               if (empty($taskInfo['tags_to_replace_content'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['tags_to_replace_content'] = $task->tags_to_replace_content;
+                       } else {
+                               $taskInfo['tags_to_replace_content'] = '';
+                       }
+               }
+               $fieldID = 'task_tags_to_replace_content';
+               $fieldCode = '<textarea name="tx_scheduler[tags_to_replace_content]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['tags_to_replace_content']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Replace content of the following tags (xpath queries allowed, one per line)'
+               );
+
+        // Replace content with
+               if (empty($taskInfo['content_replace_with'])) {
+                       if ($parentObject->CMD == 'edit') {
+                               $taskInfo['content_replace_with'] = $task->content_replace_with;
+                       } else {
+                               $taskInfo['content_replace_with'] = '';
+                       }
+               }
+               $fieldID = 'task_content_replace_with';
+               $fieldCode = '<textarea name="tx_scheduler[content_replace_with]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['content_replace_with']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Replace content with (one per line)'
+               );
+
+        // Replace complete tags
+               if (empty($taskInfo['tags_to_replace'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['tags_to_replace'] = '//script';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['tags_to_replace'] = $task->tags_to_replace;
+                       } else {
+                               $taskInfo['tags_to_replace'] = '';
+                       }
+               }
+               $fieldID = 'task_tags_to_replace';
+               $fieldCode = '<textarea name="tx_scheduler[tags_to_replace]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['tags_to_replace']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Replace complete tags (xpath queries allowed, one per line)'
+               );
+
+        // Replace tag with
+               if (empty($taskInfo['tags_replace_with'])) {
+                       if ($parentObject->CMD == 'add') {
+                               $taskInfo['tags_replace_with'] = '<!--script removed-->';
+                       } elseif ($parentObject->CMD == 'edit') {
+                               $taskInfo['tags_replace_with'] = $task->tags_replace_with;
+                       } else {
+                               $taskInfo['tags_replace_with'] = '';
+                       }
+               }
+               $fieldID = 'task_tags_replace_with';
+               $fieldCode = '<textarea name="tx_scheduler[tags_replace_with]" id="' . $fieldID . '" cols="50" rows="3">' . htmlspecialchars($taskInfo['tags_replace_with']) . '</textarea>';
+               $additionalFields[$fieldID] = array(
+                       'code'     => $fieldCode,
+                       'label'    => 'Replace tag with (one per line)'
+               );
+
+               return $additionalFields;
+}
+
+    public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
+       $retVal = true;
+       
+               $submittedData['url'] = trim($submittedData['url']);
+               if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($submittedData['url'])) {
+                       $parentObject->addMessage('URL muss angegeben werden', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                       $retVal = false;
+               }
+        
+               if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($submittedData['storeuid'])) {
+                       $parentObject->addMessage('UID muss als Zahl angegeben werden', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                       $retVal = false;
+               }
+               else {
+                       $submittedData['storeuid'] = \TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger($submittedData['storeuid']);
+                       $recData = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tt_content', $submittedData['storeuid'], 'CType');
+                       if (!is_array($recData) || $recData['CType'] != 'html') {
+                               $parentObject->addMessage('Angegebene UID ist kein HTML Element', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $retVal = false;
+                   }
+               }
+        
+               $submittedData['contentElement'] = trim($submittedData['contentElement']);
+               if ($submittedData['contentElement'] == '') {
+                       $parentObject->addMessage('Content Element muss angegeben werden', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                       $retVal = false;
+               }
+        
+        $submittedData['includeContainerTag'] = $submittedData['includeContainerTag'] == '1';
+        $submittedData['timeMarker'] = trim($submittedData['timeMarker']);
+        $submittedData['wrapper'] = trim($submittedData['wrapper']);
+        // it's important for the textareas to remove CRs input from Windows computers
+        $submittedData['attr_queries'] = str_replace("\r", '', trim($submittedData['attr_queries']));
+        $submittedData['attributes'] = str_replace("\r", '', rtrim($submittedData['attributes']));
+        $submittedData['attr_replace_with'] = str_replace("\r", '', rtrim($submittedData['attr_replace_with']));
+        $submittedData['tags_to_replace_content'] = str_replace("\r", '', trim($submittedData['tags_to_replace_content']));
+        $submittedData['content_replace_with'] = str_replace("\r", '', rtrim($submittedData['content_replace_with']));
+        $submittedData['tags_to_replace'] = str_replace("\r", '', trim($submittedData['tags_to_replace']));
+        $submittedData['tags_replace_with'] = str_replace("\r", '', rtrim($submittedData['tags_replace_with']));
+        
+               return $retVal;
+    }
+
+       public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
+               $task->url = $submittedData['url'];
+               $task->storeuid = $submittedData['storeuid'];
+               $task->contentElement = $submittedData['contentElement'];
+               $task->includeContainerTag = $submittedData['includeContainerTag'];
+               $task->timeMarker = $submittedData['timeMarker'];
+               $task->wrapper = $submittedData['wrapper'];
+               $task->attr_queries = $submittedData['attr_queries'];
+               $task->attributes = $submittedData['attributes'];
+               $task->attr_replace_with = $submittedData['attr_replace_with'];
+               $task->tags_to_replace_content = $submittedData['tags_to_replace_content'];
+               $task->content_replace_with = $submittedData['content_replace_with'];
+               $task->tags_to_replace = $submittedData['tags_to_replace'];
+               $task->tags_replace_with = $submittedData['tags_replace_with'];
+       }
+}
+?>
diff --git a/Classes/Utility/simple_html_dom.php b/Classes/Utility/simple_html_dom.php
new file mode 100644 (file)
index 0000000..c847fea
--- /dev/null
@@ -0,0 +1,1749 @@
+<?php\r
+namespace DANNYM\StoreUrl\Utility;\r
+/**\r
+ * Website: http://sourceforge.net/projects/simplehtmldom/\r
+ * Additional projects that may be used: http://sourceforge.net/projects/debugobject/\r
+ * Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)\r
+ * Contributions by:\r
+ *      Yousuke Kumakura (Attribute filters)\r
+ *      Vadim Voituk (Negative indexes supports of "find" method)\r
+ *      Antcs (Constructor with automatically load contents either text or file/url)\r
+ *\r
+ * all affected sections have comments starting with "PaperG"\r
+ *\r
+ * Paperg - Added case insensitive testing of the value of the selector.\r
+ * Paperg - Added tag_start for the starting index of tags - NOTE: This works but not accurately.\r
+ *  This tag_start gets counted AFTER \r\n have been crushed out, and after the remove_noice calls so it will not reflect the REAL position of the tag in the source,\r
+ *  it will almost always be smaller by some amount.\r
+ *  We use this to determine how far into the file the tag in question is.  This "percentage will never be accurate as the $dom->size is the "real" number of bytes the dom was created from.\r
+ *  but for most purposes, it's a really good estimation.\r
+ * Paperg - Added the forceTagsClosed to the dom constructor.  Forcing tags closed is great for malformed html, but it CAN lead to parsing errors.\r
+ * Allow the user to tell us how much they trust the html.\r
+ * Paperg add the text and plaintext to the selectors for the find syntax.  plaintext implies text in the innertext of a node.  text implies that the tag is a text node.\r
+ * This allows for us to find tags based on the text they contain.\r
+ * Create find_ancestor_tag to see if a tag is - at any level - inside of another specific tag.\r
+ * Paperg: added parse_charset so that we know about the character set of the source document.\r
+ *  NOTE:  If the user's system has a routine called get_last_retrieve_url_contents_content_type availalbe, we will assume it's returning the content-type header from the\r
+ *  last transfer or curl_exec, and we will parse that and use it in preference to any other method of charset detection.\r
+ *\r
+ * Found infinite loop in the case of broken html in restore_noise.  Rewrote to protect from that.\r
+ * PaperG (John Schlick) Added get_display_size for "IMG" tags.\r
+ *\r
+ * Licensed under The MIT License\r
+ * Redistributions of files must retain the above copyright notice.\r
+ *\r
+ * @author S.C. Chen <me578022@gmail.com>\r
+ * @author John Schlick\r
+ * @author Rus Carroll\r
+ * @version 1.5 ($Rev: 210 $)\r
+ * @package PlaceLocalInclude\r
+ * @subpackage simple_html_dom\r
+ */\r
+\r
+/**\r
+ * All of the Defines for the classes below.\r
+ * @author S.C. Chen <me578022@gmail.com>\r
+ */\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_ELEMENT', 1);\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_COMMENT', 2);\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_TEXT',       3);\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_ENDTAG',  4);\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_ROOT',       5);\r
+define('DANNYM\StoreUrl\Utility\HDOM_TYPE_UNKNOWN', 6);\r
+define('DANNYM\StoreUrl\Utility\HDOM_QUOTE_DOUBLE', 0);\r
+define('DANNYM\StoreUrl\Utility\HDOM_QUOTE_SINGLE', 1);\r
+define('DANNYM\StoreUrl\Utility\HDOM_QUOTE_NO',         3);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_BEGIN',   0);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_END',         1);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_QUOTE',   2);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_SPACE',   3);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_TEXT',       4);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_INNER',   5);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_OUTER',   6);\r
+define('DANNYM\StoreUrl\Utility\HDOM_INFO_ENDSPACE',7);\r
+define('DANNYM\StoreUrl\Utility\DEFAULT_TARGET_CHARSET', 'UTF-8');\r
+define('DANNYM\StoreUrl\Utility\DEFAULT_BR_TEXT', "\r\n");\r
+define('DANNYM\StoreUrl\Utility\DEFAULT_SPAN_TEXT', " ");\r
+// define('MAX_FILE_SIZE', 600000);\r
+\r
+/** DM: comment helper functions to have a clean class\r
+\r
+// helper functions\r
+// -----------------------------------------------------------------------------\r
+// get html dom from file\r
+// $maxlen is defined in the code as PHP_STREAM_COPY_ALL which is defined as -1.\r
+function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)\r
+{\r
+       // We DO force the tags to be terminated.\r
+       $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);\r
+       // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done.\r
+       $contents = file_get_contents($url, $use_include_path, $context, $offset);\r
+       // Paperg - use our own mechanism for getting the contents as we want to control the timeout.\r
+       //$contents = retrieve_url_contents($url);\r
+       if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)\r
+       {\r
+               return false;\r
+       }\r
+       // The second parameter can force the selectors to all be lowercase.\r
+       $dom->load($contents, $lowercase, $stripRN);\r
+       return $dom;\r
+}\r
+\r
+// get html dom from string\r
+function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)\r
+{\r
+       $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);\r
+       if (empty($str) || strlen($str) > MAX_FILE_SIZE)\r
+       {\r
+               $dom->clear();\r
+               return false;\r
+       }\r
+       $dom->load($str, $lowercase, $stripRN);\r
+       return $dom;\r
+}\r
+\r
+// dump html dom tree\r
+function dump_html_tree($node, $show_attr=true, $deep=0)\r
+{\r
+       $node->dump($node);\r
+}\r
+\r
+***/\r
+\r
+/**\r
+ * simple html dom node\r
+ * PaperG - added ability for "find" routine to lowercase the value of the selector.\r
+ * PaperG - added $tag_start to track the start position of the tag in the total byte index\r
+ *\r
+ * @package PlaceLocalInclude\r
+ */\r
+class simple_html_dom_node\r
+{\r
+       public $nodetype = HDOM_TYPE_TEXT;\r
+       public $tag = 'text';\r
+       public $attr = array();\r
+       public $children = array();\r
+       public $nodes = array();\r
+       public $parent = null;\r
+       // The "info" array - see HDOM_INFO_... for what each element contains.\r
+       public $_ = array();\r
+       public $tag_start = 0;\r
+       private $dom = null;\r
+\r
+       function __construct($dom)\r
+       {\r
+               $this->dom = $dom;\r
+               $dom->nodes[] = $this;\r
+       }\r
+\r
+       function __destruct()\r
+       {\r
+               $this->clear();\r
+       }\r
+\r
+       function __toString()\r
+       {\r
+               return $this->outertext();\r
+       }\r
+\r
+       // clean up memory due to php5 circular references memory leak...\r
+       function clear()\r
+       {\r
+               $this->dom = null;\r
+               $this->nodes = null;\r
+               $this->parent = null;\r
+               $this->children = null;\r
+       }\r
+\r
+       // dump node's tree\r
+       function dump($show_attr=true, $deep=0)\r
+       {\r
+               $lead = str_repeat('    ', $deep);\r
+\r
+               echo $lead.$this->tag;\r
+               if ($show_attr && count($this->attr)>0)\r
+               {\r
+                       echo '(';\r
+                       foreach ($this->attr as $k=>$v)\r
+                               echo "[$k]=>\"".$this->$k.'", ';\r
+                       echo ')';\r
+               }\r
+               echo "\n";\r
+\r
+               if ($this->nodes)\r
+               {\r
+                       foreach ($this->nodes as $c)\r
+                       {\r
+                               $c->dump($show_attr, $deep+1);\r
+                       }\r
+               }\r
+       }\r
+\r
+\r
+       // Debugging function to dump a single dom node with a bunch of information about it.\r
+       function dump_node($echo=true)\r
+       {\r
+\r
+               $string = $this->tag;\r
+               if (count($this->attr)>0)\r
+               {\r
+                       $string .= '(';\r
+                       foreach ($this->attr as $k=>$v)\r
+                       {\r
+                               $string .= "[$k]=>\"".$this->$k.'", ';\r
+                       }\r
+                       $string .= ')';\r
+               }\r
+               if (count($this->_)>0)\r
+               {\r
+                       $string .= ' $_ (';\r
+                       foreach ($this->_ as $k=>$v)\r
+                       {\r
+                               if (is_array($v))\r
+                               {\r
+                                       $string .= "[$k]=>(";\r
+                                       foreach ($v as $k2=>$v2)\r
+                                       {\r
+                                               $string .= "[$k2]=>\"".$v2.'", ';\r
+                                       }\r
+                                       $string .= ")";\r
+                               } else {\r
+                                       $string .= "[$k]=>\"".$v.'", ';\r
+                               }\r
+                       }\r
+                       $string .= ")";\r
+               }\r
+\r
+               if (isset($this->text))\r
+               {\r
+                       $string .= " text: (" . $this->text . ")";\r
+               }\r
+\r
+               $string .= " HDOM_INNER_INFO: '";\r
+               if (isset($node->_[HDOM_INFO_INNER]))\r
+               {\r
+                       $string .= $node->_[HDOM_INFO_INNER] . "'";\r
+               }\r
+               else\r
+               {\r
+                       $string .= ' NULL ';\r
+               }\r
+\r
+               $string .= " children: " . count($this->children);\r
+               $string .= " nodes: " . count($this->nodes);\r
+               $string .= " tag_start: " . $this->tag_start;\r
+               $string .= "\n";\r
+\r
+               if ($echo)\r
+               {\r
+                       echo $string;\r
+                       return;\r
+               }\r
+               else\r
+               {\r
+                       return $string;\r
+               }\r
+       }\r
+\r
+       // returns the parent of node\r
+       // If a node is passed in, it will reset the parent of the current node to that one.\r
+       function parent($parent=null)\r
+       {\r
+               // I am SURE that this doesn't work properly.\r
+               // It fails to unset the current node from it's current parents nodes or children list first.\r
+               if ($parent !== null)\r
+               {\r
+                       $this->parent = $parent;\r
+                       $this->parent->nodes[] = $this;\r
+                       $this->parent->children[] = $this;\r
+               }\r
+\r
+               return $this->parent;\r
+       }\r
+\r
+       // verify that node has children\r
+       function has_child()\r
+       {\r
+               return !empty($this->children);\r
+       }\r
+\r
+       // returns children of node\r
+       function children($idx=-1)\r
+       {\r
+               if ($idx===-1)\r
+               {\r
+                       return $this->children;\r
+               }\r
+               if (isset($this->children[$idx]))\r
+               {\r
+                       return $this->children[$idx];\r
+               }\r
+               return null;\r
+       }\r
+\r
+       // returns the first child of node\r
+       function first_child()\r
+       {\r
+               if (count($this->children)>0)\r
+               {\r
+                       return $this->children[0];\r
+               }\r
+               return null;\r
+       }\r
+\r
+       // returns the last child of node\r
+       function last_child()\r
+       {\r
+               if (($count=count($this->children))>0)\r
+               {\r
+                       return $this->children[$count-1];\r
+               }\r
+               return null;\r
+       }\r
+\r
+       // returns the next sibling of node\r
+       function next_sibling()\r
+       {\r
+               if ($this->parent===null)\r
+               {\r
+                       return null;\r
+               }\r
+\r
+               $idx = 0;\r
+               $count = count($this->parent->children);\r
+               while ($idx<$count && $this!==$this->parent->children[$idx])\r
+               {\r
+                       ++$idx;\r
+               }\r
+               if (++$idx>=$count)\r
+               {\r
+                       return null;\r
+               }\r
+               return $this->parent->children[$idx];\r
+       }\r
+\r
+       // returns the previous sibling of node\r
+       function prev_sibling()\r
+       {\r
+               if ($this->parent===null) return null;\r
+               $idx = 0;\r
+               $count = count($this->parent->children);\r
+               while ($idx<$count && $this!==$this->parent->children[$idx])\r
+                       ++$idx;\r
+               if (--$idx<0) return null;\r
+               return $this->parent->children[$idx];\r
+       }\r
+\r
+       // function to locate a specific ancestor tag in the path to the root.\r
+       function find_ancestor_tag($tag)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }\r
+\r
+               // Start by including ourselves in the comparison.\r
+               $returnDom = $this;\r
+\r
+               while (!is_null($returnDom))\r
+               {\r
+                       if (is_object($debug_object)) { $debug_object->debug_log(2, "Current tag is: " . $returnDom->tag); }\r
+\r
+                       if ($returnDom->tag == $tag)\r
+                       {\r
+                               break;\r
+                       }\r
+                       $returnDom = $returnDom->parent;\r
+               }\r
+               return $returnDom;\r
+       }\r
+\r
+       // get dom node's inner html\r
+       function innertext()\r
+       {\r
+               if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];\r
+               if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);\r
+\r
+               $ret = '';\r
+               foreach ($this->nodes as $n)\r
+                       $ret .= $n->outertext();\r
+               return $ret;\r
+       }\r
+\r
+       // get dom node's outer text (with tag)\r
+       function outertext()\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object))\r
+               {\r
+                       $text = '';\r
+                       if ($this->tag == 'text')\r
+                       {\r
+                               if (!empty($this->text))\r
+                               {\r
+                                       $text = " with text: " . $this->text;\r
+                               }\r
+                       }\r
+                       $debug_object->debug_log(1, 'Innertext of tag: ' . $this->tag . $text);\r
+               }\r
+\r
+               if ($this->tag==='root') return $this->innertext();\r
+\r
+               // trigger callback\r
+               if ($this->dom && $this->dom->callback!==null)\r
+               {\r
+                       call_user_func_array($this->dom->callback, array($this));\r
+               }\r
+\r
+               if (isset($this->_[HDOM_INFO_OUTER])) return $this->_[HDOM_INFO_OUTER];\r
+               if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);\r
+\r
+               // render begin tag\r
+               if ($this->dom && $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]])\r
+               {\r
+                       $ret = $this->dom->nodes[$this->_[HDOM_INFO_BEGIN]]->makeup();\r
+               } else {\r
+                       $ret = "";\r
+               }\r
+\r
+               // render inner text\r
+               if (isset($this->_[HDOM_INFO_INNER]))\r
+               {\r
+                       // If it's a br tag...  don't return the HDOM_INNER_INFO that we may or may not have added.\r
+                       if ($this->tag != "br")\r
+                       {\r
+                               $ret .= $this->_[HDOM_INFO_INNER];\r
+                       }\r
+               } else {\r
+                       if ($this->nodes)\r
+                       {\r
+                               foreach ($this->nodes as $n)\r
+                               {\r
+                                       $ret .= $this->convert_text($n->outertext());\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // render end tag\r
+               if (isset($this->_[HDOM_INFO_END]) && $this->_[HDOM_INFO_END]!=0)\r
+                       $ret .= '</'.$this->tag.'>';\r
+               return $ret;\r
+       }\r
+\r
+       // get dom node's plain text\r
+       function text()\r
+       {\r
+               if (isset($this->_[HDOM_INFO_INNER])) return $this->_[HDOM_INFO_INNER];\r
+               switch ($this->nodetype)\r
+               {\r
+                       case HDOM_TYPE_TEXT: return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);\r
+                       case HDOM_TYPE_COMMENT: return '';\r
+                       case HDOM_TYPE_UNKNOWN: return '';\r
+               }\r
+               if (strcasecmp($this->tag, 'script')===0) return '';\r
+               if (strcasecmp($this->tag, 'style')===0) return '';\r
+\r
+               $ret = '';\r
+               // In rare cases, (always node type 1 or HDOM_TYPE_ELEMENT - observed for some span tags, and some p tags) $this->nodes is set to NULL.\r
+               // NOTE: This indicates that there is a problem where it's set to NULL without a clear happening.\r
+               // WHY is this happening?\r
+               if (!is_null($this->nodes))\r
+               {\r
+                       foreach ($this->nodes as $n)\r
+                       {\r
+                               $ret .= $this->convert_text($n->text());\r
+                       }\r
+\r
+                       // If this node is a span... add a space at the end of it so multiple spans don't run into each other.  This is plaintext after all.\r
+                       if ($this->tag == "span")\r
+                       {\r
+                               $ret .= $this->dom->default_span_text;\r
+                       }\r
+\r
+\r
+               }\r
+               return $ret;\r
+       }\r
+\r
+       function xmltext()\r
+       {\r
+               $ret = $this->innertext();\r
+               $ret = str_ireplace('<![CDATA[', '', $ret);\r
+               $ret = str_replace(']]>', '', $ret);\r
+               return $ret;\r
+       }\r
+\r
+       // build node's text with tag\r
+       function makeup()\r
+       {\r
+               // text, comment, unknown\r
+               if (isset($this->_[HDOM_INFO_TEXT])) return $this->dom->restore_noise($this->_[HDOM_INFO_TEXT]);\r
+\r
+               $ret = '<'.$this->tag;\r
+               $i = -1;\r
+\r
+               foreach ($this->attr as $key=>$val)\r
+               {\r
+                       ++$i;\r
+\r
+                       // skip removed attribute\r
+                       if ($val===null || $val===false)\r
+                               continue;\r
+\r
+                       $ret .= $this->_[HDOM_INFO_SPACE][$i][0];\r
+                       //no value attr: nowrap, checked selected...\r
+                       if ($val===true)\r
+                               $ret .= $key;\r
+                       else {\r
+                               switch ($this->_[HDOM_INFO_QUOTE][$i])\r
+                               {\r
+                                       case HDOM_QUOTE_DOUBLE: $quote = '"'; break;\r
+                                       case HDOM_QUOTE_SINGLE: $quote = '\''; break;\r
+                                       default: $quote = '';\r
+                               }\r
+                               $ret .= $key.$this->_[HDOM_INFO_SPACE][$i][1].'='.$this->_[HDOM_INFO_SPACE][$i][2].$quote.$val.$quote;\r
+                       }\r
+               }\r
+               $ret = $this->dom->restore_noise($ret);\r
+               return $ret . $this->_[HDOM_INFO_ENDSPACE] . '>';\r
+       }\r
+\r
+       // find elements by css selector\r
+       //PaperG - added ability for find to lowercase the value of the selector.\r
+       function find($selector, $idx=null, $lowercase=false)\r
+       {\r
+               $selectors = $this->parse_selector($selector);\r
+               if (($count=count($selectors))===0) return array();\r
+               $found_keys = array();\r
+\r
+               // find each selector\r
+               for ($c=0; $c<$count; ++$c)\r
+               {\r
+                       // The change on the below line was documented on the sourceforge code tracker id 2788009\r
+                       // used to be: if (($levle=count($selectors[0]))===0) return array();\r
+                       if (($levle=count($selectors[$c]))===0) return array();\r
+                       if (!isset($this->_[HDOM_INFO_BEGIN])) return array();\r
+\r
+                       $head = array($this->_[HDOM_INFO_BEGIN]=>1);\r
+\r
+                       // handle descendant selectors, no recursive!\r
+                       for ($l=0; $l<$levle; ++$l)\r
+                       {\r
+                               $ret = array();\r
+                               foreach ($head as $k=>$v)\r
+                               {\r
+                                       $n = ($k===-1) ? $this->dom->root : $this->dom->nodes[$k];\r
+                                       //PaperG - Pass this optional parameter on to the seek function.\r
+                                       $n->seek($selectors[$c][$l], $ret, $lowercase);\r
+                               }\r
+                               $head = $ret;\r
+                       }\r
+\r
+                       foreach ($head as $k=>$v)\r
+                       {\r
+                               if (!isset($found_keys[$k]))\r
+                               {\r
+                                       $found_keys[$k] = 1;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // sort keys\r
+               ksort($found_keys);\r
+\r
+               $found = array();\r
+               foreach ($found_keys as $k=>$v)\r
+                       $found[] = $this->dom->nodes[$k];\r
+\r
+               // return nth-element or array\r
+               if (is_null($idx)) return $found;\r
+               else if ($idx<0) $idx = count($found) + $idx;\r
+               return (isset($found[$idx])) ? $found[$idx] : null;\r
+       }\r
+\r
+       // seek for given conditions\r
+       // PaperG - added parameter to allow for case insensitive testing of the value of a selector.\r
+       protected function seek($selector, &$ret, $lowercase=false)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }\r
+\r
+               list($tag, $key, $val, $exp, $no_key) = $selector;\r
+\r
+               // xpath index\r
+               if ($tag && $key && is_numeric($key))\r
+               {\r
+                       $count = 0;\r
+                       foreach ($this->children as $c)\r
+                       {\r
+                               if ($tag==='*' || $tag===$c->tag) {\r
+                                       if (++$count==$key) {\r
+                                               $ret[$c->_[HDOM_INFO_BEGIN]] = 1;\r
+                                               return;\r
+                                       }\r
+                               }\r
+                       }\r
+                       return;\r
+               }\r
+\r
+               $end = (!empty($this->_[HDOM_INFO_END])) ? $this->_[HDOM_INFO_END] : 0;\r
+               if ($end==0) {\r
+                       $parent = $this->parent;\r
+                       while (!isset($parent->_[HDOM_INFO_END]) && $parent!==null) {\r
+                               $end -= 1;\r
+                               $parent = $parent->parent;\r
+                       }\r
+                       $end += $parent->_[HDOM_INFO_END];\r
+               }\r
+\r
+               for ($i=$this->_[HDOM_INFO_BEGIN]+1; $i<$end; ++$i) {\r
+                       $node = $this->dom->nodes[$i];\r
+\r
+                       $pass = true;\r
+\r
+                       if ($tag==='*' && !$key) {\r
+                               if (in_array($node, $this->children, true))\r
+                                       $ret[$i] = 1;\r
+                               continue;\r
+                       }\r
+\r
+                       // compare tag\r
+                       if ($tag && $tag!=$node->tag && $tag!=='*') {$pass=false;}\r
+                       // compare key\r
+                       if ($pass && $key) {\r
+                               if ($no_key) {\r
+                                       if (isset($node->attr[$key])) $pass=false;\r
+                               } else {\r
+                                       if (($key != "plaintext") && !isset($node->attr[$key])) $pass=false;\r
+                               }\r
+                       }\r
+                       // compare value\r
+                       if ($pass && $key && $val  && $val!=='*') {\r
+                               // If they have told us that this is a "plaintext" search then we want the plaintext of the node - right?\r
+                               if ($key == "plaintext") {\r
+                                       // $node->plaintext actually returns $node->text();\r
+                                       $nodeKeyValue = $node->text();\r
+                               } else {\r
+                                       // this is a normal search, we want the value of that attribute of the tag.\r
+                                       $nodeKeyValue = $node->attr[$key];\r
+                               }\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, "testing node: " . $node->tag . " for attribute: " . $key . $exp . $val . " where nodes value is: " . $nodeKeyValue);}\r
+\r
+                               //PaperG - If lowercase is set, do a case insensitive test of the value of the selector.\r
+                               if ($lowercase) {\r
+                                       $check = $this->match($exp, strtolower($val), strtolower($nodeKeyValue));\r
+                               } else {\r
+                                       $check = $this->match($exp, $val, $nodeKeyValue);\r
+                               }\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, "after match: " . ($check ? "true" : "false"));}\r
+\r
+                               // handle multiple class\r
+                               if (!$check && strcasecmp($key, 'class')===0) {\r
+                                       foreach (explode(' ',$node->attr[$key]) as $k) {\r
+                                               // Without this, there were cases where leading, trailing, or double spaces lead to our comparing blanks - bad form.\r
+                                               if (!empty($k)) {\r
+                                                       if ($lowercase) {\r
+                                                               $check = $this->match($exp, strtolower($val), strtolower($k));\r
+                                                       } else {\r
+                                                               $check = $this->match($exp, $val, $k);\r
+                                                       }\r
+                                                       if ($check) break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               if (!$check) $pass = false;\r
+                       }\r
+                       if ($pass) $ret[$i] = 1;\r
+                       unset($node);\r
+               }\r
+               // It's passed by reference so this is actually what this function returns.\r
+               if (is_object($debug_object)) {$debug_object->debug_log(1, "EXIT - ret: ", $ret);}\r
+       }\r
+\r
+       protected function match($exp, $pattern, $value) {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}\r
+\r
+               switch ($exp) {\r
+                       case '=':\r
+                               return ($value===$pattern);\r
+                       case '!=':\r
+                               return ($value!==$pattern);\r
+                       case '^=':\r
+                               return preg_match("/^".preg_quote($pattern,'/')."/", $value);\r
+                       case '$=':\r
+                               return preg_match("/".preg_quote($pattern,'/')."$/", $value);\r
+                       case '*=':\r
+                               if ($pattern[0]=='/') {\r
+                                       return preg_match($pattern, $value);\r
+                               }\r
+                               return preg_match("/".$pattern."/i", $value);\r
+               }\r
+               return false;\r
+       }\r
+\r
+       protected function parse_selector($selector_string) {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}\r
+\r
+               // pattern of CSS selectors, modified from mootools\r
+               // Paperg: Add the colon to the attrbute, so that it properly finds <tag attr:ibute="something" > like google does.\r
+               // Note: if you try to look at this attribute, yo MUST use getAttribute since $dom->x:y will fail the php syntax check.\r
+// Notice the \[ starting the attbute?  and the @? following?  This implies that an attribute can begin with an @ sign that is not captured.\r
+// This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression.\r
+// farther study is required to determine of this should be documented or removed.\r
+//             $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";\r
+               $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";\r
+               preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER);\r
+               if (is_object($debug_object)) {$debug_object->debug_log(2, "Matches Array: ", $matches);}\r
+\r
+               $selectors = array();\r
+               $result = array();\r
+               //print_r($matches);\r
+\r
+               foreach ($matches as $m) {\r
+                       $m[0] = trim($m[0]);\r
+                       if ($m[0]==='' || $m[0]==='/' || $m[0]==='//') continue;\r
+                       // for browser generated xpath\r
+                       if ($m[1]==='tbody') continue;\r
+\r
+                       list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);\r
+                       if (!empty($m[2])) {$key='id'; $val=$m[2];}\r
+                       if (!empty($m[3])) {$key='class'; $val=$m[3];}\r
+                       if (!empty($m[4])) {$key=$m[4];}\r
+                       if (!empty($m[5])) {$exp=$m[5];}\r
+                       if (!empty($m[6])) {$val=$m[6];}\r
+\r
+                       // convert to lowercase\r
+                       if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);}\r
+                       //elements that do NOT have the specified attribute\r
+                       if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;}\r
+\r
+                       $result[] = array($tag, $key, $val, $exp, $no_key);\r
+                       if (trim($m[7])===',') {\r
+                               $selectors[] = $result;\r
+                               $result = array();\r
+                       }\r
+               }\r
+               if (count($result)>0)\r
+                       $selectors[] = $result;\r
+               return $selectors;\r
+       }\r
+\r
+       function __get($name)\r
+       {\r
+               if (isset($this->attr[$name]))\r
+               {\r
+                       return $this->convert_text($this->attr[$name]);\r
+               }\r
+               switch ($name)\r
+               {\r
+                       case 'outertext': return $this->outertext();\r
+                       case 'innertext': return $this->innertext();\r
+                       case 'plaintext': return $this->text();\r
+                       case 'xmltext': return $this->xmltext();\r
+                       default: return array_key_exists($name, $this->attr);\r
+               }\r
+       }\r
+\r
+       function __set($name, $value)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}\r
+\r
+               switch ($name)\r
+               {\r
+                       case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;\r
+                       case 'innertext':\r
+                               if (isset($this->_[HDOM_INFO_TEXT])) return $this->_[HDOM_INFO_TEXT] = $value;\r
+                               return $this->_[HDOM_INFO_INNER] = $value;\r
+               }\r
+               if (!isset($this->attr[$name]))\r
+               {\r
+                       $this->_[HDOM_INFO_SPACE][] = array(' ', '', '');\r
+                       $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;\r
+               }\r
+               $this->attr[$name] = $value;\r
+       }\r
+\r
+       function __isset($name)\r
+       {\r
+               switch ($name)\r
+               {\r
+                       case 'outertext': return true;\r
+                       case 'innertext': return true;\r
+                       case 'plaintext': return true;\r
+               }\r
+               //no value attr: nowrap, checked selected...\r
+               return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]);\r
+       }\r
+\r
+       function __unset($name) {\r
+               if (isset($this->attr[$name]))\r
+                       unset($this->attr[$name]);\r
+       }\r
+\r
+       // PaperG - Function to convert the text from one character set to another if the two sets are not the same.\r
+       function convert_text($text)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}\r
+\r
+               $converted_text = $text;\r
+\r
+               $sourceCharset = "";\r
+               $targetCharset = "";\r
+\r
+               if ($this->dom)\r
+               {\r
+                       $sourceCharset = strtoupper($this->dom->_charset);\r
+                       $targetCharset = strtoupper($this->dom->_target_charset);\r
+               }\r
+               if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}\r
+\r
+               if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))\r
+               {\r
+                       // Check if the reported encoding could have been incorrect and the text is actually already UTF-8\r
+                       if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))\r
+                       {\r
+                               $converted_text = $text;\r
+                       }\r
+                       else\r
+                       {\r
+                               $converted_text = iconv($sourceCharset, $targetCharset, $text);\r
+                       }\r
+               }\r
+\r
+               // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.\r
+               if ($targetCharset == 'UTF-8')\r
+               {\r
+                       if (substr($converted_text, 0, 3) == "\xef\xbb\xbf")\r
+                       {\r
+                               $converted_text = substr($converted_text, 3);\r
+                       }\r
+                       if (substr($converted_text, -3) == "\xef\xbb\xbf")\r
+                       {\r
+                               $converted_text = substr($converted_text, 0, -3);\r
+                       }\r
+               }\r
+\r
+               return $converted_text;\r
+       }\r
+\r
+       /**\r
+       * Returns true if $string is valid UTF-8 and false otherwise.\r
+       *\r
+       * @param mixed $str String to be tested\r
+       * @return boolean\r
+       */\r
+       static function is_utf8($str)\r
+       {\r
+               $c=0; $b=0;\r
+               $bits=0;\r
+               $len=strlen($str);\r
+               for($i=0; $i<$len; $i++)\r
+               {\r
+                       $c=ord($str[$i]);\r
+                       if($c > 128)\r
+                       {\r
+                               if(($c >= 254)) return false;\r
+                               elseif($c >= 252) $bits=6;\r
+                               elseif($c >= 248) $bits=5;\r
+                               elseif($c >= 240) $bits=4;\r
+                               elseif($c >= 224) $bits=3;\r
+                               elseif($c >= 192) $bits=2;\r
+                               else return false;\r
+                               if(($i+$bits) > $len) return false;\r
+                               while($bits > 1)\r
+                               {\r
+                                       $i++;\r
+                                       $b=ord($str[$i]);\r
+                                       if($b < 128 || $b > 191) return false;\r
+                                       $bits--;\r
+                               }\r
+                       }\r
+               }\r
+               return true;\r
+       }\r
+       /*\r
+       function is_utf8($string)\r
+       {\r
+               //this is buggy\r
+               return (utf8_encode(utf8_decode($string)) == $string);\r
+       }\r
+       */\r
+\r
+       /**\r
+        * Function to try a few tricks to determine the displayed size of an img on the page.\r
+        * NOTE: This will ONLY work on an IMG tag. Returns FALSE on all other tag types.\r
+        *\r
+        * @author John Schlick\r
+        * @version April 19 2012\r
+        * @return array an array containing the 'height' and 'width' of the image on the page or -1 if we can't figure it out.\r
+        */\r
+       function get_display_size()\r
+       {\r
+               global $debug_object;\r
+\r
+               $width = -1;\r
+               $height = -1;\r
+\r
+               if ($this->tag !== 'img')\r
+               {\r
+                       return false;\r
+               }\r
+\r
+               // See if there is aheight or width attribute in the tag itself.\r
+               if (isset($this->attr['width']))\r
+               {\r
+                       $width = $this->attr['width'];\r
+               }\r
+\r
+               if (isset($this->attr['height']))\r
+               {\r
+                       $height = $this->attr['height'];\r
+               }\r
+\r
+               // Now look for an inline style.\r
+               if (isset($this->attr['style']))\r
+               {\r
+                       // Thanks to user gnarf from stackoverflow for this regular expression.\r
+                       $attributes = array();\r
+                       preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER);\r
+                       foreach ($matches as $match) {\r
+                         $attributes[$match[1]] = $match[2];\r
+                       }\r
+\r
+                       // If there is a width in the style attributes:\r
+                       if (isset($attributes['width']) && $width == -1)\r
+                       {\r
+                               // check that the last two characters are px (pixels)\r
+                               if (strtolower(substr($attributes['width'], -2)) == 'px')\r
+                               {\r
+                                       $proposed_width = substr($attributes['width'], 0, -2);\r
+                                       // Now make sure that it's an integer and not something stupid.\r
+                                       if (filter_var($proposed_width, FILTER_VALIDATE_INT))\r
+                                       {\r
+                                               $width = $proposed_width;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       // If there is a width in the style attributes:\r
+                       if (isset($attributes['height']) && $height == -1)\r
+                       {\r
+                               // check that the last two characters are px (pixels)\r
+                               if (strtolower(substr($attributes['height'], -2)) == 'px')\r
+                               {\r
+                                       $proposed_height = substr($attributes['height'], 0, -2);\r
+                                       // Now make sure that it's an integer and not something stupid.\r
+                                       if (filter_var($proposed_height, FILTER_VALIDATE_INT))\r
+                                       {\r
+                                               $height = $proposed_height;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+               }\r
+\r
+               // Future enhancement:\r
+               // Look in the tag to see if there is a class or id specified that has a height or width attribute to it.\r
+\r
+               // Far future enhancement\r
+               // Look at all the parent tags of this image to see if they specify a class or id that has an img selector that specifies a height or width\r
+               // Note that in this case, the class or id will have the img subselector for it to apply to the image.\r
+\r
+               // ridiculously far future development\r
+               // If the class or id is specified in a SEPARATE css file thats not on the page, go get it and do what we were just doing for the ones on the page.\r
+\r
+               $result = array('height' => $height,\r
+                                               'width' => $width);\r
+               return $result;\r
+       }\r
+\r
+       // camel naming conventions\r
+       function getAllAttributes() {return $this->attr;}\r
+       function getAttribute($name) {return $this->__get($name);}\r
+       function setAttribute($name, $value) {$this->__set($name, $value);}\r
+       function hasAttribute($name) {return $this->__isset($name);}\r
+       function removeAttribute($name) {$this->__set($name, null);}\r
+       function getElementById($id) {return $this->find("#$id", 0);}\r
+       function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}\r
+       function getElementByTagName($name) {return $this->find($name, 0);}\r
+       function getElementsByTagName($name, $idx=null) {return $this->find($name, $idx);}\r
+       function parentNode() {return $this->parent();}\r
+       function childNodes($idx=-1) {return $this->children($idx);}\r
+       function firstChild() {return $this->first_child();}\r
+       function lastChild() {return $this->last_child();}\r
+       function nextSibling() {return $this->next_sibling();}\r
+       function previousSibling() {return $this->prev_sibling();}\r
+       function hasChildNodes() {return $this->has_child();}\r
+       function nodeName() {return $this->tag;}\r
+       function appendChild($node) {$node->parent($this); return $node;}\r
+\r
+}\r
+\r
+/**\r
+ * simple html dom parser\r
+ * Paperg - in the find routine: allow us to specify that we want case insensitive testing of the value of the selector.\r
+ * Paperg - change $size from protected to public so we can easily access it\r
+ * Paperg - added ForceTagsClosed in the constructor which tells us whether we trust the html or not.  Default is to NOT trust it.\r
+ *\r
+ * @package PlaceLocalInclude\r
+ */\r
+class simple_html_dom\r
+{\r
+       public $root = null;\r
+       public $nodes = array();\r
+       public $callback = null;\r
+       public $lowercase = false;\r
+       // Used to keep track of how large the text was when we started.\r
+       public $original_size;\r
+       public $size;\r
+       protected $pos;\r
+       protected $doc;\r
+       protected $char;\r
+       protected $cursor;\r
+       protected $parent;\r
+       protected $noise = array();\r
+       protected $token_blank = " \t\r\n";\r
+       protected $token_equal = ' =/>';\r
+       protected $token_slash = " />\r\n\t";\r
+       protected $token_attr = ' >';\r
+       // Note that this is referenced by a child node, and so it needs to be public for that node to see this information.\r
+       public $_charset = '';\r
+       public $_target_charset = '';\r
+       protected $default_br_text = "";\r
+       public $default_span_text = "";\r
+\r
+       // use isset instead of in_array, performance boost about 30%...\r
+       protected $self_closing_tags = array('img'=>1, 'br'=>1, 'input'=>1, 'meta'=>1, 'link'=>1, 'hr'=>1, 'base'=>1, 'embed'=>1, 'spacer'=>1);\r
+       protected $block_tags = array('root'=>1, 'body'=>1, 'form'=>1, 'div'=>1, 'span'=>1, 'table'=>1);\r
+       // Known sourceforge issue #2977341\r
+       // B tags that are not closed cause us to return everything to the end of the document.\r
+       protected $optional_closing_tags = array(\r
+               'tr'=>array('tr'=>1, 'td'=>1, 'th'=>1),\r
+               'th'=>array('th'=>1),\r
+               'td'=>array('td'=>1),\r
+               'li'=>array('li'=>1),\r
+               'dt'=>array('dt'=>1, 'dd'=>1),\r
+               'dd'=>array('dd'=>1, 'dt'=>1),\r
+               'dl'=>array('dd'=>1, 'dt'=>1),\r
+               'p'=>array('p'=>1),\r
+               'nobr'=>array('nobr'=>1),\r
+               'b'=>array('b'=>1),\r
+               'option'=>array('option'=>1),\r
+       );\r
+\r
+       function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)\r
+       {\r
+               if ($str)\r
+               {\r
+                       if (preg_match("/^http:\/\//i",$str) || is_file($str))\r
+                       {\r
+                               $this->load_file($str);\r
+                       }\r
+                       else\r
+                       {\r
+                               $this->load($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);\r
+                       }\r
+               }\r
+               // Forcing tags to be closed implies that we don't trust the html, but it can lead to parsing errors if we SHOULD trust the html.\r
+               if (!$forceTagsClosed) {\r
+                       $this->optional_closing_array=array();\r
+               }\r
+               $this->_target_charset = $target_charset;\r
+       }\r
+\r
+       function __destruct()\r
+       {\r
+               $this->clear();\r
+       }\r
+\r
+       // load html from string\r
+       function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)\r
+       {\r
+               global $debug_object;\r
+\r
+               // prepare\r
+               $this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);\r
+               // strip out cdata\r
+               $this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);\r
+               // strip out comments\r
+               $this->remove_noise("'<!--(.*?)-->'is");\r
+               // Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037\r
+               // Script tags removal now preceeds style tag removal.\r
+               // strip out <script> tags\r
+               $this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");\r
+               $this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");\r
+               // strip out <style> tags\r
+               $this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");\r
+               $this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");\r
+               // strip out preformatted tags\r
+               $this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");\r
+               // strip out server side scripts\r
+               $this->remove_noise("'(<\?)(.*?)(\?>)'s", true);\r
+               // strip smarty scripts\r
+               $this->remove_noise("'(\{\w)(.*?)(\})'s", true);\r
+\r
+               // parsing\r
+               while ($this->parse());\r
+               // end\r
+               $this->root->_[HDOM_INFO_END] = $this->cursor;\r
+               $this->parse_charset();\r
+\r
+               // make load function chainable\r
+               return $this;\r
+\r
+       }\r
+\r
+       // load html from file\r
+       function load_file()\r
+       {\r
+               $args = func_get_args();\r
+               $this->load(call_user_func_array('file_get_contents', $args), true);\r
+               // Throw an error if we can't properly load the dom.\r
+               if (($error=error_get_last())!==null) {\r
+                       $this->clear();\r
+                       return false;\r
+               }\r
+       }\r
+\r
+       // set callback function\r
+       function set_callback($function_name)\r
+       {\r
+               $this->callback = $function_name;\r
+       }\r
+\r
+       // remove callback function\r
+       function remove_callback()\r
+       {\r
+               $this->callback = null;\r
+       }\r
+\r
+       // save dom as string\r
+       function save($filepath='')\r
+       {\r
+               $ret = $this->root->innertext();\r
+               if ($filepath!=='') file_put_contents($filepath, $ret, LOCK_EX);\r
+               return $ret;\r
+       }\r
+\r
+       // find dom node by css selector\r
+       // Paperg - allow us to specify that we want case insensitive testing of the value of the selector.\r
+       function find($selector, $idx=null, $lowercase=false)\r
+       {\r
+               return $this->root->find($selector, $idx, $lowercase);\r
+       }\r
+\r
+       // clean up memory due to php5 circular references memory leak...\r
+       function clear()\r
+       {\r
+               foreach ($this->nodes as $n) {$n->clear(); $n = null;}\r
+               // This add next line is documented in the sourceforge repository. 2977248 as a fix for ongoing memory leaks that occur even with the use of clear.\r
+               if (isset($this->children)) foreach ($this->children as $n) {$n->clear(); $n = null;}\r
+               if (isset($this->parent)) {$this->parent->clear(); unset($this->parent);}\r
+               if (isset($this->root)) {$this->root->clear(); unset($this->root);}\r
+               unset($this->doc);\r
+               unset($this->noise);\r
+       }\r
+\r
+       function dump($show_attr=true)\r
+       {\r
+               $this->root->dump($show_attr);\r
+       }\r
+\r
+       // prepare HTML data and init everything\r
+       protected function prepare($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)\r
+       {\r
+               $this->clear();\r
+\r
+               // set the length of content before we do anything to it.\r
+               $this->size = strlen($str);\r
+               // Save the original size of the html that we got in.  It might be useful to someone.\r
+               $this->original_size = $this->size;\r
+\r
+               //before we save the string as the doc...  strip out the \r \n's if we are told to.\r
+               if ($stripRN) {\r
+                       $str = str_replace("\r", " ", $str);\r
+                       $str = str_replace("\n", " ", $str);\r
+\r
+                       // set the length of content since we have changed it.\r
+                       $this->size = strlen($str);\r
+               }\r
+\r
+               $this->doc = $str;\r
+               $this->pos = 0;\r
+               $this->cursor = 1;\r
+               $this->noise = array();\r
+               $this->nodes = array();\r
+               $this->lowercase = $lowercase;\r
+               $this->default_br_text = $defaultBRText;\r
+               $this->default_span_text = $defaultSpanText;\r
+               $this->root = new simple_html_dom_node($this);\r
+               $this->root->tag = 'root';\r
+               $this->root->_[HDOM_INFO_BEGIN] = -1;\r
+               $this->root->nodetype = HDOM_TYPE_ROOT;\r
+               $this->parent = $this->root;\r
+               if ($this->size>0) $this->char = $this->doc[0];\r
+       }\r
+\r
+       // parse html content\r
+       protected function parse()\r
+       {\r
+               if (($s = $this->copy_until_char('<'))==='')\r
+               {\r
+                       return $this->read_tag();\r
+               }\r
+\r
+               // text\r
+               $node = new simple_html_dom_node($this);\r
+               ++$this->cursor;\r
+               $node->_[HDOM_INFO_TEXT] = $s;\r
+               $this->link_nodes($node, false);\r
+               return true;\r
+       }\r
+\r
+       // PAPERG - dkchou - added this to try to identify the character set of the page we have just parsed so we know better how to spit it out later.\r
+       // NOTE:  IF you provide a routine called get_last_retrieve_url_contents_content_type which returns the CURLINFO_CONTENT_TYPE from the last curl_exec\r
+       // (or the content_type header from the last transfer), we will parse THAT, and if a charset is specified, we will use it over any other mechanism.\r
+       protected function parse_charset()\r
+       {\r
+               global $debug_object;\r
+\r
+               $charset = null;\r
+\r
+/** DM: comment this really bad hack!\r
+               if (function_exists('get_last_retrieve_url_contents_content_type'))\r
+               {\r
+                       $contentTypeHeader = get_last_retrieve_url_contents_content_type();\r
+                       $success = preg_match('/charset=(.+)/', $contentTypeHeader, $matches);\r
+                       if ($success)\r
+                       {\r
+                               $charset = $matches[1];\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, 'header content-type found charset of: ' . $charset);}\r
+                       }\r
+\r
+               } */\r
+\r
+               if (empty($charset))\r
+               {\r
+                       $el = $this->root->find('meta[http-equiv=Content-Type]',0, true);\r
+                       if (!empty($el))\r
+                       {\r
+                               $fullvalue = $el->content;\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag found' . $fullvalue);}\r
+\r
+                               if (!empty($fullvalue))\r
+                               {\r
+                                       $success = preg_match('/charset=(.+)/i', $fullvalue, $matches);\r
+                                       if ($success)\r
+                                       {\r
+                                               $charset = $matches[1];\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               // If there is a meta tag, and they don't specify the character set, research says that it's typically ISO-8859-1\r
+                                               if (is_object($debug_object)) {$debug_object->debug_log(2, 'meta content-type tag couldn\'t be parsed. using iso-8859 default.');}\r
+                                               $charset = 'ISO-8859-1';\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // If we couldn't find a charset above, then lets try to detect one based on the text we got...\r
+               if (empty($charset))\r
+               {\r
+                       // Use this in case mb_detect_charset isn't installed/loaded on this machine.\r
+                       $charset = false;\r
+                       if (function_exists('mb_detect_encoding'))\r
+                       {\r
+                               // Have php try to detect the encoding from the text given to us.\r
+                               // DM: change CP1252 to ISO-8859-1 since CP1252 is no valid encoding for mb_detect_encoding\r
+                               $charset = mb_detect_encoding($this->root->plaintext . "ascii", $encoding_list = array( "UTF-8", "ISO-8859-1" ) );\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, 'mb_detect found: ' . $charset);}\r
+                       }\r
+\r
+                       // and if this doesn't work...  then we need to just wrongheadedly assume it's UTF-8 so that we can move on - cause this will usually give us most of what we need...\r
+                       if ($charset === false)\r
+                       {\r
+                               if (is_object($debug_object)) {$debug_object->debug_log(2, 'since mb_detect failed - using default of utf-8');}\r
+                               $charset = 'UTF-8';\r
+                       }\r
+               }\r
+\r
+               // Since CP1252 is a superset, if we get one of it's subsets, we want it instead.\r
+               if ((strtolower($charset) == strtolower('ISO-8859-1')) || (strtolower($charset) == strtolower('Latin1')) || (strtolower($charset) == strtolower('Latin-1')))\r
+               {\r
+                       if (is_object($debug_object)) {$debug_object->debug_log(2, 'replacing ' . $charset . ' with CP1252 as its a superset');}\r
+                       $charset = 'CP1252';\r
+               }\r
+\r
+               if (is_object($debug_object)) {$debug_object->debug_log(1, 'EXIT - ' . $charset);}\r
+\r
+               return $this->_charset = $charset;\r
+       }\r
+\r
+       // read tag info\r
+       protected function read_tag()\r
+       {\r
+               if ($this->char!=='<')\r
+               {\r
+                       $this->root->_[HDOM_INFO_END] = $this->cursor;\r
+                       return false;\r
+               }\r
+               $begin_tag_pos = $this->pos;\r
+               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+\r
+               // end tag\r
+               if ($this->char==='/')\r
+               {\r
+                       $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                       // This represents the change in the simple_html_dom trunk from revision 180 to 181.\r
+                       // $this->skip($this->token_blank_t);\r
+                       $this->skip($this->token_blank);\r
+                       $tag = $this->copy_until_char('>');\r
+\r
+                       // skip attributes in end tag\r
+                       if (($pos = strpos($tag, ' '))!==false)\r
+                               $tag = substr($tag, 0, $pos);\r
+\r
+                       $parent_lower = strtolower($this->parent->tag);\r
+                       $tag_lower = strtolower($tag);\r
+\r
+                       if ($parent_lower!==$tag_lower)\r
+                       {\r
+                               if (isset($this->optional_closing_tags[$parent_lower]) && isset($this->block_tags[$tag_lower]))\r
+                               {\r
+                                       $this->parent->_[HDOM_INFO_END] = 0;\r
+                                       $org_parent = $this->parent;\r
+\r
+                                       while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)\r
+                                               $this->parent = $this->parent->parent;\r
+\r
+                                       if (strtolower($this->parent->tag)!==$tag_lower) {\r
+                                               $this->parent = $org_parent; // restore origonal parent\r
+                                               if ($this->parent->parent) $this->parent = $this->parent->parent;\r
+                                               $this->parent->_[HDOM_INFO_END] = $this->cursor;\r
+                                               return $this->as_text_node($tag);\r
+                                       }\r
+                               }\r
+                               else if (($this->parent->parent) && isset($this->block_tags[$tag_lower]))\r
+                               {\r
+                                       $this->parent->_[HDOM_INFO_END] = 0;\r
+                                       $org_parent = $this->parent;\r
+\r
+                                       while (($this->parent->parent) && strtolower($this->parent->tag)!==$tag_lower)\r
+                                               $this->parent = $this->parent->parent;\r
+\r
+                                       if (strtolower($this->parent->tag)!==$tag_lower)\r
+                                       {\r
+                                               $this->parent = $org_parent; // restore origonal parent\r
+                                               $this->parent->_[HDOM_INFO_END] = $this->cursor;\r
+                                               return $this->as_text_node($tag);\r
+                                       }\r
+                               }\r
+                               else if (($this->parent->parent) && strtolower($this->parent->parent->tag)===$tag_lower)\r
+                               {\r
+                                       $this->parent->_[HDOM_INFO_END] = 0;\r
+                                       $this->parent = $this->parent->parent;\r
+                               }\r
+                               else\r
+                                       return $this->as_text_node($tag);\r
+                       }\r
+\r
+                       $this->parent->_[HDOM_INFO_END] = $this->cursor;\r
+                       if ($this->parent->parent) $this->parent = $this->parent->parent;\r
+\r
+                       $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                       return true;\r
+               }\r
+\r
+               $node = new simple_html_dom_node($this);\r
+               $node->_[HDOM_INFO_BEGIN] = $this->cursor;\r
+               ++$this->cursor;\r
+               $tag = $this->copy_until($this->token_slash);\r
+               $node->tag_start = $begin_tag_pos;\r
+\r
+               // doctype, cdata & comments...\r
+               if (isset($tag[0]) && $tag[0]==='!') {\r
+                       $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until_char('>');\r
+\r
+                       if (isset($tag[2]) && $tag[1]==='-' && $tag[2]==='-') {\r
+                               $node->nodetype = HDOM_TYPE_COMMENT;\r
+                               $node->tag = 'comment';\r
+                       } else {\r
+                               $node->nodetype = HDOM_TYPE_UNKNOWN;\r
+                               $node->tag = 'unknown';\r
+                       }\r
+                       if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';\r
+                       $this->link_nodes($node, true);\r
+                       $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                       return true;\r
+               }\r
+\r
+               // text\r
+               if ($pos=strpos($tag, '<')!==false) {\r
+                       $tag = '<' . substr($tag, 0, -1);\r
+                       $node->_[HDOM_INFO_TEXT] = $tag;\r
+                       $this->link_nodes($node, false);\r
+                       $this->char = $this->doc[--$this->pos]; // prev\r
+                       return true;\r
+               }\r
+\r
+               if (!preg_match("/^[\w-:]+$/", $tag)) {\r
+                       $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');\r
+                       if ($this->char==='<') {\r
+                               $this->link_nodes($node, false);\r
+                               return true;\r
+                       }\r
+\r
+                       if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';\r
+                       $this->link_nodes($node, false);\r
+                       $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                       return true;\r
+               }\r
+\r
+               // begin tag\r
+               $node->nodetype = HDOM_TYPE_ELEMENT;\r
+               $tag_lower = strtolower($tag);\r
+               $node->tag = ($this->lowercase) ? $tag_lower : $tag;\r
+\r
+               // handle optional closing tags\r
+               if (isset($this->optional_closing_tags[$tag_lower]) )\r
+               {\r
+                       while (isset($this->optional_closing_tags[$tag_lower][strtolower($this->parent->tag)]))\r
+                       {\r
+                               $this->parent->_[HDOM_INFO_END] = 0;\r
+                               $this->parent = $this->parent->parent;\r
+                       }\r
+                       $node->parent = $this->parent;\r
+               }\r
+\r
+               $guard = 0; // prevent infinity loop\r
+               $space = array($this->copy_skip($this->token_blank), '', '');\r
+\r
+               // attributes\r
+               do\r
+               {\r
+                       if ($this->char!==null && $space[0]==='')\r
+                       {\r
+                               break;\r
+                       }\r
+                       $name = $this->copy_until($this->token_equal);\r
+                       if ($guard===$this->pos)\r
+                       {\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               continue;\r
+                       }\r
+                       $guard = $this->pos;\r
+\r
+                       // handle endless '<'\r
+                       if ($this->pos>=$this->size-1 && $this->char!=='>') {\r
+                               $node->nodetype = HDOM_TYPE_TEXT;\r
+                               $node->_[HDOM_INFO_END] = 0;\r
+                               $node->_[HDOM_INFO_TEXT] = '<'.$tag . $space[0] . $name;\r
+                               $node->tag = 'text';\r
+                               $this->link_nodes($node, false);\r
+                               return true;\r
+                       }\r
+\r
+                       // handle mismatch '<'\r
+                       if ($this->doc[$this->pos-1]=='<') {\r
+                               $node->nodetype = HDOM_TYPE_TEXT;\r
+                               $node->tag = 'text';\r
+                               $node->attr = array();\r
+                               $node->_[HDOM_INFO_END] = 0;\r
+                               $node->_[HDOM_INFO_TEXT] = substr($this->doc, $begin_tag_pos, $this->pos-$begin_tag_pos-1);\r
+                               $this->pos -= 2;\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               $this->link_nodes($node, false);\r
+                               return true;\r
+                       }\r
+\r
+                       if ($name!=='/' && $name!=='') {\r
+                               $space[1] = $this->copy_skip($this->token_blank);\r
+                               $name = $this->restore_noise($name);\r
+                               if ($this->lowercase) $name = strtolower($name);\r
+                               if ($this->char==='=') {\r
+                                       $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                                       $this->parse_attr($node, $name, $space);\r
+                               }\r
+                               else {\r
+                                       //no value attr: nowrap, checked selected...\r
+                                       $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;\r
+                                       $node->attr[$name] = true;\r
+                                       if ($this->char!='>') $this->char = $this->doc[--$this->pos]; // prev\r
+                               }\r
+                               $node->_[HDOM_INFO_SPACE][] = $space;\r
+                               $space = array($this->copy_skip($this->token_blank), '', '');\r
+                       }\r
+                       else\r
+                               break;\r
+               } while ($this->char!=='>' && $this->char!=='/');\r
+\r
+               $this->link_nodes($node, true);\r
+               $node->_[HDOM_INFO_ENDSPACE] = $space[0];\r
+\r
+               // check self closing\r
+               if ($this->copy_until_char_escape('>')==='/')\r
+               {\r
+                       $node->_[HDOM_INFO_ENDSPACE] .= '/';\r
+                       $node->_[HDOM_INFO_END] = 0;\r
+               }\r
+               else\r
+               {\r
+                       // reset parent\r
+                       if (!isset($this->self_closing_tags[strtolower($node->tag)])) $this->parent = $node;\r
+               }\r
+               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+\r
+               // If it's a BR tag, we need to set it's text to the default text.\r
+               // This way when we see it in plaintext, we can generate formatting that the user wants.\r
+               // since a br tag never has sub nodes, this works well.\r
+               if ($node->tag == "br")\r
+               {\r
+                       $node->_[HDOM_INFO_INNER] = $this->default_br_text;\r
+               }\r
+\r
+               return true;\r
+       }\r
+\r
+       // parse attributes\r
+       protected function parse_attr($node, $name, &$space)\r
+       {\r
+               // Per sourceforge: http://sourceforge.net/tracker/?func=detail&aid=3061408&group_id=218559&atid=1044037\r
+               // If the attribute is already defined inside a tag, only pay atetntion to the first one as opposed to the last one.\r
+               if (isset($node->attr[$name]))\r
+               {\r
+                       return;\r
+               }\r
+\r
+               $space[2] = $this->copy_skip($this->token_blank);\r
+               switch ($this->char) {\r
+                       case '"':\r
+                               $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('"'));\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               break;\r
+                       case '\'':\r
+                               $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_SINGLE;\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               $node->attr[$name] = $this->restore_noise($this->copy_until_char_escape('\''));\r
+                               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+                               break;\r
+                       default:\r
+                               $node->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_NO;\r
+                               $node->attr[$name] = $this->restore_noise($this->copy_until($this->token_attr));\r
+               }\r
+               // PaperG: Attributes should not have \r or \n in them, that counts as html whitespace.\r
+               $node->attr[$name] = str_replace("\r", "", $node->attr[$name]);\r
+               $node->attr[$name] = str_replace("\n", "", $node->attr[$name]);\r
+               // PaperG: If this is a "class" selector, lets get rid of the preceeding and trailing space since some people leave it in the multi class case.\r
+               if ($name == "class") {\r
+                       $node->attr[$name] = trim($node->attr[$name]);\r
+               }\r
+       }\r
+\r
+       // link node's parent\r
+       protected function link_nodes(&$node, $is_child)\r
+       {\r
+               $node->parent = $this->parent;\r
+               $this->parent->nodes[] = $node;\r
+               if ($is_child)\r
+               {\r
+                       $this->parent->children[] = $node;\r
+               }\r
+       }\r
+\r
+       // as a text node\r
+       protected function as_text_node($tag)\r
+       {\r
+               $node = new simple_html_dom_node($this);\r
+               ++$this->cursor;\r
+               $node->_[HDOM_INFO_TEXT] = '</' . $tag . '>';\r
+               $this->link_nodes($node, false);\r
+               $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+               return true;\r
+       }\r
+\r
+       protected function skip($chars)\r
+       {\r
+               $this->pos += strspn($this->doc, $chars, $this->pos);\r
+               $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+       }\r
+\r
+       protected function copy_skip($chars)\r
+       {\r
+               $pos = $this->pos;\r
+               $len = strspn($this->doc, $chars, $pos);\r
+               $this->pos += $len;\r
+               $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+               if ($len===0) return '';\r
+               return substr($this->doc, $pos, $len);\r
+       }\r
+\r
+       protected function copy_until($chars)\r
+       {\r
+               $pos = $this->pos;\r
+               $len = strcspn($this->doc, $chars, $pos);\r
+               $this->pos += $len;\r
+               $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next\r
+               return substr($this->doc, $pos, $len);\r
+       }\r
+\r
+       protected function copy_until_char($char)\r
+       {\r
+               if ($this->char===null) return '';\r
+\r
+               if (($pos = strpos($this->doc, $char, $this->pos))===false) {\r
+                       $ret = substr($this->doc, $this->pos, $this->size-$this->pos);\r
+                       $this->char = null;\r
+                       $this->pos = $this->size;\r
+                       return $ret;\r
+               }\r
+\r
+               if ($pos===$this->pos) return '';\r
+               $pos_old = $this->pos;\r
+               $this->char = $this->doc[$pos];\r
+               $this->pos = $pos;\r
+               return substr($this->doc, $pos_old, $pos-$pos_old);\r
+       }\r
+\r
+       protected function copy_until_char_escape($char)\r
+       {\r
+               if ($this->char===null) return '';\r
+\r
+               $start = $this->pos;\r
+               while (1)\r
+               {\r
+                       if (($pos = strpos($this->doc, $char, $start))===false)\r
+                       {\r
+                               $ret = substr($this->doc, $this->pos, $this->size-$this->pos);\r
+                               $this->char = null;\r
+                               $this->pos = $this->size;\r
+                               return $ret;\r
+                       }\r
+\r
+                       if ($pos===$this->pos) return '';\r
+\r
+                       if ($this->doc[$pos-1]==='\\') {\r
+                               $start = $pos+1;\r
+                               continue;\r
+                       }\r
+\r
+                       $pos_old = $this->pos;\r
+                       $this->char = $this->doc[$pos];\r
+                       $this->pos = $pos;\r
+                       return substr($this->doc, $pos_old, $pos-$pos_old);\r
+               }\r
+       }\r
+\r
+       // remove noise from html content\r
+       // save the noise in the $this->noise array.\r
+       protected function remove_noise($pattern, $remove_tag=false)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }\r
+\r
+               $count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);\r
+\r
+               for ($i=$count-1; $i>-1; --$i)\r
+               {\r
+                       $key = '___noise___'.sprintf('% 5d', count($this->noise)+1000);\r
+                       if (is_object($debug_object)) { $debug_object->debug_log(2, 'key is: ' . $key); }\r
+                       $idx = ($remove_tag) ? 0 : 1;\r
+                       $this->noise[$key] = $matches[$i][$idx][0];\r
+                       $this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));\r
+               }\r
+\r
+               // reset the length of content\r
+               $this->size = strlen($this->doc);\r
+               if ($this->size>0)\r
+               {\r
+                       $this->char = $this->doc[0];\r
+               }\r
+       }\r
+\r
+       // restore noise to html content\r
+       function restore_noise($text)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }\r
+\r
+               while (($pos=strpos($text, '___noise___'))!==false)\r
+               {\r
+                       // Sometimes there is a broken piece of markup, and we don't GET the pos+11 etc... token which indicates a problem outside of us...\r
+                       if (strlen($text) > $pos+15)\r
+                       {\r
+                               $key = '___noise___'.$text[$pos+11].$text[$pos+12].$text[$pos+13].$text[$pos+14].$text[$pos+15];\r
+                               if (is_object($debug_object)) { $debug_object->debug_log(2, 'located key of: ' . $key); }\r
+\r
+                               if (isset($this->noise[$key]))\r
+                               {\r
+                                       $text = substr($text, 0, $pos).$this->noise[$key].substr($text, $pos+16);\r
+                               }\r
+                               else\r
+                               {\r
+                                       // do this to prevent an infinite loop.\r
+                                       $text = substr($text, 0, $pos).'UNDEFINED NOISE FOR KEY: '.$key . substr($text, $pos+16);\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               // There is no valid key being given back to us... We must get rid of the ___noise___ or we will have a problem.\r
+                               $text = substr($text, 0, $pos).'NO NUMERIC NOISE KEY' . substr($text, $pos+11);\r
+                       }\r
+               }\r
+               return $text;\r
+       }\r
+\r
+       // Sometimes we NEED one of the noise elements.\r
+       function search_noise($text)\r
+       {\r
+               global $debug_object;\r
+               if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }\r
+\r
+               foreach($this->noise as $noiseElement)\r
+               {\r
+                       if (strpos($noiseElement, $text)!==false)\r
+                       {\r
+                               return $noiseElement;\r
+                       }\r
+               }\r
+       }\r
+       function __toString()\r
+       {\r
+               return $this->root->innertext();\r
+       }\r
+\r
+       function __get($name)\r
+       {\r
+               switch ($name)\r
+               {\r
+                       case 'outertext':\r
+                               return $this->root->innertext();\r
+                       case 'innertext':\r
+                               return $this->root->innertext();\r
+                       case 'plaintext':\r
+                               return $this->root->text();\r
+                       case 'charset':\r
+                               return $this->_charset;\r
+                       case 'target_charset':\r
+                               return $this->_target_charset;\r
+               }\r
+       }\r
+\r
+       // camel naming conventions\r
+       function childNodes($idx=-1) {return $this->root->childNodes($idx);}\r
+       function firstChild() {return $this->root->first_child();}\r
+       function lastChild() {return $this->root->last_child();}\r
+       function createElement($name, $value=null) {return @str_get_html("<$name>$value</$name>")->first_child();}\r
+       function createTextNode($value) {return @end(str_get_html($value)->nodes);}\r
+       function getElementById($id) {return $this->find("#$id", 0);}\r
+       function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);}\r
+       function getElementByTagName($name) {return $this->find($name, 0);}\r
+       function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);}\r
+       function loadFile() {$args = func_get_args();$this->load_file($args);}\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/ext_emconf.php b/ext_emconf.php
new file mode 100644 (file)
index 0000000..76ce7f3
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+/***************************************************************
+ * Extension Manager/Repository config file for ext "store_url".
+ *
+ * Auto generated 11-09-2014 15:07
+ *
+ * Manual updates:
+ * Only the data in the array - everything else is removed by next
+ * writing. "version" and "dependencies" must not be touched!
+ ***************************************************************/
+
+$EM_CONF[$_EXTKEY] = array (
+       'title' => 'StoreUrl',
+       'description' => 'Stores the contents of a URL in a HTML content element',
+       'category' => 'services',
+       'state' => 'beta',
+       'uploadfolder' => 0,
+       'createDirs' => '',
+       'clearCacheOnLoad' => 0,
+       'author' => 'Daniel Minder',
+       'author_email' => 'typo3@minder.de',
+       'author_company' => '',
+       'version' => '0.1.2',
+       '_md5_values_when_last_written' => '',
+       'constraints' => 
+       array (
+               'depends' => 
+               array (
+                       'typo3' => '6.1.0-6.2.99',
+               ),
+               'conflicts' => 
+               array (
+               ),
+               'suggests' => 
+               array (
+               ),
+       ),
+);
+
diff --git a/ext_icon.gif b/ext_icon.gif
new file mode 100644 (file)
index 0000000..b993e8a
Binary files /dev/null and b/ext_icon.gif differ
diff --git a/ext_localconf.php b/ext_localconf.php
new file mode 100644 (file)
index 0000000..9909c64
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+if (!defined ('TYPO3_MODE')) die ('Access denied.');
+
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['DANNYM\\StoreUrl\\Task\\StoreTask'] = array(
+       'extension'        => $_EXTKEY,
+       'title'            => 'URL abspeichern',
+       'description'      => 'Dieser Task speichert eine gegebene URL in ein HTML Content Element ab.',
+       'additionalFields' => 'DANNYM\\StoreUrl\\Task\\StoreTaskAdditionalFieldProvider'
+);
+?>
diff --git a/ext_tables.php b/ext_tables.php
new file mode 100644 (file)
index 0000000..3b89b1e
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+if (!defined('TYPO3_MODE')) {
+        die('Access denied.');
+}
+?>