Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DI FUNCTION TWITTER UPDATE
- if (strlen(utf8_decode($status)) > 140) {
- //ini yang penting
- $status = tweetShortener(user_current_username(),$status);
- }
- _____________________________
- TARUH DIBAWAH AKHIR FUNCTION TWITTER UPDATE
- function mysqliD() {
- include "m/cfg.php";
- $out = new mysqli("$host","$usr","$pwd","$db");
- return $out;
- }
- function tweetShortener($name,$status){
- $baseurl = BASE_URL;
- $jmlh_baseurl = strlen($baseurl);
- $jmlh_smua = 140 - ($jmlh_baseurl + 18);
- $cutStatus = substr($status, 0,$jmlh_smua);
- $dirname = generateKey();
- if(dupe($dirname) > 0 ){
- $dirname = substr ( md5(uniqid(rand(), true)), 0, 5)."a";
- }
- $maha = mysqliD();
- if( !ins($dirname, $maha->real_escape_string(trim("@".$name.": ".$status))) ){
- file_put_contents("failins.null", $m->error, FILE_APPEND);
- }
- //sasa
- $cutStatus .= "..(cont) ".BASE_URL."m/".$dirname;
- return $cutStatus;
- }
- function generateKey($len = 6) {
- define('KEY_CHARS', 'abcdefghijklmnopqrstuvwxyz0123456789');
- $k = str_repeat('.', $len);
- while ($len--) {
- $k[$len] = substr(KEY_CHARS, mt_rand(0, strlen(KEY_CHARS) - 1), 1);
- }
- return $k;
- }
- function dupe($dir){
- $m = mysqliD();
- $sql = " SELECT * FROM tb_shortener WHERE tweet_key = '$dir' ";
- if($m->connect_error){
- $m->close();
- return -1;
- } else {
- if ($r = $m->query($sql)){
- $int = $r->num_rows;
- $r->free_result();
- $m->close();
- return $int;
- } else {
- $m->close();
- return -1;
- }
- }
- }
- function ins($dir, $status){
- $m = mysqliD();
- if($m->connect_error){
- file_put_contents("fail.null", $m->connect_error, FILE_APPEND);
- $m->close();
- return false;
- } else {
- $username = user_current_username();
- $source = BASE_URL;
- $date = date('h:ia d F Y');
- $sql = "INSERT into tb_shortener (tweet_key, tweet_text, username, date, source) VALUES ('$dir','$status', '$username', '$date', '$source');";
- if($m->query($sql)){
- $m->close();
- return true;
- } else {
- file_put_contents("fail.null", $m->error, FILE_APPEND);
- }
- }
- }
- _____________________________________
- DISINI ANE BUAT LONGTWEETNYA DI FOLDER m DI ROOT
- BUAT FILE cfg.php di folder m/
- <?php
- $host = "localhost";
- $usr = "root";
- $pwd = "";
- $db = "db_shortener";
- $tb = "tb_shortener";
- $tc = "http://TC.NYA/";
- ?>
- INI BUAT NYIMPENNYA, SESUAIKAN DENGAN SERVER AGAN
- ______________________________________
- INI BUAT NAMPILIN, BUAT FILE index.php di folder m/ barengan file cfg.php (ini contoh ane)
- <?php
- mysql_connect($host, $usr, $pwd);
- mysql_select_db($db);
- if(empty($_GET['tweet_key'])) {
- header('Location: '.$tc.'');
- }
- $tweet_key = @mysql_real_escape_string($_GET['tweet_key']);
- $query = "SELECT * FROM $tb WHERE tweet_key = '$tweet_key'";
- $hasil = mysql_query($query);
- if(mysql_num_rows($hasil) == 1) {
- $data = mysql_fetch_assoc($hasil);
- $tweet_text = $data['tweet_text'];
- echo avatar($data['username']);
- echo "<h2><a href='".$tc."user/".$data['username']."'>".$data['username']."</h2>";
- echo "<blockquote>".$tweet_text."</blockquote> ";
- echo '<br/>from: <a href="'.$data['source'].'" target="_blank">'.$data['source'].'</a><br/>';
- echo '<div>Post at: '.$data['date'].'</div>';
- }
- if(mysql_num_rows($hasil) != 1) {
- echo "<h1 align='center'>Not Found</h1>";
- }
- ?>
- __________________________________________
- terakhir buat file .htaccess didalem folder m/ barengan file index.php, cfg.php
- hilangkan tanda # di RewritreBase / bila hostingannya di idhostinger :D
- # URL rewriting
- RewriteEngine on
- #RewriteBase /
- RewriteRule ^([a-z,0-9,\_]*)$ index.php?tweet_key=$1 [L,QSA]
- Semoga berhasil
- NB : Pelajarin Scriptnya jangan langsung copas.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement