
andrew
By: a guest on Nov 5th, 2008 | syntax:
PHP | size: 2.54 KB | hits: 218 | expires: Never
#!/usr/bin/php
<?php
define('PASTE_BIN', 'http://woot.pastebin.com/index.php');
{
echo "Usage: {$argv[0]} [-f file] [-e expire] [-u name] [-l language]\n\n";
echo " -f file Filename to paste; if not provided, reads from STDIN\n";
echo " -e expire Valid options: day, month, forever\n";
echo " -u name Username to paste as; if not provided uses whoami\n";
echo " -l language For syntax highlighting; default is text\n\n";
}
$name = (isset($opt['u']) ?
$opt['u'] : trim(`whoami`
));
$expire = (isset($opt['e']) ? translateExpire
($opt['e']) : 'd');
$language = isset($opt['l']) ?
$opt['l'] : 'text';
$file = isset($opt['f']) ?
$opt['f'] : NULL;
// read the file
$contents = $file
// try to auto-detect format
&& ($f = detectFormat($contents, $file)) !== NULL)
{
$language = $f;
}
'format' => $language,
'poster' => $name,
'code2' => $contents,
'expiry' => $expire,
'paste' => 'Send',
);
{
die("Error while submitting to pastebin.\n");
}
echo $m[1], "\n";
function translateExpire($value)
{
switch ($value)
{
case 'day':
case 'd':
return 'd';
case 'month':
case 'm':
return 'm';
case 'forever':
case 'f':
return 'f';
}
return 'd';
}
function detectFormat($string, $filename = NULL)
{
// first, attempt to detect the type by
// the file extension (if we're using a file)
if ($filename
&& ($pos = strrpos($filename, '.')) !== FALSE)
{
$ext = substr($filename, $pos + 1
);
switch ($ext)
{
case 'php':
case 'c':
case 'diff':
case 'html':
return $ext;
case 'py':
return 'python';
case 'patch':
return 'diff';
case 'h':
return 'c';
}
}
// if it's a script (has the shebang), attempt
// to determine type by the binary
{
switch ($bin)
{
case 'php':
case 'bash':
case 'perl':
case 'python':
return $bin;
}
}
// do some basic attempts at detecting the
// type by its contents
{
return 'php';
}
return NULL;
}
?>