Skip to content

Instantly share code, notes, and snippets.

@frah frah/DocumentParser.patch
Last active Dec 31, 2015

Embed
What would you like to do?
KBPublisher用語集日本語キーワード対応パッチ
--- old/DocumentParser.php Wed Dec 18 14:16:57 2013
+++ new/DocumentParser.php Wed Dec 18 14:18:43 2013
@@ -143,7 +143,7 @@
$ids = array();
foreach($glossary as $id => $item) {
- if(strpos(strtolower($string), strtolower($item)) !== false) {
+ if(mb_strpos(mb_strtolower($string), mb_strtolower($item)) !== false) {
$ids[] = $id;
}
}
@@ -154,8 +154,8 @@
$glossary = &$this->stripVars($manager->getGlossaryDefinitions(implode(',', $ids)));
foreach($glossary as $k => $v) {
-
- $preg = "~\b($k)\b(?![^<]*>)~i";
+ //$preg = "~\b($k)\b(?![^<]*>)~i";
+ $preg = "/(^|[a-z]\s|[^a-z])($k)(\s[a-z]|[^a-z]|$)/iu";
preg_match_all($preg, $string, $matches);
- $num = ($v['display_once']) ? 1 : count($matches[0]);
+ $num = ($v['display_once']) ? 1 : count($matches[2]);
@@ -168,7 +168,8 @@
//$str = "<span class=\"glossaryItem\" onmouseover=\"return overlib('%s', CAPTION, 'URL', HAUTO, VAUTO, FGCOLOR, '#FFFF99', BGCOLOR, '#CC9900', WIDTH, 300);\" onmouseout=\"return nd();\">";
//<a class="glossaryItem" href="/knowledgebase/glossary/#URL">URL</a></span>
- $search = "~\b(".$matches[0][$j].")\b(?!<\/span>\s)(?![^<]*>)~i";
+ //$search = "~\b(".$matches[0][$j].")\b(?!<\/span>\s)(?![^<]*>)~i";
+ $search = "/(".$matches[2][$j].")(?!<\/span>\s)(?![^<]*>)/iu";
$v['definition'] = addslashes(str_replace(array("\r\n", "\n"), ' ', $v['definition']));
$replace = sprintf($str, $id, $v['definition'], $id, $id);
$string = preg_replace($search, $replace, $string, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.