OSDN Git Service

BugTrack2/122: tempnam() fails when open_basedir is specified in php.ini
[pukiwiki/pukiwiki.git] / plugin / update_entities.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: update_entities.inc.php,v 1.9 2005/06/23 18:00:07 teanan Exp $
4 //
5 // Update entities plugin - Update XHTML entities from DTD
6 // (for admin)
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         set_plugin_messages($messages);
35 }
36
37 function plugin_update_entities_action()
38 {
39         global $script, $vars;
40         global $_entities_messages;
41
42         if (PKWK_READONLY) die_message('PKWK_READONLY prohibits this');
43
44         $msg = $body = '';
45         if (empty($vars['action']) || empty($vars['adminpass']) || ! pkwk_login($vars['adminpass'])) {
46                 $msg   = & $_entities_messages['title_update'];
47                 $items = plugin_update_entities_create();
48                 $body  = convert_html(sprintf($_entities_messages['msg_usage'], join("\n" . '-', $items)));
49                 $body .= <<<EOD
50 <form method="POST" action="$script">
51  <div>
52   <input type="hidden" name="plugin" value="update_entities" />
53   <input type="hidden" name="action" value="update" />
54   <label for="_p_update_entities_adminpass">{$_entities_messages['msg_adminpass']}</label>
55   <input type="password" name="adminpass" id="_p_update_entities_adminpass" size="20" value="" />
56   <input type="submit" value="{$_entities_messages['btn_submit']}" />
57  </div>
58 </form>
59 EOD;
60         } else if ($vars['action'] == 'update') {
61                 plugin_update_entities_create(TRUE);
62                 $msg  = & $_entities_messages['title_update'];
63                 $body = & $_entities_messages['msg_done'    ];
64         } else {
65                 $msg  = & $_entities_messages['title_update'];
66                 $body = & $_entities_messages['err_invalid' ];
67         }
68         return array('msg'=>$msg, 'body'=>$body);
69 }
70
71 // Remove &amp; => amp
72 function plugin_update_entities_strtr($entity){
73         return strtr($entity, array('&'=>'', ';'=>''));
74 }
75
76 function plugin_update_entities_create($do = FALSE)
77 {
78         $files = array('xhtml-lat1.ent', 'xhtml-special.ent', 'xhtml-symbol.ent');
79         
80         $entities = array_map('plugin_update_entities_strtr',
81                 array_values(get_html_translation_table(HTML_ENTITIES)));
82         $items   = array('php:html_translation_table');
83         $matches = array();
84         foreach ($files as $file) {
85                 $source = file(W3C_XHTML_DTD_LOCATION . $file);
86 //                      or die_message('cannot receive ' . W3C_XHTML_DTD_LOCATION . $file . '.');
87                 if (! is_array($source)) {
88                         $items[] = 'w3c:' . $file . ' COLOR(red):not found.';
89                         continue;
90                 }
91                 $items[] = 'w3c:' . $file;
92                 if (preg_match_all('/<!ENTITY\s+([A-Za-z0-9]+)/',
93                         join('', $source), $matches, PREG_PATTERN_ORDER))
94                 {
95                         $entities = array_merge($entities, $matches[1]);
96                 }
97         }
98         if (! $do) return $items;
99
100         $entities = array_unique($entities);
101         sort($entities, SORT_STRING);
102         $min = 999;
103         $max = 0;
104         foreach ($entities as $entity) {
105                 $len = strlen($entity);
106                 $max = max($max, $len);
107                 $min = min($min, $len);
108         }
109
110         $pattern = "(?=[a-zA-Z0-9]\{$min,$max})" .
111                 get_autolink_pattern_sub($entities, 0, count($entities), 0);
112         $fp = fopen(CACHE_DIR  .'entities.dat', 'w')
113                 or die_message('cannot write file ' . CACHE_DIR . 'entities.dat<br />' . "\n" .
114                         'maybe permission is not writable or filename is too long');
115         fwrite($fp, $pattern);
116         fclose($fp);
117
118         return $items;
119 }
120 ?>