Archive for February, 2009 Monthly Archives

    I have now, finally, succeeded to get into working with the twitter API - one of the most popular around. I am impressed by the possibilities and will try more. This is a little script that I startes following an introduction printed in German PHP Magazin.
    The layout needs some finetuning, but it works really well. I will keep you updated when I modify it.
    This post might be interesting for you...

    • if you are an beginner or intermediate php developer looking for a base where to start coding your own twitter display.
    • if you are already experienced in copy & pasting php code into your wordpress blog, for example, expanding the functionality of your sidebar or your page template

    The Twitter API provides JSON technology and can be accessed by the cURL command. The PHP version you therefore need is 5.2 and above.
    I you like to work with this code, copy and paste it into a page on your blog or other php enabled website.
    Caution: You need to have the Exec-PHP plugin installed in order for the code to be executed. The additional CSS definitions might scramble the display of your website layout, so consider to modify it if needed.
    Does anyone know a workaround for this?
    To get the plain php code, click on "view plain" above the code display.


    Notice: Twitter only allows 100 updates per hour, so the timeline display might be empty during heavy traffic.
    Now have fun with the code:

    <?php
    // functions
    function gradientHexBGcolor($k=6){
    return sprintf("%02X%02X%02X", 29+$k*18, 9+$k*20,9+$k*20);
    }
    function gradientHexFGcolor($k=6){
    return sprintf("%02X%02X%02X", 260-$k*5, 260-$k*5,260-$k*5);
    }
    
    // Init Data
    $fill = '';
    $thisPage = $_SERVER['REQUEST_URI'];
    
    //Enter your Twitter data here:
    $twitName = "MyTwitterUsername";
    $twitPass = "MyTwitterPassword";
    $twitUserDataURL = "http://twitter.com/users/show/MyTwitterUsername.json";
    $twitGetURL = "http://twitter.com/statuses/friends_timeline.json";
    
    // Check if a hashtag was given?
    
    if (!$_POST['hashtag']) {
    		$fill = 'Enter hashtag here...';
    		}
    		else {
    		$tag = $_POST['hashtag'];
    		$twitGetURL = "http://search.twitter.com/search.json?q=%23".$tag;		
    		}
    
    // cURL 1: get Userdata:
    // Init cURL
    $curl = curl_init();
    // set Userdata URL
    curl_setopt($curl,CURLOPT_URL,$twitUserDataURL);
    // prepare for return values
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
    // set authentification
    curl_setopt($curl,CURLOPT_USERPWD,"$twitName:$twitPass");
    // get + decode return values
    $returnUser = json_decode(curl_exec($curl));
    // close cURL
    curl_close($curl);
    
    // cURL 2: get timeline or tag search data:
    // Init cURL
    $curl = curl_init();
    // set URL
    curl_setopt($curl,CURLOPT_URL,$twitGetURL);
    // prepare for return values
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
    // set authentification
    curl_setopt($curl,CURLOPT_USERPWD,"$twitName:$twitPass");
    // get + decode return values
    $return = json_decode(curl_exec($curl));
    // close cURL:
    curl_close($curl);		
    
    // define & output css style definitions:
    echo '<style type="text/css"> 
     					div, .twitapi a, p, span, table, td, input, textarea, b, blockquote, th, form {font-family:Tahoma,Trebuchet MS,Arial,sans-serif;font-size:8pt;border:0;margin:0;padding:0;line-height:140%;}				
    					div.twitapi {width:540px;background:#CDCDCD;padding:6px 0;}	
    					.twitapi p, .twitapi br {display:none;}	
    					.twitapi hr {border:0;border-top:1px dotted #FFF;}		 	
    					.twitapi table {#position:relative;border:0;border-collapse:collapse;width:100%;}	
    					.twitapi table td {width:50%;border:0;padding:0;overflow:hidden;}
     					pre {color:#000;text-decoration:none;border:0;margin:0;padding:0;} 		
    					.twitapi a, .twitapi img,.twitapi span,.twitapi div {color:#FFF;text-decoration:none;border:0;margin:0;padding:0;} 
    					div.outer {margin:6px 3%;padding:0;width:94%;}					
    					div.wrap {#position:relative;display:table;height:48px;text-align:left;margin:6px 3%;padding:0;width:94%;}
    					div.text {#position:absolute;#top:50%;display:table-cell;vertical-align: middle;padding:0;}	
    					.twForm {color:#FFF;padding:0;}									
    					.twForm span {display:block;height:24px;margin:0;padding:0;overflow:hidden;}	
     					.twForm input, button, textarea, select {width:100%;height:100%;border:0;padding:5px;color:#FFF;overflow:hidden;}
     					.twForm .button {text-align:right;}	
     					.twForm .button:hover {color:#'.gradientHexBGcolor(7).';}	 					
     					.twForm textarea {font-weight:bold;}					 				 				 													
    					div.inner {#position:relative;#top:-50%;overflow:auto;margin:0 10px;}		
    					a.img {display:inline;float:left;width:48px;height:48px;overflow:hidden;}
    					a.img img {width:48px;height:48px;border:0;}
    					
      		</style>';
    
    
    // output twitter container & headline & buttons
    echo '<div class="twitapi">
    		<div class="wrap" style="background-color:#'.gradientHexBGcolor().';">
    		<table><tr><td>
    			<a class="img" href="'.$returnUser->profile_image_url.'"><img src ="'. $returnUser->profile_image_url.'"></a>
    				
    				<form class="twForm"  action="" method="POST"><input name="line" value="" type="hidden">		 
    					<span><textarea readonly style="background-color:#'.gradientHexBGcolor(6).';">'.$twitName.'\'s timeline</textarea></span>	
    					<span>														
    					<input class="button" style="background-color:#'.gradientHexBGcolor(2).';" value="Refresh now!" type="submit">
    					</span>				
    				</form>	
    				</td>	
    				<td>					
    				<form class="twForm" action="'.$thisPage.'" method="POST">	
    					<span>	
    					<input class="text" style="background-color:#'.gradientHexBGcolor(8).';" name="hashtag" value="'.$tag.$fill.'" type="text">
    					</span>
    					<span>								
    					<input class="button" style="background-color:#'.gradientHexBGcolor(4).';"value="Search now!" name="submit" type="submit">
    					</span>				
    				</form>	
    				</td>					
    				</tr></table>								
    		</div>
    		<hr>';
    	
    
    // output tweets
    // output friends' timeline if no hashtag given, else tweets with hashtag
    if (!$tag) {
    			foreach($return as $key=>$tweet) {
    			if ($key<=10) {		
    					$text = $tweet->text;
    					// Add links to URLS
    					$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" rel=\"nofollow\">\\0</a>", $tweet->text);
    					// Add links to Twitterprofiles with @	
    					$text = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text); 
    					// Add links to hashtags #	
    					$text = preg_replace("#(^|[\n ])\#([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://hashtags.org/search?query=\\2\" >#\\2</a>'", $text); 	 		 
    					echo '<div class="wrap" style="background-color:#'.gradientHexBGcolor($key).';">
    					<a class="img" href="http://twitter.com/'. $tweet->user->screen_name.'"><img src ="'. $tweet->user->profile_image_url.'"></a>		
    					<div class="text">	
    						<div class="inner" color="#'.gradientHexFGcolor($key).'">					
    					<a href="http://twitter.com/'. $tweet->user->screen_name.'">'. $tweet->user->screen_name.'</a>: 
    					'.$text.' >>'. $tweet->source.'</div></div></div>';
    					}
    			}
    		} 		
    		else {
    			foreach($return->results as $key=>$tweet) {	
    			if ($key<=10) {				
    						$text = $tweet->text;
    						// Add links to URLS
    						$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" rel=\"nofollow\">\\0</a>", $tweet->text);
    						// Add links to Twitterprofiles with @	
    						$text = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text); 
    						// Add links to hashtags #	
    						$text = preg_replace("#(^|[\n ])\#([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://hashtags.org/search?query=\\2\" >#\\2</a>'", $text); 	 		 
    						echo '<div class="wrap" style = "background-color:#'.gradientHexBGcolor($key).';">
    						<a class="img" href="http://twitter.com/'. $tweet->from_user.'"><img src ="'. $tweet->profile_image_url.'"></a>				
    
    						<div class="text">	
    						<div class="inner" color="'.gradientHexFGcolor($key).'"><a href="http://twitter.com/'. $tweet->from_user.'">'. $tweet->from_user.'</a>: 
    						'.$text.' at '. date('M d,Y',strtotime($tweet->created_at)).'</div></div></div>';
    						}
    			}			
    		}		
    
    
    echo '</div>';
    ?>
    

    A totally disturbing piece of art: Justive tells a short story by following a Banlieu gang expressing their senseless agression somewhere in france. Caution: violent.

    Already released in 2008, but I stumbled upon it just now. Though I did not feel comfortable watching this, I think this is a smart way of bringing the issue of juvenile violence in France into public.

      DIrector: Romain Gavras
      Release date: May 2008

    via Schmobi

    I found this video at WIRED. MIT students build a prototype of a wearable computer that projects any information on any surface, anywhere you are.

    Although I am not a friend of omnipresent technology, I must admit these are faszinating applications for future technology. Read more at the Wear ur World project website

    Wired quotes Pattie Maes, the project manager of Wear ur World:

    In the tactile world, we use our five senses to take in information about our environment and respond to it [...]. But a lot of the information that helps us understand and respond to the world doesn’t come from these senses. Instead, it comes from computers and the internet. Maes’ goal is to harness computers to feed us information in an organic fashion, like our existing senses.

    This might be right. But in my opinion, the organic fashion Mae is aiming at will rather leed to excessive Nerdism. Early adopters and grown-up-childs will refer to this technology as gadgets and will use it to impress their surrounding – just like we they do today with iPhones and Netbooks.

    That’s OK with me. I just want the ePaper thingy because that’s real hot shit.
    via Timo Heuer.

    … but today I feel I should give back some love to them.
    Ronald Jenkees just starts his fifteen minutes of fame. Holy cheesy goodness, this is a tearquenching melody:

    More

    Monthly Archives Other dates of posting

    August 2009

    July 2009

    June 2009

    March 2009

    February 2009

    January 2009

    December 2008

    November 2008

    September 2008

    August 2008

    July 2008

    June 2008

    May 2008

    April 2008

    March 2008

    February 2008

    January 2008

    September 2007

    August 2007

    July 2007

    June 2007

    May 2007

    April 2007

    March 2007

    February 2007

    January 2007

    December 2006

    November 2006

    October 2006

    September 2006

    August 2006

    July 2006

    June 2006

    May 2006

    April 2006

    March 2006

    February 2006

    January 2006

    December 2005

    November 2005

    October 2005

    September 2005

    '