pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP paste-bin - collaborative debugging tool View Help


Posted by iisonly on Thu 18th Jan 13:55
download | new post

  1. <?php
  2. /** Rate.ee pildi ripper
  3. * @author Tanel Puhu <[email protected]>
  4. * @version 1.0
  5. */
  6.  
  7. $salve_yle = true;
  8. define("DIR", "Pildid");
  9.  
  10. function microtime_float()
  11.     {
  12.        list($usec, $sec) = explode(" ", microtime());
  13.        return ((float)$usec + (float)$sec);
  14.     }
  15.  
  16.  
  17. function bar($x, $of)
  18.     {
  19.         if($x>$of) $x = $of;
  20.         $laius = 60; //22
  21.         $tarne = floor(($x/$of)*($laius));
  22.         $pros = $x*100/$of;
  23.         $riba = " [".str_repeat(' ', $laius)."]".str_repeat(chr(8),$laius+1);
  24.         $riba.= str_repeat("*", $tarne);
  25.         $riba.= @str_repeat(" ", $laius-$tarne-1);
  26.         $riba.=  "] ";
  27.         echo $riba;
  28.         printf("%-6s",    round($pros,2)."%");
  29.         echo str_repeat(chr(8), strlen($riba));
  30.     }
  31.    
  32.  
  33. function csize($byte)
  34.   {
  35.     $suf = array('b','Kb','Mb','Gb');
  36.     $n=0;
  37.     while($byte>=1024)
  38.       {
  39.         $byte = $byte/1024;
  40.         $n++;
  41.       }
  42.     return round($byte,2).$suf[$n];
  43.   }
  44.  
  45. function read ($length='255')
  46.     {
  47.       if (!isset ($GLOBALS['StdinPointer']))
  48.           {
  49.              $GLOBALS['StdinPointer'] = fopen ("php://stdin","r");
  50.           }
  51.       $line = fgets ($GLOBALS['StdinPointer'],$length);
  52.       return trim ($line);
  53.     }
  54.  
  55.         echo "Sisesta oma kasutajanimi : ";
  56.         $username = read();
  57.         echo "Sisesta oma parool : ";
  58.         $password = read();
  59.         echo str_repeat("\n", 1024);
  60.         #echo str_repeat(chr(8), strlen($password));
  61.         #echo str_repeat("*", strlen($password));
  62.  
  63.  
  64.     if(!file_exists(DIR)) mkdir(DIR);
  65.     echo "Login sisse...";
  66.    $curl = curl_init();
  67.    curl_setopt($curl, CURLOPT_URL, "http://www.rate.ee/login.php" );
  68.    curl_setopt($curl, CURLOPT_POST, 1 );
  69.    curl_setopt($curl, CURLOPT_POSTFIELDS, 'username='.$username.'&password='.$password.'&act=login');
  70.    curl_setopt ($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
  71.       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  72.       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  73.       curl_setopt($curl, CURLOPT_HEADER, 0);
  74.    $store = curl_exec ($curl);
  75.  
  76.     echo " => valmis!\n";
  77.     echo "Laen kontakte...";
  78.     $url = "http://www.rate.ee/friends.php";
  79.     curl_setopt($curl, CURLOPT_URL, $url);
  80.     $s = curl_exec($curl);
  81.  
  82. $arr = explode("WIDTH=14 HEIGHT=14 BORDER=0 ALT=", $s);
  83. unset($arr[0]);
  84. foreach((array) $arr as $i=>$a)
  85.     {
  86.         $arr[$i] = str_replace("offline> ", "", $arr[$i]);
  87.         $arr[$i] = str_replace("online> ", "", $arr[$i]);
  88.         $nimed[$i] = current(explode("</A>", $arr[$i]));
  89.         #if($i<=1) break;
  90.     }
  91.  
  92.         $h = fopen("nimed.php","w");
  93.         fwrite($h, "<?php\n\$nimed = ".var_export($nimed,1).";\n?>");
  94.         fclose($h);
  95. curl_close($curl);
  96. echo " => valmis!\n";
  97.  
  98. include "nimed.php";
  99. echo "Leian hindamislehe adred....\n";
  100.  
  101. $sott = count($nimed);
  102. $pros = $n = 0;
  103. foreach((array) $nimed as $nimi)
  104.         {
  105.            $curl = curl_init();
  106.             $url = "http://www.rate.ee/users/".$nimi."/";
  107.               curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  108.               curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  109.               curl_setopt($curl, CURLOPT_HEADER, 0);
  110.             curl_setopt($curl, CURLOPT_URL, $url);
  111.             $s = curl_exec($curl);
  112.                 $pildid = explode("<TD VALIGN=bottom><A HREF=http://www.rate.ee/show.php?id=", $s);
  113.                 unset($pildid[0]);
  114.                
  115.                 foreach((array)$pildid as $id=>$val)
  116.                     $pildid[$id] = current(explode("><IMG", $pildid[$id]));
  117.                 $imgs[$nimi] = $pildid;
  118.  
  119.             curl_close($curl);
  120.             $n++;
  121.             #echo round(100*$n/$sott,2)."% valmis \t\t $nimi (".count($pildid).". pilt/i) \t\t \n";
  122.             bar($n, $sott);
  123.         }
  124.     $h = fopen("imgs.php","w");
  125.     fwrite($h, "<?php\n\$imgs = ".var_export($imgs,1).";\n?>");
  126.     fclose($h);
  127. include "imgs.php";
  128.  
  129. echo "\nLeian suurte piltide adred...\n";
  130.  
  131. $sott=0;
  132. foreach((array)$imgs as $user=>$list)    foreach((array)$list as $im) $sott++;      //100
  133. $n = 0;                                                                                                                               //x
  134. foreach((array)$imgs as $user=>$list)
  135. {
  136.     foreach((array)$list as $im)
  137.         {
  138.                 $url = "http://www.rate.ee/show.php?id=".$im;
  139.                 $n++;
  140.                 #echo " $n) $url => ";
  141.                 if(!file_exists(DIR."/$im.jpg") or file_exists(DIR."/$im.jpg") and filesize(DIR."/$im.jpg")==0)
  142.                     {
  143.                        $curl = curl_init();
  144.                           curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  145.                           curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  146.                           curl_setopt($curl, CURLOPT_HEADER, 0);
  147.                         curl_setopt($curl, CURLOPT_URL, $url);
  148.                         $s = curl_exec($curl);
  149.                         curl_close($curl);
  150.                         $large_img = explode("<IMG SRC=http://pics.rate.ee/dating/", $s);
  151.                         $c = "http://pics.rate.ee/dating/".current(explode(" ", $large_img[1]));
  152.                         $large_imgs[$im] = $c;
  153.                         #echo " pilt lisatud!";
  154.                     } else {
  155.                         #echo " juba olemas!";
  156.                     }
  157.                 #echo " (".round(100*$n/$sott, 2)."%)\n";
  158.                 bar($n, $sott);
  159.         }
  160. }
  161.     $h = fopen("large_imgs.php","w");
  162.     fwrite($h, "<?php\n\$large_imgs = ".var_export($large_imgs,1).";\n?>");
  163.     fclose($h);
  164.  
  165. include "large_imgs.php";
  166.  
  167. $sott = count($large_imgs);         //100
  168. $n = 0;                                                       //x
  169.  
  170. echo "\nSalvestan $sott. pilti...\n";
  171. foreach((array)$large_imgs as $im=>$url)
  172.     {
  173.                     $target = DIR."/$im.jpg";
  174.                     #echo "   $target => ";
  175.         $start = microtime_float();
  176.                    $curl = curl_init();
  177.                       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  178.                       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  179.                       curl_setopt($curl, CURLOPT_HEADER, 0);
  180.                     curl_setopt($curl, CURLOPT_URL, $url);
  181.                     $s = curl_exec($curl);
  182.                     curl_close($curl);
  183.                         if(file_exists($target)) $tyyp = "w"; else $tyyp = "x";
  184.                         $h = fopen($target, $tyyp);
  185.                         fwrite($h, $s);
  186.                         fclose($h);
  187.         $end = microtime_float();
  188.                         $n++;
  189.                         #echo "done! (".csize(strlen($s)).") (".csize(strlen($s)/($end-$start))."/s) (".round(100*$n/$sott,2)."%)\n";
  190.                         bar($n, $sott);
  191.     }
  192.  
  193. echo "\nK6ik valmis!!!!\n";
  194.  
  195. ?>

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings