Posted by andrew on Wed 5 Nov 17:10 (modification of post by view diff)
report abuse | download | new post
- #!/usr/bin/php
- <?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";
- }
- // read the file
- $contents = $file
- : stream_get_contents(STDIN);
- // try to auto-detect format
- && ($f = detectFormat($contents, $file)) !== NULL)
- {
- $language = $f;
- }
- 'format' => $language,
- 'poster' => $name,
- 'code2' => $contents,
- 'expiry' => $expire,
- 'paste' => 'Send',
- );
- $ch = curl_init(PASTE_BIN);
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $r = curl_exec($ch);
- {
- }
- 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
- {
- 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;
- }
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.