Ejemplo n.º 1
0
 public function encryptPassword($password)
 {
     $secret = Config::getInstance()->get('app.user.secret');
     $result = substr(md5($password . $secret) . md5($secret . substr($password, 0, 1)), 0, 40);
     //pre($result);
     return $result;
 }
Ejemplo n.º 2
0
 protected function includeTemplate($template_name_c0c4648d020076fcb9f7ef1460db10b0)
 {
     $args = func_get_args();
     array_shift($args);
     $data_5656d190508c77a079411fbbb437745f = array();
     foreach ($args as $arg) {
         if (is_array($arg)) {
             foreach ($arg as $k => $v) {
                 $data_5656d190508c77a079411fbbb437745f[$k] = $v;
             }
         }
     }
     $template_filename_c0c4648d020076fcb9f7ef1460db10b0 = $this->_controller->getFilePath('template', $template_name_c0c4648d020076fcb9f7ef1460db10b0);
     unset($args, $arg, $k, $v);
     $request = \ORC\MVC\Request::getInstance();
     extract($data_5656d190508c77a079411fbbb437745f);
     unset($data_5656d190508c77a079411fbbb437745f);
     //         $viewModel = $this->getViewModel();
     //         $modelData = $viewModel->getAllModelData();
     //         $request = \ORC\MVC\Request::getInstance();
     if (Config::getInstance()->get('debug.template')) {
         echo sprintf('<!-- using content template %s begin -->', $template_name_c0c4648d020076fcb9f7ef1460db10b0);
     }
     include $template_filename_c0c4648d020076fcb9f7ef1460db10b0;
     if (Config::getInstance()->get('debug.template')) {
         echo sprintf('<!-- using content template %s end -->', $template_name_c0c4648d020076fcb9f7ef1460db10b0);
     }
 }
Ejemplo n.º 3
0
 protected function renderTemplate($template_name__5656d190508c77a079411fbbb437745f, array $data_5656d190508c77a079411fbbb437745f = array())
 {
     $args = func_get_args();
     array_shift($args);
     array_shift($args);
     foreach ($args as $arg) {
         if (is_array($arg)) {
             foreach ($arg as $k => $v) {
                 $data_5656d190508c77a079411fbbb437745f[$k] = $v;
             }
         }
     }
     $template_filename_c0c4648d020076fcb9f7ef1460db10b0 = $this->_controller->getFilePath('template', $template_name__5656d190508c77a079411fbbb437745f);
     unset($args, $k, $v);
     ob_start();
     extract($data_5656d190508c77a079411fbbb437745f);
     unset($data_5656d190508c77a079411fbbb437745f);
     if (Config::getInstance()->get('template.debug')) {
         echo sprintf('<!-- using block template %s begin -->', $template_name__5656d190508c77a079411fbbb437745f);
     }
     include $template_filename_c0c4648d020076fcb9f7ef1460db10b0;
     if (Config::getInstance()->get('template.debug')) {
         echo sprintf('<!-- using block template %s end -->', $template_name__5656d190508c77a079411fbbb437745f);
     }
     return ob_get_clean();
 }
Ejemplo n.º 4
0
 protected function parseURI()
 {
     $uri = $this->_request->getURI();
     list($url_path, ) = explode('?', $uri, 2);
     $config = Config::getInstance();
     if ($config->get('app.seo.ext')) {
         $url_path = preg_replace('/\\.(' . $config->get('app.seo.ext') . ')$/i', '', $url_path);
     }
     $routes = $this->get('routes');
     //pre($routes);
     $trim_chars = "/\n\r\t\v ";
     $url_args = array();
     while (strlen($url_path) > 1 && !isset($routes[$url_path])) {
         $new_arg = substr($url_path, strrpos($url_path, '/'));
         $url_path = substr($url_path, 0, strrpos($url_path, $new_arg));
         // put the new arg into the list
         array_unshift($url_args, trim($new_arg, $trim_chars));
     }
     if ($url_path == '') {
         $url_path = '/';
     }
     if ($url_path == '/') {
         //index, show the default action
         $this->set('action', strtolower(\ORC\Application::getApp()->getDefaultAction()));
     } elseif ($url_path) {
         $this->set('action', strtolower($routes[$url_path]));
     } else {
         throw new \ORC\Exception\NotExistsException('404 not found');
     }
     $this->_request->set(\ORC\MVC\Request::args, $url_args);
 }
Ejemplo n.º 5
0
 private function __construct()
 {
     $config = \ORC\Core\Config::getInstance();
     $this->_all_servers = $config->get('database.servers');
     $default_server = $config->get('database.' . self::DEFAULT_NAME);
     foreach ($config->get('database') as $server => $server_cfg) {
         if ($server == 'servers') {
             continue;
         }
         $server_name = $server_cfg['server'];
         if (isset($this->_all_servers[$server_name])) {
             $server_info = $this->_all_servers[$server_name];
         } else {
             if (isset($default_server) && isset($this->_all_servers[$default_server['server']])) {
                 $server_info = $this->_all_servers[$default_server['server']];
             } else {
                 throw new SystemException('Default database is not set', $server);
             }
         }
         foreach ($server_cfg as $k => $v) {
             if ($k == 'server') {
                 continue;
             }
             $server_info[$k] = $v;
         }
         //parse the dsn
         if (!isset($server_info['dsn'])) {
             $server_info['dsn'] = $this->getDSN($server_info);
         }
         $this->_servers[$server] = $server_info;
     }
 }
Ejemplo n.º 6
0
 /**
  * get current session
  * notice that the session will be started when it's first called
  * **so we have to start the session in handler's constructor**
  * @throws SystemException
  * @throws Exception
  * @return \ORC\APP\Session\Session
  */
 public static function getInstance()
 {
     if (isset(self::$session)) {
         return self::$session;
     }
     $config = Config::getInstance();
     $handler = $config->get('app.session.handler');
     if (empty($handler)) {
         $handler = 'php';
     }
     if ($handler == 'custom') {
         $classname = $config->get('app.session.classname');
         if (empty($classname)) {
             throw new SystemException('session handler classname is empty');
         }
     } else {
         $classname = "\\ORC\\APP\\Session\\" . $handler;
     }
     try {
         $session = new $classname();
         if ($session instanceof \ORC\APP\Session\Session) {
             self::$session = $session;
             return self::$session;
         }
     } catch (\Exception $ex) {
         throw new Exception('can not find session handler');
     }
 }
 public function execute()
 {
     $url = Config::getInstance()->get('interior.server_url');
     $connection = new Connection($url);
     $connection->usePost(false);
     pre($connection->get('knowledgepoint.get', array(), true));
     exit;
 }
 public function __construct($config_name)
 {
     $config = Config::getInstance();
     $url = $config->get('interior.' . $config_name . '.url');
     if ($url) {
         $this->url = $url;
     } else {
         throw new ConfigException('Wrong interior server config for ' . $config_name);
     }
 }
Ejemplo n.º 9
0
 public static function getCurrentURL($full_url = true)
 {
     $url = $_SERVER['REQUEST_URI'];
     if ($full_url) {
         $pathes = parse_url(Config::getInstance()->get('main_server'));
         $domain = sprintf('%s://%s', $pathes['scheme'], $pathes['host']);
         $url = $domain . $url;
     }
     return $url;
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     $config = Config::getInstance();
     $tablename = $config->get('app.session.tablename');
     if (!$tablename) {
         $tablename = 'sessions';
     }
     $this->table = $tablename;
     $this->cookie_key = sprintf('%s_sid', Application::getApp()->getName());
     parent::__construct();
 }
Ejemplo n.º 11
0
 protected function getLayoutConfig()
 {
     static $layout;
     if (!isset($layout)) {
         $config = Config::getInstance();
         $layout = new AdvancedContainer();
         foreach ($config->get('layout') as $key => $value) {
             $layout->set($key, $value);
         }
     }
     return $layout;
 }
 public function getDefaultAction()
 {
     if (!isset($this->_default_action)) {
         $default = Config::getInstance()->get('app.default');
         if (empty($default)) {
             $this->_default_action = 'Default.Index';
         } else {
             $this->_default_action = $default;
         }
     }
     return $this->_default_action;
 }
Ejemplo n.º 13
0
 /**
  * should be overwrite if want to use other tablename
  * @return \ORC\DAO\Table
  */
 protected function getTable()
 {
     static $table;
     if (!isset($table)) {
         $tablename = Config::getInstance()->get('app.file.tablename');
         if (empty($tablename)) {
             $tablename = self::DEFAULT_TABLE_NAME;
         }
         $table = new Table($tablename);
     }
     return $table;
 }
Ejemplo n.º 14
0
 /**
  * 
  * @param string $namespace
  * @return ICacher
  */
 protected function getCacher($namespace)
 {
     if (!isset($this->_cachers[$namespace])) {
         $config = Config::getInstance();
         $server_name = $config->get('crud.' . $this->_table->getServerName() . '.' . $this->_table->getTableName() . '.cache.server');
         if (!$server_name) {
             $server_name = 'default';
         }
         //make sure the namespace is unique
         $cacher_namespace = $this->resloveNamespace($namespace);
         $this->_cachers[$namespace] = CacheFactory::get($server_name, $cacher_namespace);
     }
     return $this->_cachers[$namespace];
 }
Ejemplo n.º 15
0
 protected function __construct()
 {
     $base_path = $this->getBasePath();
     if (strpos($_SERVER['REQUEST_URI'], $base_path) === 0) {
         $uri = '/' . substr($_SERVER['REQUEST_URI'], strlen($base_path));
     } else {
         Logger::getInstance('system')->addError(json_encode($_SERVER) . ':' . $base_path);
         throw new \ORC\Exception\SystemException('URL Parse Error');
     }
     $this->_uri = $uri;
     if (substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0, 5) == 'https') {
         $protocol = 'https';
     } else {
         $protocol = 'http';
     }
     //set main server
     $main_server = $protocol . '://' . $_SERVER['HTTP_HOST'] . $base_path;
     \ORC\Core\Config::getInstance()->set('main_server', $main_server);
     //var_dump($this->getBaseURL(), $this->getBasePath());
 }
Ejemplo n.º 16
0
 public function auth()
 {
     // TODO Auto-generated method stub
     $ip = Util::getIP();
     $config = Config::getInstance();
     $ips = $config->get('interior.ip');
     foreach ($ips as $ip_range) {
         if (strpos($ip_range, ',')) {
             list($start_ip, $end_ip) = explode(',', $ip_range);
             if (Util::inValidIPRange($ip, $start_ip, $end_ip)) {
                 return true;
             }
         } else {
             if ($ip == $ip_range) {
                 return true;
             }
         }
     }
     return $this->sendAccessDined();
 }
Ejemplo n.º 17
0
 /**
  * 
  * @throws SystemException
  * @return \ORC\APP\User\IUser
  */
 public static function me()
 {
     //first try to restore the current user
     $user = Session::getInstance()->get(self::SESSION_KEY);
     if (empty($user) || !$user instanceof \ORC\APP\User\IUser) {
         //create a new user object
         $classname = Config::getInstance()->get('app.user.classname');
         if (empty($classname)) {
             $classname = "\\ORC\\APP\\User\\User";
         }
         if (class_exists($classname)) {
             $user = new $classname();
             if ($user instanceof \ORC\APP\User\IUser) {
                 Session::getInstance()->set(\ORC\APP\User::SESSION_KEY, $user);
                 return $user;
             }
         }
         throw new SystemException('Unknown User Class', $user);
     }
     return $user;
 }
 protected static function create($name, $namespace)
 {
     $servers = Config::getInstance()->get('cache.servers');
     $config = Config::getInstance()->get('cache.' . $name);
     $server = $config['server'];
     if (isset($servers[$server])) {
         $server_info = $servers[$server];
         if (isset($config['namespace'])) {
             $server_info['namespace'] = $config['namespace'];
         }
         $namespace = self::resolveNamespace($server_info, $namespace);
         return self::createCacher($server_info, $name, $namespace);
     } else {
         //             $server_info = $servers['default'];
         //             if (isset($config['namespace'])) {
         //                 $server_info['namespace'] = $config['namespace'];
         //             }
         //             $namespace = self::resolveNamespace($server_info, $namespace);
         //             return self::createDefaultCacher($server_info, $name, $namespace);
         throw new ConfigException('Cache server for ' . $name . ' is missing');
     }
 }
Ejemplo n.º 19
0
 protected function __construct($name)
 {
     $this->_log_name = $name;
     $config = \ORC\Core\Config::getInstance();
     $servers = $config->get('log.servers');
     $server = $config->get('log.' . $name);
     if (!$server) {
         $server = $config->get('log.' . self::defaultLoggerName);
     }
     if (!$server) {
         throw new SystemException('Missing config for default logger', $name);
     }
     $server_info = $servers[$server['server']];
     foreach ($server as $k => $v) {
         if ($k == 'server') {
             continue;
         }
         $server_info[$k] = $v;
     }
     //loglevel
     if ($server_info['level']) {
         $this->_level = $server_info['level'];
     } else {
         $this->_level = self::WARNING;
     }
     //handlers
     if (isset($server_info['handlers'])) {
         $handlers = $server_info['handlers'];
         foreach ($handlers as $handler) {
             $this->_handlers[] = $this->explainHandler($handler);
         }
         if (count($this->_handlers) == 0) {
             $this->_handlers[] = new StreamHandler('php://stderr', $this->getLogLevel());
         }
     }
     //processer
     //@todo
     $this->_logger = new \Monolog\Logger($name, $this->getLogHandlers(), $this->getLogProcessers());
 }
 protected static function getServer($tube)
 {
     $config = Config::getInstance();
     $servers = $config->get('beanstalkd.servers');
     $routers = $config->get('beanstalkd.routers');
     if (!isset($routers[$tube])) {
         //             return new ConfigException('Unknow Router Name', $name);
         $server_name = self::DEFAULT_SERVER;
     } else {
         $server_name = $routers[$tube];
     }
     if (isset($servers[$server_name])) {
         $server = $servers[$server_name];
     } else {
         $server = $servers[self::DEFAULT_SERVER];
     }
     if (empty($server)) {
         throw new ConfigException('UNKNOW Beanstalkd Server Name');
     }
     if (!isset($server['port'])) {
         $server['port'] = self::DEFAULT_PORT;
     }
     return $server;
 }
Ejemplo n.º 21
0
 protected function getCacheExpiration()
 {
     $config = Config::getInstance();
     $expiration = $config->get('crud.' . $this->_table->getTableName() . '.cache.expire');
 }
Ejemplo n.º 22
0
 public function getTitle()
 {
     $title = '';
     if (isset($this->_title)) {
         $title = $this->_title . ' - ';
     }
     return $title . Config::getInstance()->get('template.title');
 }
Ejemplo n.º 23
0
 private function prepareReservedVariable($name)
 {
     $output = '';
     $cache_buster = Config::getInstance()->get('template.cache_buster');
     if ($cache_buster == '') {
         $cache_buster = \ORC\Util\Util::getNow();
     }
     switch ($name) {
         case 'js':
             //first get the template js
             $existing_jses = array();
             $jses = array_merge($this->_jses, $this->getViewModel()->getAllJs());
             //pre($jses, $this->_jses);
             foreach ($jses as $path) {
                 if (in_array($path, $existing_jses)) {
                     continue;
                 }
                 $existing_jses[] = $path;
                 $path = Url::getFullHttpPath($path);
                 $output .= sprintf('<script type="text/javascript" src="%s?%s"></script>', $path, $cache_buster);
             }
             break;
         case 'css':
             $existing_csses = array();
             $csses = array_merge($this->_csses, $this->getViewModel()->getAllCss());
             foreach ($csses as $css) {
                 if (!isset($existing_csses[$css['media']])) {
                     $existing_csses[$css['media']] = array();
                 }
                 if (in_array($css['path'], $existing_csses[$css['media']])) {
                     continue;
                 }
                 $existing_csses[$css['media']][] = $css['path'];
                 $css['path'] = Url::getFullHttpPath($css['path']);
                 $output .= sprintf('<link type="text/css" rel="stylesheet" href="%s?%s" media="%s" />', $css['path'], $cache_buster, $css['media']);
             }
             break;
         case 'raw_js':
             $output .= implode("\n", $this->_viewModel->getRawJs());
             break;
         case 'raw_css':
             $output .= implode("\n", $this->_viewModel->getRawCss());
             break;
         case 'title':
             $output .= $this->getViewModel()->getTitle();
             break;
     }
     return $output;
 }