2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: update_entities.inc.php,v 1.5 2004/07/31 03:09:20 henoheno Exp $
9 define('W3C_XHTML_DTD_LOCATION','http://www.w3.org/TR/xhtml1/DTD/');
12 function plugin_update_entities_init()
15 '_entities_messages'=>array(
16 'title_update' => '¥¥ã¥Ã¥·¥å¹¹¿·',
17 'msg_adminpass' => '´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É',
18 'btn_submit' => '¼Â¹Ô',
19 'msg_done' => '¥¥ã¥Ã¥·¥å¤Î¹¹¿·¤¬´°Î»¤·¤Þ¤·¤¿¡£',
23 :ʸ»ú¼ÂÂλ²¾È¤Ë¥Þ¥Ã¥Á¤¹¤ëÀµµ¬É½¸½¥Ñ¥¿¡¼¥ó¤Î¥¥ã¥Ã¥·¥å¤ò¹¹¿·|
24 PHP¤Î»ý¤Ä¥Æ¡¼¥Ö¥ë¤ª¤è¤ÓW3C¤ÎDTD¤ò¥¹¥¥ã¥ó¤·¤Æ¡¢¥¥ã¥Ã¥·¥å¤ËµÏ¿¤·¤Þ¤¹¡£
27 ¡ÖCOLOR(red){not found.}¡×¤Èɽ¼¨¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï½èÍý¤µ¤ì¤Þ¤»¤ó¡£
31 ´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ·¤Æ¡¢[¼Â¹Ô]¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£
35 set_plugin_messages($messages);
38 function plugin_update_entities_action()
40 global $script, $vars;
41 global $_entities_messages;
43 if (empty($vars['action']) or empty($vars['adminpass']) or ! pkwk_login($vars['adminpass']))
45 $items = plugin_update_entities_create();
46 $body = convert_html(sprintf($_entities_messages['msg_usage'],join("\n-",$items)));
48 <form method="POST" action="$script">
50 <input type="hidden" name="plugin" value="update_entities" />
51 <input type="hidden" name="action" value="update" />
52 {$_entities_messages['msg_adminpass']}
53 <input type="password" name="adminpass" size="20" value="" />
54 <input type="submit" value="{$_entities_messages['btn_submit']}" />
59 'msg'=>$_entities_messages['title_update'],
63 else if ($vars['action'] == 'update')
65 plugin_update_entities_create(TRUE);
67 'msg'=>$_entities_messages['title_update'],
68 'body'=>$_entities_messages['msg_done']
73 'msg'=>$_entities_messages['title_update'],
74 'body'=>$_entities_messages['err_invalid']
78 function plugin_update_entities_create($do=FALSE)
80 $files = array('xhtml-lat1.ent','xhtml-special.ent','xhtml-symbol.ent');
82 array_values(get_html_translation_table(HTML_ENTITIES)),
83 array('&'=>'',';'=>'')
85 $items = array('php:html_translation_table');
86 foreach ($files as $file)
88 $source = file(W3C_XHTML_DTD_LOCATION.$file);
89 // or die_message('cannot receive '.W3C_XHTML_DTD_LOCATION.$file.'.');
90 if (!is_array($source))
92 $items[] = "w3c:$file COLOR(red):not found.";
95 $items[] = "w3c:$file";
96 if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
97 join('',$source),$matches,PREG_PATTERN_ORDER))
99 $entities = array_merge($entities,$matches[1]);
106 $entities = array_unique($entities);
107 sort($entities,SORT_STRING);
110 foreach ($entities as $entity)
112 $len = strlen($entity);
113 $max = max($max,$len);
114 $min = min($min,$len);
117 $pattern = "(?=[a-zA-Z0-9]\{$min,$max})".get_autolink_pattern_sub($entities,0,count($entities),0);
118 $fp = fopen(CACHE_DIR.'entities.dat','w')
119 or die_message('cannot write file '.CAHCE_DIR.'entities.dat<br />maybe permission is not writable or filename is too long');
120 fwrite($fp,$pattern);