From d2f612f735fb0d1dc838e89973c82c64448c6533 Mon Sep 17 00:00:00 2001
From: KNG <34425597+ECHibiki@users.noreply.github.com>
Date: Sun, 18 Feb 2018 00:20:12 -0500
Subject: [PATCH] Condensed methods
---
tweet.php | 358 +++++++++++++++-----------------------------------------------
1 file changed, 84 insertions(+), 274 deletions(-)
diff --git a/tweet.php b/tweet.php
index 3712f1d..c017d71 100644
--- a/tweet.php
+++ b/tweet.php
@@ -1,170 +1,66 @@
$param){
+ if($start){
+ $start=false;
+ }
+ else{
+ $param_string .= urlencode("&");
+ }
+ $param_string .= urlencode($key . "=" . $param);
+ }
+ return $param_string;
}
-function generateMediaSingatureAPPEND($request, $message, $params, $secrets){
- // BUILD SIGNATURE
- $request_method = strtoupper($request["request_method"]);
- $base_url = urlEncodeCustom($request["base_url"]);
- //$message["media_data"] = 123;
- $paramter_string = urlEncodeCustom("command=" . $message["command"] . "&media=" . urlEncodeCustom($message["media"]) . "&media_id=" . $message["media_id"] . "&oauth_consumer_key=" . $params["oauth_consumer_key"]
- . "&oauth_nonce=" . $params["oauth_nonce"] . "&oauth_signature_method=" . $params["oauth_signature_method"] . "&oauth_timestamp=" . $params["oauth_timestamp"]."&oauth_token=" . $params["oauth_token"] .
- "&oauth_version=" .$params["oauth_version"]. "&segment_index=" . $message["segment_index"]);
+function generateSignature($request, $params, $secrets){
+ // BUILD SIGNATURE
+ $request_method = strtoupper($request["request_method"]);
+ $base_url = rawurlencode($request["base_url"]);
- // echo ("command=" . $message["command"] . "&media=" . $message["media"] . "&media_id=" . $message["media_id"] . "&oauth_consumer_key=" . $params["oauth_consumer_key"]
- // . "&oauth_nonce=" . $params["oauth_nonce"] . "&oauth_signature_method=" . $params["oauth_signature_method"] . "&oauth_timestamp=" . $params["oauth_timestamp"]."&oauth_token=" . $params["oauth_token"] .
- // "&oauth_version=" .$params["oauth_version"] . "&segment_index=" . $message["segment_index"]) . "
";
-
-
- // echo "
" . $message["media"] . "
";
-
+ ksort($params);
+ if(isset($params["media"])) $params["media"] = urlencode($params["media"]);
- $base_string = ($request_method . "&" . $base_url . "&" . $paramter_string);
-
- echo $base_string . "
";
+ $paramter_string = buildOAuthParamaterString($params);
- $secret_string = $secrets["consumer_secret"] . "&" . $secrets["oauth_secret"];
- echo $secret_string. "
";;
- $signature = urlencode(base64_encode(hash_hmac("SHA1",$base_string, $secret_string, true)));
-
- echo $signature . "
";
-
- return $signature;
-}
-function generateMediaSingatureCOMBINED($request, $message, $params, $secrets){
- // BUILD SIGNATURE
- $request_method = strtoupper($request["request_method"]);
- $base_url = urlEncodeCustom($request["base_url"]);
- $paramter_string = urlEncodeCustom("media=" . $message["media"] . "&oauth_consumer_key=" . $params["oauth_consumer_key"]
- . "&oauth_nonce=" . $params["oauth_nonce"] . "&oauth_signature_method=" . $params["oauth_signature_method"] . "&oauth_timestamp=" . $params["oauth_timestamp"]."&oauth_token=" . $params["oauth_token"] .
- "&oauth_version=" .$params["oauth_version"]);
-
$base_string = ($request_method . "&" . $base_url . "&" . $paramter_string);
-
+
$secret_string = $secrets["consumer_secret"] . "&" . $secrets["oauth_secret"];
- //using binary production
- echo "$base_string
";
- $signature = (hash_hmac("SHA1",$base_string, $secret_string, true));
- $signature = urlEncodeCustom(base64_encode($signature));
- return $signature;
-}
-function generateMediaSingatureFINAL($request, $message, $params, $secrets){
- // BUILD SIGNATURE
- $request_method = strtoupper($request["request_method"]);
- $base_url = urlEncodeCustom($request["base_url"]);
- //$message["media_data"] = 123;
- $paramter_string = urlEncodeCustom("command=" . $message["command"] . "&media_id=" . $message["media_id"] . "&oauth_consumer_key=" . $params["oauth_consumer_key"]
- . "&oauth_nonce=" . $params["oauth_nonce"] . "&oauth_signature_method=" . $params["oauth_signature_method"] . "&oauth_timestamp=" . $params["oauth_timestamp"]."&oauth_token=" . $params["oauth_token"] .
- "&oauth_version=" .$params["oauth_version"]);
+ $signature = (base64_encode(hash_hmac("SHA1",$base_string, $secret_string, true)));
+ return $signature;
+};
-
- // echo ("command=" . $message["command"] . "&media=" . $message["media"] . "&media_id=" . $message["media_id"] . "&oauth_consumer_key=" . $params["oauth_consumer_key"]
- // . "&oauth_nonce=" . $params["oauth_nonce"] . "&oauth_signature_method=" . $params["oauth_signature_method"] . "&oauth_timestamp=" . $params["oauth_timestamp"]."&oauth_token=" . $params["oauth_token"] .
- // "&oauth_version=" .$params["oauth_version"] . "&segment_index=" . $message["segment_index"]) . "
";
-
-
- // echo "
" . $message["media"] . "
";
-
-
- $base_string = ($request_method . "&" . $base_url . "&" . $paramter_string);
-
- echo $base_string . "
";
-
- $secret_string = $secrets["consumer_secret"] . "&" . $secrets["oauth_secret"];
- echo $secret_string. "
";;
- $signature = urlencode(base64_encode(hash_hmac("SHA1",$base_string, $secret_string, true)));
-
- echo $signature . "
";
-
- return $signature;
-}
function getMediaID($binary_file, $size, $mime){
$media_api = "https://upload.twitter.com/1.1/media/upload.json";
-
- $settings = fopen("settings/keys.ini","r");
- $keys = array();
- while(!feof($settings)){
- $line = fgets($settings);
- $key = substr($line,0,strpos($line, ":"));
- //eat last character
- $value = trim(substr($line, strpos($line, ":")+1));
- $keys[$key] = $value;
- }
- $consumer_key = $keys["consumer_key"];
- $random_value = substr(( base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000000,100000000000000))), 0, 32);
+
+ $consumer_key = $GLOBALS['oauth_data']["consumer_key"];
+ $random_value = randomAlphaNumet(32);
$random_value = str_replace("/", "5", str_replace("=", "2", $random_value));
$method = "HMAC-SHA1";
$timestamp = time();
- $access_token = $keys["access_token"];
+ $access_token = $GLOBALS['oauth_data']["access_token"];
$oauth_version = "1.0";
//Secrets
- $consumer_secret = $keys["consumer_secret"];
- $oauth_secret = $keys["oauth_secret"];
+ $consumer_secret = $GLOBALS['oauth_data']["consumer_secret"];
+ $oauth_secret = $GLOBALS['oauth_data']["oauth_secret"];
+
+ echo "$oauth_secret -- $consumer_secret -- $access_token -- $consumer_key
";
echo "
";
/////////////MAKE INIT////////////
@@ -175,16 +71,13 @@ function getMediaID($binary_file, $size, $mime){
//header data
// BUILD SIGNATURE
- $signature = generateMediaSingatureINIT(array(
+ $signature = urlencode(generateSignature(array(
"base_url" => $media_api,
- "request_method" => "POST"
- ),
- array(
+ "request_method" => "POST"),
+ array(
"command" => "$command",
"total_bytes" => "$size",
- "media_type" => "$mime"
- ),
- array(
+ "media_type" => "$mime",
"oauth_version" => "$oauth_version",
"oauth_nonce" => "$random_value",
"oauth_token" => "$access_token",
@@ -196,7 +89,7 @@ function getMediaID($binary_file, $size, $mime){
"consumer_secret" => "$consumer_secret",
"oauth_secret" => "$oauth_secret"
)
- );
+ ));
@@ -225,17 +118,14 @@ function getMediaID($binary_file, $size, $mime){
//header data
// BUILD SIGNATURE
- $signature = generateMediaSingatureAppend(array(
+ $signature = urlencode(generateSignature(array(
"base_url" => $media_api,
- "request_method" => "POST"
- ),
- array(
+ "request_method" => "POST"),
+ array(
"command" => "$command",
"media" => "$binary_file",
"media_id"=>"$media_id",
- "segment_index"=>"$segment_index"
- ),
- array(
+ "segment_index"=>"$segment_index",
"oauth_version" => "$oauth_version",
"oauth_nonce" => "$random_value",
"oauth_token" => "$access_token",
@@ -247,12 +137,10 @@ function getMediaID($binary_file, $size, $mime){
"consumer_secret" => "$consumer_secret",
"oauth_secret" => "$oauth_secret"
)
- );
+ ));
- $postfield_string = "command=$command&media_id=$media_id&segment_index=$segment_index&media=$binary_file";
- $postfield_string = "media=" . urlencode($binary_file) . "&oauth_consumer_key=$consumer_key&oauth_nonce=$random_value&oauth_signature=$signature&oauth_signature_method=$method&oauth_timestamp=$timestamp&oauth_token=$access_token&oauth_version=$oauth_version";
- //&command=$command&media_id=$media_id&segment_index=$segment_index";
- $postfield_string = "media=" . urlencode($binary_file) . "&command=$command&media_id=$media_id&segment_index=$segment_index" ;
+
+ $postfield_string = "media=" . urlencode($binary_file) . "&command=$command&media_id=$media_id&segment_index=$segment_index" ;
$msg_len = (strlen($postfield_string));
echo $msg_len . "
";
$header_data = array("Except:", "Connection: close","User-Agent: VerniyXYZ-CURL" ,"Content-Transfer-Encoding: binary",
@@ -277,17 +165,12 @@ function getMediaID($binary_file, $size, $mime){
$command = "FINALIZE";
- $signature = generateMediaSingatureFINAL(array(
+ $signature = urlencode(generateSignature(array(
"base_url" => $media_api,
- "request_method" => "POST"
- ),
- array(
+ "request_method" => "POST"),
+ array(
"command" => "$command",
- "media" => "$binary_file",
"media_id"=>"$media_id",
- "segment_index"=>"$segment_index"
- ),
- array(
"oauth_version" => "$oauth_version",
"oauth_nonce" => "$random_value",
"oauth_token" => "$access_token",
@@ -299,7 +182,7 @@ function getMediaID($binary_file, $size, $mime){
"consumer_secret" => "$consumer_secret",
"oauth_secret" => "$oauth_secret"
)
- );
+ ));
$postfield_string = "command=$command&media_id=$media_id" ;
$msg_len = (strlen($postfield_string));
echo $msg_len . "
";
@@ -325,79 +208,6 @@ function getMediaID($binary_file, $size, $mime){
return $media_id ;
}
-function getMediaIDCOMBINED($binary_file, $size, $mime){
- $media_api = "https://upload.twitter.com/1.1/media/upload.json";
-
- $settings = fopen("settings/keys.ini","r");
- $keys = array();
- while(!feof($settings)){
- $line = fgets($settings);
- $key = substr($line,0,strpos($line, ":"));
- //eat last character
- $value = trim(substr($line, strpos($line, ":")+1));
- $keys[$key] = $value;
- }
- $consumer_key = $keys["consumer_key"];
- $random_value = substr(( base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000000,100000000000000))), 0, 32);
- $random_value = str_replace("/", "5", str_replace("=", "2", $random_value));
- $method = "HMAC-SHA1";
- $timestamp = time();
- $access_token = $keys["access_token"];
- $oauth_version = "1.0";
-
- //Secrets
- $consumer_secret = $keys["consumer_secret"];
- $oauth_secret = $keys["oauth_secret"];
-
- echo "
";
- /////////////MAKE COMBO////////////
- //post data
- $command = "APPEND";
- $segment_index = 0;
- $postfield_string = "media=$binary_file";
- $msg_len = (strlen($postfield_string));
- //header data
- // BUILD SIGNATURE
- $signature = generateMediaSingatureCOMBINED(array(
- "base_url" => $media_api,
- "request_method" => "POST"
- ),
- array(
- "media" => "$binary_file",
- ),
- array(
- "oauth_version" => "$oauth_version",
- "oauth_nonce" => "$random_value",
- "oauth_token" => "$access_token",
- "oauth_timestamp" => "$timestamp",
- "oauth_consumer_key" => "$consumer_key",
- "oauth_signature_method" => "$method"
- ),
- array(
- "consumer_secret" => "$consumer_secret",
- "oauth_secret" => "$oauth_secret"
- )
- );
-
-
-
- $header_data = array("Accept: */*", "Connection: close","User-Agent: VerniyXYZ-CURL" ,"Content-Transfer-Encoding: binary",
- "Content-Type: multipart/form-data;charset=UTF-8",
- "Content-Length: $msg_len", "Host: upload.twitter.com",
-"Authorization: OAuth oauth_consumer_key=\"$consumer_key\",oauth_nonce=\"$random_value\",oauth_signature=\"$signature\",oauth_signature_method=\"$method\",oauth_timestamp=\"$timestamp\",oauth_token=\"$access_token\",oauth_version=\"$oauth_version\""
- );
- //request
- $curl = curl_init($media_api);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header_data);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postfield_string);
- curl_setopt($curl, CURLOPT_HEADER , true); // we want headers
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $http_response = curl_exec($curl);
- echo $http_response;
-
- echo "
";
-}
function makeTweet($comment, $file_arr){
/*
@@ -406,6 +216,20 @@ function makeTweet($comment, $file_arr){
3. Authenticate post and submit it to Twitter
*/
+ //authorization details
+$settings = fopen("settings/keys.ini","r");
+while(!feof($settings)){
+ $line = fgets($settings);
+ $key = substr($line,0,strpos($line, ":"));
+ //eat last character
+ $value = trim(substr($line, strpos($line, ":")+1));
+ $GLOBALS['oauth_data'][$key] = $value;
+}
+
+ print_r($GLOBALS['oauth_data']);
+
+
+
//image info
$image_string = "";//delimited by ',' commas
for($file = 0 ; $file < 4 ; $file++){
@@ -426,16 +250,16 @@ for($file = 0 ; $file < 4 ; $file++){
}
}
-
- echo ("IMAGE-STRING: " . $image_string);
+echo ("IMAGE-STRING: " . $image_string);
$image_string = urlencode($image_string);
+
//access info
$access_url = "https://api.twitter.com/1.1/statuses/update.json";
$request_method = "POST";
//message info
-$encode_tweet_msg = statusEncodeCustom($comment);
+$encode_tweet_msg = rawurlencode($comment);
$include_entities = "true";
//append to postfield_string the media code via media_ids=$media_id
@@ -445,39 +269,25 @@ $msg_len = (strlen($postfield_string));
echo "
$postfield_string
";
-//authorization details
-$settings = fopen("settings/keys.ini","r");
-$keys = array();
-while(!feof($settings)){
- $line = fgets($settings);
- $key = substr($line,0,strpos($line, ":"));
- //eat last character
- $value = trim(substr($line, strpos($line, ":")+1));
- $keys[$key] = $value;
-}
-$consumer_key = $keys["consumer_key"];
-$random_value = substr(( base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000,10000000000000)) . base64_encode(rand(1000000000000,100000000000000))), 0, 32);
+$consumer_key = $GLOBALS['oauth_data']["consumer_key"];
+$random_value = randomAlphaNumet(32);
$random_value = str_replace("/", "5", str_replace("=", "2", $random_value));
$method = "HMAC-SHA1";
$timestamp = time();
-$access_token = $keys["access_token"];
+$access_token = $GLOBALS['oauth_data']["access_token"];
$oauth_version = "1.0";
//Secrets
-$consumer_secret = $keys["consumer_secret"];
-$oauth_secret = $keys["oauth_secret"];
+$consumer_secret = $GLOBALS['oauth_data']["consumer_secret"];
+$oauth_secret = $GLOBALS['oauth_data']["oauth_secret"];
//add media id to the signature
-$signature = urlEncodeCustom(generateSingature(array(
+$signature = rawurlencode(generateSignature(array(
"base_url" => $access_url,
- "request_method" => $request_method
- ),
- array(
- "include_entities" => "$include_entities",
+ "request_method" => $request_method),
+ array("include_entities" => "$include_entities",
"status" => "$encode_tweet_msg",
- "media_ids" => "$image_string"
- ),
- array(
+ "media_ids" => "$image_string",
"oauth_version" => "$oauth_version",
"oauth_nonce"=>"$random_value",
"oauth_token"=>"$access_token",
--
2.11.4.GIT