1<?php
2/**
3 * DokuWiki Plugin elasticsearch (CLI Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8
9if (!defined('DOKU_INC')) die();
10
11use splitbrain\phpcli\Options;
12
13/**
14 * CLI tools for managing the index
15 */
16class cli_plugin_elasticsearch_img extends DokuWiki_CLI_Plugin
17{
18
19    /**
20     * Register options and arguments on the given $options object
21     *
22     * @param Options $options
23     * @return void
24     * @throws \splitbrain\phpcli\Exception
25     */
26    protected function setup(Options $options)
27    {
28        $options->setHelp('Output image data using DokuWiki\'s builtin EXIF capabilities');
29
30        $options->registerArgument('file', 'image file to convert to text', true);
31    }
32
33    /** * @inheritDoc */
34    protected function main(Options $options)
35    {
36        $args = $options->getArgs();
37
38        $meta = new JpegMeta($args[0]);
39
40        $data = [
41            'title' => $meta->getTitle(0),
42            'content' => join("\n", [
43                $meta->getField([
44                    'Iptc.Caption',
45                    'Exif.UserComment',
46                    'Exif.ImageDescription',
47                    'Exif.TIFFImageDescription',
48                    'Exif.TIFFUserComment',
49                ]),
50                $meta->getField([
51                    'Iptc.Byline',
52                    'Exif.TIFFArtist',
53                    'Exif.Artist',
54                    'Iptc.Credit',
55                ]),
56                $meta->getField([
57                    'Iptc.Keywords',
58                    'Exif.Category',
59                ]),
60                $meta->getField([
61                    'Iptc.CopyrightNotice',
62                    'Exif.TIFFCopyright',
63                    'Exif.Copyright',
64                ]),
65            ]),
66            'created' => date('Y-m-d\TH:i:s\Z', $meta->getField('Date.EarliestTime')),
67        ];
68
69        echo json_encode($data, JSON_PRETTY_PRINT);
70    }
71
72}
73