Alqoe

Twitter Picture

Feb 20th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. function twitter_media_page($query)
  2. {
  3. $content = "";
  4. $status = stripslashes($_POST['message']);
  5.  
  6. if ($_POST['message'] && $_FILES['image']['tmp_name'])
  7. {
  8. require 'tmhOAuth.php';
  9.  
  10. // Geolocation parameters
  11. list($lat, $long) = explode(',', $_POST['location']);
  12. if (is_numeric($lat) && is_numeric($long)) {
  13. $post_data['lat'] = $lat;
  14. $post_data['long'] = $long;
  15. }
  16.  
  17. list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
  18.  
  19. $tmhOAuth = new tmhOAuth(array(
  20. 'consumer_key'    => OAUTH_CONSUMER_KEY,
  21. 'consumer_secret' => OAUTH_CONSUMER_SECRET,
  22. 'user_token'      => $oauth_token,
  23. 'user_secret'     => $oauth_token_secret,
  24. ));
  25.  
  26. $image = "{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}";
  27.  
  28. $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
  29. array(
  30. 'media[]'  => "@{$image}",
  31. 'status'   => " " . $status, //A space is needed because twitter b0rks if first char is an @
  32. 'lat'      => $lat,
  33. 'long'      => $long,
  34. ),
  35. true, // use auth
  36. true  // multipart
  37. );
  38.  
  39. if ($code == 200) {
  40. $json = json_decode($tmhOAuth->response['response']);
  41.  
  42. if ($_SERVER['HTTPS'] == "on") {
  43. $image_url = $json->entities->media[0]->media_url_https;
  44. }
  45. else {
  46. $image_url = $json->entities->media[0]->media_url;
  47. }
  48.  
  49. $text = $json->text;
  50.  
  51. $content = "<div class='profile'>Upload success. Image posted to Twitter.</div>";
  52. } else {
  53. $content = "Damn! Something went wrong. Sorry :-("
  54. ."<br /> code=" . $code
  55. ."<br /> status=" . $status
  56. ."<br /> image=" . $image
  57. ."<br /> response=<pre>"
  58. . print_r($tmhOAuth->response['response'], TRUE)
  59. . "</pre><br /> info=<pre>"
  60. . print_r($tmhOAuth->response['info'], TRUE)
  61. . "</pre><br /> code=<pre>"
  62. . print_r($tmhOAuth->response['code'], TRUE) . "</pre>";
  63. }
  64. }
  65.  
  66. if($_POST) {
  67. if (!$_POST['message']) {
  68. $content .= "<div class='profile'>Please enter a message to go with your image.</div>";
  69. }
  70.  
  71. if (!$_FILES['image']['tmp_name']) {
  72. $content .= "<div class='profile'>Please select an image to upload.</div>";
  73. }
  74. }
  75.  
  76. $content .=   "<div class='statusform'><form method='post' action='Upload Picture' enctype='multipart/form-data'>
  77. Image:<br /><input type='file' name='image' /><br /><br />
  78. Message (optional):<br />
  79. <textarea name='message' style='width:100%; max-width: 100%' rows='2' id='message'>Uploaded via #TweetVia</textarea><br>
  80. <input type='submit' value='Send' class='button' />
  81. <span id='remaining'>120</span>";
  82. $content .= '   <span id="geo" style="display: none;">
  83. <input onclick="goGeo()" type="checkbox" id="geoloc" name="location" />
  84. <label for="geoloc" id="lblGeo"></label>
  85. </span>
  86. <script type="text/javascript">
  87. started = false;
  88. chkbox = document.getElementById("geoloc");
  89. if (navigator.geolocation) {
  90. geoStatus("Tweet my location");
  91. if ("'.$_COOKIE['geo'].'"=="Y") {
  92. chkbox.checked = true;
  93. goGeo();
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment