/** * Execute specific controller action * * @access public * @param string $action * @return InvalidControllerActionError if action name is not valid or true */ function execute($action) { // Prepare action name $action = trim(strtolower($action)); // If we have valid action execute and done... Else throw exception if($this->validAction($action)) { $this->setAction($action); $ret = true; Hook::fire('before_action', array( 'controller' => $this, 'action' => $action ), $ret); if ($ret) { TimeIt::start("Action"); $this->$action(); TimeIt::stop(); Hook::fire('after_action', array( 'controller' => $this, 'action' => $action ), $ret); } return true; } else { throw new InvalidControllerActionError($this->getControllerName(), $action); } // if } // execute
/** * Display template and retur output as string * * @param string $template Template path (absolute path or path relative to * the templates dir) * @return string * @throws FileDnxError */ function fetch($template) { ob_start(); try { TimeIt::start("Template"); $this->includeTemplate($template); TimeIt::stop(); } catch(Exception $e) { ob_end_clean(); throw $e; } // try return ob_get_clean(); } // fetch
/** * Contruct controller and execute specific action * * @access public * @param string $controller_name * @param string $action * @return null */ static function executeAction($controller_name, $action) { $max_users = config_option('max_users'); if ($max_users && Contacts::count() > $max_users) { echo lang("error").": ".lang("maximum number of users exceeded error"); return; } ajx_check_login(); Env::useController($controller_name); $controller_class = Env::getControllerClass($controller_name); if(!class_exists($controller_class, false)) { throw new ControllerDnxError($controller_name); } // if $controller = new $controller_class(); if(!instance_of($controller, 'Controller')) { throw new ControllerDnxError($controller_name); } // if if (is_ajax_request()) { // if request is an ajax request return a json response // execute the action $controller->setAutoRender(false); $controller->execute($action); // fill the response $response = AjaxResponse::instance(); if (!$response->hasCurrent()) { // set the current content $response->setCurrentContent("html", $controller->getContent(), page_actions(), ajx_get_panel()); } $response->setEvents(evt_pop()); $error = flash_pop('error'); $success = flash_pop('success'); if (!is_null($error)) { $response->setError(1, clean($error)); } else if (!is_null($success)) { $response->setError(0, clean($success)); } // display the object as json tpl_assign("object", $response); $content = tpl_fetch(Env::getTemplatePath("json")); tpl_assign("content_for_layout", $content); TimeIt::start("Transfer"); if (is_iframe_request()) { tpl_display(Env::getLayoutPath("iframe")); } else { tpl_display(Env::getLayoutPath("json")); } TimeIt::stop(); } else { return $controller->execute($action); } } // executeAction
/** * Render content... If template and/layout are NULL script will resolve * their names based on controller name and action. * * PageController::index will map with: * - template => views/page/index.php * - layout => layouts/page.php * * @param string $template * @param string $layout * @param boolean $die * @return boolean * @throws FileDnxError */ function render($template = null, $layout = null, $die = true) { // Set template and layout... if (!is_null($template)) { $this->setTemplate($template); } if (!is_null($layout)) { $this->setLayout($layout); } Hook::fire('override_action_view', $this, $ret); // Get template and layout paths $template_path = $this->getTemplatePath(); $layout_path = $this->getLayoutPath(); // Fetch content... $content = tpl_fetch($template_path); // Assign content and render layout TimeIt::start("Transfer"); $this->renderLayout($layout_path, $content); TimeIt::stop(); // Die! if ($die) { die; } // We are done here... return true; }
/** * Contruct controller and execute specific action * * @access public * @param string $controller_name * @param string $action * @return null */ static function executeAction($controller_name, $action) { $max_users = config_option('max_users'); if ($max_users && Users::count() > $max_users) { echo lang("error") . ": " . lang("maximum number of users exceeded error"); return; } ajx_check_login(); if (isset($_GET['active_project']) && logged_user() instanceof User) { $dont_update = false; if (GlobalCache::isAvailable()) { $option_value = GlobalCache::get('user_config_option_' . logged_user()->getId() . '_lastAccessedWorkspace', $success); if ($success) { $dont_update = $option_value == $_GET['active_project']; } } if (!$dont_update) { set_user_config_option('lastAccessedWorkspace', $_GET['active_project'], logged_user()->getId()); if (GlobalCache::isAvailable()) { GlobalCache::update('user_config_option_' . logged_user()->getId() . '_lastAccessedWorkspace', $_GET['active_project']); } } } Env::useController($controller_name); $controller_class = Env::getControllerClass($controller_name); if (!class_exists($controller_class, false)) { throw new ControllerDnxError($controller_name); } // if $controller = new $controller_class(); if (!instance_of($controller, 'Controller')) { throw new ControllerDnxError($controller_name); } // if if (is_ajax_request()) { // if request is an ajax request return a json response // execute the action $controller->setAutoRender(false); $controller->execute($action); // fill the response $response = AjaxResponse::instance(); if (!$response->hasCurrent()) { // set the current content $response->setCurrentContent("html", $controller->getContent(), page_actions(), ajx_get_panel()); } $response->setEvents(evt_pop()); $error = flash_pop('error'); $success = flash_pop('success'); if (!is_null($error)) { $response->setError(1, clean($error)); } else { if (!is_null($success)) { $response->setError(0, clean($success)); } } // display the object as json tpl_assign("object", $response); $content = tpl_fetch(Env::getTemplatePath("json")); tpl_assign("content_for_layout", $content); TimeIt::start("Transfer"); if (is_iframe_request()) { tpl_display(Env::getLayoutPath("iframe")); } else { tpl_display(Env::getLayoutPath("json")); } TimeIt::stop(); } else { return $controller->execute($action); } }
// two weeks // Defaults define('DEFAULT_CONTROLLER', 'access'); define('DEFAULT_ACTION', 'index'); define('DEFAULT_THEME', 'default'); define('SLIMEY_PATH', ROOT_URL . '/public/assets/javascript/slimey/'); define('PLUGINS_URL', ROOT_URL . '/plugins'); if (!defined('PHP_PATH')) { define('PHP_PATH', 'php'); } // --------------------------------------------------- // Init... // --------------------------------------------------- include_once 'environment/environment.php'; if (Env::isDebuggingTime()) { TimeIt::start("Total"); } include_once 'library/json/json.php'; // Lets prepare everything for autoloader require APPLICATION_PATH . '/functions.php'; // __autoload() function is defined here... if (!($callbacks = spl_autoload_functions())) { $callbacks = array(); } foreach ($callbacks as $callback) { spl_autoload_unregister($callback); } spl_autoload_register('feng__autoload'); foreach ($callbacks as $callback) { spl_autoload_register($callback); }
function getAssignableCompanies($project = null) { if ($this->isMemberOfOwnerCompany()) { return Companies::getCompaniesWithUsers(); } TimeIt::start('get assignable companies'); if ($project instanceof Project) { $ws = $project->getAllSubWorkspacesQuery(true); } $uid = $this->getId(); $cid = $this->getCompany()->getId(); $tp = TABLE_PREFIX; $gids = "SELECT `group_id` FROM `{$tp}group_users` WHERE `user_id` = {$uid}"; $q1 = "SELECT `project_id` FROM `{$tp}project_users` WHERE (`user_id` = {$uid} OR `user_id` IN ({$gids})) AND `can_assign_to_other` = '1'"; $q2 = "SELECT `project_id` FROM `{$tp}project_users` WHERE (`user_id` = {$uid} OR `user_id` IN ({$gids})) AND `can_assign_to_owners` = '1'"; if (isset($ws)) { $q1 .= " AND `project_id` IN ({$ws})"; $q2 .= " AND `project_id` IN ({$ws})"; } $query1 = "SELECT `user_id` FROM `{$tp}project_users` WHERE `project_id` IN ({$q1})"; $query2 = "SELECT `user_id` FROM `{$tp}project_users` WHERE `project_id` IN ({$q2})"; $query = "SELECT `company_id` FROM `{$tp}users` WHERE `id` IN ({$query1}) AND `company_id` <> 1 AND `company_id` <> {$cid} OR `id` IN ({$query2}) AND `company_id` = 1"; // get companies for assignable users (see getAssignableUsers) $companies = Companies::findAll(array('conditions' => "`id` = {$cid} OR `id` IN ({$query})")); TimeIt::stop(); return $companies; }