public function run() { $iID = $this->post('id'); $iAccountID = $this->post('account_id'); (new m\Account())->del($iID); c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID])); }
/** * 启动程序 * @return [type] [description] */ public function start() { $this->init(); //数据库初使化 DB::init(); //路由初使化 Router::init(); //TODO:: 还需要支持自定义的路由 if (file_exists(APP_PATH . 'config/Router.php')) { } //调用控制器 $controllerFile = APP_PATH . MODULE . 'controller/' . CONTROLLER . CLASS_EXT; if (file_exists($controllerFile)) { include_once $controllerFile; $controller = MODULE ? MODULE : "Controller" . '\\' . CONTROLLER; $action = ACTION; $obj = new $controller(); if (method_exists($obj, $action)) { $obj->{$action}(); } else { throw new \Exception("非法操作: " . ACTION); } } else { throw new \Exception("无法加载控制器: " . CONTROLLER); } }
public function run() { $iAccountID = $this->get('id'); $oAccount = new m\Account(); $aDetail = $oAccount->getAccountDetail($iAccountID); if (empty($aDetail)) { c\Router::redirect(c\Router::genURL('Home')); } $aFields = $oAccount->getAccountFields($iAccountID); $oUser = new m\User(); $aDefaultPassword = $oUser->getDefaultPassword(); $aEmails = $oUser->getEmails(); foreach ($aFields as $k => $v) { $aFields[$k]['display'] = u\Str::partCover($v['value'], 2, 1); } sort($aFields); $aFieldNames = array_map(function ($v) { foreach ($v as $key => $value) { if ($key !== 'name') { unset($v[$key]); } } return $v; }, $aFields); $aAccountAll = $oAccount->getAllAccount(); $aSiteList = []; foreach ($aAccountAll as $aAccountDetail) { $aSiteList[] = ['name' => 'link:' . $aAccountDetail['name']]; } $aData = ['page_title' => 'Open Sesame - ' . $aDetail['name'], 'app' => $aDetail, 'fields' => $aFields, 'form_action_add' => c\Router::genURL('AddField'), 'form_action_del' => c\Router::genURL('DeleteField'), 'form_action_updatefield' => c\Router::genURL('UpdateField'), 'form_action_updateaccount' => c\Router::genURL('UpdateAccount'), 'site_list' => json_encode($aSiteList), 'field_names' => json_encode($aFieldNames), 'default_password' => $aDefaultPassword['data'], 'emails' => $aEmails['data']]; return $aData; }
/** *Redirect **/ public function redirect($url, $code = null) { if ($code == 301) { header("HTTP/1.1 301 Moved Permanently"); } header("location: " . Router::url($url)); }
public function run() { error_reporting(Config::get('app.debug') ? E_ALL : 0); //Set Date Timezone date_default_timezone_set(Config::get('app.timezone')); //Set Cache Ctatus ini_set('opcache.revalidate_freq', Config::get('app.cache') ? '0' : '1'); try { static::stripTraillingSlash(); $this->session->start(); Router::init(); $routerParams = Router::getParams(); $this->handleMiddlewares($routerParams); $controllerParams = []; foreach ($routerParams as $paramName => $paramValue) { if (substr($paramName, 0, 1) != '_') { $controllerParams[$paramName] = $paramValue; } } if (isset($routerParams['_params']) && is_array($routerParams['_params'])) { foreach ($routerParams['_params'] as $paramName => $paramValue) { $controllerParams[$paramName] = $paramValue; } } $controllerFullName = '\\App\\Controllers\\' . $routerParams['_controller']; try { return $this->di->call($controllerFullName . '::' . $routerParams['_method'], $controllerParams); } catch (Exception $e) { new ExceptionHandler($e); } } catch (Exception $e) { new ExceptionHandler($e); } return true; }
public function run($config) { $this->extr($config); //раскручиваем конфиг Router::init()->run(); //вызываем роутер }
public function __construct() { $app = App::getInstance(); // On initialise l'objet Request if ($_ENV['USE_ROUTES']) { require '../Config/routes.php'; $this->request = Router::run(new Request($app)); } else { $this->request = new Request($app); } // On parse l'url (définition du controller, action,...) Router::parse($this->request); // On affiche les erreurs ? Debug::set(); // On charge le bon controller try { $controller = $this->loadController(); } catch (SwithException $e) { (new SwithError(['message' => "Le controller {$this->request->controller} est introuvable", "title" => "Controlleur introuvable"]))->display(); } if (method_exists($controller, "beforeRender")) { $controller->beforeRender(); } // On appelle la fonction $action = $this->request->getAction(); $availablesActions = array_diff(get_class_methods($controller), get_class_methods(get_parent_class($controller))); if (in_array($action, $availablesActions)) { call_user_func_array([$controller, $action], $this->request->params); } else { (new SwithError(['message' => "Le controller {$this->request->controller} n'a pas de methode {$action}", "title" => "Methode introuvable"]))->display(); } $controller->render($controller->view); }
/** * Routes for this Members Module */ public function routes() { Router::any('members', 'Modules\\Members\\Controllers\\Members@members'); Router::any('online-members', 'Modules\\Members\\Controllers\\Members@online'); Router::any('profile/(:any)', 'Modules\\Members\\Controllers\\Members@viewProfile'); Router::any('edit-profile', 'Modules\\Members\\Controllers\\Members@editProfile'); }
public function run() { $sFieldName = $this->post('field_name'); $sFieldValue = $this->post('field_value'); $iAccountID = $this->post('account_id'); (new m\Account())->addField($sFieldName, $sFieldValue, $iAccountID); c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID])); }
public function run() { $sAccountName = $this->post('account_name'); $sAccountURL = 'http://' . parse_url($this->post('account_url'))['host']; $iAccountID = $this->post('account_id'); (new m\Account())->updateAccount($sAccountName, parse_url($sAccountURL)['host'], $iAccountID, false); c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID])); }
public function run() { $sName = $this->post('name'); $sURL = $this->post('url'); $aURLDetail = parse_url($sURL); $iAccountID = (new m\Account())->addAccount($sName, $aURLDetail['host']); c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID])); }
public function routes() { Router::any('AdminPanel', 'Modules\\AdminPanel\\Controllers\\AdminPanel@dashboard'); Router::any('AdminPanel-Users', 'Modules\\AdminPanel\\Controllers\\AdminPanel@users'); Router::any('AdminPanel-User/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@user'); Router::any('AdminPanel-Groups', 'Modules\\AdminPanel\\Controllers\\AdminPanel@groups'); Router::any('AdminPanel-Group/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@group'); }
public function routes() { Router::any('Profile/(:any)', 'Modules\\Profile\\Controllers\\Profile@viewprofile'); Router::any('Profile', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error'); Router::any('Profile_Error', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error'); Router::any('Profile_Error/(:any)', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error'); Router::any('EditProfile', 'Modules\\Profile\\Controllers\\Profile@profile_edit'); Router::any('PrivacySettings', 'Modules\\Profile\\Controllers\\Profile@privacy_settings'); }
public static function nested($class, $offset = 1) { if (!isset(\Core\Router::$uriParts[$offset])) { return; } $next = \Core\Router::$uriParts[$offset]; $parts = array_slice(explode('\\', $class), 1); $path = strtolower(implode(DIRECTORY_SEPARATOR, $parts)); \Core\Router::controller($path, $next); }
public function run() { $oAccount = new m\Account(); $iTotal = $oAccount->getTotal(); if ($iTotal === false) { $oAccount->createTable(); } $aData = ['page_title' => 'Open Sesame', 'form_action_add' => c\Router::genURL('AddAccount'), 'site_total' => $iTotal, 'recomm' => (new m\Recommand())->get(4)]; return $aData; }
/** * Add assets to load * * @param string|array $name * @param string $type */ public static function add($name, $type) { if (!self::$router instanceof Router) { trigger_error('Set a instance of Router', E_USER_ERROR); return; } if (!is_array($name)) { $name = array($name); } foreach ($name as $once) { if (!isset(self::$toLoad[$type][$once])) { $assetUrl = self::$router->getAssetUrl($once, $type); if (!empty($assetUrl)) { self::$toLoad[$type][$once] = $assetUrl; } else { trigger_error('Generate asset url unsuccessful for ' . $once); } } } }
public function routes() { Router::any('Messages', 'Modules\\Messages\\Controllers\\Messages@messages'); Router::any('ViewMessage/(:any)', 'Modules\\Messages\\Controllers\\Messages@view'); Router::any('MessagesInbox', 'Modules\\Messages\\Controllers\\Messages@inbox'); Router::any('MessagesInbox/(:any)', 'Modules\\Messages\\Controllers\\Messages@inbox'); Router::any('MessagesOutbox', 'Modules\\Messages\\Controllers\\Messages@outbox'); Router::any('MessagesOutbox/(:any)', 'Modules\\Messages\\Controllers\\Messages@outbox'); Router::any('NewMessage', 'Modules\\Messages\\Controllers\\Messages@newmessage'); Router::any('NewMessage/(:any)', 'Modules\\Messages\\Controllers\\Messages@newmessage'); }
public function run() { $sKeyword = $this->get('q'); $aList = (new m\Search())->handle($sKeyword); $aOutput = []; foreach ($aList as $aAccount) { $aOutput[] = ['name' => $aAccount['name'], 'rowid' => $aAccount['rowid'], 'info_url' => c\Router::genURL('Detail', ['id' => $aAccount['rowid']]), 'goto_url' => $aAccount['value']]; } $aData = ['page_title' => '搜索结果', 'keyword' => $sKeyword, 'total' => count($aList), 'form_action_del' => c\Router::genURL('DeleteAccount'), 'site_list' => $aOutput]; return $aData; }
public function routes() { // Check to make sure Forum is Enabled, otherwise hide it if ($this->forum_on_off == 'Enabled') { Router::any('Forum', 'Modules\\Forum\\Controllers\\Forum@forum'); Router::any('Topics/(:num)', 'Modules\\Forum\\Controllers\\Forum@topics'); Router::any('Topics/(:num)/(:num)', 'Modules\\Forum\\Controllers\\Forum@topics'); Router::any('Topic/(:num)', 'Modules\\Forum\\Controllers\\Forum@topic'); Router::any('Topic/(:num)/(:num)', 'Modules\\Forum\\Controllers\\Forum@topic'); Router::any('NewTopic/(:num)', 'Modules\\Forum\\Controllers\\Forum@newtopic'); } }
public function testFindUrl() { $r = new Router($this->container); $r->addRoute('a/b', 'controller1', 'action1'); $r->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2', array('myvar1', 'myvar2')); $this->assertEquals('a/1/b/2', $r->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); $this->assertEquals('', $r->findUrl('controller2', 'action2', array('myvar1' => 1))); $this->assertEquals('a/b', $r->findUrl('controller1', 'action1')); $this->assertEquals('', $r->findUrl('controller1', 'action2')); }
function __construct() { LoaderJavascript::add("debug", "controller.init", Conf::$debug); LoaderJavascript::add("test", "controller.init"); $this->debug = new Debug($this); $this->debug->handle_errors(); if (!Conf::$install) { $this->roleUser(); } $this->request = new Request(); Router::parse($this->request->url, $this->request); }
/** * 推荐帐号。 * @param int $iSize 推荐个数。 * @return array */ public function get($iSize) { $sSQL = 'SELECT rowid, name, value FROM ' . Account::TABLE_NAME . ' WHERE valid=1 AND parent=0 ORDER BY RANDOM() LIMIT ' . $iSize; $ret = u\DB::getList($sSQL); foreach ($ret as $k => $v) { $ret[$k]['url'] = c\Router::genURL('Detail', ['id' => $v['rowid']]); } return $ret; }
public function routes() { Router::any('AdminPanel', 'Modules\\AdminPanel\\Controllers\\AdminPanel@dashboard'); Router::any('AdminPanel-Users', 'Modules\\AdminPanel\\Controllers\\AdminPanel@users'); Router::any('AdminPanel-Users/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@users'); Router::any('AdminPanel-Users/(:any)/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@users'); Router::any('AdminPanel-User/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@user'); Router::any('AdminPanel-Groups', 'Modules\\AdminPanel\\Controllers\\AdminPanel@groups'); Router::any('AdminPanel-Group/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@group'); Router::any('AdminPanel-Forum-Settings', 'Modules\\AdminPanel\\Controllers\\AdminPanel@forum_settings'); Router::any('AdminPanel-Forum-Categories', 'Modules\\AdminPanel\\Controllers\\AdminPanel@forum_categories'); Router::any('AdminPanel-Forum-Categories/(:any)/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@forum_categories'); Router::any('AdminPanel-Forum-Categories/(:any)/(:any)/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@forum_categories'); Router::any('AdminPanel-Forum-Blocked-Content', 'Modules\\AdminPanel\\Controllers\\AdminPanel@forum_blocked'); }
public static function load() { session_start(); require ROOT . '/app/Autoloader.php'; App\Autoloader::register(); require ROOT . '/core/Autoloader.php'; Core\Autoloader::register(); //regle de routing Router::prefix(PREFIX, 'admin'); Router::connect('', 'pages/show/1'); /*Router::connect(':id/categories.html','posts/category/id:([0-9]+)'); Router::connect('blog/*','posts/*'); Router::connect('cgv.html','pages/show/1');*/ Router::connect('login.html', 'users/login'); }
/** * 执行 */ public static function dispatch($pattern_map, $url) { $class_action = \Core\Router::match_all($pattern_map, $url); $parts = explode('::', $class_action); $class_file = strtolower(W_APPLICATION_PATH . $parts[0] . W_EXT); if (file_exists($class_file)) { $parts[0] = str_replace('/', '\\', $parts[0]); $class = new $parts[0](); $path = explode('/', $parts[1]); $action = array_shift($path); $class->run($action); } else { \Core\Application::abort(404, 'dispatch 404'); } }
function __construct() { $this->request = new Request(); Router::parse($this->request->url, $this->request); $controller = $this->loadController(); $action = $this->request->action; foreach ($this->request->params as $param) { $this->parametre .= $param . ", "; } $this->parametre = rtrim($this->parametre, ", "); if (empty($this->parametre)) { $controller->{$action}(); } else { $controller->{$action}($this->parametre); } }
/** * 获得一个帐号的所有记录。 * @param int $iAccountID 帐号ID。 * @return array */ public function getAccountFields($iAccountID) { $sSQL = 'SELECT *, rowid FROM ' . self::TABLE_NAME . ' WHERE parent=? AND valid=' . self::STATUS_VALID; $aResult = u\DB::getList($sSQL, [$iAccountID]); foreach ($aResult as $k => $v) { $aResult[$k]['value'] = $sRealValue = $this->decrypt(gzinflate($v['value'])); $aResult[$k]['name'] = base64_decode(gzinflate($v['name'])); if (substr($sRealValue, 0, 5) === 'link:') { $sSQLAccount = 'SELECT rowid FROM ' . self::TABLE_NAME; $sSQLAccount .= ' WHERE valid=' . self::STATUS_VALID . ' AND name=? LIMIT 1'; $sLinkAccount = substr($sRealValue, 5); $aAccountID = u\DB::getOne($sSQLAccount, [$sLinkAccount]); $aResult[$k]['link'] = c\Router::genURL('Detail', ['id' => $aAccountID['rowid']]); $aResult[$k]['linkname'] = $sLinkAccount; } } return $aResult; }
static function activationMotDePasse($mail, $login, $mdp, $ticket) { $message = ' <html> <head> <title>Activation du nouveau mot de passe</title> </head> <body> <p>Bonjour ' . $login . ',<br><br>Vous venez de faire une demande de réinitialisation de mot de passe, pour activer ce nouveau mot de passe vous devez cliquer sur le liens en dessous.<br>Si vous n\'avez pas éffectué de réinistialisation de mot de passe, merci de ne pas prendre en compte ce mail.</p> <table> <tr> <td>Votre nouveau mot de passe :</td><td>' . $mdp . '</td> </tr> </table> <a href="' . \core\Router::url("ticket/traite/" . $ticket) . '">Activer le mot de passe</a> </body> </html> '; return Mail::envoi($mail, "[Mot de passe] Réinitialisation", $message); }
public function routes() { Router::any('blog', 'Modules\\Blog\\Controllers\\Blog@index'); Router::any('blog/(:num)', 'Modules\\Blog\\Controllers\\Blog@index'); Router::any('blog/drafts', 'Modules\\Blog\\Controllers\\Blog@drafts'); Router::any('blog/drafts/(:num)', 'Modules\\Blog\\Controllers\\Blog@drafts'); Router::any('blog/my', 'Modules\\Blog\\Controllers\\Blog@my'); Router::any('blog/my/(:num)', 'Modules\\Blog\\Controllers\\Blog@my'); Router::any('blog/scheduled', 'Modules\\Blog\\Controllers\\Blog@scheduled'); Router::any('blog/scheduled/(:num)', 'Modules\\Blog\\Controllers\\Blog@scheduled'); Router::any('blog/category/(:any)', 'Modules\\Blog\\Controllers\\Blog@category'); Router::any('blog/category/(:any)/(:num)', 'Modules\\Blog\\Controllers\\Blog@category'); Router::any('blog/post/(:any)', 'Modules\\Blog\\Controllers\\Blog@post'); Router::get('blog/check-for-new-posts/(:num)/(:num)', 'Modules\\Blog\\Controllers\\Blog@checkForNewPosts'); Router::any('blog/add', 'Modules\\Blog\\Controllers\\Blog@add'); Router::any('blog/edit/(:num)', 'Modules\\Blog\\Controllers\\Blog@edit'); Router::any('blog/delete/(:num)', 'Modules\\Blog\\Controllers\\Blog@delete'); Router::any('blog/search/(:any)', 'Modules\\Blog\\Controllers\\Blog@search'); Router::any('blog/search/(:any)/(:num)', 'Modules\\Blog\\Controllers\\Blog@search'); Router::any('blog/comment/add', 'Modules\\Blog\\Controllers\\Blog@commentsAdd'); Router::any('blog/comment/delete/(:num)', 'Modules\\Blog\\Controllers\\Blog@commentsDelete'); }
/** * Permet de parser l'url (définir quel est le controller, quelle est l'action) * @param Request $request objet Request */ public static function parse(Request $request) { if (!$request->isRooted) { // On définit les prefixes s'il y en a Router::setPrefixes(); // On enlève les / en début et fin d'url $url = trim($request->url, '/'); // On créer un tableau à partir de l'URL $params = explode('/', $url); // On vérifie si on a un prefixe ou pas if (isset($params[0]) && in_array($params[0], self::$prefixes)) { // Si oui on le stock dans la request $request->prefixe = $params[0]; // et on l'enlève du tableau URL array_shift($params); } // On déinit ensuite le controlleur $request->controller = !empty($params[0]) ? $params[0] : App::getInstance()->getAppSettings("default_controller"); // On vérifie si y a pas une tentative de hack avec "l'ancien system" en vérifiant qu'on appelle pas controller/prefixe_action if (isset($params[1])) { $action = $params[1]; // On check si l'action n'est pas au format prefixe_action foreach (Self::$prefixes as $k) { if (strpos($action, $k . '_') === 0) { // Si c'est le cas on définit le prefixe et on reformat l'action $request->prefixe = $k; $action = str_replace($k . '_', '', $action); } } $request->action = $action; } else { $request->action = App::getInstance()->getAppSettings("default_action"); } $request->params = array_slice($params, 2); } }