problem = $problem; $this->data_zip = new ZipArchive; $ret = $this->data_zip->open($this->problem->getDataZipPath(), ZipArchive::RDONLY); if ($ret !== true) { UOJLog::error('zip open failed: ', $this->problem->getDataZipPath(), $ret); } $this->data_zip_root = $this->problem->info['id'] . '/'; $this->finfo = new finfo(FILEINFO_MIME_ENCODING); for ($i = 0; $i < $this->data_zip->count(); $i++) { $name = $this->data_zip->getNameIndex($i); if (strStartWith($name, $this->data_zip_root) && !strEndWith($name, '/')) { $this->rest_data_files[substr($name, strlen($this->data_zip_root))] = true; } } } public function setProblemConf(array $problem_conf) { foreach ($problem_conf as $key => $val) { $this->problem_conf[$key] = ['val' => $val]; } } public function setProblemConfRowStatus($key, $status) { $this->problem_conf[$key]['status'] = $status; return $this; } public function addTab($file_name, $fun) { $this->tabs[$file_name] = $fun; return $this; } public function echoAllTabs($active_tab) { $rest = array_keys($this->rest_data_files); natsort($rest); foreach (array_merge(array_keys($this->tabs), $rest) as $tab) { if ($tab !== $active_tab) { echo ''; } } public function echoFileNotFound($file_name) { echo '

', HTML::escape($file_name), ' ', '文件未找到', '

'; } public function echoFilePre($file_name, $max_len = 1000) { $content = $this->getFile($file_name, $max_len + 4); if ($content === false) { $this->echoFileNotFound($file_name); return; } $mimetype = $this->finfo->buffer($content); if ($mimetype === false) { $this->echoFileNotFound($file_name); return; } echo '
', HTML::escape($file_name), '
'; echo '
', $mimetype, '
'; echo '
', "\n";
		$type = $mimetype == 'binary' ? 'binary' : 'text';
		echo HTML::escape(uojStringPreview($content, $max_len, $type));
		echo "\n
"; } public function echoProblemConfTable() { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($this->problem_conf as $key => $info) { $val = isset($info['val']) ? $info['val'] : ''; if (!isset($info['status'])) { echo ''; echo ''; echo ''; echo ''; } elseif ($info['status'] == 'danger') { echo ''; echo ''; echo ''; echo ''; } } echo ''; echo '
problem.conf
keyvalue
', HTML::escape($key), '', HTML::escape($val), '
', HTML::escape($key), '', HTML::escape($val), ' ', '
'; } public function displayFile($file_name) { if ($file_name === null) { $this->echoFileNotFound(''); } if (isset($this->tabs[$file_name])) { ($this->tabs[$file_name])($this); } elseif (isset($this->rest_data_files[$file_name])) { $this->echoFilePre($file_name); } else { $this->echoFileNotFound($file_name); } } public function isFile($name) { return $this->data_zip->statName($this->data_zip_root . $name); } public function getFile($name, $max_len = 0) { return $this->data_zip->getFromName($this->data_zip_root . $name, $max_len); } }