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')); }
private function assertionsForXMLRDFCollection($response) { $dom = new Zend_Dom_Query(); $dom->setDocumentXML($response->getBody()); $results1 = $dom->query('rdf:Description'); $collection_1_description_about = BASE_URI_ . '/api/collections/' . COLLECTION_1_tenant . ":" . COLLECTION_1_code; $this->AssertEquals($collection_1_description_about, $results1->current()->getAttribute('rdf:about')); $results2 = $dom->query('rdf:type'); $this->AssertEquals(COLLECTION_1_type_resource, $results2->current()->getAttribute('rdf:resource')); $results3 = $dom->query('dcterms:title'); $this->AssertEquals(COLLECTION_1_title, $results3->current()->nodeValue); $results4 = $dom->query('dcterms:creator'); $this->AssertEquals(COLLECTION_1_creator, $results4->current()->nodeValue); $this->AssertEquals(COLLECTION_1_creator_about, $results4->current()->getAttribute('rdf:about')); }
/** * 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(); }
/** * @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']); } } } }
/** * 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; }
/** * 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; }
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; }
/** * 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; }
/** * 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; }
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); }
/** * 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 that Convert from a table to Csv * @param unknown_type $html */ private function htmlToCsv($html) { $html = str_replace(array("\t", "\r", "\n"), "", $html); $csv = ""; $dom = new Zend_Dom_Query($html); $results = $dom->query('tr'); $count = count($results); // get number of matches: 4 foreach ($results as $result) { $tdList = $result->childNodes; $tdNumber = $tdList->length; if ($tdNumber > 0) { for ($i = 0; $i < $tdNumber; $i++) { $value = $tdList->item($i)->nodeValue; if ($i != $tdNumber - 1) { $csv .= trim($value) . ";"; } else { $csv .= trim($value); } } $csv .= "\n"; } } $exportData = str_getcsv($csv, "\n"); return $exportData; }
/** * Constructor and Login * @param $credentials * @return Oara_Network_Publisher_Daisycon */ public function __construct($credentials) { $user = $credentials['user']; $password = $credentials['password']; $url = "http://panel.webepartners.pl/Account/Login"; $dir = COOKIES_BASE_DIR . DIRECTORY_SEPARATOR . $credentials['cookiesDir'] . DIRECTORY_SEPARATOR . $credentials['cookiesSubDir'] . DIRECTORY_SEPARATOR; $cookieName = $credentials["cookieName"]; $cookies = $dir . $cookieName . '_cookies.txt'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($credentials['cookieName'] == strstr($file, '_', true)) { unlink($dir . $file); break; } } closedir($handle); } $this->_client = array(CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_COOKIEJAR => $cookies, CURLOPT_COOKIEFILE => $cookies, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false); //Init curl $ch = curl_init(); $options = $this->_client; $options[CURLOPT_URL] = $url; $options[CURLOPT_FOLLOWLOCATION] = true; curl_setopt_array($ch, $options); $result = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $info = curl_getinfo($ch); $dom = new Zend_Dom_Query($result); $results = $dom->query('input[type="hidden"]'); $hiddenValue = null; foreach ($results as $result) { $name = $result->attributes->getNamedItem("name")->nodeValue; if ($name == "__RequestVerificationToken") { $hiddenValue = $result->attributes->getNamedItem("value")->nodeValue; } } if ($hiddenValue == null) { throw new Exception("hidden value not found"); } $valuesLogin = array(new Oara_Curl_Parameter('__RequestVerificationToken', $hiddenValue), new Oara_Curl_Parameter('Login', $user), new Oara_Curl_Parameter('Password', $password)); // Login form fields $return = array(); foreach ($valuesLogin as $parameter) { $return[] = $parameter->getKey() . '=' . urlencode($parameter->getValue()); } $arg = implode('&', $return); //Init curl $ch = curl_init(); $options = $this->_client; $options[CURLOPT_URL] = $url; $options[CURLOPT_FOLLOWLOCATION] = true; $options[CURLOPT_POSTFIELDS] = $arg; $options[CURLOPT_POST] = true; curl_setopt_array($ch, $options); $result = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $info = curl_getinfo($ch); //Init curl $ch = curl_init(); $options = $this->_client; $options[CURLOPT_URL] = "http://panel.webepartners.pl/AffiliateTools/Api"; $options[CURLOPT_FOLLOWLOCATION] = true; $options[CURLOPT_POSTFIELDS] = $arg; $options[CURLOPT_POST] = true; curl_setopt_array($ch, $options); $result = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $info = curl_getinfo($ch); $this->_user = urlencode($user); $dom = new Zend_Dom_Query($result); $apiPass = null; $results = $dom->query('a [href*="Authorize"]'); if (count($results) > 0) { $item = $results->current(); $url = $item->attributes->getNamedItem("href")->nodeValue; $parsedUrl = parse_url($url); parse_str($parsedUrl["query"], $parameters); $apiPass = $parameters["password"]; } $this->_pass = $apiPass; }
<?php require 'Zend/Dom/Query.php'; $dom = @DOMDocument::loadHTMLFile('http://sxsw.com/music/shows/bands'); $dom = new Zend_Dom_Query($dom->saveHTML()); $items = $dom->query("#node-794 .content p a"); $artists = array(); $out = fopen('sxsw.csv', 'w'); foreach ($items as $item) { $xml = simplexml_import_dom($item); $data = array(trim((string) $xml), (string) $xml['href']); fputcsv($out, $data, "\t", '"'); } fclose($out);
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $paymentExport = array(); $paymentExport[] = new Oara_Curl_Parameter('session', $this->_sessionId); $urls = array(); $urls[] = new Oara_Curl_Request('http://affiliate.paidonresults.com/cgi-bin/invoice-status.pl?', $paymentExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('#tableID1 tr'); foreach ($results as $result) { $childrenList = $result->childNodes; $numberChildren = $childrenList->length; if ($numberChildren == 18) { $value = $childrenList->item(14)->nodeValue; if (preg_match('/[0-9]+(,[0-9]{3})*(\\.[0-9]{2})?$/', $value, $matches)) { $obj = array(); $obj['pid'] = $childrenList->item(4)->nodeValue; $date = new Zend_Date($childrenList->item(0)->nodeValue, "dd/MMM/yyyy"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['value'] = Oara_Utilities::parseDouble($matches[0]); $obj['method'] = 'BACS'; $paymentHistory[] = $obj; } } } return $paymentHistory; }