/** * */ private function initializePatterns() { if (refnotes_configuration::getSetting('replace-footnotes')) { $entry = '(?:\\(\\(|\\[\\()'; $exit = '(?:\\)\\)|\\)\\])'; $id = '@@FNT\\d+|#\\d+'; } else { $entry = '\\[\\('; $exit = '\\)\\]'; $id = '#\\d+'; } $strictName = refnotes_note::getNamePattern('strict'); $extendedName = refnotes_note::getNamePattern('extended'); $namespace = refnotes_namespace::getNamePattern('optional'); $text = '.*?'; $strictName = '(?:' . $id . '|' . $strictName . ')'; $fullName = '\\s*(?:' . $namespace . $strictName . '|:' . $namespace . $extendedName . ')\\s*'; $lookaheadExit = '(?=' . $exit . ')'; $nameEntry = $fullName . $lookaheadExit; $extendedName = '(?:' . $id . '|' . $extendedName . ')'; $optionalFullName = $namespace . $extendedName . '?'; $structuredEntry = '\\s*' . $optionalFullName . '\\s*>>' . $text . $lookaheadExit; $define = '\\s*' . $optionalFullName . '\\s*>\\s*'; $optionalDefine = '(?:' . $define . ')?'; $lookaheadExit = '(?=' . $text . $exit . ')'; $defineEntry = $optionalDefine . $lookaheadExit; $this->entryPattern = $entry . '(?:' . $nameEntry . '|' . $structuredEntry . '|' . $defineEntry . ')'; $this->exitPattern = $exit; $this->handlePattern = '/' . $entry . '\\s*(' . $optionalFullName . ')\\s*(?:>>(.*))?(.*)/s'; }
function generate_bib() { global $conf; $bibtext = ''; // we merge all the files in this string $basefn = PLUGIN_TEXIT_CONF . 'bibliography.bib'; if (!is_callable("refnotes_configuration::getSetting")) { // case where refnotes isn't available. In this case the // file to include is just $basefn. return $basefn; } // code coming from refnotes' syntax.php $refnotes_nsdir = refnotes_configuration::getSetting('reference-db-namespace'); $refnotes_nsdir = str_replace(':', '/', $refnotes_nsdir); $refnotes_nsdir = trim($refnotes_nsdir, '/ '); $destfn = $conf['datadir'] . '/' . $refnotes_nsdir . '/texit.bib'; $all_refnotes_pages = array(); $opts = array('listdirs' => false, 'listfiles' => true, 'pagesonly' => true, 'skipacl' => false, 'sneakyacl' => true, 'showhidden' => false); // we cannot use $opts in search_list or in search_namespaces, see // https://bugs.dokuwiki.org/index.php?do=details&task_id=2858 search($all_refnotes_pages, $conf['datadir'], 'search_universal', $opts, $refnotes_nsdir); // now all_refnotes_pages contains all the configuration pages of refnotes, that // we'll have to merge... // First step here is to see if we need to recompile anything: if (is_readable($destfn)) { // if the file is readable, then it might be up-to-date? $needsupdate = false; if (is_readable($basefn)) { $needsupdate = $this->_needs_update($basefn, $destfn); } foreach ($all_refnotes_pages as $page) { // A problem here: if the refnote page doesn't contain // any bibtex code, the update will take place anyway, // but it doesn't sound critical. if ($this->_needs_update(wikiFN($page['id']), $destfn)) { $needsupdate = true; } } // if the file doesn't need update, we just return. if (!$needsupdate) { return $destfn; } } if (is_readable($basefn)) { $bibtext = file_get_contents($basefn); } foreach ($all_refnotes_pages as $page) { $fn = wikiFN($page['id']); $bibtext .= $this->parse_refnotes_page($fn); } if (empty($bibtext)) { return false; } file_put_contents($destfn, $bibtext); // we return the filename where the bibliography is saved return $destfn; }
/** * */ private function loadPages() { global $conf; if (file_exists($conf['indexdir'] . '/page.idx')) { require_once DOKU_INC . 'inc/indexer.php'; $pageIndex = idx_getIndex('page', ''); $namespace = refnotes_configuration::getSetting('reference-db-namespace'); $namespacePattern = '/^' . trim($namespace, ':') . ':/'; $cache = new refnotes_reference_database_cache(); foreach ($pageIndex as $pageId) { $pageId = trim($pageId); if (preg_match($namespacePattern, $pageId) == 1 && file_exists(wikiFN($pageId))) { $this->enabled = false; $this->page[$pageId] = new refnotes_reference_database_page($this, $cache, $pageId); $this->enabled = true; } } $cache->save(); } }
/** * */ private function saveConfig($config) { global $config_cascade; $json = new JSON(JSON_LOOSE_TYPE); $config = $json->decode($config); $namespace = $config['namespaces']; $namespace = $this->translateStyles($namespace, 'js', 'dw'); $saved = refnotes_configuration::save('general', $config['general']); $saved = $saved && refnotes_configuration::save('namespaces', $namespace); $saved = $saved && refnotes_configuration::save('notes', $config['notes']); if ($config['general']['reference-db-enable']) { $saved = $saved && $this->setupReferenceDatabase($config['general']['reference-db-namespace']); } /* Touch local config file to expire the cache */ $saved = $saved && touch(reset($config_cascade['main']['local'])); $this->sendResponse('text/plain', $saved ? 'saved' : 'failed'); }
/** * Constructor */ public function __construct() { $this->presetStyle = refnotes_configuration::load('namespaces'); $this->namespace = array(); $this->mapping = array(); }