Esempio n. 1
0
 /**
  * 書き込む(元の実装に忠実?)
  * @global type $adminname
  * @return type
  */
 function set($str, $keeptimestamp)
 {
     global $adminname;
     if ($this->auth_users == array()) {
         return;
     }
     // 管理人の設定は省く
     unset($this->auth_users[$adminname]);
     $lines[] = '<?php';
     $lines[] = 'use PukiWiki\\Auth\\Auth;';
     $lines[] = 'return array(';
     $lines[] = "\t" . '$adminname	=> array($adminpass, Auth::ROLE_ADMIN),';
     // 管理人は、ここでハードコーディング
     foreach ($this->auth_users as $user => $val) {
         $line = "\t" . '\'' . $user . '\' => array(' . "\n" . $val[0];
         for ($i = 1; $i < count($val); $i++) {
             if (!empty($val[$i])) {
                 $line .= ',' . $val[$i];
             }
         }
         $line .= "),";
         $lines[] = $line;
     }
     $lines[] = ');';
     parent::set($lines);
 }
Esempio n. 2
0
 /**
  * コンストラクタ
  * @param string $file ファイル名
  */
 public function __construct($file)
 {
     if (empty($file)) {
         throw new Exception('File::__construct(): file name is missing!');
     }
     parent::__construct($file);
 }
Esempio n. 3
0
 /**
  * コンストラクタ
  * @param string $page
  */
 public function __construct($page = null)
 {
     if (empty($page)) {
         throw new Exception('CounterFile::__construct(): Page name is missing!');
     }
     if (!is_string($page)) {
         throw new Exception('CounterFile::__construct(): Page name must be string!');
     }
     $this->page = $page;
     parent::__construct(self::$dir . Utility::encode($page) . '.count');
 }
Esempio n. 4
0
 /**
  * 書き込み
  * @global boolean $notify
  * @global boolean $notify_diff_only
  * @param string $str
  */
 public function set($diffdata = '', $keeptimestamp = false)
 {
     global $notify, $notify_diff_only, $notify_subject;
     // 差分を作成
     //$diff = new Diff(WikiFactory::Wiki($this->page)->source(true), explode("\n",$postdata));
     //$str = $diff->getDiff();
     if ($notify) {
         $str = $notify_diff_only ? preg_replace('/^[^-+].*\\n/m', '', $diffdata) : $diffdata;
         $summary = array('ACTION' => 'Page update', 'PAGE' => &$page, 'URI' => Router::get_script_uri() . '?' . rawurlencode($page), 'USER_AGENT' => TRUE, 'REMOTE_ADDR' => TRUE);
         Mailer::notify($notify_subject, $str, $summary) or Utility::dieMessage('Mailer::notify(): Failed');
     }
     parent::set($diffdata);
 }
Esempio n. 5
0
 /**
  * コンストラクタ
  * @param string $page ページ名
  * @param string $file ファイル名
  * @param int $age バックアップの世代
  */
 public function __construct($page, $file, $age = 0)
 {
     if (empty($page)) {
         throw new Exception('AttachFile::__construct(): Page name is missing!');
     }
     if (!is_string($page)) {
         throw new Exception('AttachFile::__construct(): Page name must be string!');
     }
     if (empty($file)) {
         throw new Exception('AttachFile::__construct(): File name is missing!');
     }
     if (!is_string($file)) {
         throw new Exception('AttachFile::__construct(): File name must be string!');
     }
     parent::__construct(self::$dir . Utility::encode($page) . '_' . Utility::encode($file) . ($age !== 0 ? '.' . $age : ''));
 }
Esempio n. 6
0
 /**
  * ログ記入
  * @param $value 未使用(何も入れないこと)
  * @param $keeptimestamp 未使用(何も入れないこと)
  */
 public function set($value = '', $keeptimestamp = false)
 {
     // 設定
     $config = $this->config[$this->kind];
     // ログを取らない場合書き込まない
     if (!$config['use']) {
         return;
     }
     // 書き込むデーターを取得
     $rc = self::log_common_check();
     // ない場合終了
     if (empty($rc)) {
         return;
     }
     // ログを読み込む
     $data = parent::get(false);
     // 行数
     $count = count($data);
     // 更新するキーを取得
     if (!empty($config['updtkey'])) {
         // 最低限記録するキー
         $mustkey = isset($config['mustkey']) ? $config['mustkey'] : 0;
         // 保存するキーを定義から取得
         $_key = explode(':', $config['updtkey']);
         // 設定項目名を取得
         $name = self::set_fieldname();
         // 更新フラグ
         $set = false;
         // 行の分解
         for ($i = 0; $i < $count; $i++) {
             // ログの1行を配列に変換した後、項目名を付与する
             // $line = array(
             //     'ts' => 000000,
             //     'ip' => 127.0.0.1
             //     ...
             // );
             // みたいな感じになる
             $line = self::line2field($data[$i], $name);
             if (isset($line['ts']) && $line['ts'] <= UTIME - self::LOG_LIFE_TIME) {
                 // 一定期間過ぎたエントリは削除
                 continue;
             }
             // 行書き換えフラグ
             $sw_update = true;
             // 列の分解
             foreach ($_key as $idx) {
                 // 書き込む前のデーターと異なっていた場合
                 if (isset($rc[$idx]) && isset($line[$idx]) && $rc[$idx] != $line[$idx]) {
                     $sw_update = false;
                     break;
                 }
                 /*
                 					if (empty($rc[$idx]) || empty($line[$idx])) {
                 						$sw_update = false;
                 						break;
                 					}
                 					if ($rc[$idx] !== $line[$idx]) {
                 						$sw_update = false;
                 						break;
                 					}
                 */
             }
             if ($sw_update) {
                 // 書き換え
                 $data[$i] = self::array2table($rc);
                 $set = true;
                 break;
             }
         }
         unset($i);
         // 追記するデーター
         if (!$set) {
             if ($mustkey) {
                 if (self::log_mustkey_check($_key, $data)) {
                     $data[] = self::array2table($rc);
                 }
             } else {
                 $data[] = self::array2table($rc);
             }
         }
     } else {
         // 新規データー
         $data[] = self::array2table($rc);
     }
     // 配列の長さ制限
     if ($count > self::LOG_MAX_ENTRIES) {
         $i = 0;
         // 古いエントリから削除するため配列を反転
         foreach (array_reverse($data) as $line) {
             if ($i > self::LOG_MAX_ENTRIES) {
                 break;
             }
             $ret[] = $line;
             $i++;
         }
         // 戻す
         $data = array_reverse($ret);
     }
     // 保存(空行は削除)
     parent::set($data);
 }
Esempio n. 7
0
 /**
  * バックアップファイルの内容を圧縮形式に応じて取得する
  * TODO:gzとbz2解凍がスレッドセーフでない
  * @access    private
  *
  * @return    Array     ファイルの内容
  */
 private function read_sub($ext, $join)
 {
     // ファイルを取得
     $data = '';
     switch ($ext) {
         case '.txt':
             $data = parent::get();
             break;
         case '.lzf':
             $data = lzf_decompress(parent::get());
             break;
         case '.gz':
             $handle = gzopen($this->filename, 'r');
             while (!gzeof($handle)) {
                 $data .= gzread($handle, 1024);
             }
             gzclose($handle);
             break;
         case '.bz2':
             $handle = bzopen($this->filename, 'r');
             while (!feof($handle)) {
                 $data .= bzread($handle, 1024);
             }
             bzclose($handle);
             break;
     }
     // 取得した内容を改行ごとに配列として返す
     return $join ? $data : explode("\n", $data);
 }