<?php
-/////////////////////////////////////////////////
-// PukiWiki - Yet another WikiWikiWeb clone.
-//
-// $Id: update_entities.inc.php,v 1.5 2004/07/31 03:09:20 henoheno Exp $
+// PukiWiki - Yet another WikiWikiWeb clone
+// $Id: update_entities.inc.php,v 1.15 2007/04/08 10:29:24 henoheno Exp $
+// Copyright (C) 2003-2007 PukiWiki Developers Team
+// License: GPL v2 or (at your option) any later version
//
+// Update entities plugin - Update XHTML entities from DTD
+// (for admin)
-// DTD¤Î¾ì½ê
-define('W3C_XHTML_DTD_LOCATION','http://www.w3.org/TR/xhtml1/DTD/');
+// DTDの場所
+define('W3C_XHTML_DTD_LOCATION', 'http://www.w3.org/TR/xhtml1/DTD/');
-// ¥á¥Ã¥»¡¼¥¸ÀßÄê
+// メッセージ設定
function plugin_update_entities_init()
{
$messages = array(
'_entities_messages'=>array(
- 'title_update' => '¥¥ã¥Ã¥·¥å¹¹¿·',
- 'msg_adminpass' => '´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É',
- 'btn_submit' => '¼Â¹Ô',
- 'msg_done' => '¥¥ã¥Ã¥·¥å¤Î¹¹¿·¤¬´°Î»¤·¤Þ¤·¤¿¡£',
+ 'title_update' => 'キャッシュ更新',
+ 'msg_adminpass' => '管理者パスワード',
+ 'btn_submit' => '実行',
+ 'msg_done' => 'キャッシュの更新が完了しました。',
'msg_usage' => '
-* ½èÍýÆâÍÆ
+* 処理内容
-:ʸ»ú¼ÂÂλ²¾È¤Ë¥Þ¥Ã¥Á¤¹¤ëÀµµ¬É½¸½¥Ñ¥¿¡¼¥ó¤Î¥¥ã¥Ã¥·¥å¤ò¹¹¿·|
-PHP¤Î»ý¤Ä¥Æ¡¼¥Ö¥ë¤ª¤è¤ÓW3C¤ÎDTD¤ò¥¹¥¥ã¥ó¤·¤Æ¡¢¥¥ã¥Ã¥·¥å¤ËµÏ¿¤·¤Þ¤¹¡£
+:文字実体参照にマッチする正規表現パターンのキャッシュを更新|
+PHPの持つテーブルおよびW3CのDTDをスキャンして、キャッシュに記録します。
-* ½èÍýÂоÝ
-¡ÖCOLOR(red){not found.}¡×¤Èɽ¼¨¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï½èÍý¤µ¤ì¤Þ¤»¤ó¡£
+* 処理対象
+「COLOR(red){not found.}」と表示されたファイルは処理されません。
-%s
-* ¼Â¹Ô
-´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ·¤Æ¡¢[¼Â¹Ô]¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£
+* 実行
+管理者パスワードを入力して、[実行]ボタンをクリックしてください。
'
- )
- );
+ ));
set_plugin_messages($messages);
}
global $script, $vars;
global $_entities_messages;
- if (empty($vars['action']) or empty($vars['adminpass']) or ! pkwk_login($vars['adminpass']))
- {
+ if (PKWK_READONLY) die_message('PKWK_READONLY prohibits this');
+
+ $msg = $body = '';
+ if (empty($vars['action']) || empty($vars['adminpass']) || ! pkwk_login($vars['adminpass'])) {
+ $msg = & $_entities_messages['title_update'];
$items = plugin_update_entities_create();
- $body = convert_html(sprintf($_entities_messages['msg_usage'],join("\n-",$items)));
+ $body = convert_html(sprintf($_entities_messages['msg_usage'], join("\n" . '-', $items)));
$body .= <<<EOD
-<form method="POST" action="$script">
+<form method="post" action="$script">
<div>
<input type="hidden" name="plugin" value="update_entities" />
<input type="hidden" name="action" value="update" />
- {$_entities_messages['msg_adminpass']}
- <input type="password" name="adminpass" size="20" value="" />
+ <label for="_p_update_entities_adminpass">{$_entities_messages['msg_adminpass']}</label>
+ <input type="password" name="adminpass" id="_p_update_entities_adminpass" size="20" value="" />
<input type="submit" value="{$_entities_messages['btn_submit']}" />
</div>
</form>
EOD;
- return array(
- 'msg'=>$_entities_messages['title_update'],
- 'body'=>$body
- );
- }
- else if ($vars['action'] == 'update')
- {
+ } else if ($vars['action'] == 'update') {
plugin_update_entities_create(TRUE);
- return array(
- 'msg'=>$_entities_messages['title_update'],
- 'body'=>$_entities_messages['msg_done']
- );
+ $msg = & $_entities_messages['title_update'];
+ $body = & $_entities_messages['msg_done' ];
+ } else {
+ $msg = & $_entities_messages['title_update'];
+ $body = & $_entities_messages['err_invalid' ];
}
+ return array('msg'=>$msg, 'body'=>$body);
+}
- return array(
- 'msg'=>$_entities_messages['title_update'],
- 'body'=>$_entities_messages['err_invalid']
- );
+// Remove & => amp
+function plugin_update_entities_strtr($entity){
+ return strtr($entity, array('&'=>'', ';'=>''));
}
-function plugin_update_entities_create($do=FALSE)
+function plugin_update_entities_create($do = FALSE)
{
- $files = array('xhtml-lat1.ent','xhtml-special.ent','xhtml-symbol.ent');
- $entities = strtr(
- array_values(get_html_translation_table(HTML_ENTITIES)),
- array('&'=>'',';'=>'')
- );
- $items = array('php:html_translation_table');
- foreach ($files as $file)
- {
- $source = file(W3C_XHTML_DTD_LOCATION.$file);
-// or die_message('cannot receive '.W3C_XHTML_DTD_LOCATION.$file.'.');
- if (!is_array($source))
- {
- $items[] = "w3c:$file COLOR(red):not found.";
+ $files = array('xhtml-lat1.ent', 'xhtml-special.ent', 'xhtml-symbol.ent');
+
+ $entities = array_map('plugin_update_entities_strtr',
+ array_values(get_html_translation_table(HTML_ENTITIES)));
+ $items = array('php:html_translation_table');
+ $matches = array();
+ foreach ($files as $file) {
+ $source = file(W3C_XHTML_DTD_LOCATION . $file);
+// or die_message('cannot receive ' . W3C_XHTML_DTD_LOCATION . $file . '.');
+ if (! is_array($source)) {
+ $items[] = 'w3c:' . $file . ' COLOR(red):not found.';
continue;
}
- $items[] = "w3c:$file";
+ $items[] = 'w3c:' . $file;
if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
- join('',$source),$matches,PREG_PATTERN_ORDER))
+ join('', $source), $matches, PREG_PATTERN_ORDER))
{
- $entities = array_merge($entities,$matches[1]);
+ $entities = array_merge($entities, $matches[1]);
}
}
- if (!$do)
- {
- return $items;
- }
+ if (! $do) return $items;
+
$entities = array_unique($entities);
- sort($entities,SORT_STRING);
+ sort($entities, SORT_STRING);
$min = 999;
$max = 0;
- foreach ($entities as $entity)
- {
+ foreach ($entities as $entity) {
$len = strlen($entity);
- $max = max($max,$len);
- $min = min($min,$len);
+ $max = max($max, $len);
+ $min = min($min, $len);
}
- $pattern = "(?=[a-zA-Z0-9]\{$min,$max})".get_autolink_pattern_sub($entities,0,count($entities),0);
- $fp = fopen(CACHE_DIR.'entities.dat','w')
- or die_message('cannot write file '.CAHCE_DIR.'entities.dat<br />maybe permission is not writable or filename is too long');
- fwrite($fp,$pattern);
+ $pattern = "(?=[a-zA-Z0-9]\{$min,$max})" .
+ get_autolink_pattern_sub($entities, 0, count($entities), 0);
+ $fp = fopen(CACHE_DIR .'entities.dat', 'w')
+ or die_message('cannot write file ' . CACHE_DIR . 'entities.dat<br />' . "\n" .
+ 'maybe permission is not writable or filename is too long');
+ fwrite($fp, $pattern);
fclose($fp);
return $items;