<?php
// one_image_website_generic_changes.php
// April, 2026

$res='';
$pblockuptop='';

if (isset($_POST['offdr'])) {
   $res='<p>Nothing to do.</p>';
   if ($_POST['offdr'] != '') {
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['offdr'])))) {
       foreach(glob($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['offdr'])) . DIRECTORY_SEPARATOR . '*[ph][th][pm]*') as $filename) {
          if (strpos($filename, 'GETME') === false && strpos($filename, 'backup') === false) {
          $cont=file_get_contents($filename);
          $newcont=$cont;
          $parts=explode('image_list = new Array();', $cont);
          $partsagain=explode('initthearr(image_list);', $cont);
          $partsscrone=explode('SCRIPT LANGUAGE=', $cont);
          $partsscr=explode('/onrightclick.js', $cont);
          if (basename($filename) == 'index.php') { // block up the top only
            $newcont=$pblockuptop . $cont;
          } else if (basename($filename) == 'index.html' || basename($filename) == 'index.htm') { // fair few interventions and rearragements
          } else if (strpos(basename($filename),'.htm') !== false) { // one intervention, as required
            if (sizeof($parts) == 2 && sizeof($partsagain) == 1) {
              if (sizeof($partsscrone) == 2 && sizeof($partsscr) == 2) {
                if (strpos($partsscrone[1], '/onrightclick.js') !== false && strpos($parts[0], '<head>') !== false) {
                  $parts[0]=str_replace("<head>", "<head>\n<script type=text/javascript src='/onrightclick.js?rand=86475'></script>\n", $parts[0]);
                  $parts[1]=str_replace("/onrightclick.js", "/onYNFTrightclick.js", $parts[1]);
                }
              }
              $newcont=$parts[0] . "\n image_list = new Array(); \n initthearr(image_list); \n" . $parts[1];
            } else if (sizeof($parts) == 2 && sizeof($partsagain) >= 2) {
              $res=str_replace('<p>Nothing to do.</p>', '<p>Regarding One Image Website folder ' . $_POST['offdr'] . '</p>', $res) . '<p>' . $filename . ' already changed.</p>';
            } else {
              $res=str_replace('<p>Nothing to do.</p>','<p>Regarding One Image Website folder ' . str_replace('+',' ',urldecode($_POST['offdr'])) . '</p>',$res) . '<p>' . $filename . ' not changed.</p>';
            }
          }
          if ($newcont != $cont) {
            $res=str_replace('<p>Nothing to do.</p>','<p>Regarding One Image Website folder ' . str_replace('+',' ',urldecode($_POST['offdr'])) . '</p>',$res) . '<p>' . $filename . ' changed.</p>';
            file_put_contents($filename . '_backup', $cont);
            //file_put_contents($filename, $newcont);
          } else {
            $res=str_replace('<p>Nothing to do.</p>','<p>Regarding One Image Website folder ' . str_replace('+',' ',urldecode($_POST['offdr'])) . '</p>',$res) . '<p>' . $filename . ' not coded for yet.</p>';
          }
          }
       }
     }
   }
}

?>
<html>
<body>
<?php echo $res; ?>
<form method=POST target=_self action='./one_image_website_generic_changes.php'>
<input type=text value='' placeholder='Eg. streetart' name=offdr id=offdr></input>
<input type=submit id=fsub value='Process this One Image Website folder HTML and PHP'></input>
</form>
</body>
</html>
