Add year support on url. Closes #76

This commit is contained in:
Remy Sharp 2011-10-20 18:28:26 +01:00
parent d2a81328a3
commit 76a99b6692
2 changed files with 66 additions and 15 deletions

View file

@ -38,6 +38,15 @@ The `users` directory contains a list of files, each representing a host
on mit-license.org. The minimum requirement for the JSON is that is on mit-license.org. The minimum requirement for the JSON is that is
contains a `copyright` field - everything else is optional. contains a `copyright` field - everything else is optional.
Available fields:
* copyright (required)
* url
* email
* format
* version
* theme
### copyright ### copyright
Create a new file and give it the name of the CNAME you want (in my case Create a new file and give it the name of the CNAME you want (in my case
@ -61,6 +70,18 @@ the copyright text, you can include a `url` property:
"url": "http://remysharp.com" "url": "http://remysharp.com"
} }
### email
You can also include a link to your email which is displayed after the
copyright notice using the `email` property (note the `mailto:` is
automatically added):
{
"copyright": "Remy Sharp, http://remysharp.com",
"url": "http://remysharp.com",
"email": "me@mysite.com"
}
### format ### format
And if you want your license to appear as plain text, just add the And if you want your license to appear as plain text, just add the
@ -84,7 +105,7 @@ extra assurance for you.
Targeting requires the [sha from the license commit](https://github.com/remy/mit-license/commits/master/LICENSE.html). This can be Targeting requires the [sha from the license commit](https://github.com/remy/mit-license/commits/master/LICENSE.html). This can be
specified on the URL (in your permalink) or in the JSON file. specified on the URL (in your permalink) or in the JSON file.
For example: http://rem.mit-license.org/a526bf7ad1 (make sure to view-source) shows an older version of comments inline to the HTML document (compared to the [latest version](http://rem.mit-license.org)). For example: http://rem.mit-license.org/a526bf7ad1 (make sure to view-source) shows an older version of the LICENSE.html file (compared to the [latest version](http://rem.mit-license.org) - the older version didn't have the new themes).
This can also be targeted in my JSON file: This can also be targeted in my JSON file:
@ -103,15 +124,6 @@ If you've got an eye for design (or like me: not): you can contribute a
theme by adding a CSS file to the `themes` directory. The default theme theme by adding a CSS file to the `themes` directory. The default theme
is simple and clean, but you can add your own as you like. is simple and clean, but you can add your own as you like.
Current available themes:
* default - [preview](http://mit-license.org) (by
[@remy](http://github.com/remy) &
[@raphaelbastide](http://github.com/raphaelbastide))
* flesch - [preview](http://jsbin.com/ufefid/3) (by
[@flesch](http://github.com/flesch))
* afterdark - [preview](http://jsbin.com/ivufon/4) (by [@rmartindotco](http://github.com/rmartindotco))
To use a theme, add the `theme` property to your `user.json` file, for To use a theme, add the `theme` property to your `user.json` file, for
example: example:
@ -121,12 +133,20 @@ example:
"theme": "flesch" "theme": "flesch"
} }
Current available themes:
* default - [preview](http://mit-license.org) (by
[@remy](http://github.com/remy) &
[@raphaelbastide](http://github.com/raphaelbastide))
* flesch - [preview](http://jsbin.com/ufefid/3) (by
[@flesch](http://github.com/flesch))
* afterdark - [preview](http://jsbin.com/ivufon/4) (by [@rmartindotco](http://github.com/rmartindotco))
## Formats & URLs ## Formats & URLs
The following types of requests can be made to this project: The following types of requests can be made to this project:
* [http://rem.mit-license.org/](http://rem.mit-license.org/) # HTML, or the default format specified in * [http://rem.mit-license.org/](http://rem.mit-license.org/) HTML, or the default format specified in
the json file (currently none specified on `rem`) the json file (currently none specified on `rem`)
* [http://rem.mit-license.org/license.html](http://rem.mit-license.org/license.html) HTML * [http://rem.mit-license.org/license.html](http://rem.mit-license.org/license.html) HTML
* [http://rem.mit-license.org/license.txt](http://rem.mit-license.org/license.txt) Text * [http://rem.mit-license.org/license.txt](http://rem.mit-license.org/license.txt) Text
@ -138,6 +158,13 @@ HTML
* [http://rem.mit-license.org/a526bf7ad1/license.txt](http://rem.mit-license.org/a526bf7ad1/license.txt) a526bf7ad1 version, * [http://rem.mit-license.org/a526bf7ad1/license.txt](http://rem.mit-license.org/a526bf7ad1/license.txt) a526bf7ad1 version,
text text
The url also supports including a start year:
* [http://rem.mit-license.org/2009/](http://rem.mit-license.org/2009/) will
show a license year range of 2009-2011 (2011 being the current year)
* [http://rem.mit-license.org/2009-2010](http://rem.mit-license.org/2009-2010/)
allows me to force the year range
## Ways to contribute ## Ways to contribute
Aside from code contributions that make the project better, there are a Aside from code contributions that make the project better, there are a
@ -168,6 +195,7 @@ Domain contributions:
* [buritica](http://github.com/buritica) - 2015-2016 * [buritica](http://github.com/buritica) - 2015-2016
* [adamstrawson](http://github.com/adamstrawson) - 2016-2018 (2 years) * [adamstrawson](http://github.com/adamstrawson) - 2016-2018 (2 years)
* [keithamus](http://github.com/keithamus) - 2018-2026 (8 years) * [keithamus](http://github.com/keithamus) - 2018-2026 (8 years)
* [pmuellr](http://github.com/pmuellr) - 2026-2027
*Please note that the whois says 2014 currently, I'm following up with *Please note that the whois says 2014 currently, I'm following up with
the domain registra to make sure it's renewed for the right amount of the domain registra to make sure it's renewed for the right amount of

View file

@ -36,12 +36,16 @@
exit; exit;
} }
/**
* Load up the user.json file and read properties in
**/
if (file_exists($user_file)) { if (file_exists($user_file)) {
$user = json_decode(file_get_contents($user_file)); $user = json_decode(file_get_contents($user_file));
$holder = htmlentities($user->copyright, ENT_COMPAT | ENT_HTML5, 'UTF-8'); $holder = htmlentities($user->copyright, ENT_COMPAT | ENT_HTML401, 'UTF-8');
if (property_exists($user, 'url')) { if (property_exists($user, 'url')) {
$holder = '<a href="'.$user->url.'">' . $holder . '</a>'; $holder = '<a href="' . $user->url . '">' . $holder . '</a>';
} }
if (property_exists($user, 'email')) { if (property_exists($user, 'email')) {
$holder = $holder . ' &lt;<a href="mailto:' . $user->email . '">' . $user->email . '</a>&gt;'; $holder = $holder . ' &lt;<a href="mailto:' . $user->email . '">' . $user->email . '</a>&gt;';
} }
@ -61,6 +65,12 @@
$holder = "&lt;copyright holders&gt;"; $holder = "&lt;copyright holders&gt;";
} }
/**
* Now process the request url. Optional parts of the url are (in order):
* [sha]/[year|year-range]/license.[format]
* eg. http://rem.mit-license.org/a526bf7ad1/2009-2010/license.txt
**/
// grab sha from request uri // grab sha from request uri
$request_uri = explode('/', $_SERVER["REQUEST_URI"]); $request_uri = explode('/', $_SERVER["REQUEST_URI"]);
@ -76,6 +86,19 @@
$request = array_pop($request_uri); $request = array_pop($request_uri);
} }
// check if we have a year or a year range up front
$year = date('Y');
preg_match('/^(\d{4})(?:(?:\-)(\d{4}))?$/', $request, $match);
if (count($match) > 1) {
if ($match[2]) {
$year = $match[2];
}
if ($match[1]) {
$year = $match[1] . '-' . $year;
}
$request = array_pop($request_uri);
}
// check if there's a SHA on the url and read this to switch license versions // check if there's a SHA on the url and read this to switch license versions
$sha = ''; $sha = '';
if ($request != "" && $request != "/" && $request != "/index.php") { if ($request != "" && $request != "/" && $request != "/index.php") {
@ -101,7 +124,7 @@
} }
// replace info tag and display // replace info tag and display
$info = date('Y') . ' ' . $holder; $info = $year . ' ' . $holder;
$license = str_replace('{{info}}', $info, $license); $license = str_replace('{{info}}', $info, $license);
$license = str_replace('{{theme}}', $theme, $license); $license = str_replace('{{theme}}', $theme, $license);
@ -114,4 +137,4 @@
header('content-type: text/plain'); header('content-type: text/plain');
} }
echo $license; echo $license;