*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); class helper_plugin_medialist extends DokuWiki_Plugin { /** * syntax parser * * @param $data string matched the regex {{medialist>[^\r\n]+?}} * @return array parameter for render process * * ----------------------------------------------------------------------- * [ns:] namespace, must end ":" or ":*" * [page] page id * * {{pagelist>ns:}} * - show media files in the given namespace * - show button to open the given ns by fullscreen media manager * {{pagelist>ns: page}} * - distinguish linked files in the page if they found in the list * {{pagelist>ns: +page}} * - add linked media files to the list (@BOTH@) * * {{pagelist>page}} * - show media files linked in the given page * {{pagelist>page ns:}} * - show button to open the given ns by fullscreen media manager * ----------------------------------------------------------------------- */ public function parse($data) { global $INFO; $params = array(); // parameter array for render process $match = substr($data, 12, -2); $match = str_replace(' ',' ', trim($match)); // remove excessive white spaces // v1 syntax (backword compatibility for 2009-05-21 release) // @PAGE@, @NAMESPACE@, @ALL@ are complete keyword arguments, // not replacement patterns. switch ($match) { case '@PAGE@': $match = '@ID@'; break; case '@NAMESPACE@': $match = '@NS@:*'; break; case '@ALL@': case '@BOTH@': $match = '@NS@:* +@ID@'; break; } // v2 syntax (available since 2016-06-XX release) // - enable replacement patterns @ID@, @NS@, @PAGE@ // for media file search scope // - Namespace search if scope parameter ends colon ":", and // require "*" after the colon for recursive search // replacement patterns identical with Namespace Template // @see https://www.dokuwiki.org/namespace_templates#syntax $args = $match; $args = str_replace('@ID@', $INFO['id'], $args); $args = str_replace('@NS@', getNS($INFO['id']), $args); $args = str_replace('@PAGE@', noNS($INFO['id']), $args); $args = explode(' ', $args, 2); // check first parameter if (substr($args[0], -1) == ':') { $params['ns'] = substr($args[0], 0, -1); $params['depth'] = 1; // set depth option for search() } elseif (substr($args[0], -2) == ':*') { $params['ns'] = substr($args[0], 0, -2); } else { $params['page'] = $args[0]; } // check second parameter if (!empty($args[1])) { if (isset($params['ns'])) { $params['page'] = ltrim($args[1], '+'); $params['append'] = (bool) ($args[1][0] == '+'); } else { $params['uploadns'] = rtrim($args[1],':'); } } return $params; } /** * Renders xhtml */ public function render_xhtml($params) { $linked_media = array(); $stored_media = array(); // search internal files in the given namespace if (isset($params['ns'])) { // search option for lookup_stored_media() $opt = array(); if (array_key_exists('depth', $params)) { $opt = $opt + array('depth' => $params['depth']); } $stored_media = $this->_lookup_stored_media($params['ns'], $opt); } // search linked/used media in the given page if (isset($params['page'])) { $linked_media = $this->_lookup_linked_media($params['page']); } if (isset($params['append']) && $params['append']) { $media = array_unique(array_merge($stored_media, $linked_media), SORT_REGULAR); } else { $media = isset($params['ns']) ? $stored_media : $linked_media; if (!$params['ns'] && $params['page']) { $linked_media = array(); } } // prepare list items $items = array(); foreach ($media as $item) { $base = !isset($params['ns']) ? getNS($item['id']) : $params['ns']; if (in_array($item, $linked_media)) { $item = $item + array('level' => 1, 'base' => $base, 'linked'=> 1); } else { $item = $item + array('level' => 1, 'base' => $base); } $items[] = $item; } // create output $out = ''; $out .= '