upd to 0.2
This commit is contained in:
87
exec.php
87
exec.php
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* mySQL image replacer - https://github.com/zlaxy/mysqlimagereplacer
|
||||
* v.0.1 alpha - uder DWTWL license https://soundragon.su/license/license.html
|
||||
* mySQL image replacer - https://gitlab.com/zlax/mysqlimagereplacer
|
||||
* adopted for php8.2
|
||||
* v.0.2 beta - uder DWTWL license https://soundragon.su/license/license.html
|
||||
* exec script
|
||||
*
|
||||
* !MAKE BACKUP OF YOUR SQL-TABLE BEFORE YOU TRY THIS SCRIPT!
|
||||
@@ -33,9 +34,9 @@ function DownloadFopen($URL) {
|
||||
} else {
|
||||
if (exif_imagetype($fileprefix.rawurldecode(pathinfo($URL)['basename']))>0) $result=$fileprefix.pathinfo($URL)['basename'];
|
||||
else {
|
||||
unlink ($fileprefix.rawurldecode(pathinfo($URL)['basename']));
|
||||
$result=false;
|
||||
}
|
||||
unlink ($fileprefix.rawurldecode(pathinfo($URL)['basename']));
|
||||
$result=false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file_put_contents(rawurldecode(pathinfo($URL)['basename']), file_get_contents($URL));
|
||||
@@ -67,22 +68,40 @@ $htmlprefix=$indatacsv[11];
|
||||
$fixalready=$indatacsv[12];
|
||||
$fixundownload=$indatacsv[13];
|
||||
$correctimagenumber=$indatacsv[14];
|
||||
$filtcolumn=$indatacsv[15];
|
||||
$filtvalue=$indatacsv[16];
|
||||
$ahrefparents=$indatacsv[17];
|
||||
$webarchived=$indatacsv[18];
|
||||
|
||||
unlink ("indata.csv");
|
||||
|
||||
if ($logmessage=="emptyindata") echo "Can't read data file, please check write pirivlegies for ",$execdir," directory";
|
||||
if (isset($logmessage) && $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];
|
||||
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);
|
||||
$filteredpostnumber=0;
|
||||
while($row=mysqli_fetch_assoc($resulttable)){
|
||||
if (!empty($filtcolumn) && !empty($filtvalue)) {
|
||||
if ($row[$filtcolumn] == $filtvalue) {
|
||||
if (!empty($row[$dbcolumn]))
|
||||
$originalcontent=$row[$dbcolumn];
|
||||
$filteredpostnumber++;
|
||||
}
|
||||
} else { if (!empty($row[$dbcolumn]))
|
||||
$originalcontent=$row[$dbcolumn];
|
||||
$filteredpostnumber++;
|
||||
}
|
||||
if (isset($originalcontent)) {
|
||||
$newcontent=$originalcontent;
|
||||
if ($fixbroken) {
|
||||
$contentpost=new DOMDocument();
|
||||
@@ -106,10 +125,25 @@ if ($subdir) chdir ($subdir);
|
||||
$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');
|
||||
if ($ahrefparents) {
|
||||
$aofimg=$contentpost->importNode($tag->parentNode, true);
|
||||
if (isset($aofimg)) {
|
||||
$ahreofimg=$aofimg->getAttribute('href');
|
||||
if ($ahreofimg=="") $ahreofimg=$tag->getAttribute('src');
|
||||
$imgsrctag=$ahreofimg;
|
||||
}
|
||||
} else $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 ($webarchived) {
|
||||
$parsedimgsrctagarch=parse_url($tag->getAttribute('src'));
|
||||
if ($parsedimgsrctagarch['host']==$webarchived) {
|
||||
$webarchivelink="https://web.archive.org/web/20200101id_/".$tag->getAttribute('src');
|
||||
$newimgsrc=DownloadFopen($webarchivelink);
|
||||
} else
|
||||
$newimgsrc=DownloadFopen($imgsrctag);
|
||||
} else
|
||||
$newimgsrc=DownloadFopen($imgsrctag);
|
||||
if ($newimgsrc) {
|
||||
if ($htmlprefix=="http") {
|
||||
$srcbase="http://".$servername."/".$dirname."/";
|
||||
@@ -120,7 +154,7 @@ if ($subdir) chdir ($subdir);
|
||||
}
|
||||
if ($subdir) $srcbase=$srcbase.rawurlencode($subdir)."/";
|
||||
$newimgsrc=$srcbase.$newimgsrc;
|
||||
$newcontent=str_replace($imgsrctag,$newimgsrc,$newcontent);
|
||||
$newcontent=str_replace($tag->getAttribute('src'),$newimgsrc,$newcontent);
|
||||
unset($newimgsrc);
|
||||
$updatedurls++;
|
||||
SaveStatus ($totalstatus,$rawsedit,$updatedurls,$failedtoupdate,$deletedurls,$execdir);
|
||||
@@ -138,9 +172,10 @@ if ($subdir) chdir ($subdir);
|
||||
$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";
|
||||
}
|
||||
$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";
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user