public static function createCheckoutRequest(Credentials $credentials, PaymentRequest $paymentRequest) { LogPagSeguro::info("PaymentService.Register(" . $paymentRequest->toString() . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); try { $connection = new HttpConnection(); $connection->post(self::buildCheckoutRequestUrl($connectionData), PaymentParser::getData($paymentRequest), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new HttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $PaymentParserData = PaymentParser::readSuccessXml($connection->getResponse()); $paymentUrl = self::buildCheckoutUrl($connectionData, $PaymentParserData->getCode()); LogPagSeguro::info("PaymentService.Register(" . $paymentRequest->toString() . ") - end {1}" . $PaymentParserData->getCode()); break; case 'BAD_REQUEST': $errors = PaymentParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("PaymentService.Register(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("PaymentService.Register(" . $paymentRequest->toString() . ") - error " . $e->getOneLineMessage()); throw $e; break; } return isset($paymentUrl) ? $paymentUrl : false; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
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(); }
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(); $contador = 0; $DOM = new DOMDocument(); $url_array = explode(PHP_EOL, file_get_contents('../file/cats_list.ccd')); $contador = 0; while (count($url_array) > 0) { $url = array_shift($url_array); get_dom($url, $DOM, $http); $paginator = $DOM->getElementById('pagination_next_bottom'); if ($paginator != null) { getProductsLinks($DOM); $link_paginator = $paginator->getElementsByTagName('a'); $link_number = $link_paginator->item(0)->getAttribute('href'); $pages = substr($link_number, -1) . '<br/>'; for ($i = 2; $i <= $pages; $i++) { $http->get($url . '?p=' . $i, true); get_dom($url, $DOM, $http); getProductsLinks($DOM); } } else { getProductsLinks($DOM); } } $http->close(); }
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(); }
/** * Returns a transaction from a notification code * * @param Credentials $credentials * @param String $notificationCode * @throws PagSeguroServiceException * @throws Exception * @return a transaction * @see Transaction */ public static function checkTransaction(Credentials $credentials, $notificationCode) { LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); try { $connection = new HttpConnection(); $connection->get(self::buildTransactionNotificationUrl($connectionData, $notificationCode), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new HttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': // parses the transaction $transaction = TransactionParser::readTransaction($connection->getResponse()); LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - end " . $transaction->toString() . ")"); break; case 'BAD_REQUEST': $errors = TransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::info("NotificationService.CheckTransaction(notificationCode={$notificationCode}) - error " . $e->getOneLineMessage()); throw $e; break; } return isset($transaction) ? $transaction : null; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
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(); $contador = 0; $DOM = new DOMDocument(); $url_array = explode(PHP_EOL, file_get_contents('../file/cats_list.ccd')); while (count($url_array) > 0 && $contador < 400) { $url = array_shift($url_array); if ($url == null || ($url = " ")) { continue; } get_dom($url, $DOM, $http); $paginator = $DOM->getElementById('pagination_next_bottom'); if ($paginator != null) { getProductsLinks($DOM); $link_paginator = $paginator->previousSibling; while ($link_paginator->nodeType !== 1) { $link_paginator = $link_paginator->previousSibling; } $link_last = $link_paginator->getElementsByTagName('a'); $link_number = $link_last->item(0)->getAttribute('href'); $pages = substr($link_number, -1) . '<br/>'; for ($i = 2; $i <= $pages; $i++) { echo $i . '<br />'; $http->get($url . '?id_category=58&n=9&p=' . $i, true); get_dom($url . '?id_category=58&n=9&p=' . $i, $DOM, $http); $contador = $contador + getProductsLinks($DOM); } } else { $contador = $contador + getProductsLinks($DOM); } } $http->close(); if (count($url_array) > 0) { file_put_contents("../file/cats_list.ccd", ""); while (count($url_array) > 0) { $my_url = array_shift($url_array); file_put_contents("../file/cats_list.ccd", $my_url . PHP_EOL, FILE_APPEND); } } echo "</br>Se han procesado: " . $contador . " urls</br>"; echo "Quedan " . count($url_array) . " por procesar<br />"; }
$url = 'https://api.twitter.com/1.1/search/tweets.json'; $getfield = '?q=%23meat&count=25'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $data_twitter = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true); foreach ($data_twitter['statuses'] as $statuse) { //Formato a fecha $date = new DateTime($statuse['created_at']); $date->modify('-3 hours'); $date_format = $date->format('d/m/Y H:i:s'); //Construcción de array para json $data_post[] = array('type' => 'twitter', 'content' => $statuse['text'], 'date' => $date_format, 'likes' => $statuse['favorite_count']); } //fin twitter //Instagram $http = new HttpConnection(); $http->init(); $data_instagram = json_decode($http->get("https://api.instagram.com/v1/tags/meat/media/recent?access_token=44110995.1677ed0.6d87a7ce19f544c99e2912686465de59&count=25"), true); $http->close(); foreach ($data_instagram['data'] as $data) { //Formato a fecha $horas_restantes = 4; $date_format = $data['created_time'] - $horas_restantes * 3600; $date_format = date('d/m/Y H:i:s', $date_format); //Construcción de array para json $data_post[] = array('type' => 'instagram', 'content' => $data['images']['standard_resolution']['url'] . ' ' . $data['caption']['text'], 'date' => $date_format, 'likes' => $data['likes']['count']); } //fin instagram //Router $router = new AltoRouter(); $router->setBasePath('');
if (isset($_POST['rst'])) { unlink('file/product.ccd'); unlink('file/products.csv'); unlink('file/url_list.ccd'); unlink('file/error_url.ccd'); } $count_success = 0; $count_failed = 0; if (!empty($_POST['url_single'])) { $url_array[] = $_POST['url_single']; } else { //Lectura del xml echo "<p>Leyendo fichero xml</p>"; $url_array = leyendo_xml($url_xml); } $http = new HttpConnection(); //$http->setCookiePath("cookies/"); $http->init(); /*$registration = array('email'=>'*****@*****.**','passwd'=>"Ayudasmayores",'back'=>"my-account","SubmitLogin"=>""); $http->post("http://cosmomedica.com/shop/autenticacion",$registration,true,true);*/ if (isset($user) && isset($pass)) { $registration = array('email' => $user, 'passwd' => $pass, 'back' => "my-account", "SubmitLogin" => ""); $http->post($site_url, $registration, true, true); echo "<p>registrandose en la aplicacion</p>"; } else { $http->get($site_url, true); } $ref_shop = ''; try { $DOM = new DOMDocument(); include $script;
/** * Constructor * * @param mixed url a string or a peer.URL object * @param array env environment */ public function __construct($url, $env) { parent::__construct($url); $this->request->setEnvironment($env); }
/** * Save the cookies to the sessions and remember all of the parents members. */ public function __sleep() { $this->saveCookiesToSession(); return parent::__sleep(); }
/** * Search transactions abandoned associated with this set of credentials within a date range * * @param Credentials $credentials * @param String $initialDate * @param String $finalDate * @param integer $pageNumber * @param integer $maxPageResults * @return a object of TransactionSerachResult class * @see TransactionSearchResult * @throws PagSeguroServiceException * @throws Exception */ public static function searchAbandoned(Credentials $credentials, $initialDate, $finalDate, $pageNumber, $maxPageResults) { LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - begin"); $connectionData = new PagSeguroConnectionData($credentials, self::serviceName); $searchParams = array('initialDate' => PagSeguroHelper::formatDate($initialDate), 'finalDate' => PagSeguroHelper::formatDate($finalDate), 'pageNumber' => $pageNumber, 'maxPageResults' => $maxPageResults); try { $connection = new HttpConnection(); $connection->get(self::buildSearchUrlAbandoned($connectionData, $searchParams), $connectionData->getServiceTimeout(), $connectionData->getCharset()); $httpStatus = new HttpStatus($connection->getStatus()); switch ($httpStatus->getType()) { case 'OK': $searchResult = TransactionParser::readSearchResult($connection->getResponse()); LogPagSeguro::info("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $searchResult->toString()); break; case 'BAD_REQUEST': $errors = TransactionParser::readErrors($connection->getResponse()); $e = new PagSeguroServiceException($httpStatus, $errors); LogPagSeguro::error("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; default: $e = new PagSeguroServiceException($httpStatus); LogPagSeguro::error("TransactionSearchService.searchAbandoned(initialDate=" . PagSeguroHelper::formatDate($initialDate) . ", finalDate=" . PagSeguroHelper::formatDate($finalDate) . ") - end " . $e->getOneLineMessage()); throw $e; break; } return isset($searchResult) ? $searchResult : false; } catch (PagSeguroServiceException $e) { throw $e; } catch (Exception $e) { LogPagSeguro::error("Exception: " . $e->getMessage()); throw $e; } }
/** * Sends an HTTP request using the POST method * * @param string data Content to be sent * @return string Response from remote server **/ function POST($data) { parent::POST($data); $this->error = false; $this->headers['Content-length'] = strlen($data); $path = $this->urlInfo['path']; // NOTE: the entire URL is required for proxy connections if ($this->isOpened()) { $url = $path; } else { $url = $this->url; } $out = "POST {$url} HTTP/1.1\r\n"; foreach ($this->headers as $header => $value) { $out .= "{$header}: {$value}\r\n"; } $out .= "\r\n" . $data; if ($this->open()) { $this->write($out); $response = $this->read(); if (!$this->keepAlive) { $this->close(); } return $response; } return false; }
/** * Perform this action * * @param string[] args */ public function perform(array $args) { $installation = new Installation(); $installation->setBase(new Folder(isset($args[0]) ? $args[0] : dirname(Runtime::getInstance()->bootstrapScript()) . '/..')); $force = in_array('-f', $args); with($version = $installation->getVersion()); Console::writeLine('===> Local version ', $version, ' @ ', $installation->getBase()); if (strstr($version, '-dev')) { Console::writeLine('*** Cannot update development checkouts'); return 2; } // Query releases website for newer versions $c = new HttpConnection(self::UPGRADE_URL); $r = $c->get(new RequestData($version)); switch ($r->getStatusCode()) { case HttpConstants::STATUS_OK: case HttpConstants::STATUS_NOT_EXTENDED: Console::writeLine('*** ', $this->readLine($r->getInputStream())); return 2; case HttpConstants::STATUS_SEE_OTHER: $upgrade = $r->getHeader('X-Upgrade-To'); $base = $r->getHeader('Location'); Console::writeLine('---> Upgrading to ', $upgrade, ' (', $base, ')'); $target = new Folder($installation->getBase(), $upgrade); $target->exists() || $target->create(); // Verify dependencies $this->extract($base, 'depend', $target); with($p = new Properties($target->getURI() . 'depend.ini')); $verify = 1; $rtversion = phpversion(); $extensions = array_flip(array_map('strtolower', get_loaded_extensions())); foreach ($p->readSection('php') as $op => $compare) { if (!version_compare(phpversion(), $compare, $op)) { $verify &= $this->error('PHP version ' . $op . ' ' . $compare . ' required, have ' . $rtversion); } } foreach ($p->readSection('ext.required') as $ext => $usage) { if (!isset($extensions[$ext])) { $verify &= $this->error('PHP Extension ' . $ext . ' required for ' . $usage); } } foreach ($p->readSection('ext.conflict') as $ext => $usage) { if (isset($extensions[$ext])) { $verify &= $this->error('PHP Extension ' . $ext . ' conflicts (' . $usage . ')'); } } foreach ($p->readSection('ext.optional') as $ext => $usage) { if (!isset($extensions[$ext])) { $verify &= $this->error('PHP Extension ' . $ext . ' not found, needed for ' . $usage . ' (ignoring)'); } } foreach ($p->readSection('ini') as $setting => $match) { $value = ini_get($setting); if (!preg_match($match, $value)) { $verify &= $this->error('PHP .ini setting ' . $setting . ' needs to match ' . $match . ' (but is ' . $value . ')'); } } // Remove depend.ini, finally check if we should continue create(new File($p->getFilename()))->unlink(); if (!$verify) { if (!$force) { return 3; } Console::writeLine('!!! Ignoring errors because -f was passed'); } // Download base, tools, libraries and meta information $this->extract($base, 'base', $target); $this->extract($base, 'tools', $target); $this->extract($base, 'lib', $target); $this->extract($base, 'meta-inf', $target); // Verify it works by running the XP Framework core unittests $tests = array('net.xp_framework.unittest.core.**'); Console::writeLine('---> Running tests with [USE_XP=', $upgrade, ']:'); $rt = Runtime::getInstance(); set_include_path(implode(PATH_SEPARATOR, array(rtrim($target->getURI(), DIRECTORY_SEPARATOR), '', $target->getURI() . 'lib' . DIRECTORY_SEPARATOR . 'xp-net.xp_framework-' . $upgrade . '.xar'))); with($p = $rt->newInstance($rt->startupOptions(), 'class', 'xp.unittest.Runner', $tests)); $p->in->close(); while (!$p->out->eof()) { Console::writeLine($p->out->readLine()); } while (!$p->err->eof()) { Console::writeLine($p->err->readLine()); } $exit = $p->close(); // Nonzero exit means failure if (0 !== $exit) { Console::writeLine('*** Test run failed, please consult above error messsages'); Console::writeLine($p->getCommandLine()); return 2; } Console::writeLine('===> Done, installed @ ', $target); return 0; default: throw new IllegalStateException('Unexpected response ' . xp::stringOf($r)); } }
<?php header('Content-Type: text/html; charset=utf-8'); //error_reporting(E_ALL ^ E_WARNING); include "../classes/httpFile.php"; //include("classes/product.php"); include "../functions/crawler_functions.php"; $url = $_POST['url']; $script = $_POST['script']; echo $url . ' ' . $script; $http = new HttpConnection(); //$http->setCookiePath("cookies/"); $http->init(); /*$registration = array('email'=>'*****@*****.**','passwd'=>"Ayudasmayores",'back'=>"my-account","SubmitLogin"=>""); $http->post("http://cosmomedica.com/shop/autenticacion",$registration,true,true);*/ $http->get($url, true); echo "<p>registrandose en la aplicacion</p>"; $DOM = new DOMDocument(); get_dom($url, $DOM, $http); $count_success = 0; include "../mainscripts/cat/" . $script; getCats($DOM); //echo "<br />"; //opcciones finales $http->close(); echo "<p>Se han procesado {$count_success} urls correctamente</p>"; echo "<a href='getProducts.php?parser=" . $script . "' class='btn-type'>Obtener Productos</a>"; /* $configuracion['variables']['ref_count'] = $reference_count; $achivo_contenido = ";<?php die(); ?>".PHP_EOL.put_ini_file(null,$configuracion); file_put_contents('crawler.conf.php', $achivo_contenido); echo "<p>Se han procesado $count_success urls correctamente</p>";