예제 #1
0
 /**
  * Construct a new request signer.  Perform the request with the doRequest() method below.
  * 
  * A request can have either one file or a body, not both. 
  * 
  * The files array consists of arrays:
  * - file			the filename/path containing the data for the POST/PUT
  * - data			data for the file, omit when you have a file
  * - mime			content-type of the file
  * - filename		filename for content disposition header
  * 
  * When OAuth (and PHP) can support multipart/form-data then we can handle more than one file.
  * For now max one file, with all the params encoded in the query string.
  * 
  * @param string request
  * @param string method		http method.  GET, PUT, POST etc.
  * @param array params		name=>value array with request parameters
  * @param string body		optional body to send
  * @param array files		optional files to send (max 1 till OAuth support multipart/form-data posts)
  */
 function __construct($request, $method = null, $params = null, $body = null, $files = null)
 {
     parent::__construct($request, $method, $params, $body);
     // When there are files, then we can construct a POST with a single file
     if (!empty($files)) {
         $empty = true;
         foreach ($files as $f) {
             $empty = $empty && empty($f['file']) && !isset($f['data']);
         }
         if (!$empty) {
             if (!is_null($body)) {
                 throw new OAuthException2('When sending files, you can\'t send a body as well.');
             }
             $this->files = $files;
         }
     }
 }
예제 #2
0
파일: api.php 프로젝트: JaimeA/SkunkWrx
 function push($audience_email, $project_id)
 {
     $st = $this->db->prepare('SELECT * FROM audience LEFT JOIN projects ON (audience.project_id=projects.PROJECT_ID) WHERE audience.audience_email=:audience_email AND projects.project_id=:project_id ');
     $st->bindValue(':audience_email', $audience_email, PDO::PARAM_STR);
     $st->bindValue(':project_id', $project_id, PDO::PARAM_INT);
     $st->execute();
     $data = $st->fetchAll(PDO::FETCH_ASSOC);
     if (!empty($data)) {
         $this->CONDUCTTR_PROJECT_ID = $data[0]['PROJECT_ID'];
         $this->CONDUCTTR_CONSUMER_KEY = $data[0]['CONSUMER_KEY'];
         $this->CONDUCTTR_CONSUMER_SECRET = $data[0]['CONSUMER_SECRET'];
         $this->CONDUCTTR_ACCESS_TOKEN = $data[0]['ACCESS_TOKEN'];
         $this->CONDUCTTR_ACCESS_TOKEN_SECRET = $data[0]['ACCESS_TOKEN_SECRET'];
         $this->REGISTRATION_REQUIRED = $data[0]['REGISTRATION_REQUIRED'];
         $this->BADGES_GROUP_ID = $data[0]['BADGES_GROUP_ID'];
         $this->ROLES_GROUP_ID = $data[0]['ROLES_GROUP_ID'];
         $this->DELAY = $data[0]['DELAY'];
         $this->audience_id = $data[0]['id'];
         $this->audience_email = $data[0]['audience_email'];
         $this->audience_phone = $data[0]['audience_phone'];
         $this->audience_first_name = $data[0]['audience_first_name'];
         $this->audience_last_name = $data[0]['audience_last_name'];
         $this->roles = $data[0]['roles'];
         $this->profile_image = $data[0]['profile_image'];
     }
     /* NEW CODE - MESSAGE FEED Based */
     if ($this->INVENTORY == false) {
         $CONDUCTTR_REQUEST_URL = "https://api.conducttr.com/v1/project/" . $this->CONDUCTTR_PROJECT_ID . "/get_communicator";
         $params = array("audience_email" => $this->audience_email);
         $options = array('consumer_key' => $this->CONDUCTTR_CONSUMER_KEY, 'consumer_secret' => $this->CONDUCTTR_CONSUMER_SECRET);
         OAuthStore::instance("2Leg", $options);
         $req = new OAuthRequestSigner($CONDUCTTR_REQUEST_URL, "GET", $params);
         $secrets = array('signature_methods' => array('HMAC-SHA1'), 'token' => $this->CONDUCTTR_ACCESS_TOKEN, 'token_secret' => $this->CONDUCTTR_ACCESS_TOKEN_SECRET, 'nonce' => $this->makeNonce(), 'timestamp' => time(), 'consumer_key' => $this->CONDUCTTR_CONSUMER_KEY, 'consumer_secret' => $this->CONDUCTTR_CONSUMER_SECRET);
         $req->sign(0, $secrets);
         $signed_url = sprintf('%s?%s', $CONDUCTTR_REQUEST_URL, $req->getQueryString(false));
         $options = array(CURLOPT_HEADER => false, CURLOPT_URL => $signed_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
         $curl = curl_init();
         curl_setopt_array($curl, $options);
         $response = curl_exec($curl);
         if (!$response) {
             $response = curl_error($curl);
         }
         curl_close($curl);
         $results = json_decode($response);
         /* UNLOCKED ITEMS */
         $st = $this->db->prepare('UPDATE messages SET unlocked=:unlocked WHERE audience_id=:audience_id');
         $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
         $st->bindValue(':unlocked', false, PDO::PARAM_INT);
         $st->execute();
         for ($i = 0; $i < sizeof($results->results); $i++) {
             $total_count = 0;
             $total_question_count = 0;
             foreach ($results->results[$i] as $key => $value) {
                 for ($j = 0; $j < sizeof($value); $j++) {
                     $id = $value[$j][1];
                     $message_feed_id = $value[$j][16];
                     $name = $value[$j][5];
                     $body = $value[$j][3];
                     $type = $value[$j][17];
                     $character_name = $value[$j][15];
                     $count = 0;
                     $is_question = false;
                     /* Debug */
                     echo "<b>MESSAGE ID: </b>" . $id;
                     echo "<br>";
                     echo "<b>MESSAGE FEED ID: </b>" . $message_feed_id;
                     echo "<br>";
                     echo "<b>MESSAGE NAME: </b>" . $name;
                     echo "<br>";
                     echo "<b>Body: </b>" . $body;
                     echo "<br>";
                     echo "<b>Type: </b>" . $type;
                     echo "<br>";
                     echo "<b>Character name: </b>" . $character_name;
                     echo "<br><br>";
                     /* Debug */
                     if ($type != "Mail" && $type != "Blog") {
                         $parsed_body = preg_replace('/\\<\\/div\\>/', "</div>\n", $body);
                         $parsed_body = preg_replace("/<\\/?([a-z][a-z0-9]*)\\b[^>]*>/", "", $parsed_body);
                         $parsed_body = preg_replace("/\n+/", "\n", $parsed_body);
                         $parsed_body = preg_replace("/\\|name\\|/", $this->audience_first_name, $parsed_body);
                         $parsed_body = preg_replace("/\\|lname\\|/", $this->audience_last_name, $parsed_body);
                         $array = explode("\n", $parsed_body);
                         $count = 0;
                         for ($w = 0; $w < sizeof($array); $w++) {
                             if (!empty($array[$w])) {
                                 if ($array[$w][0] != "d" && $array[$w][0] != "q" && $array[$w][0] != "w" && $array[$w][0] != "g" && $array[$w][0] != "o") {
                                     $count++;
                                 }
                                 if (($array[$w][0] == "q" || $array[$w][0] == "w" || $array[$w][0] == "g" || $array[$w][0] == "o") && $array[$w][1] == ".") {
                                     $is_question |= true;
                                 }
                             }
                         }
                     } else {
                         preg_match("/q\\./", $body, $question);
                         if (empty($question)) {
                             $parsed_body = preg_replace("/<div.*?>/", "", $body);
                             $parsed_body = preg_replace("/<\\/div>/", "", $parsed_body);
                         } else {
                             $parsed_body = preg_replace("/<\\/?([a-z][a-z0-9]*)\\b[^>]*>/", "\n", $body);
                         }
                         $parsed_body = preg_replace("/\n+/", "\n", $parsed_body);
                         $parsed_body = preg_replace("/\\|name\\|/", $this->audience_first_name, $parsed_body);
                         $parsed_body = preg_replace("/\\|lname\\|/", $this->audience_last_name, $parsed_body);
                         $array = explode("\\[", $parsed_body);
                         $array = explode("\n", $parsed_body);
                         $count = 0;
                         for ($w = 0; $w < sizeof($array); $w++) {
                             if (!empty($array[$w])) {
                                 if ($array[$w][0] != "d" && $array[$w][0] != "q" && $array[$w][0] != "w" && $array[$w][0] != "g" && $array[$w][0] != "o") {
                                     $count++;
                                 }
                             }
                         }
                         $array = explode("\n", $parsed_body);
                         for ($w = 0; $w < sizeof($array); $w++) {
                             if (!empty($array[$w])) {
                                 if (($array[$w][0] == "q" || $array[$w][0] == "w" || $array[$w][0] == "g" || $array[$w][0] == "0") && $array[$w][1] == ".") {
                                     $is_question |= true;
                                 }
                             }
                         }
                     }
                     //$st = $this->db->prepare('INSERT IGNORE INTO messages (id, audience_id, name, type, body, message_feed_id, character_name, question, count, unlocked) VALUES (:id, :audience_id, :name, :type, :body, :message_feed_id, :character_name, :question, :count, :unlocked)');
                     $st = $this->db->prepare('INSERT INTO messages (id, audience_id, name, type, body, message_feed_id, character_name, question, count, unlocked) VALUES (:id, :audience_id, :name, :type, :body, :message_feed_id, :character_name, :question, :count, :unlocked) ON DUPLICATE KEY UPDATE unlocked=true');
                     $st->bindValue(':id', $id, PDO::PARAM_STR);
                     $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
                     $st->bindValue(':name', $name, PDO::PARAM_STR);
                     $st->bindValue(':message_feed_id', $message_feed_id, PDO::PARAM_INT);
                     $st->bindValue(':character_name', $character_name, PDO::PARAM_INT);
                     $st->bindValue(':body', $parsed_body, PDO::PARAM_STR);
                     $st->bindValue(':type', $type, PDO::PARAM_STR);
                     $st->bindValue(':question', $is_question, PDO::PARAM_BOOL);
                     $st->bindValue(':count', $count, PDO::PARAM_INT);
                     $st->bindValue(':unlocked', true, PDO::PARAM_BOOL);
                     $st->execute();
                     print_r($st->errorInfo());
                     $total_count += $count;
                     if ($is_question) {
                         $total_question_count++;
                     }
                 }
             }
             /*
             $st = $this->db->prepare('INSERT INTO message_feeds (id, audience_id, character_name, type, count, question_count) VALUES (:id, :audience_id, :character_name, :type, :count, :question_count) ON DUPLICATE KEY UPDATE count=:count,question_count=:question_count ');	
             $st->bindValue(':id', $message_feed_id, PDO::PARAM_INT);
             $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
             $st->bindValue(':character_name',$character_name, PDO::PARAM_STR);
             $st->bindValue(':type',$type, PDO::PARAM_STR);
             $st->bindValue(':count',$total_count, PDO::PARAM_INT);
             $st->bindValue(':question_count',$total_question_count, PDO::PARAM_INT);
             $st->execute();
             */
         }
     } else {
         $CONDUCTTR_REQUEST_URL = "https://api.conducttr.com/v1/project/" . $this->CONDUCTTR_PROJECT_ID . "/get_audience_inventory";
         $params = array("audience_email" => $this->audience_email);
         $options = array('consumer_key' => $this->CONDUCTTR_CONSUMER_KEY, 'consumer_secret' => $this->CONDUCTTR_CONSUMER_SECRET);
         OAuthStore::instance("2Leg", $options);
         $req = new OAuthRequestSigner($CONDUCTTR_REQUEST_URL, "GET", $params);
         $secrets = array('signature_methods' => array('HMAC-SHA1'), 'token' => $this->CONDUCTTR_ACCESS_TOKEN, 'token_secret' => $this->CONDUCTTR_ACCESS_TOKEN_SECRET, 'nonce' => $this->makeNonce(), 'timestamp' => time(), 'consumer_key' => $this->CONDUCTTR_CONSUMER_KEY, 'consumer_secret' => $this->CONDUCTTR_CONSUMER_SECRET);
         $req->sign(0, $secrets);
         $signed_url = sprintf('%s?%s', $CONDUCTTR_REQUEST_URL, $req->getQueryString(false));
         $options = array(CURLOPT_HEADER => false, CURLOPT_URL => $signed_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
         $curl = curl_init();
         curl_setopt_array($curl, $options);
         $response = curl_exec($curl);
         if (!$response) {
             $response = curl_error($curl);
         }
         curl_close($curl);
         $results = json_decode($response);
         /* UNLOCKED ITEMS */
         $st = $this->db->prepare('UPDATE inventory_items SET unlocked=:unlocked WHERE audience_id=:audience_id');
         $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
         $st->bindValue(':unlocked', false, PDO::PARAM_INT);
         $st->execute();
         for ($i = 0; $i < sizeof($results->results); $i++) {
             $inventory_count = 0;
             $type = $results->results[$i]->inventory_name;
             preg_match("/\\{(.*?)\\}/", $results->results[$i]->inventory_name, $matches);
             $inventory_name = preg_replace("/\\{(.*?)\\}/", "", $type);
             if ($matches[0] == "{whatsup}" || $matches[0] == "{msngr}") {
                 $type = "Msngr";
             } else {
                 if ($matches[0] == "{cmail}" || $matches[0] == "{mail}") {
                     $type = "Mail";
                 } else {
                     if ($matches[0] == "{fakebook}" || $matches[0] == "{gosocial}") {
                         $type = "GoSocial";
                     } else {
                         if ($matches[0] == "{tuiter}" || ($matches[0] == "{tuitter}" || $matches[0] == "{microblog}")) {
                             $type = "Microblog";
                         } else {
                             if ($matches[0] == "{media}" || $matches[0] == "{file}") {
                                 $type = "Media";
                             } else {
                                 if ($matches[0] == "{blog}") {
                                     $type = "Blog";
                                 }
                             }
                         }
                     }
                 }
             }
             $st = $this->db->prepare('INSERT INTO inventory_attributes (audience_id, inventory_name, type ) VALUES (:audience_id, :inventory_name, :type) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)');
             $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
             $st->bindValue(':inventory_name', $inventory_name, PDO::PARAM_STR);
             $st->bindValue(':type', $type, PDO::PARAM_STR);
             $st->execute();
             $inventory_id = $this->db->lastInsertId();
             for ($j = 0; $j < sizeof($results->results[$i]->items); $j++) {
                 $count++;
                 if ($matches[0] == "{whatsup}" || $matches[0] == "{msngr}") {
                     $type = "msngr";
                 } else {
                     if ($matches[0] == "{cmail}" || $matches[0] == "{mail}") {
                         $type = "mail";
                     } else {
                         if ($matches[0] == "{fakebook}" || $matches[0] == "{gosocial}") {
                             $type = "gosocial";
                         } else {
                             if ($matches[0] == "{tuiter}" || ($matches[0] == "{tuitter}" || $matches[0] == "{microblog}")) {
                                 $type = "microblog";
                             } else {
                                 if ($matches[0] == "{media}" || $matches[0] == "{file}") {
                                     $type = "media";
                                 } else {
                                     if ($matches[0] == "{blog}") {
                                         $type = "blog";
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $is_question = false;
                 if ($type != "mail" && $type != "blog") {
                     //print_r($results->results[$i]->items[$j]->body);
                     $messages_array = preg_replace("/<\\/?([a-z][a-z0-9]*)\\b[^>]*>/", "\n", $results->results[$i]->items[$j]->body);
                     $messages_array = preg_replace("/\n+/", "\n", $messages_array);
                     $messages_array = preg_replace("/\\|name\\|/", $this->audience_first_name, $messages_array);
                     $messages_array = preg_replace("/\\|lname\\|/", $this->audience_last_name, $messages_array);
                     $array = explode("\n", $messages_array);
                     $count = 0;
                     for ($w = 0; $w < sizeof($array); $w++) {
                         if (!empty($array[$w])) {
                             if ($array[$w][0] != "d" && $array[$w][0] != "q" && $array[$w][0] != "w" && $array[$w][0] != "g" && $array[$w][0] != "o") {
                                 $count++;
                             }
                             if (($array[$w][0] == "q" || $array[$w][0] == "w" || $array[$w][0] == "g" || $array[$w][0] == "o") && $array[$w][1] == ".") {
                                 $is_question |= true;
                             }
                         }
                     }
                 } else {
                     preg_match("/q\\./", $results->results[$i]->items[$j]->body, $question);
                     if (empty($question)) {
                         $messages_array = preg_replace("/<div.*?>/", "", $results->results[$i]->items[$j]->body);
                         $messages_array = preg_replace("/<\\/div>/", "", $messages_array);
                     } else {
                         $messages_array = preg_replace("/<\\/?([a-z][a-z0-9]*)\\b[^>]*>/", "\n", $results->results[$i]->items[$j]->body);
                     }
                     $messages_array = preg_replace("/\n+/", "\n", $messages_array);
                     $messages_array = preg_replace("/\\|name\\|/", $this->audience_first_name, $messages_array);
                     $messages_array = preg_replace("/\\|lname\\|/", $this->audience_last_name, $messages_array);
                     $array = explode("\\[", $messages_array);
                     $count = 0;
                     for ($w = 0; $w < sizeof($array); $w++) {
                         if (!empty($array[$w])) {
                             $count++;
                         }
                     }
                     $array = explode("\n", $messages_array);
                     for ($w = 0; $w < sizeof($array); $w++) {
                         if (!empty($array[$w])) {
                             if (($array[$w][0] == "q" || $array[$w][0] == "w" || $array[$w][0] == "g") && $array[$w][1] == ".") {
                                 $is_question |= true;
                             }
                         }
                     }
                 }
                 $item_name = $results->results[$i]->items[$j]->name;
                 $insert = false;
                 $item_roles = array();
                 preg_match_all("/\\/(.*?)\\//", $results->results[$i]->items[$j]->name, $item_roles);
                 if (!empty($item_roles[1])) {
                     for ($r = 0; $r < sizeof($item_roles[1]); $r++) {
                         if (in_array($item_roles[1][$r], unserialize($this->roles))) {
                             $insert = true;
                         }
                     }
                 } else {
                     $insert = true;
                 }
                 //print_r($item_roles[1]);
                 //print_r('<br>');
                 //print_r(unserialize($this->roles));
                 //print_r('<br>');
                 //echo "Insert: ".$insert;
                 if ($insert) {
                     //print_r('<br>Insert '.$results->results[$i]->items[$j]->name.'<br>');
                     $st = $this->db->prepare('INSERT INTO inventory_items (audience_id, inventory_name, item_name, type, body, inventory_id, question, count, unlocked) VALUES (:audience_id, :inventory_name, :item_name,:type,:body,:inventory_id, :question, :count, :unlocked) ON DUPLICATE KEY UPDATE body=:body,question=:question, count=:count, unlocked=:unlocked');
                     $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
                     $st->bindValue(':inventory_name', $inventory_name, PDO::PARAM_STR);
                     $st->bindValue(':inventory_id', $inventory_id, PDO::PARAM_INT);
                     $st->bindValue(':item_name', $item_name, PDO::PARAM_STR);
                     $st->bindValue(':body', $messages_array, PDO::PARAM_STR);
                     $st->bindValue(':type', $type, PDO::PARAM_STR);
                     $st->bindValue(':question', $is_question, PDO::PARAM_BOOL);
                     $st->bindValue(':count', $count, PDO::PARAM_INT);
                     $st->bindValue(':unlocked', true, PDO::PARAM_BOOL);
                     $st->execute();
                     //print_r($st->errorInfo());
                     $inventory_count += $count;
                 }
                 //else print_r('Not inserted '.$results->results[$i]->items[$j]->name.'<br>');
             }
             $item_name = $results->results[$i]->items[$j]->name;
             $st = $this->db->prepare('UPDATE inventory_attributes SET count=:count WHERE id=:inventory_id AND audience_id=:audience_id');
             $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
             $st->bindValue(':inventory_id', $inventory_id, PDO::PARAM_INT);
             $st->bindValue(':count', $inventory_count, PDO::PARAM_INT);
             $st->execute();
             $inventory_id = $this->db->lastInsertId();
         }
         /* RESET ITEMS */
         $st = $this->db->prepare('UPDATE inventory_items SET already_read=:already_read WHERE audience_id=:audience_id AND unlocked=false');
         $st->bindValue(':audience_id', $this->audience_id, PDO::PARAM_INT);
         $st->bindValue(':already_read', false, PDO::PARAM_INT);
         $st->execute();
     }
     return array("Response" => "OK");
 }
function oauth_test()
{
    error_reporting(E_ALL);
    header('Content-Type: text/plain; charset=utf-8');
    echo "Performing OAuth module tests.\n\n";
    echo "See also: http://wiki.oauth.net/TestCases\n\n";
    assert_options(ASSERT_CALLBACK, 'oauth_assert_handler');
    assert_options(ASSERT_WARNING, 0);
    $req = new OAuthRequest('http://www.example.com', 'GET');
    echo "***** Parameter Encoding *****\n\n";
    assert('$req->urlencode(\'abcABC123\') == \'abcABC123\'');
    assert('$req->urlencode(\'-._~\') == \'-._~\'');
    assert('$req->urlencode(\'%\') == \'%25\'');
    assert('$req->urlencode(\'&=*\') == \'%26%3D%2A\'');
    assert('$req->urlencode(\'&=*\') == \'%26%3D%2A\'');
    assert('$req->urlencode("\\n") == \'%0A\'');
    assert('$req->urlencode(" ") == \'%20\'');
    assert('$req->urlencode("\\x7f") == \'%7F\'');
    echo "***** Normalize Request Parameters *****\n\n";
    $req = new OAuthRequest('http://example.com/?name', 'GET');
    assert('$req->getNormalizedParams() == \'name=\'');
    $req = new OAuthRequest('http://example.com/?a=b', 'GET');
    assert('$req->getNormalizedParams() == \'a=b\'');
    $req = new OAuthRequest('http://example.com/?a=b&c=d', 'GET');
    assert('$req->getNormalizedParams() == \'a=b&c=d\'');
    // At this moment we don't support two parameters with the same name
    // so I changed this test case to "a=" and "b=" and not "a=" and "a="
    $req = new OAuthRequest('http://example.com/?b=x!y&a=x+y', 'GET');
    assert('$req->getNormalizedParams() == \'a=x%20y&b=x%21y\'');
    $req = new OAuthRequest('http://example.com/?x!y=a&x=a', 'GET');
    assert('$req->getNormalizedParams() == \'x=a&x%21y=a\'');
    echo "***** Base String *****\n\n";
    $req = new OAuthRequest('http://example.com/?n=v', 'GET');
    assert('$req->signatureBaseString() == \'GET&http%3A%2F%2Fexample.com%2F&n%3Dv\'');
    $req = new OAuthRequest('https://photos.example.net/request_token', 'POST', 'oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1191242090&oauth_nonce=hsu94j3884jdopsl&oauth_signature_method=PLAINTEXT&oauth_signature=ignored', array('X-OAuth-Test' => true));
    assert('$req->signatureBaseString() == \'POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0\'');
    $req = new OAuthRequest('http://photos.example.net/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature=ignored&oauth_signature_method=HMAC-SHA1', 'GET');
    assert('$req->signatureBaseString() == \'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal\'');
    echo "***** HMAC-SHA1 *****\nRequest signing\n";
    OAuthStore::instance('MySQL', array('conn' => false));
    $req = new OAuthRequestSigner('http://photos.example.net/photos?file=vacation.jpg&size=original', 'GET');
    assert('$req->urldecode($req->calculateDataSignature(\'bs\', \'cs\', \'\',   \'HMAC-SHA1\')) == \'egQqG5AJep5sJ7anhXju1unge2I=\'');
    assert('$req->urldecode($req->calculateDataSignature(\'bs\', \'cs\', \'ts\', \'HMAC-SHA1\')) == \'VZVjXceV7JgPq/dOTnNmEfO0Fv8=\'');
    $secrets = array('consumer_key' => 'dpf43f3p2l4k3l03', 'consumer_secret' => 'kd94hf93k423kf44', 'token' => 'nnch734d00sl2jdk', 'token_secret' => 'pfkkdhi9sl3r4s00', 'signature_methods' => array('HMAC-SHA1'), 'nonce' => 'kllo9940pd9333jh', 'timestamp' => '1191242096');
    $req->sign(0, $secrets);
    assert('$req->getParam(\'oauth_signature\', true) == \'tR3+Ty81lMeYAr/Fid0kMTYa/WM=\'');
    echo "***** HMAC-SHA1 *****\nRequest verification\n";
    $req = new OAuthRequestVerifier('http://photos.example.net/photos?file=vacation.jpg&size=original' . '&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk' . '&oauth_signature_method=HMAC-SHA1&oauth_nonce=kllo9940pd9333jh' . '&oauth_timestamp=1191242096&oauth_version=1.0' . '&oauth_signature=' . rawurlencode('tR3+Ty81lMeYAr/Fid0kMTYa/WM='), 'GET');
    $req->verifySignature('kd94hf93k423kf44', 'pfkkdhi9sl3r4s00');
    echo "\n";
    echo "***** Yahoo! test case ******\n\n";
    OAuthStore::instance('MySQL', array('conn' => false));
    $req = new OAuthRequestSigner('http://example.com:80/photo', 'GET');
    $req->setParam('title', 'taken with a 30% orange filter');
    $req->setParam('file', 'mountain & water view');
    $req->setParam('format', 'jpeg');
    $req->setParam('include', array('date', 'aperture'));
    $secrets = array('consumer_key' => '1234=asdf=4567', 'consumer_secret' => 'erks823*43=asd&123ls%23', 'token' => 'asdf-4354=asew-5698', 'token_secret' => 'dis9$#$Js009%==', 'signature_methods' => array('HMAC-SHA1'), 'nonce' => '3jd834jd9', 'timestamp' => '12303202302');
    $req->sign(0, $secrets);
    // echo "Basestring:\n",$req->signatureBaseString(), "\n\n";
    //echo "queryString:\n",$req->getQueryString(), "\n\n";
    assert('$req->getQueryString() == \'title=taken%20with%20a%2030%25%20orange%20filter&file=mountain%20%26%20water%20view&format=jpeg&include=date&include=aperture\'');
    //echo "oauth_signature:\n",$req->getParam('oauth_signature', true),"\n\n";
    assert('$req->getParam(\'oauth_signature\', true) == \'jMdUSR1vOr3SzNv3gZ5DDDuGirA=\'');
    echo "\n\nFinished.\n";
}