Example #1
0
 /**
  * Given an action, find the controller and method responsible for
  * handling the action.
  *
  * In addition, send some extra variables to the controller
  * and initialize it.
  *
  * @param string $action
  * @return array
  */
 public function resolve_controller_callback($action)
 {
     /** @var $controller controller_abstract */
     list($controller, $method) = $this->router->route_action($action);
     $controller->init($action);
     return array($controller, $method);
 }
Example #2
0
 public function init()
 {
     $this->setRequestParams();
     $rout = new router($this->contData);
     $contName = $rout->getController();
     $this->cont = new $contName();
     $this->cont->init($this->contData);
 }
Example #3
0
 public function __construct(router $router, user $user, array $data)
 {
     $this->router = $router;
     $this->route = $router->getRoute();
     $this->user = $user;
     $this->parameters = $router->getParameters();
     $this->data = $data;
     $this->db = new db(HOST, USER, PASSWORD, DATABASE, ENCODING);
 }
Example #4
0
 public function __construct()
 {
     parent::__construct();
     if (!users_helper::isLoggedin() || !session::permission('site_access_cp', 'system')) {
         router::redirect('cp/users/login');
     }
 }
Example #5
0
 public function getJson($addWhere = '', $addSql = '', $showMax = 12)
 {
     $sort = input::getInput("mix.sort") ? input::getInput("mix.sort") : 'id';
     $order = input::getInput("mix.order") ? input::getInput("mix.order") : "asc";
     $page = input::getInput("mix.page") ? input::getInput("mix.page") : 1;
     $rows = input::getInput("mix.rows") ? input::getInput("mix.rows") : 10;
     $db = sf::getLib("db");
     if ($select) {
         $sql = $select . " ";
     } else {
         $sql = "SELECT * FROM `" . $this->table . "` ";
     }
     $addWhere && ($sql .= "WHERE " . $addWhere . " ");
     if ($addSql) {
         $sql .= $addSql . " ";
     } else {
         $sql .= " ORDER BY {$sort} {$order} ";
     }
     if (!router::get("totalnum" . $key)) {
         $query = $db->query($sql);
         $total = $db->num_rows($query);
     } else {
         $total = router::get("totalnum" . $key);
     }
     $sql .= "LIMIT " . $rows * ($page - 1) . "," . $rows;
     $query = $db->query($sql);
     while ($row = $db->fetch_array($query)) {
         $result[] = $this->fillObject($row)->toArray();
     }
     return '{"total":' . $total . ',"rows":' . json_encode($result) . '}';
 }
Example #6
0
 public function __construct()
 {
     parent::__construct();
     if (!config::item('news_blog', 'news') && uri::segment(1) != 'news') {
         router::redirect('news/' . utf8::substr(uri::getURI(), 5));
     }
 }
Example #7
0
File: pps.php Project: xpd1437/swap
 public static function dispatch()
 {
     $uri = visitor::uri();
     $target = router::parse_pps_uri($uri);
     if (config::get_module('view.default_skeleton', false) !== false) {
         if (config::get_module('view.cache_pps_in_server', false)) {
             $use_cache = false;
             if (defined('kern\\data_dir')) {
                 $version_key = config::get_kern('version_key', router::default_version_key);
                 $cache_dir = data_dir . '/cache/' . $serve_mode . '/' . $target->get_param($version_key, '0');
                 $cache_file = $cache_dir . '/' . sha1($uri) . '.cache';
                 if (is_readable($cache_file)) {
                     $use_cache = true;
                 }
             }
             if ($use_cache) {
                 $content = file_get_contents($cache_file);
             } else {
                 $content = pps_rendor::render_for($target);
                 if (!is_dir($cache_dir)) {
                     @mkdir($cache_dir, 0777, true);
                 }
                 @file_put_contents($cache_file, $content);
             }
         } else {
             $content = pps_rendor::render_for($target);
         }
     } else {
         $content = '';
     }
     visitor::set_content($content);
 }
Example #8
0
 public function signUP($username, $pass, $passControl)
 {
     if ($pass !== $passControl) {
         return 'The passwords do not match.';
     }
     if (!ctype_alnum(str_replace(array('-', '_'), '', $username))) {
         return 'This username contains forbidden characters. Please stick to alphanumerics, hyphens, and underscores.';
     }
     if (strlen(trim($username)) < 4 || strlen(trim($username)) > 32) {
         return 'Your username is either too short or too long. It has to consist of 4-32 characters.';
     }
     if (strlen(trim($pass)) < 4 || strlen(trim($pass)) > 32) {
         return 'This is not a valid password (too short or too long).';
     }
     $userRows = database::fetchRows('users', 'id', 'name', $username);
     if ($userRows->num_rows != 1) {
         $user['name'] = trim($username);
         $user['password'] = trim($pass);
         database::addRow('users', $user);
         $_SESSION['user'] = $username;
         $_SESSION['loggedIn'] = true;
         router::redirect('u/' . $username);
     } else {
         return 'This username has already been taken.';
     }
 }
Example #9
0
 public function confirm($action = '')
 {
     // Do we have necessary data?
     if (input::get('oauth_token') && input::get('oauth_verifier')) {
         // Get temporary access token
         $this->initialize(session::item('twitter', 'remote_connect', 'token'), session::item('twitter', 'remote_connect', 'secret'));
         $access = $this->twitter->getAccessToken(input::get('oauth_verifier'));
         // Do we have temporary token?
         if ($access) {
             // Get saved token
             $token = $this->getToken(0, $access['user_id']);
             // Do we have saved token or are we logging in?
             if ($token || $action == 'login' && $token) {
                 $this->users_model->login($token['user_id']);
                 router::redirect(session::item('slug') . '#home');
             } elseif (!$token || $action == 'signup') {
                 // Get user data
                 $this->initialize($access['oauth_token'], $access['oauth_token_secret']);
                 $user = $this->getUser($access['user_id']);
                 // Do we have user data?
                 if ($user && isset($user->id)) {
                     $connection = array('name' => 'twitter', 'twitter_id' => $user->id, 'token' => $access['oauth_token'], 'secret' => $access['oauth_token_secret']);
                     session::set(array('connection' => $connection), '', 'remote_connect');
                     $account = array('username' => isset($user->name) ? $user->name : '');
                     session::set(array('account' => $account), '', 'signup');
                     router::redirect('users/signup#account');
                 }
             }
         }
     }
     router::redirect('users/login');
 }
Example #10
0
 protected function _sendFeedback()
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('name' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 2, 'max_length' => 255)), 'email' => array('rules' => array('required', 'is_string', 'trim', 'valid_email', 'min_length' => 4, 'max_length' => 255)), 'subject' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 5, 'max_length' => 255)), 'message' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 10, 'max_length' => 10000)));
     if (config::item('feedback_captcha', 'feedback') == 1 || config::item('feedback_captcha', 'feedback') == 2 && !users_helper::isLoggedin()) {
         $rules['captcha'] = array('rules' => array('is_captcha'));
     }
     validate::setRules($rules);
     // Validate form values
     if (!validate::run($rules)) {
         return false;
     }
     // Get values
     $email = input::post('email');
     $subject = input::post('subject');
     $message = input::post('message') . "\n\n--\n" . input::post('name') . ' <' . input::post('email') . '>' . "\n" . input::ipaddress();
     // Send feedback
     if (!$this->feedback_model->sendFeedback($email, $subject, $message)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('send_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('message_sent', 'feedback'));
     router::redirect('feedback');
 }
Example #11
0
 public static function route()
 {
     self::$URI = isset($_SERVER['REDIRECT_URL']) ? explode('/', $_SERVER['REDIRECT_URL']) : NULL;
     self::$class = isset(self::$URI[URI_Level + 0]) ? self::$URI[URI_Level + 0] : 'main';
     self::$method = isset(self::$URI[URI_Level + 1]) ? self::$URI[URI_Level + 1] : 'index';
     $file_path = 'controllers/' . self::$class . '.php';
     if (!file_exists($file_path)) {
         self::$method = self::$class;
         self::$class = 'main';
         self::$params = isset(self::$URI[URI_Level + 1]) ? array_slice(self::$URI, URI_Level + 1) : array();
     } else {
         self::$params = isset(self::$URI[URI_Level + 2]) ? array_slice(self::$URI, URI_Level + 1) : array();
     }
     $file_path = 'controllers/' . self::$class . '.php';
     include_once $file_path;
     if (!method_exists(self::$class, self::$method)) {
         //echo '404';
         //echo self::$class, self::$method;
         show_404();
     }
     //Static Way
     //call_user_func_array(array(self::$class,self::$method),self::$params);
     //Normal?
     $class = new self::$class();
     call_user_func_array(array($class, self::$method), self::$params);
 }
Example #12
0
 public static function instance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function processInput()
 {
     if (isset($_GET['push'])) {
         $this->model->pushSettings();
         router::redirectMessage('index.php?view=device', 'Push Successful');
     }
 }
Example #14
0
 public static function Ret()
 {
     $class = __CLASS__;
     if (!self::$SINGLETON) {
         self::$SINGLETON = new $class();
     }
     return self::$SINGLETON;
 }
Example #15
0
 public function __construct()
 {
     parent::__construct();
     // Is this control panel?
     if (strtolower(uri::segment(1)) == 'cp' && !$this->isLoggedin() && (uri::segment(2) != 'users' || uri::segment(3) != 'login')) {
         router::redirect('cp/users/login');
     }
 }
Example #16
0
 /**
  * 创建唯一router实例
  * @access public
  * @static
  * @return Object routerObject
  * @example $router = router::getInstance()
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof router) {
         self::$_instance = new self();
         log::accessLog("Create router instance success");
     }
     log::returnLog(self::$_instance);
     return self::$_instance;
 }
Example #17
0
 public static function run()
 {
     spl_autoload_register(__CLASS__ . "::" . 'autoload');
     if (app_config::$use_db == true) {
         db::set_db_config(app_config::$db);
     }
     url::init(app_config::$url);
     router::route(app_config::$router, app_config::$re_route);
 }
Example #18
0
 public function __construct()
 {
     /**
      * Get the database and set the config
      */
     $db = new database();
     $db->setup($a = array('hostname' => 'localhost', 'username' => 'govhack', 'password' => 'govhack', 'database' => 'govhack_ip'))->connect();
     /**
      * Load the page controllers
      */
     $search = new search($db);
     $index = new index();
     $about = new about();
     /**
      * Get the application router
      */
     $router = new router();
     $router->add('/', $index)->add('/index', $index)->add('/about', $about)->add('/search', $search)->add('/*', $search);
     $router->route();
 }
Example #19
0
 public function confirm()
 {
     $class = uri::segment(4);
     $action = uri::segment(5) == 'signup' ? 'signup' : 'login';
     $service = $this->users_authentication_model->getService($class);
     if ($service) {
         loader::library('authentication/' . uri::segment(4), $service['settings'], 'users_authentication_' . $class . '_model');
         $this->{'users_authentication_' . $class . '_model'}->confirm($action);
     }
     router::redirect('users/login');
 }
Example #20
0
 public function __construct()
 {
     parent::__construct();
     // Is user loggedin ?
     if (!users_helper::isLoggedin()) {
         router::redirect('users/login');
     } elseif (!config::item('visitors_active', 'users')) {
         error::show404();
     }
     loader::model('users/visitors', array(), 'users_visitors_model');
 }
Example #21
0
function getColumnStr($subject = '', $orderfield = '')
{
    $result = router::get();
    $result['ordermode'] = $result['ordermode'] == 'DESC' ? 'ASC' : 'DESC';
    $result['orderfield'] = $orderfield;
    $str = array_shift($result);
    $str .= '/' . array_shift($result);
    foreach ($result as $key => $val) {
        $str .= '/' . $key . '/' . $val;
    }
    return link_to($str, $subject, array('class' => $result['ordermode']));
}
Example #22
0
 public function __construct()
 {
     parent::__construct(true);
     // Is user loggedin ?
     if (!users_helper::isLoggedin()) {
         router::redirect('users/login');
     } elseif (!config::item('invoices_active', 'billing')) {
         router::redirect('users/settings');
     }
     loader::model('billing/gateways');
     loader::model('billing/transactions');
 }
Example #23
0
 private function startController()
 {
     $router = new router();
     $controller = "controllers\\" . $router->getController();
     $this->controller = $controller;
     $this->controllerstring = "controllers_" . $router->getController();
     $obj = new $controller();
     $method = $router->getAction();
     $this->action = $method;
     try {
         $obj->{$method}();
         $this->view = $obj;
         if (!empty($obj->view)) {
             $this->viewfile = $obj->view;
         } else {
             $this->viewfile = $method;
         }
     } catch (\Exception $e) {
         $this->render = '<p class="errorMessage">' . $e->getMessage() . '</p>';
     }
 }
Example #24
0
 /**
  * Default data for main page.
  */
 public function init()
 {
     // title is globally also for 404 pages.
     $serial_title = property::getInstance()->get('seo_title');
     $serial_desc = property::getInstance()->get('seo_description');
     $serial_keywords = property::getInstance()->get('seo_keywords');
     $this->metadata['title'][] = $serial_title[language::getInstance()->getUseLanguage()];
     if (router::getInstance()->isMain()) {
         $this->metadata['description'][] = $serial_desc[language::getInstance()->getUseLanguage()];
         $this->metadata['keywords'][] = $serial_keywords[language::getInstance()->getUseLanguage()];
     }
     $this->metadata['global_title'] = $serial_title[language::getInstance()->getUseLanguage()];
 }
Example #25
0
 public function delete()
 {
     // Get URI vars
     $typeID = (int) uri::segment(6);
     $fieldID = (int) uri::segment(7);
     // Get user type
     if (!$typeID || !($type = $this->users_types_model->getType($typeID))) {
         view::setError(__('no_type', 'users_types'));
         router::redirect('cp/userstypes');
     }
     // Delete profile question
     $this->deleteField('users', 'users_data_' . $type['keyword'], $typeID, $fieldID);
 }
 public function index()
 {
     if ($_POST) {
         if ($this->model->Feedback($_POST)) {
             Session::setSession('done', 'Ваше письмо отправлено!');
             router::redirect($_SERVER['REQUEST_URI']);
             exit;
         } else {
             Session::setSession('done', 'Ошибка в отправлении письма!');
             router::redirect($_SERVER['REQUEST_URI']);
         }
     }
 }
Example #27
0
 function start()
 {
     db::connect();
     if (!router::get(1)) {
         return true;
     }
     self::$map = array('mode' => router::get(0), 'app' => router::get(1), 'module' => 'main', 'action' => router::get(2), 'id' => router::get(4));
     s::set('SYS_PATH', 'http://' . SERVER . SYS_DIR);
     define('APP', APPS . self::get('app') . '/');
     s::set('APP', APP);
     define('MODULE', APP . self::get('module') . '/');
     s::set('MODULE', MODULE);
     if (stristr(self::$map['mode'], 'admin')) {
         self::$map['mode'] = 'admin';
     } else {
         self::$map['mode'] = 'web';
     }
     if (self::$map['mode'] == 'admin') {
         if (defined('ADMIN_USER_SITE_ID')) {
             admin::observer();
             define('ADMIN_SITE_ID', ADMIN_USER_SITE_ID);
             s::set('ADMIN_SITE_ID', ADMIN_USER_SITE_ID);
             db::table('admin_sites');
             db::where('site_id', ADMIN_USER_SITE_ID);
             db::limit(1);
             $row = db::select();
             define('ADMIN_SITE', db::get('site_domain'));
             s::set('ADMIN_SITE', ADMIN_SITE);
         }
     } else {
         web::getSite();
         $lang = lang::gets(LANG_INDEX, SITE_ID);
         /*
         	Authentification webUser
         */
         web::observer();
     }
     /*
     	Set params
     */
     params::send();
     if (router::get(0) == 'feed' || router::get(0) == 'rss') {
         self::$map['module'] = 'feed';
     }
     if (self::$map['mode'] == 'admin') {
         load::module(self::get('app'), self::get('module'), self::get('action'));
     } else {
         load::handler(self::get('app'), self::get('module'), self::get('action'));
     }
 }
Example #28
0
 /**
  * @author Damien Lasserre <*****@*****.**>
  */
 public function __construct()
 {
     /** @var string $_layout */
     $_layout = APPLICATION_PATH . '/application/layout/layout.phtml';
     /** @var router $_router */
     $_router = new router();
     if (null !== $_router->root_url) {
         $this->_path = $_router->root_url;
     }
     if (null !== $_router->getLayoutAssign()) {
         foreach ($_router->getLayoutAssign() as $key => $value) {
             $this->{$key} = $value;
         }
     }
     $this->_display_layout = $_router->_display_layout;
     $this->_view = $_router->_view;
     if ($this->_display_layout and file_exists($_layout)) {
         /** @noinspection PhpIncludeInspection */
         require_once $_layout;
     } else {
         $this->content();
     }
 }
Example #29
0
 public function getTemplatePath($action = '')
 {
     if (empty($this->template)) {
         if (empty($action)) {
             $action = application::getAction();
         }
         $module = application::getModule();
         $controller = application::getController();
         $path = zotop::module($module, 'path');
         $path = $path . DS . router::application() . DS . 'template' . DS . $controller . DS . $action . '.php';
         return $path;
     }
     return $this->template;
 }
Example #30
0
 public function checkout()
 {
     // Get URI vars
     $planID = (int) uri::segment(4);
     $gatewayID = uri::segment(5);
     // Get plan
     if (!$planID || !($plan = $this->plans_model->getPlan($planID, false)) || !$plan['active']) {
         view::setError(__('no_plan', 'billing_plans'));
         router::redirect('billing/plans');
     }
     $retval = $this->process($gatewayID, session::item('user_id'), 'plans', $planID, $plan['name'], $plan['price'], '', 'billing/plans');
     if (!$retval) {
         router::redirect('billing/plans/payment/' . $planID);
     }
 }