<?php
// say.php
// Relies on Mac OS X operating system underneath
// RJM Programming
// May, 2016
$title='';
$wordset=["","","","","","","","","",""];

function maybevoice($mvin) {
  $mvins=explode("_",trim($mvin));
  if ($mvins[0] == "-v" && sizeof($mvins) > 1) {
    return "-v " . $mvins[1] . " \"" . str_replace("_"," ",str_replace("-v_" . $mvins[1] . "_","",trim($mvin))) . "\"";
  } else {
    return $mvin;
  }
}

if (isset($_GET['macbeth'])) {
 $wordset[0]="When shall we three meet again. In thunder, lightning, or in rain?";
 $wordset[1]="When the hurlyburly's done. When the battle's lost and won.";
 $wordset[2]="That will be ere the set of sun.";
 $wordset[3]="Where the place?";
 $wordset[4]="Upon the heath.";
 $wordset[5]="There to meet with Macbeth.";
 $wordset[6]="I come, Graymalkin!";
 $wordset[7]="Paddock calls.";
 $wordset[8]="Anon.";
 $wordset[9]="Fair is foul, and foul is fair.  Hover through the fog and filthy air.";
}

if (isset($_GET['say'])) {
  if ($_GET['say'] == "") {
    exec("say hello world");
    $title="Just said ... hello world";
  } else {
    $cexec='';
    $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say']))) . ";");
    $title="Just said ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say'])));

    if (isset($_GET['say2'])) {
     $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say2']))) . ";");
     $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say2'])));
     if (isset($_GET['say3'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say3']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say3'])));
     if (isset($_GET['say4'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say4']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say4'])));
     if (isset($_GET['say5'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say5']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say5'])));
     if (isset($_GET['say6'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say6']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say6'])));
     if (isset($_GET['say7'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say7']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say7'])));
     if (isset($_GET['say8'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say8']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say8'])));
     if (isset($_GET['say9'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say9']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say9'])));
     if (isset($_GET['say10'])) {
      $cexec.=("say " . maybevoice(str_replace(" ","_",urldecode($_GET['say10']))) . ";");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_GET['say10'])));
     }
     }
     }
     }
     }
     }
     }
     }
    }
    //echo $cexec;
    //exit;
    if ($cexec != '') exec($cexec);


  }
} else if (isset($_POST['say'])) {
  if ($_POST['say'] == "") {
    exec("say hello world");
    $title="Just said ... hello world";
  } else {
    exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say']))) . "");
    $title="Just said ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say'])));
    if (isset($_POST['say2'])) {
     exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say2']))) . "");
     $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say2'])));
     if (isset($_POST['say3'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say3']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say3'])));
     if (isset($_POST['say4'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say4']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say4'])));
     if (isset($_POST['say5'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say5']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say5'])));
     if (isset($_POST['say6'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say6']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say6'])));
     if (isset($_POST['say7'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say7']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say7'])));
     if (isset($_POST['say8'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say8']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say8'])));
     if (isset($_POST['say9'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say9']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say9'])));
     if (isset($_POST['say10'])) {
      exec("say " . maybevoice(str_replace(" ","_",urldecode($_POST['say10']))) . "");
      $title.=" ... and ... " . maybevoice(str_replace(" ","_",urldecode($_POST['say10'])));
     }
     }
     }
     }
     }
     }
     }
     }
    }
  }
} 

if (1 == 1) {
  echo "
<html>
<head>
<title>" . $title . "</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

</script>
</head>
<body style='background-color:orange;'>
<h1 style='text-align:center; width:100%;'>Text to English Speech via MAMP Web Server</h1>
<div style='text-align:center; width:100%;'>
<form style='text-align:center; width:100%;' action='./say.php' method='POST'>
What You Want to Hear: <input style='width:80%;' name='say' id='say' type='text' value=\"" . $wordset[0] . "\"></input><br>
And Then: <input style='width:80%;' name='say2' id='say2' type='text' value=\"" . $wordset[1] . "\"></input><br>
And Back to You: <input style='width:80%;' name='say3' id='say3' type='text' value=\"" . $wordset[2] . "\"></input><br>
More: <input style='width:80%;' name='say4' id='say4' type='text' value=\"" . $wordset[3] . "\"></input><br>
More: <input style='width:80%;' name='say5' id='say5' type='text' value=\"" . $wordset[4] . "\"></input><br>
More: <input style='width:80%;' name='say6' id='say6' type='text' value=\"" . $wordset[5] . "\"></input><br>
More: <input style='width:80%;' name='say7' id='say7' type='text' value=\"" . $wordset[6] . "\"></input><br>
More: <input style='width:80%;' name='say8' id='say8' type='text' value=\"" . $wordset[7] . "\"></input><br>
More: <input style='width:80%;' name='say9' id='say9' type='text' value=\"" . $wordset[8] . "\"></input><br>
More: <input style='width:80%;' name='say10' id='say10' type='text' value=\"" . $wordset[9] . "\"></input><br><br><input type='submit' value='Hear This'></input>
</form>
</div>
</body>
</html> 
";
}
?>
