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
14    function __construct($plugin, $mode, $renderer, $data){
15        parent::__construct($plugin, $mode, $renderer, $data);
16        $this->_defaultPicture = $data['defaultPicture'];
17    }
18
19    function _print($tab, $type) {
20        $this->renderer->doc .= '<div class="nspagesPicturesModeMain">';
21        foreach($tab as $item) {
22                $picture = $this->_getFirstImage($item['id']);
23                $url = wl($item['id']);
24
25                // TODO: implement support for non-HTML mode
26                //       Note that, wrt indexing, it's not an issue to build a <a> ourselves instead of using the api
27                //       because non xhtml mode (eg: "metadata" mode) isn't plugged on this xhtml specific code
28                $optionalId = '';
29                if ($this->includeItemsInTOC) {
30                  $anchorId = $this->buildAnchorId($item);
31                  $optionalId = 'id="' . $anchorId . '"';
32                  $this->renderer->toc_additem($anchorId, $item['nameToDisplay'], $this->renderer->getLastLevel() + 1);
33                }
34
35                $this->renderer->doc .= '<a href="'. $url .'" title="'.$item['nameToDisplay'].'">';
36                $this->renderer->doc .= '<div class="nspagesPicturesModeImg" style="background-image:url('. $picture .')" ' . $optionalId . '>';
37                $this->renderer->doc .= '<span class="nspagesPicturesModeTitle">'.$item['nameToDisplay'];
38                if ( $this->_displayModificationDate ){
39                    $this->renderer->doc .= '</span><span class="nspagesPicturesDate">' . date('d/m/Y', $item['mtime']);
40                }
41                $this->renderer->doc .= '</span></div></a>';
42        }
43        $this->renderer->doc .= '</div>';
44    }
45
46    private function _getFirstImage($pageId){
47      $meta = p_get_metadata($pageId);
48      $picture = $meta['relation']['firstimage'];
49      if ( $picture != "" ){
50          return ml($picture, self::$_dims, true);
51      } else {
52          if ( $this->_defaultPicture == '' ){
53                return "lib/tpl/dokuwiki/images/logo.png";
54          } else {
55                return ml($this->_defaultPicture, self::$_dims, true);
56          }
57      }
58    }
59}
60