PukiWiki PHP Cross Reference Collaborative Wikis

Source: /plugin/update_entities.inc.php - 120 lines - 3690 bytes - Summary - Text - Print

   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  ?>

title

Description

title

Description

title

Description

title

title

Body