<?php
// make_graphviz_peers.php
// October, 2024
// Look for <h1 id=myh1>Trying out <span title='Actually neato -n for this Flow Chart idea'>Dot</span> GraphViz hosted in PHP " . $plus . " Venn Diagram <span id=ssel></span> <a id=pemail title=Email class=share  onclick=emailit(this); style=text-decoration:none;cursor:pointer;>&#128231;</a>&nbsp;<a id=psms title=SMS class=share  onclick=smsit(this); style=text-decoration:none;cursor:pointer;>&#128223;</a></h1
  error_reporting( E_ERROR | E_USER_ERROR );

  $yesrecall='';
  $listis='';
  $selis='';
  $two=2;
  foreach(glob('./*.php') as $filename) {
    $cont=file_get_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($filename));
    if (strpos($filename, '_junk.') === false && strpos($cont, '</' . 'h1>') !== false && strpos($cont, '</ti' . 'tle>') !== false && strpos($cont, 'GraphV' . 'iz hosted in PHP') !== false) {
     if (sizeof(explode('</' . 'h1>', $cont)) <= 3) {
      $hashbit='#' . explode(' - ', explode('</ti' . 'tle>', explode('<ti' . 'tle>', $cont)[1])[0])[-1 + sizeof(explode(' - ', explode('</ti' . 'tle>', explode('<ti' . 'tle>', $cont)[1])[0]))];
      $listis.="/" . basename($filename) . $hashbit . "\n";
      if ($selis == "") {
        $selis='<sup id="supgws" style="vertical-align: top;">&nbsp;<details title="Open to reveal other GraphViz web applications you can navigate to." style="display: inline-block;" id="gvdtls"><summary style="color: #e162bf;list-style-type:' . "'\\\\01F4C8'" . '"></summary><select size="2" id="gvwapps" onchange="if (this.value != ' . "''" . ') { this.style.cursor=' . "'progress'" . '; location.href=this.value; }"><option value="">Optionally select a GraphViz web application below ...</option><option value="/' . basename($filename) . '">' . substr($hashbit,1) . '</option></select></details></sup>';
      } else {
        $two++;
        $selis=str_replace('</select>', '<option value="/' . basename($filename) . '">' . substr($hashbit,1) . '</option></select>', str_replace(' size="' . (-1 + $two) . '"', ' size="' . (0 + $two) . '"', $selis));
      }
     }
    }
  }
  
  $selis=str_replace('"', '\"', $selis);
  
  //file_put_contents('x.x', $listis);
  //echo "<html><body><textarea>" . $listis . "</textarea><h1>Wow " . $selis . "</h1></body></html>";

  if (2 == 2) {
  foreach(glob('./*.php') as $filename) {
    $cont=file_get_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($filename));
    if (strpos($filename, '_junk.') === false && strpos($cont, '</' . 'h1>') !== false && strpos($cont, '</ti' . 'tle>') !== false && strpos($cont, 'GraphV' . 'iz hosted in PHP') !== false) {
     if (sizeof(explode('</' . 'h1>', $cont)) <= 3) {
      if (strpos($cont, '<sup ') !== false) {
        $oldsup='<sup ' . explode('</sup>', explode('<sup ', $cont)[1])[0] . '</sup>';
        $lendiff=abs(strlen($oldsup) - strlen($selis));
        if ($lendiff > 20) {
          file_put_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('.', '_junk.',basename($filename)), $cont);
          $cont=str_replace($oldsup, '', $cont);
          $cont=str_replace('</h1>', $selis . '</h1>', $cont);
          file_put_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($filename), $cont);
          if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
            $listis=$listis;
          } else if (basename($filename) == basename($_SERVER["SCRIPT_FILENAME"])) { // thanks to https://stackoverflow.com/questions/4545878/how-to-know-if-php-script-is-called-via-require-once
            $yesrecall='/' . basename($filename);
          }
       }
      } else {
        file_put_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . str_replace('.', '_junk.',basename($filename)), $cont);
        $cont=str_replace('</h1>', $selis . '</h1>', $cont);
        file_put_contents(rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($filename), $cont);
        if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
            $listis=$listis;
        } else if (basename($filename) == basename($_SERVER["SCRIPT_FILENAME"])) { // thanks to https://stackoverflow.com/questions/4545878/how-to-know-if-php-script-is-called-via-require-once
            $yesrecall='/' . basename($filename);
        }
      }
     }
    }
  }
  }
  
  if ($yesrecall != '') {
    header('Location: ' . $yesrecall);
    exit;
  }

?>
