* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ # NOTE Some Linux distributon change the location of DokuWiki core libraries (DOKU_INC) # # Bitnami (Docker) /opt/bitnami/dokuwiki # LinuxServer.io (Docker) /app/dokuwiki # Arch Linux /usr/share/webapps/dokuwiki # Debian/Ubuntu /usr/share/dokuwiki # # NOTE If DokuWiki core libraries (DOKU_INC) is in another location you can # create a PHP file in bootstrap3 root directory called "doku_inc.php" with # this content: # # hsc($INPUT->str('prefix')), 'icons' => hsc($INPUT->str('icons')), 'callback' => hsc($INPUT->str('callback')), 'width' => hsc($INPUT->str('width')), 'height' => hsc($INPUT->str('height')), 'icon' => hsc($INPUT->str('icon')), 'color' => hsc($INPUT->str('color')), ); $iconify_dir = dirname(__FILE__) . '/assets/iconify/json'; $cache_key = md5(serialize($params) . $conf['template'] . filemtime(__FILE__)); $cache_files = $params; $cache_files[] = __FILE__; $content_type = 'application/javascript; charset=utf-8'; $cache = new dokuwiki\Cache\Cache($cache_key, '.js'); $cache->setEvent('ICONIFY_CACHE'); $cache_ok = $cache->useCache(array('files' => $cache_files)); if ($params['icon']) { $content_type = 'image/svg+xml; charset=utf-8'; list($params['prefix'], $params['icons']) = explode('-', str_replace('.svg', '', $params['icon']), 2); } header("Content-Type: $content_type"); http_cached($cache->cache, $cache_ok); $collection_file = "$iconify_dir/" . $params['prefix'] . ".json"; if (!file_exists($collection_file)) { header('Content-Type: text/plain; charset=utf-8', true); http_status(404); print "Not Found"; exit; } $collection_data = json_decode(io_readFile($collection_file), true); $iconify_data = array( 'prefix' => $params['prefix'], 'icons' => array(), 'aliases' => array(), ); foreach (explode(',', $params['icons']) as $icon) { if (isset($collection_data['aliases'][$icon])) { $iconify_data['aliases'][$icon] = $collection_data['aliases'][$icon]; $icon = $collection_data['aliases'][$icon]['parent']; } if (!$icon_data = $collection_data['icons'][$icon]) { continue; } $iconify_data['icons'][$icon] = $icon_data; if ($params['width']) { $iconify_data['icons'][$icon]['width'] = $params['width']; } if ($params['height']) { $iconify_data['icons'][$icon]['height'] = $params['height']; } } foreach (array('width', 'height', 'top', 'left', 'inlineHeight', 'inlineTop', 'verticalAlign') as $property) { if (isset($collection_data[$property])) { $iconify_data[$property] = $collection_data[$property]; } } if ($params['callback']) { $content = $params['callback'] . "(" . json_encode($iconify_data) . ");"; } elseif ($params['icon']) { $icon = $params['icons']; $width = '1em'; $height = '1em'; $fill = ''; if (isset($iconify_data['aliases'][$icon])) { $icon = $iconify_data['aliases'][$icon]['parent']; } if (!isset($iconify_data['icons'][$icon])) { header('Content-Type: text/plain; charset=utf-8', true); http_status(404); print "Not Found"; exit; } if ($params['width']) { $width = $params['width']; $height = $params['width']; } if ($params['height']) { $width = $params['height']; $height = $params['height']; } if ($params['color']) { $fill = $params['color']; } # TODO add "rotate" support $body = $iconify_data['icons'][$icon]['body']; if ($fill) { $body = str_replace('currentColor', $fill, $body); } $svg = '%s'; $content = sprintf($svg, $width, $height, $body); } else { $content = "SimpleSVG._loaderCallback(" . json_encode($iconify_data) . ");"; } http_cached_finish($cache->cache, $content); #print $content;