/** * @param waSystem $system * @param array $options * @return waSmarty3View */ public function __construct(waSystem $system, $options = array()) { parent::__construct($system, $options); $this->smarty = new Smarty(); $this->setOptions($options); if (isset($options['auto_literal'])) { $this->smarty->auto_literal = $options['auto_literal']; } if (isset($options['left_delimiter'])) { $this->smarty->left_delimiter = $options['left_delimiter']; } if (isset($options['right_delimiter'])) { $this->smarty->right_delimiter = $options['right_delimiter']; } $this->smarty->setTemplateDir(isset($options['template_dir']) ? $options['template_dir'] : $this->system->getAppPath()); $this->smarty->setCompileDir(isset($options['compile_dir']) ? $options['compile_dir'] : $this->system->getAppCachePath('templates/compiled/')); $this->smarty->setCacheDir($this->system->getAppCachePath('templates/cache/')); if (ini_get('safe_mode')) { $this->smarty->use_sub_dirs = false; } else { $this->smarty->use_sub_dirs = true; } // not use //$this->smarty->setCompileCheck(wa()->getConfig()->isDebug()?true:false); $this->smarty->addPluginsDir($this->system->getConfig()->getPath('system') . '/vendors/smarty-plugins'); $this->smarty->loadFilter('pre', 'translate'); }
public function getCurrentUrl() { $url = $this->system->getConfig()->getRequestUrl(); $url = preg_replace("!\\?.*\$!", '', $url); $url = urldecode($url); return substr($url, strlen($this->root_url)); }
public function block($id) { if ($id && $this->wa->appExists('site')) { wa('site'); $model = new siteBlockModel(); $block = $model->getById($id); if (!$block && strpos($id, '.') !== false) { list($app_id, $id) = explode('.', $id); $path = $this->wa->getConfig()->getAppsPath($app_id, 'lib/config/site.php'); if (file_exists($path)) { $site_config = (include $path); if (isset($site_config['blocks'][$id])) { if (!is_array($site_config['blocks'][$id])) { $block = array('content' => $site_config['blocks'][$id]); } else { $block = $site_config['blocks'][$id]; } } } } if ($block) { try { return $this->view->fetch('string:' . $block['content']); } catch (Exception $e) { if (waSystemConfig::isDebug()) { return '<pre class="error">' . htmlentities($e->getMessage(), ENT_QUOTES, 'utf-8') . "</pre>"; } else { waLog::log($e->__toString()); return '<div class="error">' . _ws('Syntax error at block') . ' ' . $id . '</div>'; } } } } return ''; }
public function config($name) { return $this->wa->getConfig()->getOption($name); }
/** 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); }