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