\n"; $_SESSION["subdir"]="images"; echo "
\n"; echo " database host:
\n"; echo " database user:
\n"; echo " database pass:
\n"; echo " database name:
\n"; echo " type template:
\n"; echo " \n"; echo "
\n"; if ($_SESSION["error"]=="dbconnection") echo " Error: ", mysqli_connect_error(),"
\n"; if ($_SESSION["error"]=="dbconnectionname") echo " Error: enter database name.
\n"; } // Second wizard-page if ($_SESSION["step"]==1) { echo "STEP 2: entries and directories:
\n"; echo "
\n"; echo " entries located in ",$_SESSION["dbname"],"@",$_SESSION["dbhost"],"
\n"; echo " Table name:
\n"; echo " Column name:
\n"; echo " Content directory: ~/
\n"; echo " \n"; echo "
\n"; if ($_SESSION["error"]) echo $_SESSION["error"],"
\n"; } // Third wizard-page if ($_SESSION["step"]==2) { echo "STEP 3: check data:
\n"; $postnumber=0; $totalimagenumber=0; $_SESSION["correctimagenumber"]=0; $_SESSION["alreadyimagenumber"]=0; $_SESSION["brokenimagenumber"]=0; $dbconnection=mysqli_connect($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpass"],$_SESSION["dbname"]); mysqli_set_charset($dbconnection,'utf8'); $resulttable=mysqli_query($dbconnection,"SELECT * FROM ".$_SESSION["dbtable"]); $resultrows=mysqli_num_rows($resulttable); $_SESSION["imgsrcs"]=array(); // Checking table while($row=mysqli_fetch_assoc($resulttable)){ $contentpost=new DOMDocument(); $contentpost->loadHTML($row[$_SESSION["dbcolumn"]]); $imageTags=$contentpost->getElementsByTagName('img'); $imagenumberinpost=0; foreach($imageTags as $tag) { $imagenumberinpost++; $totalimagenumber++; $_SESSION["imgsrcs"][$postnumber][$imagenumberinpost]=$tag->getAttribute('src'); $testurl=parse_url($_SESSION["imgsrcs"][$postnumber][$imagenumberinpost]); if ((!empty($testurl['host'])&&!empty($testurl['path']))&&(($testurl['scheme']=="http")||($testurl ['scheme']=="https"))&&(!($testurl['host']==$_SERVER['SERVER_NAME']))) $_SESSION["correctimagenumber"]++; else if ($testurl['host']==$_SERVER['SERVER_NAME']) $_SESSION["alreadyimagenumber"]++; else $_SESSION["brokenimagenumber"]++; } $postnumber++; } echo "
\n"; echo " directory to upload new images:
\n"; echo " ",getcwd(),"/ (leave blank if you don't need subdir)
\n"; echo " type of html-prefix:
\n"; echo " http://
\n"; echo " https://
\n"; echo " without prefix and domain name
\n"; echo " type of download:
\n"; echo " file_put_contents
\n"; echo " curl
\n"; echo " wget
\n"; echo " number of rows in table: $resultrows
\n"; echo " number of rows with imgsrc tags: ",count($_SESSION["imgsrcs"]),"
\n"; echo " total number of img src tags: $totalimagenumber
\n"; echo " broken image links: ",$_SESSION["brokenimagenumber"],"
\n"; echo " already downloaded image links: ",$_SESSION["alreadyimagenumber"],"
\n"; echo " correct external image links for download: ",$_SESSION["correctimagenumber"],"
\n"; echo " delete broken tags?
\n"; echo " remove undownloadble tags?
\n"; echo " fix prefix to already downloaded tags?
\n"; echo " \n"; echo "
\n"; if ($_SESSION["error"]) echo $_SESSION["error"],"
\n"; if ($_SESSION["correctimagenumber"]<1) echo "you dont have any external images to download or fix
\n"; if ($_SESSION["details"]=="step2") { echo "green links will be try to downloaded, yellow (already downloaded) and red (broken) - not:
\n"; foreach ($_SESSION["imgsrcs"] as $postnum=>$postimgs) { echo ($postnum+1),":
\n"; foreach ($postimgs as $imgs) { $testurl=parse_url($imgs); if ((!empty($testurl['host'])&&!empty($testurl['path']))&&(($testurl['scheme']=="http")||($testurl ['scheme']=="https"))&&(!($testurl['host']==$_SERVER['SERVER_NAME']))) echo " "; else if ($testurl['host']==$_SERVER['SERVER_NAME']) echo " "; else echo " "; echo $imgs,"
\n"; } echo "
\n"; } } } // Approve page if ($_SESSION["step"]==3) { echo "STEP 4: approve processing:
\n"; echo "
\n"; echo " new img src tag will be like that:
\n"; echo " \"http://",$_SERVER['SERVER_NAME'],"/",$_SESSION["dirname"]; if ($_SESSION["subdir"]) echo "/",rawurlencode($_SESSION["subdir"]); echo "/newimage.jpg\"
\n"; echo " will be:
\n"; if ($_SESSION["correctimagenumber"]>0) { echo $_SESSION["correctimagenumber"]," images uploaded, images placed to ",getcwd(); if ($_SESSION["subdir"]) echo "/",$_SESSION["subdir"]; echo "/
\n"; } if ($_SESSION["fixbroken"]) echo $_SESSION["brokenimagenumber"]," tags will be deleted
\n"; echo " are you sure to proceed?
\n"; echo " \n"; echo "
\n"; } // Start page if ($_SESSION["step"]==4) { $_SESSION["error"]=""; echo "RESULT:
\n"; if ($_SESSION["subdir"]) { mkdir($_SESSION["subdir"]); if (!chdir($_SESSION["subdir"])) $_SESSION["error"]="error to apperate with new directory"; } else { if (mkdir ("testimuploaddir")) rmdir("testimuploaddir"); else $_SESSION["error"]="error to apperate with directory, check privilegies"; } if ($_SESSION["error"]) echo $_SESSION["error"]."
\n"; else { chdir(__DIR__); $csvsessiondata[]=$_SESSION["dbhost"]; $csvsessiondata[]=$_SESSION["dbuser"]; $csvsessiondata[]=$_SESSION["dbpass"]; $csvsessiondata[]=$_SESSION["dbname"]; $csvsessiondata[]=$_SESSION["dbtable"]; $csvsessiondata[]=$_SESSION["dbcolumn"]; $csvsessiondata[]=$_SERVER['SERVER_NAME']; $csvsessiondata[]=$_SESSION["fixbroken"]; $csvsessiondata[]=$_SESSION["dirname"]; $csvsessiondata[]=$_SESSION["subdir"]; $csvsessiondata[]=$_SESSION["downloadtype"]; $csvsessiondata[]=$_SESSION["htmlprefix"]; $csvsessiondata[]=$_SESSION["fixalready"]; $csvsessiondata[]=$_SESSION["fixundownload"]; $csvsessiondata[]=$_SESSION["correctimagenumber"]; $fhandle=fopen("indata.csv","w"); fputcsv($fhandle,$csvsessiondata); fclose($fhandle); exec("php -q exec.php < /dev/null > exec.log &"); echo "Process started, it's take some time. Please press Details for check status
\n"; } echo "
\n"; echo " \n"; echo "
\n"; } // Result page if ($_SESSION["step"]==5) { echo "RESULT:
\n"; if (file_exists("outdata.csv")) { $fhandle=fopen("outdata.csv","r"); $outdatacsv=fgetcsv($fhandle, 1024, ","); fclose($fhandle); $rawsedit=$outdatacsv[0]; $updatedurls=$outdatacsv[1]; $failedtoupdate=$outdatacsv[2]; $deletedurls=$outdatacsv[3]; echo "raws edited: ",$rawsedit,", urldecode downloaded: ",$updatedurls,", failed to download: ",$failedtoupdate,", deleted tags: ",$deletedurls,"
\n"; } else { $logexec=file_get_contents("exec.log"); echo $logexec; } echo "
\n"; echo " \n"; echo "
\n"; } } $_SESSION["step"]=0; $_SESSION["error"]=""; $_SESSION["details"]=""; if ($_POST["next0"]) { $_SESSION["dbhost"]=$_POST["dbhost"]; $_SESSION["dbuser"]=$_POST["dbuser"]; $_SESSION["dbpass"]=$_POST["dbpass"]; $_SESSION["dbname"]=$_POST["dbname"]; $_SESSION["template"]=$_POST["dbtype"]; $dbconnection=mysqli_connect($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpass"],$_SESSION["dbname"]); $_SESSION["step"]=1; if (!$dbconnection) { $_SESSION["step"]=0; $_SESSION["error"]="dbconnection"; } if ($_SESSION["template"]=="Wordpress") { $_SESSION["dbtable"]="wp_posts"; $_SESSION["dbcolumn"]="post_content"; $_SESSION["dirname"]="wp-content/uploads"; } if ($_SESSION["template"]=="Joomla") { $_SESSION["dbtable"]="prefix_content"; $_SESSION["dbcolumn"]="fulltext"; $_SESSION["dirname"]="images/stories"; } if ($_SESSION["template"]=="Drupal") { $_SESSION["dbtable"]="field_data_body"; $_SESSION["dbcolumn"]="body_value"; $_SESSION["dirname"]="sites/default/files"; } if (!$_POST["dbname"]) { $_SESSION["step"]=0; $_SESSION["error"]="dbconnectionname"; } } if ($_POST["prev1"]) { $_SESSION["dbtable"]=$_POST["dbtable"]; $_SESSION["dbcolumn"]=$_POST["dbcolumn"]; $_SESSION["dirname"]=$_POST["dirname"]; $_SESSION["step"]=0; } if ($_POST["next1"]) { $_SESSION["dbtable"]=$_POST["dbtable"]; $_SESSION["dbcolumn"]=$_POST["dbcolumn"]; $_SESSION["dirname"]=$_POST["dirname"]; $dbconnection=mysqli_connect($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpass"],$_SESSION["dbname"]); $columns=mysqli_query($dbconnection, "SHOW COLUMNS FROM ".$_SESSION["dbtable"]); if (!$columns) { $_SESSION["error"]=mysqli_error(); $_SESSION["step"]=1; } if (mysqli_num_rows($columns)>0) { $_SESSION["error"]="Column not found"; while ($row = mysqli_fetch_assoc($columns)) if ($row[Field]==$_SESSION["dbcolumn"]) $_SESSION["error"]=""; } else $_SESSION["error"]="Table is empty or not exists"; $uploadsdir=chdir("../".$_SESSION["dirname"]); if ($uploadsdir) { if (!is_writeable(getcwd())) $_SESSION["error"]="Cant write to directory, check previlegies"; } else $_SESSION["error"]="Cant open directory"; if (!$_SESSION["error"]) $_SESSION["step"]=2; else $_SESSION["step"]=1; } if ($_POST["prev2"]) { $_SESSION["step"]=1; $_SESSION["subdir"]=$_POST["subdir"]; } if ($_POST["deta2"]) { $_SESSION["details"]="step2"; $_SESSION["step"]=2; $_SESSION["subdir"]=$_POST["subdir"]; $_SESSION["htmlprefix"]=$_POST["htmlprefix"]; $_SESSION["downloadtype"]=$_POST["dwnldtype"]; $_SESSION["fixbroken"]=$_POST["fixbroken"]; $_SESSION["fixundownload"]=$_POST["fixundownload"]; $_SESSION["fixalready"]=$_POST["fixalready"]; $uploadsdir=chdir("../".$_SESSION["dirname"]); } if ($_POST["next2"]) { $_SESSION["step"]=3; $_SESSION["subdir"]=$_POST["subdir"]; $_SESSION["htmlprefix"]=$_POST["htmlprefix"]; $_SESSION["downloadtype"]=$_POST["dwnldtype"]; $_SESSION["fixbroken"]=$_POST["fixbroken"]; $_SESSION["fixundownload"]=$_POST["fixundownload"]; $_SESSION["fixalready"]=$_POST["fixalready"]; $uploadsdir=chdir("../".$_SESSION["dirname"]); if ($_POST["fixbroken"]) { if (($_SESSION["correctimagenumber"]<1)&($_SESSION["brokenimagenumber"]<1)) $_SESSION["step"]=2; } else if ($_SESSION["correctimagenumber"]<1) $_SESSION["step"]=2; } if ($_POST["prev3"]) { $_SESSION["step"]=2; $uploadsdir=chdir("../".$_SESSION["dirname"]); } if ($_POST["next3"]) { $_SESSION["step"]=4; $uploadsdir=chdir("../".$_SESSION["dirname"]); } if ($_POST["deta4"]) { $_SESSION["step"]=5; } if ($_POST["deta5"]) { $_SESSION["step"]=5; } ?> image replacer