Selasa, 11 September 2012

0 Memasang Fitur Upload Avatar pada Dabr


kemudian masuk ke file common/twitter.php
tambahkan code di bawah ini di menu register
‘avatar’ => array(
‘hidden’ => true,
‘security’ => true,
‘callback’ => ‘twitter_avatar_page’,
),

masih di dalam file yang sama tambahkan fungsi di bawah ini
function twitter_avatar_page($query) {
if ( ! empty($_FILES)) {
require ‘tmhOAuth.php’;
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,
));
// note the type and filename are set here as well
$params = array(
‘image’ => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
);
// if we are setting the background we want it to be displayed
$code = $tmhOAuth->request(‘POST’, $tmhOAuth->url("1/account/update_profile_image"),
$params,
true, // use auth
true // multipart
);
if ($code == 200) {
$json = json_decode($tmhOAuth->response['response']);
$text = $json->text;
$content = "<span class=’status shift’><font color=’green’>You’ve success to upload a photo profile.</font></span>";
} else {
$content = "<span class=’status shift’><font color=’red’>Damn! Something went wrong. Sorry :-( </font></span>";
}
}
if($_POST) {
if (!$_FILES['image']['tmp_name']) {
$content .= "<span class=’status shift’><font color=’red’>Please select an image to upload.</font></span>";
}
}
$user = twitter_user_info(user_current_username());
$content .= theme(‘user_header’, $user);
$content .= "<form method=’post’ action=’avatar’ enctype=’multipart/form-data’><div>
Upload your avatar<br/>
<input type=’file’ name=’image’ /><br/>
<button type=’submit’ class=’button’>Upload</button></div></form>";
return theme(‘page’, ‘Upload Avatar’, $content);
}
selesai, semoga berhasil :)

0 Comments

Bagaimana Pendapat Anda ?