r3211: start RackTables contribs directory
[racktables-contribs] / XKCD-import.phps
CommitLineData
7adb7e5e
DO
1<?php
2/*
3 * XKCD (xkcd.com) is a relatively popular webcomic, which is licensed under
4 * Creative Commons Attribution-NonCommercial 2.5 License. This script
5 * imports files with XKCD art into RackTables system. The files are taken
6 * from a local mirror of XKCD archive, if there is one.
7 *
8 * First, it is necessary to get the files themselves. It was possible
9 * earlier to do that with a straight wget pass:
10 * $ wget -r -A png http://imgs.xkcd.com/comics/
11 * However, after changes on the XKCD server more work is necessary:
12 * $ wget --mirror --level=2 --span-hosts --domains=xkcd.com,imgs.xkcd.com --accept=html,jpg,png http://xkcd.com/archive/
13 * There should be several hundred PNG and JPEG pictures in the imgs.xkcd.com/comics
14 * directory after that. (There are other XKCD ripping script available
15 * on the Internet.)
16 *
17 * Second, two variables below ($imgdir and $racktables_root) must be set
18 * according to local filesystem layout. After that the script can be
19 * executed from command-line (php XKCD-files.php) to import the files.
20 */
21
22exit;
23$imgdir = '/tmp/imgs.xkcd.com/comics';
24$racktables_root = '/var/www/vhosts/racktables.org/demo/trunk';
25
26$mimetype = array ('png' => 'image/png', 'jpg' => 'image/jpeg');
27chdir ($racktables_root);
28$script_mode = TRUE;
29include ('inc/init.php');
30
31foreach (array ('png', 'jpg') as $ext)
32 foreach (glob ("${imgdir}/*.${ext}") as $longname)
33 {
34 echo "${longname} : ";
35 $data = file_get_contents ($longname);
36 commitAddFile (basename ($longname), $mimetype[$ext], strlen ($data), $data, 'XKCD (http://xkcd.com/)');
37 echo "OK \n";
38 }
39
40?>