Lexer->addSpecialPattern('----+ *photogallery(?: [ a-zA-Z0-9_]*)?-+\n.*?\n?----+', $mode, 'plugin_photogallery'); } /** * Handle the match - parse the data * * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text * @param Doku_Handler $handler The Doku_Handler object * @return bool|array Return an array with all data you want to use in render, false don't add an instruction */ function handle($match, $state, $pos, Doku_Handler $handler){ global $ID; $data = array(); // get lines $lines = explode("\n", $match); array_pop($lines); // get command $cmd = array_shift($lines); $cmd = str_replace('photogallery', '', $cmd); $cmd = trim($cmd, '- '); if (!strpos('show|link',$cmd)) { $cmd = 'show'; } $data['command'] = $cmd; // set the defaults $data['phpthumb'] = $this->getConf('use_phpThumb'); $data['autoplay'] = $this->getConf('autoplay'); $data['pw'] = $this->getConf('poster_width'); $data['ph'] = $this->getConf('poster_height'); $data['tw'] = $this->getConf('thumbnail_width'); $data['th'] = $this->getConf('thumbnail_height'); $data['iw'] = $this->getConf('viewport_width'); $data['ih'] = $this->getConf('viewport_height'); $data['vprot'] = $this->getConf('viewport_rotate'); $data['panar'] = $this->getConf('panorama_ratio'); $data['panw'] = $this->getConf('panorama_width'); $data['panh'] = $this->getConf('panorama_height'); $data['posteralign'] = $this->getConf('posteralign'); $data['filter'] = ''; $data['fullsize'] = $this->getConf('fullsize'); $data['sort'] = $this->getConf('sort'); $data['limit'] = 0; $data['offset'] = 0; $data['ns'] = getNS($ID); $this->_setConfOptions($data,$this->getConf('options')); // parse additional options $params = $this->getConf('options'); $params = preg_replace('/[,&\?]+/',' ',$params); $params = explode(' ',$params); foreach($params as $param){ if($param === '') continue; if($param == 'titlesort'){ $data['sort'] = 'title'; }elseif($param == 'datesort'){ $data['sort'] = 'date'; }elseif($param == 'modsort'){ $data['sort'] = 'mod'; }elseif(preg_match('/^=(\d+)$/',$param,$match)){ $data['limit'] = $match[1]; }elseif(preg_match('/^\+(\d+)$/',$param,$match)){ $data['offset'] = $match[1]; }elseif(is_numeric($param)){ $data['cols'] = (int) $param; }elseif(preg_match('/^(\d+)([xX])(\d+)$/',$param,$match)){ if($match[2] == 'X'){ $data['iw'] = $match[1]; $data['ih'] = $match[3]; }else{ $data['tw'] = $match[1]; $data['th'] = $match[3]; } }elseif(strpos($param,'*') !== false){ $param = preg_quote($param,'/'); $param = '/^'.str_replace('\\*','.*?',$param).'$/'; $data['filter'] = $param; }else{ if(substr($param,0,2) == 'no'){ $data[substr($param,2)] = false; }else{ $data[$param] = true; } } } // Check phpThumb requirements if ($data['phpthumb'] == true){ if (!$this->_phpThumbCheck()){ msg($this->getLang('phpthumbdisabled'),2); $data['phpthumb'] = false; } } // parse info foreach ($lines as $line) { // ignore comments preg_match('/^(.*?(? $value){ if ((!isset($data[$key])) and (isset($rdata[$key]))){ $data[$key] = $value; } } break; } } } } return $data; } /** * Create output or save the data * * @param $format string output format being rendered * @param $renderer Doku_Renderer the current renderer object * @param $data array data created by handler() * @return boolean rendered correctly? */ function render($mode, Doku_Renderer $R, $data){ global $ID; global $conf; $this->metaAliases = $this->getMetaTagAliases(); $cmd = $data['command']; if($mode == 'xhtml'){ if($this->_auth_check($data)){ $R->info['cache'] = false; // Disable global render cache $this->_photo_gallery($data, $R); // Start gallery } elseif($cmd == 'show') msg(sprintf($this->getLang('notauthorized'),$data['ns']),-1); return true; }elseif($mode == 'metadata'){ // NOM da rivedere $rel = p_get_metadata($ID,'relation',METADATA_RENDER_USING_CACHE); $img = $rel['firstimage']; if(empty($img)){ $files = $this->_findimages($data); } return true; } return false; } function _phpThumbCheck(){ $fperm = fileperms(PHOTOGALLERY_PGFETCH_FILE); if (($fperm & PHOTOGALLERY_PGFETCH_EXE_PERM) != PHOTOGALLERY_PGFETCH_EXE_PERM){ msg($this->getLang('phpthumbexecerror'),-1); if (@chmod(PHOTOGALLERY_PGFETCH_FILE, $fperm | PHOTOGALLERY_PGFETCH_EXE_PERM)){ msg($this->getLang('phpthumbexecpermset'),1); return true; } else{ msg($this->getLang('phpthumbpermseterror'),-1); return false; } } return true; } /** * Does the gallery formatting */ function _photo_gallery($data, $R){ global $conf; global $lang; global $ID; global $auth; global $USERINFO; $cmd = $data['command']; if (empty($data['rss'])) { if(($cmd == 'show') and (!$this->_media_folder_exists($data['ns']))){ $R->doc .= '
' . ($data['description'] ?? '') . '
'; $R->doc .= ''; $info = ''; $this->_addString($info,$imgcnt,sprintf($this->getLang('imagescnt'),$imgcnt)); $this->_addString($info,$vidcnt,sprintf($this->getLang('videoscnt'),$vidcnt),', '); $R->doc .= $info; if (isset($data['ziplink'])){ $R->doc .= ' - '.$data['ziplink']; } $R->doc .= '
'; $R->doc .= '' . ($data['copyright'] ?? '') . '
'.DOKU_LF; $R->doc .= ''.nl2br(hsc($desc)).'
'; } } if (!empty($data['showkeywords'])) { $keywords = $this->_meta($img,'keywords'); if(!empty($keywords)){ $ret .= ''.hsc($keywords).'
'; } } if (!empty($data['showinfo'])) { $ret .= $this->_exif($img); } if (!empty($data['showfname'])) { $ret .= ''.hsc($img['file']).'
'; } if (!empty($data['showlink'])) { $ret .= ''; } return $ret; } /** * Return the EXIF data for the image */ function _exif($img){ // Read EXIF data $jpeg = $img['meta'] ?? null; $ret = ''; if($jpeg){ $make = $jpeg->getField(array('Exif.Make','Exif.TIFFMake')); $model = $jpeg->getField(array('Exif.Model','Exif.TIFFModel')); $model = preg_replace('/^'.$make.' /','',$model); $shutter = $jpeg->getShutterSpeed(); $fnumber = $jpeg->getField(array('Exif.FNumber')); $iso = $jpeg->getField(array('Exif.ISOSpeedRatings')); $date = $jpeg->getDateField('EarliestTimeStr'); $yy = substr($date ,0,4); $mm = substr($date ,5,2); $dd = substr($date ,8,2); $date = $dd.'/'.$mm.'/'.$yy; $ret .= $date; $this->_addString($ret,$make.$model,$make.' '.$model, ' - '); $this->_addString($ret,$shutter,$shutter.'s',', '); $this->_addString($ret,$fnumber,'f/'.$fnumber,', '); $this->_addString($ret,$iso,'ISO '.$iso,', '); $this->_addString($ret,$ret,null,null,'','
'); } return $ret; } /** * Creates a compressed zip file */ function _createzipfile($files,$zipfile,$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($zipfile) && !$overwrite) return false; if(count($files)) { //create the archive $zip = new ZipArchive(); if($zip->open($zipfile,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($files as $img) { $file = mediaFN($img['id']); $zip->addFile($file,basename(dirname($file)).'/'.basename($file)); } //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($zipfile); } else { return false; } } /** * Check ACLs on Gallery */ protected function _auth_check($data){ global $USERINFO; global $INPUT; global $auth; global $conf; if (!$auth) return false; $user = $INPUT->server->str('REMOTE_USER'); if (is_null($user)) return false; $groups = $USERINFO['grps'] ?? []; if (!empty($data['authlist'])) { $authlist = $data['authlist'] . ','. $conf['superuser']; return auth_isMember($authlist, $user, $groups); } return true; } /** * Check ACLs on Zip link */ function _zip_auth_check($data){ global $INPUT; global $USERINFO; global $auth; global $conf; if(!$auth) return false; $user = $INPUT->server->str('REMOTE_USER'); if(is_null($user)) return false; $groups = $USERINFO['grps'] ?? []; $authlist = $data['zipauthlist']; if (isset($authlist)){ $authlist .= ','.$conf['superuser']; return auth_isMember($authlist, $user, $groups); } else return true; } /** * Return if a namespace has exists as media folder */ function _media_folder_exists($ns){ global $conf; return is_dir($conf['mediadir'].'/'.utf8_encodeFN(str_replace(':','/',$ns))); } /** * Sets additional comma separated options */ function _setConfOptions(&$data, $optstr){ $opts = explode(',', $optstr); foreach ($opts as $opt) $data[trim($opt)] = true; } /** * Adds a string to $source only if $check is true. */ function _addString(&$source, $check, $value = '', $separator = '', $prefix = '', $suffix = ''){ if($check){ if($source) $source .= $separator; $source .= $value; $source = $prefix.$source.$suffix; } } } // $jpeg = new JpegMeta(mediaFN($img['id'])); // if($ext == 'jpg' || $ext == 'jpeg') { // //try to use the caption from IPTC/EXIF // require_once(DOKU_INC.'inc/JpegMeta.php'); // $jpeg = new JpegMeta(mediaFN($src)); // if($jpeg !== false) $cap = $jpeg->getTitle(); // $exif_data = exif_read_data($path,'IFD0',0); // $emake = $exif_data['Make']; // $emodel = $exif_data['Model']; // $emodel = str_replace($emake,"",$emodel); // $eexposuretime = $exif_data['ExposureTime']; // // $efnumber = $exif_data['FNumber']; // $efnumber = $exif_data['COMPUTED']['ApertureFNumber']; // $eiso = $exif_data['ISOSpeedRatings']; // $edate = $exif_data['DateTimeOriginal']; // $yy = substr($edate ,0,4); // $mm = substr($edate ,5,2); // $dd = substr($edate ,8,2); // $h = substr($edate ,11,2); // $m = substr($edate ,14,2); // $s = substr($edate ,17,2); // $date = $dd.'/'.$mm.'/'.$yy; // $time = $h.':'.$m.':'.$s; // return $date." - ".$emake." ".$emodel.", ".$eexposuretime."s, ".$efnumber.", ISO ".$eiso; // $page = $this->_apply_macro($page, $parent_id); // resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID // if (auth_quickaclcheck($page) >= AUTH_READ) // $pages[] = $page; // function _showname($img,$data){ // //prepare link // $lnk = ml($img['id'],array('id'=>$ID),false); // // prepare output // $ret .= hsc($img['file']);