/** * 格納されたログを出力する */ public static final function flush() { if (self::isPublishLevel() >= 4) { self::$LOG[] = new self(4, "use memory: " . number_format(memory_get_usage()) . "byte / " . number_format(memory_get_peak_usage()) . "byte"); self::$LOG[] = new self(4, sprintf("------- end logger ( %f sec ) ------- ", microtime(true) - (double) self::$START)); } if (!empty(self::$LOG)) { $level = array("none", "error", "warning", "info", "debug"); foreach (self::$LOG as $log) { $value = $log->value(); if (Rhaco::def("core.Log@expression") === true) { ob_start(); var_dump($value); $value = substr(ob_get_clean(), 0, -1); } $value = "[" . $level[$log->level()] . " " . $log->time() . "]:[" . $log->file() . ":" . $log->line() . "] " . $value . "\n"; if (self::$DISP_LEVEL >= $log->level() && self::$DISP) { print $value; } if (self::$FILE_LEVEL >= $log->level()) { if (empty(self::$PATH)) { throw new Exception("not found path"); } File::append(sprintf("%s/%s.log", File::path(self::$PATH), date("Ymd")), $value); } self::call_filter($level[$log->level()], $log); } self::call_filter("flush", self::$LOG); } self::$LOG = array(); }
public static function __import__() { /** (none/nocache/private/private_no_expire/public) */ session_cache_limiter(Rhaco::def("core.Request@limiter", "nocache")); session_cache_expire(Rhaco::def("core.Request@expire", 2592000)); session_start(); }
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); }
/** * 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; }
/** * 初期定義 * * @param string $path * @param string $lib * @param string $url */ public static function init($path, $url = null, $lib = null, $work = null) { self::$inited = true; if (is_file($path)) { $path = dirname($path); } self::$PATH = preg_replace("/^(.+)\\/\$/", "\\1", str_replace("\\", "/", $path)) . "/"; if (isset($lib)) { if (is_file($lib)) { $lib = dirname($lib); } self::$LIB = preg_replace("/^(.+)\\/\$/", "\\1", str_replace("\\", "/", $lib)) . "/"; } else { self::$LIB = self::$PATH . "lib/"; } if (isset($work)) { if (is_file($work)) { $work = dirname($work); } self::$WORK = preg_replace("/^(.+)\\/\$/", "\\1", str_replace("\\", "/", $work)) . "/"; } else { self::$WORK = self::$PATH . "work/"; } self::$URL = preg_replace("/^(.+)\\/\$/", "\\1", $url) . "/"; Rhaco::add(self::$LIB); }
/** * * @return database.model.Column */ function columnName() { if (!Rhaco::isVariable("_R_D_C_", "Category::Name")) { $column = new Column("column=name,variable=name,type=string,size=30,require=true,", __CLASS__); $column->label(Message::_("name")); Rhaco::addVariable("_R_D_C_", $column, "Category::Name"); } return Rhaco::getVariable("_R_D_C_", null, "Category::Name"); }
public static function __import__() { $server = Rhaco::def("ext.Installer@server"); if (!empty($server)) { if (is_array($server)) { foreach ($server as $s) { self::add($s); } } else { self::add($server); } } }
/** * クラスファイルから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(); }
function _redirectForm($url, $headers) { print <<<HTML <html> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head> <body onload="document.login.submit();"> <form action="{$url}" method="post" name="login"> HTML; foreach ($headers as $name => $value) { printf('<input type="hidden" name="%s" value="%s" />', $name, $value); } print <<<HTML <input type="submit" value="login" /> </form> </body> </html> HTML; Rhaco::end(); }
/** * Ethna_Renderer_Rhacoクラスのコンストラクタ * * @access public */ public function __construct($controller) { parent::__construct($controller); $this->template_dir = $controller->getTemplatedir() . '/'; $this->compile_dir = $controller->getDirectory('template_c'); Rhaco::constant('TEMPLATE_PATH', $this->template_dir); $this->engine = new TemplateParser_Ethna(); /* $this->setTemplateDir($template_dir); $this->compile_dir = $compile_dir; */ $this->engine->template_dir = $this->template_dir; $this->engine->compile_dir = $this->compile_dir; $this->engine->compile_id = md5($this->template_dir); // 一応がんばってみる if (is_dir($this->engine->compile_dir) === false) { Ethna_Util::mkdir($this->engine->compile_dir, 0755); } $this->_setDefaultPlugin(); }
/** * 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; }
<?php Rhaco::import("core.File"); Rhaco::import("core.Log"); /** * * @author Kazutaka Tokushima * @license New BSD License */ class Command extends Object { protected $resource; protected $stdout; protected $stderr; protected $end_code; private $proc; private $close = true; protected function __new__($command = null) { if (!empty($command)) { $this->open($command); $this->close(); } } public function open($command, $out_file = null, $error_file = null) { Log::debug($command); $this->close(); if (!empty($out_file)) { File::write($out_file); }
<?php require_once '__init__.php'; Rhaco::import('generic.Urls'); Rhaco::import('model.Todo'); Rhaco::import('model.Category'); $db = new DbUtil(Category::connection()); $patterns = array('^$' => array('class' => 'generic.Views', 'method' => 'read', 'args' => array(new Todo(), new C(Q::eq(Todo::columnClose(), false), Q::fact())), 'template' => 'list.html'), '^detail/(\\d+)$' => array('method' => 'detail', 'args' => array(new Todo(), new C(Q::fact()))), '^create$' => array('method' => 'create', 'args' => array(new Todo(), Rhaco::url())), '^update/(\\d+)$' => array('method' => 'update', 'args' => array(new Todo(), null, Rhaco::url())), '^delete/(\\d+)$' => array('method' => 'delete', 'args' => array(new Todo(), null, Rhaco::url())), '^cat/(\\d+)$' => array('method' => 'detail', 'args' => array(new Category(), new C(Q::depend())))); $parser = Urls::parser($patterns, $db); $parser->setVariable('categories', $db->select(new Category())); $parser->write();
<?php /** * Clipp API * * @author riaf <*****@*****.**> * @package arbo * @version $Id$ */ Rhaco::import('network.http.ServiceRestAPIBase'); Rhaco::import('model.ClippAtomEntry10'); class ClippAPI extends ServiceRestAPIBase { var $url = 'http://clipp.in/service/'; var $method; function ClippAPI($user, $pass) { parent::ServiceRestAPIBase($this->url); $this->setBasicAuthorization($user, $pass); } function add($entry) { $this->method = 'add'; if (Variable::istype('ClippAtomEntry10', $entry)) { $this->browser->setRequestHeader(array('type' => 'application/atom+xml;type=entry;charset=utf-8', 'rawdata' => '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL . $entry->get())); return $this->post(); } return false; } function buildUrl($hash = array()) {
public function __construct($data_name) { $this->data_name = $data_name; $this->path = Rhaco::def("generic.Crud@url", $_SERVER["SCRIPT_NAME"]); }
<?php Rhaco::import("core.Paginator"); Rhaco::import("core.Text"); Rhaco::import("core.Model"); Rhaco::import("db.Db"); Rhaco::import("db.Column"); Rhaco::import("db.Q"); Rhaco::module("StatementIterator"); /** * @author Kazutaka Tokushima * @license New BSD License */ abstract class Dao extends Object implements Model { private static $CONNECTION; private static $DAO; protected $_database_; protected $_table_; protected $_has_hierarchy_ = 1; private $_columns_ = array(); private $_self_columns_ = array(); private $_conds_ = array(); private $_alias_ = array(); protected $_class_id_; protected $_has_many_conds_ = array(); protected $_hierarchy_; protected function __new__() { if (func_num_args() == 1) { $this->dict(func_get_arg(0));
/** * * @return database.model.Column */ function columnCtime() { if (!Rhaco::isVariable("_R_D_C_", "Comment::Ctime")) { $column = new Column("column=ctime,variable=ctime,type=timestamp,", __CLASS__); $column->label(Message::_("ctime")); Rhaco::addVariable("_R_D_C_", $column, "Comment::Ctime"); } return Rhaco::getVariable("_R_D_C_", null, "Comment::Ctime"); }
<?php Rhaco::import("core.File"); /** * メール送信に関する情報を制御する * * @author Kazutaka Tokushima * @author Kentaro YABE * @license New BSD License */ class Mail extends Object { protected static $__to__ = "type=string{}"; protected static $__cc__ = "type=string{}"; protected static $__bcc__ = "type=string{}"; protected static $__attach__ = "type=File{}"; protected static $__image__ = "type=File{}"; protected $subject; protected $to; protected $cc; protected $bcc; protected $attach; protected $image; protected $message; protected $html; protected $from; protected $name; protected $return_path; private $eol = "\n"; private $encode = "jis"; private $boundary = array("mixed" => "mixed", "alternative" => "alternative", "related" => "related");
/** * アプリケーションのワーキング(テンポラリ)ファイルパスを取得する * * @param string $path * @return string */ function work_path($path = null) { return Rhaco::work($path); }
<?php Rhaco::import("db.Dao"); /** * @author Kazutaka Tokushima * @license New BSD License */ class StatementIterator implements Iterator { private $dao; private $statement; private $resultset; private $key; private $resultset_counter; public function __construct(Dao $dao, PDOStatement $statement) { $this->dao = $dao; $this->statement = $statement; } public function rewind() { $this->resultset = $this->statement->fetch(PDO::FETCH_ASSOC); $this->resultset_counter = 0; } public function current() { $obj = clone $this->dao; $this->key = $obj->parse_resultset($this->resultset); return $obj; } public function key()
<?php Rhaco::import("model.table.StageTable"); /** * */ class Stage extends StageTable { }
<?php Rhaco::import("model.table.StageCategoryTable"); /** * */ class StageCategory extends StageCategoryTable { }
<?php /** * Tumblr API * * @author riaf<*****@*****.**> * @package arbo * @license New BSD License * @version $Id$ */ Rhaco::import('network.http.ServiceRestAPIBase'); class TumblrAPI extends ServiceRestAPIBase { var $url = 'http://www.tumblr.com/api/'; var $login; var $password; var $method; function TumblrAPI($login, $password) { parent::ServiceRestAPIBase(); $this->login = $login; $this->password = $password; } /** * 投稿 */ function write($params, $type = 'Regular') { $this->method = 'write'; return $this->post(array_merge($params, array('email' => $this->login, 'password' => $this->password, 'type' => $type))); }
<?php /** * Au * * @author riaf <*****@*****.**> * @package arbo * @license New BSD License * @version $Id$ */ Rhaco::import('model.MobileCarrierBase'); class Au extends MobileCarrierBase { function isAu() { return true; } }
public function atom() { Rhaco::import("net.feed.atom.Atom"); $atom = new Atom(); $atom->title($this->title()); $atom->subtitle($this->description()); $atom->generator($this->webMaster()); $atom->updated($this->lastBuildDate()); $link = new AtomLink(); $link->href($this->link()); $atom->link($link); foreach ($this->arItem() as $item) { $entry = new AtomEntry(); $entry->title($item->title()); $entry->published($item->pubDate()); $author = new AtomAuthor(); $author->name($item->author()); $entry->author($author); $link = new AtomLink(); $link->href($item->link()); $entry->link($link); $content = new AtomContent(); $content->value($item->description()); $entry->content($content); $summary = new AtomSummary(); $summary->value($item->comments()); $entry->summary($summary); $atom->add($entry); } return $atom; /*** $src = text(' <rss version="2.0"> <channel> <title>rhaco</title> <link>http://rhaco.org</link> <description>php</description> <language>ja</language> <copyright>rhaco.org</copyright> <docs>hogehoge</docs> <lastBuildDate>2007-10-10T10:10:10+09:00</lastBuildDate> <managingEditor>tokushima</managingEditor> <pubDate>2007-10-10T10:10:10+09:00</pubDate> <webMaster>kazutaka</webMaster> <item> <title>rhaco</title> <link>http://rhaco.org</link> <description>rhaco desc</description> </item> <item> <title>everes</title> <link>http://www.everes.net</link> <description>everes desc</description> </item> </channel> </rss> '); $xml = Rss::parse($src); eq("2.0",$xml->version()); eq("rhaco",$xml->title()); eq("http://rhaco.org",$xml->link()); eq("php",$xml->description()); eq("ja",$xml->language()); eq("rhaco.org",$xml->copyright()); eq("hogehoge",$xml->docs()); eq(1191978610,$xml->lastBuildDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmLastBuildDate()); eq("tokushima",$xml->managingEditor()); eq(1191978610,$xml->pubDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmPubDate()); eq("kazutaka",$xml->webMaster()); eq(2,sizeof($xml->item())); $atom = $xml->atom(); eq(true,$atom instanceof Atom); eq("rhaco",$atom->title()); eq("php",$atom->subtitle()); eq(1191978610,$atom->updated()); eq("kazutaka",$atom->generator()); eq(2,sizeof($atom->entry())); */ }
<?php require dirname(__FILE__) . '/__init__.php'; Rhaco::import('tag.HtmlParser'); $db = new DbUtil(Event::connection()); $p = new HtmlParser('index.html'); $p->setVariable('event', $db->get(new Event(), new C(Q::depend(), Q::eq(Event::columnId(), Rhaco::constant('CURRENT_EVENT', 1))))); $p->setVariable('hatena', Rhaco::obj('HatenaSyntax', array('headlevel' => 4, 'id' => 'event_description'))); $p->write();
private static function search_connections() { foreach (Rhaco::constants("db.Db@") as $key => $dsn) { if (isset($key[6])) { self::connection(substr($key, 6)); } } if (empty(self::$SESSION)) { throw new Exception("undef connection"); } }
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; }
/** * URLのパターンからTemplateを切り替える * @param array $urlconf */ public function handler(array $urlconf = array()) { $params = array(); foreach ($urlconf as $pattern => $conf) { if (is_int($pattern)) { $pattern = $conf; $conf = null; } if (preg_match("/" . str_replace(array("\\/", "/", "__SLASH__"), array("__SLASH__", "\\/", "\\/"), $pattern) . "/", $this->args(), $params)) { if ($conf !== null) { if (is_array($conf)) { if (isset($conf["class"])) { $this->class = $conf["class"]; } if (isset($conf["method"])) { $this->method = $conf["method"]; } if (isset($conf["template"])) { $this->template = $conf["template"]; } if (isset($conf["name"])) { $this->name = $conf["name"]; } } else { $this->dict($conf); } } self::$match_pattern = empty($this->name) ? $params[0] : $this->name; if (!empty($this->class)) { if (false !== strrpos($this->class, ".") || !class_exists($this->class)) { $this->class = Rhaco::import($this->class); } if (empty($this->method) && !empty($pattern)) { $method_patterns = array(); $patterns = explode("/", $pattern); if ($patterns[0] == "^") { array_shift($patterns); } foreach ($patterns as $p) { if (!preg_match("/[\\w_]/", $p)) { break; } $method_patterns[] = $p; } if (!empty($method_patterns)) { $this->method = implode("_", $method_patterns); } } } if (empty($this->method) && !empty($this->template)) { $obj = new self(); $obj->copy_module($this, true); $obj->template($this->template); } else { $method = empty($this->method) ? "index" : $this->method; if (!method_exists($this->class, $method)) { throw new Exception("Not found " . $this->class . "::" . $method); } array_shift($params); try { $class = $this->class; $action = new $class(); $action->copy_module($this, true); if ($action instanceof self) { $action->handled(); } $obj = call_user_func_array(array($action, $method), $params); } catch (Exception $e) { Log::debug($e); $on_error = Rhaco::def("core.Flow@on_error"); if ($on_error === null) { throw $e; } if (isset($on_error[0])) { Http::status_header((int) $on_error[0]); } if (isset($on_error[2])) { Http::redirect($on_error[2]); } if (isset($on_error[1])) { $template = new Template(); $template->output($on_error[1]); } exit; } } if ($obj instanceof self) { $obj = $obj->templ(); } if (!$obj instanceof Template) { throw new Exception("Forbidden " . $this->args()); } $obj->path($this->path()); $obj->url($this->url()); $this->templ = $obj; if (!$this->isTemplate()) { $this->template($obj->filename()); } if (!$this->isTemplate()) { $cs = explode(".", $this->class); $class = array_pop($cs); $class = implode("/", $cs) . (!empty($cs) ? "/" : "") . strtolower($class[0]) . substr($class, 1); $this->template($class . "/" . $method . ".html"); } return $this; } } throw new Exception("no match pattern"); }
<?php Rhaco::import("core.Tag"); /** * @author Kazutaka Tokushima * @license New BSD License */ class AtomContent extends Object { protected $type; protected $mode; protected $lang; protected $base; protected $value; protected function __getattr__($arg, $param) { if (is_string($arg)) { return Tag::xmltext($arg); } return $arg; } protected function __str__() { if ($this->none()) { return ""; } $result = new Tag("content"); foreach ($this->access_members() as $name => $value) { if (!empty($value)) { switch ($name) { case "type":