Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function twitter_media_page($query)
- {
- $content = "";
- $status = stripslashes($_POST['message']);
- if ($_POST['message'] && $_FILES['image']['tmp_name'])
- {
- require 'tmhOAuth.php';
- // Geolocation parameters
- list($lat, $long) = explode(',', $_POST['location']);
- if (is_numeric($lat) && is_numeric($long)) {
- $post_data['lat'] = $lat;
- $post_data['long'] = $long;
- }
- list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
- $tmhOAuth = new tmhOAuth(array(
- 'consumer_key' => OAUTH_CONSUMER_KEY,
- 'consumer_secret' => OAUTH_CONSUMER_SECRET,
- 'user_token' => $oauth_token,
- 'user_secret' => $oauth_token_secret,
- ));
- $image = "{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}";
- $code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
- array(
- 'media[]' => "@{$image}",
- 'status' => " " . $status, //A space is needed because twitter b0rks if first char is an @
- 'lat' => $lat,
- 'long' => $long,
- ),
- true, // use auth
- true // multipart
- );
- if ($code == 200) {
- $json = json_decode($tmhOAuth->response['response']);
- if ($_SERVER['HTTPS'] == "on") {
- $image_url = $json->entities->media[0]->media_url_https;
- }
- else {
- $image_url = $json->entities->media[0]->media_url;
- }
- $text = $json->text;
- $content = "<div class='profile'>Upload success. Image posted to Twitter.</div>";
- } else {
- $content = "Damn! Something went wrong. Sorry :-("
- ."<br /> code=" . $code
- ."<br /> status=" . $status
- ."<br /> image=" . $image
- ."<br /> response=<pre>"
- . print_r($tmhOAuth->response['response'], TRUE)
- . "</pre><br /> info=<pre>"
- . print_r($tmhOAuth->response['info'], TRUE)
- . "</pre><br /> code=<pre>"
- . print_r($tmhOAuth->response['code'], TRUE) . "</pre>";
- }
- }
- if($_POST) {
- if (!$_POST['message']) {
- $content .= "<div class='profile'>Please enter a message to go with your image.</div>";
- }
- if (!$_FILES['image']['tmp_name']) {
- $content .= "<div class='profile'>Please select an image to upload.</div>";
- }
- }
- $content .= "<div class='statusform'><form method='post' action='Upload Picture' enctype='multipart/form-data'>
- Image:<br /><input type='file' name='image' /><br /><br />
- Message (optional):<br />
- <textarea name='message' style='width:100%; max-width: 100%' rows='2' id='message'>Uploaded via #TweetVia</textarea><br>
- <input type='submit' value='Send' class='button' />
- <span id='remaining'>120</span>";
- $content .= ' <span id="geo" style="display: none;">
- <input onclick="goGeo()" type="checkbox" id="geoloc" name="location" />
- <label for="geoloc" id="lblGeo"></label>
- </span>
- <script type="text/javascript">
- started = false;
- chkbox = document.getElementById("geoloc");
- if (navigator.geolocation) {
- geoStatus("Tweet my location");
- if ("'.$_COOKIE['geo'].'"=="Y") {
- chkbox.checked = true;
- goGeo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment