/** * libraryをimportする * 必要であればダウンロードを試みる * * @param string $package_path */ public static function import($package_path, $package_server = null) { if ($package_server !== null) { $package_server = self::add($package_server); } $expand_path = self::$PATH . str_replace(".", "/", $package_path); try { return self::import_include($expand_path, $package_path); } catch (Exception $e) { $uri = str_replace(".", "/", $package_path); $tgz = File::absolute(self::$PATH, str_replace(".", "_", $package_path) . ".tgz"); $http = new Http(); if ($package_server !== null) { if (null !== ($result = self::read_server($http, $package_server, $uri, $tgz, $package_path, $expand_path))) { return $result; } } else { foreach (self::$IMPORT_URLS as $server) { if (null !== ($result = self::read_server($http, $server, $uri, $tgz, $package_path, $expand_path))) { return $result; } } } } throw new Exception($package_path . " not found"); }
private static function parse_package($package_root_path, $base_dir, $package, &$tgz_filename) { $tgz_filename = File::absolute(self::$tgz_dir, str_replace("/", "_", $package) . ".tgz"); if (is_file($tgz_filename)) { return true; } $package_name = basename($base_dir); $search_path = File::absolute($base_dir, preg_replace("/^" . $package_name . "\\//", "", $package)); $base_name = basename($search_path); if (is_file($search_path . ".php")) { $isdir = is_dir($search_path); $tar = File::pack($base_dir, $search_path . ".php", $package_root_path, !$isdir); if ($isdir) { $tar .= File::pack($base_dir, $search_path, $package_root_path); } else { $parent_dir = basename(dirname($search_path)); $parent_search = dirname(dirname($search_path)) . "/" . $parent_dir . ".php"; if (is_file($parent_search)) { $tar .= File::pack($base_dir, $parent_search, $package_root_path); } } File::gzwrite($tgz_filename, $tar); return true; } else { if (is_file($search_path . "/" . $base_name . ".php")) { File::tgz($tgz_filename, $base_dir, $search_path, $package_root_path); return true; } } return false; }
/** * URLからフィードを取得 * * @param string $url * @return Atom */ public function do_read($url) { $urls = func_get_args(); $feed = null; if (!self::$CACHE || File::isExpiry($urls, self::$CACHE_TIME)) { foreach ($urls as $url) { if (is_string($url) && ($url = trim($url)) && !empty($url)) { if (!self::$CACHE || File::isExpiry($url, self::$CACHE_TIME)) { $src = Tag::xhtmlnize($this->do_get($url)->body(), "link"); if (Tag::setof($tag, $src, "head")) { foreach ($tag->in("link") as $link) { if ("alternate" == strtolower($link->inParam("rel")) && strpos(strtolower($link->inParam("type")), "application") === 0 && $url != ($link = File::absolute($url, $link->inParam("href")))) { $src = $this->do_get($link)->body(); break; } } } $tmp = self::parse($src); if (self::$CACHE) { File::cwrite($url, $tmp); } } else { $tmp = File::cread($url); } if ($feed === null) { if ($this->title !== null) { $tmp->title($this->title()); } if ($this->subtitle !== null) { $tmp->subtitle($this->subtitle()); } if ($this->id !== null) { $tmp->id($this->id()); } if ($this->generator !== null) { $tmp->generator($this->generator()); } if ($this->updated !== null) { $tmp->updated($this->updated()); } $feed = $tmp; } else { $feed->add($tmp); } } } if (!$feed instanceof Atom) { $feed = new Atom(); } $feed->sort(); if (self::$CACHE) { File::cwrite($urls, $feed); } } else { $feed = File::cread($urls); } return $feed; }
function diff($path, $revA, $revB) { $url = File::absolute($this->url, $path); $result = Command::out(sprintf("%s diff -r %d:%d %s", $this->cmd, $revA, $revB, $url)); if (empty($result)) { throw new Exception("undef"); } return preg_replace("/^\\+{3} .+\n/", "", preg_replace("/^-{3} .+\n/", "", trim(preg_replace("/^.+={60,70}\n(.+)\$/ms", "\\1", str_replace(array("\r\n", "\r"), "\n", $result))))); }
public function create() { try { Subversion::cmd('import', array(OpenpearConfig::svn_skeleton(work_path('skeleton')), File::absolute(OpenpearConfig::svn_root(), $this->package()->name())), array('message' => sprintf('[New Package] %s (@%s)', $this->package()->name(), $this->maintainer()->name()), 'username' => OpenpearConfig::system_user('openpear'))); // $message = new OpenpearMessage(); // $message->subject('New Package is ready for your commit!'); $this->delete(); C($this)->commit(); } catch (Exception $e) { Log::error($e->getMessage()); $this->trial_count += 1; $this->save(); C($this)->commit(); } }
public function download($save_dir, $save_filename, $ext = true) { $b = new Http(); $b->do_get($this->url() . "&fmt=22"); if (preg_match("/var[\\s]+swfArgs[\\s]*=[\\s]*(\\{.+?\\})/m", $b->body(), $match)) { $json = Text::parse_json($match[1]); $base_url = "http://www.youtube.com/get_video?video_id=" . $json["video_id"] . "&t=" . $json["t"]; $url = $base_url . "&fmt=22"; if ($b->do_head($url)->status() !== 200) { $url = $base_url . "&fmt=18"; } $b->do_download($url, File::absolute($save_dir, $save_filename) . ($ext ? $this->ext : "")); return; } throw new Exception("undef video"); }
public function check_repo_exists() { $this->login_required(); try { $package = OpenpearPackage::get_package($this->in_vars('package_id')); $info = Subversion::cmd('info', array(File::absolute(OpenpearConfig::svn_root(), implode('/', array($package->name(), 'trunk', $this->in_vars('dir', '')))))); if (isset($info['kind']) && $info['kind'] == 'dir') { echo 'ok'; } else { throw new RuntimeException('directory is not found'); } } catch (Exception $e) { Log::debug($e); echo 'ng'; } exit; }
public function download($save_dir, $save_filename, $ext = true) { $b = new Http(); if (!empty($this->original_image_url)) { $b->do_download($this->original_image_url, File::absolute($save_dir, $save_filename) . ($ext ? ".jpg" : "")); return; } else { $b->do_get($this->url); if (Tag::setof($tag, $b->body(), "body")) { foreach ($tag->in("script") as $s) { if (preg_match("/addVariable\\('url', '(.+?)'\\)/", $s->value(), $match)) { $b->do_download(trim($match[1]), File::absolute($save_dir, $save_filename) . ($ext ? ".flv" : "")); return; } } } } throw new Exception("undef video"); }
private static function parse_package($base_dir, $name, &$tgz_filename) { $tgz_filename = File::absolute(self::$tgz_dir, $name . ".tgz"); if (is_file($tgz_filename)) { return true; } $search_path = File::absolute($base_dir, $name); if (is_dir($search_path)) { $ignore = array("__\\w+__\\.php\$", "^work/", "^work\$"); File::tgz($tgz_filename, $search_path, $search_path, null, $ignore); return true; } else { if (is_file($search_path . ".php")) { File::tgz($tgz_filename, $base_dir, $search_path . ".php"); return true; } } return false; }
/** * libraryをimportする * 必要であればダウンロードを試みる * * @param string $package_path */ public static function install($name, $install_server = null) { if ($install_server !== null) { $install_server = self::add($install_server); } $tgz = File::absolute(self::$PATH, str_replace(".", "_", $name) . ".tgz"); $http = new Http(); if ($install_server !== null) { if (self::read_server($http, $install_server, $name, $tgz, $name)) { return; } } else { foreach (self::$INST_URLS as $server) { if (self::read_server($http, $server, $name, $tgz, $name)) { return; } } } throw new Exception($name . " not found"); }
<?php /** * 更新を監視してmxmlcする */ include_once dirname(__FILE__) . "/__settings__.php"; import("core.Command"); import("core.File"); import("core.Request"); $req = new Request(); $cmd = new Command(); $cmd->open(File::absolute(def("mxmlc@flex_bin"), "fcsh"), null, work_path("mxmlc_error")); $src = new File(path("flex/src/" . $req->inVars("f", "index.mxml"))); $bin = path("flex/bin/" . $src->oname() . ".swf"); $lib = path("flex/lib/"); $rsl = path("flex/rsl/"); while (true) { $lib_last_update = $src_last_update = $rsl_last_update = $id = 0; $mxmlc = sprintf("mxmlc -output %s --file-specs %s ", $bin, $src); if ($lib_last_update < ($lib_update = File::last_update($lib, true))) { $lib_last_update = $lib_update; $files = array(); foreach (File::ls($lib) as $f) { $files[] = $f->fullname(); } $mxmlc .= "-library-path+=" . implode(",", $files) . " "; } if ($rsl_last_update < ($rsl_update = File::last_update($rsl, true))) { $rsl_last_update = $rsl; $files = array(); foreach (File::ls($rsl) as $f) {
/** * メディアの絶対パスを返す * @param string $url ベースのURLに続く相対パス * @return string */ public function media($url = null) { return $this->flow instanceof Flow ? File::absolute($this->flow->media_url(), $url) : null; }
public final function srcpath_link(OpenpearPackage $package, $path) { $ret = ''; $parent = ''; foreach (explode('/', $path) as $p) { $link = File::absolute(url(sprintf('package/%s/src/%s', $package->name())), implode('/', array($parent, $p))); $ret .= sprintf('<a href="%s">%s</a>', $link, $p); $parent .= $p; } return $ret; }
private function request($url, $method, array $header = array(), array $vars = array(), $download_path = null, $status_redirect = true) { Log::debug($url); $result = (object) array("url" => $url, "status" => 200, "head" => null, "redirect" => null, "body" => null, "encode" => null, "cmd" => null); $h = array_change_key_case($header, CASE_LOWER); $raw = null; $content_type = isset($h["content-type"]) ? $h["content-type"] : "application/x-www-form-urlencoded"; $user_agent = isset($h["user-agent"]) ? $h["user-agent"] : (empty($this->agent) ? isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "" : $this->agent); $accept = isset($h["accept"]) ? $h["accept"] : (isset($_SERVER["HTTP_ACCEPT"]) ? $_SERVER["HTTP_ACCEPT"] : ""); $accept_language = isset($h["accept-language"]) ? $h["accept-language"] : (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) ? $_SERVER["HTTP_ACCEPT_LANGUAGE"] : ""); $accept_charset = isset($h["accept-charset"]) ? $h["accept-charset"] : (isset($_SERVER["HTTP_ACCEPT_CHARSET"]) ? $_SERVER["HTTP_ACCEPT_CHARSET"] : ""); unset($h["content-type"], $h["user-agent"], $h["accept"], $h["accept-language"], $h["accept-charset"]); if (isset($h["rawdata"])) { $raw = $h["rawdata"]; unset($h["rawdata"]); } else { if (!empty($vars)) { if (strtoupper($method) == "GET") { $url = strpos($url, "?") === false ? $url . "?" : $url . "&"; $url .= self::query($vars, null, true, $this->query_array); if (substr($url, -1) === "&") { $url = substr($url, 0, -1); } } else { $query_vars = array(array(), array()); foreach (self::expand_vars($tmp, $vars, null, false) as $v) { $query_vars[is_string($v[1]) ? 0 : 1][] = $v; } if (empty($query_vars[1])) { $raw = self::query($vars, null, true, $this->query_array); if (substr($raw, -1) === "&") { $raw = substr($raw, 0, -1); } } else { $boundary = "-----------------" . md5(microtime()); $content_type = "multipart/form-data; boundary=" . $boundary; $raws = array(); foreach ($query_vars[0] as $v) { $raws[] = sprintf('Content-Disposition: form-data; name="%s"', $v[0]) . "\r\n\r\n" . $v[1] . "\r\n"; } foreach ($query_vars[1] as $v) { $raws[] = sprintf('Content-Disposition: form-data; name="%s"; filename="%s"', $v[0], $v[1]->name()) . "\r\n" . sprintf('Content-Type: %s', $v[1]->mime()) . "\r\n" . sprintf('Content-Transfer-Encoding: %s', "binary") . "\r\n\r\n" . $v[1]->get() . "\r\n"; } $raw = "--" . $boundary . "\r\n" . implode("--" . $boundary . "\r\n", $raws) . "\r\n--" . $boundary . "--\r\n" . "\r\n"; } } } } $ulist = parse_url(preg_match("/^([\\w]+:\\/\\/)(.+?):(.+)(@.+)\$/", $url, $m) ? $m[1] . urlencode($m[2]) . ":" . urlencode($m[3]) . $m[4] : $url); $ssl = isset($ulist["scheme"]) && ($ulist["scheme"] == "ssl" || $ulist["scheme"] == "https"); try { $fp = fsockopen(($ssl ? "ssl://" : "") . $ulist["host"], !isset($ulist["port"]) ? $ssl ? 443 : 80 : $ulist["port"], $errorno, $errormsg, $this->timeout); } catch (Exception $e) { throw new InvalidArgumentException("connection fail " . $url); } if ($fp == false || false == stream_set_blocking($fp, 1) || false == stream_set_timeout($fp, $this->timeout)) { throw new InvalidArgumentException("connection fail [" . $url . "] " . $errormsg . " " . $errorno); } $cmd = sprintf("%s %s%s HTTP/1.1\r\n", $method, !isset($ulist["path"]) ? "/" : $ulist["path"], isset($ulist["query"]) ? sprintf("?%s", $ulist["query"]) : "") . sprintf("Host: %s\r\n", $ulist["host"]) . (empty($user_agent) ? "" : sprintf("User-Agent: %s\r\n", $user_agent)) . (empty($accept) ? "" : sprintf("Accept: %s\r\n", $accept)) . (empty($accept_language) ? "" : sprintf("Accept-Language: %s\r\n", $accept_language)) . (empty($accept_charset) ? "" : sprintf("Accept-Charset: %s\r\n", $accept_charset)) . sprintf("Content-Type: %s\r\n", $content_type) . sprintf("Connection: Close\r\n") . (isset($ulist["user"]) && isset($ulist["pass"]) ? sprintf("Authorization: Basic %s\r\n", base64_encode(sprintf("%s:%s", urldecode($ulist["user"]), urldecode($ulist["pass"])))) : ""); foreach ($h as $key => $value) { $cmd .= sprintf("%s: %s\r\n", $key, $value); } if (!empty($raw)) { $cmd .= "Content-length: " . strlen($raw) . "\r\n\r\n" . $raw; } fwrite($fp, $result->cmd = $cmd . "\r\n"); stream_set_timeout($fp, $this->timeout); while (!feof($fp) && !preg_match("/\r\n\r\n\$/", $result->head)) { $result->head .= fgets($fp, 4096); } $result->status = preg_match("/HTTP\\/.+[ ](\\d\\d\\d)/i", $result->head, $httpCode) ? intval($httpCode[1]) : 0; $result->encode = preg_match("/Content-Type.+charset[\\s]*=[\\s]*([\\-\\w]+)/", $result->head, $match) ? trim($match[1]) : null; $result->url = $url; switch ($result->status) { case 300: case 301: case 302: case 303: case 307: if (preg_match("/Location:[ ](.*)/i", $result->head, $redirect_url)) { $result->redirect = preg_replace("/[\r\n]/", "", File::absolute($url, $redirect_url[1])); if ($status_redirect) { fclose($fp); if ($method === "GET") { $vars = array(); } return $this->request($result->redirect, "GET", $h, $vars, $download_path, $status_redirect); } } } $download_handle = $download_path !== null && File::mkdir(dirname($download_path)) === null ? fopen($download_path, "wb") : null; if (preg_match("/^Content\\-Length:[\\s]+([0-9]+)\r\n/i", $result->head, $m)) { if (0 < ($length = $m[1])) { $rest = $length % 4096; $count = ($length - $rest) / 4096; while (!feof($fp)) { if ($count-- > 0) { self::write_body($result, $download_handle, fread($fp, 4096)); } else { self::write_body($result, $download_handle, fread($fp, $rest)); break; } } } } else { if (preg_match("/Transfer\\-Encoding:[\\s]+chunked/i", $result->head)) { while (!feof($fp)) { $size = hexdec(trim(fgets($fp, 4096))); $buffer = ""; while ($size > 0 && strlen($buffer) < $size) { $value = fgets($fp, $size); if ($value === feof($fp)) { break; } $buffer .= $value; } self::write_body($result, $download_handle, substr($buffer, 0, $size)); } } else { while (!feof($fp)) { self::write_body($result, $download_handle, fread($fp, 4096)); } } } fclose($fp); if ($download_handle !== null) { fclose($download_handle); } return $result; }
/** * Storeから削除する * @param string $key キー名 * @return boolean */ public static function delete($key = null) { $id = self::id($key); if (Object::C(__CLASS__)->has_module("store_delete")) { return Object::C(__CLASS__)->call_module("store_delete", $id); } return self::rm(File::absolute(App::work("store"), $id)); }
/** * アプリケーションの説明 * @param string $path アプリケーションXMLのファイルパス * @return string{} "title"=>"..","summary"=>"..","description"=>"..","installation"=>".." */ public static function info($path = null) { $name = $summary = $description = $installation = ''; if (empty($path)) { $path = self::path(); } $app = empty(self::$branch) ? 'index' : self::$branch; $filename = is_file(File::absolute($path, $app . '.php')) ? File::absolute($path, $app . '.php') : (is_file(File::absolute($path, basename($path) . '.php')) ? File::absolute($path, basename($path) . '.php') : null); if (is_file($filename)) { $name = basename(dirname($filename)); $src = File::read($filename); if (Tag::setof($t, $src, 'app')) { $summary = $t->in_param('summary'); $name = $t->in_param('name', $t->in_param('label', $name)); $description = $t->f('description.value()'); $installation = $t->f('installation.value()'); } else { if (preg_match("/\\/" . "\\*\\*(.+?)\\*\\//ms", $src, $match)) { $description = trim(preg_replace("/^[\\s]*\\*[\\s]{0,1}/m", "", str_replace(array("/" . "**", "*" . "/"), "", $match[0]))); if (preg_match("/@name[\\s]+(.+)/", $description, $match)) { $description = str_replace($match[0], "", $description); $name = trim($match[1]); } if (preg_match("/@summary[\\s]+(.+)/", $description, $match)) { $description = str_replace($match[0], "", $description); $summary = trim($match[1]); } } } } return array('name' => $name, 'summary' => $summary, 'description' => $description, 'installation' => $installation, 'filename' => $filename); }
/** * ????? * @const string $svn_url リポジトリのURL */ public function source_browse($package_name, $path = '') { if (empty($path)) { $this->redirect_method('source_browse', $package_name, '/trunk'); } // TODO 仕様の確認 // TODO SVNとの連携 $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name)); $path = rtrim(ltrim($path, ' /.'), '/'); $local_root = File::absolute(OpenpearConfig::svn_root(), $package->name()); $repo_path = File::absolute($local_root, $path); $info = Subversion::cmd('info', array($repo_path)); if ($info['kind'] === 'dir') { $this->vars('tree', self::format_tree(Subversion::cmd('list', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD'))))); } else { if ($info['kind'] === 'file') { $this->put_block('package/source_viewfile.html'); $p = explode('.', $info['path']); $ext = array_pop($p); if (in_array($ext, $this->allowed_ext)) { $source = Subversion::cmd('cat', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD'))); $this->vars('code', $source); try { $cache_key = array('syntax_highlight', md5($source)); if (Store::has($cache_key)) { $this->vars('code', Store::get($cache_key)); } else { include_once 'geshi/geshi.php'; $geshi = new Geshi($source, $ext); $code = $geshi->parse_code(); Store::set($cache_key, $code); $this->vars('code', $code); } $this->vars('geshi', true); } catch (Exception $e) { Log::debug($e); $this->vars('geshi', false); } } } else { $this->redirect_by_map('package', $package_name); } } $this->vars('path', $path); $this->vars('info', self::format_info($info)); $this->vars('package', $package); $this->vars('real_url', File::absolute(OpenpearConfig::svn_url(), implode('/', array($package->name(), $path)))); $this->vars('externals', Subversion::cmd('propget', array('svn:externals', $info['url']))); $this->add_vars_other_tree($package_name); }
private function build_dir($path = '') { return File::absolute($this->working_dir, $path); }
private final function parseUrl($src, $base) { if (substr($base, -1) !== "/") { $base = $base . "/"; } if (preg_match_all("/<[^<]+?[\\s](href|src|action)[\\s]*=[\\s]*([\"\\'])([^\\2]+?)\\2[^>]*?>/msi", $src, $match)) { foreach ($match[1] as $key => $param) { if (!preg_match("/(^javascript:)|(^mailto:)|(^[\\w]+:\\/\\/)|(^[#\\?])|(^PHP_TAG_START)|(^\\{\\\$)/", $match[3][$key])) { $src = str_replace($match[0][$key], str_replace($match[3][$key], File::absolute($base, $match[3][$key]), $match[0][$key]), $src); } } } return $src; }
/** * テンポラリファイルを保存するパスを返す * @param string $path テンポラリからの相対ファイルパス * @return string */ public static function tmp_path($path = null) { return File::absolute(App::work("test_tmp"), $path); }
/** * クラスファイルからgettext文字列を抜き出してpotファイルを作成する * @param string $path * @param string $lc_messages_path */ public static function po_generate($path, $lc_messages_path) { $messages = array(); foreach (File::ls($path, true) as $file) { if ($file->isClass()) { ob_start(); include_once $file->fullname(); Rhaco::import($file->oname()); ob_get_clean(); $ref = Info::reflection($file->oname()); foreach ($ref->methods as $method) { foreach ($method->gettext as $text) { $messages[$text->str]["#: " . str_replace($path, "", $file->fullname()) . ":" . $text->line] = true; } } } } ksort($messages, SORT_STRING); $output_src = sprintf(Text::plain(' # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE\'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\\n" "Report-Msgid-Bugs-To: \\n" "POT-Creation-Date: %s\\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" "Language-Team: LANGUAGE <*****@*****.**>\\n" '), date("Y-m-d H:iO")) . "\n\n"; foreach ($messages as $str => $lines) { $output_src .= "\n" . implode("\n", array_keys($lines)) . "\n"; $output_src .= "msgid \"" . $str . "\"\n"; $output_src .= "msgstr \"\"\n"; } File::write(File::absolute($lc_messages_path, "messages.pot"), $output_src); //Rhaco::import("ext.Setup"); //Setup::po_generate(dirname(__FILE__),Rhaco::selfpath()."/resources/locale/"); //Setup::mo_generate(Rhaco::selfpath()."/resources/locale/"); //Test::each_flush(); }
protected function __new__() { if (func_num_args() > 0) { foreach (Text::dict(func_get_arg(0)) as $n => $v) { switch ($n) { case "_scope_": case "_inc_session_": case "_init_": $this->{$n} = $v; } } } if (isset($_GET) && is_array($_GET)) { foreach ($_GET as $key => $value) { $this->vars[$key] = $this->mq_off($value); } } if (isset($_POST) && is_array($_POST)) { foreach ($_POST as $key => $value) { $this->vars[$key] = $this->mq_off($value); } } if (empty($this->vars) && isset($_SERVER['argv'])) { $argv = $_SERVER['argv']; array_shift($argv); if (isset($argv[0]) && $argv[0][0] != '-') { $this->args = implode(' ', $argv); } else { $size = sizeof($argv); for ($i = 0; $i < $size; $i++) { if ($argv[$i][0] == '-') { if (isset($argv[$i + 1]) && $argv[$i + 1][0] != '-') { $this->vars[substr($argv[$i], 1)] = $argv[$i + 1]; $i++; } else { $this->vars[substr($argv[$i], 1)] = ''; } } } } } if ('' != ($pathinfo = array_key_exists('PATH_INFO', $_SERVER) ? empty($_SERVER['PATH_INFO']) && array_key_exists('ORIG_PATH_INFO', $_SERVER) ? $_SERVER['ORIG_PATH_INFO'] : $_SERVER['PATH_INFO'] : (isset($this->vars['pathinfo']) ? $this->vars['pathinfo'] : null))) { if ($pathinfo[0] != '/') { $pathinfo = '/' . $pathinfo; } $this->args = preg_replace("/(.*?)\\?.*/", "\\1", $pathinfo); } if (isset($this->vars['application_branch'])) { App::branch($this->vars['application_branch']); unset($this->vars['application_branch']); } if (isset($_COOKIE) && is_array($_COOKIE)) { foreach ($_COOKIE as $key => $value) { $this->vars[$key] = $this->mq_off($value); } } if (isset($_FILES) && is_array($_FILES)) { foreach ($_FILES as $key => $files) { $this->files($key, $files); } } if ($this->_inc_session_) { if (!self::$session_start) { ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', self::$session_gc_divisor); session_cache_limiter(self::$session_limiter); session_cache_expire(self::$session_expire); session_name(self::$session_name); if (Object::C(__CLASS__)->has_module('session_read')) { ini_set('session.save_handler', 'user'); session_set_save_handler(array($this, '__session_open__'), array($this, '__session_close__'), array($this, '__session_read__'), array($this, '__session_write__'), array($this, '__session_destroy__'), array($this, '__session_gc__')); if (isset($this->vars[self::$session_name])) { list($session_name, $id, $path) = array(self::$session_name, $this->vars[self::$session_name], session_save_path()); if (Object::C(__CLASS__)->call_module('session_verify', $session_name, $id, $path) !== true) { session_regenerate_id(true); } } } else { if (isset($this->vars[self::$session_name]) && is_dir(session_save_path()) && !is_file(File::absolute(session_save_path(), 'sess_' . $this->vars[self::$session_name]))) { session_regenerate_id(true); } } session_start(); self::$session_start = true; } if (empty($this->_scope_)) { $this->_scope_ = $this->_class_; } $this->session_init(); } }
/** * パッケージのmediaのパスを返す * @param strng $path ベースパスに続くメディアのパス * @return string */ function module_media($path = null) { list($file) = debug_backtrace(false); $root = Lib::module_root_path($file["file"]) . "/resources/media"; return empty($path) ? $root : File::absolute($root, $path); }
/** * テンポラリファイルを作成する * デストラクタで削除される * @param string $path * @param string $body */ public static function ftmp($path, $body) { $path = File::absolute(Rhaco::def("ext.Test@ftmp"), $path); File::write($path, Text::plain($body)); }
/** * work dirを変更する * -work PATH * @param Request $req * @param string $value PATH */ public static function __setup_work__(Request $req, $value) { $path = File::absolute(App::work() . '/', $value); self::app_config_update(App::url(), $path, App::mode()); self::info_print('work dir changed `' . $path . '`'); }
private static function lib($repository) { if (!$repository->start("lib")) { return; } foreach (Lib::classes(true) as $class_path => $class) { $i = new InfoClass($class_path, false); $base_dir = Lib::path(); $search_path = File::absolute($base_dir, str_replace(".", "/", $i->package())); $target = is_file($search_path . ".php") ? $search_path . ".php" : (is_file($search_path . "/" . basename($search_path) . ".php") ? $search_path : null); if ($target !== null) { $tgz_filename = $repository->tgz_path($i->package()); File::tgz($tgz_filename, $target, $base_dir); touch($tgz_filename, File::last_update($target)); $repository->add($i->package(), $i->name(), File::last_update($i->path()), $i->document()); } } }
/** * URLパターンからハンドリング * @param mixed{} $urls * @param int $index * @return $this */ private function handler(array $urls = array(), $index = 0) { if (preg_match("/^\\/" . str_replace("/", "\\/", self::$package_media_url) . "\\/(\\d+)\\/(\\d+)\\/(.+)\$/", $this->args(), $match)) { if ($match[1] == $index) { foreach ($urls as $args) { if ($match[2] == $args['map_index'] && isset($args['class'])) { $this->attach_file(File::absolute(Lib::module_root_path(Lib::imported_path(Lib::import($args['class']))) . '/resources/media', $match[3])); } } Http::status_header(404); exit; } return $this; } foreach (array_keys($urls) as $pattern) { if (preg_match("/^" . (empty($pattern) ? "" : "\\/") . str_replace(array("\\/", "/", "__SLASH__"), array("__SLASH__", "\\/", "\\/"), $pattern) . '[\\/]{0,1}$/', $this->args(), $params)) { Log::debug("match pattern `" . $pattern . "` " . (empty($urls[$pattern]['name']) ? '' : '[' . $urls[$pattern]['name'] . ']')); array_shift($params); $this->pattern = $pattern; $map = $urls[$pattern]; $action = null; if (!empty($map['redirect']) && empty($map['class'])) { $this->redirect($map['redirect'][0] == '/' ? substr($map['redirect'], 1) : $map['redirect']); } if (!empty($map['template']) && empty($map['method'])) { $action = new self('_scope_=' . $map['scope']); $action->set($this, $map, $pattern, $params, $urls); } else { if (empty($map['class'])) { throw new RuntimeException('Invalid map'); } $class = class_exists($map['class']) ? $map['class'] : Lib::import($map['class']); if (!method_exists($class, $map['method'])) { throw new RuntimeException($map['class'] . '::' . $map['method'] . ' not found'); } if (!is_subclass_of($class, __CLASS__)) { throw new RuntimeException("class is not " . __CLASS__); } $action = new $class('_scope_=' . $map['scope'] . ',_init_=false'); foreach (array('redirect', 'name') as $k) { $action->{$k} = $map[$k]; } $action->set($this, $map, $pattern, $params, $urls); call_user_func_array(array($action, $map['method']), $params); if (!$action->is_filename()) { $ref = new ReflectionObject($action); $file = dirname($ref->getFileName()) . '/resources/templates/' . $map['method'] . '.html'; if (is_file($file)) { $action->template($file); $action->media_url(App::url('/' . self::$package_media_url . '/' . $index . '/' . $urls[$pattern]['map_index'])); } else { if ($action->is_filename($map['method'] . '.html')) { $action->template($map['method'] . '.html'); } } } } $action->call_module('after_flow', $action); $this->add_object($action->o('Template')); $this->cp(self::execute_var($map['vars'])); $this->vars('t', new Templf($action)); break; } } return $this; }
private final function rtblock($src, $filename) { if (strpos($src, 'rt:block') !== false || strpos($src, 'rt:extends') !== false) { $blocks = $paths = array(); while (Tag::setof($xml, $this->rtcomment($src), 'rt:extends')) { $bxml = Tag::anyhow($src); foreach ($bxml->in('rt:block') as $block) { if (strtolower($block->name()) == 'rt:block') { $name = $block->in_param('name'); if (!empty($name) && !array_key_exists($name, $blocks)) { $blocks[$name] = $block->value(); $paths[$name] = $filename; } } } if ($xml->is_param('href')) { $src = File::read($filename = File::absolute(dirname($filename), $xml->in_param('href'))); $this->filename = $filename; } else { $src = File::read($this->filename()); } $this->selected_template = $xml->in_param('name'); $src = $this->rttemplate($this->replace_xtag($src)); } if (empty($blocks)) { $bxml = Tag::anyhow($src); foreach ($bxml->in('rt:block') as $block) { $src = str_replace($block->plain(), $block->value(), $src); } } else { while (Tag::setof($xml, $src, 'rt:block')) { $xml = Tag::anyhow($src); foreach ($xml->in('rt:block') as $block) { $name = $block->in_param('name'); $src = str_replace($block->plain(), array_key_exists($name, $blocks) ? $blocks[$name] : $block->value(), $src); } } } } return $src; /*** ftmp("template/base.html",' ======================= <rt:block name="aaa"> base aaa </rt:block> <rt:block name="bbb"> base bbb </rt:block> <rt:block name="ccc"> base ccc </rt:block> <rt:block name="ddd"> base ddd </rt:block> ======================= '); ftmp("template/extends1.html",' <rt:extends href="base.html" /> <rt:block name="aaa"> extends1 aaa </rt:block> <rt:block name="ddd"> extends1 ddd <rt:loop param="abc" var="ab" loop_counter="loop_counter" key="loop_key"> {$loop_key}:{$loop_counter} {$ab} </rt:loop> <rt:if param="abc"> aa </rt:if> <rt:if param="aa" value="1"> bb </rt:if> <rt:if param="aa" value="2"> bb <rt:else /> cc </rt:if> <rt:if param="zz"> zz </rt:if> <rt:if param="aa"> aa </rt:if> <rt:if param="tt"> true </rt:if> <rt:if param="ff"> false </rt:if> </rt:block> '); ftmp("template/sub/extends2.html",' <rt:extends href="../extends1.html" /> <rt:block name="aaa"> <a href="hoge/fuga.html">fuga</a> <a href="{$newurl}/abc.html">abc</a> sub extends2 aaa </rt:block> <rt:block name="ccc"> sub extends2 ccc </rt:block> '); $template = new Template("http://rhaco.org",tmp_path("template")); $template->vars("newurl","http://hoge.ho"); $template->vars("abc",array(1,2,3)); $template->vars("aa",1); $template->vars("zz",null); $template->vars("ff",false); $template->vars("tt",true); $result = $template->read("sub/extends2.html"); $ex = text(' ======================= <a href="http://rhaco.org/hoge/fuga.html">fuga</a> <a href="http://hoge.ho/abc.html">abc</a> sub extends2 aaa base bbb sub extends2 ccc extends1 ddd 0:1 1 1:2 2 2:3 3 aa bb cc aa true ======================= '); eq($ex,$result); */ }