public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(config::get('db.host'), config::get('db.name'), config::get('db.user'), config::get('db.password')); Lang::load(self::$router->getLanguage()); if ($_POST and (isset($_POST['username_in']) and isset($_POST['password_in'])) or isset($_POST['exit'])) { $us = new RegisterController(); if (isset($_POST['exit'])) { $us->LogOut(); } else { $us->Login($_POST); } } if (self::$router->getController() == 'admin' and !Session::getSession('root') or self::$router->getController() == 'myblog' and !Session::getSession('id')) { self::$router->setController(Config::get('default_controller')); self::$router->setAction(Config::get('default_action')); Session::setSession('message', 'Отказ в доступе'); } $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData()); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist'); } $layout = self::$router->getRoute(); $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
public static function run($uri) { self::$router = new Router($uri); # создаем обект базы данных и передаем параметры подключения self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); # при каждом запросе к руту admin выполняется проверка, имеет ли пользователь на это права $layout = self::$router->getRoute(); if ($layout == 'admin' && Session::get('role') != 'admin') { if ($controller_method != 'admin_login') { Router::redirect('/admin/users/login'); } } // Calling controller's method $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.'); } # код віполняющий рендеринг $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
public function viewAction($id) { $result = \App::db()->query("SELECT * FROM parsing_data WHERE `id` = ?", array($id))->fetch(); $data = unserialize($result['data']); $this->view->assign('data', $data); $this->view->render(); }
static function getDatabase() { if (!self::$db) { self::$db = new Database('root', '', 'common-database'); } return self::$db; }
public function actionLogin() { $username = isset($_POST['username']) ? trim($_POST['username']) : ''; $password = isset($_POST['password']) ? trim($_POST['password']) : ''; $validate = isset($_POST['validate']) ? trim($_POST['validate']) : ''; if (empty($username) || empty($password) || empty($validate)) { $this->location('/', array('error' => '参数错误')); } if (!ValidateCode::checkCode($validate)) { $msg = '验证码错误'; $this->location('/', array('error' => $msg)); } else { $sql = "SELECT * FROM ha_user WHERE usertype=4 and userstatus=1 and userid='{$username}' and password='******'"; $data = App::db()->getRow($sql); if (!empty($data)) { $_SESSION['user'] = $data; $_SESSION['is_login'] = 1; $code = 200; $this->location('/', array('m' => 'main')); } else { $code = 401; $msg = '用户名或密码错误'; $this->location('/', array('error' => $msg)); } } }
public static function run($uri) { self::$router = new Router($uri); self::$db = DB::getInstance(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . 'controller'; $controller_method = strtolower(self::$router->getMethod_prefix() . self::$router->getAction()); $controller_parametr = self::$router->getParams(); $layout = self::$router->getRoute(); if ($layout == 'admin' && Session::get('role') != 'admin') { if ($controller_method != 'admin_login') { Router::redirect('/admin/users/login'); } } //Calling conrollers method $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Метод ' . $controller_method . ' в классе ' . $controller_class . 'не найден'); } $layout_path = VIEW_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); // основной рендер вывода страниц echo $layout_view_object->render(); }
public function __construct() { $this->db = App::db(); $db_map = App::conf('db_map'); $this->db_name = current(array_keys($db_map)); $this->db->usedb($this->db_name); }
public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . "Controller"; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); $layout = self::$router->getRoute(); if ($layout == "admin" && Session::get("role") != "admin") { if ($controller_method != "admin_login") { Router::redirect("/admin/users/login"); } } //Calling controller's method $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception("Method {$controller_method} does not exist in {$controller_class}"); } $layout_path = VIEWS_PATH . DS . $layout . ".html"; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
static function getDatabase() { if (!self::$db) { self::$db = new Database(DB_LOGIN, DB_PASS, DB_NAME); } return self::$db; }
public static function db() { if (self::$db == null) { self::$db = new Mysql(DB_HOST, DB_USER, DB_PASS, DB_NAME, 3306); } return self::$db; }
/** * @expectedException \Magelight\Exception * @expectedExceptionMessage Database `default` configuration not found. */ public function testDbEmptyConfig() { $mysqlConfig = null; $index = \Magelight\App::DEFAULT_INDEX; $this->configMock->expects($this->once())->method('getConfig')->with('/global/db/' . $index, null)->will($this->returnValue($mysqlConfig)); $this->app->db(); }
/** * @return Db */ public static function db() { if (is_null(self::$db)) { self::$db = new Db(); } return self::$db; }
public static function start() { $router = new Router(); self::$db = self::loadDb(); self::$auth = self::loadAuth(); self::$access = self::loadAccess(); self::$router = $router::init(); }
public function getCurrentUser() { $userId = $_SESSION['user_id']; $user = App::db()->select('id, username')->where('id', $userId)->limit(1)->get(); if ($user->num_results() > 0) { return $user->row(); } return false; }
function __construct() { $login = '******'; $password = ''; $host = 'localhost'; $db = 'site'; $this->search(); self::$db = $this->connectDB($login, $password, $host, $db); include_once 'Engine/Module.class.php'; }
/** * Open a new session * * @param string $savePath Not used * @param string $name The session name (defaulty 'PHPSESSID') */ public function open($savePath, $name) { $this->db = App::db(); $this->table = DB::getFullTablename('Session'); // Update the session mtime if (App::request()->getCookies($name)) { SessionModel::getDbInstance()->update(SessionModel::getTable(), new DBExample(array('id' => App::request()->getCookies($name))), array('mtime' => time())); } // Clean expired sessions $this->gc(0); }
/** * V0.7.0 : Add the table UserOption */ public function v0_7_0() { App::db()->query('CREATE TABLE IF NOT EXISTS `' . DB::getFullTablename('UserOption') . '`( `userId` INT(11) NOT NULL DEFAULT 0, `userIp` VARCHAR(15) NOT NULL DEFAULT "", `plugin` VARCHAR(32) NOT NULL, `key` VARCHAR(64) NOT NULL, `value` VARCHAR(4096), UNIQUE INDEX(`userId`, `plugin`, `key`), UNIQUE INDEX(`userIp`, `plugin`, `key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); }
public function actionOp() { if ($this->isPost()) { $id = $_POST['id']; $val = $_POST['value']; $sql = "UPDATE ha_club SET status='{$val}' WHERE clubid={$id}"; if (App::db()->query($sql)) { $this->json(200); } else { $this->json(500, '服务器错误'); } } }
/** * @param $url * @return bool|UrlModel */ public static function findOneByLongurl($url) { $columns = static::getColumnNames(); $columnsCommaList = implode(',', $columns); $tableName = static::getTableName(); $sql = "SELECT {$columnsCommaList} FROM {$tableName} WHERE longurl = ?"; $row = App::db()->getRow($sql, array($url)); if (is_array($row)) { $model = new static(); $model->populate($row); return $model; } return false; }
public function actionDelete() { if ($this->isPost()) { $id = $_POST['id']; $sql = "delete from ha_orderdetail where orderid={$id}"; App::db()->query($sql); $sql1 = "delete from ha_order where orderid={$id}"; if (App::db()->query($sql1)) { $this->json(200); } else { $this->json(500, '删除失败'); } } }
public static function run($uri) { self::$router = new Router($uri); Lang::load(self::$router->getLanguage()); self::$db = DB::getInstance(); // if (self::$router->getRoute() == 'admin' && is_null(Session::get('user'))) { // self::$router->redirect('/admin/'); // } if (self::$router->getController() == "favicon.ico") { die; } // $test = self::$router->getController(); // echo $test."<br>"; // $test = self::renameToSafeCall($test); // echo $test."<br>"; $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); if (self::$router->getRoute() == 'admin' && is_null(Session::get('user'))) { if (strtolower(self::$router->getAction()) != 'login') { Router::redirect('/admin/users/login'); } } $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new MethodException('Cannot run method ' . $controller_method . ' on class ' . $controller_class); } $layout = self::$router->getRoute(); $layout_path = VIEWS_PATH . DS . $layout . '.php'; $array_content = array(); $array_content['content'] = $content; // exception from rules for account_count if (isset($controller_object->getData()['account_count'])) { $array_content['account_count'] = $controller_object->getData()['account_count']; } $layout_view_object = new View($array_content, $layout_path); echo $layout_view_object->render(); }
public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); $class_name = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); $controller_object = new $class_name(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); //content in obb $content = $view_object->render(); } else { echo $controller_method . 'in ' . $class_name . 'does not exist'; } $layout = self::$router->getRoute(); $layout_path = VIEW . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); // content in obb echo $layout_view_object->render(); }
/** * Save object into database */ public function save() { $columns = static::getColumnNames(); $columnsCommaList = implode(',', $columns); $tableName = static::getTableName(); $primaryKeyColumn = static::getPrimaryKey(); $valuesPlaceholders = implode(',', array_fill(0, count($columns), '?')); // -> ?, ?, ? $values = array(); foreach ($columns as $column) { $values[] = $this->{$column}; } App::db()->execute("LOCK TABLES {$tableName} WRITE"); // "transaction lock" for MyISAM tables // TODO Update object if already saved $sql = "INSERT INTO {$tableName} ({$columnsCommaList}) VALUES ({$valuesPlaceholders})"; $newPk = App::db()->execute($sql, $values); $this->{$primaryKeyColumn} = $newPk; App::db()->execute("UNLOCK TABLES"); return true; }
public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); // Calling controller's method $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { // Controller's action may return a view path $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.'); } $layout = self::$router->getRoute(); $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
public static function run($uri) { self::$router = new Router($uri); self::$db = DB::getInstance(); Lang::load(self::$router->getLanguage()); $controllerClass = ucfirst(self::$router->getController() . 'Controller'); $controllerMethod = self::$router->getMethodPrefix() . self::$router->getAction(); // Instancing the controller $controllerObject = new $controllerClass(); if (method_exists($controllerObject, $controllerMethod)) { // Controller's may return a view $viewPath = $controllerObject->{$controllerMethod}(); $viewObject = new View($controllerObject->getData(), $viewPath); $content = $viewObject->render(); } else { throw new Exception("Method {$controllerMethod} of class {$controllerClass} was not found."); } $layout = self::$router->getRoute(); $layoutPath = VIEWS_PATH . DS . $layout . '.html'; $layoutViewObj = new View(compact('content'), $layoutPath); echo $layoutViewObj->render(); }
public function searchAction() { $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : ''; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '0'; $text = isset($_REQUEST['text']) ? $_REQUEST['text'] : ''; // VALIDATE $errors = array(); if (empty($url)) { $errors[] = 'Cannot parse content for undefined url'; } if (!is_numeric($type)) { $errors[] = 'Wrong search type given'; } if ($type == \HtmlContentParser::SEARCH_TYPE_TEXT && empty($text)) { $errors[] = 'Undefined text for search on page'; } if (!empty($errors)) { $result = array('status' => 'error', 'error' => join("\n", $errors)); $this->view->renderJsonData($result); exit; } if (strpos($url, 'http://') === false) { $url = 'http://' . $url; } // GET PAGE CONTENT AND PARSE IT $pageContent = \Http::getUrlContent($url); $parser = new \HtmlContentParser($type, $pageContent); $parser->setSearchText($text); $result = $parser->parse(); // SAVE RESULT TO DATABASE \App::db()->query("INSERT INTO `parsing_data` (`host`, `type`,`data`, `count`) VALUES (?, ?, ?, ?)", array($url, $type, serialize($result), count($result))); // OUTPUT JSON $result = array('status' => 'ok', 'error' => ''); $this->view->renderJsonData($result); exit; }
public static function run($uri) { self::$router = new Router($uri); //переопределяем значение router self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); //присваиваем в $db даннные для подключения к базе Lang::load(self::$router->getLanguage()); //подгружаем язык из router.class.php $controller_class = ucfirst(self::$router->getController()) . 'Controller'; //присваеваем значение контроллера ($controller из router.class.php) $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); //присваеваем значение метода ($method_prefix из router.class.php) $layout = self::$router->getRoute(); //$route из router.class.php if ($layout == 'admin' && Session::get('role') != 'admin') { //проверяем если админ не залогинен if ($controller_method != 'admin_login') { Router::redirect('/admin/users/login'); //перенаправляем на формулогина } } // Calling controller's method $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { //method_exists — Проверяет, существует ли метод в данном классе // Controller's action may return a view path $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.'); } $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
<div class="pagination"> <ul id="pagination-digg"> <?php for ($i = 1; $i <= ceil($nbrResultat / $_SESSION['nbrResultatPage']); $i++) { echo "<li><a href='?pageResultat=" . $i . "'>" . $i . "</a></li>"; } ?> </ul> </div> </div> <table> <?php if (is_file("src/config/fr_CH.php")) { $fieldsTitles = (include "src/config/fr_CH.php"); } $fieldsNames = App::db()->getFieldsNames($tableName); echo "<tr>"; foreach ($fieldsNames as $fieldName) { if (isset($fieldsTitles[$fieldName])) { $url = AddQuerystringVar($_SERVER['REQUEST_URI'], "ORDERBY", $fieldName); echo "<th><a href='" . $url . "'>" . $fieldsTitles[$fieldName] . "</th>"; } else { echo "<th><a href='?ORDERBY=" . $fieldName . "'>" . $fieldName . "</th>"; } } echo "</tr>"; echo "<tr>"; for ($i = 0; $i < count($fieldsNames); $i++) { if (isset($_GET['queryFields'])) { $querystring = $_GET['queryFields']; if (array_key_exists($fieldsNames[$i], $querystring)) {
private final function __construct() { $this->db = \App::db($this->dbNode); $this->init(); }
public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); $layout = self::$router->getRoute(); if ($layout == 'user' && Session::get('role') != 'user') { if ($controller_method != 'login') { Router::redirect('/users/login'); } } elseif ($layout == 'admin' && Session::get('role') != 'admin') { if ($controller_method != 'admin_login') { Router::redirect('/admin/users/login'); } } $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.'); } $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }