|\(.*?\))/', '', $text);
$text = preg_replace('/\'s/', '', $text);
$text = strtolower(trim($text));
$poss_id = preg_replace('/\s+/', '_', $text);
$id = $poss_id;
$counter = 1;
while (isset($seen_ids[$id]))
{
$id = $poss_id . '_' . $counter;
$counter++;
}
$seen_ids[$id] = true;
return $id;
}
/** generateID($text) **/
function mkAllDir($destination_dir)
{
///cho '
* Make all directories: ' . $destination_dir . '
' . "\n";
$dirs_to_create = array();
$dir = $destination_dir;
while (!empty($dir) && !file_exists($dir))
{
///cho 'Does not exist - create...
';
array_unshift($dirs_to_create, $dir);
$dir = substr($dir, 0, strrpos($dir, '/'));
///cho 'Testing for the existance of: ' . $dir . '
';
}
foreach ($dirs_to_create as $dir)
{
if (!file_exists($dir))
{
mkdir($dir, 0775);
}
}
if (!file_exists($destination_dir))
{
printError('Failed to create directory: ' . $destination_dir);
}
}
/**
*/
function parseCLIArguments()
{
if (isset($_SERVER['argc']) && $_SERVER['argc'] > 0)
{
for ($i = 1; $i < $_SERVER['argc'] && !$unknown_argument; $i++)
{
if (preg_match('/^\-+(l|m)/i', $_SERVER['argv'][$i], $matches))
{
$i++;
$_REQUEST[$matches[1]] = $_SERVER['argv'][$i];
}
else if (preg_match('/^\-+l/i', $_SERVER['argv'][$i]))
{
$i++;
$_REQUEST['l'] = $_SERVER['argv'][$i];
}
else
{
return false;
}
}
}
return true;
}
/** parseCLIArguments() **/
/**
*/
function printError($message, $is_fatal=true)
{
if ($is_fatal)
{
exit('Error! ' . $message . "
\n");
}
else
{
echo 'Error! ' . $message . "
\n";
}
}
/** printError($message) **/
/**
*/
function recursiveRemove($dir, $base_dir, $remove_this_dir=false)
{
///cho "recursiveRemove(\"$dir\", \"$base_dir\", $remove_this_dir)
";
// Ensure that base_dir is within_dir - safety first!
if (strpos($dir, $base_dir) === false)
{
printError('Can\'t delete directory as is isn\'t within project');
}
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (preg_match('/^\./', $file))
{
// Skip dot files
}
else
{
$path = fileCat(array($dir, $file));
if (is_dir($path))
{
recursiveRemove($path, $base_dir, true);
}
else
{
unlink($path);
if (file_exists($path))
{
printError('Failed to delete file: ' . $path);
}
}
}
}
closedir($dh);
}
else
{
printError('Failed to open directory for reading: ' . $dir);
}
// Now that the directory is (hopefully) empty, we can delete it if
// required to
if ($remove_this_dir)
{
rmdir($dir);
if (file_exists($dir))
{
printError('Failed to remove directory: ' . $dir);
}
}
}
else
{
printError('Can\'t recursive delete - not a directory: ' . $dir);
}
}
/** recursiveRemove() **/
?>