/** * Glossaryの正規表現パターンを生成 * @return string */ private static function getAutoGlossaryPattern($force = false) { global $cache, $glossarypage; static $pattern; $wiki = Factory::Wiki($glossarypage); if (!$wiki->has()) { return null; } // Glossaryの更新チェック if ($cache['wiki']->hasItem(self::AUTO_GLOSSARY_TERM_CACHE)) { if (self::getGlossaryTime() < $wiki->time()) { $force = true; } } // キャッシュ処理 if ($force) { unset($pattern); $cache['wiki']->removeItem(self::AUTO_GLOSSARY_PATTERN_CACHE); } else { if (!empty($pattern)) { return $pattern; } else { if ($cache['wiki']->hasItem(self::AUTO_GLOSSARY_PATTERN_CACHE)) { $pattern = $cache['wiki']->getItem(self::AUTO_GLOSSARY_PATTERN_CACHE); $cache['wiki']->touchItem(self::AUTO_GLOSSARY_PATTERN_CACHE); return $pattern; } } } // パターンキャッシュを生成 global $autoglossary, $nowikiname; // 用語集を取得 $pairs = self::getGlossaryDict($force); foreach ($pairs as $term => $val) { if (preg_match('/^' . RendererDefines::WIKINAME_PATTERN . '$/', $term) ? $nowikiname : mb_strlen($term) >= $autoglossary) { $auto_terms[] = $term; } } if (empty($auto_terms)) { return array('(?!)', 'PukiWiki', 'PukiWiki'); } else { // 用語辞書パターンからマッチパターン用の正規表現を生成 $auto_terms = array_unique($auto_terms); sort($auto_terms, SORT_STRING); $auto_terms_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_terms)); $auto_terms = array_values(array_diff($auto_terms, $auto_terms_a)); $result = Trie::regex($auto_terms); $result_a = Trie::regex($auto_terms_a); } $pattern = array($result, $result_a); // パターンキャッシュを保存 $cache['wiki']->setItem(self::AUTO_GLOSSARY_PATTERN_CACHE, $pattern); return $pattern; }
/** * 自動リンクの正規表現パターンを生成 * @return string */ private function getAutoLinkPattern($force = false) { global $cache; static $pattern; // キャッシュ処理 if ($force) { unset($pattern); $cache['wiki']->removeItem(self::AUTO_LINK_PATTERN_CACHE); } else { if (!empty($pattern)) { return $pattern; } else { if ($cache['wiki']->hasItem(self::AUTO_LINK_PATTERN_CACHE)) { $pattern = $cache['wiki']->getItem(self::AUTO_LINK_PATTERN_CACHE); $cache['wiki']->touchItem(self::AUTO_LINK_PATTERN_CACHE); return $pattern; } } } // 用語マッチパターンキャッシュを生成 global $autolink, $nowikiname; $config = new Config('AutoLink'); // FIXME $config->read(); $ignorepages = $config->get('IgnoreList'); $forceignorepages = $config->get('ForceIgnoreList'); unset($config); $auto_pages = array_merge($ignorepages, $forceignorepages); foreach (Listing::pages('wiki') as $page) { if (preg_match('/^' . RendererDefines::WIKINAME_PATTERN . '$/', $page) ? $nowikiname : strlen($page) >= $autolink) { $auto_pages[] = $page; } } if (empty($auto_pages)) { $result = $result_a = $nowikiname ? '(?!)' : RendererDefines::WIKINAME_PATTERN; } else { $auto_pages = array_unique($auto_pages); sort($auto_pages, SORT_STRING); $auto_pages_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_pages)); $auto_pages = array_values(array_diff($auto_pages, $auto_pages_a)); // 正規表現を最適化 $result = Trie::regex($auto_pages); $result_a = Trie::regex($auto_pages_a); } $pattern = array($result, $result_a, $forceignorepages); $cache['wiki']->setItem(self::AUTO_LINK_PATTERN_CACHE, $pattern); return $pattern; }
/** * AutoAliasの正規表現パターンを生成 * @return string */ private function getAutoAliasPattern($force = false) { global $cache, $aliaspage; static $pattern; $wiki = Factory::Wiki($aliaspage); if (!$wiki->has()) { return null; } // AutoAliasNameの更新チェック if ($cache['wiki']->hasItem(self::AUTOALIAS_PATTERN_CACHE)) { $term_cache_meta = $cache['wiki']->getMetadata(self::AUTOALIAS_PATTERN_CACHE); if ($term_cache_meta['mtime'] < $wiki->time()) { $force = true; } } // キャッシュ処理 if ($force) { unset($pattern); $cache['wiki']->removeItem(self::AUTOALIAS_PATTERN_CACHE); } else { if (!empty($pattern)) { return $pattern; } else { if ($cache['wiki']->hasItem(self::AUTOALIAS_PATTERN_CACHE)) { $pattern = $cache['wiki']->getItem(self::AUTOALIAS_PATTERN_CACHE); $cache['wiki']->touchItem(self::AUTOALIAS_PATTERN_CACHE); return $pattern; } } } global $WikiName, $autolink, $nowikiname; $config = new Config('AutoAlias'); $config->read(); $ignorepages = $config->get('IgnoreList'); $forceignorepages = $config->get('ForceIgnoreList'); unset($config); $auto_pages = array_merge($ignorepages, $forceignorepages); foreach (self::getAutoAliasDict($force) as $term => $val) { if (preg_match('/^' . $WikiName . '$/', $term) ? $nowikiname : mb_strlen($term) >= $autolink) { $auto_terms[] = $term; } } if (empty($auto_terms)) { $result = $result_a = $nowikiname ? '(?!)' : $WikiName; } else { $auto_terms = array_unique($auto_terms); sort($auto_terms, SORT_STRING); $auto_terms_a = array_values(preg_grep('/^[A-Z]+$/i', $auto_terms)); $auto_terms = array_values(array_diff($auto_terms, $auto_terms_a)); $result = Trie::regex($auto_terms); $result_a = Trie::regex($auto_terms_a); } $pattern = array($result, $result_a, $forceignorepages); $cache['wiki']->setItem(self::AUTOALIAS_PATTERN_CACHE, $pattern); return $pattern; }