3 * Pagelist Plugin: lists pages
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Esther Brunner <wikidesign@gmail.com>
8 // must be run within Dokuwiki
9 if (!defined('DOKU_INC')) die();
11 if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC
.'lib/plugins/');
12 require_once(DOKU_PLUGIN
.'syntax.php');
14 class syntax_plugin_pagelist
extends DokuWiki_Syntax_Plugin
{
16 function getType() { return 'substition';}
17 function getPType() { return 'block';}
18 function getSort() { return 168; }
21 * Connect pattern to lexer
23 function connectTo($mode) {
24 $this->Lexer
->addSpecialPattern('<pagelist.+?</pagelist>', $mode, 'plugin_pagelist');
30 function handle($match, $state, $pos, &$handler) {
33 $match = substr($match, 9, -11); // strip markup
34 list($flags, $match) = explode('>', $match, 2);
35 $flags = explode('&', substr($flags, 1));
36 $items = explode('*', $match);
40 for ($i = 0; $i < $c; $i++
) {
41 if (!preg_match('/\[\[(.+?)\]\]/', $items[$i], $match)) continue;
42 list($id, $title) = explode('|', $match[1], 2);
43 list($id, $section) = explode('#', $id, 2);
45 resolve_pageid(getNS($ID), $id, $exists);
47 // page has an image title
48 if (($title) && (preg_match('/\{\{(.+?)\}\}/', $title, $match))) {
49 list($image, $title) = explode('|', $match[1], 2);
50 list($ext, $mime) = mimetype($image);
51 if (!substr($mime, 0, 5) == 'image') $image = '';
54 'section' => cleanID($section),
55 'title' => trim($title),
56 'image' => trim($image),
60 // text title (if any)
64 'section' => cleanID($section),
65 'title' => trim($title),
70 return array($flags, $pages);
76 function render($mode, &$renderer, $data) {
77 list($flags, $pages) = $data;
80 if ($mode == 'xhtml') {
81 if (!$my =& plugin_load('helper', 'pagelist')) return false;
82 $my->setFlags($flags);
84 foreach($pages as $page) {
87 $renderer->doc
.= $my->finishList();
90 // for metadata renderer
91 } elseif ($mode == 'metadata') {
92 foreach ($pages as $page) {
93 $renderer->meta
['relation']['references'][$page['id']] = $page['exists'];
100 // vim:ts=4:sw=4:et:enc=utf-8: