User’s browser and platform php class

Because I’ve been working in a drupal website, I tought it would be handy to learn some php so I can make some scripts for it, although I’m still a long long way from making a working drupal module. For now I’m using php code input format when I want to include some script.

As parte of my learning I made a class (which I’me really not using for anythin now) to detect user browser and platform. It uses HTTP_USER_AGENT to obtain the relevant information. Note that te code is mostly untested. I just tested Firefox and Chromium under Linux and Chrome and IE under Windows.

class Agent{
 	private $_browser;
 	private $_os;
 	private $_browsers = array("firefox", "msie", "chrome", "opera", "safari", "mozilla");
 	private $_OS = array("windows", "win32", "linux", "machintosh");
 
 	public function __Construct(){
 		//Get user agent
 		$info = $_SERVER['HTTP_USER_AGENT'];
 
 		//Lower string case for easier matches
 		$info = strtolower($info);
 		print $info."";
 
 		//Search for browser
 		foreach ($this->gt;_browsers as $browser){
 
 			 if (strpos($info, $browser) === false){
 			 	continue;
 			 }
 
 			 else{
 			 	$this->_browser = $browser;
 
 			 	//We need to change the name os IE from msie to IE
 			 	if ($this->_browser === "msie") $this->_browser = "Internet " .
 			 			"Explorer";
 
 			 	break;// We've found the browser, leave the loop
 			 }
 		}
 
 		//Search for OS
 		foreach ($this->gt;_OS as $os){
 
 			 if (strpos($info, $os) === false)
 			 	continue;
 			 else{
 			 	$this->_os = $os;
 
 			 	//If windows identifies as win32 we change it to Windows
 			 	if ($this->_os == "win32") $this->_os = "Windows";
 
 			 	break; //We've found our OS, leave loop
 			 }
 		}
 
 	//Make first letter of browser and OS uppercase
 	$this->_browser = ucfirst($this->_browser);
 	$this->_os = ucfirst($this->_os);
 
 	}
 
 	//Selector that returns browser type. The b in Browser is capitalized because of the
 	//library funtion get_browser
 	function get_Browser(){
 		return $this->_browser;
 	}
 
 	//Selector returns os
 	function get_os(){
 		return $this->_os;
 	}
 
 	//Browser modifier
 	function set_browser(string $browser){
 		$this->_browser = $browser;
 	}
 
 	//Os modifier
 	function set_os(string $os){
 		$this->_os = $os;
 	}
 
 	//Print browser and OS
 	function print_agent(){
 		print $this->_browser."@".$this->_os;
 	} 
 
 }

Technorati Tags: , , ,

Canonical’s GNOME contribution

Since Ubuntu showed up in the Linux world there was always the question: “Does Ubuntu gives back to Debian ?” Then, 2 years ago another news came up. “Canonical (company behind Ubuntu) doesn’t contribute much to the Linux Kenel”. Mark Shuttleworth defended the company. In 2010 we see, in  GNOME census report, that only 1.03% of commits in GNOME come from Canonical employees. I think it’s not much from a company that has the largest desktop Linux distribution which uses GNOME as it’s main Desktop environment. In the report they come behind companies that are almost unknown for most people and behind other major Linux companies like Red Hat, Novel and others like Sun, Nokia and Intel, but these are much bigger then Canonical.

I know that’s just numbers, and Canonical supports GNOME in many other ways, with money, servers, etc. I’m just commenting on the numbers of commits, which are not great. Sometimes I feel Canonical uses a lot of resources modifying GNOME to their needs (e.g. notification system, the “system-tray” etc) instead of improving GNOME so it can be better for everyone. Well, their not doing anything BAD, it’s the way FOSS works, but other companies choose to work in a different way.

Technorati Tags: , , , ,

Found memory Hog!!!

A few day ago I wrote a blog post ranting Firefox for it’s memory use. Firefox was using more then 600MB of RAM. I tried using chromium for a change and today, after leaving the computer on for 4 or 5 hours, I came back home and noticed RAM usage was huge! One of chormium tabs was using more then  600MB! I killed the process associated with that tab and the one that crashed was: (drums please) FACEBOOK!!!! You RAM Eating Bastard!!! I guess I’ll be using Facebook less from now on.

Technorati Tags: , ,

(Quase) em litígio com a ensitel – A resolução

Boas notícias, caros leitores :D

Como alguém me indicou e bem no forum andriodpt, fui hoje à Vodafone, uma vez que o telemóvel está bloqueado à rede e afinal de contas foram eles que o comercializaram e a ensitel é apenas um agente. Após cerca de um minuto a explicar à funcionária o problema do telemóvel e a  incapacidade da ensitel de decidir se uma partícula no ecrã é ou não defeito de fabrico, esta olhou para o telemóvel e disse que era uma impureza no ecrã. Levantou-se e voltou com um Tattoo novinho. Fez-se a troca e lá fui todo feliz e contente para casa com um telemóvel em perfeitas condições :D .

Ok, não estou a dizer toda a verdade, tive de voltar a casa antes de fazer a troca para ir buscar o cartão de memória de 2GB original já que tinha um de 8GB no telemóvel. Voltei à loja e fez-se a troca. Nem tive de me preocupar em trazer carregador, auricular etc. Se muitas vezes critico a Vodafone, por várias razões, aqui prestou um serviço ***** !

Escusado será dizer que vou à ensitel esfregar-lhes na cara a sua incompetência e dizer-lhes que perderam um cliente.

Technorati Tags: , ,