Advertisement
Guest User

long--

a guest
Jan 4th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.16 KB | None | 0 0
  1. DI FUNCTION TWITTER UPDATE
  2.  
  3. if (strlen(utf8_decode($status)) > 140) {
  4.     //ini yang penting
  5.        $status = tweetShortener(user_current_username(),$status);
  6. }
  7.  
  8. _____________________________
  9.  
  10.  
  11. TARUH DIBAWAH AKHIR FUNCTION TWITTER UPDATE
  12.  
  13. function mysqliD() {
  14.     include "m/cfg.php";
  15.     $out = new mysqli("$host","$usr","$pwd","$db");
  16.     return $out;
  17. }
  18. function tweetShortener($name,$status){
  19.         $baseurl = BASE_URL;
  20.         $jmlh_baseurl = strlen($baseurl);
  21.         $jmlh_smua = 140 - ($jmlh_baseurl + 18);
  22.         $cutStatus = substr($status, 0,$jmlh_smua);
  23.         $dirname =   generateKey();
  24.        
  25.        
  26.         if(dupe($dirname) > 0 ){
  27.                 $dirname =  substr ( md5(uniqid(rand(), true)), 0, 5)."a";
  28.         }
  29.        
  30.         $maha = mysqliD();
  31.  
  32.         if( !ins($dirname, $maha->real_escape_string(trim("@".$name.": ".$status))) ){
  33.             file_put_contents("failins.null", $m->error, FILE_APPEND);
  34.         }
  35.         //sasa
  36. $cutStatus .= "..(cont) ".BASE_URL."m/".$dirname;
  37. return $cutStatus;
  38. }
  39.  
  40. function generateKey($len = 6) {
  41.    define('KEY_CHARS', 'abcdefghijklmnopqrstuvwxyz0123456789');
  42.     $k = str_repeat('.', $len);
  43.     while ($len--) {
  44.         $k[$len] = substr(KEY_CHARS, mt_rand(0, strlen(KEY_CHARS) - 1), 1);
  45.     }
  46.     return $k;
  47. }
  48.  
  49. function dupe($dir){
  50.    
  51.      $m = mysqliD();
  52.      $sql =  " SELECT * FROM tb_shortener WHERE tweet_key = '$dir' ";
  53.          if($m->connect_error){
  54.               $m->close();
  55.               return -1;
  56.            } else {
  57.                if ($r = $m->query($sql)){
  58.                      $int = $r->num_rows;
  59.                      $r->free_result();
  60.                      $m->close();
  61.                      return $int;
  62.                   } else {
  63.                       $m->close();
  64.                       return -1;
  65.                   }
  66.            }
  67.            
  68. }
  69.  
  70. function ins($dir, $status){
  71.   $m = mysqliD();
  72.     if($m->connect_error){
  73.         file_put_contents("fail.null", $m->connect_error, FILE_APPEND);
  74.         $m->close();
  75.         return false;
  76.     }  else {
  77.             $username = user_current_username();
  78.             $source = BASE_URL;
  79.             $date = date('h:ia d F Y');
  80.             $sql = "INSERT into tb_shortener (tweet_key, tweet_text, username, date, source) VALUES ('$dir','$status', '$username', '$date', '$source');";
  81.            if($m->query($sql)){
  82.                 $m->close();
  83.                 return true;
  84.              } else {
  85.                   file_put_contents("fail.null", $m->error, FILE_APPEND);
  86.              }
  87.         }
  88. }
  89.  
  90. _____________________________________
  91.  
  92. DISINI ANE BUAT LONGTWEETNYA DI FOLDER m DI ROOT
  93. BUAT FILE cfg.php di folder m/
  94. <?php
  95.     $host   = "localhost";
  96.     $usr    = "root";
  97.     $pwd    = "";
  98.     $db     = "db_shortener";
  99.     $tb = "tb_shortener";
  100.     $tc     = "http://TC.NYA/";
  101.  
  102. ?>
  103.  
  104. INI BUAT NYIMPENNYA, SESUAIKAN DENGAN SERVER AGAN
  105.  
  106. ______________________________________
  107. INI BUAT NAMPILIN, BUAT FILE index.php di folder m/ barengan file cfg.php (ini contoh ane)
  108.  
  109. <?php
  110.  
  111.         mysql_connect($host, $usr, $pwd);
  112.         mysql_select_db($db);
  113.         if(empty($_GET['tweet_key'])) {
  114.             header('Location: '.$tc.'');
  115.         }
  116.         $tweet_key = @mysql_real_escape_string($_GET['tweet_key']);
  117.          
  118.         $query = "SELECT * FROM $tb WHERE tweet_key = '$tweet_key'";
  119.         $hasil = mysql_query($query);
  120.         if(mysql_num_rows($hasil) == 1) {
  121.         $data  = mysql_fetch_assoc($hasil);
  122.         $tweet_text = $data['tweet_text'];
  123.         echo avatar($data['username']);
  124.         echo "<h2><a href='".$tc."user/".$data['username']."'>".$data['username']."</h2>";
  125.         echo "<blockquote>".$tweet_text."</blockquote> ";
  126.         echo '<br/>from: <a href="'.$data['source'].'" target="_blank">'.$data['source'].'</a><br/>';
  127.         echo '<div>Post at: '.$data['date'].'</div>';
  128.        
  129.         }
  130.    
  131.     if(mysql_num_rows($hasil) != 1) {
  132.             echo "<h1 align='center'>Not Found</h1>";
  133.         }
  134.       ?>
  135.  
  136. __________________________________________
  137.  
  138. terakhir buat file .htaccess didalem folder m/ barengan file index.php, cfg.php
  139. hilangkan tanda # di RewritreBase / bila hostingannya di idhostinger :D
  140.  
  141. # URL rewriting
  142. RewriteEngine on
  143. #RewriteBase /
  144.  
  145. RewriteRule ^([a-z,0-9,\_]*)$ index.php?tweet_key=$1 [L,QSA]
  146.  
  147.  
  148.  
  149. Semoga berhasil
  150. NB : Pelajarin Scriptnya jangan langsung copas.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement