Posted (Updated ) in Uncategorized

Due to the antics of some douchebag (IP address 109.120.34.16) I’ve had to look into blocking pages based on IP address with .htaccess files. This may come in handy to others out there so I figured I’d write up my findings.

To block everyone except specific IPs here’s what you’ll need (more info):

order deny,allow
deny from all
allow from <ip address>

To apply this restriction only to specific files, wrap the above code in the <File> tag:

<Files wp-login.php>
	order deny,allow
	deny from all
	allow from <ip address>
</Files>

Thanks to user NuclearMeltdown on the #httpd channel on Freenode for his assistance.

Read More »

Posted (Updated ) in Linux

You’ve recently upgraded to Ubuntu Natty and discovered that Unity is crap. Don’t worry – you’re in the vast majority. One of the many issues with this disastrous attempt at a shell is that it moves application menus into a global menu in the top panel. This may be useful for small screens – but for the other 99% of the market it’s just downright frustrating.

After a bit of searching I came across this post describing how to banish the global menu back to the warped hell from whence it came. You want to remove the indicator-appmenu package.

This is but one of a great many great challenge you’ll face if you decide to continue on with Unity. Good luck…and may God have mercy on your soul should you choose to stick with it.

Read More »

Posted (Updated ) in Linux

OK so this is an issue I’ve had for a very long time now (since Firefox 4 beta) whereby Google keeps defaulting to a strange language and seemingly completely ignoring my preference for English:

Incorrect language on google.com in Firefox 4

 

The reason for this is a bad language string in Firefox’s settings. You can fix it by doing the following:

Edit - Preferences 
Content - 
Choose... (under Languages)

You’ll see the following language:

chrome://global/locale/intl.properties

Delete it. It’s wrong and it’s causing you problems. Once deleted, time to add your language of choice:

Select Language to add... -
<pick your desired language>

You should now be greeted with a much easier to read google index page!

Here’s hoping this post will make it out in time to save the flood of Ubuntu Natty users on their shiney new Firefox 4 installs :)

Read More »

Posted (Updated ) in PHP

EDIT Aug 6 2011: If you’re having trouble connecting to
{imap.gmail.com:993/imap/ssl}
try
{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}
If you get a ‘Too many incorrect logins’ error, you can unlock your account again here.

I’m a big fan of the Android platform and have been using an application called SMS Backup to send all SMS’s to Gmail for archiving (now replaced by SMS Backup+). To cut a long story short, I needed to download those SMS’s with a PHP script. SMS Backup had uploaded them all under the creatively named SMS label and so I needed a way to download all emails with a specified label. It turned out to be a relatively thing to do once you know what you’re looking for.

A quick Google search (I’m such a fanboy) will lead you to this page where a script is provided to download all email from Gmail using the IMAP protocol:

<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'your username here';
$password = 'your password here';
 
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
 
/* grab emails */
$emails = imap_search($inbox,'ALL');
 
/* if emails are returned, cycle through each... */
if($emails) {
 
	/* begin output var */
	$output = '';
 
	/* put the newest emails on top */
	rsort($emails);
 
	/* for every email... */
	foreach($emails as $email_number) {
		/* get information specific to this email */
		$overview = imap_fetch_overview($inbox,$email_number,0);
		$message = imap_fetchbody($inbox,$email_number,2);
 
		/* output the email header information */
		$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
		$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
		$output.= '<span class="from">'.$overview[0]->from.'</span>';
		$output.= '<span class="date">on '.$overview[0]->date.'</span>';
		$output.= '</div>';
 
		/* output the email body */
		$output.= '<div class="body">'.$message.'</div>';
	}
 
	echo $output;
}
 
/* close the connection */
imap_close($inbox);

This gets us half way there. Now – to filter by label. As it turns out, this is ridiculously simple. Change the $hostname variable to this:

$hostname = '{imap.gmail.com:993/imap/ssl}SMS';

And with that, ladies and gentlemen, we have a completed script!

…but what if you want to retrieve only your Spam mail (not that you would), your starred mail or your deleted mail? This is also quite possible. After much more Googling I came across this blog post detailing what you need to put in your $hostname. In the instance above, it’d be

$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Trash';

Read More »

Posted (Updated ) in Linux

When performing various actions on a clean install of Ubuntu 10.10 on my web server, I kept being presented with the following message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = "en_US:en",
	LC_ALL = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

After some googling, many people (in this thread http://ubuntuforums.org/showthread.php?t=138022) suggested:

sudo locale-gen
sudo dpkg-reconfigure locales

however the solution that worked for me was:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

You might need to reset your machine before changes take effect:

sudo shutdown -r now

Read More »

Posted (Updated ) in Javascript, PHP

Update Jul 02 2011: crossdomains.xml should be crossdomain.xml
Update Jun 29 2011: Updated S3 upload URL – no more security error

If you’ve ever wanted to allow people on your website to upload files to Amazon S3, you’ll know the only real way to do this is with flash – as it allows the client to upload directly instead of funneling all traffic through your server. You could write your own script for this, however there’s already a nifty little prebuilt tool I’m sure you’ve already heard of called Uploadify which can not only do the job for you, it can do so with great flexability.

For the lazy: Download the entire script here

Read More »

Posted (Updated ) in Database, PHP

NOTE: If you’re looking for the Doctrine 2 modules for K3 see this post.

Download the module here.

I’ve previously written a module for Kohana 3 for Doctrine, as well as drivers for Kohana’s Auth and Session modules, however I’ve finally had the time to merge the three and fix up some longstanding issues present with them; namely the folder structure and lack of PDO support. To make my life a little easier I’ve moved the project to Google Code too.

You can find the project here. It’s got Doctrine 1.23 already in there, you should just be able to drop it in and add it to your bootstrap file. It also includes sample schema and data fixtures for the kohana auth and session modules – they can be found in /models/fixtures.

Good luck!

Read More »

Posted (Updated ) in PHP

If you’ve ever come across the infuriating error

htmlspecialchars(): Invalid multibyte sequence in argument

I have a simple solution for you: Turn display_errors on in your php.ini file!

It turns out there’s a weird bug that doesn’t appear to be getting fixed any time soon that causes htmlspecialchars() to display this error only when display_errors is set to Off.

See this post for further details and a very big thank you to the Andy Young for writing it and saving me (and I’m sure many others) alot of time!

Read More »

Posted (Updated ) in Database, PHP

Update Feb 22 2012: 1.0.8 is out. Now works with and requires Doctrine 2.2. Thanks to Markus for his patch.

Since releasing my original Doctrine 2 module for Kohana 3, I’ve done a bit of reshuffling of folders and added some additional features from my Doctrine 1.2 module. Due to the extent of modifications, I decided to put up a new post with some added information on how to use the new module.

Features:

  • Doctrine 2 integration (obviously)
  • Auth and Session drivers
  • /doctrine controller to load your schema files and generate the DB tables
  • Works in Kohana 3.0 and 3.1

For the impatient ones out there, here’s the download link:
Doctrine 2 Module for Kohana 3

 

As always, install the module (remembering to add it to your bootstrap file) and download the latest copy of Doctrine 2 from here, placing into the /modules/doctrine2/classes/vendor/doctrine folder. It should be noted that my module is tailored to the tarball download and not the SVN or Github ones which have a slightly different folder structure.

Read More »

Posted (Updated ) in Database, PHP

UPDATE 28 Dec 2010: This module is now defunct. Please instead use the Better Doctrine 2 Module for Kohana 3.

For those of you who don’t already know, Doctrine 2 stable was just released. It features what is essentially a complete rewrite and paradigm shift from the 1.2 version and comes with a laundry list of improvements. You can read the official blog post here. To celebrate the occasion I decided to do up a quick Kohana 3 module. Info & specz below:

Firstly the configuration. You’ll need the following files & folders:
/doctrine/Entities (These are essentially (to my meager knowledge) your model files.)
/doctrine/Proxies
/modules/doctrine/classes/doctrine
/modules/doctrine/init.php

Download the latest copy of Doctrine 2 from here and extract into the /modules/doctrine/classes/doctrine folder.

Here’s /modules/doctrine/init.php

<?php
	use Doctrine\ORM\EntityManager,
		Doctrine\ORM\Configuration;
 
	class Doctrine
	{
		private static $_instance = null;
		private $_application_mode = 'development';
		private $_em = array();
 
		/*
		 * Rename $conn_name to whatever you want your default DB connection to be
		 */
		public static function em( $conn_name = 'default' )
		{
			if ( self::$_instance === null )
				self::$_instance = new Doctrine();
 
			return isset(self::$_instance->em[ $conn_name ])
				? self::$_instance->em[ $conn_name ]
				: reset(self::$_instance->_em);
		}
 
		public function __construct()
		{
			require __DIR__.'/classes/doctrine/Doctrine/Common/ClassLoader.php';
 
			$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', __DIR__.'/classes/doctrine');
			$classLoader->register();
			//This allows Doctrine-CLI tool & YAML mapping driver
			$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__.'/classes/doctrine/Doctrine');
			$classLoader->register();
			//Load entities
			$classLoader = new \Doctrine\Common\ClassLoader('Entities', APPPATH.'doctrine');
			$classLoader->register();
 
			//Set up caching method
			$cache = $this->_application_mode == 'development'
				? new \Doctrine\Common\Cache\ArrayCache
				: new \Doctrine\Common\Cache\ApcCache;
 
			$config = new Configuration;
			$config->setMetadataCacheImpl( $cache );
			$driver = $config->newDefaultAnnotationDriver( APPPATH.'doctrine/Entities' );
			$config->setMetadataDriverImpl( $driver );
			$config->setQueryCacheImpl( $cache );
 
			$config->setProxyDir( APPPATH.'doctrine/Proxies' );
			$config->setProxyNamespace('Proxies');
			$config->setAutoGenerateProxyClasses( $this->_application_mode == 'development' );
 
			$dbconfs = Kohana::config('database');
 
			foreach ( $dbconfs as $conn_name => $dbconf )
				$this->_em[ $conn_name ] = EntityManager::create(array(
					'dbname' 	=> $dbconf['connection']['database'],
					'user' 		=> $dbconf['connection']['username'],
					'password' 	=> $dbconf['connection']['password'],
					'host' 		=> $dbconf['connection']['hostname'],
					'driver' 	=> 'pdo_mysql',
				), $config);
		}
	}

Once the module is enabled, you can access Doctrine from anywhere with the following code:

Doctrine::em()

The module supports multiple databases and uses the Kohana database config file for connection details. To grab any specific database use the following (where connection_name is the name specified in the config file)

Doctrine::em('connection_name')

Download the complete module here.

Hope this helps.

Read More »

Page 11 of 15« First...910111213...Last »