Release of grains plugin to racktables-contribs
[racktables-contribs] / XKCD-import.php
CommitLineData
7adb7e5e
DO
1<?php
2/*
54921c2b
DO
3 * UPDATE: This revision of script can run with RackTables 0.19.x.
4 *
7adb7e5e
DO
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
54921c2b 11 * earlier to do that with a single wget pass:
7adb7e5e
DO
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
54921c2b 16 * directory after that. (There are other XKCD ripping scripts available
7adb7e5e
DO
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
54921c2b 24# the line below prevents unintentional changes to DB
7adb7e5e
DO
25exit;
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');
30chdir ($racktables_root);
31$script_mode = TRUE;
32include ('inc/init.php');
33
34foreach (array ('png', 'jpg') as $ext)
35 foreach (glob ("${imgdir}/*.${ext}") as $longname)
36 {
37 echo "${longname} : ";
38 $data = file_get_contents ($longname);
54921c2b 39 commitAddFile (basename ($longname), $mimetype[$ext], $data, 'XKCD (http://xkcd.com/)');
7adb7e5e
DO
40 echo "OK \n";
41 }
42
43?>