예제 #1
1
/**
 * [getValue description]
 * @param  object $dom       объект DOMDocument()
 * @param  string $classname название класса на странице
 * @param  string $title     название валюты
 */
function getValue(DOMDocument $dom, $classname, $title)
{
    $finder = new DomXPath($dom);
    $div = $finder->query("//*[contains(@class, '{$classname}')]");
    $val = $div->item(0)->textContent;
    echo $title . ' ' . substr($val, -5) . '<br>';
}
예제 #2
0
 /**
  * Fetch and Parse a form for input fields
  *
  */
 public function getInputs($type = 'text')
 {
     $content = preg_replace("/&(?!(?:apos|quot|[gl]t|amp);|#)/", '&amp;', $this->source);
     $doc = new DOMDocument();
     @$doc->loadHTML($content);
     $xpath = new DomXPath($doc);
     $list = array();
     if ($type == 'text') {
         $items = $xpath->query('//form//input | //form//select | //form//textarea');
         foreach ($items as $item) {
             if ($item->getAttribute('type') != 'submit' and $item->getAttribute('name') != 'Submit-button') {
                 if ($item->getAttribute('type') != 'hidden') {
                     $field = str_replace('[]', '', $this->has_attribute($item, 'name'));
                     $field = trim($field);
                     array_push($list, $field);
                 }
             }
         }
     } elseif ($type == 'hidden') {
         $items = $xpath->query('//input | //select');
         foreach ($items as $item) {
             if ($item->getAttribute('type') == 'hidden') {
                 array_push($list, array('name' => trim($this->has_attribute($item, 'name')), 'value' => trim($this->has_attribute($item, 'value'))));
             }
         }
     }
     return $list;
 }
예제 #3
0
 private function parse_search($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $finder = new DomXPath($doc);
     $torrents = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' hl-tr ')]");
     $links = $finder->query("//*[contains(@class, 'med tLink hl-tags bold')]");
     $result = array();
     for ($i = 0; $i < $torrents->length; $i++) {
         $torrent = $torrents->item($i);
         $status = $this->clean($torrent->childNodes->item(2)->attributes->getNamedItem('title')->textContent);
         $category = $this->clean($torrent->childNodes->item(4)->textContent);
         $title = $this->clean($torrent->childNodes->item(6)->textContent);
         $torrent_id = (int) $this->clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent);
         $detail_url = "http://rutracker.org/forum/viewtopic.php?t={$torrent_id}";
         $author_url = parse_url($torrent->childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent);
         $author_id = explode('=', $author_url['query']);
         $author_id = $author_id[1];
         $author = array("id" => (int) $author_id, "name" => $this->clean($torrent->childNodes->item(8)->firstChild->firstChild->textContent));
         $download_url = $this->clean($torrent->childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent);
         $size = $this->clean(str_replace(' ↓', '', $torrent->childNodes->item(10)->childNodes->item(3)->textContent));
         $seeders = (int) $this->clean($torrent->childNodes->item(12)->firstChild->textContent);
         $leachers = (int) $this->clean($torrent->childNodes->item(14)->textContent);
         $downloads = (int) $this->clean($torrent->childNodes->item(16)->textContent);
         $added = date('d-m-Y', $this->clean($torrent->childNodes->item(18)->childNodes->item(1)->textContent));
         $result[] = array("id" => $torrent_id, "title" => $title, "category" => $category, "status" => $status, "detail_url" => $detail_url, "author" => $author, "size" => $size, "download_url" => $download_url, "seeders" => $seeders, "leachers" => $leachers, "downloads" => $downloads, "added" => $added);
     }
     return $result;
 }
 /**
  * test xml generation for IPhone
  *
  * birthday must have 12 hours added
  */
 public function testAppendXmlData()
 {
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
     $testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
     $testDoc->formatOutput = true;
     $testDoc->encoding = 'utf-8';
     $appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
     $email = new Syncroton_Model_FileReference(array('contentType' => 'text/plain', 'data' => 'Lars'));
     $email->appendXML($appData, $this->_testDevice);
     #echo $testDoc->saveXML();
     $xpath = new DomXPath($testDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
     $xpath->registerNamespace('Email', 'uri:Email');
     $xpath->registerNamespace('Email2', 'uri:Email2');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:ContentType');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/ItemOperations:Data');
     $this->assertEquals(1, $nodes->length, $testDoc->saveXML());
     $this->assertEquals('TGFycw==', $nodes->item(0)->nodeValue, $testDoc->saveXML());
     // try to encode XML until we have wbxml tests
     $outputStream = fopen("php://temp", 'r+');
     $encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
     $encoder->encode($testDoc);
 }
예제 #5
0
 private static function _createBlockCode($code)
 {
     if (substr($code, 0, 5) == '<span') {
         $dom = new DomDocument();
         $dom->loadXML($code);
         $xpath = new DomXPath($dom);
         $parentSpan = $xpath->query('/span')->item(0);
         $block_code = self::$_dom->createElement('fo:inline');
         $block_code->setAttribute('color', substr($parentSpan->getAttributeNode('style')->value, 7, 7));
         $nodes = $xpath->query('/span/node()');
         foreach ($nodes as $node) {
             if ($node->nodeType == XML_ELEMENT_NODE) {
                 $child = self::$_dom->createElement('fo:inline', $node->nodeValue);
                 $child->setAttribute('color', substr($node->getAttributeNode('style')->value, 7, 7));
             } else {
                 $child = self::$_dom->importNode($node, true);
             }
             $block_code->appendChild($child);
         }
         if (preg_match("/^\\s+\$/", $block_code->firstChild->textContent)) {
             $block_code->removeChild($block_code->firstChild);
         }
     } else {
         $block_code = self::$_dom->createElement('fo:inline', $code);
     }
     return $block_code;
 }
 /**
  * test testGetProperties method
  */
 public function testGetProperties()
 {
     $body = '<?xml version="1.0" encoding="utf-8"?>
              <propfind xmlns="DAV:">
                 <prop>
                     <default-alarm-vevent-date xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vevent-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vtodo-date xmlns="urn:ietf:params:xml:ns:caldav"/>
                     <default-alarm-vtodo-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
                 </prop>
              </propfind>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id, 'HTTP_DEPTH' => '0'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //var_dump($this->response->body);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-datetime');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-date');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
예제 #7
0
    /**
     * test xml generation for IPhone
     */
    public function testSearch()
    {
        $doc = new DOMDocument();
        $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
			<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
			<Search xmlns="uri:Search">
				<Store>
					<Name>GAL</Name>
					<Query>Lars</Query>
					<Options>
						<Range>0-3</Range>
						<RebuildResults/>
						<DeepTraversal/>
					</Options>
				</Store>
			</Search>
		');
        $search = new Syncroton_Command_Search($doc, $this->_device, null);
        $search->handle();
        $responseDoc = $search->getResponse();
        #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
        $xpath = new DomXPath($responseDoc);
        $xpath->registerNamespace('Search', 'uri:Search');
        $nodes = $xpath->query('//Search:Search/Search:Status');
        $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
        $this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
        $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total');
        $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
        $this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
        $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result');
        $this->assertEquals(4, $nodes->length, $responseDoc->saveXML());
        #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
    }
예제 #8
0
 public function ovfImport($url, $xpath = false)
 {
     $this->url = $url;
     $dom = new DomDocument();
     $loaded = $dom->load($url);
     if (!$loaded) {
         return $loaded;
     }
     $xpath = new DomXPath($dom);
     // register the namespace
     $xpath->registerNamespace('envl', 'http://schemas.dmtf.org/ovf/envelope/1');
     $vs_nodes = $xpath->query('//envl:VirtualSystem');
     // selects all name element
     $refs_nodes = $xpath->query('//envl:References');
     // selects all name element
     $disk_nodes = $xpath->query('//envl:DiskSection');
     // selects all name element
     $refs_nodes_0 = $refs_nodes->item(0);
     $disk_nodes_0 = $disk_nodes->item(0);
     $vs_nodes_0 = $vs_nodes->item(0);
     if ($refs_nodes_0 && $disk_nodes_0 && $vs_nodes_0) {
         $this->buildReferences($refs_nodes_0);
         $this->buildDiskSection($disk_nodes_0);
         $this->buildVirtualSystem($vs_nodes_0);
         return true;
     } else {
         return false;
     }
 }
예제 #9
0
 /**
  * @param string $html
  * @return TorrentsCollection
  */
 public function parse(string $html) : TorrentsCollection
 {
     libxml_use_internal_errors(true);
     $doc = new \DOMDocument();
     $doc->loadHTML($html);
     $finder = new \DomXPath($doc);
     $torrents = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' hl-tr ')]");
     $links = $finder->query("//*[contains(@class, 'med tLink hl-tags bold')]");
     $result = new TorrentsCollection();
     for ($i = 0; $i < $torrents->length; $i++) {
         if (is_null($links->item($i))) {
             continue;
         }
         $childNodes = $torrents->item($i)->childNodes;
         $status = self::clean($childNodes->item(2)->attributes->getNamedItem('title')->textContent);
         $category = self::clean($childNodes->item(4)->textContent);
         $title = self::clean($childNodes->item(6)->textContent);
         $torrentId = (int) self::clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent);
         $detailUrl = self::DETAIL_URL . $torrentId;
         $authorUrl = parse_url($childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent);
         $authorId = (int) explode('=', $authorUrl['query'])[1];
         $authorName = self::clean($childNodes->item(8)->firstChild->firstChild->textContent);
         $downloadUrl = self::clean($childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent);
         $downloadUrl = self::DOWNLOAD_URL . $downloadUrl;
         $size = self::clean(str_replace(' ↓', '', $childNodes->item(10)->childNodes->item(3)->textContent));
         $seeders = (int) self::clean($childNodes->item(12)->firstChild->textContent);
         $leachers = (int) self::clean($childNodes->item(14)->textContent);
         $downloads = (int) self::clean($childNodes->item(16)->textContent);
         $added = (new \DateTimeImmutable())->setTimestamp((int) self::clean($childNodes->item(18)->childNodes->item(1)->textContent));
         $torrent = (new Torrent())->setId($torrentId)->setTitle($title)->setCategory($category)->setStatus($status)->setDetailUrl($detailUrl)->setAuthorId($authorId)->setAuthorName($authorName)->setSize($size)->setDownloadUrl($downloadUrl)->setSeeders($seeders)->setLeachers($leachers)->setDownloads($downloads)->setAdded($added);
         $result->add($torrent);
     }
     return $result;
 }
 public function testExpandProperty()
 {
     $list = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup);
     $body = '<?xml version="1.0" encoding="UTF-8"?>
             <A:expand-property xmlns:A="DAV:">
               <A:property name="expanded-group-member-set" namespace="http://calendarserver.org/ns/">
                 <A:property name="last-name" namespace="http://calendarserver.org/ns/"/>
                 <A:property name="principal-URL" namespace="DAV:"/>
                 <A:property name="calendar-user-type" namespace="urn:ietf:params:xml:ns:caldav"/>
                 <A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/>
                 <A:property name="first-name" namespace="http://calendarserver.org/ns/"/>
                 <A:property name="record-type" namespace="http://calendarserver.org/ns/"/>
                 <A:property name="displayname" namespace="DAV:"/>
               </A:property>
             </A:expand-property>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals/groups/' . $list->list_id . '/'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
     $xpath->registerNamespace('cs', 'http://calendarserver.org/ns/');
     $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/groups/' . $list->list_id . '/"]');
     $this->assertEquals(1, $nodes->length, 'group itself (not shown by client) is missing');
     $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/intelligroups/' . $list->list_id . '/"]');
     $this->assertEquals(1, $nodes->length, 'intelligroup (to keep group itself) is missing');
     $nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/users/' . Tinebase_Core::getUser()->contact_id . '/"]');
     $this->assertEquals(1, $nodes->length, 'user is missing');
 }
예제 #11
0
    /**
     * This function will return an associative array of all Glyphs equipped on the character.
     *
     * Associative Array Format:
     * "name" - Name of Glyph
     * "type" = Major, Minor, or Prime
     * "url" - URL of the Glyph
     * "itemNumber" - Unique item number of the Glyph.
     *
     * @return - An Associative Array. 
     */
    public function getGlyphs($character, $server) {

        $cacheFileName = Functions::getCacheDir().'talents_'.$character.'.html';
        $contents = Functions::getPageContents($this->talentURLBuilder($character, $server), $cacheFileName);

        $dom = Functions::loadNewDom($contents);
        $xpath = new DomXPath($dom);

        $glyphTypes = array("major", "minor", "prime");
        $glyphArray = array();

        foreach($glyphTypes as $gT) {

            $glyphNames = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/span[@class="name"]');
            $glyphLinks = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/@href');

            $ctr = 0;
            foreach($glyphNames as $g) {

                $itemNumber = explode("/", $glyphLinks->item($ctr)->nodeValue);

                $tmpArray = array(
                    "name" => trim(utf8_decode($g->nodeValue)),
                    "type" => $gT,
                    "url" => $glyphLinks->item($ctr)->nodeValue,
                    "itemNumber" => $itemNumber[4] );

                array_push($glyphArray, $tmpArray);

                $ctr++;
            }
        }

        return $glyphArray;
    }
예제 #12
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * If a valid file could be generated the file name is supposed to be
  * returned, otherwise return null.
  *
  * @param Project $project
  * @param string  $existingResult
  *
  * @return string
  */
 public function handle(Project $project, $existingResult = null)
 {
     if (!isset($project->analyzers['pdepend'])) {
         return;
     }
     $pdependResultFile = $project->dataDir . '/' . $project->analyzers['pdepend'];
     $document = new \DomDocument();
     $document->load($pdependResultFile);
     $xPath = new \DomXPath($document);
     foreach ($xPath->query('//package') as $packageNode) {
         $packageCommits = 0;
         foreach ($xPath->query('./class', $packageNode) as $classNode) {
             $fileNode = $xPath->query('./file', $classNode)->item(0);
             $file = $fileNode->getAttribute('name');
             $classCommits = $this->countGitChangesPerFileRange($project, $file, $classNode->getAttribute('start'), $classNode->getAttribute('end'));
             $packageCommits += $classCommits;
             $classNode->setAttribute('commits', $classCommits);
             foreach ($xPath->query('./method', $classNode) as $methodNode) {
                 $methodCommits = $this->countGitChangesPerFileRange($project, $file, $methodNode->getAttribute('start'), $methodNode->getAttribute('end'));
                 $methodNode->setAttribute('commits', $methodCommits);
             }
         }
         $packageNode->setAttribute('commits', $packageCommits);
     }
     $document->save($pdependResultFile);
     return null;
 }
예제 #13
0
 /**
  * 
  * Enter description here ...
  * @param unknown_type $url
  */
 public static function getProductComments($url)
 {
     header('Content-type: text/html; charset=utf-8');
     $url = "http://ormatek.com/products/980";
     $doc = file_get_contents($url);
     $doc = mb_convert_encoding($doc, 'HTML-ENTITIES', "UTF-8");
     $query = ".//*[@class='comment']";
     $dom = new DomDocument();
     libxml_use_internal_errors(true);
     $dom->loadHTML($doc);
     $xpath = new DomXPath($dom);
     $nodes = $xpath->query($query);
     $i = 0;
     if (!is_array($nodes)) {
         return null;
     }
     foreach ($nodes as $node) {
         $name = $node->getElementsByTagName("b")->item(0)->nodeValue;
         $text = $node->getElementsByTagName("p")->item(0)->nodeValue;
         $date = $node->getElementsByTagName("span")->item(0)->nodeValue;
         $rating = 0;
         $i++;
         $param[] = array('id' => $i, 'name' => $name, 'date' => $date, 'rating' => $rating, 'text' => $text);
     }
     return $param;
 }
예제 #14
0
 protected function xpathQuery($html, $xpath)
 {
     $dom = new \DomDocument();
     $dom->loadHtml($html);
     $domXpath = new \DomXPath($dom);
     return $domXpath->query($xpath);
 }
예제 #15
0
 function DataAsHTML($xslFileName)
 {
     $xmlData = new SimpleXMLElement('<page/>');
     $this->generateXML($xmlData, $this->data);
     $xmlfilemodule = simplexml_load_file("modules/" . $this->data['name'] . "/elements.xml");
     $xmlData = dom_import_simplexml($xmlData)->ownerDocument;
     foreach (dom_import_simplexml($xmlfilemodule)->childNodes as $child) {
         $child = $xmlData->importNode($child, TRUE);
         $xmlData->documentElement->appendChild($child);
     }
     $xslfile = "templates/" . $this->template_name . "/" . $xslFileName . ".xsl";
     $xslfilemodule = "modules/" . $this->data['name'] . "/elements.xsl";
     if (in_array($this->data['name'], $this->selfPages)) {
         $xslfile = "templates/" . $this->template_name . "/" . $this->data['name'] . ".xsl";
     }
     $domXSLobj = new DOMDocument();
     $domXSLobj->load($xslfile);
     $xpath = new DomXPath($domXSLobj);
     $next = $xpath->query('//xsl:include');
     $next = $next->item(0);
     $next->setAttribute('href', $xslfilemodule);
     $next->setAttribute('xml:base', ROOT_SYSTEM);
     $xsl = new XSLTProcessor();
     $xsl->importStyleSheet($domXSLobj);
     return $xsl->transformToXml($xmlData);
 }
예제 #16
0
 function bold()
 {
     $this->CI =& get_instance();
     $content = "";
     $output = $this->CI->output->get_output();
     $dom = new DOMDocument();
     $dom->loadHTML($output);
     $finder = new DomXPath($dom);
     $classname = "lead";
     $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]");
     foreach ($nodes as $node) {
         $words = explode(' ', $node->nodeValue);
         $temp = $dom->createElement("p");
         $temp->setAttribute("class", "lead");
         foreach ($words as $word) {
             if (ctype_upper($word[0])) {
                 //First char is uppercase
                 $newNode = $dom->createElement('strong', $word . " ");
                 $temp->appendChild($newNode);
             } else {
                 $newNode = $dom->createTextNode($word . " ");
                 $temp->appendChild($newNode);
             }
         }
         $node->parentNode->replaceChild($temp, $node);
     }
     echo $dom->saveHTML();
 }
    /**
     * test processing of meeting reponse
     */
    public function testMeetingResponse()
    {
        $doc = new DOMDocument();
        $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
			<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
			<MeetingResponse xmlns="uri:MeetingResponse" xmlns:Search="uri:Search">
				<Request>
					<UserResponse>2</UserResponse>
					<CollectionId>17</CollectionId>
					<RequestId>f0c79775b6b44be446f91187e24566aa1c5d06ab</RequestId>
				</Request>
				<Request>
					<UserResponse>2</UserResponse>
					<Search:LongId>1129::64c542b3b4bf624630a1fbbc30d2375a3729b734</Search:LongId>
				</Request>
			</MeetingResponse>
		');
        $meetingResponse = new Syncroton_Command_MeetingResponse($doc, $this->_device, null);
        $meetingResponse->handle();
        $responseDoc = $meetingResponse->getResponse();
        #$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
        $xpath = new DomXPath($responseDoc);
        $xpath->registerNamespace('MeetingResponse', 'uri:MeetingResponse');
        $nodes = $xpath->query('//MeetingResponse:MeetingResponse/MeetingResponse:Result');
        $this->assertEquals(2, $nodes->length, $responseDoc->saveXML());
        #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total');
        #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
        #$this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
        #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result');
        #$this->assertEquals(4, $nodes->length, $responseDoc->saveXML());
        #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
    }
예제 #18
0
파일: marca.php 프로젝트: hesselek/parser
function getProducts()
{
    $base_url = 'http://www.marcapl.com/marca/';
    include "../classes/httpFile.php";
    include "../functions/crawler_functions.php";
    $http = new HttpConnection();
    $http->init('galleta');
    $DOM = new DOMDocument();
    $url_array = explode(PHP_EOL, file_get_contents('../file/cats_list.ccd'));
    while (count($url_array) > 0) {
        $url = array_shift($url_array);
        if ($url == null || $url == " ") {
            echo "ENtrando";
            continue;
        }
        //$url = 'http://www.marcapl.com/marca/index.php?seccion=productos&productos=listado&seccion1=Guantes%20de%20Trabajo&seccion2=Abrigo&i=0';
        //$http->get(urlencode($url),false);
        get_dom($url, $DOM, $http);
        //$listado = $DOM->getElementById('listado_producto_referencia');
        $finder = new DomXPath($DOM);
        $listado = $finder->query("//*[contains(@id, 'listado_producto_referencia')]");
        foreach ($listado as $item) {
            $link = $item->getElementsByTagName('a');
            $enlace = $link->item(0)->getAttribute('href');
            if ($link != null) {
                file_put_contents("../file/url_list.ccd", $base_url . str_replace(" ", "%20", $enlace) . PHP_EOL, FILE_APPEND);
            }
            echo $enlace . '<br />';
        }
    }
    $http->close();
}
예제 #19
0
 /**
  * Collects all translateable strings(from tags with 'trans' attribute) from html templates
  *
  * @param string $file absoulute path to file
  */
 function extractFromHtml($file)
 {
     $dom = new DomDocument();
     $dom->loadHTMLFile($file);
     $xpath = new DomXPath($dom);
     $nodes = $xpath->query("//*[@trans]");
     foreach ($nodes as $i => $node) {
         //            $info = "<{$node->tagName}> at $file";
         $info = "";
         if ($node->hasAttribute('context')) {
             $info = 'Context: ' . $node->getAttribute('context') . '.  ' . $info;
         }
         if ($node->hasAttribute('placeholder')) {
             $this->addTranslationStr($node->getAttribute('placeholder'), $info);
         }
         if ($node->hasAttribute('title')) {
             $this->addTranslationStr($node->getAttribute('title'), $info);
         }
         if ($node->hasAttribute('data-intro')) {
             $this->addTranslationStr($node->getAttribute('data-intro'), $info);
         }
         if ($node->nodeValue != '' && $node->getAttribute('trans') != 'attr-only') {
             $this->addTranslationStr($node->nodeValue, $info);
         }
     }
 }
예제 #20
0
 /**
  * @param string $accountNumber
  * @param int|null $maxItems
  * @param \DateTime|null $dateFrom
  * @param \DateTime|null $dateTo
  * @return \mixed[]
  */
 public function getTransfers($accountNumber, $maxItems = null, DateTime $dateFrom = null, DateTime $dateTo = null)
 {
     $data = $this->getRawData($accountNumber, $dateFrom, $dateTo);
     $transferData = substr($data, strpos($data, '<table class=\'main\'>'));
     $transferData = substr($transferData, 0, strpos($transferData, '</table>') + 8);
     $dom = new \DOMDocument();
     $dom->loadHTML($transferData);
     $finder = new \DomXPath($dom);
     $nodes = $finder->query('//table[@class="main"]//tbody//tr');
     $transfers = array();
     /** @var \DOMElement $node */
     $i = 1;
     $length = $nodes->length;
     foreach ($nodes as $node) {
         $value = str_replace(',', '.', trim($node->childNodes->item(2)->nodeValue));
         $value = (double) str_replace(' ', '', $value);
         $transfers[] = array(\DateTime::createFromFormat('d.m.Y', $node->childNodes->item(0)->nodeValue), $value, $node->childNodes->item(12)->nodeValue, $node->childNodes->item(14)->nodeValue);
         if ($maxItems !== null && $i >= $maxItems) {
             break;
         }
         $i++;
         if ($i >= $length) {
             break;
         }
     }
     $stateData = substr($data, strpos($data, '<table class=\'summary\'>'));
     $stateData = substr($stateData, 0, strpos($stateData, '</table>') + 8);
     $dom = new \DOMDocument();
     $dom->loadHTML($stateData);
     $finder = new \DomXPath($dom);
     $nodes = $finder->query('//table[@class="summary"]//tbody//tr//td[2]');
     $value = trim($nodes->item(0)->nodeValue);
     $value = str_replace(',', '.', $value);
     return array('state' => (double) str_replace(' ', '', $value), 'transfers' => $transfers);
 }
function leistungsschutzrecht_fetchsites()
{
    require_once "include/network.php";
    $sites = array();
    $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
    $site = fetch_url($url);
    $doc = new DOMDocument();
    @$doc->loadHTML($site);
    $xpath = new DomXPath($doc);
    $list = $xpath->query("//td/a");
    foreach ($list as $node) {
        $attr = array();
        if ($node->attributes->length) {
            foreach ($node->attributes as $attribute) {
                $attr[$attribute->name] = $attribute->value;
            }
        }
        if (isset($attr["href"])) {
            $urldata = parse_url($attr["href"]);
            if (isset($urldata["host"]) and !isset($urldata["path"])) {
                $cleanedurlpart = explode("%", $urldata["host"]);
                $hostname = explode(".", $cleanedurlpart[0]);
                $site = $hostname[sizeof($hostname) - 2] . "." . $hostname[sizeof($hostname) - 1];
                $sites[$site] = $site;
            }
        }
    }
    if (sizeof($sites)) {
        set_config('leistungsschutzrecht', 'sites', $sites);
    }
}
예제 #22
0
function getProducts()
{
    include "../classes/httpFile.php";
    include "../functions/crawler_functions.php";
    error_reporting(E_ALL ^ E_WARNING);
    $http = new HttpConnection();
    $http->setCookiePath("cookies/");
    $http->init();
    $DOM = new DOMDocument();
    $url_array = split(PHP_EOL, file_get_contents('../file/cats_list.ccd'));
    while (count($url_array) > 0) {
        $url = array_shift($url_array);
        $http->get($url, true);
        get_dom($url, $DOM, $http);
        $finder = new DomXPath($DOM);
        $classname = "product-container";
        $product = $finder->query("//*[contains( normalize-space( @class ), ' {$classname} ' )\r\n\t\t  \t\t\tor substring( normalize-space( @class ), 1, string-length( '{$classname}' ) + 1 ) = '{$classname} '\r\n\t\t  \t\t\tor substring( normalize-space( @class ), string-length( @class ) - string-length( '{$classname}' ) ) = ' {$classname}'\r\n\t\t  \t\t\tor @class = '{$classname}']");
        foreach ($product as $p) {
            $enlaces = $p->getElementsByTagName('a');
            $enlace = $enlaces->item(0)->getAttribute('href');
            echo $enlace . '<br/>';
            file_put_contents("../file/url_list.ccd", $enlace . PHP_EOL, FILE_APPEND);
        }
    }
    $http->close();
}
 /**
  * test testGetProperties method
  */
 public function testGetProperties()
 {
     $body = '<?xml version="1.0" encoding="utf-8"?>
              <propfind xmlns="DAV:">
                 <prop>
                     <getlastmodified xmlns="DAV:"/>
                     <getcontentlength xmlns="DAV:"/>
                     <resourcetype xmlns="DAV:"/>
                     <getetag xmlns="DAV:"/>
                     <id xmlns="http://owncloud.org/ns"/>
                 </prop>
              </propfind>';
     $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName, 'HTTP_DEPTH' => '0'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     //var_dump($this->response->body);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
     $responseDoc = new DOMDocument();
     $responseDoc->loadXML($this->response->body);
     //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
     $xpath = new DomXPath($responseDoc);
     $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
     $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
     $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
     $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
 }
    /**
     * Test for EZP-22517
     *
     * Checks that the header level is kept.
     *
     * @link https://jira.ez.no/browse/EZP-22517
     */
    public function testHeaderCustomTag()
    {
        $parser = new eZSimplifiedXMLInputParser(0, eZXMLInputParser::ERROR_NONE);
        $input = '<header level="3">h3</header>
<custom name="factbox" custom:title="factbox" custom:align="right">
<header level="2">h2</header>
</custom>';
        $dom = $parser->process($input);
        self::assertInstanceOf('DomDocument', $dom);
        $xpath = new DomXPath($dom);
        $header3 = $xpath->query('/section/section/section/section/header');
        $header2 = $xpath->query('/section/section/section/paragraph/custom/header');
        self::assertEquals(1, $header3->length);
        self::assertEquals("h3", $header3->item(0)->textContent);
        self::assertEquals(1, $header2->length);
        self::assertEquals("h2", $header2->item(0)->textContent);
    }
예제 #25
0
 public function testBasicView()
 {
     $action = new CreateUserAction();
     ok($action);
     $view = new ActionKit\View\StackView($action);
     ok($view);
     $html = $view->render();
     ok($html);
     $resultDom = new DOMDocument();
     $resultDom->loadXML($html);
     $finder = new DomXPath($resultDom);
     $nodes = $finder->query("//form");
     is(1, $nodes->length);
     $nodes = $finder->query("//input");
     is(4, $nodes->length);
     $nodes = $finder->query("//*[contains(@class, 'formkit-widget')]");
     is(8, $nodes->length);
     $nodes = $finder->query("//*[contains(@class, 'formkit-widget-text')]");
     is(2, $nodes->length);
     $nodes = $finder->query("//*[contains(@class, 'formkit-label')]");
     is(3, $nodes->length);
     $nodes = $finder->query("//input[@name='last_name']");
     is(1, $nodes->length);
     $nodes = $finder->query("//input[@name='first_name']");
     is(1, $nodes->length);
 }
function fetchShipsFromRSI($page)
{
    error_log("fetching page " . $page);
    $memUrl = 'https://robertsspaceindustries.com/api/store/getShips';
    $data = array('storefront' => 'pledge', 'pagesize' => '255', 'page' => $page);
    // use key 'http' even if you send the request to https://...
    $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
    $context = stream_context_create($options);
    $result = file_get_contents($memUrl, false, $context);
    $var = json_decode($result, true);
    $str = $var["data"]["html"];
    $ret = array();
    if ($var["success"] != "1" || !strlen($str)) {
        return $ret;
    }
    error_log("------------ " . $var["success"] . " || " . strlen($str));
    $DOM = new DOMDocument();
    $DOM->loadHTML('<?xml encoding="utf-8" ?>' . $str);
    $xpath = new DomXPath($DOM);
    $items = $xpath->query('//li[@class="ship-item"]');
    foreach ($items as $idx => $item) {
        $id = $xpath->query("@data-ship-id", $item);
        $divc = $xpath->query('./div[@class="center"]', $item)->item(0);
        $img = $xpath->query("./img/@src", $divc);
        $name = $xpath->query("./a[@class='filet']/span[contains(concat(' ', normalize-space(@class), ' '), name)]", $divc);
        $temp = split(' - ', $name->item(0)->nodeValue);
        $divb = $xpath->query("./div[contains(concat(' ', normalize-space(@class), ' '), bottom)]/span/span", $item);
        $imgm = $xpath->query("./div[contains(concat(' ', normalize-space(@class), ' '), bottom)]/span/img/@src", $item);
        $mname = basename($imgm->item(0)->value, ".png");
        $shiparr = array("id" => $id->item(0)->value, "name" => $temp[0], "class" => $temp[1], "img" => "https://robertsspaceindustries.com" . $img->item(0)->value, "crew" => $divb->item(0)->nodeValue, "length" => $divb->item(1)->nodeValue, "mass" => $divb->item(2)->nodeValue, "mimg" => "https://robertsspaceindustries.com" . $imgm->item(0)->value, "mname" => $mname, "updated_at" => current_time('mysql'));
        array_push($ret, $shiparr);
    }
    return $ret;
}
예제 #27
0
/**
 * Checks Cardboard availability status.
 *
 * @return bool
 *   Returns true if Cardboard is available.
 */
function cardboard_is_available()
{
    $dom = new DOMDocument();
    $html = @$dom->loadHTMLFile(CARDBOARD_URL);
    $classname = 'button-text';
    $finder = new DomXPath($dom);
    $nodes = $finder->query("//*[contains(@class, '{$classname}')]");
    return 'Not available' != $nodes->item(1)->textContent;
}
예제 #28
0
파일: PGPage.php 프로젝트: byjg/pgbrowser
 /**
  * Return the matching nodes of the expression (xpath or css)
  * @param string $query the expression to search for
  * @param string $dom the context to search
  * @return DomNodeList|phpQueryObject
  */
 public function search($query, $dom = null)
 {
     if ($this->is_xpath($query)) {
         return $dom ? $this->xpath->query($query, $dom) : $this->xpath->query($query);
     }
     phpQuery::selectDocument($this->parser);
     $doc = $dom ? pq($dom) : $this->parser;
     return $doc[$query];
 }
예제 #29
0
 public function xpath($path)
 {
     $xpath = new \DomXPath($this->dom);
     $list = $xpath->query($path);
     $return = [];
     foreach ($list as $node) {
         $return[] = $this->newElement($node);
     }
     return $return;
 }
예제 #30
0
function printAppointmentsForLocations(DomXPath $xpath, $locations)
{
    foreach ($locations as $location) {
        $appointmentCells = $xpath->query("descendant-or-self::*[@summary = 'Available appointments at " . $location . "']/tr/td");
        if ($appointmentCells->length > 0) {
            echo $location . " appointments:\n";
            printAppointments($appointmentCells);
        }
    }
}