#!/usr/bin/php
// requires growlnotify and pastebin-user-keygen.php, and a Keychain entry for your dev key
<?php
$paste = shell_exec("pbpaste"); // grab clipboard contents
$api_user_key = exec('php /Users/antonio/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.009EEC74-1F8A-42D1-B8F0-8D0561F1BE32/pastebin-user-keygen.php'); // generates a user session key
$api_dev_key = shell_exec('security find-generic-password -wl "Pastebin dev key" | tr -d "\\n"'); // grabs api_developer_key from keychain
$api_paste_code = $paste; // your paste text
$api_paste_name = $argv[1]; // name or title of your paste
$api_paste_format = $argv[2]; // syntax of paste
$api_paste_expire_date = $argv[3]; // expiry date for paste
$api_paste_private = $argv[4]; // 0=public 1=unlisted 2=private
$api_paste_name = urlencode($api_paste_name);
$api_paste_code = urlencode($api_paste_code);
$url = 'https://pastebin.com/api/api_post.php';
$ch = curl_init($url);
if (empty($api_paste_code)) {
exit("Clipboard empty!");
} elseif (empty($api_paste_name)) {
exit("Title missing!");
} elseif (empty($api_paste_format)) {
exit("Format missing!");
} elseif (empty($api_paste_expire_date)) {
$api_paste_expire_date = 'N';
shell_exec("/usr/local/bin/growlnotify --appIcon /Users/antonio/Dropbox/Apps/Pastebin/pastebin.png Pastebin -m 'Paste never expires!'");
}
if (empty($api_paste_private)) {
$api_paste_private = '2'; // default privacy setting 'Private'
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key='.$api_user_key.'&api_paste_private='.$api_paste_private.'&api_paste_name='.$api_paste_name.'&api_paste_expire_date='.$api_paste_expire_date.'&api_paste_format='.$api_paste_format.'&api_dev_key='.$api_dev_key.'&api_paste_code='.$api_paste_code.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
$response = curl_exec($ch);
echo $response;
?>
Comments