7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: update_entities.inc.php 1601 2009-03-21 05:51:06Z fishbone $
14 * @link http://www.magic3.org
16 // Update entities plugin - Update XHTML entities from DTD
20 define('W3C_XHTML_DTD_LOCATION', 'http://www.w3.org/TR/xhtml1/DTD/');
23 function plugin_update_entities_init()
26 '_entities_messages'=>array(
27 'title_update' => 'キャッシュ更新',
28 'msg_adminpass' => '管理者パスワード',
30 'msg_done' => 'キャッシュの更新が完了しました。',
34 :文字実体参照にマッチする正規表現パターンのキャッシュを更新|
35 PHPの持つテーブルおよびW3CのDTDをスキャンして、キャッシュに記録します。
38 「COLOR(red){not found.}」と表示されたファイルは処理されません。
42 管理者パスワードを入力して、[実行]ボタンをクリックしてください。
45 set_plugin_messages($messages);
48 function plugin_update_entities_action()
50 //global $script, $vars;
52 global $_entities_messages;
54 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits this');
57 $action = WikiParam::getVar('action');
58 $pass = WikiParam::getVar('pass');
59 //if (empty($vars['action']) || empty($vars['adminpass']) || ! pkwk_login($vars['adminpass'])) {
60 if (empty($action) || empty($pass) || !pkwk_login($pass)){
61 $msg = $_entities_messages['title_update'];
62 $items = plugin_update_entities_create();
63 $body = convert_html(sprintf($_entities_messages['msg_usage'], join("\n" . '-', $items)));
64 $postScript = $script . WikiParam::convQuery("?");
66 <form action="$postScript" method="post" class="form">
68 <input type="hidden" name="plugin" value="update_entities" />
69 <input type="hidden" name="action" value="update" />
70 <input type="hidden" name="pass" />
71 <label for="_p_update_entities_adminpass">{$_entities_messages['msg_adminpass']}</label>
72 <input type="password" name="password" id="_p_update_entities_adminpass" size="12" />
73 <input type="submit" class="button" value="{$_entities_messages['btn_submit']}" onclick="this.form.pass.value = hex_md5(this.form.password.value);" />
78 //} else if ($vars['action'] == 'update') {
79 } else if ($action == 'update') {
80 plugin_update_entities_create(TRUE);
81 $msg = $_entities_messages['title_update'];
82 $body = $_entities_messages['msg_done' ];
84 $msg = $_entities_messages['title_update'];
85 $body = $_entities_messages['err_invalid' ];
87 return array('msg'=>$msg, 'body'=>$body);
90 // Remove & => amp
91 function plugin_update_entities_strtr($entity){
92 return strtr($entity, array('&'=>'', ';'=>''));
95 function plugin_update_entities_create($do = FALSE)
97 $files = array('xhtml-lat1.ent', 'xhtml-special.ent', 'xhtml-symbol.ent');
99 $entities = array_map('plugin_update_entities_strtr',
100 array_values(get_html_translation_table(HTML_ENTITIES)));
101 $items = array('php:html_translation_table');
103 foreach ($files as $file) {
104 $source = file(W3C_XHTML_DTD_LOCATION . $file);
105 // or die_message('cannot receive ' . W3C_XHTML_DTD_LOCATION . $file . '.');
106 if (! is_array($source)) {
107 $items[] = 'w3c:' . $file . ' COLOR(red):not found.';
110 $items[] = 'w3c:' . $file;
111 if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
112 join('', $source), $matches, PREG_PATTERN_ORDER))
114 $entities = array_merge($entities, $matches[1]);
117 if (! $do) return $items;
119 $entities = array_unique($entities);
120 sort($entities, SORT_STRING);
123 foreach ($entities as $entity) {
124 $len = strlen($entity);
125 $max = max($max, $len);
126 $min = min($min, $len);
130 $pattern = "(?=[a-zA-Z0-9]\{$min,$max})" . get_autolink_pattern_sub($entities, 0, count($entities), 0);
131 WikiPage::updateEntityData($pattern);
133 $fp = fopen(CACHE_DIR .'entities.dat', 'w')
134 or die_message('cannot write file ' . CACHE_DIR . 'entities.dat<br />' . "\n" .
135 'maybe permission is not writable or filename is too long');
136 fwrite($fp, $pattern);