\n";
$_SESSION["subdir"]="images";
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 view
if ($_SESSION["step"]==1) {
echo "STEP 2: entries and directories:
\n";
echo "\n";
if ($_SESSION["error"]) echo $_SESSION["error"],"
\n";
}
// Third wizard-page view
if ($_SESSION["step"]==2) {
echo "STEP 3: check data:
\n";
$postnumber=0;
$filteredpostnumber=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);
if (!empty($_SESSION["IDcolumn"]))
$_SESSION["imgsrcsID"]=array();
$_SESSION["imgsrcs"]=array();
$_SESSION["imgsrcahrefs"]=array();
// -- Checking table
while($row=mysqli_fetch_assoc($resulttable)) {
$contentpost=new DOMDocument();
if (!empty($_SESSION["filtcolumn"]) && !empty($_SESSION["filtvalue"])) {
if ($row[$_SESSION["filtcolumn"]] == $_SESSION["filtvalue"]) {
if (!empty($row[$_SESSION["dbcolumn"]]))
$contentpost->loadHTML($row[$_SESSION["dbcolumn"]]);
$filteredpostnumber++;
}
} else {
if (!empty($row[$_SESSION["dbcolumn"]]))
$contentpost->loadHTML($row[$_SESSION["dbcolumn"]]);
$filteredpostnumber++;
}
$imageTags=$contentpost->getElementsByTagName('img');
$ahrefImageTags=$imageTags;
$imagenumberinpost=0;
foreach($imageTags as $tag) {
$imagenumberinpost++;
$totalimagenumber++;
if (!empty($_SESSION["IDcolumn"]))
$_SESSION["imgsrcsID"][$postnumber]=$row[$_SESSION["IDcolumn"]];
$_SESSION["imgsrcs"][$postnumber][$imagenumberinpost]=$tag->getAttribute('src');
$aofimg=$contentpost->importNode($tag->parentNode, true);
if (isset($aofimg)) {
$ahreofimg=$aofimg->getAttribute('href');
if ($ahreofimg=="") $ahreofimg=$tag->getAttribute('src');
$_SESSION["imgsrcahrefs"][$postnumber][$imagenumberinpost]=$ahreofimg;
}
else
$_SESSION["imgsrcahrefs"][$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 (isset($testurl['host']) && ($testurl['host']==$_SERVER['SERVER_NAME']))
$_SESSION["alreadyimagenumber"]++;
else $_SESSION["brokenimagenumber"]++;
}
$postnumber++;
}
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);
if (!empty($_SESSION["IDcolumn"]))
echo " (ID ", $_SESSION["imgsrcsID"][$postnum],")";
echo ":
\n";
foreach ($postimgs as $imgnum=>$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 (isset($testurl['host']) && ($testurl['host']==$_SERVER['SERVER_NAME']))
echo " ";
else echo " ";
echo $imgs,", (";
if ($_SESSION["imgsrcahrefs"][$postnum][$imgnum]==$_SESSION["imgsrcs"][$postnum][$imgnum])
echo "";
else echo "";
echo $_SESSION["imgsrcahrefs"][$postnum][$imgnum];
if ($_SESSION["imgsrcahrefs"][$postnum][$imgnum]==$_SESSION["imgsrcs"][$postnum][$imgnum])
echo "";
else echo "";
echo ")
\n";
}
echo "
\n";
}
}
}
// Approve page view
if ($_SESSION["step"]==3) {
echo "STEP 4: approve processing:
\n";
echo "\n";
}
// Start page view
if ($_SESSION["step"]==4) {
$_SESSION["error"]="";
echo "RESULT:
\n";
if ($_SESSION["subdir"]) {
if (!is_dir($_SESSION["subdir"]))
mkdir($_SESSION["subdir"]);
if (!chdir($_SESSION["subdir"]))
$_SESSION["error"]="can't to operate with new directory";
} else {
if (mkdir ("testimuploaddir"))
rmdir("testimuploaddir");
else $_SESSION["error"]="can't to operate 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"];
$csvsessiondata[]=$_SESSION["filtcolumn"];
$csvsessiondata[]=$_SESSION["filtvalue"];
$csvsessiondata[]=$_SESSION["ahrefparents"];
$csvsessiondata[]=$_SESSION["webarchived"];
$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";
}
// Result page view
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 echo "no results
\n";
if (file_exists("exec.log")) {
$logexec=file_get_contents("exec.log");
echo $logexec;
} else echo "no log
\n";
echo "\n";
}
}
// First wizard-page handler
$_SESSION["step"]=0;
$_SESSION["error"]="";
$_SESSION["details"]="";
if (isset($_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";
$_SESSION["IDcolumn"]="ID";
$_SESSION["filtcolumn"]="post_type";
$_SESSION["filtvalue"]="post";
}
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";
}
}
// Second wizard-page handler
if (isset($_POST["prev1"])) {
$_SESSION["dbtable"]=$_POST["dbtable"];
$_SESSION["dbcolumn"]=$_POST["dbcolumn"];
$_SESSION["dirname"]=$_POST["dirname"];
$_SESSION["IDcolumn"]=$_POST["IDcolumn"];
$_SESSION["filtcolumn"]=$_POST["filtcolumn"];
$_SESSION["filtvalue"]=$_POST["filtvalue"];
$_SESSION["step"]=0;
} if (isset($_POST["next1"])) {
$_SESSION["dbtable"]=$_POST["dbtable"];
$_SESSION["dbcolumn"]=$_POST["dbcolumn"];
$_SESSION["dirname"]=$_POST["dirname"];
$_SESSION["IDcolumn"]=$_POST["IDcolumn"];
$_SESSION["filtcolumn"]=$_POST["filtcolumn"];
$_SESSION["filtvalue"]=$_POST["filtvalue"];
$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;
}
// Third wizard-page handler
if (isset($_POST["prev2"])) {
$_SESSION["step"]=1;
$_SESSION["subdir"]=$_POST["subdir"];
}
if (isset($_POST["deta2"])) {
$_SESSION["details"]="step2";
$_SESSION["step"]=2;
$_SESSION["subdir"]=$_POST["subdir"];
$_SESSION["htmlprefix"]=$_POST["htmlprefix"];
$_SESSION["downloadtype"]=$_POST["dwnldtype"];
if (isset($_POST['ahrefparents']) && ($_POST['ahrefparents'] == 'yes'))
$_SESSION["ahrefparents"]=true;
else $_SESSION["ahrefparents"]=false;
if (isset($_POST['webarchived']))
$_SESSION["webarchived"]=$_POST["webarchived"];
else $_SESSION["webarchived"]=false;
if (isset($_POST['fixbroken']) && ($_POST['fixbroken'] == 'yes'))
$_SESSION["fixbroken"]=true;
else $_SESSION["fixbroken"]=false;
if (isset($_POST['fixundownload']) && ($_POST['fixundownload'] == 'yes'))
$_SESSION["fixundownload"]=true;
else $_SESSION["fixundownload"]=false;
if (isset($_POST['fixalready']) && ($_POST['fixalready'] == 'yes'))
$_SESSION["fixalready"]=true;
else $_SESSION["fixalready"]=false;
$uploadsdir=chdir("../".$_SESSION["dirname"]);
}
if (isset($_POST["next2"])) {
$_SESSION["step"]=3;
$_SESSION["subdir"]=$_POST["subdir"];
$_SESSION["htmlprefix"]=$_POST["htmlprefix"];
$_SESSION["downloadtype"]=$_POST["dwnldtype"];
if (isset($_POST['ahrefparents']) && ($_POST['ahrefparents'] == 'yes'))
$_SESSION["ahrefparents"]=true;
else $_SESSION["ahrefparents"]=false;
if (isset($_POST['webarchived']))
$_SESSION["webarchived"]=$_POST["webarchived"];
else $_SESSION["webarchived"]=false;
if (isset($_POST['fixbroken']) && ($_POST['fixbroken'] == 'yes'))
$_SESSION["fixbroken"]=true;
else $_SESSION["fixbroken"]=false;
if (isset($_POST['fixundownload']) && ($_POST['fixundownload'] == 'yes'))
$_SESSION["fixundownload"]=true;
else $_SESSION["fixundownload"]=false;
if (isset($_POST['fixalready']) && ($_POST['fixalready'] == 'yes'))
$_SESSION["fixalready"]=true;
else $_SESSION["fixalready"]=false;
$uploadsdir=chdir("../".$_SESSION["dirname"]);
if (isset($_POST['fixbroken']) && ($_POST['fixbroken'] == 'yes')) {
if (($_SESSION["correctimagenumber"]<1)&($_SESSION["brokenimagenumber"]<1))
$_SESSION["step"]=2;
} else if ($_SESSION["correctimagenumber"]<1)
$_SESSION["step"]=2;
}
// Approve page handler
if (isset($_POST["prev3"])) {
$_SESSION["step"]=2;
$uploadsdir=chdir("../".$_SESSION["dirname"]);
}
if (isset($_POST["next3"])) {
$_SESSION["step"]=4;
$uploadsdir=chdir("../".$_SESSION["dirname"]);
}
// Start page handler
if (isset($_POST["deta4"])) {
$_SESSION["step"]=5;
}
// Result page handler
if (isset($_POST["deta5"])) {
$_SESSION["step"]=5;
}
?>
image replacer