/** * package serverを立ち上げる * * @param string $package_root パッケージ名 */ public static function handler($package_root = null) { if (empty($package_root) || Rhaco::path() == "") { $debug = debug_backtrace(); $first_action = array_pop($debug); if ($package_root === null) { $package_root = basename(dirname($first_action["file"])); } if (Rhaco::path() == "") { Rhaco::init($first_action["file"]); } } $base_dir = Rhaco::path(); $request = new Request(); $package_root_path = str_replace(".", "/", $package_root); $preg_quote = (empty($package_root_path) ? "" : preg_quote($package_root_path, "/") . "\\/") . "(.+)"; $tag = new Tag("rest"); if (preg_match("/^\\/state\\/" . $preg_quote . "\$/", $request->args(), $match)) { $tag->add(new Tag("package", $match[1])); if (self::parse_package($package_root_path, $base_dir, $match[1], $tgz_filename)) { $tag->add(new Tag("status", "success")); $tag->output(); } } else { if (preg_match("/^\\/download\\/" . $preg_quote . "\$/", $request->args(), $match)) { if (self::parse_package($package_root_path, $base_dir, $match[1], $tgz_filename)) { Http::attach(new File($tgz_filename)); } } } Http::status_header(403); $tag->add(new Tag("status", "fail")); $tag->output(); exit; }
public static function __import__() { self::$BASE_PATH = Rhaco::def("core.Template@path", Rhaco::path("templates")); self::$BASE_URL = Rhaco::def("core.Template@url", Rhaco::url("templates")); self::$CACHE = Rhaco::def("core.Template@cache", false); self::$CACHE_TIME = Rhaco::def("core.Template@time", 86400); }
/** * install serverを立ち上げる * * @param string $package_root パッケージ名 */ public static function handler() { $base_dir = Rhaco::path(); $request = new Request(); $tag = new Tag("rest"); if (preg_match("/^\\/state\\/(.+)\$/", $request->args(), $match)) { $tag->add(new Tag("package", $match[1])); if (self::parse_package($base_dir, $match[1], $tgz_filename)) { $tag->add(new Tag("status", "success")); $tag->output(); } } else { if (preg_match("/^\\/download\\/(.+)\$/", $request->args(), $match)) { if (self::parse_package($base_dir, $match[1], $tgz_filename)) { Http::attach(new File($tgz_filename)); } } } Http::status_header(403); $tag->add(new Tag("status", "fail")); $tag->output(); exit; }
private function search_model() { $models = array(); foreach (File::ls(Rhaco::path(), true) as $file) { if ($file->isClass()) { ob_start(); include_once $file->fullname(); ob_end_clean(); if (is_implements_of($file->oname(), "Model")) { $models[] = $file; } } } return $models; }
/** * アプリケーションのファイルパスを取得する * * @param string $path * @return string */ function path($path = null) { return Rhaco::path($path); }
function upload() { if ($this->isPost() && $this->isFile('stage')) { $file = $this->getFile('stage'); $src = mb_convert_encoding(file_get_contents($file->tmp), 'utf-8', 'Shift_JIS,EUC-JP,UTF-8'); if (SimpleTag::setof($tag, $src, 'body', true)) { foreach ($tag->getIn('applet') as $applet) { if ($applet->getParameter('code') != 'MasaoConstruction') { continue; } $gamedata = array(); foreach ($applet->getIn('param') as $param) { $gamedata[$param->getParameter('name')] = array('name' => $param->getParameter('name'), 'value' => $param->getParameter('value')); } if (empty($gamedata)) { break; } $stage = $this->dbUtil->insert($this->toObject(new Stage())); if (!Variable::istype('Stage', $stage)) { break; } $_images = array('title', 'ending', 'gameover', 'pattern', 'chizu'); foreach ($_images as $k) { if (!isset($gamedata[sprintf("filename_%s", $k)])) { continue; } $gamedata[sprintf("filename_%s", $k)] = array('name' => sprintf("filename_%s", $k), 'value' => 'images/' . $k . '.gif'); if ($this->isFile('img_' . $k)) { $image = $this->getFile('img_' . $k); $img_info = getimagesize($image->tmp); if ($img_info[2] != IMAGETYPE_GIF) { continue; } $filename = Rhaco::path(sprintf('images/%s_%d.gif', $k, $stage->id)); if (move_uploaded_file($image->tmp, $filename)) { $gamedata[sprintf("filename_%s", $k)] = array('name' => sprintf("filename_%s", $k), 'value' => sprintf("images/%s_%d.gif", $k, $stage->getId())); } } } FileUtil::write(Rhaco::path(sprintf('stages/%d.apif', $stage->id)), serialize($gamedata)); Header::redirect(Rhaco::url()); Rhaco::end(); } } } return $this->parser('upload.html'); }