示例#1
1
文件: Offer.php 项目: stunti/zf2
 /**
  * Parse the given Offer element
  *
  * @param  DOMElement $dom
  * @return void
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
     $this->MerchantId = (string) $xpath->query('./az:Merchant/az:MerchantId/text()', $dom)->item(0)->data;
     $name = $xpath->query('./az:Merchant/az:Name/text()', $dom);
     if ($name->length == 1) {
         $this->MerchantName = (string) $name->item(0)->data;
     }
     $this->GlancePage = (string) $xpath->query('./az:Merchant/az:GlancePage/text()', $dom)->item(0)->data;
     $this->Condition = (string) $xpath->query('./az:OfferAttributes/az:Condition/text()', $dom)->item(0)->data;
     $this->OfferListingId = (string) $xpath->query('./az:OfferListing/az:OfferListingId/text()', $dom)->item(0)->data;
     $Price = $xpath->query('./az:OfferListing/az:Price/az:Amount', $dom);
     if ($Price->length == 1) {
         $this->Price = (int) $xpath->query('./az:OfferListing/az:Price/az:Amount/text()', $dom)->item(0)->data;
         $this->CurrencyCode = (string) $xpath->query('./az:OfferListing/az:Price/az:CurrencyCode/text()', $dom)->item(0)->data;
     }
     $availability = $xpath->query('./az:OfferListing/az:Availability/text()', $dom)->item(0);
     if ($availability instanceof DOMText) {
         $this->Availability = (string) $availability->data;
     }
     $result = $xpath->query('./az:OfferListing/az:IsEligibleForSuperSaverShipping/text()', $dom);
     if ($result->length >= 1) {
         $this->IsEligibleForSuperSaverShipping = (bool) $result->item(0)->data;
     }
 }
function eactivities_override_registration_form()
{
    $page_so_far = ob_get_contents();
    $shortcode_markup = '';
    $dom = new DOMDocument();
    $dom->loadHTML($page_so_far);
    $xpath = new DOMXPath($dom);
    $form = $xpath->query('//form')->item(0);
    $username = $xpath->query('//label[@for=\'user_login\']')->item(0)->parentNode;
    $email = $xpath->query('//label[@for=\'user_email\']')->item(0)->parentNode;
    $shortcode = create_user_registration_element($dom, 'user_shortcode', 'Shortcode');
    $form->insertBefore($shortcode, $email);
    $firstname = create_user_registration_element($dom, 'first_name', 'First Name');
    $form->insertBefore($firstname, $email);
    $lastname = create_user_registration_element($dom, 'last_name', 'Last Name');
    $form->insertBefore($lastname, $email);
    if (!get_option('allow_custom_usernames')) {
        $username->setAttribute('style', 'display:none;');
    }
    if (!get_option('name_on_registration')) {
        $firstname->setAttribute('style', 'display:none;');
        $lastname->setAttribute('style', 'display:none;');
    }
    ob_get_clean();
    echo $dom->saveHTML();
}
示例#3
0
 function hook_article_filter($article)
 {
     if (strpos($article["guid"], "rockpapershotgun.com") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             // remove category stuff
             $stuff = $xpath->query('(//div[@class="dd_post_share"])|(//div[@class="social"])|(//iframe)');
             foreach ($stuff as $removethis) {
                 $removethis->parentNode->removeChild($removethis);
             }
             $entries = $xpath->query('(//div[@class="entry"])');
             foreach ($entries as $entry) {
                 $basenode = $entry;
                 break;
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
     }
     return $article;
 }
示例#4
0
 function hook_article_filter($article)
 {
     if (strpos($article["link"], "gulli.com") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             // first remove advertisement stuff
             $stuff = $xpath->query('(//script)|(//noscript)|(//div[@class="adsenseContainer"])|(//div[@class="_newsCrumb"])|(//div[@class="_forumBox"])|(//div[@class="nointelliTXT"])');
             foreach ($stuff as $removethis) {
                 $removethis->parentNode->removeChild($removethis);
             }
             // now get the (cleaned) article
             $entries = $xpath->query('(//div[@id="_contentLeft"])');
             foreach ($entries as $entry) {
                 $basenode = $entry;
                 break;
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
     }
     return $article;
 }
示例#5
0
 public function run()
 {
     header('Content-Type: text/html; charset=utf-8');
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $links = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_foto"]//a/@href');
     $titles = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_data"]//span[@class="product_list_name"]');
     $desc = $xpath->query('//td[@class="main_table"]//td[@class="right"]//table[@class="tekst"]//td[@class="product_list_data"]//td[@class="product_list_desc"]');
     for ($i = 0, $j = 0; $i < $links->length; $i++, $j = $j + 2) {
         $description = $doc->saveHTML($desc->item($j));
         $description = strip_tags($description, '<p><div><br>');
         $title = $titles->item($i)->nodeValue;
         $src = self::PREFIX_TO_IMAGES . $links->item($i)->value;
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         $permalink = $this->createPermalink($title);
         \DB\base\Manager::connection()->exec("\n                INSERT INTO element \n                    (label, permalink, opis, extension, kategoria_id)\n                    VALUES\n                    ('" . $title . "','" . $permalink . "','" . $description . "', '" . $ext . "'," . $kategoria . ")\n            ");
         $lastId = \DB\base\Manager::connection()->query("\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
示例#6
0
 /**
  * Constructs a new object object from DOM Document.
  *
  * @param   DomDocument $dom the ReST fragment for this object
  */
 public function __construct(DomDocument $dom)
 {
     $xpath = new DOMXPath($dom);
     $result = $xpath->query('//result/weblog');
     if ($result->length == 1) {
         $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
     } else {
         // follow the same behavior of blogPostTags
         // and raise an Exception if the URL is not a valid weblog
         throw new Zend_Service_Technorati_Exception("Your URL is not a recognized Technorati weblog");
     }
     $result = $xpath->query('//result/url/text()');
     if ($result->length == 1) {
         try {
             // fetched URL often doens't include schema
             // and this issue causes the following line to fail
             $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
         } catch (Zend_Service_Technorati_Exception $e) {
             if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) {
                 $this->_url = $this->getWeblog()->getUrl();
             }
         }
     }
     $result = $xpath->query('//result/inboundblogs/text()');
     if ($result->length == 1) {
         $this->_inboundBlogs = (int) $result->item(0)->data;
     }
     $result = $xpath->query('//result/inboundlinks/text()');
     if ($result->length == 1) {
         $this->_inboundLinks = (int) $result->item(0)->data;
     }
 }
 function testOne()
 {
     $doc = new \DOMDocument();
     $doc->load(__DIR__ . '/../../../../../../../resources/sample/Response/response01.xml');
     $xpath = new \DOMXPath($doc);
     $xpath->registerNamespace('samlp', Protocol::SAML2);
     $xpath->registerNamespace('ds', Protocol::NS_XMLDSIG);
     $xpath->registerNamespace('a', Protocol::NS_ASSERTION);
     $list = $xpath->query('/samlp:Response/a:Assertion/ds:Signature');
     $this->assertEquals(1, $list->length);
     /** @var $signatureNode \DOMElement */
     $signatureNode = $list->item(0);
     $signatureValidator = new SignatureXmlValidator();
     $signatureValidator->loadFromXml($signatureNode);
     $list = $xpath->query('./ds:KeyInfo/ds:X509Data/ds:X509Certificate', $signatureNode);
     $this->assertEquals(1, $list->length);
     /** @var $signatureNode \DOMElement */
     $certificateDataNode = $list->item(0);
     $certData = $certificateDataNode->textContent;
     $certificate = new X509Certificate();
     $certificate->setData($certData);
     $key = KeyHelper::createPublicKey($certificate);
     $ok = $signatureValidator->validate($key);
     $this->assertTrue($ok);
 }
示例#8
0
 function hook_article_filter($article)
 {
     if (strpos($article["link"], "daujones.com") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             // first remove advertisement stuff
             $stuff = $xpath->query('(//form)|(//span)|(//div[@class="rightnav"])|(//div[@class="kommentare"])|(//a)|(//h2[@style])|(//center)');
             foreach ($stuff as $removethis) {
                 $removethis->parentNode->removeChild($removethis);
             }
             $entries = $xpath->query('(//div[@class="maincontent"])');
             foreach ($entries as $entry) {
                 $basenode = $entry;
                 break;
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
     }
     return $article;
 }
 /**
  * Parse
  * @param DOMNode $contribNode
  */
 protected function parseSpecificContributions(&$contribNode)
 {
     parent::parseSpecificContributions($contribNode);
     if ($this->pluginConf["ENABLE_324_IMPORT"] == true) {
         return;
     }
     if ($contribNode->nodeName != "actions") {
         return;
     }
     $actionXpath = new DOMXPath($contribNode->ownerDocument);
     $compressNodeList = $actionXpath->query('action[@name="import_from_324"]', $contribNode);
     if (!$compressNodeList->length) {
         return;
     }
     unset($this->actions["import_from_324"]);
     $compressNode = $compressNodeList->item(0);
     $contribNode->removeChild($compressNode);
     $compressNodeList = $actionXpath->query('action[@name="migrate_metaserial"]', $contribNode);
     if (!$compressNodeList->length) {
         return;
     }
     unset($this->actions["import_from_324"]);
     $compressNode = $compressNodeList->item(0);
     $contribNode->removeChild($compressNode);
 }
 function OneQuery($query_key, $text, $limit = 1, $properties = null)
 {
     $url = 'http://viaf.org/viaf/search?query=' . urlencode('local.personalNames all "' . $text . '"') . '&httpAccept=' . urlencode('application/rss+xml');
     //echo $url . "\n";
     $xml = get($url);
     //echo $xml;
     if ($xml != '') {
         $dom = new DOMDocument();
         $dom->loadXML($xml);
         $xpath = new DOMXPath($dom);
         $xpath->registerNamespace('opensearch', 'http://a9.com/-/spec/opensearch/1.1/');
         $xpath_query = "//opensearch:totalResults";
         $count = 0;
         $nodeCollection = $xpath->query($xpath_query);
         foreach ($nodeCollection as $node) {
             $count = $node->firstChild->nodeValue;
         }
         if ($count > 0) {
             $xpath_query = "//item/title";
             $nodeCollection = $xpath->query($xpath_query);
             foreach ($nodeCollection as $node) {
                 $hit = new stdclass();
                 $hit->score = 1;
                 $hit->match = $count == 1;
                 $hit->name = $node->firstChild->nodeValue;
                 $nc = $xpath->query('../guid', $node);
                 foreach ($nc as $n) {
                     $hit->id = str_replace('http://viaf.org/viaf/', '', $n->firstChild->nodeValue);
                 }
                 $this->StoreHit($query_key, $hit);
             }
         }
     }
 }
示例#11
0
 public function run()
 {
     header('Content-Type: text/html; charset=UTF-8');
     $url = $this->getUrl();
     $kategoria = $this->getKategoria();
     $dir = opendir('uploads/');
     $doc = new \DOMDocument();
     @$doc->loadHTMLFile($url);
     $xpath = new \DOMXPath($doc);
     $titles = $xpath->query('//div[@class="rendslide-box"]//div[@class="product-box"]//td[@class="label"]//p[@class="font-fitter"]');
     $links = $xpath->query('//div[@class="rendslide-box"]//div[@class="slide page"]/@onclick');
     for ($i = 0; $i < $links->length; $i++) {
         $title = iconv('UTF8', 'LATIN1', $titles->item($i)->nodeValue);
         $link = str_replace("'", "", str_replace('window.location.href=', '', $links->item($i)->value));
         $subDoc = new \DOMDocument();
         @$subDoc->loadHTMLFile($link);
         $subXpath = new \DOMXPath($subDoc);
         $src = $subXpath->query('//div[@id="product"]//div[@class="left"]//a[@class="box"]/@href')->item(0)->value;
         $ext = pathinfo($src, PATHINFO_EXTENSION);
         $description = $subDoc->saveHTML($subXpath->query('//div[@id="product"]//div[@class="right"]//div[@class="left-margin"]')->item(0));
         $permalink = $this->createPermalink($title);
         $description = iconv('UTF8', 'LATIN1', $description);
         $description = preg_replace('/<p>.<\\/p>/', '', $description);
         \DB\base\Manager::connection()->exec("\n                INSERT INTO element \n                    (label, permalink, opis, extension, kategoria_id)\n                    VALUES\n                    ('" . $title . "','" . $permalink . "','" . $description . "', '" . $ext . "'," . $kategoria . ")\n            ");
         $lastId = \DB\base\Manager::connection()->query("\n                SELECT id FROM element ORDER BY id DESC LIMIT 1\n            ")->fetchColumn();
         $imgCt = file_get_contents($src);
         $folder = 'uploads/' . $lastId;
         mkdir($folder);
         $fp = fopen($folder . "/image." . $ext, "w");
         fwrite($fp, $imgCt);
         fclose($fp);
     }
 }
示例#12
0
 /**
  * Return all languages as array.
  *
  * @param $keys = an array with values tot return
  *
  * @return array - resulting languages
  */
 public function listAll($keys = null)
 {
     if ($this->cache === null) {
         if ($keys === null) {
             $keys = $this->allowed_keys;
         } elseif (!is_array($keys)) {
             $keys = array($keys);
         }
         $keys = array_intersect($keys, $this->allowed_keys);
         $result = array();
         $doc = new DOMDocument();
         $doc->load($this->getFile());
         $xPath = new DOMXPath($doc);
         foreach ($xPath->query("/languages/lang") as $lang) {
             /** @var $lang DOMElement */
             $r = array();
             $code = $lang->getAttribute('code');
             foreach ($keys as $key) {
                 $r[$key] = $xPath->query($key, $lang)->item(0)->nodeValue;
             }
             $result[$code] = $r;
         }
         $this->cache = $result;
     }
     return $this->cache;
 }
示例#13
0
 function hook_article_filter($article)
 {
     if (strpos($article["link"], "tagesschau.de") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             // first remove header, footer
             $stuff = $xpath->query('(//script)|(//noscript)|(//h3[@class="headline"])|(//div[@class="infokasten"])|(//div[@class="socialMedia"])|(//div[@class="linklist"])|(//img[@title="galerie"])');
             foreach ($stuff as $removethis) {
                 $removethis->parentNode->removeChild($removethis);
             }
             /* $iframes = $xpath->query('(//iframe[@src])'); */
             /* foreach ($iframes as $iframe) { */
             /*     $src = $iframe->getAttribute("src"); */
             /*     $src = "http://www.tagesschau.de/"+$src; */
             /*     $iframe->setAttribute("src", $src); */
             /* } */
             $entries = $xpath->query('(//div[@class="box"])');
             foreach ($entries as $entry) {
                 $basenode = $entry;
                 break;
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
     }
     return $article;
 }
示例#14
0
 /**
  * get the menus to be added inside the ohers menu item
  * @return $menus array of menus
  */
 public function getMenus()
 {
     $menus = array();
     if (file_exists(jApp::configPath() . '/havefnubb/hfnumenus.xml')) {
         $doc = new DOMDocument();
         $doc->load(realpath(jApp::configPath()) . '/havefnubb/hfnumenus.xml');
         $xpath = new DOMXPath($doc);
         $query = '/menus/menu';
         $entries = $xpath->query($query);
         $gJConfig = jApp::config();
         foreach ($entries as $idx => $menu) {
             $queryName = '//name[@lang="' . $gJConfig->locale . '"]';
             $items = $xpath->query($queryName);
             $name = $items->item($idx)->nodeValue;
             $queryItemName = '//menu/itemName';
             $items = $xpath->query($queryItemName);
             $itemName = $items->item($idx)->nodeValue;
             $queryUrl = '//menu/url';
             $items = $xpath->query($queryUrl);
             $url = $items->item($idx)->nodeValue;
             $queryOrder = '//menu/order';
             $items = $xpath->query($queryOrder);
             $order = $items->item($idx)->nodeValue;
             $menus[] = array('itemName' => $itemName, 'name' => $name, 'url' => $url, 'order' => $order);
         }
     }
     return $menus;
 }
示例#15
0
 /**
  * Sends a request to the REST API service and does initial processing
  * on the response.
  *
  * @param  string       $op    Name of the operation for the request
  * @param  string|array $query Query data for the request (optional)
  * @throws Zend_Service_Exception
  * @return DOMDocument Parsed XML response
  */
 protected function _makeRequest($op, $query = null)
 {
     if ($query != null) {
         $query = array_diff($query, array_filter($query, 'is_null'));
     }
     $response = $this->_rest->restGet('/simpy/api/rest/' . $op . '.do', $query);
     if ($response->isSuccessful()) {
         $doc = new DOMDocument();
         $doc->loadXML($response->getBody());
         $xpath = new DOMXPath($doc);
         $list = $xpath->query('/status/code');
         if ($list->length > 0) {
             $code = $list->item(0)->nodeValue;
             if ($code != 0) {
                 $list = $xpath->query('/status/message');
                 $message = $list->item(0)->nodeValue;
                 /**
                  * @see Zend_Service_Exception
                  */
                 require_once 'Zend/Service/Exception.php';
                 throw new Zend_Service_Exception($message, $code);
             }
         }
         return $doc;
     }
     /**
      * @see Zend_Service_Exception
      */
     require_once 'Zend/Service/Exception.php';
     throw new Zend_Service_Exception('HTTP ' . $response->getStatus());
 }
示例#16
0
文件: tables.php 项目: bmdevel/ezc
 /**
  * Filter XHtml document
  *
  * Filter for the document, which may modify / restructure a document and
  * assign semantic information bits to the elements in the tree.
  *
  * @param DOMDocument $document
  * @return DOMDocument
  */
 public function filter(DOMDocument $document)
 {
     $xpath = new DOMXPath($document);
     // Find all tables
     $tables = $xpath->query('//*[local-name() = "table"]');
     foreach ($tables as $table) {
         // Ignore tables, which again contain tables, as these most
         // probably contain the website content somehow.
         if ($xpath->query('.//*[local-name() = "table"]', $table)->length > 0) {
             continue;
         }
         // Extract all cells from the table and check what they contain
         $cells = $xpath->query('.//*[local-name() = "td"] | .//*[local-name() = "th"]', $table);
         $cellCount = $cells->length;
         $cellContentCount = 0;
         foreach ($cells as $cell) {
             $cellContentCount += (int) $this->cellHasContent($cell);
         }
         // Completely remove table, if it does not meet the configured
         // expectations
         if ($cellContentCount / $cellCount < $this->threshold) {
             $table->parentNode->removeChild($table);
             continue;
         }
         // Tables with only one column are most probably also used only for
         // layout. We remove them, too.
         if ($xpath->query('.//*[local-name() = "tr"]', $table)->length >= $cellCount) {
             $table->parentNode->removeChild($table);
             continue;
         }
     }
 }
示例#17
0
 /**
  * Constructs a new object from DOM Element.
  * Parses given Key element from $dom and sets API key string.
  *
  * @param   DomElement $dom the ReST fragment for this object
  * @param   string $apiKey  the API Key string
  */
 public function __construct(DomDocument $dom, $apiKey = null)
 {
     $xpath = new DOMXPath($dom);
     $this->_apiQueries = (int) $xpath->query('/tapi/document/result/apiqueries/text()')->item(0)->data;
     $this->_maxQueries = (int) $xpath->query('/tapi/document/result/maxqueries/text()')->item(0)->data;
     $this->setApiKey($apiKey);
 }
示例#18
0
 protected function parseSpecificContributions(&$contribNode)
 {
     parent::parseSpecificContributions($contribNode);
     if ($contribNode->nodeName != "actions") {
         return;
     }
     $actionXpath = new DOMXPath($contribNode->ownerDocument);
     if (!isset($this->options["FTP_LOGIN_SCREEN"]) || $this->options["FTP_LOGIN_SCREEN"] != "TRUE" || $this->options["FTP_LOGIN_SCREEN"] === false) {
         // Remove "ftp_login" && "ftp_set_data" actions
         $nodeList = $actionXpath->query('action[@name="dynamic_login"]', $contribNode);
         if (!$nodeList->length) {
             return;
         }
         unset($this->actions["dynamic_login"]);
         $contribNode->removeChild($nodeList->item(0));
         $nodeList = $actionXpath->query('action[@name="ftp_set_data"]', $contribNode);
         if (!$nodeList->length) {
             return;
         }
         unset($this->actions["ftp_set_data"]);
         $contribNode->removeChild($node = $nodeList->item(0));
     } else {
         // Replace "login" by "dynamic_login"
         $loginList = $actionXpath->query('action[@name="login"]', $contribNode);
         if ($loginList->length && $loginList->item(0)->getAttribute("auth_ftp_impl") == null) {
             $contribNode->removeChild($loginList->item(0));
         }
         $dynaLoginList = $actionXpath->query('action[@name="dynamic_login"]', $contribNode);
         if ($dynaLoginList->length) {
             $dynaLoginList->item(0)->setAttribute("name", "login");
             $dynaLoginList->item(0)->setAttribute("auth_ftp_impl", "true");
         }
     }
 }
 function generate()
 {
     parent::generate();
     $xpath = new DOMXPath($this->_doc);
     $this->appendLine('<?php');
     $this->appendLine('require_once("KalturaClientBase.php");');
     $this->appendLine('');
     // enumes
     $enumNodes = $xpath->query("/xml/enums/enum");
     foreach ($enumNodes as $enumNode) {
         $this->writeEnum($enumNode);
     }
     // classes
     $classNodes = $xpath->query("/xml/classes/class");
     foreach ($classNodes as $classNode) {
         $this->writeClass($classNode);
     }
     $serviceNodes = $xpath->query("/xml/services/service");
     foreach ($serviceNodes as $serviceNode) {
         $this->writeService($serviceNode);
     }
     $this->appendLine();
     $this->writeMainClient($serviceNodes);
     $this->appendLine();
     $this->addFile("KalturaClient.php", $this->getTextBlock());
 }
示例#20
0
 /**
  * get rendered menu and adds drop down markup
  *
  * @param string $html rendered navigation
  * @param string $class css class to check for adding drop down
  *
  * @return string
  */
 public function __invoke($html, $class = 'toplevel', $toggle = false)
 {
     $domDoc = new \DOMDocument('1.0', 'utf-8');
     $domDoc->loadXML('<?xml version="1.0" encoding="utf-8"?>' . $html);
     $xpath = new \DOMXPath($domDoc);
     foreach ($xpath->query('//a[starts-with(@class, "' . $class . '")]') as $item) {
         $result = $xpath->query('../ul', $item);
         if ($result->length === 1) {
             $ul = $result->item(0);
             $ul->setAttribute('class', 'dropdown-menu');
             $li = $item->parentNode;
             $li->setAttribute('id', substr($item->getAttribute('href'), 1));
             if (($existingClass = $li->getAttribute('class')) !== '') {
                 $li->setAttribute('class', $existingClass . ' dropdown');
             } else {
                 $li->setAttribute('class', 'dropdown');
             }
             if ($toggle) {
                 $item->setAttribute('data-toggle', 'dropdown');
             }
             if (($existingClass = $item->getAttribute('class')) !== '') {
                 $item->setAttribute('class', $item->getAttribute('class') . ' dropdown-toggle');
             } else {
                 $item->setAttribute('class', 'dropdown-toggle');
             }
             $space = $domDoc->createTextNode(' ');
             $item->appendChild($space);
             $caret = $domDoc->createElement('b', '');
             $caret->setAttribute('class', 'caret');
             $item->appendChild($caret);
         }
     }
     return $domDoc->saveXML($xpath->query('/ul')->item(0), LIBXML_NOEMPTYTAG);
 }
 /**
  * Returns array, containing detailed results for any Google search.
  *
  * @access       private
  * @param        string        $query      String, containing the search query.
  * @param        string        $tld        String, containing the desired Google top level domain.
  * @return       array                     Returns array, containing the keys 'URL', 'Title' and 'Description'.
  */
 public static function googleArray($query)
 {
     $result = array();
     $pages = 1;
     $delay = 0;
     for ($start = 0; $start < $pages; $start++) {
         $url = 'http://www.google.' . GOOGLE_TLD . '/custom?q=' . $query . '&filter=0' . '&num=100' . ($start == 0 ? '' : '&start=' . $start . '00');
         $str = SEOstats::cURL($url);
         if (preg_match("#answer=86640#i", $str)) {
             $e = 'Please read: http://www.google.com/support/websearch/' . 'bin/answer.py?&answer=86640&hl=en';
             throw new SEOstatsException($e);
         } else {
             $html = new DOMDocument();
             @$html->loadHtml($str);
             $xpath = new DOMXPath($html);
             $links = $xpath->query("//div[@class='g']//a");
             $descs = $xpath->query("//td[@class='j']//div[@class='std']");
             $i = 0;
             foreach ($links as $link) {
                 if (!preg_match('#cache#si', $link->textContent) && !preg_match('#similar#si', $link->textContent)) {
                     $result[] = array('url' => $link->getAttribute('href'), 'title' => utf8_decode($link->textContent), 'descr' => utf8_decode($descs->item($i)->textContent));
                     $i++;
                 }
             }
             if (preg_match('#<div id="nn"><\\/div>#i', $str) || preg_match('#<div id=nn><\\/div>#i', $str)) {
                 $pages += 1;
                 $delay += 200000;
                 usleep($delay);
             } else {
                 $pages -= 1;
             }
         }
     }
     return $result;
 }
示例#22
0
 /**
  * Parse the given Offer Set Element
  *
  * @param  DOMElement $dom
  * @return void
  */
 public function __construct(DOMElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01');
     $offer = $xpath->query('./az:OfferSummary', $dom);
     if ($offer->length == 1) {
         $lowestNewPrice = $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount', $dom);
         if ($lowestNewPrice->length == 1) {
             $this->LowestNewPrice = (int) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:Amount/text()', $dom)->item(0)->data;
             $this->LowestNewPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestNewPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
         }
         $lowestUsedPrice = $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount', $dom);
         if ($lowestUsedPrice->length == 1) {
             $this->LowestUsedPrice = (int) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:Amount/text()', $dom)->item(0)->data;
             $this->LowestUsedPriceCurrency = (string) $xpath->query('./az:OfferSummary/az:LowestUsedPrice/az:CurrencyCode/text()', $dom)->item(0)->data;
         }
         $this->TotalNew = (int) $xpath->query('./az:OfferSummary/az:TotalNew/text()', $dom)->item(0)->data;
         $this->TotalUsed = (int) $xpath->query('./az:OfferSummary/az:TotalUsed/text()', $dom)->item(0)->data;
         $this->TotalCollectible = (int) $xpath->query('./az:OfferSummary/az:TotalCollectible/text()', $dom)->item(0)->data;
         $this->TotalRefurbished = (int) $xpath->query('./az:OfferSummary/az:TotalRefurbished/text()', $dom)->item(0)->data;
     }
     $offers = $xpath->query('./az:Offers/az:Offer', $dom);
     if ($offers->length >= 1) {
         /**
          * @see Zend_Service_Amazon_Offer
          */
         require_once 'Zend/Service/Amazon/Offer.php';
         foreach ($offers as $offer) {
             $this->Offers[] = new Zend_Service_Amazon_Offer($offer);
         }
     }
 }
示例#23
0
    /**
     * Constructs a new object object from DOM Document.
     *
     * @param   DomDocument $dom the ReST fragment for this object
     */
    public function __construct(DomDocument $dom)
    {
        $xpath = new DOMXPath($dom);

        /**
         * @see Zend_Service_Technorati_Author
         */
        require_once 'Zend/Service/Technorati/Author.php';

        $result = $xpath->query('//result');
        if ($result->length == 1) {
            $this->_author = new Zend_Service_Technorati_Author($result->item(0));
        }

        /**
         * @see Zend_Service_Technorati_Weblog
         */
        require_once 'Zend/Service/Technorati/Weblog.php';

        $result = $xpath->query('//item/weblog');
        if ($result->length >= 1) {
            foreach ($result as $weblog) {
                $this->_weblogs[] = new Zend_Service_Technorati_Weblog($weblog);
            }
        }
    }
示例#24
0
 /**
  * load all app files for given path and build.xml document
  *
  * @param string $path app base path
  * @param DOMDocument $build build.xml
  * @return boolean
  */
 private function _doBuild($path, DOMDocument $build)
 {
     $Classes = Classes::get();
     $x = new DOMXPath($build);
     $app = $x->query('/build/app');
     if ($app->length != 1) {
         throw new PException('App error!');
     }
     $app = $app->item(0);
     if (!$app->hasAttribute('name')) {
         throw new PException('App name error!');
     }
     $this->_apps[$app->getAttribute('name')] = $build;
     $files = $x->query('/build/files/file');
     foreach ($files as $file) {
         if ($file->hasAttribute('class')) {
             $Classes->addClass($file->getAttribute('class'), $path . $file->nodeValue);
             continue;
         }
         if ($file->hasAttribute('include')) {
             if (!file_exists($path . $file->nodeValue)) {
                 continue;
             }
             $this->_includes[] = $path . $file->nodeValue;
             continue;
         }
     }
     return true;
 }
示例#25
0
 public static function parse($html, $url)
 {
     $recipe = RecipeParser_Parser_MicrodataSchema::parse($html, $url);
     // Turn off libxml errors to prevent mismatched tag warnings.
     libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $doc->loadHTML('<?xml encoding="UTF-8">' . $html);
     $xpath = new DOMXPath($doc);
     // Photo -- skip logo if it was used in place of photo
     if (strpos($recipe->photo_url, "FDC_Logo_vertical.png") !== false || strpos($recipe->photo_url, "FDC_share-logo.png") !== false) {
         $recipe->photo_url = '';
     }
     if ($recipe->photo_url) {
         $recipe->photo_url = str_replace("/thumbs/", "/large/", $recipe->photo_url);
     }
     // Yield
     $yield = '';
     $nodes = $xpath->query('//*[@class="yield"]');
     // Find as 'yield'
     if ($nodes->length) {
         $line = $nodes->item(0)->nodeValue;
         $line = RecipeParser_Text::formatYield($line);
         $recipe->yield = $line;
         // Or as number of 'servings'
     } else {
         $nodes = $xpath->query('//*[@class="servings"]//*[@class="value"]');
         if ($nodes->length) {
             $line = $nodes->item(0)->nodeValue;
             $line = RecipeParser_Text::formatYield($line);
             $recipe->yield = $line;
         }
     }
     return $recipe;
 }
示例#26
0
 public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
 {
     if ($version == "") {
         $th = $domth->documentElement;
         $ct = $domct->documentElement;
         $th->setAttribute("id", "0");
         $xp = new DOMXPath($domth);
         $te = $xp->query("/thesaurus/te");
         if ($te->length > 0) {
             $te0 = $te->item(0);
             $th->setAttribute("nextid", $te0->getAttribute("nextid"));
             $te = $xp->query("te", $te0);
             $te1 = [];
             for ($i = 0; $i < $te->length; $i++) {
                 $te1[] = $te->item($i);
             }
             foreach ($te1 as $tei) {
                 $th->appendChild($tei);
                 $this->fixThesaurus2($domth, $tei, 0, $unicode);
             }
             $te0->parentNode->removeChild($te0);
         }
         $ct->setAttribute("version", $version = "2.0.0");
         $th->setAttribute("version", "2.0.0");
         $th->setAttribute("creation_date", $now = date("YmdHis"));
         $th->setAttribute("modification_date", $now);
         $version = "2.0.0";
     }
     return $version;
 }
示例#27
0
 function hook_article_filter($article)
 {
     if (strpos($article["link"], "titanic-magazin.de") !== FALSE) {
         $doc = new DOMDocument();
         @$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
         $basenode = false;
         if ($doc) {
             $xpath = new DOMXPath($doc);
             // first remove advertisement + tracking stuff
             $stuff = $xpath->query('(//script)|(//noscript)|(//form)|(//a[@name="form"])|(//p)|(//a[@href="newsticker.html"])');
             foreach ($stuff as $removethis) {
                 if ($removethis->localName === "p") {
                     if ($removethis->textContent == "bezahlte Anzeige") {
                         $removethis->parentNode->removeChild($removethis);
                     }
                 } else {
                     $removethis->parentNode->removeChild($removethis);
                 }
             }
             // now get the (cleaned) article
             $entries = $xpath->query('(//div[@class="tt_news-bodytext"])');
             foreach ($entries as $entry) {
                 $basenode = $entry;
                 break;
             }
             if ($basenode) {
                 $article["content"] = $doc->saveXML($basenode);
             }
         }
     }
     return $article;
 }
示例#28
0
 public function run($args)
 {
     if (count($args) != 1) {
         $this->usageError('Please supply the path to fhir-single.xsd');
     }
     $output_dir = Yii::app()->basePath . '/components/fhir_schema';
     system('mkdir -p ' . escapeshellarg($output_dir));
     $doc = new DOMDocument();
     $doc->load($args[0]);
     $xpath = new DOMXPath($doc);
     $xpath->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema');
     $types = array();
     foreach ($xpath->query('xs:complexType') as $complexType) {
         $type = $complexType->getAttribute('name');
         $types[$type] = array();
         $base = $xpath->evaluate('string(.//xs:extension/@base)', $complexType);
         if ($base && isset($types[$base])) {
             $types[$type] = $types[$base];
         }
         foreach ($xpath->query('.//*[@maxOccurs]', $complexType) as $item) {
             $plural = $item->getAttribute('maxOccurs') != '1';
             if ($item->tagName == 'xs:element') {
                 $elements = array($item);
             } else {
                 $elements = $xpath->query('.//xs:element', $item);
             }
             foreach ($elements as $element) {
                 $el_name = $element->getAttribute('name') ?: $element->getAttribute('ref');
                 $el_type = $element->getAttribute('type') ?: $element->getAttribute('ref');
                 $types[$type][$el_name] = array('type' => $el_type, 'plural' => $plural);
             }
         }
         file_put_contents("{$output_dir}/{$type}.json", json_encode($types[$type], JSON_FORCE_OBJECT));
     }
 }
示例#29
0
 public function add_counter()
 {
     $mode = (string) getRequest("param0");
     $preParams = array();
     $data = $this->prepareData($preParams, 'settings');
     $this->setDataType("settings");
     $this->setActionType("view");
     if ($mode == "do") {
         $name = getRequest('counter-name');
         $site = getRequest('counter-site');
         $post = array('name' => $name, 'site' => $site);
         $post = json_encode($post);
         $headers = array("Content-type" => 'application/json', 'Content-length' => strlen($post));
         $response = self::get_response("counters", "POST", $post, $headers);
         $dom = new DOMDocument();
         $dom->loadXML($response);
         $xpath = new DOMXPath($dom);
         $errors = $xpath->query("//errors/error/text");
         if ($errors->length) {
             $errorMessage = '';
             foreach ($errors as $error) {
                 $errorMessage .= $error->nodeValue;
             }
             $data = array("error" => array("text" => $errorMessage, "name" => $name, "site" => $site));
             $this->setData($data);
             return $this->doData();
         }
         $counterId = $xpath->query("//counter/id")->item(0)->nodeValue;
         $this->chooseRedirect("/admin/stat/edit_counter/{$counterId}");
     }
     $this->setData($data);
     return $this->doData();
 }
示例#30
-3
 protected function load_page($link)
 {
     $doc = new DOMDocument();
     # curl does not follow the 301?
     $url = str_replace("-rss", "", $link);
     $html = fetch_file_contents($url, false, false, false, false, false, 0, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
     $html_enc = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $doc->loadHTML($html_enc);
     $basenode = false;
     $add_content = "";
     if ($doc) {
         $xpath = new DOMXPath($doc);
         $nextpage = $xpath->query('//table[@id="table-jtoc"]/tr/td/a[@id="atoc_next"]');
         if ($nextpage && $nextpage->length > 0 && $nextpage->item(0)->hasAttributes()) {
             $add_content = $this->load_page("http://www.golem.de" . $nextpage->item(0)->attributes->getNamedItem("href")->value);
         }
         // first remove advertisement stuff
         $stuff = $xpath->query('(//script)|(//noscript)|(//div[contain(@class, "iqad")])|(//ol[@id="list-jtoc"])|(//table[@id="table-jtoc"])|(//header[@class="cluster-header"]/h1)');
         foreach ($stuff as $removethis) {
             $removethis->parentNode->removeChild($removethis);
         }
         // now get the (cleaned) article
         $entries = $xpath->query('(//article)');
         foreach ($entries as $entry) {
             $basenode = $entry;
             break;
         }
         if ($basenode) {
             return $doc->saveXML($basenode) . $add_content;
         } else {
             return false;
         }
     }
 }