コード例 #1
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new CookieSorage();
     }
     return self::$instance;
 }
コード例 #2
0
 protected function executeInternal($deep)
 {
     $cookies = VarTable::ParseVariables($this->text);
     CookieSorage::getInstance()->cookies = $cookies;
     // file_put_contents(ScriptLoadAction::$cookie_file_name, $cooks);
     $this->oData = $this->iData;
     if ($deep) {
         $this->executeChild();
     } else {
         $this->bData = $this->oData;
     }
 }
コード例 #3
0
 protected function download($sour)
 {
     $sour = $this->correct_url($sour);
     // $this->trace($this->name." from: ".$sour);
     $this->dir = str_replace("/", DIRECTORY_SEPARATOR, $this->dir);
     $this->dir = str_replace("\\", DIRECTORY_SEPARATOR, $this->dir);
     $this->dir .= DIRECTORY_SEPARATOR;
     $this->dir = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $this->dir);
     $dest = "";
     if ($this->original) {
         $dest = urldecode($sour);
         $dest = $this->extractFileName($dest);
         // $this->trace($this->name." to: ".$dest);
         $exists = file_exists($this->dir . $dest);
         if (!$this->override && $exists) {
             $this->trace($this->name . ": {$sour} --X " . $this->dir . $dest);
             return $dest;
         }
     } else {
         $fsour = fopen($sour, 'r');
         $dest .= uniqid('gen-');
         // Пытаемся определить mime-type для определения расширения
         $fheads = stream_get_meta_data($fsour);
         foreach ($fheads["wrapper_data"] as $fhead) {
             if (strpos($fhead, 'Content-Type:') !== false) {
                 $s = explode(' ', trim($fhead));
                 if (count($s) == 2) {
                     $s = explode('/', $s[1]);
                     if (count($s) == 2) {
                         $dest .= "." . $s[1];
                     }
                 }
                 break;
             }
         }
         fclose($fsour);
     }
     /*
             $fsour = fopen($sour, 'r'); 
     $fdest = fopen($this->dir.$dest, 'w+'); 
     $len = stream_copy_to_stream($fsour, $fdest); 
     fclose($fsour); 
     fclose($fdest); 
     */
     $proxy = "";
     $max_times = 20;
     while ($max_times > 0) {
         $this->trace($this->name . ": {$sour} --> " . $this->dir . $dest);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_COOKIE, CookieSorage::getInstance()->cookies);
         // curl_setopt($ch, CURLOPT_COOKIEJAR, self::$cookie_file_name);
         // curl_setopt($ch, CURLOPT_COOKIEFILE, self::$cookie_file_name);
         if (ProxyList::getInstance()->HasProxy()) {
             $proxy = ProxyList::getInstance()->Current();
             curl_setopt($ch, CURLOPT_PROXY, $proxy);
             // curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
         }
         curl_setopt($ch, CURLOPT_URL, $sour);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
         $st = curl_exec($ch);
         $fd = @fopen($this->dir . $dest, "w");
         fwrite($fd, $st);
         @fclose($fd);
         $errno = curl_errno($ch);
         $error = curl_error($ch);
         curl_close($ch);
         if ($errno == 0) {
             break;
         }
         $this->trace($this->name . " ERROR: " . $error);
         $max_times--;
         if ($max_times > 0) {
             $this->trace($this->name . " change proxy: {$proxy} -> " . ProxyList::getInstance()->Next());
         }
     }
     /*
     		$ch = curl_init();
     		curl_setopt($ch, CURLOPT_URL, $sour);
     		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
     
     
     		$st = curl_exec($ch);
     		$fd = @fopen($this->dir.$dest, "w");
     		fwrite($fd, $st);
     		@fclose($fd);
     
     		curl_close($ch);
     */
     return $dest;
 }
コード例 #4
0
 protected function loadText($url)
 {
     $this->trace($this->name . ": " . $url);
     $proxy = "";
     $max_times = 20;
     $i = 1;
     while ($max_times > 0) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_COOKIE, CookieSorage::getInstance()->cookies);
         // curl_setopt($ch, CURLOPT_COOKIEJAR, self::$cookie_file_name);
         // curl_setopt($ch, CURLOPT_COOKIEFILE, self::$cookie_file_name);
         if (ProxyList::getInstance()->HasProxy()) {
             $proxy = ProxyList::getInstance()->Current();
             curl_setopt($ch, CURLOPT_PROXY, $proxy);
             // curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
         }
         // $headers = array('Content-type: text/html; charset='.$this->enc);
         // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_URL, $url);
         // set url to post to
         curl_setopt($ch, CURLOPT_TIMEOUT, 900);
         curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
         curl_setopt($ch, CURLOPT_FAILONERROR, false);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         // allow redirects
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         // return into a variable
         $result = curl_exec($ch);
         // run the whole process
         $errno = curl_errno($ch);
         $error = curl_error($ch);
         curl_close($ch);
         if ($errno == 0) {
             break;
         }
         $this->trace($this->name . " in {$i} time. ERROR: {$errno} {$error}");
         $i++;
         $max_times--;
         if ($max_times > 0 && ProxyList::getInstance()->HasProxy()) {
             $this->trace($this->name . " change proxy: {$proxy} -> " . ProxyList::getInstance()->Next());
         }
     }
     CookieSorage::getInstance()->ParseCookie($result);
     return $result;
 }