Okay, for those who don't know Twittermail, Twittermail is an open idea by Boris Veldhuijzen van Zanten, he thought that it would be great if people could e-mail their tweets to Twitter.com.
This is potentially very useful for people who use mobile phones. Of course you can go to the mobile webpage of Twitter, but sending an e-mail is pretty much easier. Some older phones do not even contain a browser and only have e-mail functionality. Also a lot of businesses block Twitter.com on their corporate network but with Twittermail you can continually update your Twitter account even from your business e-mail address.
Those who register at Twittermail, get a secret unique email address like 1234abcde [AT] twittermail com. When you send an e-mail to this secret email address, it will get posted instantly to Twitter.com through the Twitter API.
Twittermail is a small project so basically we only need a sign-up form, a settings page and we need to show some recent activity. Since we handle loads of visitors and more than 3000 emails a day this project needed to be very scalable and thin. We read a lot about the benchmarking results[sub]1[/sub]. We managed to do this project in exactly 48 hours, thanks to CakePHP .
Users supply us their Twitter credentials so that we can create a unique email address. Because we need to verify if the information they provide is valid, we created a custom validation which checks the Twitter API whether or not everything is valid. In our model we created a custom function called 'isValidTwitter', in this function we make a CURL call to the Twitter API, we parse the output from JSON to an array and we get back the user information or an error.
'message' => __
$curl_result = curl_exec;
$twitterResponse = json_decode;
From now on you can do whatever you want with the results. In our project we encode the password, fetch some Twitter information and save it to the database.
Because we don't need a very complex User Authentication, we didn't use ACL.
Localization & Internationalization, l10n and i18n
At the moment our Website is English-only, but we already made it multi-language proof by using the __ function. For those who never worked with localization, in the cake console you can simply generate a language file by using the command 'cake I18n' here you get the option to extract all __ strings to POI files. You can read more about localization at the wonderful Cookbook at http://book.cakephp.org/view/162/Localizing-Your-Application
Because we're currently serving more than 25,000 users and more than 1,000,000 emails have been sent, scaling is an serious subject. First of all, use Cache! You don't need to get all data over and over again from the database. For example in the sidebar we have 'Newest Twittermailers'. This is cached for a year , every time when someone is registering, we're resetting the cache. Cache isn't a thing you should forget, and for those who never worked with it please read the Cookbook.
// Reset / Delete the cache, so next time the newest Twittermailers list will be re-generated.
This is a very substantial improvement in the Cake 1.2 series, in the past I always used for my CakePHP projects 'expect' . This model behavior allows you to filter and limit model find operations. Using Containable will help you cut down on needless wear and tear on your database, increasing the speed and overall performance of your application. The class will also help you search and filter your data for your users in a clean and consistent way.
It helps you to select only the data you really want, it's recommended to read the full recept about this at http://book.cakephp.org/view/474/Containable
Think about security
Often developers forget to think about security, but security is a very important subject when you're developing web-applications. Use the validations and double check them with the sanitize object built-in CakePHP.
Put this code in your AppController and AppModel to achieve a higher lever of security, read about it at http://book.cakephp.org/view/153/Data-Sanitization/ For example:
And remember: NEVER trust the input of your users!
Then there's the Model::save function, that lacks a complete description in the cakebook, but in my opinion the $fieldList method is very important.
Like I said before, never trust the input of your users, supply $fieldList with an array of all the fields you're supposed to fill.
How we did it in 48 hours
f course, this is a small project, but because of Cake we were able to manage this project in 48 hours. It's essential to stick to the CakePHP 'rules', just use the validation methods, use the helpers, use the build-in components, it actually helps you with keeping your code clean and compact.
Show the world you're happy with CakePHP, put the 'cakephp - power' button on your website, be proud you're using CakePHP. Also don't forget to donate, the cake developers team are working day-and-night to supply us a better CakePHP, the only thing we could do is using CakePHP and show our satisfaction, at the end of 2009 we will donate the Cake Foundation 10% of Twittermail's profit.