/** * returns the content of this item * * @return string content */ public function getContent() { if ($this->items !== false && $this->valid()) { try { // load entry page $client = new Zend_Http_Client($this->getLink() . '?page=all'); $response = $client->request(); $content = $response->getBody(); $content = utf8_decode($content); // parse content $dom = new Zend_Dom_Query($content); $text = $dom->query('.article'); $innerHTML = ''; // convert innerHTML from DOM to string // taken from http://us2.php.net/domelement (patrick smith) $children = $text->current()->childNodes; foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child, true)); if (count($tmp_doc->getElementById('comments')) > 0) { continue; } // convert to text $innerHTML .= @$tmp_doc->saveHTML(); } return $innerHTML; } catch (Exception $e) { // return default content return current($this->items)->get_content(); } } }
protected static function _changeExternalLinks(&$content) { if (empty($content)) { return; } $dom = new Zend_Dom_Query(); $dom->setDocumentHtml($content, 'utf-8'); if ($dom->getDocumentErrors()) { return; } $query = $dom->query('.externalLink'); if (!$query->count()) { return; } $links = array(); /** @var DOMElement $a */ foreach ($query as $a) { $link = $a->getAttribute('href'); if (empty($link)) { continue; } $links[] = $link; GFNLinkProxy_Api::preload($link); } foreach ($links as $link) { $content = preg_replace_callback('#(<a[^>]+href=("|\')?)(' . preg_quote($link, '#') . ')(("|\')?[^>]+class=("|\')?[^"\']*externalLink[^"\']*("|\')?[^>]*>)#sU', array(__CLASS__, '_replace'), $content, 1); } }
/** * @desc find id * @author makinder * @param string|array $url; * @version 0.0.1 */ protected function _findId($urls) { if (!is_array($urls)) { throw new Exception('url must be an array' . $urls); } foreach ($urls as $what => $url) { $total_info = file_get_contents($url); $dom = new Zend_Dom_Query($total_info); $links = $dom->query('a'); $data = array(); foreach ($links as $item) { $data[] = $item->getAttribute('href'); } $find = '/title/tt'; $result = array(); foreach ($data as $index => $value) { if (strpos($value, $find) !== false) { $item = substr($value, strpos($value, '/tt') + 1, 9); $result[] = $item; } } $request = array(); $hoho[$what] = array_unique($result); } return $hoho; }
/** * Get Sizing Chart content from remote resource */ public function getNewSizingChartContent($ptn) { if ($ptn) { $uri = Mage::getStoreConfig('yk_config/asc/url') . $ptn; $client = new Zend_Http_Client(); $client->setUri($uri); $response = $client->request(); if ($html = $response->getBody()) { $dom = new Zend_Dom_Query(); $dom->setDocumentHtml($html); $results = $dom->query(Mage::getStoreConfig('yk_config/asc/container')); if (count($results)) { foreach ($results as $result) { $innerHTML = ''; $children = $result->childNodes; foreach ($children as $child) { $innerHTML .= $child->ownerDocument->saveHTML($child); } return $innerHTML; } } } } return false; }
private function logIn() { $valuesLogin = array(new Oara_Curl_Parameter('username', $this->_credentials['user']), new Oara_Curl_Parameter('password', $this->_credentials['password'])); $cookies = COOKIES_BASE_DIR . DIRECTORY_SEPARATOR . $this->_credentials['cookiesDir'] . DIRECTORY_SEPARATOR . $this->_credentials['cookiesSubDir'] . DIRECTORY_SEPARATOR . $this->_credentials["cookieName"] . '_cookies.txt'; unlink($cookies); $this->_options = array(CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_COOKIEJAR => $cookies, CURLOPT_COOKIEFILE => $cookies, CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTPHEADER => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'), CURLOPT_ENCODING => "gzip", CURLOPT_VERBOSE => false); $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, "https://billing.purevpn.com/clientarea.php"); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); sleep(10); $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, "https://billing.purevpn.com/clientarea.php"); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); $dom = new Zend_Dom_Query($html); $hidden = $dom->query('#frmlogin input[name="token"][type="hidden"]'); foreach ($hidden as $values) { $valuesLogin[] = new Oara_Curl_Parameter($values->getAttribute("name"), $values->getAttribute("value")); } $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, "https://billing.purevpn.com/dologin.php?goto=clientarea.php"); $options[CURLOPT_HTTPHEADER] = array('Referer: https://billing.purevpn.com/clientarea.php', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'); $options[CURLOPT_POST] = true; $arg = array(); foreach ($valuesLogin as $parameter) { $arg[] = $parameter->getKey() . '=' . urlencode($parameter->getValue()); } $options[CURLOPT_POSTFIELDS] = implode('&', $arg); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); $rch = curl_init(); $options = $this->_options; $options[CURLOPT_URL] = "https://billing.purevpn.com/check_affiliate.php?check=affiliate"; $options[CURLOPT_HEADER] = true; $options[CURLOPT_NOBODY] = false; $options[CURLOPT_HTTPHEADER] = array('Referer: https://billing.purevpn.com/affiliates.php', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'); curl_setopt_array($rch, $options); $header = curl_exec($rch); preg_match('/Location:(.*?)\\n/', $header, $matches); $newurl = trim(array_pop($matches)); curl_close($rch); if (preg_match("/S=(.*)/", $newurl, $matches)) { $this->_s = $matches[1]; } $rch = curl_init(); $options = $this->_options; $options[CURLOPT_URL] = $newurl; $options[CURLOPT_HTTPHEADER] = array('Referer: https://billing.purevpn.com/affiliates.php', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'); curl_setopt_array($rch, $options); $content = curl_exec($rch); }
public function task(Zend_Http_Response $response, Zend_Http_Client $client) { $query = new Zend_Dom_Query($response->getBody()); $images = $query->query('img'); foreach ($images as $image) { $this->images[] = $image->getAttribute('src'); } $this->images = array_unique($this->images); }
/** * returns the thumbnail of this item (for multimedia feeds) * * @return mixed thumbnail data */ public function getThumbnail() { $item = current($this->items); // allways take photo from content $dom = new Zend_Dom_Query(@$item->get_content()); $imgTags = $dom->query('img'); if (count($imgTags)) { return $imgTags->current()->getAttribute('src'); } }
public function run() { if ($this->debugMode) { echo "Restricting crawl to {$this->domain}\n"; } //loop across available items in the queue of pages to crawl while (!$this->queue->isEmpty()) { if (isset($this->limit) && $this->counter >= $this->limit) { break; } $this->counter++; //get a new url to crawl $url = $this->queue->pop(); if ($this->debugMode) { echo "Queue Length: " . $this->queue->queueLength() . "\n"; echo "Crawling " . $url . "\n"; } //set the url into the http client $this->client->setUri($url); //make the request to the remote server $this->currentResponse = $this->client->request(); //don't bother trying to parse this if it's not text if (stripos($this->currentResponse->getHeader('Content-type'), 'text') === false) { continue; } //search for <a> tags in the document $body = $this->currentResponse->getBody(); $linksQuery = new Zend_Dom_Query($body); $links = $linksQuery->query('a'); if ($this->debugMode) { echo "\tFound " . count($links) . " links...\n"; } foreach ($links as $link) { //get the href of the link and find out if it links to the current host $href = $link->getAttribute('href'); $urlparts = parse_url($href); if ($this->stayOnDomain && isset($urlparts["host"]) && $urlparts["host"] != $this->domain) { continue; } //if it's an absolute link without a domain or a scheme, attempt to fix it if (!isset($urlparts["host"])) { $href = 'http://' . $this->domain . $href; //this is a really naive way of doing this! } //push this link into the queue to be crawled $this->queue->push($href); } //for each page that we see, run every registered task across it foreach ($this->tasks as $task) { $task->task($this->currentResponse, $this->client); } } //after we're done with everything, call the shutdown hook on all the tasks $this->shutdownTasks(); }
public function testQueueJsString() { $script = 'Inline JS script.'; queue_js_string($script); $matcher = array('tag' => 'script', 'attributes' => array('type' => 'text/javascript')); $output = $this->_getJsOutput(false); $dom = new Zend_Dom_Query('<fake>' . $output . '</fake>'); $result = $dom->queryXpath("//script[@type='text/javascript']"); $this->assertCount(1, $result, "Script tag for inline script not found."); $this->assertContains($script, $output); }
public function testQueueCssString() { $style = 'Inline stylesheet.'; queue_css_string($style, 'screen'); $matcher = array('tag' => 'style', 'attributes' => array('type' => 'text/css', 'media' => 'screen')); $output = $this->_getCssOutput(); $dom = new Zend_Dom_Query('<fake>' . $output . '</fake>'); $result = $dom->queryXpath("//style[@type='text/css' and @media='screen']"); $this->assertCount(1, $result, "Style tag for inline stylesheet not found."); $this->assertContains($style, $output); }
/** * Get the list of downloads from Jdownloader * @return array of Application_Model_JDownloaderPackage */ public function getDownloads() { if ($this->options->get('nightly', false)) { $data = $this->sendRawCommand("/get/downloads/all/list"); } else { $data = $this->sendRawCommand(self::CMD_GET_DOWNLOADS_ALL_LIST); } // time to parse xml // WHILE NOT DOWNLOADING /* <?xml version="1.0" encoding="UTF-8" standalone="no"?> <jdownloader> <package package_ETA="~" package_linksinprogress="0" package_linkstotal="1" package_loaded="0 B" package_name="Added 1298019679499" package_percent="0,00" package_size="82.11 MB" package_speed="0 B" package_todo="82.11 MB"> <file file_hoster="megavideo.com" file_name="The Big Bang Theory - 1x02 - The Big Bran Hypothes" file_package="Added 1298019679499" file_percent="0,00" file_speed="0" file_status=""/> </package> </jdownloader> */ // WHILE DONWLOADING /* <?xml version="1.0" encoding="UTF-8" standalone="no"?> <jdownloader> <package package_ETA="14m:37s" package_linksinprogress="1" package_linkstotal="1" package_loaded="1.52 MB" package_name="Added 1298019679499" package_percent="1,85" package_size="82.11 MB" package_speed="94.00 KB" package_todo="80.59 MB"> <file file_hoster="megavideo.com" file_name="The Big Bang Theory - 1x02 - The Big Bran Hypothes.flv" file_package="Added 1298019679499" file_percent="1,85" file_speed="96256" file_status="ETA 14m:37s @ 94.00 KB/s (1/1)"/> </package> </jdownloader> */ $xml = new Zend_Dom_Query($data); if ($this->options->get('nightly', false)) { $result = $xml->queryXpath('//packages'); } else { $result = $xml->queryXpath('//package'); } $packages = array(); while ($result->valid()) { /* @var $domPackage DOMElement */ $domPackage = $result->current(); $package = new Application_Model_JDownloaderPackage(); $package->setName($domPackage->getAttribute('package_name'))->setETA($domPackage->getAttribute('package_ETA'))->setPercent($domPackage->getAttribute('package_percent'))->setSize($domPackage->getAttribute('package_size'))->setDownloading($domPackage->getAttribute('package_linksinprogress') != '0'); /* @var $domFiles DOMNodeList */ $domFiles = $domPackage->getElementsByTagName('file'); for ($i = 0; $i < $domFiles->length; $i++) { /* @var $domFile DOMElement */ $domFile = $domFiles->item($i); $file = new Application_Model_JDownloaderFile(); $file->setName($domFile->getAttribute('file_name'))->setHoster($domFile->getAttribute('file_hoster'))->setPercent($domFile->getAttribute('file_percent'))->setDownloading($domFile->getAttribute('file_status') != ''); // add file inside the package $package->appendFile($file); } // add package in the list $packages[] = $package; $result->next(); } return $packages; }
/** * @description Searches for a line in the searcher * @param string $lookIn * @param string $searchString ('google','yandex','rambler','mail') * @author makinder, Se# * @version 0.0.2 * @changeLog * 0.0.2 configurable urls */ public function links($resource, $string, $urls = array()) { $urls = empty($urls) ? self::$urls : $urls; $urls = self::insertString($urls, $string, '$string'); if (isset($urls[$resource])) { $url = $urls[$resource]; } else { return false; } $dom = new Zend_Dom_Query(file_get_contents($url)); return $dom->query('a'); }
/** * Gets captcha word * * @param string $html * @return array */ public function getCaptcha($html) { $dom = new Zend_Dom_Query($html); $id = $dom->query('#captcha-id')->current()->getAttribute('value'); foreach ($_SESSION as $key => $value) { if (preg_match("/Zend_Form_Captcha_(.*)/", $key, $regs)) { //if (ereg("Zend_Form_Captcha_(.*)", $key, $regs)) { if ($regs[1] == $id) { return array('id' => $id, 'input' => $value['word']); } } } }
public function test11RetrieveConceptFiletrStatus() { // Use API to search for concept and filter on status // todo: test additionele zoek parameters print "\n" . "Test: get concept via filters"; $client = Authenticator::authenticate(); //prepare and send request $uri = BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . CONCEPT_prefLabel . '&status:' . CONCEPT_status_forfilter . '&tenant:' . TENANT . '&inScheme:' . CONCEPT_schema_forfilter; print "\n filtered request's uri: " . $uri . "\n"; $client->setUri($uri); $client->setConfig(array('maxredirects' => 0, 'timeout' => 30)); $client->SetHeaders(array('Accept' => 'text/html,application/xhtml+xml,application/xml', 'Content-Type' => 'application/xml', 'Accept-Language' => 'nl,en-US,en', 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'keep-alive')); $response = $client->request(Zend_Http_Client::GET); // analyse respond print "\n get status: " . $response->getMessage() . "\n"; $this->AssertEquals(200, $response->getStatus()); $namespaces = array("rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "skos" => "http://www.w3.org/2004/02/skos/core#", "openskos" => "http://openskos.org/xmlns/openskos.xsd"); $dom = new Zend_Dom_Query(); $dom->setDocumentXML($response->getBody()); $dom->registerXpathNamespaces($namespaces); $elem = $dom->queryXpath('/rdf:RDF'); $this->assertEquals(XML_ELEMENT_NODE, $elem->current()->nodeType, 'The root node of the response is not an element'); $this->assertEquals(1, $elem->current()->getAttribute("openskos:numFound")); $resDescr = $dom->queryXpath('/rdf:RDF/rdf:Description'); $i = 0; $l = $resDescr->count(); $resDescr->rewind(); while ($i < $l) { $labels = $resDescr->current()->getElementsByTagName("altLabel"); //print "\n val:" . $labels ->item(0) ->textContent; $randomn = rand(0, 4096); $labels->item(0)->nodeValue = "test-1-" . $randomn; $doc = $resDescr->current()->ownerDocument; $xml = $doc->saveXML(); var_dump($xml); // try $newdom isntead of $dom, which can be corrupted //$dom = new DOMDocument('1.0', 'utf-8'); //$rdf = $dom -> createElement("rdf:RDF"); //$dom ->importNode($newDescr, TRUE);// appendChild($rdf); //$rdf ->appendChild($newDescr); //$xml = $dom->saveXML(); //var_dump($xml); $client->setUri(BASE_URI_ . "/public/api/concept?"); $client->setConfig(array('maxredirects' => 0, 'timeout' => 30)); $response = $client->setEncType('text/xml')->setRawData($xml)->setParameterGet('tenant', TENANT)->setParameterGet('collection', COLLECTION_1_code)->setParameterGet('key', API_KEY)->request(Zend_Http_Client::PUT); print "\n Update response message: " . $response->getMessage(); $this->AssertEquals(200, $response->getStatus(), 'Update request returned worng status code'); $resDescr->next(); $i++; } }
/** * Check the connection */ public function checkConnection() { //If not login properly the construct launch an exception $connection = false; $urls = array(); $urls[] = new Oara_Curl_Request('https://affiliates.affutd.com/affiliates/Dashboard.aspx', array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('.lnkLogOut'); if (count($results) > 0) { $connection = true; } return $connection; }
/** * Check the connection */ public function checkConnection() { // If not login properly the construct launch an exception $connection = false; $urls = array(); $urls[] = new Oara_Curl_Request('https://secure.rentalcars.com/affiliates/?master=1', array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('#header_logout'); if (count($results) > 0) { $connection = true; } return $connection; }
function parse_item($node, $defs, $fix) { $d = new DOMDocument(); $d->appendChild($d->importNode($node, TRUE)); $zend = new Zend_Dom_Query($d->saveHTML()); //debug($d->saveHTML()); $properties = array(); foreach ($defs->properties as $property => $def) { if (is_string($def)) { $def = (object) array('selector' => $def); } //debug($def); if ($def->selector) { $t = array(); foreach ($zend->query($def->selector) as $selected) { $t[] = $selected; } $item = $t[0]; } else { $item = $node; } if (!$item) { continue; } if ($def->derived) { $data = $properties[$def->derived]; } else { $data = format($item, $def); } if (function_exists($fix)) { $data = call_user_func($fix, $property, $data); } if ($def->date) { $data = strtodate($def->date, $data); } $properties[$property] = $data; } if (!($properties['dc:identifier'] && $properties['dc:date'] && $properties['dc:title'])) { return FALSE; } $properties['dc:identifier'] = base_url($properties['dc:identifier']); if (!$properties['start']) { $properties['start'] = strtotime($properties['dc:date']); } if (!$properties['end'] && is_numeric($properties['start'])) { $properties['end'] = $properties['start'] + 3600; } // 1hr return $properties; }
/** * Removes the base path of the URL to HTML resources * * @param string $html * @return string|bool If error, then output FALSE */ protected function deleteBasePathUrl($html) { //$domHtml $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>'; $str_end = '</body>'; //--------------------------- $filtrHtmlEntities = new Default_Form_Filter_HtmlEntities(); $html = $filtrHtmlEntities->filter($html); $html = $str_begin . $html . $str_end; // Check for correct XML $domDoc = new DOMDocument('1.0', 'utf-8'); $success = $domDoc->loadXML($html); if (!$success) { return FALSE; } // Correct code $domQuery = new Zend_Dom_Query(); $domQuery->setDocumentXml($html, "utf-8"); foreach (self::$tags as $tag => $attr) { $results = $domQuery->query($tag); if ($results->count()) { foreach ($results as $result) { // $result variable is of DOMElement type if ($result->hasAttribute($attr)) { $value = $result->getAttribute($attr); $st = new Default_Plugin_String($value); if ($st->beginsWith('/')) { // it was: /zf-myblog/public/pic/1.gif // it is: /pic/1.gif $baseURL = Default_Plugin_SysBox::getBaseURL(); $value = str_replace($baseURL, '', $value); $result->setAttribute($attr, $value); } else { // it was: https://mysite.com:8080/zf-myblog/public/pic/1.gif // it is: /pic/1.gif $hostPortBaseURL = Default_Plugin_SysBox::getHostPortBaseURL(); $value = str_replace($hostPortBaseURL, '', $value); $result->setAttribute($attr, $value); } } } $domDoc = $results->getDocument(); $html = $domDoc->saveXml(); $domQuery->setDocumentXml($html, "utf-8"); } } $html = str_replace($str_begin, '', $html); $html = str_replace($str_end, '', $html); return $html; }
/** * Check the connection */ public function checkConnection() { //If not login properly the construct launch an exception $connection = true; $urls = array(); $urls[] = new Oara_Curl_Request('https://www.winneraffiliates.com/', array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('#lgUsername'); if (count($results) > 0) { $connection = false; } return $connection; }
private function assertions($response) { $dom = new Zend_Dom_Query(); $dom->setDocumentXML($response->GetBody()); // comparing test xml with teh data from the xml from the file // Asserting // Assert - 1 $results1 = $dom->query('skos:notation'); $this->AssertEquals(1, count($results1)); $this->AssertEquals(self::$notation, $results1->current()->nodeValue); // Assert - 2 $results2 = $dom->query('skos:inScheme'); $this->AssertEquals(1, count($results2)); $this->assertStringStartsWith("http://data.beeldengeluid.nl/gtaa/Onderwerpen", $results2->current()->getAttribute('rdf:resource')); }
public function testImport() { print "\n" . "Testing import ... "; $response = RequestResponse::ImportConceptRequest(self::$client, self::$postData, self::$boundaryNumeric); Logging::var_error_log("\n Response body ", $response->getBody(), __DIR__ . "/ImportResponse.html"); $this->AssertEquals(200, $response->getStatus(), 'Failed to import concept'); $output = array('0' => "The ouput of sending jobs: "); $retvar = 0; $sendjob = exec(PHP_JOBS_PROCESS, $output, $retvar); // check via spraql query //$sparqlResult = $this ->sparqlRetrieveTriplesForNotation(self::$notation); //var_dump($sparqlResult); self::$client->setUri(BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . self::$prefLabel); $responseGet = self::$client->request(Zend_Http_Client::GET); $this->AssertEquals(200, $responseGet->getStatus(), $responseGet->getMessage()); $dom = new Zend_Dom_Query(); $namespaces = RequestResponse::setNamespaces(); $dom->registerXpathNamespaces($namespaces); $xml = $responseGet->getBody(); $dom->setDocumentXML($xml); var_dump($xml); $results1 = $dom->query('rdf:RDF'); $this->AssertEquals(1, $results1->current()->getAttribute('openskos:numFound')); $results2 = $dom->queryXpath('/rdf:RDF/rdf:Description'); $this->AssertEquals(1, count($results2)); }
/** * Reveals target for short URL * * @param string $shortenedUrl URL to reveal target of * @throws Zend_Service_ShortUrl_Exception When URL is not valid or is not shortened by this service * @return string */ public function unshorten($shortenedUrl) { $this->_validateUri($shortenedUrl); $this->_verifyBaseUri($shortenedUrl); //TinyUrl.com does not have an API for that, but we can use preview feature //we need new Zend_Http_Client $this->setHttpClient(new Zend_Http_Client()); $this->getHttpClient()->setCookie('preview', 1)->setUri($shortenedUrl); //get response $response = $this->getHttpClient()->request(); require_once 'Zend/Dom/Query.php'; $dom = new Zend_Dom_Query($response->getBody()); //find the redirect url link $results = $dom->query('a#redirecturl'); //get href $originalUrl = $results->current()->getAttribute('href'); return $originalUrl; }
/** * Constructor and Login * @param $tradeDoubler * @return Oara_Network_Publisher_Td_Export */ public function __construct($credentials) { $this->_credentials = $credentials; $user = $this->_credentials['user']; $password = $this->_credentials['password']; $loginUrl = 'https://member.impactradius.co.uk/secure/login.user'; $valuesLogin = array(new Oara_Curl_Parameter('j_username', $user), new Oara_Curl_Parameter('j_password', $password)); $credentials = $this->_credentials; $this->_newClient = new Oara_Curl_Access($loginUrl, $valuesLogin, $credentials); $urls = array(); $urls[] = new Oara_Curl_Request('https://member.impactradius.co.uk/secure/mediapartner/accountSettings/mp-wsapi-flow.ihtml?', array()); $exportReport = $this->_newClient->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('div .uitkFields'); $count = count($results); if ($count == 0) { $activeAPI = array(new Oara_Curl_Parameter('_eventId', "activate")); $urls = array(); $urls[] = new Oara_Curl_Request('https://member.impactradius.co.uk/secure/mediapartner/accountSettings/mp-wsapi-flow.ihtml?', $activeAPI); $exportReport = $this->_newClient->post($urls); $urls = array(); $urls[] = new Oara_Curl_Request('https://member.impactradius.co.uk/secure/mediapartner/accountSettings/mp-wsapi-flow.ihtml?', array()); $exportReport = $this->_newClient->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('div .uitkFields'); $count = count($results); // get number of matches: 4 if ($count == 0) { throw new Exception("No API credentials"); } } $i = 0; foreach ($results as $result) { if ($i == 0) { $this->_accountSid = str_replace(array("\n", "\t", " "), "", $result->nodeValue); } else { if ($i == 1) { $this->_authToken = str_replace(array("\n", "\t", " "), "", $result->nodeValue); } } $i++; } }
/** * returns the thumbnail of this item (for multimedia feeds) * * @return mixed thumbnail data */ public function getThumbnail() { $item = current($this->items); // search enclosures (media tags) if (count(@$item->get_enclosures()) > 0) { // thumbnail given? if (@$item->get_enclosure(0)->get_thumbnail()) { return @$item->get_enclosure(0)->get_thumbnail(); } elseif (@$item->get_enclosure(0)->get_link()) { return @$item->get_enclosure(0)->get_link(); } // no enclosures: search image link in content } else { $dom = new Zend_Dom_Query(@$item->get_content()); $imgTags = $dom->query('img'); if (count($imgTags)) { return $imgTags->current()->getAttribute('src'); } } }
public function getThumbnailUrl($videoId) { $this->_videoId = $videoId; $this->_mediaSiteId = 'liveleak'; $urlVideoId = rawurlencode($videoId); $videoUrl = "http://www.liveleak.com/view?i={$urlVideoId}"; try { $client = XenForo_Helper_Http::getClient($videoUrl); $response = $client->request('GET'); $body = $response->getBody(); if ($body) { $dom = new Zend_Dom_Query($body); $thumbnailUrl = $dom->query('meta[property="og:image"]'); if ($thumbnailUrl->count()) { $this->_thumbnailUrl = $thumbnailUrl->current()->getAttribute('content'); } } } catch (Zend_Http_Client_Exception $e) { } return $this->verifyThumbnailUrl($this->_thumbnailUrl); }
/** * add the base path to the URL of HTML Resources * * @param string $html * @return string */ protected function addBasePathUrl($html) { //$domHtml $str_begin = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<body>'; $str_end = '</body>'; //--------------------------- $html = str_replace(' ', ' ', $html); $html = $str_begin . $html . $str_end; // Check for correct XML $domDoc = new DOMDocument('1.0', 'utf-8'); $success = $domDoc->loadXML($html); if (!$success) { return FALSE; } $domQuery = new Zend_Dom_Query(); $domQuery->setDocumentXml($html, "utf-8"); foreach (self::$tags as $tag => $attr) { $results = $domQuery->query($tag); if ($results->count()) { foreach ($results as $result) { // $result variable is of DOMElement type if ($result->hasAttribute($attr)) { $value = $result->getAttribute($attr); $st = new Default_Plugin_String($value); if ($st->beginsWith('/')) { $baseURL = Default_Plugin_SysBox::getUrlRes($value); $result->setAttribute($attr, $baseURL); } } } $domDoc = $results->getDocument(); $html = $domDoc->saveXml(); $domQuery->setDocumentXml($html, "utf-8"); } } $html = str_replace($str_begin, '', $html); $html = str_replace($str_end, '', $html); return $html; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getMerchantList() */ public function getMerchantList() { $merchants = array(); $valuesFromExport = array(new Oara_Curl_Parameter('c', 'stats'), new Oara_Curl_Parameter('a', 'listMonth')); $urls = array(); $urls[] = new Oara_Curl_Request('http://www.afiliant.com/publisher/index.php?', $valuesFromExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('#id_shop'); $merchantLines = $results->current()->childNodes; for ($i = 0; $i < $merchantLines->length; $i++) { $cid = $merchantLines->item($i)->attributes->getNamedItem("value")->nodeValue; if (is_numeric($cid)) { $obj = array(); $name = $merchantLines->item($i)->nodeValue; $obj = array(); $obj['cid'] = $cid; $obj['name'] = $name; $merchants[] = $obj; } } return $merchants; }
/** * @param $credentials * @throws Exception */ public function __construct($credentials) { $user = $credentials['user']; $password = $credentials['password']; $loginUrl = 'http://affiliates.shuttlefare.com/users/sign_in'; $dir = COOKIES_BASE_DIR . DIRECTORY_SEPARATOR . $credentials['cookiesDir'] . DIRECTORY_SEPARATOR . $credentials['cookiesSubDir'] . DIRECTORY_SEPARATOR; if (!Oara_Utilities::mkdir_recursive($dir, 0777)) { throw new Exception('Problem creating folder in Access'); } $cookies = $dir . $credentials["cookieName"] . '_cookies.txt'; unlink($cookies); $valuesLogin = array(new Oara_Curl_Parameter('user[email]', $user), new Oara_Curl_Parameter('user[password]', $password), new Oara_Curl_Parameter('user[remember_me]', '0'), new Oara_Curl_Parameter('commit', 'Sign in')); $this->_options = array(CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_COOKIEJAR => $cookies, CURLOPT_COOKIEFILE => $cookies, CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTPHEADER => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'), CURLOPT_ENCODING => "gzip", CURLOPT_VERBOSE => false); $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, "http://affiliates.shuttlefare.com/users/sign_in"); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); $dom = new Zend_Dom_Query($html); $hidden = $dom->query('input[type="hidden"]'); foreach ($hidden as $values) { $valuesLogin[] = new Oara_Curl_Parameter($values->getAttribute("name"), $values->getAttribute("value")); } $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, "http://affiliates.shuttlefare.com/users/sign_in"); $options[CURLOPT_POST] = true; $arg = array(); foreach ($valuesLogin as $parameter) { $arg[] = urlencode($parameter->getKey()) . '=' . urlencode($parameter->getValue()); } $options[CURLOPT_POSTFIELDS] = implode('&', $arg); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); }
/** * returns the content of this item * * @return string content */ public function getContent() { if ($this->items !== false && $this->valid()) { try { // load entry page $client = new Zend_Http_Client($this->getLink()); $response = $client->request(); $content = $response->getBody(); $content = utf8_decode($content); // parse content $dom = new Zend_Dom_Query($content); $text = $dom->query('.meldung_wrapper'); $innerHTML = ''; // convert innerHTML from DOM to string // taken from http://us2.php.net/domelement (patrick smith) $children = $text->current()->childNodes; foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child, true)); // make relative image src absolute $images = $tmp_doc->getElementsByTagName('img'); foreach ($images as $image) { if ($image->hasAttribute('src') && strpos($image->getAttribute('src'), 'http://') === false) { $image->setAttribute('src', 'http://www.heise.de' . $image->getAttribute('src')); } } // convert to text $innerHTML .= @$tmp_doc->saveHTML(); } return utf8_encode($innerHTML); } catch (Exception $e) { // return default content return current($this->items)->get_content(); } } }
function indexAction() { #Submit the form $teste = new Zend_Http_Client("http://www.sintegra.es.gov.br/resultado.php"); #set the paramenters $teste->setParameterPost("num_cnpj", "31.804.115-0002-43"); $teste->setParameterPost("num_ie", ""); $teste->setParameterPost("botao", "Consultar"); #request the url $retorno = $teste->request(Zend_Http_Client::POST); #get the html body $queryValues = new Zend_Dom_Query($retorno->getBody()); $queryTitulos = new Zend_Dom_Query($retorno->getBody()); #query the values based on type $resultValor = $queryValues->query('td.valor'); $resultTitulo = $queryValues->query('td.titulo'); $resultadorHTML = array(); $v_valor = $this->parseDataResult($resultValor); $v_titulo = $this->parseDataResult($resultTitulo); for ($i = 0; $i < count($v_valor); $i++) { $resultadorHTML[$v_titulo[$i]] = $v_valor[$i]; } $this->view->loadURL = json_encode($v_valor); }