示例#1
0
 /**
  * コンストラクタ
  * @param string $page
  */
 public function __construct($page)
 {
     if (empty($page)) {
         throw new Exception('DiffFile::__construct(): Page name is missing!');
     }
     $this->page = $page;
     parent::__construct(self::$dir . Utility::encode($page) . '.txt');
 }
示例#2
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');
 }
示例#3
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 : ''));
 }
示例#4
0
 /**
  * コンストラクタ
  * @param string $page
  */
 public function __construct($page = null)
 {
     if (empty($this->kind)) {
         throw new Exception('LogFile::__construct(): class "' . get_called_class() . '" does not defined $kind value.');
     }
     $this->config = Utility::loadConfig('config-log.ini.php');
     if (!$this->isWiki) {
         if (empty($page)) {
             throw new Exception('LogFile::__construct(): Page name is missing!');
         }
         // ページ名
         $this->page = $page;
         parent::__construct(self::$dir . $this->kind . '/' . Utility::encode($page) . '.txt');
     } else {
         // Wikiに保存する場合
         parent::__construct(DATA_DIR . Utility::encode($this->config[$this->kind]['file']) . '.txt');
     }
 }
示例#5
0
 /**
  * コンストラクタ
  * @param string $page ページ名
  */
 public function __construct($page = null)
 {
     if (empty($page)) {
         throw new Exception('BackupFile::__construct(): Page name is missing!');
     }
     if (!is_string($page)) {
         throw new Exception('BackupFile::__construct(): Page name must be string!');
     }
     global $do_backup, $cycle, $maxage;
     if (Auth::check_role('readonly') || !$do_backup) {
         return;
     }
     // バックアップのページ名
     $this->page = $page;
     // バックアップの拡張子
     if (function_exists('lzf_compress')) {
         // lzfが使用出来る場合
         $this->ext = '.lzf';
     } else {
         if (function_exists('bzcompress')) {
             // bz2が使用出来る場合
             $this->ext = '.bz2';
         } else {
             if (function_exists('gzcompress')) {
                 $this->ext = '.gz';
             }
         }
     }
     // バックアップの世代間の区切りの正規表現
     $this->splitter_reglex = '/^(' . preg_quote(self::SPLITTER) . '\\s\\d+(\\s(\\d+)|))$/';
     // バックアップの名前(拡張子抜き)
     $this->name = self::$dir . Utility::encode($page);
     // バックアップの最終更新日時
     $this->time = $this->has() ? filemtime($this->filename) : UTIME;
     // このhasBackup()でファイル名($this->file)も定義
     parent::__construct($this->name . $this->ext);
 }
示例#6
0
function encode($str)
{
    return Utility::encode($str);
}
示例#7
0
function plugin_edit_action()
{
    // global $vars, $_title_edit, $load_template_func;
    global $vars, $load_template_func, $_string, $_edit_msg;
    $page = isset($vars['page']) ? $vars['page'] : null;
    if (empty($page)) {
        return array('msg' => $_edit_msg['msg_edit'], 'body' => $_edit_msg['err_empty_page']);
    }
    $wiki = Factory::Wiki($page);
    if (!$wiki->isEditable(true)) {
        Utility::dieMessage($_string['err_empty_page'], 403);
    }
    // if (PKWK_READONLY) die_message(  sprintf($_string['error_prohibit'], 'PKWK_READONLY') );
    if (Auth::check_role('readonly')) {
        Utility::dieMessage($_string['error_prohibit'], 403);
    }
    if (PKWK_READONLY == Auth::ROLE_AUTH && Auth::get_role_level() > Auth::ROLE_AUTH) {
        Utility::dieMessage(sprintf($_string['error_prohibit'], 'PKWK_READONLY'), 403);
    }
    if (isset($vars['realview'])) {
        return plugin_edit_realview();
    }
    if (!$wiki->has() && Auth::is_check_role(PKWK_CREATE_PAGE)) {
        Utility::dieMessage(sprintf($_string['error_prohibit'], 'PKWK_CREATE_PAGE'), 403);
    }
    if (preg_match($wiki::INVALIED_PAGENAME_PATTERN, $page)) {
        Utility::dieMessage($_string['illegal_chars']);
    }
    if (isset($vars['preview']) || $load_template_func && isset($vars['template'])) {
        return plugin_edit_preview();
    } else {
        if (isset($vars['write'])) {
            return plugin_edit_write();
        } else {
            if (isset($vars['cancel'])) {
                return plugin_edit_cancel();
            }
        }
    }
    $postdata = $vars['original'] = $wiki->get(true);
    Auth::is_role_page($postdata);
    if (isset($vars['id']) && !empty($vars['id'])) {
        $source = $wiki->get();
        $postdata = plugin_edit_parts($vars['id'], $source);
        if ($postdata === FALSE) {
            unset($vars['id']);
            // なかったことに :)
            $postdata = $vars['original'];
        }
    }
    if (empty($postdata)) {
        // Check Page name length
        // http://pukiwiki.sourceforge.jp/dev/?PukiWiki%2F1.4%2F%A4%C1%A4%E7%A4%C3%A4%C8%CA%D8%CD%F8%A4%CB%2F%C4%B9%A4%B9%A4%AE%A4%EB%A5%DA%A1%BC%A5%B8%CC%BE%A4%CE%A5%DA%A1%BC%A5%B8%A4%CE%BF%B7%B5%AC%BA%EE%C0%AE%A4%F2%CD%DE%BB%DF
        $filename_max_length = 250;
        $filename = Utility::encode($page) . '.txt';
        $filename_length = strlen($filename);
        if ($filename_length > $filename_max_length) {
            // Filename too long
            return array('msg' => $_edit_msg['title_edit'], 'body' => join("\n", array('<p class="alert alert-warning"><span class="fa fa-exclamation-triangle"></span>' . $_edit_msg['err_long'], '</p>', '<dl class="dl-horizontal">', '<dt>Page name</dt>', '<dd>' . Utility::htmlsc($page) . '</dd>', '<dt>Filename</dt>', '<dd>' . $filename . '</dd>', '<dt>Filename length</dt>', '<dd>' . $filename_length . '</dd>', '<dt>Filename limit</dt>', '<dd>' . $filename_max_length . '</dd>', '</dl>')));
        } else {
            $postdata = $wiki->auto_template();
        }
    }
    return array('msg' => sprintf($_edit_msg['title_edit'], $page), 'body' => Utility::editForm($page, $postdata));
}
示例#8
0
 function make_login_link()
 {
     $query = array('app_key' => $this->app_key, 'perms' => self::LIVEDOOR_PERMS, 't' => UTIME, 'v' => self::LIVEDOOR_VERSION, 'userdata' => empty($this->callbackUrl) ? '' : Utility::encode($this->callbackUrl));
     $query['sig'] = $this->make_hash($query);
     return self::LIVEDOOR_URL_AUTH . http_build_query($query);
 }
示例#9
0
function attach_doupload($file, $page, $pass = NULL, $temp)
{
    global $_attach_messages, $_string;
    global $notify, $notify_subject, $notify_exclude, $spam;
    $filename = Utility::encode($page) . '_' . Utility::encode($file);
    $type = Utility::getMimeInfo($temp);
    $must_compress = PLUGIN_ATTACH_UNKNOWN_COMPRESS !== 0 ? attach_is_compress($type, PLUGIN_ATTACH_UNKNOWN_COMPRESS) : false;
    // 不明なファイルを圧縮するか?
    // ファイル名の長さをチェック
    $filename_length = strlen($filename);
    if ($filename_length >= 255 || $must_compress && $filename_length >= 251) {
        return array('result' => FALSE, 'msg' => $_attach_messages['err_filename']);
    }
    // スパムチェック
    if ($spam !== 0) {
        // ファイルの内容でスパムチェック
        // if attach spam, filtering attach file.
        $vars['uploadname'] = $file['name'];
        $vars['uploadtext'] = attach_gettext($file['tmp_name']);
        if ($vars['uploadtext'] === '' || $vars['uploadtext'] === FALSE) {
            return FALSE;
        }
        if (isset($spam['method']['attach'])) {
            $_method =& $spam['method']['attach'];
        } else {
            if (isset($spam['method']['_default'])) {
                $_method =& $spam['method']['_default'];
            } else {
                $_method = array();
            }
        }
        $exitmode = isset($spam['exitmode']) ? $spam['exitmode'] : '';
        Spam::pkwk_spamfilter('File Attach', $page, $vars, $_method, $exitmode);
    }
    if ($must_compress) {
        // 添付ファイルを圧縮する
        switch (PLUGIN_ATTACH_COMPRESS_TYPE) {
            case 'GZ':
                if (!extension_loaded('zlib')) {
                    Utility::dieMessage('#attach: zlib extention has not loaded.');
                }
                $obj = new AttachFile($page, $file . '.gz');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $tp = fopen($file['tmp_name'], 'rb') or die_message($_attach_messages['err_load_file']);
                $zp = gzopen($obj->filename, 'wb') or die_message($_attach_messages['err_write_tgz']);
                while (!feof($tp)) {
                    gzwrite($zp, fread($tp, 8192));
                }
                gzclose($zp);
                fclose($tp);
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            case 'ZIP':
                if (!class_exists('ZipArchive')) {
                    Utility::dieMessage('#attach: ZipArchive class has not defined.');
                }
                $obj = new AttachFile($page, $file . '.zip');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $zip = new ZipArchive();
                $zip->addFile($temp, $file);
                // if ($zip->status !== ZIPARCHIVE::ER_OK)
                if ($zip->status !== 0) {
                    die_message($_attach_messages['err_upload'] . '(' . $zip->status . ').');
                }
                $zip->close();
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            case 'BZ2':
                if (!extension_loaded('bz2')) {
                    Utility::dieMessage('#attach: bz2 extention has not loaded.');
                }
                $obj = new AttachFile($page, $file . '.bz2');
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                $tp = fopen($file['tmp_name'], 'rb') or die_message($_attach_messages['err_load_file']);
                $zp = bzopen($obj->filename, 'wb') or die_message($_attach_messages['err_write_tgz']);
                while (!feof($tp)) {
                    bzwrite($zp, fread($tp, 8192));
                }
                bzclose($zp);
                fclose($tp);
                chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                break;
            default:
                //miko
                $obj = new AttachFile($page, $file);
                if ($obj->exist) {
                    return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
                }
                if (move_uploaded_file($temp, $obj->filename)) {
                    chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
                }
                break;
        }
    } else {
        // 通常添付
        $obj = new AttachFile($page, $file);
        if (isset($obj->exist)) {
            return array('result' => FALSE, 'msg' => $_attach_messages['err_exists']);
        }
        if (move_uploaded_file($temp, $obj->filename)) {
            chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
        }
    }
    if (file_exists($temp)) {
        unlink($temp);
    }
    // ページのタイムスタンプを更新
    Factory::Wiki($page)->touch();
    $obj->status['pass'] = $pass !== TRUE && $pass !== NULL ? md5($pass) : '';
    if ($notify) {
        $notify_exec = TRUE;
        foreach ($notify_exclude as $exclude) {
            $exclude = preg_quote($exclude);
            if (substr($exclude, -1) == '.') {
                $exclude .= '*';
            }
            if (preg_match('/^' . $exclude . '/', get_remoteip())) {
                $notify_exec = FALSE;
                break;
            }
        }
        $footer['ACTION'] = 'File attached';
        $footer['FILENAME'] = $file['name'];
        $footer['FILESIZE'] = $file['size'];
        $footer['PAGE'] = $page;
        $footer['URI'] = get_cmd_uri('attach', '', array('refer' => $page, 'pcmd' => 'info', 'file' => $file['name']));
        $footer['USER_AGENT'] = TRUE;
        $footer['REMOTE_ADDR'] = TRUE;
        pkwk_mail_notify($notify_subject, "\n", $footer);
    }
    return array('result' => TRUE, 'msg' => $_attach_messages['msg_uploaded']);
}
示例#10
0
 /**
  * リネームする
  * @param string $to
  */
 public function rename($to)
 {
     if ($this->status['freeze']) {
         return attach_info('msg_isfreeze');
     }
     if (Auth::check_role('role_contents_admin') && !Auth::login($pass)) {
         return attach_info('err_adminpass');
     }
     // 基点名(エンコードされたページ名+_)
     $basename = AttachFile::$dir . Utility::encode($this->page) . '_';
     // 新しいファイル名
     $newname = Utility::encode($to);
     if (file_exists($basename . $newname)) {
         // ファイルが存在する場合
         return false;
     }
     $rename_targets = array();
     foreach (AttachFile::exists() as $file) {
         if (!preg_match('/^(' . preg_quote(Utility::encode($this->filename)) . ')(\\.((\\d+)|(log)))$/', $file, $matches)) {
             continue;
         }
         // 0 …ファイル名全体 1…ファイル名 2…拡張子
         rename($basename . $matches[0], $basename . $newname . $matches[2]);
     }
     AttachFile::clearCache();
     return true;
 }
示例#11
0
function plugin_popular_getlist($view, $max = PLUGIN_POPULAR_DEFAULT, $except)
{
    static $localtime;
    if (!isset($localtime)) {
        list($zone, $zonetime) = Time::setTimeZone(DEFAULT_LANG);
        $localtime = UTIME + $zonetime;
    }
    $today = gmdate('Y/m/d', $localtime);
    // $yesterday = gmdate('Y/m/d', strtotime('yesterday', $localtime));
    $yesterday = gmdate('Y/m/d', gmmktime(0, 0, 0, gmdate('m', $localtime), gmdate('d', $localtime) - 1, gmdate('Y', $localtime)));
    $counters = array();
    foreach (Listing::pages() as $page) {
        if (!empty($except) && preg_match("/" . $except . "/", $page)) {
            continue;
        }
        $wiki = Factory::Wiki($page);
        if (!$wiki->isReadable() || $wiki->isHidden() || !$wiki->isValied()) {
            continue;
        }
        //$count_file = COUNTER_DIR . str_replace('.txt','.count', $file);
        $count_file = COUNTER_DIR . Utility::encode($page) . '.count';
        if (file_exists($count_file)) {
            $array = file($count_file);
            $count = rtrim($array[0]);
            $date = rtrim($array[1]);
            $today_count = rtrim($array[2]);
            $yesterday_count = rtrim($array[3]);
            $counters['_' . $page] = 0;
            if ($view == 'today' or $view == 'recent') {
                // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
                // array_splice()によってキー値が変更されてしまうのを防ぐ
                // ため、キーに '_' を連結する
                if ($today == $date) {
                    $counters['_' . $page] = $today_count;
                }
            }
            if ($view == 'yesterday' or $view == 'recent') {
                if ($today == $date) {
                    $counters['_' . $page] += $yesterday_count;
                } elseif ($yesterday == $date) {
                    $counters['_' . $page] += $today_count;
                }
            }
            if ($view == 'total') {
                $counters['_' . $page] = $count;
            }
            if ($counters['_' . $page] == 0) {
                unset($counters['_' . $page]);
            }
        }
    }
    asort($counters, SORT_NUMERIC);
    // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
    $counters = array_reverse($counters, TRUE);
    // with array_splice()
    if ($max && $max != 0) {
        $counters = array_splice($counters, '0', $max);
    }
    return $counters;
}
示例#12
0
 /**
  * セッションを設定
  * @return void
  */
 public function setSession()
 {
     global $session;
     $value = '';
     foreach (array_merge(array('api', 'ts'), $this->field_name) as $key) {
         $value .= empty($value) ? '' : '::';
         // delm
         $value .= $key . '$$';
         switch ($key) {
             case 'api':
                 $value .= $this->auth_name;
                 break;
             case 'ts':
                 $value .= UTIME;
                 break;
             default:
                 $value .= Utility::encode($this->response[$key]);
         }
     }
     // 復号化
     $session->offsetSet($this->session_name, $this->bc->encrypt($value));
     // OpenID認証の場合のみ
     if ($this->auth_name != 'openid_verify') {
         LogFactory::factory('login')->set();
     }
 }