DOMXPath PHP Class Code Examples

This page contains top rated real world PHP examples of class DOMXPath extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: RSSFeedTest.php Project: luisbrito/Phraseanet
1
 public function checkATOMRootNode(\DOMDocument $dom_doc, \DOMXPath $xpath, Feed $feed)
 {
     $ids = $xpath->query('/Atom:feed/Atom:id');
     $this->assertEquals(self::$DI['app']['feed.user-link-generator']->generatePublic($feed, 'atom', 1)->getURI(), $ids->item(0)->nodeValue);
     $titles = $xpath->query('/Atom:feed/Atom:title');
     $this->assertEquals($feed->getTitle(), $titles->item(0)->nodeValue);
     $subtitles = $xpath->query('/Atom:feed/Atom:subtitle');
     if ($subtitles->length > 0) {
         $this->assertEquals($feed->getSubtitle(), $subtitles->item(0)->nodeValue);
     }
     $updateds = $xpath->query('/Atom:feed/Atom:updated');
     $this->assertTrue(new \DateTime() >= new \DateTime($updateds->item(0)->nodeValue));
     $entries_item = $xpath->query('/Atom:feed/Atom:entry');
     $count = 0;
     $offset_start = 0;
     $n_entries = 20;
     $entries = $feed->getEntries()->slice($offset_start, $n_entries);
     foreach ($entries_item as $entry) {
         if (sizeof($entries) == 0) {
             $offset_start += $n_entries;
             $entries = $feed->getEntries()->slice($offset_start, $n_entries);
             if (sizeof($entries) == 0) {
                 //no more
                 break;
             }
         }
         $feed_entry = array_shift($entries);
         $this->checkATOMEntryNode($entry, $xpath, $feed, $feed_entry);
         $count++;
     }
     $this->assertEquals($feed->getCountTotalEntries(), $count);
 }
Example #2
Show file File: odt2pdf.php Project: Nikitian/fl-ru-damp
1
 /**
  * Парсим структуру данных шаблона, обрабатываем условия, заменяем все переменные на значения
  * 
  * @param string $content     Данные из шаблона (файл self::$content_file)
  * @param array  $variables   Переменные формата array('$name' => 'Название')
  * @return string
  */
 public function parseStructure($content, $variables)
 {
     list($keys, $vals) = $this->prepareVariables($variables);
     $content = $this->clearDataVar($content);
     $condition_keys = $this->prepareConditionsVar($variables);
     $dom = new DOMDocument('1.0');
     $dom->loadXML($content);
     $xpath = new DOMXPath($dom);
     foreach ($condition_keys as $key => $condition) {
         if (!is_bool($vals[$key])) {
             continue;
         }
         if ($vals[$key] == false) {
             $find = '//text:p[@text:style-name= "' . $condition . '"]';
             $element = $xpath->query($find, $dom->documentElement);
             if ($element->length > 0) {
                 for ($i = 0; $i < $element->length; $i++) {
                     $remove_element[] = $element->item($i);
                 }
             }
         }
     }
     if ($remove_element) {
         foreach ($remove_element as $element) {
             $parent = $element->parentNode;
             $parent->removeChild($element);
         }
         $content = $dom->saveXML();
     }
     $content = str_replace($keys, $vals, $content);
     return $this->clearEmptyVariables($content);
 }
Example #3
Show file File: class.ilPCFileList.php Project: arlendotcn/ilias
0
 /**
  * Get all file items that are used within the page
  */
 static function collectFileItems($a_page, $a_domdoc)
 {
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//FileItem/Identifier');
     $file_ids = array();
     foreach ($nodes as $node) {
         $id_arr = explode("_", $node->getAttribute("Entry"));
         $file_id = $id_arr[count($id_arr) - 1];
         if ($file_id > 0 && ($id_arr[1] == "" || $id_arr[1] == IL_INST_ID || $id_arr[1] == 0)) {
             $file_ids[$file_id] = $file_id;
         }
     }
     // file items in download links
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query("//IntLink[@Type='File']");
     foreach ($nodes as $node) {
         $t = $node->getAttribute("Target");
         if (substr($t, 0, 9) == "il__dfile") {
             $id_arr = explode("_", $t);
             $file_id = $id_arr[count($id_arr) - 1];
             $file_ids[$file_id] = $file_id;
         }
     }
     return $file_ids;
 }
Example #4
Show file File: rstxml.php Project: jordanmanning/ezpublish
0
 /**
  * Extracts information from the file $fileName associated with the url $url.
  *
  * The document type for this document is given in $type, and the images on
  * disk should be in the directory named $imagePath. The urls where the
  * images link to should be in $imageUrlPath.
  *
  * @param string $fileName
  * @param string $type
  * @param string $url
  * @param string $imagePath
  * @param string $imageUrlPath
  * @return array(ezcSearchDocument)
  */
 public static function extract($fileName, $type, $url, $imagePath = null, $imageUrlPath = null)
 {
     $published = filemtime($fileName);
     $converted = file_get_contents($fileName);
     $dom = new DomDocument();
     @$dom->loadHtml($converted);
     $tbody = $dom->getElementsByTagName('div')->item(0);
     $xpath = new DOMXPath($dom);
     $tocElem = $xpath->evaluate("//h1[@class='title']", $tbody)->item(0);
     $title = $tocElem ? $tocElem->nodeValue : 'no title';
     $docs = array();
     $body = $urls = array();
     $currentUrl = $url;
     $lastUrl = $url;
     $currentBody = '';
     // child::*[self::p or self::h1]
     $xpath = new DOMXPath($dom);
     $tbody = $xpath->evaluate("//p|//h1|//ol|//ul|//dl|//img|//a", $tbody);
     $body = '';
     foreach ($tbody as $item) {
         switch ($item->tagName) {
             case 'a':
                 $name = $item->getAttribute('name');
                 if (strlen($name)) {
                     $currentUrl = $url . '#' . $name;
                 }
                 break;
             case 'img':
                 $alt = $item->getAttribute('alt');
                 $src = $item->getAttribute('src');
                 $location = $imagePath == null ? dirname($fileName) . '/' . $src : $imagePath . '/' . preg_replace('@(\\.\\./)+@', '', $src);
                 $imgurl = $src[0] == '/' ? $src : ($imageUrlPath === null ? $url . '/' . $src : $imageUrlPath . '/' . preg_replace('@(\\.\\./)+@', '', $src));
                 echo "  - {$src} => {$imgurl}\n";
                 $docs[] = self::extractImage($alt, $location, $imgurl);
                 break;
             case 'p':
             case 'h1':
             case 'dl':
                 if ($lastUrl !== $currentUrl) {
                     $docs[] = new ezcSearchSimpleArticle(null, $title, $currentBody, $published, $lastUrl, $type);
                     $currentBody = '';
                     $lastUrl = $currentUrl;
                 }
                 $currentBody .= strip_tags($dom->saveXml($item)) . "\n\n";
                 break;
         }
     }
     if ($currentBody != '') {
         $docs[] = new ezcSearchSimpleArticle(null, $title, $currentBody, $published, $lastUrl, $type);
     }
     return $docs;
 }
Example #5
Show file File: Rss.php Project: yakamoz-fang/concrete
0
 /**
  * Set the XPath query (incl. on all Extensions)
  *
  * @param DOMXPath $xpath
  * @return void
  */
 public function setXpath(DOMXPath $xpath)
 {
     parent::setXpath($xpath);
     foreach ($this->extensions as $extension) {
         $extension->setXpath($this->xpath);
     }
 }
Example #6
Show file File: rssfuncs.php Project: cs-team/tiny_tiny_rss-openshift-quickstart
0
function cache_images($html, $site_url, $debug)
{
    $cache_dir = CACHE_DIR . "/images";
    libxml_use_internal_errors(true);
    $charset_hack = '<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		</head>';
    $doc = new DOMDocument();
    $doc->loadHTML($charset_hack . $html);
    $xpath = new DOMXPath($doc);
    $entries = $xpath->query('(//img[@src])');
    foreach ($entries as $entry) {
        if ($entry->hasAttribute('src')) {
            $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
            $local_filename = CACHE_DIR . "/images/" . sha1($src) . ".png";
            if ($debug) {
                _debug("cache_images: downloading: {$src} to {$local_filename}");
            }
            if (!file_exists($local_filename)) {
                $file_content = fetch_file_contents($src);
                if ($file_content && strlen($file_content) > 1024) {
                    file_put_contents($local_filename, $file_content);
                }
            }
            if (file_exists($local_filename)) {
                $entry->setAttribute('src', SELF_URL_PATH . '/image.php?url=' . base64_encode($src));
            }
        }
    }
    $node = $doc->getElementsByTagName('body')->item(0);
    return $doc->saveXML($node);
}
Example #7
Show file File: Author.php Project: Simarpreet05/joomla
0
 /**
  * Constructs a new object from DOM Element.
  *
  * @param   DomElement $dom the ReST fragment for this object
  */
 public function __construct(DomElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $result = $xpath->query('./firstname/text()', $dom);
     if ($result->length == 1) {
         $this->setFirstName($result->item(0)->data);
     }
     $result = $xpath->query('./lastname/text()', $dom);
     if ($result->length == 1) {
         $this->setLastName($result->item(0)->data);
     }
     $result = $xpath->query('./username/text()', $dom);
     if ($result->length == 1) {
         $this->setUsername($result->item(0)->data);
     }
     $result = $xpath->query('./description/text()', $dom);
     if ($result->length == 1) {
         $this->setDescription($result->item(0)->data);
     }
     $result = $xpath->query('./bio/text()', $dom);
     if ($result->length == 1) {
         $this->setBio($result->item(0)->data);
     }
     $result = $xpath->query('./thumbnailpicture/text()', $dom);
     if ($result->length == 1) {
         $this->setThumbnailPicture($result->item(0)->data);
     }
 }
Example #8
Show file File: class.ilPCMediaObject.php Project: arlendotcn/ilias
0
 /**
  * Save all usages of media objects (media aliases, media objects, internal links)
  *
  * @param	string		$a_xml		xml data of page
  */
 static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
 {
     $usages = array();
     // media aliases
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//MediaAlias');
     foreach ($nodes as $node) {
         $id_arr = explode("_", $node->getAttribute("OriginId"));
         $mob_id = $id_arr[count($id_arr) - 1];
         if ($mob_id > 0 && $id_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     // media objects
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
     foreach ($nodes as $node) {
         $mob_entry = $node->getAttribute("Entry");
         $mob_arr = explode("_", $mob_entry);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0 && $mob_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     // internal links
     $xpath = new DOMXPath($a_domdoc);
     $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
     foreach ($nodes as $node) {
         $mob_target = $node->getAttribute("Target");
         $mob_arr = explode("_", $mob_target);
         //echo "<br>3<br>";
         //echo $mob_target."<br>";
         //var_dump($mob_arr);
         $mob_id = $mob_arr[count($mob_arr) - 1];
         if ($mob_id > 0 && $mob_arr[1] == "") {
             $usages[$mob_id] = true;
         }
     }
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     ilObjMediaObject::_deleteAllUsages($a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
     foreach ($usages as $mob_id => $val) {
         // save usage, if object exists...
         if (ilObject::_lookupType($mob_id) == "mob") {
             ilObjMediaObject::_saveUsage($mob_id, $a_page->getParentType() . ":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
         }
     }
     return $usages;
 }
Example #9
Show file File: init.php Project: Verisor/tt-rss
0
 function process_article($article)
 {
     if (!class_exists("Readability")) {
         require_once dirname(dirname(__DIR__)) . "/lib/readability/Readability.php";
     }
     if (function_exists("curl_init")) {
         $ch = curl_init($article["link"]);
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_NOBODY, true);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir"));
         curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
         @($result = curl_exec($ch));
         $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
         if (strpos($content_type, "text/html") === FALSE) {
             return $article;
         }
     }
     $tmp = fetch_file_contents($article["link"]);
     if ($tmp) {
         $tmpdoc = new DOMDocument("1.0", "UTF-8");
         if (!$tmpdoc->loadHTML($tmp)) {
             return $article;
         }
         if (strtolower($tmpdoc->encoding) != 'utf-8') {
             $tmpxpath = new DOMXPath($tmpdoc);
             foreach ($tmpxpath->query("//meta") as $elem) {
                 $elem->parentNode->removeChild($elem);
             }
             $tmp = $tmpdoc->saveHTML();
         }
         $r = new Readability($tmp, $article["link"]);
         if ($r->init()) {
             $tmpxpath = new DOMXPath($r->dom);
             $entries = $tmpxpath->query('(//a[@href]|//img[@src])');
             foreach ($entries as $entry) {
                 if ($entry->hasAttribute("href")) {
                     $entry->setAttribute("href", rewrite_relative_url($article["link"], $entry->getAttribute("href")));
                 }
                 if ($entry->hasAttribute("src")) {
                     $entry->setAttribute("src", rewrite_relative_url($article["link"], $entry->getAttribute("src")));
                 }
             }
             $article["content"] = $r->articleContent->innerHTML;
         }
     }
     return $article;
 }
Example #10
Show file File: HasXPath.php Project: zhangjingli35/hamcrest
0
 /**
  * Applies the configurd XPath to the DOM node and returns either
  * the result if it's an expression or the node list if it's a query.
  *
  * @param DOMNode $node context from which to issue query
  * @return mixed result of expression or DOMNodeList from query
  */
 protected function evaluate(DOMNode $node)
 {
     if ($node instanceof DOMDocument) {
         $xpathDocument = new DOMXPath($node);
         return $xpathDocument->evaluate($this->_xpath);
     } else {
         $xpathDocument = new DOMXPath($node->ownerDocument);
         return $xpathDocument->evaluate($this->_xpath, $node);
     }
 }
Example #11
Show file File: Functions.php Project: awflu/YetiForceCRM
0
 static function removeHtmlTags(array $tags, $html)
 {
     $crmUrl = vglobal($key);
     $doc = new DOMDocument('1.0', 'UTF-8');
     $previousValue = libxml_use_internal_errors(TRUE);
     $doc->loadHTML('<?xml encoding="utf-8" ?>' . $html);
     libxml_clear_errors();
     libxml_use_internal_errors($previousValue);
     foreach ($tags as $tag) {
         $xPath = new DOMXPath($doc);
         $nodes = $xPath->query('//' . $tag);
         for ($i = 0; $i < $nodes->length; $i++) {
             if ('img' === $tag) {
                 $htmlNode = $nodes->item($i)->ownerDocument->saveHTML($nodes->item($i));
                 $imgDom = new DOMDocument();
                 $imgDom->loadHTML($htmlNode);
                 $xpath = new DOMXPath($imgDom);
                 $src = $xpath->evaluate("string(//img/@src)");
                 if ($src == '' || 0 !== strpos('index.php', $src) || FALSE === strpos($crmUrl, $src)) {
                     $nodes->item($i)->parentNode->removeChild($nodes->item($i));
                 }
             } else {
                 $nodes->item($i)->parentNode->removeChild($nodes->item($i));
             }
         }
     }
     $savedHTML = $doc->saveHTML();
     $savedHTML = preg_replace('/<html[^>]+\\>/', '', $savedHTML);
     $savedHTML = preg_replace('/<body[^>]+\\>/', '', $savedHTML);
     $savedHTML = preg_replace('#<head(.*?)>(.*?)</head>#is', '', $savedHTML);
     $savedHTML = preg_replace('/<!--(.*)-->/Uis', '', $savedHTML);
     $savedHTML = str_replace(['</html>', '</body>', '<?xml encoding="utf-8" ?>'], ['', '', ''], $savedHTML);
     return $savedHTML;
 }
Example #12
Show file File: ts_backend.php Project: jordanmanning/ezpublish
0
 /**
  * Stores a context.
  *
  * This method stores the context that it received to the backend specified
  * storage place.
  *
  * @throws ezcTranslationWriterNotInitializedException when the writer is
  *         not initialized with initWriter().
  * @param string $context The context's name
  * @param array(ezcTranslationData)  $data The context's translation map
  * @return void
  */
 public function storeContext($context, array $data)
 {
     if (is_null($this->dom)) {
         throw new ezcTranslationWriterNotInitializedException();
     }
     $dom = $this->dom;
     $root = $dom->getElementsByTagName('TS')->item(0);
     // find the context element
     $xpath = new DOMXPath($dom);
     $result = $xpath->query('//context/name[text()="' . htmlspecialchars($context) . '"]');
     // If the context does not exist, we create a node for it; otherwise we just use it.
     if (!$result->length) {
         $contextNode = $dom->createElement('context');
         $nameNode = $dom->createElement('name', htmlspecialchars($context));
         $contextNode->appendChild($nameNode);
         $root->appendChild($contextNode);
     } else {
         $contextNode = $result->item(0)->parentNode;
     }
     // for every entry, we add a new message
     foreach ($data as $info) {
         // check if the string is already there, if so, remove it first
         $xpath = new DOMXPath($dom);
         $xpathString = str_replace('"', '",\'"\',"', $info->original);
         $result = $xpath->query('message/source[text()=concat("' . $xpathString . '","")]', $contextNode);
         if ($result->length) {
             $node = $result->item(0)->parentNode;
             $contextNode->removeChild($node);
         }
         // create the new element
         $message = $dom->createElement('message');
         $source = $dom->createElement('source', htmlspecialchars($info->original));
         $message->appendChild($source);
         $translation = $dom->createElement('translation', htmlspecialchars($info->translation));
         switch ($info->status) {
             case ezcTranslationData::UNFINISHED:
                 $translation->setAttribute('type', 'unfinished');
                 break;
             case ezcTranslationData::OBSOLETE:
                 $translation->setAttribute('type', 'obsolete');
                 break;
         }
         $message->appendChild($translation);
         if ($info->comment) {
             $comment = $dom->createElement('comment', htmlspecialchars($info->comment));
             $message->appendChild($comment);
         }
         if ($info->filename && $info->line) {
             $location = $dom->createElement('location');
             $location->setAttribute('filename', $info->filename);
             $location->setAttribute('line', $info->line);
             $message->appendChild($location);
         }
         $contextNode->appendChild($message);
     }
 }
Example #13
Show file File: init.php Project: cs-team/tiny_tiny_rss-openshift-quickstart
0
 function hook_article_filter($article)
 {
     $owner_uid = $article["owner_uid"];
     if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
         if (strpos($article["plugin_data"], "pennyarcade,{$owner_uid}:") === FALSE) {
             if ($debug_enabled) {
                 _debug("af_pennyarcade: Processing comic");
             }
             $doc = new DOMDocument();
             $doc->loadHTML(fetch_file_contents($article["link"]));
             $basenode = false;
             if ($doc) {
                 $xpath = new DOMXPath($doc);
                 $entries = $xpath->query('(//div[@class="post comic"])');
                 foreach ($entries as $entry) {
                     $basenode = $entry;
                 }
                 if ($basenode) {
                     $article["content"] = $doc->saveXML($basenode);
                     $article["plugin_data"] = "pennyarcade,{$owner_uid}:" . $article["plugin_data"];
                 }
             }
         } else {
             if (isset($article["stored"]["content"])) {
                 $article["content"] = $article["stored"]["content"];
             }
         }
     }
     if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
         if (strpos($article["plugin_data"], "pennyarcade,{$owner_uid}:") === FALSE) {
             if ($debug_enabled) {
                 _debug("af_pennyarcade: Processing news post");
             }
             $doc = new DOMDocument();
             $doc->loadHTML(fetch_file_contents($article["link"]));
             if ($doc) {
                 $xpath = new DOMXPath($doc);
                 $entries = $xpath->query('(//div[@class="post"])');
                 $basenode = false;
                 foreach ($entries as $entry) {
                     $basenode = $entry;
                 }
                 $uninteresting = $xpath->query('(//div[@class="heading"])');
                 foreach ($uninteresting as $i) {
                     $i->parentNode->removeChild($i);
                 }
                 if ($basenode) {
                     $article["content"] = $doc->saveXML($basenode);
                     $article["plugin_data"] = "pennyarcade,{$owner_uid}:" . $article["plugin_data"];
                 }
             }
         } else {
             if (isset($article["stored"]["content"])) {
                 $article["content"] = $article["stored"]["content"];
             }
         }
     }
     return $article;
 }
Example #14
Show file File: init.php Project: XelaRellum/tt-rss
0
 function hook_article_filter($article)
 {
     if (strpos($article["link"], "reddit.com/r/") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML($article["content"]);
         $xpath = new DOMXPath($doc);
         $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0);
         $found = $this->inline_stuff($article, $doc, $xpath);
         if (!defined('NO_CURL') && function_exists("curl_init") && !$found && $this->host->get($this, "enable_readability") && mb_strlen(strip_tags($article["content"])) <= 150) {
             if (!class_exists("Readability")) {
                 require_once dirname(dirname(__DIR__)) . "/lib/readability/Readability.php";
             }
             if ($content_link && strpos($content_link->getAttribute("href"), "twitter.com") === FALSE && strpos($content_link->getAttribute("href"), "youtube.com") === FALSE && strpos($content_link->getAttribute("href"), "reddit.com") === FALSE) {
                 /* link may lead to a huge video file or whatever, we need to check content type before trying to
                 			parse it which p much requires curl */
                 $ch = curl_init($content_link->getAttribute("href"));
                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($ch, CURLOPT_HEADER, true);
                 curl_setopt($ch, CURLOPT_NOBODY, true);
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir"));
                 curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
                 @($result = curl_exec($ch));
                 $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
                 if ($content_type && strpos($content_type, "text/html") !== FALSE) {
                     $tmp = fetch_file_contents($content_link->getAttribute("href"));
                     //_debug("tmplen: " . mb_strlen($tmp));
                     if ($tmp && mb_strlen($tmp) < 65535 * 4) {
                         $r = new Readability($tmp, $content_link->getAttribute("href"));
                         if ($r->init()) {
                             $tmpxpath = new DOMXPath($r->dom);
                             $entries = $tmpxpath->query('(//a[@href]|//img[@src])');
                             foreach ($entries as $entry) {
                                 if ($entry->hasAttribute("href")) {
                                     $entry->setAttribute("href", rewrite_relative_url($content_link->getAttribute("href"), $entry->getAttribute("href")));
                                 }
                                 if ($entry->hasAttribute("src")) {
                                     $entry->setAttribute("src", rewrite_relative_url($content_link->getAttribute("href"), $entry->getAttribute("src")));
                                 }
                             }
                             $article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"];
                             // prob not a very good idea (breaks wikipedia pages, etc) -
                             // inliner currently is not really fit for any random web content
                             //$doc = new DOMDocument();
                             //@$doc->loadHTML($article["content"]);
                             //$xpath = new DOMXPath($doc);
                             //$found = $this->inline_stuff($article, $doc, $xpath);
                         }
                     }
                 }
             }
         }
         $node = $doc->getElementsByTagName('body')->item(0);
         if ($node && $found) {
             $article["content"] = $doc->saveXML($node);
         }
     }
     return $article;
 }
Example #15
Show file File: af_comics_pa.php Project: XelaRellum/tt-rss
0
 function process(&$article)
 {
     if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
         if ($debug_enabled) {
             _debug("af_pennyarcade: Processing comic");
         }
         $doc = new DOMDocument();
         $doc->loadHTML(fetch_file_contents($article["link"]));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
         return true;
     }
     if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
         if ($debug_enabled) {
             _debug("af_pennyarcade: Processing news post");
         }
         $doc = new DOMDocument();
         $doc->loadHTML(fetch_file_contents($article["link"]));
         if ($doc) {
             $xpath = new DOMXPath($doc);
             $entries = $xpath->query('(//div[@class="post"])');
             $basenode = false;
             foreach ($entries as $entry) {
                 $basenode = $entry;
             }
             $meta = $xpath->query('(//div[@class="meta"])')->item(0);
             if ($meta->parentNode) {
                 $meta->parentNode->removeChild($meta);
             }
             $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0);
             if ($header->parentNode) {
                 $header->parentNode->removeChild($header);
             }
             $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0);
             if ($header->parentNode) {
                 $header->parentNode->removeChild($header);
             }
             $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0);
             if ($basenode) {
                 $basenode->insertBefore($avatar, $basenode->firstChild);
             }
             $uninteresting = $xpath->query('(//div[@class="avatar"])');
             foreach ($uninteresting as $i) {
                 $i->parentNode->removeChild($i);
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
         return true;
     }
     return false;
 }
Example #16
Show file File: xmlMergerTask.php Project: philippjenni/icinga-web
0
 /**
  * Prepares the document, registers the Namespaces and sets up the DOMXPath searcher
  * 
  */
 private function setupDOM()
 {
     $target_file = $this->getTarget();
     $source_file = $this->getSource();
     if (!file_exists($target_file)) {
         throw new BuildException("Unknown XML-Merger target " . $target_file);
     }
     if (!file_exists($source_file)) {
         throw new BuildException("Unknown XML-Merger source " . $source_file);
     }
     $dom_target = new DOMDocument("1.0", "UTF-8");
     $dom_source = new DOMDocument("1.0", "UTF-8");
     $dom_target->load($target_file);
     $dom_source->load($source_file);
     $dom_target->formatOutput = true;
     $dom_source->formatOutput = true;
     $path_target = new DOMXPath($dom_target);
     $path_source = new DOMXPath($dom_source);
     $this->registerXPathNamespaces($target_file, $path_target);
     $this->registerXPathNamespaces($source_file, $path_source);
     $this->setTargetDOM($dom_target);
     $this->setSourceDOM($dom_source);
     $this->setTargetXPath($path_target);
     $this->setSourceXPath($path_source);
 }
Example #17
Show file File: Response.php Project: DbyD/cruk
0
 /**
  * Extracts a node from the DOMDocument (Assertion).
  *
  * @param string $assertionXpath Xpath Expresion
  *
  * @throws Exception
  * @return DOMNodeList The queried node
  */
 protected function _queryAssertion($assertionXpath)
 {
     if ($this->encrypted) {
         $xpath = new DOMXPath($this->decryptedDocument);
     } else {
         $xpath = new DOMXPath($this->document);
     }
     $xpath->registerNamespace('samlp', OneLogin_Saml2_Constants::NS_SAMLP);
     $xpath->registerNamespace('saml', OneLogin_Saml2_Constants::NS_SAML);
     $xpath->registerNamespace('ds', OneLogin_Saml2_Constants::NS_DS);
     $xpath->registerNamespace('xenc', OneLogin_Saml2_Constants::NS_XENC);
     $assertionNode = $this->encrypted ? '/samlp:Response/saml:EncryptedAssertion/saml:Assertion' : '/samlp:Response/saml:Assertion';
     $signatureQuery = $assertionNode . '/ds:Signature/ds:SignedInfo/ds:Reference';
     $assertionReferenceNode = $xpath->query($signatureQuery)->item(0);
     if (!$assertionReferenceNode) {
         // is the response signed as a whole?
         $signatureQuery = '/samlp:Response/ds:Signature/ds:SignedInfo/ds:Reference';
         $assertionReferenceNode = $xpath->query($signatureQuery)->item(0);
         if ($assertionReferenceNode) {
             $id = substr($assertionReferenceNode->attributes->getNamedItem('URI')->nodeValue, 1);
             $nameQuery = "/samlp:Response[@ID='{$id}']/" . ($this->encrypted ? "saml:EncryptedAssertion/" : "") . "saml:Assertion" . $assertionXpath;
         } else {
             $nameQuery = "/samlp:Response/" . ($this->encrypted ? "saml:EncryptedAssertion/" : "") . "saml:Assertion" . $assertionXpath;
         }
     } else {
         $id = substr($assertionReferenceNode->attributes->getNamedItem('URI')->nodeValue, 1);
         $nameQuery = $assertionNode . "[@ID='{$id}']" . $assertionXpath;
     }
     return $xpath->query($nameQuery);
 }
Example #18
Show file File: CliClientGenerator.php Project: DBezemer/server
0
 function generate()
 {
     parent::generate();
     // services / actions / parameters
     $serviceIds = $this->getServiceIds();
     $this->addFile('services/services.map', serialize($serviceIds), false);
     foreach ($serviceIds as $serviceId) {
         $actionNames = $this->getActionNames($serviceId);
         $this->addFile("services/{$serviceId}.service", serialize($actionNames), false);
         foreach ($actionNames as $actionName) {
             $parameters = $this->getActionParameters($serviceId, $actionName);
             $this->addFile("actions/{$serviceId}/{$actionName}.action", serialize($parameters), false);
         }
     }
     // enums
     $xpath = new DOMXPath($this->_doc);
     $enumNodes = $xpath->query("/xml/enums/enum");
     foreach ($enumNodes as $enumNode) {
         $enumName = $enumNode->getAttribute('name');
         $values = $this->getEnumValueList($enumName);
         $this->addFile("enums/{$enumName}.enum", serialize($values), false);
     }
     // objects
     $xpath = new DOMXPath($this->_doc);
     $objectNodes = $xpath->query("/xml/classes/class");
     foreach ($objectNodes as $objectNode) {
         $objectName = $objectNode->getAttribute('name');
         $properties = $this->getObjectPropertiesList($objectName);
         $derivedTypes = $this->getDerivedTypesList($objectName);
         $objectDetails = array('properties' => $properties, 'derivedTypes' => $derivedTypes);
         $this->addFile("objects/{$objectName}.object", serialize($objectDetails), false);
     }
 }
Example #19
Show file File: init.php Project: cs-team/tiny_tiny_rss-openshift-quickstart
0
 function hook_article_filter($article)
 {
     $owner_uid = $article["owner_uid"];
     if (strpos($article["guid"], "dilbert.com") !== FALSE) {
         if (strpos($article["plugin_data"], "dilbert,{$owner_uid}:") === FALSE) {
             $doc = new DOMDocument();
             @$doc->loadHTML(fetch_file_contents($article["link"]));
             $basenode = false;
             if ($doc) {
                 $xpath = new DOMXPath($doc);
                 $entries = $xpath->query('(//img[@src])');
                 // we might also check for img[@class='strip'] I guess...
                 $matches = array();
                 foreach ($entries as $entry) {
                     if (preg_match("/dyn\\/str_strip\\/.*zoom\\.gif\$/", $entry->getAttribute("src"), $matches)) {
                         $entry->setAttribute("src", rewrite_relative_url("http://dilbert.com/", $matches[0]));
                         $basenode = $entry;
                         break;
                     }
                 }
                 if ($basenode) {
                     $article["content"] = $doc->saveXML($basenode);
                     $article["plugin_data"] = "dilbert,{$owner_uid}:" . $article["plugin_data"];
                 }
             }
         } else {
             if (isset($article["stored"]["content"])) {
                 $article["content"] = $article["stored"]["content"];
             }
         }
     }
     return $article;
 }