OSDN Git Service

BugTrack/566 CVS キーワード置換調整, SKIN_DIR='./skin/'
[pukiwiki/pukiwiki.git] / plugin / update_entities.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: update_entities.inc.php,v 1.2 2003/07/22 05:56:49 arino Exp $
6 //
7
8 // DTD¤Î¾ì½ê
9 define('W3C_XHTML_DTD_LOCATION','http://www.w3.org/TR/xhtml1/DTD/');
10
11 // ¥á¥Ã¥»¡¼¥¸ÀßÄê
12 function plugin_update_entities_init()
13 {
14         $messages = array(
15                 '_entities_messages'=>array(
16                         'title_update'  => '¥­¥ã¥Ã¥·¥å¹¹¿·',
17                         'msg_adminpass' => '´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É',
18                         'btn_submit'    => '¼Â¹Ô',
19                         'msg_done'      => '¥­¥ã¥Ã¥·¥å¤Î¹¹¿·¤¬´°Î»¤·¤Þ¤·¤¿¡£',
20                         'msg_usage'     => '
21 * ½èÍýÆâÍÆ
22
23 :ʸ»ú¼ÂÂλ²¾È¤Ë¥Þ¥Ã¥Á¤¹¤ëÀµµ¬É½¸½¥Ñ¥¿¡¼¥ó¤Î¥­¥ã¥Ã¥·¥å¤ò¹¹¿·|
24 PHP¤Î»ý¤Ä¥Æ¡¼¥Ö¥ë¤ª¤è¤ÓW3C¤ÎDTD¤ò¥¹¥­¥ã¥ó¤·¤Æ¡¢¥­¥ã¥Ã¥·¥å¤Ëµ­Ï¿¤·¤Þ¤¹¡£
25
26 * ½èÍýÂоÝ
27 ¡ÖCOLOR(red){not found.}¡×¤¬É½¼¨¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï½èÍý¤µ¤ì¤Þ¤»¤ó¡£
28 -%s
29
30 * ¼Â¹Ô
31 ´ÉÍý¼Ô¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ·¤Æ¡¢[¼Â¹Ô]¥Ü¥¿¥ó¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£
32 '
33                 )
34         );
35         set_plugin_messages($messages);
36 }
37
38 function plugin_update_entities_action()
39 {
40         global $script,$post,$vars,$adminpass;
41         global $_entities_messages;
42         
43         if (empty($vars['action']) or empty($post['adminpass']) or md5($post['adminpass']) != $adminpass)
44         {
45                 $items = plugin_update_entities_create();
46                 $body = convert_html(sprintf($_entities_messages['msg_usage'],join("\n-",$items)));
47                 $body .= <<<EOD
48 <form method="POST" action="$script">
49  <div>
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']}" />
55  </div>
56 </form>
57 EOD;
58                 return array(
59                         'msg'=>$_entities_messages['title_update'],
60                         'body'=>$body
61                 );
62         }
63         else if ($vars['action'] == 'update')
64         {
65                 plugin_update_entities_create(TRUE);
66                 return array(
67                         'msg'=>$_entities_messages['title_update'],
68                         'body'=>$_entities_messages['msg_done']
69                 );
70         }
71         
72         return array(
73                 'msg'=>$_entities_messages['title_update'],
74                 'body'=>$_entities_messages['err_invalid']
75         );
76 }
77 function plugin_update_entities_create($do=FALSE)
78 {
79         $files = array('xhtml-lat1.ent','xhtml-special.ent','xhtml-symbol.ent');
80         $entities = strtr(
81                 array_values(get_html_translation_table(HTML_ENTITIES)),
82                 array('&'=>'',';'=>'')
83         );
84         $items = array('php:html_translation_table');
85         foreach ($files as $file)
86         {
87                 $source = file(W3C_XHTML_DTD_LOCATION.$file);
88 //                      or die_message('cannot receive '.W3C_XHTML_DTD_LOCATION.$file.'.');
89                 if (!is_array($source))
90                 {
91                         $items[] = "w3c:$file COLOR(red):not found.";
92                         continue;
93                 }
94                 $items[] = "w3c:$file";
95                 if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
96                         join('',$source),$matches,PREG_PATTERN_ORDER))
97                 {
98                         $entities = array_merge($entities,$matches[1]);
99                 }
100         }
101         if (!$do)
102         {
103                 return $items;
104         }
105         $entities = array_unique($entities);
106         sort($entities,SORT_STRING);
107         $min = 999;
108         $max = 0;
109         foreach ($entities as $entity)
110         {
111                 $len = strlen($entity);
112                 $max = max($max,$len);
113                 $min = min($min,$len);
114         }
115         
116         $pattern = "(?=[a-zA-Z0-9]\{$min,$max})".get_autolink_pattern_sub($entities,0,count($entities),0);
117         $fp = fopen(CACHE_DIR.'entities.dat','w')
118                 or die_message('cannot write file '.CAHCE_DIR.'entities.dat<br />maybe permission is not writable or filename is too long');
119         fwrite($fp,$pattern);
120         fclose($fp);
121         
122         return $items;
123 }
124 ?>