Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ($_SERVER["SERVER_NAME"]=='localhost')
- require 'alinc.php';
- else
- require 'statusparse.inc.php';
- define('ALLPARSED','../zallinf.txt');
- define('TMDIR','../imgtmbs/');
- //--------------------------------------------------
- function get_addr (&$item, $key) {
- preg_match('/src="([^"]*?)("|$)/ims',$item, $out);
- @$item=$out[1];
- }
- //-----------------------------------------------------------------
- // main entrace
- //-----------------------------------------------------------------
- if (!isset($_GET["step"])) {
- session_start();
- session_destroy();
- session_commit();
- }
- //---------------------------------
- session_start();
- //---------------------------------
- if (isset($_SESSION["statusparse"]))
- $statusparse=$_SESSION["statusparse"];
- //else
- //-----------------------start processing
- if (isset($_GET['start'])) {
- $statusparse= new StatusParse(true);
- //-----------------------
- $allpgs = file(ALLPARSED);
- $statusparse->urls=$allpgs;
- $statusparse->initquery='stage_1';
- $_SESSION["statusparse"]=$statusparse;
- session_commit();
- header('Location: '.$_SERVER["PHP_SELF"].'?step');
- }
- //--------------------------------------------processing
- else
- if (isset($_GET['step'])) {
- $processing=false;
- //----------------------------status
- if (isset($_GET["status"])) {
- if ($statusparse->initquery!='fin') {
- echo 'current stage: '.$statusparse->initquery.'<br />';
- echo 'current step: '.$statusparse->step.'<br />';
- if ($statusparse->initquery=='stage_1')
- echo 'current el: '.
- $statusparse->urls[$statusparse->step].'<br />';
- else
- echo 'current el: '.
- $statusparse->elems[$statusparse->step].'<br />';
- echo 'elems: '.count($statusparse->urls).'<br />';
- }
- else
- echo('parse complete');
- exit();
- }
- //------------------------------------------stage 1
- if ($statusparse->initquery=='stage_1') {
- //--------------------------
- if ($statusparse->step<count($statusparse->urls)) {
- $processing=true;
- $statusparse->elems=array_merge($statusparse->elems,
- file($statusparse->urls[$statusparse->step]));
- $statusparse->step++;
- }
- else {
- //-------------prep to stage 5
- $processing=true;
- array_walk($statusparse->elems,'get_addr');
- $statusparse->initquery='stage_5';
- $statusparse->step=0;
- }
- }
- //------------------------------------------stage 5
- if ($statusparse->initquery=='stage_5') {
- if ($statusparse->step<count($statusparse->elems)) {
- $processing=true;
- $el=trim($statusparse->elems[$statusparse->step]);
- $tname=array_pop(explode('/',$el));
- //---------------------------------------
- /*if ($ch=curl_init()) {
- $statusparse->log_res($el);
- curl_setopt($ch, CURLOPT_URL,$el);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($ch, CURLOPT_USERAGENT,
- 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko)'.
- ' Chrome/20.0.1132.57 Safari/536.11');
- $data=curl_exec($ch);
- $statusparse->log_res($data);
- curl_close($ch);
- } else {
- $statusparse->log_res('curl init error');
- }*/
- //---------------------------------------
- //$ss=file_get_contents($el);
- list($w,$h)=getimagesize($el);
- $nh=200;
- $nw=$w*($nh/$h);
- $thumb=imagecreatetruecolor($nw,$nh);
- $source=imagecreatefromjpeg($el);
- imagecopyresampled($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
- imagejpeg($thumb,TMDIR.$tname,100);
- imagedestroy($source);
- imagedestroy($thumb);
- $statusparse->log_res($el.'|ABC|'.TMDIR.$tname);
- $statusparse->step++;
- }
- else {
- $processing=true;
- $statusparse->initquery='fin';
- }
- }
- //--------------------------------------------continue;
- if ($processing) {
- $statusparse->n_redirects++;
- if ($statusparse->n_redirects>15)
- $statusparse->n_redirects=0;
- //-------------------
- $_SESSION["statusparse"]=$statusparse;
- session_commit();
- if ($statusparse->n_redirects==0) {
- echo '<head><script type="text/javascript">'.
- 'setTimeout(function() {location.replace("'.$_SERVER["PHP_SELF"].'?step");},1000)'.
- '</script></head><body>';
- echo 'parsing suspended to prevent error 310 <br />';
- echo '<a href="'.$_SERVER["PHP_SELF"].'?step">continue</a></body>';
- }
- else
- header('Location: '.$_SERVER["PHP_SELF"].'?step');
- }
- else {
- header('Content-type:text/plain; charset=windows-1251');
- $logstr=file_get_contents($statusparse->resfile);
- echo $logstr;
- }
- //------------------------------------------------
- }
- else
- show_form();
- //--------------------------------------------------------
- function show_form() {
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta http-equiv="Cache-Control" content="no-cache" />
- <title>Grab thumbs</title>
- <style type="text/css">
- #statframe {
- position:relative;
- top:10px;
- left:65%;
- width:800px;
- height:300px;
- margin-top:20px;
- margin-left:-400px;
- }
- #statframe iframe {
- border:solid 1px black;
- width:100%;
- height:100%;
- }
- </style>
- <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
- <script type="text/javascript">
- var rr;
- function go(el) {
- var inf=<?='"'.array_pop(explode("/",$_SERVER['PHP_SELF'])).'"'?>;
- zWin=open(inf+'?start','zgoinf');
- var x=frames['statifr'];
- x.document.body.innerHTML='';
- rr=setInterval(function() {
- x.location.replace(inf+'?step&status');
- if (x.document.body.innerHTML.indexOf('parse complete')!=-1) {
- clearInterval(rr);
- }
- },1000)
- }
- //------------------------------------------
- function stop_refr() {
- clearInterval(rr);
- }
- </script>
- </head>
- <body>
- <form onsubmit="go(this);return false;" name="parseform" method="post" enctype="application/x-www-form-urlencoded" >
- <input type="submit" name="submit" value="grab" />
- <input type="button" name="zzu" value="stop" onclick="stop_refr();return false;" />
- </form>
- <div id="statframe">
- <iframe name="statifr"></iframe>
- </div>
- </body>
- <?PHP
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement