OSDN Git Service

Cleanup comments only
[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.5 2004/07/31 03:09:20 henoheno 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, $vars;
41         global $_entities_messages;
42
43         if (empty($vars['action']) or empty($vars['adminpass']) or ! pkwk_login($vars['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
78 function plugin_update_entities_create($do=FALSE)
79 {
80         $files = array('xhtml-lat1.ent','xhtml-special.ent','xhtml-symbol.ent');
81         $entities = strtr(
82                 array_values(get_html_translation_table(HTML_ENTITIES)),
83                 array('&'=>'',';'=>'')
84         );
85         $items = array('php:html_translation_table');
86         foreach ($files as $file)
87         {
88                 $source = file(W3C_XHTML_DTD_LOCATION.$file);
89 //                      or die_message('cannot receive '.W3C_XHTML_DTD_LOCATION.$file.'.');
90                 if (!is_array($source))
91                 {
92                         $items[] = "w3c:$file COLOR(red):not found.";
93                         continue;
94                 }
95                 $items[] = "w3c:$file";
96                 if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
97                         join('',$source),$matches,PREG_PATTERN_ORDER))
98                 {
99                         $entities = array_merge($entities,$matches[1]);
100                 }
101         }
102         if (!$do)
103         {
104                 return $items;
105         }
106         $entities = array_unique($entities);
107         sort($entities,SORT_STRING);
108         $min = 999;
109         $max = 0;
110         foreach ($entities as $entity)
111         {
112                 $len = strlen($entity);
113                 $max = max($max,$len);
114                 $min = min($min,$len);
115         }
116
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);
121         fclose($fp);
122
123         return $items;
124 }
125 ?>