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