/** * @param GAQuery $pQuery * @return array */ public function retrieveData(GAQuery $pQuery) { if (!$this->isAuth()) { return null; } $r = new Request($pQuery->get()); $header[] = 'Authorization: GoogleLogin auth=' . $this->getAuth(); $r->setOption(CURLOPT_SSL_VERIFYPEER, 0); $r->setOption(CURLOPT_HTTPHEADER, $header); $r->setOption(CURLOPT_HEADER, false); return SimpleJSON::decode($r->execute()); }
/** * Méthode de demande d'authentication pour le service google souhaité * @return void */ private function login() { $r = new Request(self::URL_LOGIN); $r->setOption(CURLOPT_FOLLOWLOCATION, true); $r->setOption(CURLOPT_SSL_VERIFYPEER, 0); $data = array('accountType' => $this->account_type, 'Email' => $this->email, 'Passwd' => $this->password, 'source' => self::SOURCE, 'service' => $this->service); $r->setDataPost($data); $retour = $r->execute(); $retour = preg_replace("/(\n|\r)/", "", $retour); $toParse = array("Auth", "LSID", "SID"); foreach ($toParse as $var) { if (preg_match("/" . $var . "=(.*)\$/", $retour, $extract, PREG_OFFSET_CAPTURE)) { try { $this->{$var} = $extract[1][0]; $retour = preg_replace("/" . $var . "=.*\$/", "", $retour); } catch (Exception $e) { return; } } else { return; } } }
/** * @return bool */ private function next() { $message = "" . count($this->urlsDone) . " done" . PHP_EOL; $message .= "" . count($this->urlsToCrawl) . " left" . PHP_EOL; if (count($this->urlsToCrawl) == 0) { return false; } $url = array_shift($this->urlsToCrawl); if (in_array($url, $this->urlsDone)) { return true; } $message .= "Loading : " . $url . PHP_EOL; $this->dispatchEvent(new SimpleCrawlerEvent(SimpleCrawlerEvent::OUTPUT, $message)); $r = new Request($url); try { $d = $r->execute(); } catch (\Exception $e) { $d = false; } if (!$d) { $this->urlsDone[] = $url; $redirect = $r->getRedirectURL(); if ($redirect) { $this->urlsToCrawl[] = $redirect; } else { $this->log($url, $r->getResponseHTTPCode(), $r->getRedirectURL()); } return true; } $baseHref = $this->extract('/\\<base href="([^"]+)"/', $d); $title = $this->extract('/\\<title\\>([^<]+)/', $d); $description = $this->extract('/\\<meta name="description" content="([^"]+)"/', $d); preg_match_all('/href\\="([^"]+)"/', $d, $matches); if (isset($matches[1]) && !empty($matches[1])) { foreach ($matches[1] as $u) { if (strpos($u, 'http://') === 0 || strpos($u, 'https://') === 0 || strpos($u, 'javascript:') === 0 || strpos($u, '#') === 0 || $u === "/") { continue; } if (strpos($u, "/") === 0) { $u = substr($u, 1, strlen($u)); } $u = $baseHref . $u; if ($this->deepRunning && !in_array($u, $this->urlsToCrawl) && !in_array($u, $this->urlsDone)) { $this->urlsToCrawl[] = $u; } } } $this->urlsDone[] = $url; $this->log($url, $title, $description); return true; }
/** * Exécute une requête HTTP via CURL * Renvoie le résultat * @throws Exception * @param string $pUrl * @return string */ public static function load($pUrl) { $r = new Request($pUrl); try { $d = $r->execute(); } catch (Exception $e) { throw $e; } return $d; }