From c9102c46993a62167101b55ac2a38a4a3e8ddf7c Mon Sep 17 00:00:00 2001 From: ECHibki Date: Thu, 22 Mar 2018 04:56:01 -0400 Subject: [PATCH] Retrieve timeline --- .htaccess | 1 - README.md | 4 -- add-to-queue.php | 35 ------------ class/random.php | 14 ----- class/twitter-connection.php | 129 ++++++++++++++++++++++++++++++++++--------- form-script.js | 73 ------------------------ index.php | 10 ++++ queue-form.php | 30 ---------- settings/userinfo.ini | 2 + timed-post.php | 21 ------- 10 files changed, 116 insertions(+), 203 deletions(-) delete mode 100644 .htaccess delete mode 100644 README.md delete mode 100644 add-to-queue.php delete mode 100644 class/random.php delete mode 100644 form-script.js create mode 100644 index.php delete mode 100644 queue-form.php create mode 100644 settings/userinfo.ini delete mode 100644 timed-post.php diff --git a/.htaccess b/.htaccess deleted file mode 100644 index b0bec50..0000000 --- a/.htaccess +++ /dev/null @@ -1 +0,0 @@ -directoryindex queue-form.php \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 3b326b4..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Anonymous Twitter Board - -Anonymous Twitter board is an extention off of my EroTweet repo for the purpose of giving people an open bulletin board for others to post their thoughts. - diff --git a/add-to-queue.php b/add-to-queue.php deleted file mode 100644 index 007641c..0000000 --- a/add-to-queue.php +++ /dev/null @@ -1,35 +0,0 @@ - - - -
-Back to Form -

- -
- -checkCommentValid($_POST["comment"]); - - $file_string = $construction->uploadAndVerify($_FILES); - - echo "
"; - - $do_not_submit = false; - for($file = 0 ; $file < 4 ; $file++) if($construction->die_state[$file] == true) $do_not_submit = true; - if($comment_error) $do_not_submit = true; - - if($do_not_submit) echo "Error in Tweet. Aborting addition to queue.
"; - else $construction->addToDatabase($file_string, $comment); - - $construction->displayTabularDatabase(); - -?> - -
-Back to Form - - diff --git a/class/random.php b/class/random.php deleted file mode 100644 index cdf5ee2..0000000 --- a/class/random.php +++ /dev/null @@ -1,14 +0,0 @@ - \ No newline at end of file diff --git a/class/twitter-connection.php b/class/twitter-connection.php index f3bc576..84b04ea 100644 --- a/class/twitter-connection.php +++ b/class/twitter-connection.php @@ -9,22 +9,103 @@ A NOTE ON TWITTER ERRORS: require("class/oauth-random.php"); class TwitterConnection{ private $oauth_data = array(); + private $user_info = array(); + private $media_api = "https://upload.twitter.com/1.1/media/upload.json"; private $status_api = "https://api.twitter.com/1.1/statuses/update.json"; + private $user_timeline_api = "https://api.twitter.com/1.1/statuses/user_timeline.json"; function __construct(){ - $this->getOAuthData(); + $this->oauth_data = $this->getIniFile("settings/keys.ini"); + $this->user_info = $this->getIniFile("settings/userinfo.ini"); } - function getOAuthData(){ - $settings = fopen("settings/keys.ini","r"); - while(!feof($settings)){ - $line = fgets($settings); - $key = substr($line,0,strpos($line, ":")); + function getIniFile($path){ + $path_string = fopen($path,"r"); + $return_array = array(); + while(!feof($path_string)){ + $line = fgets($path_string); + $key = substr($line,0,strpos($line, "=")); //eat last character - $value = trim(substr($line, strpos($line, ":")+1)); - $this->oauth_data[$key] = $value; + $value = trim(substr($line, strpos($line, "=")+1)); + + $return_array[$key] = $value; } + return $return_array; + } + + + function getUserTimeline($since_id = 976628662446551043, $count = 5){ + //add media id to the signature + + $random_value = OauthRandom::randomAlphaNumet(32); + $method = "HMAC-SHA1"; + $oauth_version = "1.0"; + $timestamp = time(); + + + $get_fields = "since_id=" . $since_id . "&count=" . $count . "&include_rts=true&exclude_replies=false&user_id=" . $this->user_info["User-ID"]; + //$msg_len = (strlen($this->user_timeline_api . "?$get_fields")); //GET REQUESTS HAVE NO DYNAMIC LENGTH + + $param_array = array( "user_id" => $this->user_info["User-ID"], + "since_id" => "$since_id", + "exclude_replies"=>"false", + "count" => "$count", + "include_rts" => "true", + "oauth_version" => "$oauth_version", + "oauth_nonce"=>"$random_value", + "oauth_token"=> $this->oauth_data["oauth_token"], + "oauth_timestamp" => "$timestamp", + "oauth_consumer_key" => $this->oauth_data["oauth_consumer_key"], + "oauth_signature_method" => "$method" + ); + + $signature = rawurlencode($this->generateSignature(array( + "base_url" => $this->user_timeline_api, + "request_method" => "GET"), + $param_array, + array( + "consumer_secret" => $this->oauth_data["consumer_secret"], + "oauth_secret" => $this->oauth_data["oauth_secret"] + ) + )); + + $param_array["oauth_signature"] = $signature; + $header_data = array("Accept: */*", "Connection: close","User-Agent: VerniyXYZ-CURL" , + "Content-Type: application/x-www-form-urlencoded;charset=UTF-8", "Host: api.twitter.com", + $this->buildAuthorizationString($param_array)); + + //request + echo "
"; + $curl = curl_init($this->user_timeline_api . "?$get_fields"); + curl_setopt($curl, CURLOPT_HTTPGET, 1); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header_data); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false); + + echo "
-- Fin --
"; + $content = curl_exec($curl); + echo ( $content); + + } + + + function buildAuthorizationString($parameters){ + $authorization_string = 'Authorization: OAuth '; + + ksort($parameters); + $is_first_join = false; + foreach($parameters as $key => $value){ + if(!$is_first_join){ + $is_first_join = true; + $authorization_string .= $key . '="' . $value . '"'; + } + else{ + $authorization_string .= "," . $key . '="' . $value . '"'; + } + } + return $authorization_string; } function makeTweet($comment, $file_arr){ @@ -46,12 +127,7 @@ class TwitterConnection{ $oauth_version = "1.0"; $timestamp = time(); - - //add media id to the signature - $signature = rawurlencode($this->generateSignature(array( - "base_url" => $this->status_api, - "request_method" => $request_method), - array("include_entities" => "$include_entities", + $param_array = array("include_entities" => "$include_entities", "status" => "$encode_tweet_msg", "media_ids" => "$image_string", "oauth_version" => "$oauth_version", @@ -60,20 +136,24 @@ class TwitterConnection{ "oauth_timestamp" => "$timestamp", "oauth_consumer_key" => $this->oauth_data["oauth_consumer_key"], "oauth_signature_method" => "$method" - ), + ); + + //add media id to the signature + $signature = rawurlencode($this->generateSignature(array( + "base_url" => $this->status_api, + "request_method" => $request_method), + $param_array, array( "consumer_secret" => $this->oauth_data["consumer_secret"], "oauth_secret" => $this->oauth_data["oauth_secret"] ) )); + $param_array["oauth_signature"] = $signature; $header_data = array("Accept: */*", "Connection: close","User-Agent: VerniyXYZ-CURL" , - "Content-Type: application/x-www-form-urlencoded;charset=UTF-8", - "Content-Length: $msg_len", "Host: api.twitter.com", - - 'Authorization: OAuth oauth_consumer_key="' . $this->oauth_data["oauth_consumer_key"] .'",oauth_nonce="' . $random_value . '",oauth_signature="' . $signature - . '",oauth_signature_method="' .$method . '"' . ',oauth_timestamp="' . $timestamp . '",oauth_token="' . $this->oauth_data["oauth_token"] . '",oauth_version="' . $oauth_version . '"' - ); + "Content-Type: application/x-www-form-urlencoded;charset=UTF-8", + "Content-Length: $msg_len", "Host: api.twitter.com", + $this->buildAuthorizationString($param_array)); //request echo "
"; @@ -229,7 +309,7 @@ class TwitterConnection{ 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_HEADER , true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $http_response = curl_exec($curl); echo $http_response; @@ -271,7 +351,7 @@ class TwitterConnection{ 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_HEADER , true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $http_response = curl_exec($curl); echo $http_response; @@ -282,8 +362,7 @@ class TwitterConnection{ $request_method = strtoupper($request_arr["request_method"]); $base_url = rawurlencode($request_arr["base_url"]); - ksort($paramater_arr); - + ksort($paramater_arr); if(isset($paramater_arr["media"])) $paramater_arr["media"] = rawurlencode($paramater_arr["media"]); $paramter_string = $this->buildOAuthParamaterString($paramater_arr); diff --git a/form-script.js b/form-script.js deleted file mode 100644 index dcb1ca4..0000000 --- a/form-script.js +++ /dev/null @@ -1,73 +0,0 @@ -//Files and character counter -var character_counter = document.getElementById('CharacterCount'); -var error_msg = document.getElementById('errorMsg'); -var error_msg_text = document.createTextNode(""); -error_msg.appendChild(error_msg_text); -var textarea = document.getElementById('Comment'); -var submit = document.getElementById('submit'); -submit.setAttribute('disabled',''); - -function checkIfSubmitToBeDisabled(){ - //check all file fontainers - for(var i = 1 ; i <= 4; i++){ - if(document.getElementById("f" + i).files.length == 0){ - var length = textarea.value.length; - if(length == 0) { - submit.setAttribute('disabled',''); - error_msg_text.nodeValue = "value", "Input a comment and/or file"; - } - } - else{ - var length = textarea.value.length; - if(length > 500){ - characterCountColoring(); - return; - } - else{ - submit.removeAttribute('disabled'); - eerror_msg_text.nodeValue = "Click to submit"; - return; - } - } - } -} - -function characterCountColoring(){ - var length = textarea.value.trim().length; - var red = 0; var blue = 100; var green = 100; - if(length == 0){ - submit.setAttribute('disabled',''); - error_msg_text.nodeValue = "Input a comment and/or file"; - } - else if(length > 500){ - red = 255; blue = 0; green = 0; - submit.setAttribute('disabled',''); - error_msg_text.nodeValue = "Character count exceeded(>500)"; - } - else{ - red = Math.ceil(length/500 * 180); - submit.removeAttribute('disabled'); - error_msg.innerHTML = "Click to submit"; - } - character_counter.innerHTML = '' + length + '' -} - -function setFileListener(file){ - file_node = document.getElementById(file); - (function(_file_node){ - _file_node.addEventListener("change", checkIfSubmitToBeDisabled); - })(file_node); -} - -for(var i = 1 ; i <= 4; i++) setFileListener("f" + i); - -if (textarea.addEventListener) { - textarea.addEventListener('input', function() { - characterCountColoring(); - }, false); -} -else if (textarea.attachEvent) { - textarea.attachEvent('onpropertychange', function() { - characterCountColoring(); - }); -} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..40983c7 --- /dev/null +++ b/index.php @@ -0,0 +1,10 @@ + + + +getUserTimeline(); +?> + + \ No newline at end of file diff --git a/queue-form.php b/queue-form.php deleted file mode 100644 index 1cdfbe4..0000000 --- a/queue-form.php +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - Submit to @VerniyEro - - -

Submit to @VerniyEro

-buildPassForm(); - } - else{ - $construction->buildQueueForm(); - } -?> - - - \ No newline at end of file diff --git a/settings/userinfo.ini b/settings/userinfo.ini new file mode 100644 index 0000000..2434630 --- /dev/null +++ b/settings/userinfo.ini @@ -0,0 +1,2 @@ +User-ID=-- +User-Name=-- \ No newline at end of file diff --git a/timed-post.php b/timed-post.php deleted file mode 100644 index 33fa50a..0000000 --- a/timed-post.php +++ /dev/null @@ -1,21 +0,0 @@ -retrieveOldestEntry(); - echo "
" . var_dump($oldest); - echo "
"; - - //ob_start(); - require("class/twitter-connection.php"); - //ob_end_clean(); - $connection = new TwitterConnection(); - $connection->makeTweet($oldest["Comment"], explode(",", $oldest["ImageLocation"])); - - echo "
"; - - - $construction->deleteOldestEntry($oldest); - - echo "Found, Added and Deleted
"; -?> \ No newline at end of file -- 2.11.4.GIT