コード例 #1
0
 protected function prepare()
 {
     $this->assign('wa_url', $this->system->getRootUrl());
     $this->assign('wa_backend_url', waSystem::getInstance()->getConfig()->getBackendUrl(true));
     $this->assign('wa_app', $this->system->getApp());
     $this->assign('wa_app_url', $this->system->getAppUrl(null, true));
     $this->assign('wa_app_static_url', $this->system->getAppStaticUrl());
     if (!$this->helper) {
         $this->helper = new waViewHelper($this);
     }
     $this->assign('wa', $this->helper);
 }
コード例 #2
0
 public function getUrl($path, $params = array(), $absolute = false)
 {
     if (is_bool($params)) {
         $absolute = $params;
         $params = array();
     }
     $parts = explode('/', $path);
     $app = $parts[0];
     if (!$app) {
         $app = $this->system->getApp();
     }
     if (isset($parts[1])) {
         $params['module'] = $parts[1];
     }
     if (isset($parts[2])) {
         $params['action'] = $parts[2];
     }
     $routes = array();
     if (!$this->route || $this->route['app'] != $app || !isset($this->route['module']) && isset($params['module']) && $params['module'] != 'frontend' || isset($this->route['module']) && isset($params['module']) && $this->route['module'] != $params['module']) {
         // find base route
         if (isset($params['domain'])) {
             $routes[$params['domain']] = $this->getRoutes($params['domain']);
             unset($params['domain']);
         } else {
             $routes = $this->routes;
         }
         // filter by app and module
         foreach ($routes as $domain => $domain_routes) {
             foreach ($domain_routes as $r_id => $r) {
                 if (!isset($r['app']) || $r['app'] != $app || isset($params['module']) && isset($r['module']) && $r['module'] != $params['module']) {
                     unset($routes[$domain][$r_id]);
                 }
             }
             if (!$routes[$domain]) {
                 unset($routes[$domain]);
             }
         }
     } else {
         $routes[$this->getDomain()] = array($this->route);
     }
     $max = -1;
     $result = null;
     foreach ($routes as $domain => $domain_routes) {
         foreach ($domain_routes as $r) {
             $i = $this->countParams($r, $params);
             if (isset($params['module']) && isset($r['module'])) {
                 $i++;
             }
             if ($absolute || $this->getDomain() != $domain) {
                 $root_url = self::getUrlByRoute($r, $domain);
             } else {
                 $root_url = $this->system->getRootUrl(false, true) . self::clearUrl($r['url']);
             }
             if ($i > $max) {
                 $max = $i;
                 $result = $root_url;
             }
             $app_routes = $this->getAppRoutes($r['app'], $r);
             foreach ($app_routes as $app_r) {
                 $j = $i + $this->countParams($app_r, $params);
                 if (!isset($params['action']) && !isset($app_r['action'])) {
                     $j++;
                 }
                 $u = $app_r['url'];
                 if (preg_match_all('/<([a-z_]+):?([^>]*)?>/ui', $u, $match, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
                     $offset = 0;
                     foreach ($match as $m) {
                         $v = $m[1][0];
                         if (isset($params[$v])) {
                             $u = substr($u, 0, $m[0][1] + $offset) . $params[$v] . substr($u, $m[0][1] + $offset + strlen($m[0][0]));
                             $offset += strlen($params[$v]) - strlen($m[0][0]);
                             $j++;
                         } else {
                             if (substr($u, $m[0][1] - 1, 1) === '(' && substr($u, $m[0][1] + strlen($m[0][0]), 3) === '/)?') {
                                 $u = substr($u, 0, $m[0][1] - 1) . substr($u, $m[0][1] + strlen($m[0][0]) + 3);
                             } else {
                                 continue 2;
                             }
                         }
                     }
                 }
                 if ($j >= $max || $result === null) {
                     if ($j == $max && $this->getDomain() && $domain != $this->getDomain() && $result) {
                     } else {
                         $max = $j;
                         $result = $root_url . self::clearUrl($u);
                     }
                 }
             }
         }
     }
     return $result;
 }
コード例 #3
0
 /** Execute appropriate controller and return it's result.
  * Throw 404 exception if no controller found. */
 public function execute($plugin = null, $module = null, $action = null, $default = false)
 {
     if (!$this->system->getConfig()->checkRights($module, $action)) {
         throw new waRightsException(_ws("Access denied."));
     }
     // current app prefix
     $prefix = $this->system->getConfig()->getPrefix();
     // Load plugin locale and set plugin as active
     if ($plugin) {
         $plugin_path = $this->system->getAppPath('plugins/' . $plugin, $this->system->getApp());
         if (!file_exists($plugin_path . '/lib/config/plugin.php')) {
             $plugin = null;
         } else {
             $plugin_info = (include $plugin_path . '/lib/config/plugin.php');
             // check rights
             if (isset($plugin_info['rights']) && $plugin_info['rights']) {
                 if (!$this->system->getUser()->getRights($this->system->getConfig()->getApplication(), 'plugin.' . $plugin)) {
                     throw new waRightsException(_ws("Access denied"), 403);
                 }
             }
             waSystem::pushActivePlugin($plugin, $prefix);
             if (is_dir($plugin_path . '/locale')) {
                 waLocale::load($this->system->getLocale(), $plugin_path . '/locale', waSystem::getActiveLocaleDomain(), false);
             }
         }
     }
     // custom login and signup
     if (wa()->getEnv() == 'frontend') {
         if (!$plugin && !$action && $module == 'login') {
             $login_action = $this->system->getConfig()->getFactory('login_action');
             if ($login_action) {
                 $controller = $this->system->getDefaultController();
                 $controller->setAction($login_action);
                 $r = $controller->run();
                 return $r;
             }
         } elseif (!$plugin && !$action && $module == 'signup') {
             $signup_action = $this->system->getConfig()->getFactory('signup_action');
             if ($signup_action) {
                 $controller = $this->system->getDefaultController();
                 $controller->setAction($signup_action);
                 $r = $controller->run();
                 return $r;
             }
         }
     }
     //
     // Check possible ways to handle the request one by one
     //
     // list of failed class names (for debugging)
     $class_names = array();
     // Single Controller (recomended)
     $class_name = $prefix . ($plugin ? ucfirst($plugin) . 'Plugin' : '') . ucfirst($module) . ($action ? ucfirst($action) : '') . 'Controller';
     if (class_exists($class_name, true)) {
         /**
          * @var $controller waController
          */
         $controller = new $class_name();
         $r = $controller->run();
         if ($plugin) {
             waSystem::popActivePlugin();
         }
         return $r;
     }
     $class_names[] = $class_name;
     // Single Action
     $class_name = $prefix . ($plugin ? ucfirst($plugin) . 'Plugin' : '') . ucfirst($module) . ($action ? ucfirst($action) : '') . 'Action';
     if (class_exists($class_name)) {
         // get default view controller
         /**
          * @var $controller waDefaultViewController
          */
         $controller = $this->system->getDefaultController();
         $controller->setAction($class_name);
         $r = $controller->run();
         if ($plugin) {
             waSystem::popActivePlugin();
         }
         return $r;
     }
     $class_names[] = $class_name;
     // Controller Multi Actions, Zend/Symfony style
     $class_name = $prefix . ($plugin ? ucfirst($plugin) . 'Plugin' : '') . ucfirst($module) . 'Actions';
     if (class_exists($class_name, true)) {
         $controller = new $class_name();
         $r = $controller->run($action);
         if ($plugin) {
             waSystem::popActivePlugin();
         }
         return $r;
     }
     $class_names[] = $class_name;
     // Plugin is no longer active
     if ($plugin) {
         waSystem::popActivePlugin();
     }
     // Last chance: default action for this module
     if ($action && $default) {
         return $this->execute($plugin, $module);
     }
     // Too bad. 404.
     throw new waException(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).<br />Not found classes: %s', $this->system->getConfig()->getCurrentUrl(), $module, $action, implode(', ', $class_names)), 404);
 }
コード例 #4
0
ファイル: waException.class.php プロジェクト: Lazary/webasyst
    public function __toString()
    {
        try {
            $wa = wa();
            $additional_info = '';
        } catch (Exception $e) {
            $wa = null;
            $additional_info = $e->getMessage();
        }
        $message = nl2br($this->getMessage());
        if ($wa && waSystem::getApp()) {
            $app = $wa->getAppInfo();
            $backend_url = $wa->getConfig()->getBackendUrl(true);
        } else {
            $app = array();
        }
        if (!waSystemConfig::isDebug() && $wa) {
            $env = $wa->getEnv();
            $file = $code = $this->getCode();
            if (!$code || !file_exists(dirname(__FILE__) . '/data/' . $code . '.php')) {
                $file = 'error';
            }
            include dirname(__FILE__) . '/data/' . $file . '.php';
            exit;
        }
        if ($wa && $wa->getEnv() == 'cli' || !$wa && php_sapi_name() == 'cli') {
            return date("Y-m-d H:i:s") . " php " . implode(" ", waRequest::server('argv')) . "\n" . "Error: {$this->getMessage()}\nwith code {$this->getCode()} in '{$this->getFile()}' around line {$this->getLine()}:{$this->getFileContext()}\n" . $this->getTraceAsString() . "\n" . ($additional_info ? "Error while initializing waSystem during error generation: " . $additional_info . "\n" : '');
        } elseif ($this->code == 404) {
            $response = new waResponse();
            $response->setStatus(404);
            $response->sendHeaders();
        }
        $request = htmlentities(var_export($_REQUEST, true), ENT_NOQUOTES, 'utf-8');
        $params = htmlentities(var_export(waRequest::param(), true), ENT_NOQUOTES, 'utf-8');
        $context = htmlentities($this->getFileContext(), ENT_NOQUOTES, 'utf-8');
        $trace = htmlentities($this->getTraceAsString(), ENT_NOQUOTES, 'utf-8');
        $result = <<<HTML
<div style="width:99%; position:relative; text-align: left;">
\t<h2 id='Title'>{$message}</h2>
\t<div id="Context" style="display: block;">
\t\t<h3>Error with code {$this->getCode()} in '{$this->getFile()}' around line {$this->getLine()}:</h3>
\t\t<pre>{$context}</pre>
\t</div>
\t<div id="Trace">
\t\t<h2>Call stack</h2>
\t\t<pre>{$trace}</pre>
\t</div>
\t<div id="Request">
\t\t<h2>Request</h2>
\t\t<pre>{$request}</pre>
    </div>
</div>
<div style="text-align: left;">
    <h2>Params</h2>
    <pre>{$params}</pre>
</div>
HTML;
        if ($additional_info) {
            $additional_info = htmlentities($additional_info, ENT_NOQUOTES, 'utf-8');
            $result .= <<<HTML

<div style="text-align: left;">
    <h2>Error while initializing waSystem during error generation</h2>
    <pre>{$additional_info}</pre>
</div>
HTML;
        }
        return $result;
    }
コード例 #5
0
 public function userRights($name)
 {
     return $this->wa->getUser()->getRights($this->wa->getApp(), $name);
 }
コード例 #6
0
 protected function prepare()
 {
     $this->smarty->compile_id = isset($this->options['compile_id']) ? $this->system->getApp() . "_" . $this->options['compile_id'] : $this->system->getApp() . "_" . $this->system->getLocale();
     parent::prepare();
 }
コード例 #7
0
 public function app()
 {
     return $this->wa->getApp();
 }
コード例 #8
-1
 /**
  * @return waPageModel
  */
 protected function getPageModel()
 {
     $class = $this->wa->getApp() . 'PageModel';
     return new $class();
 }