Beispiel #1
0
 /**
  * お気にスレなどのidxファイルを同期する
  *
  * @static
  * @access  public
  * @param   string  $idx_path   idxファイルのパス
  * @param   boolean $noMsg      結果メッセージのpushを抑制するならtrue
  * @return  void
  */
 function syncIdx($idx_path, $noMsg = false)
 {
     global $_conf;
     static $done = array();
     // {{{ 読込
     if (isset($done[$idx_path])) {
         return;
     }
     $lines = BbsMap::_readData($idx_path);
     if (!$lines) {
         return;
     }
     $map = BbsMap::_getMapping();
     if (!$map) {
         return;
     }
     $neolines = array();
     $updated = false;
     // }}}
     // {{{ 同期
     foreach ($lines as $line) {
         $data = explode('<>', rtrim($line, "\n"));
         $host = $data[10];
         $bbs = $data[11];
         $type = BbsMap::_detectHostType($host);
         if (isset($map[$type]) && isset($map[$type][$bbs])) {
             $newhost = $map[$type][$bbs]['host'];
         } else {
             $newhost = $host;
         }
         if ($host != $newhost) {
             $data[10] = $newhost;
             $neolines[] = implode('<>', $data) . "\n";
             $updated = true;
         } else {
             $neolines[] = $line;
         }
     }
     // }}}
     // {{{ 書込
     $name = basename($idx_path);
     $name_hs = htmlspecialchars($name, ENT_QUOTES);
     if ($updated) {
         BbsMap::_writeData($idx_path, $neolines);
         !$noMsg and P2Util::pushInfoHtml(sprintf('<p>p2 info: %s を同期しました。</p>', $name_hs));
     } else {
         !$noMsg and P2Util::pushInfoHtml(sprintf('<p>p2 info: %s は変更されませんでした。</p>', $name_hs));
     }
     $done[$idx_path] = true;
     // }}}
 }