1<?php 2/** 3* Plugin nspages : Displays nicely a list of the pages of a namespace 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 */ 7 8if(!defined('DOKU_INC')) die(); 9require_once 'printer.php'; 10 11class nspages_printerPictures extends nspages_printer { 12 private static $_dims = array('w' => 350, 'h' => 220); 13 private $_defaultPicture; 14 15 function __construct($plugin, $mode, $renderer, $data){ 16 parent::__construct($plugin, $mode, $renderer, $data); 17 $this->_defaultPicture = $data['defaultPicture']; 18 } 19 20 function _print($tab, $type) { 21 $this->renderer->doc .= '<div class="nspagesPicturesModeMain">'; 22 foreach($tab as $item) { 23 $picture = $this->_getFirstImage($item['id']); 24 $url = wl($item['id']); 25 26 // TODO: implement support for non-HTML mode 27 // Note that, wrt indexing, it's not an issue to build a <a> ourselves instead of using the api 28 // because non xhtml mode (eg: "metadata" mode) isn't plugged on this xhtml specific code 29 $optionalId = ''; 30 if ($this->includeItemsInTOC) { 31 $anchorId = $this->buildAnchorId($item); 32 $optionalId = 'id="' . $anchorId . '"'; 33 $this->renderer->toc_additem($anchorId, $item['nameToDisplay'], $this->renderer->getLastLevel() + 1); 34 } 35 36 $this->renderer->doc .= '<a href="'. $url .'" title="'.$item['nameToDisplay'].'">'; 37 $this->renderer->doc .= '<div class="nspagesPicturesModeImg" style="background-image:url('. $picture .')" ' . $optionalId . '>'; 38 $this->renderer->doc .= '<span class="nspagesPicturesModeTitle">'.$item['nameToDisplay']; 39 if ( $this->_displayModificationDate ){ 40 $this->renderer->doc .= '</span><span class="nspagesPicturesDate">' . date('d/m/Y', $item['mtime']); 41 } 42 $this->renderer->doc .= '</span></div></a>'; 43 } 44 $this->renderer->doc .= '</div>'; 45 } 46 47 private function _getFirstImage($pageId){ 48 $meta = p_get_metadata($pageId); 49 $picture = $meta['relation']['firstimage']; 50 if ( $picture != "" ){ 51 return ml($picture, self::$_dims, true); 52 } else { 53 if ( $this->_defaultPicture == '' ){ 54 return "lib/tpl/dokuwiki/images/logo.png"; 55 } else { 56 return ml($this->_defaultPicture, self::$_dims, true); 57 } 58 } 59 } 60} 61