コード例 #1
0
 /**
  * 构造
  * 
  * @param array $params => array (
  *     host     => (string) 主机,默认值为空
  *     port     => (int) 端口,默认值为空
  *     
  *     prefix   => (string) 缓存名前缀,默认值为空
  * )
  * @return Cache_Abstract
  */
 public function __construct($params)
 {
     $this->_exception = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $this->_exception->sendHttpStatus(500);
         }
     }
     $this->_params = $params;
 }
コード例 #2
0
ファイル: Exceptions.php プロジェクト: lpeska/UPComp
 public static function get_instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Database();
     }
     return self::$instance;
 }
コード例 #3
0
 /**
  * 获取实例
  *
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #4
0
ファイル: App.php プロジェクト: kissthink/MiniFramework
 /**
  * 调派
  */
 private function dispatch()
 {
     $this->controller = $this->_router->_controller;
     $this->action = $this->_router->_action;
     $controllerName = ucfirst($this->controller) . 'Controller';
     $controllerFile = APP_PATH . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . $controllerName . '.php';
     if (file_exists($controllerFile)) {
         include_once $controllerFile;
     } else {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Controller "' . $controllerFile . '" not found.');
         } else {
             $this->_exception->sendHttpStatus(404);
         }
     }
     if (class_exists($controllerName)) {
         $controller = new $controllerName();
     } else {
         if ($this->_exception->throwExceptions()) {
             throw new Exception($controllerName . ' does not exist.');
         } else {
             $this->_exception->sendHttpStatus(404);
         }
     }
     $action = $this->_router->_action . 'Action';
     if (method_exists($controller, $action)) {
         $controller->{$action}();
     } else {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Action "' . $this->_router->_action . '" does not exist.');
         } else {
             $this->_exception->sendHttpStatus(404);
         }
     }
 }
コード例 #5
0
ファイル: Planet.php プロジェクト: riaf/Planet
 /**
  * Planet クロールする
  **/
 public static function __setup_crawl__()
 {
     $http_feed = new Feed();
     foreach (C(PlanetSubscription)->find_all() as $subscription) {
         Exceptions::clear();
         Log::debug(sprintf('[crawl] feed: %d (%s)', $subscription->id(), $subscription->title()));
         try {
             $feed = $http_feed->do_read($subscription->rss_url());
             $subscription->title($feed->title());
             if ($feed->is_link()) {
                 $subscription->link(self::_get_link_href($feed->link()));
             }
             $subscription->rss_url($http_feed->url());
             $subscription->save(true);
             foreach ($feed->entry() as $entry) {
                 Exceptions::clear();
                 try {
                     $planet_entry = new PlanetEntry();
                     $planet_entry->subscription_id($subscription->id());
                     $planet_entry->title(Tag::cdata($entry->title()));
                     $planet_entry->description(Text::htmldecode(Tag::cdata($entry->fm_content())));
                     $planet_entry->link($entry->first_href());
                     $planet_entry->updated($entry->published());
                     $planet_entry->save();
                 } catch (Exception $e) {
                     Log::warn($e->getMessage());
                 }
             }
         } catch (Exception $e) {
             Log::error($e);
         }
     }
 }
コード例 #6
0
ファイル: DbWriter.php プロジェクト: remyguillaume/GRest
 public function Delete($object, $objectId)
 {
     $query = "delete from {$object} where Id={$objectId}";
     $nbRows = mysql_query($query) or die(mysql_error() . "\n" . $query);
     if ($nbRows == 0) {
         Exceptions::InternalServerErrorException('Data could not be deleted.');
     }
 }
コード例 #7
0
ファイル: class.Permission.php プロジェクト: rogerp91/OC
 /**
  * Get permissions from messagin_group table
  * @return void
  */
 function __construct()
 {
     try {
         $sth = DB::prep("SELECT groups,banned,history FROM messaging_groups WHERE id = (SELECT `group` FROM messaging_admin WHERE id = :id)");
         $sth->bindParam(":id", $_SESSION['userid'], PDO::PARAM_INT);
         $this->result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
コード例 #8
0
 public function __construct(string $file, string $message = NULL, $changed = NULL)
 {
     if ($data = lang($file, $message, $changed)) {
         $message = $data;
     } else {
         $message = $file;
     }
     $debug = Debug::next();
     echo Exceptions::continue($message, $debug->file, $debug->line);
 }
コード例 #9
0
ファイル: class.AddMsg.php プロジェクト: rogerp91/OC
 public function __construct($m, $to_user, $html = false)
 {
     $this->to_user = $to_user;
     try {
         $this->SetMsg($m, $html);
         $this->InsertMessage();
         $this->InsertHistory();
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
コード例 #10
0
ファイル: class.UserBan.php プロジェクト: rogerp91/OC
 /**
  * Check if user is banned or not
  *
  * @param Integer 
  * @return Integer
  * @author  
  */
 public static function IsBanned($ip)
 {
     try {
         $sth = DB::prep("SELECT COUNT(*) as c FROM messaging_ban WHERE ip = INET_ATON(:ip)");
         $sth->bindParam(":ip", $ip, PDO::PARAM_STR);
         $result = DB::getFirst($sth, null, PDO::FETCH_OBJ);
         return $result->c;
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
コード例 #11
0
ファイル: View.php プロジェクト: kissthink/MiniFramework
 /**
  * 渲染
  * 
  */
 public function display()
 {
     $viewTpl = APP_PATH . DIRECTORY_SEPARATOR . 'Views' . DIRECTORY_SEPARATOR . strtolower($this->_controller) . DIRECTORY_SEPARATOR . $this->_action . '.php';
     if (file_exists($viewTpl)) {
         $this->_render = $viewTpl;
     } else {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('View "' . $this->_action . '" does not exist.');
         } else {
             $this->_exception->sendHttpStatus(404);
         }
     }
     include $this->_render;
 }
コード例 #12
0
ファイル: class.UserBan.php プロジェクト: rogerp91/OC
 /**
  * Ban user with id
  * 
  * @param Integer User id
  * @return void
  * @author  
  */
 public static function BanUser($id)
 {
     try {
         $user = self::GetUser($id);
         $ip = $user->ip;
         $host = gethostbyaddr($ip);
         $sth = DB::prep("INSERT INTO messaging_ban (ip,host) VALUES( INET_ATON(:ip), :host) ");
         $sth->bindParam(":ip", $ip, PDO::PARAM_STR);
         $sth->bindParam(":host", $host, PDO::PARAM_STR);
         $sth->execute();
         self::DeleteUser($id);
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
コード例 #13
0
ファイル: Exceptions.php プロジェクト: hisaboh/w2t
 public static function add(Exception $exception, $name = null)
 {
     if (self::$self === null) {
         self::$self = new self();
     }
     if ($exception instanceof self) {
         foreach ($exception->messages as $e) {
             self::add($e);
         }
     } else {
         self::$self->messages["exceptions"][] = $exception;
         if ($name !== null) {
             self::$self->messages[$name][] = $exception;
         }
     }
 }
コード例 #14
0
ファイル: OpenpearTimeline.php プロジェクト: nequal/Openpear
 protected function __create_verify__($commit)
 {
     if ($this->type == 'favorite') {
         try {
             $timeline = C(__CLASS__)->find_get(Q::eq('type', 'favorite'), Q::eq('maintainer_id', $this->maintainer_id), Q::eq('package_id', $this->package_id));
             if ($timeline instanceof OpenpearTimeline) {
                 Exceptions::add(new RuntimeException());
                 return false;
             }
         } catch (NotfoundDaoException $e) {
             # pass
         } catch (Exception $e) {
             Log::debug($e);
         }
     }
 }
コード例 #15
0
ファイル: class.VarTest.php プロジェクト: rogerp91/OC
 public static function Length($min, $max, $string, $exception = 0, $ex_code = 0)
 {
     try {
         $min = (int) $min;
         $max = (int) $max;
         if ($min == 0 or $max == 0) {
             throw new Exception(e400, 400);
         }
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
     if (strlen($string) >= $min and strlen($string) <= $max) {
         return true;
     } else {
         throw new Exception($exception, $ex_code);
     }
 }
コード例 #16
0
 /**
  * 构造
  * 
  * @param array $params => array (
  *     host         => (string) 主机,默认值为localhost
  *     dbname       => (string) 数据库名
  *     username     => (string) 用户名
  *     passwd       => (string) 密码
  * 
  *     port         => (string) 端口
  *     charset      => (string) 字符集编码,默认值为utf8
  *     persistent   => (boolean) 是否启用持久连接,默认值为false
  * )
  * @return Db_Abstract
  */
 public function __construct($params)
 {
     $this->_exception = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($this->_exception->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $this->_exception->sendHttpStatus(500);
         }
     }
     if (!isset($params['charset'])) {
         $params['charset'] = 'utf8';
     }
     if (!isset($params['persistent'])) {
         $params['persistent'] = false;
     }
     $this->_params = $params;
 }
コード例 #17
0
ファイル: Controller.php プロジェクト: Rockbeat-Sky/framework
 /**
  * Start initialize controller
  * 
  * @param string
  * @param array
  * @return void
  */
 public function __init($method, $params)
 {
     $this->SKY = (object) ['method' => $method, 'params' => $params];
     // is class have method ?
     if (!method_exists($this, $method)) {
         Loader::getClass('Sky.core.Log')->write(300, $method . ' Page Not Found');
         Exceptions::show404();
     }
     // run before controller if have?
     if (method_exists($this, '__before')) {
         $this->__before();
     }
     call_user_func_array([$this, $method], $params);
     // run after controller if have?
     if (method_exists($this, '__after')) {
         $this->__after();
     }
 }
コード例 #18
0
ファイル: Router.php プロジェクト: kissthink/MiniFramework
 /**
  * 构造
  * 
  */
 public function __construct()
 {
     $this->_exception = Exceptions::getInstance();
     $this->_request = Request::getInstance();
     $exceptions = Exceptions::getInstance();
     if (false === strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) {
         //Rewrite
         $this->_routeType = 'rewrite';
         $this->_uriArray = $this->parseUrlToArray();
         $controller = isset($this->_uriArray[1]) && !empty($this->_uriArray[1]) ? $this->_uriArray[1] : 'index';
         $action = isset($this->_uriArray[2]) && !empty($this->_uriArray[2]) ? $this->_uriArray[2] : 'index';
     } else {
         //GET
         $this->_routeType = 'get';
         if (empty($_SERVER['QUERY_STRING'])) {
             $controller = 'index';
             $action = 'index';
         } else {
             parse_str($_SERVER['QUERY_STRING'], $urlParams);
             $controller = isset($urlParams['c']) ? $urlParams['c'] : 'index';
             $action = isset($urlParams['a']) ? $urlParams['a'] : 'index';
         }
     }
     if ($this->checkRoute($controller)) {
         $this->_controller = $controller;
     } else {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Controller "' . $controller . '" not found.');
         } else {
             $exceptions->sendHttpStatus(404);
         }
     }
     if ($this->checkRoute($action)) {
         $this->_action = strtolower($action);
     } else {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Action "' . $action . '" does not exist.');
         } else {
             $exceptions->sendHttpStatus(404);
         }
     }
 }
コード例 #19
0
ファイル: Cache.php プロジェクト: sujinw/MiniFramework
 /**
  * 工厂模式获取缓存实例
  * 
  * @param string $adapter
  * @param array $params
  */
 public static function factory($adapter = 'Memcache', $params = array())
 {
     $exceptions = Exceptions::getInstance();
     if (!is_array($params)) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter params must be in an array.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     if (!is_string($adapter) || empty($adapter)) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter name must be specified in a string.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     $adapterName = 'Cache_' . ucwords($adapter);
     if (!class_exists($adapterName, false)) {
         $adapterPath = MINI_PATH . DIRECTORY_SEPARATOR . 'Library' . DIRECTORY_SEPARATOR . 'Cache';
         $adapterFile = $adapterPath . DIRECTORY_SEPARATOR . $adapterName . '.php';
         if (!file_exists($adapterFile)) {
             if ($exceptions->throwExceptions()) {
                 throw new Exception('Adapter "' . $adapterName . '" not found.');
             } else {
                 $exceptions->sendHttpStatus(500);
             }
         }
         require_once $adapterFile;
     }
     $cacheAdapter = new $adapterName($params);
     if (!$cacheAdapter instanceof Cache_Abstract) {
         if ($exceptions->throwExceptions()) {
             throw new Exception('Adapter class "' . $adapterName . '" does not extend Cache_Abstract.');
         } else {
             $exceptions->sendHttpStatus(500);
         }
     }
     return $cacheAdapter;
 }
コード例 #20
0
ファイル: Cache.php プロジェクト: Rockbeat-Sky/framework
 /**
  * Write or create new cache file
  *
  * @param string
  * @param string | html
  * @return void
  */
 function write($filename, $content)
 {
     if (!Config::read('App.Base.enable_cache')) {
         return;
     }
     $expire = time() + $this->getConfig('cache_expiration') * 60;
     $filename = md5($filename);
     $filepath = $this->getConfig('cache_path') . $filename . '.tmp';
     if (!($fp = @fopen($filepath, 'w'))) {
         Loader::getClass('Sky.core.Log')->write(400, 'Unable to write cache file: ' . $filepath);
         Exceptions::showError('error', "Unable to write cache file: " . $filepath);
     }
     if (flock($fp, LOCK_EX)) {
         fwrite($fp, $expire . 'T_SKY-->' . $content);
         flock($fp, LOCK_UN);
     } else {
         Loader::getClass('Sky.core.Log')->write(300, 'Unable to secure a file lock for file at: ' . $filepath);
         return;
     }
     fclose($fp);
     @chmod($filepath, 0755);
 }
コード例 #21
0
 public function login_condition(Request $request)
 {
     if ($request->user() instanceof OpenpearMaintainer) {
         return true;
     }
     if ($request->is_post() && $request->is_vars('login') && $request->is_vars('password')) {
         try {
             $user = C(OpenpearMaintainer)->find_get(Q::ob(Q::b(Q::eq('name', $request->in_vars('login'))), Q::b(Q::eq('mail', $request->in_vars('login')))));
             if ($user instanceof OpenpearMaintainer) {
                 if ($user->certify($request->in_vars('password'))) {
                     $request->user($user);
                     return true;
                 } else {
                     Exceptions::add(new Exception('password is incorrect'), 'password');
                 }
             }
         } catch (Exception $e) {
             Log::debug($e);
         }
     }
     return false;
 }
コード例 #22
0
ファイル: class.UsersAndGroups.php プロジェクト: rogerp91/OC
 /**
  * Returns group information from database
  *
  * @return Object
  * @author  Gregor Kuplenik, gregor.kuplenik@insis.si
  */
 public static function GetGroup($id)
 {
     try {
         $sth = DB::prep("SELECT * FROM messaging_groups WHERE id = :id");
         $sth->bindParam(":id", $id, PDO::PARAM_INT);
         return DB::getFirst($sth, null, PDO::FETCH_OBJ);
     } catch (Exception $e) {
         Exceptions::PrintOut($e);
     }
 }
コード例 #23
0
ファイル: Flow.php プロジェクト: satully/dev_socialapp
 private static function parse_map(Tag $map_tag, $url, $path, $scope, $base_class, $secure, $update, $map_index, $get_meta)
 {
     $params = $args = $vars = $modules = $meta = array();
     if (!$map_tag->is_param('class')) {
         $map_tag->param('class', $base_class);
     }
     $params['url'] = $url;
     $params['scope'] = $scope;
     $params['map_index'] = $map_index;
     $params['redirect'] = File::path_slash($map_tag->in_param('redirect'), false, false);
     $params['template'] = File::path_slash($map_tag->in_param('template'), false, false);
     $params['secure'] = $map_tag->in_param('secure', $secure) === 'true';
     $params['update'] = $map_tag->in_param('update', $update) === 'true';
     if (!empty($params['template']) && !empty($path)) {
         $params['template'] = $path . '/' . $params['template'];
     }
     foreach (array('class', 'method', 'name') as $c) {
         $params[$c] = $map_tag->in_param($c);
     }
     foreach ($map_tag->in('module') as $t) {
         $modules[] = self::parse_module($t);
     }
     foreach ($map_tag->in('var') as $t) {
         $vars[] = self::parse_var($t);
     }
     foreach ($map_tag->in('arg') as $a) {
         $args[$a->in_param('name')] = $a->in_param('value', $a->value());
     }
     if ($get_meta) {
         $meta['summary'] = $map_tag->in_param('summary');
     }
     list($params['vars'], $params['modules'], $params['args'], $params['meta']) = array($vars, $modules, $args, $meta);
     if (!empty($params['class']) && empty($params['method'])) {
         Exceptions::add(new InvalidArgumentException('map `' . $map_tag->plain() . '` method not found'));
     }
     if (!empty($params['method']) && empty($params['class'])) {
         Exceptions::add(new InvalidArgumentException('map `' . $map_tag->plain() . '` class not found'));
     }
     return $params;
 }
コード例 #24
0
ファイル: Exceptions.php プロジェクト: qlixes/springphp
function show_error($heading, $message)
{
    $exceptions =& Exceptions::instance();
    $exceptions->show_error($heading, $message);
}
コード例 #25
0
 /**
  * 新規作成時検証
  */
 protected function __create_verify__($commit)
 {
     if (!$this->new_password()) {
         Exceptions::add(new Exception('Subversion Password is required'), 'new_password');
     }
     if (!$this->new_password_conf() || $this->new_password() !== $this->new_password_conf()) {
         Exceptions::add(new Exception('Incorrect Confirm Password'), 'new_password_conf');
     }
 }
コード例 #26
0
ファイル: URI.php プロジェクト: Rockbeat-Sky/framework
 /**
  * Filter segments for malicious characters
  *
  * @access	private
  * @param	string
  * @return	string
  */
 private function _filter_uri($str)
 {
     if ($str != '' && $this->getConfig('permitted_uri_chars') != '' && $this->getConfig('enable_query_strings') == FALSE) {
         // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
         // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
         if (!preg_match("|^[" . str_replace(array('\\-', '\\-'), '-', preg_quote($this->getConfig('permitted_uri_chars'), '-')) . "]+\$|i", $str)) {
             Exceptions::showError('Server Error', 'The URI you submitted has disallowed characters.');
         }
     }
     // Convert programatic characters to entities
     $bad = array('$', '(', ')', '%28', '%29');
     $good = array('&#36;', '&#40;', '&#41;', '&#40;', '&#41;');
     return str_replace($bad, $good, $str);
 }
コード例 #27
0
ファイル: history.php プロジェクト: rogerp91/OC
<?php

$perms = new Permission();
if (!$perms->IsAllowed('history')) {
    Exceptions::PrintOut("You do not have access to the History");
}
/**
 * Check $_POST variables for "search"
 */
$post_check = Post::Check(array("search"));
if ($post_check) {
    /**
     * If variable is passed, search for the historic messages with passed variable
     */
    $historic = History::SearchHistory($_POST['search']);
} else {
    /**
     * Else output the default historic messages
     */
    $historic = History::ListHistory();
}
include 'views/template/history.html';
コード例 #28
0
ファイル: Dao.php プロジェクト: hisaboh/w2t
 private final function save_verify()
 {
     foreach ($this->self_columns() as $name => $column) {
         $type = $this->a($name, "type");
         $value = $this->{$name};
         if ($this->a($name, "require") === true && ($value === "" || $value === null)) {
             Exceptions::add(new Exception($name . " required"));
         }
         if ($this->a($name, "unique") === true) {
             $q = array(Q::eq($name, $value));
             foreach ($this->primary_columns() as $column) {
                 if (null !== ($value = $this->{$column->name()}())) {
                     $q[] = Q::neq($column->name(), $this->{$column->name()}());
                 }
             }
             if (0 < call_user_func_array(array(C($this), "find_count"), $q)) {
                 Exceptions::add(new Exception($name . " unique"));
             }
         }
     }
     foreach ($this->self_columns() as $column) {
         if (!$this->{"is" . ucfirst($column->name())}()) {
             Exceptions::add(new Exception("verify fail"));
         }
     }
     $this->__save_verify__();
     Exceptions::validation();
 }
コード例 #29
0
ファイル: new_group.php プロジェクト: rogerp91/OC
<?php

$perms = new Permission();
if (!$perms->IsAllowed('groups')) {
    Exceptions::PrintOut("You do not have access to the Users and groups");
}
/**
 * Check if post names are set
 */
$post_check = Post::Check(array("title", "users", "banned", "history"));
/**
 * If post names are all set, try to insert the group
 */
if ($post_check) {
    $new_user = new UsersAndGroups();
    $result = $new_user->NewGroup($_POST['title'], array($_POST['users'], $_POST['banned'], $_POST['history']));
    /*
     * If result is not true, output the error variable
     */
    if (!$result) {
        $error = $new_user->error;
    }
}
/**
 * Include view template file
 */
include 'views/template/new_group.html';
コード例 #30
0
ファイル: historydelete.php プロジェクト: rogerp91/OC
<?php

$perms = new Permission();
if (!$perms->IsAllowed('history')) {
    Exceptions::PrintOut("You do not have access to the History");
}
/**
 * Check $_GET for "sess" and "email"
 */
$check = Post::GCheck(array("sess", "email"));
if ($check) {
    /**
     * If passed, we delete the specific historic messages
     */
    $delete = History::DeleteConv($_GET['sess'], $_GET['email']);
    if ($delete) {
        /**
         * Delete success, return to history page
         */
        header("Location: index.php?page=history");
    } else {
        /**
         * Print out the error
         */
        Exceptions::PrintOut("There is a problem deleting the historic conversation. Either no id has been passed or id does not exists in database");
    }
}