Most sites have pages for Terms and Conditions, a Privacy policy and /or a page about cookies. Presumably they are usually tucked away in a CMS somewhere, or as static HTML — no doubt copied & pasted verbatim from the Internet. Whether the CMS is the natural place for them remains to be seen, and certainly if a site doesn’t have content as such then supporting those sorts of pages introduces new problems — is the content simply dropped into a view somewhere?
To help solve this problem — in Laravel 4, specifically — I’ve created a simple package called Legalpages. The idea behind it is simple — you install it, enter a few pieces of information about your business or organisation in a configuration file — and done, your site now has Terms and Conditions, Privacy and cookie pages. I’ve used some boilerplate documents, which get tailored according to the information you provide, but you can customise them if you wish — they wind up in your app/storage
directory in Markdown format for easy editing.
I’ve created a simple package for working with UK Postcodes. It contains two principle components:
- A simple class to encapsulate UK Postcodes
- A wrapper to this web service
The postcode class can be used for:
- validating postcodes
- formatting them, e.g. “sw1a2aa” -> “SW1A 2AA”
- getting the outcode (the first part of a postcode; e.g. M1, SW1A, GL9)
The meat and bones of the package, though, is the web service. Most notably, it allows you to take a postcode, and find out its latitude and longitude. Here’s an example of how it’s used:
// Create the client
$client = new Lukaswhite\UkPostcodes\UkPostcodesClient();
// Call the web service
$postcode = $client->postcode('sw1a2aa');
print get_class($postcode);
// Lukaswhite\UkPostcodes\UkPostcode
print $postcode->formatted();
// SW1A 2AA
print get_class($postcode->getCoordinate());
// League\Geotools\Coordinate\Coordinate
print $postcode->getCoordinate()->getLatitude();
// 51.503539898876
print $postcode->getCoordinate()->getLongitude();
// -0.12768084037293
print get_class($postcode->getCoordinate()->getEllipsoid());
// League\Geotools\Coordinate\Ellipsoid
print $postcode->council->title;
// City of Westminster
print $postcode->council->code;
// E09000033
print $postcode->council->uri;
// http://statistics.data.gov.uk/id/statistical-geography/E09000033
print $postcode->ward->title;
// St. James's
print $postcode->constituency->title;
// Cities of London and Westminster
I signed up for an online service the other day (Commando.io), and they had a really nice little interaction during the signup and signin processes. As soon as you enter your email address, it automatically displays your Gravatar. Nice little touch.
So, I thought I’d write a quick tutorial on how to replicate the effect.
There is a demo here.
Getting Started
For simplicity, I based the form on one of the example templates for the Bootstrap framework.
It’s pretty straightforward to download the Bootstrap framework using Bower:
Sometimes you may wish to run Artisan commands from your admin dashboard /application, without using the command line. Perhaps you don’t have access to the command line (in which case perhaps it’s time to switch hosting!), or more likely perhaps you want to manually run tasks right from your application. Here’s a quick guide to how you might set that up.
Running a command
To run a command programmatically, you simply do this:
Artisan::call('my-command', array());
The first argument is the name of the command, the second your options, which I’m going to ignore for brevity.
It’s probably more useful if you can get a hold of the command’s output; you can do this by passing a third argument, which should be a class that implements Symfony\Component\Console\Output\OutputInterface
. Perhaps the most useful of these classes is StreamOutput
. So, for example, you can write the output to a file:
Laravel 4’s pagination functionality supports Twitter Bootstrap out-of-the-box. However, if you prefer to use Zurb’s Foundation, here is the code you’ll need. Just drop the presenter class somewhere where your autoloader will pick it up, pick one (or both) of the template files, and configure your app/config/view.php
file to point to the appropriate template file.
First, the presenter class:
The simple template file:
The slider template file:
I haven’t written anything here for quite a while, but I have been writing. I’ve had quite a number of articles published on Sitepoint (and before the re-brand, the PHPMaster site).
Here’s a list of my latest articles.
Creating a Subscription-Based Website with Laravel and Recurly, Part 1 and Part 2
- Sitepoint, September 2013
Building a subscription-based website or application with Laravel, using Recurly to process recurring payments. In this first part I look at setting up the application, configuring users and roles, and building an authentication system.
Whenever I start a new web project, the initial steps are pretty much the same:
- Create a new folder, in my case in
/var/www
- Change the ownership of the new folder
- Come up with a new hostname, e.g.
myproject.local
- Create an entry in
etc/hosts
- Create an Apache virtual host for it
- Create a new database
- Create a new Git repository
- Intialise the Git repository
- Create a new project in Sublime
Not particularly hard, but pretty repetitive. And if something’s repetitive, chances are it can be scripted!
So here’s what I came up with:
Until very recently, this website was powered by Drupal. Now although Drupal’s great in a whole raft of situations, there are times when either it’s overkill for something small, or just doesn’t fit into one’s workflow. I came to realise that both of these applied to this site, so when it came to re-developing, I decided to abandon Drupal for the site altogether.
In the end, I decided to rebuild the site using Jekyll, along with a few other tools along the way.
This post explains the motivations behind the decision, what I did next and some of the challenges I faced along the way.
The Need for Re-development
There were several aspects that made re-developing my site something of a priority.
First, it wasn’t mobile-friendly. I may have been able to get away with that some years ago when I first drafted the site, but now that’s just not acceptable. After weighing the pros and cons of a responsive vs a separate mobile site, I decided on the former — and the only way to do that would be to start the front end build again from scratch.
There isn’t really an out-of-the-box solution for gift certificates in Drupal Commerce; there’s no module (at time of writing) you can simply download, enable and forget about. Being Drupal, there are many ways to skin a cat, so to speak, so in this post I’m going to outline how I got them working on a site I built.
Of course, the way your gift certificates work may well differ from site-to-site; I had a way I wanted it to work, but your requirements might be subtly different, but hopefully whatever your requirements, some of what follows is of some use.
To outline, here’s what I wanted to achieve:
- Gift certificates available as products, which a customer can purchase
- A range of values (£5, £10, £20 etc) available
- A product display page that differed from “conventional” products — there are less fields required, so the layout was likely to be different
- I wanted a customer to be able to specify a recipient for the gift certificate
- The customer needed to supply an email address for the recipient, so we can send it to them via email
- I wanted the customer to be able to specify the recipient’s name, to personalise the email
- The customer ought to be able to enter their name as they wished it to appear on the email; the billing name on the order might well be too formal
- There ought to be an optional text field to add a personal message
- The gift certificate needed to be sent out via email when the order was completed, and paid for
I’m writing my first book at the moment. Lately I’ve been doing all my writing in Markdown, but ultimately i’ll need an alternative format. For word processing, such as it is, I tend to use Open Office — so really I wanted to be able to write in Markdown, but convert to Open Office (or indeed, any of a variety of formats). For one thing, it’s nice to get an idea of the number of pages, which my Markown editor just can’t do. Also, I prefer to work with separate files for each chapter — but I’m not entirely sure what order the chapters will end up in. So, what I really wanted was a quick way to do two things — concatenate all my chapters, and then convert the lot to Open Office format.
My solution to this is in two parts.
First, a shell script to concatenate the files. It’s important it’s fairly easy to rearrange chapters, so the format of this was crucial.