Showing posts with label Dabr Tutorial. Show all posts
Showing posts with label Dabr Tutorial. Show all posts

Friday, April 27, 2012

Edit Header Navigasi

hapus aja bagian $body = theme('menu_top'); di file common/theme.php
Code:
.....
function theme_page($title, $content) {
        $body = theme('menu_top');
.....
Trus bikin function baru lagi di common/theme.php. Misal
Code:
.....
function theme_google_analytics() {
        global $GA_ACCOUNT;
        if (!$GA_ACCOUNT) return '';
        $googleAnalyticsImageUrl = googleAnalyticsGetImageUrl();
        return "<img src='{$googleAnalyticsImageUrl}' />";
} 

function theme_mikarai() {
        $out = '<div class="menu"><center><a href="">Home</a> | <a href="/replies">Replies</a> | <a href="/search">Search</a> | <a href="/directs">Directs</a></div>';
    return $out;
} 
Jadi function theme_page seperti ini
Code:
.....
function theme_page($title, $content) {
         if (user_is_authenticated()) {
               $body = theme('mikarai');
        }
        $body .= $content;
.....
.....
Gunanya if (user_is_authenticated()) supaya menu itu gak muncul sebelum agan login.

Fitur Edit Profil

Edit file common/twitter.php nya gan..
PHP Code:
..........
.......... 
'trends' => array(
                
'hidden' => true,
                
'security' => true,
                
'callback' => 'twitter_trends_page',
        ), 
'profile' => array(
               
'security' => true,
               
'callback' => 'twitter_profile_page',
  ),
));

function 
twitter_profile_page() {

    
// process form data
    
if ($_POST['name']){
        
// post profile update
        
$post_data = array("name" => $_POST['name'],
            
"url" => $_POST['url'],
            
"location" => $_POST['location'],
            
"description" => $_POST['description'],
        );
        
$url "http://twitter.com/account/update_profile.json";
        
$user twitter_process($url$post_data);
    } else {
        
// retrieve profile information
        
$user twitter_user_info(user_current_username());
    }
    
    
$content theme('user_header'$user);
    
$content .= theme('profile_form'$user);
    
    
theme('page'"Profile Edit"$content);
}

function 
theme_profile_form($user){
    
// Profile form
    
$out .= "<form name='profile' action='profile' method='post'>
<hr />Name: <input name='name' maxlength='20' value='{$user->name}' />
<br />Bio: <input name='description' size=40 maxlength='160' value='{$user->description}' />
<br />Link: <input name='url' maxlength='100' size=40 value='{$user->url}' />
<br />Location: <input name='location' maxlength='30' value='{$user->location}' />"
;

    
// Javascript link to use Geo Coordinates
    
if(!empty($_COOKIE['lat']) && !empty($_COOKIE['long'])){
        
$out .= " <a href='javascript:document.forms[\"profile\"].location.value=\"dabr: {$_COOKIE['lat']},{$_COOKIE['long']}\";void(0);'>Use Geo</a>";
    }    

    
$out .= "<br /><input type='submit' value='Update' /></form>";

    return 
$out;
}

function 
long_url($shortURL)
{
        if (!
defined('LONGURL_KEY'))
..........
..........
..........  

Cara Buat Fitur Mute

Setelah saya menggunakan fitur mute yang sudah saya share sebelumnya, banyak sekali terjadi perubahan di twitter client saya, yang paling utama adalah url shorted berubah menjadi http://t.co semua, ini hal yang sederhana tapi saya pribadi tidak menginginkan fitur yang saya beri menjadi tidak berfungsi semestinya, nah dari situ saya menemukan triknya, agak pusing tapi menyenangkan...

Pertama, kamu buat file mute.php dan taruh di dalam folder common, isi file mute.php dengan code di bwah ini

code:

<?php

function muted_page($query) {
/*
mute landing page to show the mutedlist account
thanks for your respect to not change any information here :)
*/

$content = "<p>Muted Feature is help you to mute an annoying tweets from your timeline <img src='/smile/mv/sip.gif'><br/>";
$content .= "<br/>Just go to user profile page and click <b>`mute`</b> button to mute him/her tweet <img src='/smile/mv/ketawa.gif'>";
$content .= "</p>";

$act = $_REQUEST['act'];
$screen_name = $_REQUEST['user'];

if ($act != "" && $act != NULL) {
mute_save($screen_name,$act);
header('Location: '. BASE_URL . "mute");exit();

} else {
$muted_list = mute_read();
$content .= "<ul>";
foreach ($muted_list as $item) {
$content .= "<li>@$item&nbsp;";
$content .= "<a href='mute/?act=unmute&user={$item}'>Unmute</a></li>";
}
$content .= "</ul>";
theme('page', 'Muted List', $content);
}
}

function sensor($tl) {
/*
lembaga sensor tweets
here we censored any tweeps from mutedlist account
*/

$muted_list = mute_read();
$new_tl = array();

foreach ($tl as $item) {
$user = strtolower($item->from->screen_name);
if (!in_array($user,$muted_list)) $new_tl[strval($item->id)] = $item;
}
$hsl = json_decode(json_encode($new_tl));
return $hsl;
}

function mute_read() {
/* mutelist reader */

$muted_list = unserialize(base64_decode($_COOKIE['muted']));
if (!$muted_list) { return array();}
else { return json_decode($muted_list); }
}

function mute_save($new,$act) {
/* mutelist writer */

$new = strtolower($new);
$muted_list = mute_read();
if ($act == "mute") {
if (!in_array($new,$muted_list)) array_push($muted_list,$new);
} elseif ($act == "unmute") {
$tmp = array();
foreach ($muted_list as $item) {
if ($item != $new) array_push($tmp,$item);
}
$muted_list = $tmp;
}
$muted_list = json_encode($muted_list);
$duration = time() + (3600 * 24 * 365);
setcookie('muted', base64_encode(serialize($muted_list)), $duration, '/');
}

/* Remove mutedlist cookies when user logout */

if (!isset($GLOBALS['user'])) {
if(!array_key_exists('USER_AUTH', $_COOKIE)) {
$duration = time() - 3600;
setcookie("muted", NULL, $duration, '/');
setcookie("muted", NULL, $duration);
}
}

?>


Langkah selanjutnya, masuk ke file /common/twitter.php, tambahkan :

code pemanggilan file mute.php dengan cara menambahkan require 'mute.php'; di bagian awal file setelah code php

tambahkan code di dalam menu_register(array(

code:

'mute' => array(
'callback' => 'muted_page',
'security' => true,
), 


masih di dalam file yang sama, cari function twitter_home_page() dan pada code 

code:

$tl = twitter_standard_timeline($tl, 'friends');


danti dengan

code:

$tl = sensor(twitter_standard_timeline($tl, 'friends')); 


masih di dalam file yang sama, cari function theme_user_header($user) , tambahkan kode di bawah ini :

code:

if ($user->following !== false) {
$muted_list = mute_read();
if (in_array(strtolower($user->screen_name),$muted_list)) {
$out .= " | <a href='/mute/?act=unmute&user={$user->screen_name}'>Unmute</a>";
} else {
$out .= " | <a href='/mute/?act=mute&user={$user->screen_name}'>Mute</a>";
}
}


sebelum kode

code:

$out .= " | <a href='confirm/spam/{$user->screen_name}/{$user->id}'>Report Spam</a>";
$out .= " | <a href='search?query=%40{$user->screen_name}'>Search @{$user->screen_name}</a>";
$out .= "</div></div>";
return $out;
}


dan kalau bisa, jika agan menggunakan Embedly. tolong di cabut ya api keynya.
soalnya bentrok sama fitur ini....

Who's Online Dabr

[buat twitter who is online]

buat file count.php di root

Code:
<?php
error_reporting(E_ERROR | E_PARSE);
$dataFile = "onlineusers.txt";
if (user_is_authenticated()) {
    $user = user_current_username();
}
// this is the time in **minutes** to consider someone online before removing them from our file
// berapa menit tenggang waktu yg dibutuhkan untuk tahu user masih online atau tidak.
$sessionTime = 5;
if(!file_exists($dataFile)) {
    $fp = fopen($dataFile, "w+");
    fclose($fp);
}
$users = array();
$onusers = array();
// check up
$fp = fopen($dataFile, "r");
flock($fp, LOCK_SH);
while(!feof($fp)) {
    $users[] = rtrim(fgets($fp, 32));
}
flock($fp, LOCK_UN);
fclose($fp);
// clean up
$x = 0;
$alreadyIn = FALSE;
foreach($users as $key => $data) {
    list(,$lastvisit) = explode("|", $data);
    if(time() - $lastvisit >= $sessionTime * 60) {
        $users[$x] = "";
    } else {
        if(strpos($data, $user) !== FALSE) {
            $alreadyIn = TRUE;
            $users[$x] = "$user|" . time(); //updating
        }
    }
    $x++;
}
if($alreadyIn == FALSE) {
    $users[] = "$user|" . time();
}
// write up
$fp = fopen($dataFile, "w+");
flock($fp, LOCK_EX);
$i = 0;
foreach($users as $single) {
    if($single != "") {
        fwrite($fp, $single . "\r\n");
        $i++;
    }
}
flock($fp, LOCK_UN);
fclose($fp);
?>
edit file common/theme.php, tambahkan code :

Code:
if (user_is_authenticated()) {
        require_once("count.php");
    }
echo    '</body>
        </html>';
    exit();

sesudah
       
         </head>
         <body>';

      echo $body;
buat file online.php di root

Code:
<?php
$myFile = "onlineusers.txt";
$fsc = file($myFile);
$lines = count(file($myFile));
$content = "<div>".$lines." Online Users:<br />";
foreach($fsc as $line) {
    $array = explode("|", $line);
    $content .= $array[0] ."</a><br />";
}
$content .= "</div>";

?>
edit index.php

tmbahkan code 

Code:
'online' => array (
        'security' => true,
        'callback' => 'online_page',
    ),

di menu_register(


tambahkan juga function online page.
Code :

function online_page() {
    require_once("online.php");
    theme('page', 'Online Users', $content);
}
file onlineusers.txt akan otomatis terbuat. Chmod ke 777

kalo g otomatis tinggal buat file onlineusers.txt di root dan chmod ke 777

Mengatasi 404 Not Found dengan .htaccess d

Coba buat file .htaccess di folder root (/public_html/folder_tempat_script_dabr_yg_agan_simpan)

File .htaccess saya seperti ini
PHP Code:
# URL rewriting RewriteEngine on
RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)$ index.php?q=$[L,QSA]

<
IfModule header_module>
    
# 1 week cache
    
<FilesMatch "\.(png|ico)$">
    
Header set Cache-Control "max-age=604800, public"
    
</FilesMatch>
</
IfModule>  
Mudah2an bisa jalan, gan. Cmiwww...

Mengedit Footer

edit file common/theme.php
Jadi seperti ini
PHP Code:
....
....
function 
theme_page($title$content) {
        
$body theme('logo');
        
$body .= theme('menu_top');
        
$body .= $content;
        
$body .= theme('footer');
        if (
DEBUG_MODE == 'ON') {
                global 
$dabr_start$api_time;
                
$time microtime(1) - $dabr_start;
                
$body .= '<p>Processed in '.round($time4).' seconds ('.round($api_time $time 100).'% waiting for Twitter\'s API)</p>';
        }
        if (
$title == 'Login') {
                
$title 'mobile Twitter client';
                
$meta '<meta name="description" content="another mobile Twitter client" />';
        }
        
ob_start('ob_gzhandler');
        
header('Content-Type: text/html; charset=utf-8');
        echo    
'<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                        <head>
                                <title>'
,Mikarai,' / ',$title,'</title>
                                <base href="'
,BASE_URL,'" />
                                '
.$meta.theme('css').'
                                <meta name="viewport" content="width=device-width; initial-scale=1.0;" />
                                <script type="text/javascript">'
.file_get_contents('js/ga.js').'</script>
                        </head>
                        <body>'
,  $body'</body>
                </html>'
;
        exit();
}
......
......
......
......

function 
theme_google_analytics() {
        global 
$GA_ACCOUNT;
        if (!
$GA_ACCOUNT) return '';
        
$googleAnalyticsImageUrl googleAnalyticsGetImageUrl();
        return 
"<img src='{$googleAnalyticsImageUrl}' />";
}

function 
theme_footer() {
        
$out '<div class="menu"><center><a href="followers">Followers</a> | <a href="/friends">Friends</a> | <a href="/lists">Lists</a> | <a href="/trends">Trends</a> | <a href="/search">Search</a> | <a href="/profile">Profile</a> | <a href="/about">About</a> | <a href="/settings">Settings</a><center><center><p><p><b>© Mikarai</b>.</center><b></p></p></div>';
    return 
$out;
}
?>  
Edit sesuka hati agan saja.. 

Menghilangkan About atau mengedit Menu di HomePage

Buka file common/user.php
Cari code ini
PHP Code:
function user_ensure_authenticated() {
    if (!
user_is_authenticated()) {
        
$content theme('login');
        
$content .= file_get_contents('about.html');
        
theme('page''Login'$content);
    }
}  
Cukup hilangkan aja kode
PHP Code:
$content .= file_get_contents('about.html');  

Mengatasi masalah Twitter Time Out

coba ganti: define('API_URL','http://api.twitter.com');
dengan yang ini: define('API_URL','http://api.twitter.com/1/');

ganti di config.php

Membuat Tweet otomatis terpotong jika lebih dari 140 karakter

Pertama agan buka /common/twitter.php --> buka pake notepad aja
trus cari sepenggal kode berikut :
Quote:
function twitter_update() {
twitter_ensure_post_action();
$status = twitter_url_shorten(stripslashes(trim($_POST['status'])));
nah dibawah kode itu , tambahin kode ini gan ..
Quote:
if (mb_strlen($status) > 140)
$status = mb_substr($status, 0, 140, 'utf-8');
kalo udah --> save --> upload lagi ke hostingan ..

Membatasi Jumlah Tweet yang Muncul di Home atau Timeline

edit file twitter.php di folder common.
cari kode dibawah ini
PHP Code:
function twitter_home_page() {
        
user_ensure_authenticated();
        
//$request = API_URL.'statuses/home_timeline.json?count=20&include_rts=true&page='.intval($_GET['page']);
        
$request API_URL.'statuses/home_timeline.json?count=20&include_rts=true';  
Ganti angka 20 itu sama 5 atau 6 (sesuai tweet yang mau ditampilin di home).

Cara Membuat Twitter Client Sendiri

Intro :
Quote:
baca [TWITTER] Tanya jawab disini  bagi yang belum tahu apa itu Twitter dan embel-embelnya
NOTES
Quote:
Jika ada Pertanyaan silahkan langsung tanyakan lewat sini, no pm no vm, no ym. Jika ada yang minta dibuatkan nggak peduli itu udah iso ataupun belum. Jangan Kontak TS. Silahkan belajar sendiri dan buat sendiri, atau minta buatkan ke agan-agan yang aktif pada thread ini.
Langsung saja yuk di share dan dibahas dimari

untuk yang pertama cara buat twitter client versi mobile dulu yuk
Untuk membuat Twitter Client harus membutuhkan :
Quote:
  • Hosting - Bisa yang gratisan asal support :
    Quote:
    * PHP 5.2+
    * curl PHP module
    * mcrypt PHP module
    * mod_rewrite apache module
  • domain (kalo cuma buat coba-coba bisa pake yg gratisan)
  • source Code Twitter Client, Download dimari
  • Satu lagi, ya harus pynya Akun Twitter juga 
Step by Step 
1. Download dulu source codenya
2. setelah itu daftarkan dulu Applikasi yang ingin agan buat dimari

Keterangan Pendaftaran :
Quote:
* Application Name : Nama aplikasi
* Application Website : http://www.domainmu.com/
* Application Type : Browser
* Callback URL : isikan dengan alamat URL Dabr yang akan kita upload nanti, misal : http://www.domainmu.com/dabr
* Default Access Type : Read&Write
* Use Twitter for Login : Yes
3. Setelah mengisi form langsung di save maka kamu akan mendapatkan dua macam key, yaitu Consumer Key dan Consumer Secret Key. Maka Key itulah yang akan kita pakai nanti

4. Kemabli ke file yang akan agan upload nanti, kemudian Rename file config-sample.php menjadi config.php, serta ubah beberapa scriptnya seperti :

Quote:
// Cookie encryption key. Max 52 characters
define('ENCRYPTION_KEY', 'Example Key - Change Me!');
// OAuth consumer and secret keys. Available from http://twitter.com/oauth_clients
define('OAUTH_CONSUMER_KEY', 'masukkan Consumer Key di Sini');
define('OAUTH_CONSUMER_SECRET', 'masukkan Consumer Secret di Sini');
5. Setelah itu upload semua isi file ke hosting anda dengan lokasi root folder yang diisi sewaktu mendaftar di Twitter Apps , misalnya tadi http://www.domainmu.com/dabr

6. Selesai dan silahkan mencoba untuk memakainya.

Contoh Demo yg udah jadi : 

Note:
Setelah agan memulai tutor yang ada di blog ini. diharap jangan di pakai dulu clientnya sebelum menyelesaikan tutorial disini. maka anda akan tahu akibatnya (syntax error, dll)

 

Copyright © Zaki's Blog.

Managed by FHMZK