Add project
This commit is contained in:
parent
24d316d377
commit
c6f3a863ff
24
README.md
24
README.md
|
@ -1,2 +1,24 @@
|
||||||
# mysqlimagereplacer
|
# mysqlimagereplacer
|
||||||
mySQL image downloader / replacer
|
|
||||||
|
mySQL image downloader / replacer wizard
|
||||||
|
|
||||||
|
v.0.1 alpha
|
||||||
|
|
||||||
|
DWTWL license https://soundragon.su/license/license.html
|
||||||
|
|
||||||
|
This is alpha version written for specific needs. If you want complete and expanded version of this script, then making the request.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
!MAKE BACKUP OF YOUR SQL-TABLE BEFORE YOU TRY THIS SCRIPT!
|
||||||
|
|
||||||
|
requirement: php-xml module
|
||||||
|
|
||||||
|
Using:
|
||||||
|
|
||||||
|
1. Check php-xml is installed.
|
||||||
|
2. Copy files to new subdirectory of your web-server, for example:
|
||||||
|
/mysqlim/
|
||||||
|
3. Add write privilegies for this directory.
|
||||||
|
4. Login to wizard by web-browser:
|
||||||
|
http://yourserver.com/mysqlim/
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* mySQL image replacer - https://github.com/zlaxy/mysqlimagereplacer
|
||||||
|
* v.0.1 alpha - uder DWTWL license https://soundragon.su/license/license.html
|
||||||
|
* exec script
|
||||||
|
*
|
||||||
|
* !MAKE BACKUP OF YOUR SQL-TABLE BEFORE YOU TRY THIS SCRIPT!
|
||||||
|
*/
|
||||||
|
ignore_user_abort(true);
|
||||||
|
ini_set('max_execution_time', '6000');
|
||||||
|
ini_set('max_input_time', '6000');
|
||||||
|
|
||||||
|
function SaveStatus ($status,$raws,$updated,$failed,$deleted,$execdir) {
|
||||||
|
$csvstatusndata[]=$raws;
|
||||||
|
$csvstatusndata[]=$updated;
|
||||||
|
$csvstatusndata[]=$failed;
|
||||||
|
$csvstatusndata[]=$deleted;
|
||||||
|
if ($status=="started") {
|
||||||
|
$fhandle=fopen($execdir."/outdata.csv","w");
|
||||||
|
fputcsv($fhandle,$csvstatusndata);
|
||||||
|
fclose($fhandle);
|
||||||
|
} else
|
||||||
|
if ($status=="finished") unlink ($execdir."/outdata.csv");
|
||||||
|
}
|
||||||
|
|
||||||
|
function DownloadFopen($URL) {
|
||||||
|
if (file_exists(rawurldecode(pathinfo($URL)['basename']))) {
|
||||||
|
$fileprefix=mt_rand(1000000,9999999);
|
||||||
|
file_put_contents($fileprefix.rawurldecode(pathinfo($URL)['basename']), file_get_contents($URL));
|
||||||
|
if (md5_file($fileprefix.rawurldecode(pathinfo($URL)['basename']))==md5_file(rawurldecode(pathinfo($URL)['basename']))) {
|
||||||
|
unlink ($fileprefix.rawurldecode(pathinfo($URL)['basename']));
|
||||||
|
$result=pathinfo($URL)['basename'];
|
||||||
|
} else {
|
||||||
|
if (exif_imagetype($fileprefix.rawurldecode(pathinfo($URL)['basename']))>0) $result=$fileprefix.pathinfo($URL)['basename'];
|
||||||
|
else {
|
||||||
|
unlink ($fileprefix.rawurldecode(pathinfo($URL)['basename']));
|
||||||
|
$result=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file_put_contents(rawurldecode(pathinfo($URL)['basename']), file_get_contents($URL));
|
||||||
|
if (exif_imagetype(rawurldecode(pathinfo($URL)['basename']))>0) $result=pathinfo($URL)['basename'];
|
||||||
|
else {
|
||||||
|
unlink (rawurldecode(pathinfo($URL)['basename']));
|
||||||
|
$result=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$execdir=__DIR__;
|
||||||
|
$fhandle=fopen("indata.csv","r") or $logmessage="emptyindata";
|
||||||
|
$indatacsv=fgetcsv($fhandle, 1024, ",");
|
||||||
|
fclose($fhandle);
|
||||||
|
$dbhost=$indatacsv[0];
|
||||||
|
$dbuser=$indatacsv[1];
|
||||||
|
$dbpass=$indatacsv[2];
|
||||||
|
$dbname=$indatacsv[3];
|
||||||
|
$dbtable=$indatacsv[4];
|
||||||
|
$dbcolumn=$indatacsv[5];
|
||||||
|
$servername=$indatacsv[6];
|
||||||
|
$fixbroken=$indatacsv[7];
|
||||||
|
$dirname=$indatacsv[8];
|
||||||
|
$subdir=$indatacsv[9];
|
||||||
|
$downloadtype=$indatacsv[10];
|
||||||
|
$htmlprefix=$indatacsv[11];
|
||||||
|
$fixalready=$indatacsv[12];
|
||||||
|
$fixundownload=$indatacsv[13];
|
||||||
|
$correctimagenumber=$indatacsv[14];
|
||||||
|
unlink ("indata.csv");
|
||||||
|
|
||||||
|
if ($logmessage=="emptyindata") echo "Can't read data file, please check write pirivlegies for ",$execdir," directory";
|
||||||
|
chdir("../".$dirname);
|
||||||
|
if ($subdir) chdir ($subdir);
|
||||||
|
$dbconnection=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
|
||||||
|
mysqli_set_charset($dbconnection,'utf8');
|
||||||
|
$resulttable=mysqli_query($dbconnection,"SELECT * FROM ".$dbtable);
|
||||||
|
$totalstatus="started";
|
||||||
|
$updatedurls=0;
|
||||||
|
$failedtoupdate=0;
|
||||||
|
$deletedurls=0;
|
||||||
|
$rawsedit=0;
|
||||||
|
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||||
|
while($row=mysqli_fetch_assoc($resulttable)){
|
||||||
|
$originalcontent=$row[$dbcolumn];
|
||||||
|
$newcontent=$originalcontent;
|
||||||
|
if ($fixbroken) {
|
||||||
|
$contentpost=new DOMDocument();
|
||||||
|
$xmlEncodding = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||||
|
$contentpost->loadHTML($xmlEncodding.$originalcontent, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||||
|
$imageTags=$contentpost->getElementsByTagName('img');
|
||||||
|
for ($i = $imageTags->length; --$i >= 0; ) { // http://php.net/manual/class.domnodelist.php#83390
|
||||||
|
$tag = $imageTags->item($i);
|
||||||
|
$imgsrctag=$tag->getAttribute('src');
|
||||||
|
$parsedimgsrctag=parse_url($imgsrctag);
|
||||||
|
if (!((!empty($parsedimgsrctag['host'])&&!empty($parsedimgsrctag['path']))&&(($parsedimgsrctag['scheme']=="http")||($parsedimgsrctag ['scheme']=="https")))) {
|
||||||
|
$tag->parentNode->removeChild($tag);
|
||||||
|
$deletedurls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newcontent=str_replace($xmlEncodding,"",$contentpost->saveHTML());
|
||||||
|
}
|
||||||
|
if ($correctimagenumber>0) {
|
||||||
|
$contentpost=new DOMDocument();
|
||||||
|
$contentpost->loadHTML($newcontent);
|
||||||
|
$imageTags=$contentpost->getElementsByTagName('img');
|
||||||
|
for ($i = $imageTags->length; --$i >= 0; ) { // http://php.net/manual/class.domnodelist.php#83390
|
||||||
|
$tag = $imageTags->item($i);
|
||||||
|
$imgsrctag=$tag->getAttribute('src');
|
||||||
|
$parsedimgsrctag=parse_url($imgsrctag);
|
||||||
|
if ((!empty($parsedimgsrctag['host'])&&!empty($parsedimgsrctag['path']))&&(($parsedimgsrctag['scheme']=="http")||($parsedimgsrctag ['scheme']=="https"))&&(!($parsedimgsrctag['host']==$servername))) {
|
||||||
|
$newimgsrc=DownloadFopen($imgsrctag);
|
||||||
|
if ($newimgsrc) {
|
||||||
|
if ($htmlprefix=="http") {
|
||||||
|
$srcbase="http://".$servername."/".$dirname."/";
|
||||||
|
} else if ($htmlprefix=="https") {
|
||||||
|
$srcbase="https://".$servername."/".$dirname."/";
|
||||||
|
} else {
|
||||||
|
$srcbase="/".$dirname."/";
|
||||||
|
}
|
||||||
|
if ($subdir) $srcbase=$srcbase.rawurlencode($subdir)."/";
|
||||||
|
$newimgsrc=$srcbase.$newimgsrc;
|
||||||
|
$newcontent=str_replace($imgsrctag,$newimgsrc,$newcontent);
|
||||||
|
unset($newimgsrc);
|
||||||
|
$updatedurls++;
|
||||||
|
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||||
|
} else if ($fixundownload==true) {
|
||||||
|
$tag->parentNode->removeChild($tag);
|
||||||
|
$deletedurls++;
|
||||||
|
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||||
|
} else $failedtoupdate++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt = mysqli_prepare($dbconnection, "UPDATE `".$dbtable."` SET `".$dbcolumn."` = ? WHERE `".$dbtable."`.`".$dbcolumn."`=?");
|
||||||
|
mysqli_stmt_bind_param($stmt, 'ss', $newcontent, $originalcontent);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
$rawsedit++;
|
||||||
|
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||||
|
}
|
||||||
|
$totalstatus="finished";
|
||||||
|
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||||
|
echo $updatedurls," urls was downloaded and updated, ",$failedtoupdate," urls was failed to update","<br>\n";
|
||||||
|
if ($fixbroken or $fixundownload) echo $deletedurls, " tags was deleted<br>\n";
|
||||||
|
|
||||||
|
?>
|
|
@ -0,0 +1,337 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* mySQL image replacer - https://github.com/zlaxy/mysqlimagereplacer
|
||||||
|
* v.0.1 alpha - uder DWTWL license https://soundragon.su/license/license.html
|
||||||
|
* interface script
|
||||||
|
*
|
||||||
|
* !MAKE BACKUP OF YOUR SQL-TABLE BEFORE YOU TRY THIS SCRIPT!
|
||||||
|
*
|
||||||
|
* requirement: php-xml module
|
||||||
|
*
|
||||||
|
* todo: curl and $wgetline="wget --timeout=2 http://somedomain/image.jpg";
|
||||||
|
* todo: rawurlencode for non-latin domains
|
||||||
|
*/
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
function PageView() {
|
||||||
|
// First wizard-page
|
||||||
|
if ($_SESSION["step"]==0) {
|
||||||
|
echo "STEP 1: choose database:<br>\n";
|
||||||
|
$_SESSION["subdir"]="images";
|
||||||
|
echo "<form action=index.php method=post>\n";
|
||||||
|
echo " database host: <input type=text name=\"dbhost\" value=\"localhost\" maxlength=255><br>\n";
|
||||||
|
echo " database user: <input type=text name=\"dbuser\" value=\"",$_SESSION["dbuser"],"\" maxlength=255><br>\n";
|
||||||
|
echo " database pass: <input type=password name=\"dbpass\" maxlength=255><br>\n";
|
||||||
|
echo " database name: <input type=text name=\"dbname\" value=\"",$_SESSION["dbname"],"\" maxlength=255><br>\n";
|
||||||
|
echo " type template: <select name=\"dbtype\">\n";
|
||||||
|
echo " <option value=\"Custom\"";
|
||||||
|
if (($_SESSION["template"]=="Custom")||(!$_SESSION["template"])) echo " selected";
|
||||||
|
echo ">Custom</option>\n";
|
||||||
|
echo " <option value=\"Wordpress\"";
|
||||||
|
if ($_SESSION["template"]=="Wordpress") echo " selected";
|
||||||
|
echo ">Wordpress</option>\n";
|
||||||
|
echo " <option value=\"Joomla\"";
|
||||||
|
if ($_SESSION["template"]=="Joomla") echo " selected";
|
||||||
|
echo ">Joomla</option>\n";
|
||||||
|
echo " <option value=\"Drupal\"";
|
||||||
|
if ($_SESSION["template"]=="Drupal") echo " selected";
|
||||||
|
echo ">Drupal</option>\n";
|
||||||
|
echo " </select><br>\n";
|
||||||
|
echo " <input type=submit name=\"next0\" value=\"Next\">\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
if ($_SESSION["error"]=="dbconnection") echo " Error: ", mysqli_connect_error(),"<br>\n";
|
||||||
|
if ($_SESSION["error"]=="dbconnectionname") echo " Error: enter database name.<br>\n";
|
||||||
|
}
|
||||||
|
// Second wizard-page
|
||||||
|
if ($_SESSION["step"]==1) {
|
||||||
|
echo "STEP 2: entries and directories:<br>\n";
|
||||||
|
echo "<form action=index.php method=post>\n";
|
||||||
|
echo " entries located in ",$_SESSION["dbname"],"@",$_SESSION["dbhost"],"<br>\n";
|
||||||
|
echo " Table name: <input type=text name=\"dbtable\" value=\"",$_SESSION["dbtable"],"\" maxlength=255><br>\n";
|
||||||
|
echo " Column name: <input type=text name=\"dbcolumn\" value=\"",$_SESSION["dbcolumn"],"\" maxlength=255><br>\n";
|
||||||
|
echo " Content directory: ~/<input type=text name=\"dirname\" value=\"",$_SESSION["dirname"],"\" maxlength=255><br>\n";
|
||||||
|
echo " <input type=submit name=\"prev1\" value=\"Previous\"> <input type=submit name=\"next1\" value=\"Next\">\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
if ($_SESSION["error"]) echo $_SESSION["error"],"<br>\n";
|
||||||
|
}
|
||||||
|
// Third wizard-page
|
||||||
|
if ($_SESSION["step"]==2) {
|
||||||
|
echo "STEP 3: check data:<br>\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 "<form action=index.php method=post>\n";
|
||||||
|
echo " directory to upload new images:<br>\n";
|
||||||
|
echo " ",getcwd(),"/<input type=text name=\"subdir\" value=\"",$_SESSION["subdir"],"\" maxlength=63> (leave blank if you don't need subdir)<br>\n";
|
||||||
|
echo " type of html-prefix:<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"htmlprefix\" value=\"http\"";
|
||||||
|
if ($_SESSION["htmlprefix"]=="http") echo " checked";
|
||||||
|
echo ">http://<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"htmlprefix\" value=\"https\"";
|
||||||
|
if ($_SESSION["htmlprefix"]=="https") echo " checked";
|
||||||
|
echo ">https://<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"htmlprefix\" value=\"wo\"";
|
||||||
|
if ($_SESSION["htmlprefix"]=="wo") echo " checked";
|
||||||
|
echo ">without prefix and domain name<br>\n";
|
||||||
|
echo " type of download:<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"dwnldtype\" value=\"put\"";
|
||||||
|
if (!($_SESSION["downloadtype"]=="curl")) echo " checked";
|
||||||
|
echo ">file_put_contents<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"dwnldtype\" value=\"curl\"";
|
||||||
|
if ($_SESSION["downloadtype"]=="curl") echo " checked";
|
||||||
|
echo " disabled"; // usopported in alpha version
|
||||||
|
echo ">curl<br>\n";
|
||||||
|
echo " <input type=\"radio\" name=\"dwnldtype\" value=\"wget\"";
|
||||||
|
if ($_SESSION["downloadtype"]=="wget") echo " checked";
|
||||||
|
echo " disabled"; // usopported in alpha version
|
||||||
|
echo ">wget<br>\n";
|
||||||
|
echo " number of rows in table: $resultrows<br>\n";
|
||||||
|
echo " number of rows with imgsrc tags: ",count($_SESSION["imgsrcs"]),"<br>\n";
|
||||||
|
echo " total number of img src tags: $totalimagenumber<br>\n";
|
||||||
|
echo " broken image links: ",$_SESSION["brokenimagenumber"],"<br>\n";
|
||||||
|
echo " already downloaded image links: ",$_SESSION["alreadyimagenumber"],"<br>\n";
|
||||||
|
echo " correct external image links for download: ",$_SESSION["correctimagenumber"],"<br>\n";
|
||||||
|
echo " <input type=checkbox name=fixbroken value=true";
|
||||||
|
if ($_SESSION["fixbroken"]) echo " checked";
|
||||||
|
echo ">delete broken tags?<br>\n";
|
||||||
|
echo " <input type=checkbox name=fixundownload value=true";
|
||||||
|
if ($_SESSION["fixundownload"]) echo " checked";
|
||||||
|
echo ">remove undownloadble tags?<br>\n";
|
||||||
|
echo " <input type=checkbox name=fixalready value=true";
|
||||||
|
if ($_SESSION["fixalready"]) echo " checked";
|
||||||
|
echo " disabled"; // usopported in alpha version
|
||||||
|
echo ">fix prefix to already downloaded tags?<br>\n";
|
||||||
|
echo " <input type=submit name=\"prev2\" value=\"Previous\"> <input type=submit name=\"deta2\" value=\"Details\"> <input type=submit name=\"next2\" value=\"Next\">\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
if ($_SESSION["error"]) echo $_SESSION["error"],"<br>\n";
|
||||||
|
if ($_SESSION["correctimagenumber"]<1) echo "you dont have any external images to download or fix<br>\n";
|
||||||
|
if ($_SESSION["details"]=="step2") {
|
||||||
|
echo "green links will be try to downloaded, yellow (already downloaded) and red (broken) - not:<hr>\n";
|
||||||
|
foreach ($_SESSION["imgsrcs"] as $postnum=>$postimgs) {
|
||||||
|
echo ($postnum+1),":<br>\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 " <font color=green>";
|
||||||
|
else if ($testurl['host']==$_SERVER['SERVER_NAME']) echo " <font color=yellow>";
|
||||||
|
else echo " <font color=red>";
|
||||||
|
echo $imgs,"</font><br>\n";
|
||||||
|
}
|
||||||
|
echo "<hr>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Approve page
|
||||||
|
if ($_SESSION["step"]==3) {
|
||||||
|
echo "STEP 4: approve processing:<br>\n";
|
||||||
|
echo "<form action=index.php method=post>\n";
|
||||||
|
echo " new img src tag will be like that:<br>\n";
|
||||||
|
echo " <i>\"http://",$_SERVER['SERVER_NAME'],"/",$_SESSION["dirname"];
|
||||||
|
if ($_SESSION["subdir"]) echo "/",rawurlencode($_SESSION["subdir"]);
|
||||||
|
echo "/newimage.jpg\"</i><br>\n";
|
||||||
|
echo " will be:<br>\n";
|
||||||
|
if ($_SESSION["correctimagenumber"]>0) {
|
||||||
|
echo $_SESSION["correctimagenumber"]," images uploaded, images placed to ",getcwd();
|
||||||
|
if ($_SESSION["subdir"]) echo "/",$_SESSION["subdir"];
|
||||||
|
echo "/<br>\n";
|
||||||
|
}
|
||||||
|
if ($_SESSION["fixbroken"]) echo $_SESSION["brokenimagenumber"]," tags will be deleted<br>\n";
|
||||||
|
echo " are you sure to proceed?<br>\n";
|
||||||
|
echo " <input type=submit name=\"prev3\" value=\"Previous\"> <input type=submit name=\"next3\" value=\"Next\">\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
}
|
||||||
|
// Start page
|
||||||
|
if ($_SESSION["step"]==4) {
|
||||||
|
$_SESSION["error"]="";
|
||||||
|
echo "RESULT:<br>\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"]."<br>\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<br>\n";
|
||||||
|
}
|
||||||
|
echo "<form action=index.php method=post>\n";
|
||||||
|
echo " <input type=submit name=\"deta4\" value=\"Details\">\n";
|
||||||
|
echo "</form>\n";
|
||||||
|
}
|
||||||
|
// Result page
|
||||||
|
if ($_SESSION["step"]==5) {
|
||||||
|
echo "RESULT:<br>\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,"<br>\n";
|
||||||
|
} else {
|
||||||
|
$logexec=file_get_contents("exec.log");
|
||||||
|
echo $logexec;
|
||||||
|
}
|
||||||
|
echo "<form action=index.php method=post>\n";
|
||||||
|
echo " <input type=submit name=\"deta5\" value=\"Details\">\n";
|
||||||
|
echo "</form>\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;
|
||||||
|
}
|
||||||
|
|
||||||
|
?><!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>image replacer</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php PageView();?>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue