<?php
// cow_says_insertion.php
// RJM Programming - November, 2026

  $wper="100";
  $hval="400";
  $bs="1.0";
  if (isset($_POST['lhdiag']) || isset($_GET['lhdiag'])) {
  $wper="125";
  $hval="800";
  $bs="0.75";
  }
  if (!isset($_POST['lhdiag']) && isset($_GET['lhdiag'])) {
    if (substr(str_replace('+',' ',urldecode($_GET['lhdiag'])),0,7) == 'cowsay ') {
      $_POST['lhdiag']=$_GET['lhdiag'];
    }
  }
  if (!isset($_POST['rhdiag']) && isset($_GET['rhdiag'])) {
    if (substr(str_replace('+',' ',urldecode($_GET['rhdiag'])),0,7) == 'cowsay ') {
      $_POST['rhdiag']=$_GET['rhdiag'];
    }
  }
  $cb="For stegosaurus enter -c \"stegosaurus\" ";
  $sb=" -c \"stegosaurus\" ";
  $sbtwo=" -t ";
  $lts='|';
  $gts='|';
  $clist="beavis, cheese, cow, daemon, dragon, fox, ghostbusters, kitty, meow, miki, milk, octopus, pig, stegosaurus, stimpy, trex, turkey, turtle, tux";
  $clistsw="-c";
if (strtoupper(PHP_OS) == "DARWIN") {
$lts='<';
$gts='>';
$revstr="";
$sb=" -r -g -p ";
$sbtwo=" ";
$cb="For random greedy paranoid enter -r -g -p";
$clist="actually, alpaca, beavis.zen, blowfish, bong, bud-frogs, bunny, cheese, cower, cupcake, daemon, default, dragon, dragon-and-cow, elephant, elephant-in-snake, eyes, flaming-sheep, fox, ghostbusters, head-in, hellokitty, kiss, kitty, koala, kosh, llama, luke-koala, mech-and-cow, meow, milk, moofasa, moose, mutilated, ren, sheep, skeleton, small, stegosaurus, stimpy, supermilker, surgery, sus, three-eyes, turkey, turtle, tux, udder, vader, vader-koala, www";
$clistsw="-f";
}

function otherwayaround($instuff) {
  global $revstr, $lts, $gts;
  $outstuff=$instuff;
  if (strpos($instuff,$lts) !== false && strpos($instuff,$gts) !== false) {
    $revstr=explode($gts, explode($lts, $instuff)[1])[0];
    if (trim($revstr) != "") {
      $outstuff=str_replace($lts . $revstr . $gts, $lts . strrev($revstr) . $gts, $instuff);
    }
  }
  return $instuff;
}

$lhthingo=(isset($_POST['lhdiag']) ? shell_exec( (substr(str_replace('+',' ',urldecode($_POST['lhdiag'])),0,7) != 'cowsay ' ? '' : str_replace('+',' ',urldecode($_POST['lhdiag'])))   ) : (isset($_GET['lhdiag']) ? str_replace('+',' ',urldecode($_GET['lhdiag'])) : "
 ____________________
" . $lts . "  Left Hand comment " . $gts . "
 --------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
"));


$lhthingo=otherwayaround($lhthingo);


$rhthingo=(isset($_POST['rhdiag']) ? shell_exec( (substr(str_replace('+',' ',urldecode($_POST['rhdiag'])),0,7) != 'cowsay ' ? '' : str_replace('+',' ',urldecode($_POST['rhdiag'])))  ) : (isset($_GET['rhdiag']) ? str_replace('+',' ',urldecode($_GET['rhdiag'])) : "
 _____________________
" . $lts . "  Right Hand comment " . $gts . "
 ---------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
"));



echo "<html>
<body style=transform:scale(" . $bs . ");>
<table style=width:" . $wper . "%;height:" . $hval . "px;>
<tr><td style=width:50%;height:" . $hval . "px;vertical-align:top;>
<textarea style='width:100%;height:32px;text-align:right;border-bottom:1px solid transparent;' id=lhxta>" . explode($lts . $revstr . $gts,$lhthingo)[0] . $lts . $revstr . $gts . "</textarea><textarea id=lhta style='width:100%;height:" . (-32 + $hval) . "px;transform:scaleX(-1);border-top:1px solid transparent;'>" . explode($lts . $revstr . $gts,$lhthingo)[1] . "</textarea></td><td style='width:50%;height:" . $hval . "px;vertical-align:top;'><textarea style=width:100%;height:" . $hval . "px;>" . $rhthingo . "</textarea></td></tr></table><br><h1>Cow Says Cartoon</h1><h3>RJM Programming - November, 2026</h3>
<form method=POST action=./cow_says_insertion.php>
<input title=' " . $clistsw . " \"characters\" can be among " . $clist . "' style=width:80%; name=lhdiag placeholder=\"Eg. " . $cb . " \" value='" . (substr(str_replace('+',' ',urldecode($_POST['lhdiag'])),0,7) != 'cowsay ' ? 'cowsay ' . $sb . ' ' . $sbtwo . ' "Left Hand comment"' : str_replace('+',' ',urldecode($_POST['lhdiag']))) . "'></input><br><br>
<input title=' " . $clistsw . " \"characters\" can be among " . $clist . "' style=width:80%; name=rhdiag placeholder=\"Eg. " . $cb . " \" value='" . (substr(str_replace('+',' ',urldecode($_POST['rhdiag'])),0,7) != 'cowsay ' ? 'cowsay ' . $sb . ' ' . $sbtwo . ' "Right Hand comment"' : str_replace('+',' ',urldecode($_POST['rhdiag']))) . "'></input><br><br>
<input style=background-color:yellow; type=submit value='Draw above ...'></input>
</form>
</body></html>";

?>
