Example #1
0
 protected static function load_classes()
 {
     $store_key = array(__DIR__, '__autoload');
     if (Store::has($store_key)) {
         $classes = Store::get($store_key);
     } else {
         $classes = array();
         $modules = array();
         $dir = path('libs');
         $itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
         $pattern = '/^' . preg_quote($dir, '/') . '\\/(.+?)\\.php$/';
         foreach ($itr as $elem) {
             if ($elem->isFile() && preg_match($pattern, $elem->getPathname(), $match)) {
                 $class_name = $elem->getBasename('.php');
                 if ($class_name == basename($elem->getPath())) {
                     $modules[$class_name] = str_replace('/', '.', substr($elem->getPath(), strlen($dir) + 1));
                 } else {
                     if ($class_name !== __CLASS__) {
                         $classes[$class_name] = str_replace('/', '.', $match[1]);
                     }
                 }
             }
         }
         foreach ($modules as $module_name => $module_path) {
             foreach ($classes as $class_name => $class_path) {
                 if (strpos($class_path, $module_path) === 0) {
                     unset($classes[$class_name]);
                 }
             }
         }
         $classes = $modules + $classes;
         Store::set($store_key, $classes);
     }
     self::$classes = $classes;
 }
Example #2
0
 public static function unread_count(OpenpearMaintainer $maintainer)
 {
     $key = array('openpear_message_unread', $maintainer->id());
     if (Store::has($key)) {
         return Store::get($key);
     }
     $unread_messages_count = C(__CLASS__)->find_count(Q::eq('maintainer_to_id', $maintainer->id()), Q::eq('unread', true));
     Store::set($key, $unread_messages_count);
     return $unread_messages_count;
 }
Example #3
0
 /**
  * linktitleHandler
  */
 public static function linktitleHandler($url)
 {
     if (module_const('is_cache', false)) {
         $store_key = array('__hatenaformat_linktitlehandler', $url);
         if (Store::has($store_key)) {
             return Store::get($store_key);
         }
     }
     if (Tag::setof($title, Http::read($url), 'title')) {
         $url = $title->value();
         if (module_const('is_cache', false)) {
             Store::set($store_key, $url, self::CACHE_EXPIRE);
         }
     }
     return $url;
 }
Example #4
0
 /**
  * チェンジセットを取得する
  * @param int $revision
  * @param bool $cache
  * @return OpenpearChangeset
  **/
 public static function get_changeset($revision, $cache = true)
 {
     $cache_key = self::cache_key($revision);
     if ($cache) {
         if (isset(self::$cached_changesets[$revision])) {
             return self::$cached_changesets[$revision];
         } else {
             if (Store::has($cache_key)) {
                 $changeset = Store::get($cache_key);
                 self::$cached_changesets[$revision] = $changeset;
                 return $changeset;
             }
         }
     }
     $changeset = C(__CLASS__)->find_get(Q::eq('revision', $revision));
     Store::set($cache_key, $changeset);
     return $changeset;
 }
Example #5
0
 /**
  * メンテナ情報を取得する
  * @param int $id
  * @param bool $cache
  * @return OpenpearMaintainar
  **/
 public static function get_maintainer($id, $cache = true)
 {
     $cache_key = self::cache_key($id);
     if ($cache) {
         Log::debug('cache on');
         if (isset(self::$cached_maintainers[$id])) {
             return self::$cached_maintainers[$id];
         } else {
             if (Store::has($cache_key)) {
                 $maintainer = Store::get($cache_key);
                 self::$cached_maintainers[$id] = $maintainer;
                 return $maintainer;
             }
         }
     }
     $maintainer = C(__CLASS__)->find_get(Q::eq('id', $id));
     Store::set($cache_key, $maintainer, OpenpearConfig::object_cache_timeout(3600));
     return $maintainer;
 }
Example #6
0
 public static function packages(OpenpearMaintainer $maintainer)
 {
     $store_key = array('charges_maintainer', $maintainer->id());
     if (Store::has($store_key, self::CACHE_TIMEOUT)) {
         $packages = Store::get($store_key);
     } else {
         try {
             $packages = array();
             $charges = C(OpenpearCharge)->find_all(Q::eq('maintainer_id', $maintainer->id()));
             foreach ($charges as $charge) {
                 $packages[] = $charge->package();
             }
         } catch (Exception $e) {
             $packages = array();
         }
         Store::set($store_key, $packages, self::CACHE_TIMEOUT);
     }
     return $packages;
 }
Example #7
0
 /**
  * xml定義からhandlerを処理する
  * @param string $file アプリケーションXMLのファイルパス
  */
 public static final function load($file = null)
 {
     if (!isset($file)) {
         $file = App::mode() . App::called_filename();
     }
     if (!self::$is_app_cache || !Store::has($file)) {
         $parse_app = self::parse_app($file, false);
         if (self::$is_app_cache) {
             Store::set($file, $parse_app);
         }
     }
     if (self::$is_app_cache) {
         $parse_app = Store::get($file);
     }
     if (empty($parse_app['apps'])) {
         throw new RuntimeException('undef app');
     }
     $app_result = null;
     $in_app = $match_handle = false;
     $app_index = 0;
     try {
         foreach ($parse_app['apps'] as $app) {
             switch ($app['type']) {
                 case 'handle':
                     $self = new self('_inc_session_=false');
                     foreach ($app['modules'] as $module) {
                         $self->add_module(self::import_instance($module));
                     }
                     if ($self->has_module('flow_handle_begin')) {
                         $self->call_module('flow_handle_begin', $self);
                     }
                     try {
                         if ($self->handler($app['maps'], $app_index++)->is_pattern()) {
                             $self->cp(self::execute_var($app['vars']));
                             $src = $self->read();
                             if ($self->has_module('flow_handle_end')) {
                                 $self->call_module('flow_handle_end', $src, $self);
                             }
                             print $src;
                             $in_app = true;
                             $match_handle = true;
                             if (!$parse_app["handler_multiple"]) {
                                 exit;
                             }
                         }
                     } catch (Exception $e) {
                         Log::warn($e);
                         if (isset($app['on_error']['status'])) {
                             Http::status_header((int) $app['on_error']['status']);
                         }
                         if (isset($app['on_error']['redirect'])) {
                             $this->save_exception($e);
                             $this->redirect($app['on_error']['redirect']);
                         } else {
                             if (isset($app['on_error']['template'])) {
                                 if (!$e instanceof Exceptions) {
                                     Exceptions::add($e);
                                 }
                                 $self->output($app['on_error']['template']);
                             } else {
                                 throw $e;
                             }
                         }
                     }
                     break;
                 case 'invoke':
                     $class_name = isset($app['class']) ? Lib::import($app['class']) : get_class($app_result);
                     $ref_class = new ReflectionClass($class_name);
                     foreach ($app['methods'] as $method) {
                         $invoke_class = $ref_class->getMethod($method['method'])->isStatic() ? $class_name : (isset($app['class']) ? new $class_name() : $app_result);
                         $args = array();
                         foreach ($method['args'] as $arg) {
                             if ($arg['type'] === 'result') {
                                 $args[] =& $app_result;
                             } else {
                                 $args[] = $arg['value'];
                             }
                         }
                         if (is_object($invoke_class)) {
                             foreach ($app['modules'] as $module) {
                                 $invoke_class->add_module(self::import_instance($module));
                             }
                         }
                         $app_result = call_user_func_array(array($invoke_class, $method['method']), $args);
                         $in_app = true;
                     }
                     break;
             }
         }
         if (!$match_handle) {
             Log::debug("nomatch");
             if ($parse_app["nomatch_redirect"] !== null) {
                 Http::redirect(App::url($parse_app["nomatch_redirect"]));
             }
             if ($parse_app["nomatch_template"] !== null) {
                 Http::status_header(404);
                 $self = new self();
                 $self->output($parse_app["nomatch_template"]);
             }
         }
         if (!$in_app) {
             Http::status_header(404);
         }
     } catch (Exception $e) {
         if (!$e instanceof Exceptions) {
             Exceptions::add($e);
         }
     }
     exit;
 }
Example #8
0
 /**
  * Determine if any flashes exist in current session.
  * 
  * @return boolean
  */
 public function exists()
 {
     return $this->session->has($this->key);
 }
Example #9
0
 /**
  * ?????
  * @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);
 }
Example #10
0
 /**
  * ファイルから生成する
  * @param string $filename テンプレートファイルパス
  * @param string $template_name 対象となるテンプレート名
  * @return string
  */
 public function read($filename = null, $template_name = null)
 {
     if (!empty($filename)) {
         $this->filename($filename);
     }
     $this->selected_template = $template_name;
     $cfilename = $this->filename() . $this->selected_template;
     if (!self::$is_cache || !Store::has($cfilename, true)) {
         if (strpos($filename, '://') === false) {
             $src = $this->parse(File::read($this->filename()));
         } else {
             if (empty($this->media_url)) {
                 $this->media_url($this->filename());
             }
             $src = $this->parse(Http::read($this->filename()));
         }
         if (self::$is_cache) {
             Store::set($cfilename, $src);
         }
     } else {
         $src = Store::get($cfilename);
     }
     $src = $this->html_reform($this->exec($src));
     $this->call_module('after_read_template', $src, $this);
     return $this->replace_ptag($src);
 }