<?php

include 'misc.inc';

// $names = RandomGunk('/usr/share/dict/propernames', 100);
$swords = RandomGunk('../tools/anagram/simple_english.txt', 1000);
$dwords = RandomGunk('/usr/share/dict/american-english', 1000);

/*
$html .= "\n<h2>Random names</h2>\n";
$p=0;
while ($p<count($names))
{
	for ($a=0; $a<mt_rand(2,4); $a++)
	{
		$html .= $names[$p].' ';
		$p++;
	}
	$html .= "<br>\n";
}
*/

$delim = '...........!!!??:';
$wrds = array('is', 'is', 'was', 'has', 'wants', 'and', 'or', 'with', 'on', 'of', 'of', 'from');
$questions1 = array('what', 'where', 'when', 'who', 'why');
$questions2 = array('can', 'is', 'was', 'did', 'could');
$html .= "\n<h2>Random text</h2>\n";
$html .= "<span id=\"original\">\n";

$p=0;
while ($p<count($swords))
{
	$comma = '';
	$cnt = mt_rand(2,7);
	$sentence = '';
	$used_comma = 0;
	for ($a=0; $a<$cnt; $a++)
	{
		$w = strtolower($swords[$p]);
		$sentence .= $comma.trim($w);
		$comma = ' ';
		if ($a>0 && $a<($cnt-1) && mt_rand(0,100)<50)
		{
			$sentence .= $comma.$wrds[mt_rand(0,count($wrds)-1)];
			$comma = ' ';
		}

		if ($used_comma==0 && $cnt>6 && $a>=2 && $a<$cnt-2)
		{
			$sentence .= ',';
			$used_comma++;
		}

		$p++;
		if ($p==50)		// google API handles 50 words max
		{
			$html .= "</span>\n";
			$html .= "<span id=\"japanese\" style=\"display:none;\"></span>\n";
			$html .= "<span id=\"final\"></span>\n";
		}
	}

	$chosen_delimiter = substr($delim, mt_rand(0, strlen($delim)), 1);
	if ($chosen_delimiter=='?')
	{
		if (mt_rand(0,100)<50)  $sentence = $questions2[mt_rand(0, count($questions2)-1)].' '.$sentence;
		if (mt_rand(0,100)<50)  $sentence = $questions1[mt_rand(0, count($questions1)-1)].' '.$sentence;
	}
	$sentence = ucfirst($sentence);

	$html .= $sentence.$chosen_delimiter."\n";
	if (mt_rand(0,100)<8)  $html .= "<br><br>\n";
}

$delim = '...........!!?';
$html .= "<br><br>\n<h2>Random and difficult words</h2>\n";
$p=0;
while ($p<count($dwords))
{
	$comma = '';
	for ($a=0; $a<mt_rand(2,6); $a++)
	{
		$w = strtolower($dwords[$p]);
		$w = preg_replace('%\'s$%', '', $w);
		if ($a==0)	$w = ucfirst($w);
		$html .= $comma.trim($w);
		$comma = ' ';
		$p++;
	}
	$html .= substr($delim, mt_rand(0, strlen($delim)), 1)."<br>\n";
}

$siteheaders = '
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript"><!--
google.load("language", "1");

function initialize()
{
	google.language.translate(document.getElementById("original").innerHTML, "en", "ja", function(result)
	{
		if (!result.error)
		{
			var container = document.getElementById("japanese");
			container.innerHTML = result.translation;
			// document.getElementById("final").style.color="#B00020";
			initialize2();
		}
	});
}
google.setOnLoadCallback(initialize);

function initialize2()
{
	google.language.translate(document.getElementById("japanese").innerHTML, "ja", "en", function(result)
	{
		if (!result.error)
		{
			var container = document.getElementById("final");
			container.innerHTML = result.translation;
			document.getElementById("original").style.display="none";
		}
	});
}
--></script>';

$title = 'Random text generator (instead of "Lorem Ipsum")';
$description = 'Random arbitrary text and names that you can freely copy paste for whatever purpose';
include 'header.inc';

echo $html;
include 'footer.inc';

?>
