Closed GoogleCodeExporter closed 9 years ago
and you can exchange the content of 't' and 'd' to change the order of the
message
and the picture url...
't' means 'topic'
'd' means 'description'
so let
't' => '','d' => stripslashes($_POST['message']),
will result in 'xxx - http://moby.to/xxxxxx'
while let
't' => stripslashes($_POST['message']),'d' => '',
will result in 'http://moby.to/xxxxxx - xxx'
Original comment by felixonm...@gmail.com
on 11 Jan 2010 at 6:01
sorry and for the original version of dabr the line
if ($GLOBALS['user']['password'] == '') {
should be changed to
if (user_type() == 'oauth') {
so it can work properly...
sorry again
Original comment by felixonm...@gmail.com
on 11 Jan 2010 at 6:12
here's another option that uses yfrog, imgur, and posterous
http://myopiclunacy.com/2009/11/24/expanding-dabr-photo-upload-options
Original comment by ldoug...@gmail.com
on 11 Jan 2010 at 9:36
why not using OAuth ? so don't have to see the "You can\'t use Mobypicture
uploads
while accessing Dabr using an OAuth login"
yfrog is already use OAuth , so why not implement it to dabr .. to make it
easier and
get more trust from user :-)
Original comment by malco...@gmail.com
on 13 Jan 2010 at 10:45
[deleted comment]
[deleted comment]
Here is my new patch:
in common/twitter.php:
'twitpic' => array(
'security' => true,
'callback' => 'twitter_twitpic_page',
),
====>
'picture' => array(
'security' => true,
'callback' => 'twitter_picture_page',
),
And then:
after
if ($_POST['message']) {
:
$ms1 = stripslashes($_POST['message']);
$ms2 = urlencode($ms1);
switch ($_POST['service']){
case 'twitpic':
$response = twitter_process('http://twitpic.com/api/upload', array(
'media' => '@'.$_FILES['media']['tmp_name'],
'username' => user_current_username(),
'password' => $GLOBALS['user']['password'],
));
if (preg_match('#mediaurl>(.*)</mediaurl#', $response, $matches)) {
//$id = $matches[1];
twitter_update_pic($ms1.' '.$matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'imgly':
if($_POST['service']=='imgly')
$response = twitter_process('http://img.ly/api/upload', array(
'media' => '@'.$_FILES['media']['tmp_name'],
'username' => user_current_username(),
'password' => $GLOBALS['user']['password'],
));
if (preg_match('#mediaurl>(.*)</mediaurl#', $response, $matches)) {
//$id = base64_encode($matches[1]);
twitter_update_pic($ms1.' '.$matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'twicli':
$response = twitter_process('http://twic.li/api/uploadPhotoAndTweet', array(
'photo' => '@'.$_FILES['media']['tmp_name'],
'tweet' => $ms2,
'username' => user_current_username(),
'password' => $GLOBALS['user']['password'],
));
if (preg_match('#square_url>(.*)</square_url#', $response, $matches)) {
//$id = base64_encode($matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'tweetphoto':
$response = twitter_process('http://tweetphotoapi.com/api/upload.aspx',
array(
'media' => '@'.$_FILES['media']['tmp_name'],
'api_key' => '<YOUR API KEY>',
'username' => user_current_username(),
'password' => $GLOBALS['user']['password'],
));
if (preg_match('#MediaUrl>(.*)</MediaUrl#', $response, $matches)) {
//$id = base64_encode($matches[1]);
twitter_update_pic($ms1.' '.$matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'imgur':
$response = twitter_process('http://imgur.com/api/upload', array(
'image' => '@'.$_FILES['media']['tmp_name'],
'key' => '<YOUR API KEY>',
));
if (preg_match('#small_thumbnail>(.*)</small_thumbnail#', $response,
$matches)) {
//$id = base64_encode($matches[1]);
twitter_update_pic($ms1.' '.$matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'twitsnaps':
$response = twitter_process('http://www.twitsnaps.com/api.php', array(
'file' => '@'.$_FILES['media']['tmp_name'],
'message' => $ms2,
'user_name' => user_current_username(),
'password' => $GLOBALS['user']['password'],
));
if (preg_match('#imageurl>(.*)</imageurl#', $response, $matches)) {
//$id = base64_encode($matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
case 'moby':
$response = twitter_process('http://api.mobypicture.com' array(
'action' => 'postMediaUrl',
'i' => '@'.$_FILES['media']['tmp_name'],
'u' => user_current_username(),
'p' => $GLOBALS['user']['password'],
'k' => MOBYPICTURE_API_KEY,
's' => 'none',
'format' => 'plain',
));
if (preg_match('/(http:\/\/moby\.to\/.+)/', $response, $matches)) {
//$id = base64_encode($matches[1]);
twitter_update_pic($ms1.' '.$matches[1]);
twitter_refresh("picture/confirm/".$_POST['service']);
} else {
twitter_refresh("picture/fail/".$_POST['service']);
}
break;
}
$content = $response;
} elseif ($query[1] == 'confirm') {
$content = $_POST['service']."<p>Picture upload to $query[2] success.</p>";
} elseif ($query[1] == 'fail') {
$content = $_POST['service']."<p>Picture upload to $query[2] failed. No idea
why!</p>";
} else {
//$content = '<form method="post" action="twitpic" enctype="multipart/form-
data">Image <input type="file" name="media" /><br />Message: <input type="text"
name="message" maxlength="120" /><br /><input type="submit" value="Upload"
/></form>';
$content = '<form method="post" action="picture" enctype="multipart/form-
data">Service: <select name="service"><option
value="twicli">Twic.li</option><option
value="moby">Mobypicture</option><option value="imgur">imgur</option><option
value="imgly">Img.ly</option><option
value="twitsnaps">TwitSnaps</option><option
value="tweetphoto">TweetPhoto</option><option
value="twitpic">Twitpic</option></select><br />Image: <input type="file"
name="media"
/><br />Message: <input type="text" name="message" maxlength="120" /><br
/><input
type="submit" value="Upload" /></form>';
}
return theme('page', 'Picture Upload', $content);
}
function twitter_update_pic($status) { //simply update a status for picture
function
use
$request = 'http://twitter.com/statuses/update.json';
$post_data = array('source' => 'dabr', 'status' => $status);
$b = twitter_process($request, $post_data);
}
this patch added 6 other
services(Twic.li/Mobypicture/imgur/Img.ly/TwitSnaps/Tweetphoto) to dabr :-)
Original comment by felixonm...@gmail.com
on 20 Jan 2010 at 3:02
What should be deleted before adding the code?
Original comment by rudolfpi...@gmail.com
on 7 Mar 2011 at 2:08
Can somebody assist me in adding more image hosting services?
Original comment by rudolfpi...@gmail.com
on 21 Mar 2011 at 9:28
why i always get error when i want to try this code?
Original comment by gajahan...@gmail.com
on 2 Sep 2011 at 2:38
@gajahan
the code is now outdated far and the way I was using does not work any more.
Original comment by felixonm...@gmail.com
on 2 Sep 2011 at 3:10
I kept this issue open in case it helped others implement the same, but if it
doesn't work then I'm now closing it.
Original comment by david.carrington
on 2 Sep 2011 at 3:39
Image is uploaded to MobyPicture, but message is not sent to Twitter.. somebody
help me :(
function twitter_mobypic_page($query) {
if (user_type() == 'oauth') {
//Has the user submitted an image and message?
if ($_POST['message']) {
$mobypicURL = 'https://api.mobypicture.com/2.0/upload.json';
//Set the initial headers
$header = array(
'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.xml',
'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/"'
);
//Using Abraham's OAuth library
require_once('OAuth.php');
// instantiating OAuth customer
$consumer = new OAuthConsumer(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
// instantiating signer
$sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
// user's token
list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
$token = new OAuthConsumer($oauth_token, $oauth_token_secret);
// Generate all the OAuth parameters needed
$signingURL = 'https://api.twitter.com/1/account/verify_credentials.xml';
$request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $signingURL, array());
$request->sign_request($sha1_method, $consumer, $token);
$header[1] .= ", oauth_consumer_key=\"" . $request->get_parameter('oauth_consumer_key') ."\"";
$header[1] .= ", oauth_signature_method=\"" . $request->get_parameter('oauth_signature_method') ."\"";
$header[1] .= ", oauth_token=\"" . $request->get_parameter('oauth_token') ."\"";
$header[1] .= ", oauth_timestamp=\"" . $request->get_parameter('oauth_timestamp') ."\"";
$header[1] .= ", oauth_nonce=\"" . $request->get_parameter('oauth_nonce') ."\"";
$header[1] .= ", oauth_version=\"" . $request->get_parameter('oauth_version') ."\"";
$header[1] .= ", oauth_signature=\"" . urlencode($request->get_parameter('oauth_signature')) ."\"";
//open connection
$ch = curl_init();
//Set paramaters
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$mobypicURL);
//mobypic requires the data to be sent as POST
$media_data = array(
'media' => '@'.$_FILES['media']['tmp_name'],
'message' => ' ' . stripslashes($_POST['message']), //A space is needed because mobypic b0rks if first char is an @
'key' =>MOBYPIC_API_KEY
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$media_data);
//execute post
$result = curl_exec($ch);
$response_info=curl_getinfo($ch);
//close connection
curl_close($ch);
if ($response_info['http_code'] == 200) { //Success
//Decode the response
$json = json_decode($result);
$id = $json->response->media->id;
$mobypicURL = $json->response->media->url;
$text = $json->response->media->text;
$message = trim($text);
//Send the user's message to twitter
$request = API_URL.'statuses/update.json';
$post_data = array('source' => 'dabr', 'value' => $message);
$status = twitter_process($request, $post_data);
//Back to the timeline
twitter_refresh("mobypic/confirm/$id");
}
else {
$content = "<p>mobypic upload failed. No idea why!</p>";
$content .= "<pre>";
$json = json_decode($result);
$content .= "<br / >message " . urlencode($_POST['message']);
$content .= "<br / >json " . print_r($json);
$content .= "<br / >Response " . print_r($response_info);
$content .= "<br / >header " . print_r($header);
$content .= "<br / >media_data " . print_r($media_data);
$content .= "<br />URL was " . $mobypicURL;
$content .= "<br />File uploaded was " . $_FILES['media']['tmp_name'];
$content .= "</pre>";
}
}
elseif ($query[1] == 'confirm') {
$content = "<p>Upload success. Image posted to Twitter.</p>";
}
else {
$content = "<form method='post' action='mobypic' enctype='multipart/form-data'>Image <input type='file' name='media' /><br />Message (optional):<br /><textarea name='message' style='width:90%; max-width: 400px;' rows='3' id='message'></textarea><br><input type='submit' value='Send'><span id='remaining'>110</span></form>";
$content .= js_counter("message", "110");
}
return theme('page', 'Mobypicture Upload', $content);
}
}
Original comment by saif4...@gmail.com
on 6 Jan 2012 at 1:12
Original issue reported on code.google.com by
felixonm...@gmail.com
on 11 Jan 2010 at 5:21