Monday, August 6, 2012

google doodle olimpiade

udah ada yang liat belom gan,
kalo belom ke http://www.google.co.id/ dulu

google doodle lari2
atau kalo udah ganti kesini aja http://www.google.com/doodles/hurdles-2012

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=$1 [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...

 

Copyright © Zaki's Blog.

Managed by FHMZK