/** * public action to handle the login posted data **/ public function login() { if (count($_POST) > 0) { $this->redirect_to($this->process_login()); } Session::set('timestamp', time()); Session::unset_var('errors'); $this->use_layout = "login"; $this->redirect_url = Session::get('referrer'); $this->form = new LoginForm(); }
public function info_messages() { if ($messages = Session::get('user_messages')) { foreach ($messages as $message) { $html .= $this->content_tag("li", $message, array("class" => "user_message")); } Session::unset_var('user_messages'); return $this->content_tag("ul", $html, array("class" => "user_messages", "id" => "user_message_box")); } return false; }
public function create() { $this->display_action_name = 'Create'; $model = $this->model; $this->model = new Campaign(); $this->model->ClientID = $this->cm_conf['campaign_monitor_ClientID']; Session::unset_var('user_errors'); //remove old errors; if ($this->model->is_posted()) { $this->model = $this->model->handle_post(); $errors = ""; if (count($this->model->errors)) { $errors .= "<br />" . implode("<br />", $this->model->errors); } if (strlen($errors) > 0) { $errors .= ":"; foreach ($this->model->errors as $k => $val) { $errors .= $val . "<br />"; } Session::add_message('There was an error creating you campaign.' . $errors); } else { Session::add_message('Your campaign has been created!'); $this->redirect_to('/admin/email'); } } $lists = $model->GetLists(); $this->mail_lists = array_merge(array('' => array('ListID' => '', 'Name' => 'None')), $lists->rowset); $segments = $model->GetSegments(); $this->segments = array_merge(array('' => array('ListID' => '', 'Name' => 'None')), $segments->rowset); $cont = new CmsContent("published"); $this->contents = $cont->all(); $this->form = $this->render_partial("form"); }
function __destruct() { if ($this->user_id) { Session::set($this->session_key, $this->user_id); } else { Session::unset_var($this->session_key); } }
/** * Parse URL, extract controller and action and execute them * * @uses $action * @uses $application_controller_file * @uses $application_helper_file * @uses $controller * @uses $controller_class * @uses $controller_file * @uses $controller_object * @uses determine_layout() * @uses execute_after_filters() * @uses $helpers * @uses $helper_file * @uses $helpers_base_path * @uses $keep_flash * @uses $loaded * @uses recognize_route() * @uses raise() * @uses ScaffoldController * @uses Session::unset_var() * @uses $view_file * @uses $views_path * @return boolean true */ function process_route() { # First try to load the routes and setup the paths to everything if (!$this->loaded) { if (!$this->recognize_route()) { $this->raise("Failed to load any defined routes", "Controller " . $this->controller . " not found", "404"); } } //error_log('process_route(): controller="'.$this->controller // .'" action="'.$this->action.'"'); # Include main application controller file if (file_exists($this->application_controller_file)) { include_once $this->application_controller_file; } # If controller is loaded then start processing if ($this->loaded) { include_once $this->controller_file; if (class_exists($this->controller_class, false)) { $class = $this->controller_class; $this->controller_object = new $class(); } if (is_object($this->controller_object)) { $this->controller_object->controller = $this->controller; $this->controller_object->action = $this->action; $this->controller_object->controller_path = "{$this->added_path}/{$this->controller}"; $this->controller_object->views_path = $this->views_path; $this->controller_object->layouts_path = $this->layouts_path; $this->controller_object->plugin = $this->plugin; Trax::$current_controller_path = "{$this->added_path}/{$this->controller}"; Trax::$current_controller_name = $this->controller; Trax::$current_action_name = $this->action; Trax::$current_controller_object =& $this->controller_object; # Which layout should we use? $this->controller_object->determine_layout(); # Check if there is any defined scaffolding to load if (isset($this->controller_object->scaffold)) { $scaffold = $this->controller_object->scaffold; if (file_exists(TRAX_LIB_ROOT . "/scaffold_controller.php")) { include_once TRAX_LIB_ROOT . "/scaffold_controller.php"; $this->controller_object = new ScaffoldController($scaffold); Trax::$current_controller_object =& $this->controller_object; $render_options['scaffold'] = true; if (!file_exists($this->controller_object->layout_file)) { # the generic scaffold layout $this->controller_object->layout_file = TRAX_LIB_ROOT . "/templates/scaffolds/layout.phtml"; } } } # Include main application helper file if (file_exists($this->application_helper_file)) { include_once $this->application_helper_file; } # Include helper file for this controller if (file_exists($this->helper_file)) { include_once $this->helper_file; } # Include any extra helper files defined in this controller if (count($this->controller_object->helpers) > 0) { foreach ($this->controller_object->helpers as $helper) { if (strstr($helper, "/")) { $file = substr(strrchr($helper, "/"), 1); $path = substr($helper, 0, strripos($helper, "/")); $helper_path_with_file = $this->helpers_base_path . "/" . $path . "/" . $file . "_helper.php"; } else { $helper_path_with_file = $this->helpers_base_path . "/" . $helper . "_helper.php"; } if (file_exists($helper_path_with_file)) { # Include the helper file include $helper_path_with_file; } } } # Suppress output ob_start(); #error_log('started capturing HTML'); # Call the controller method based on the URL if ($this->controller_object->execute_before_filters()) { $controller_layout = null; if (isset($this->controller_object->layout)) { $controller_layout = $this->controller_object->layout; } #Get PUBLIC methods from controller object $all_methods = get_class_methods($this->controller_object); # Get Inherited methods from active_controller $inherited_methods = array_merge(get_class_methods(__CLASS__), $this->controller_object->before_filters, $this->controller_object->after_filters); # Get non-inherited methods $action_methods = array_diff($all_methods, $inherited_methods); #error_log("available methods:".print_r($action_methods, true)); if (in_array($this->action, $action_methods)) { #error_log('method '.$this->action.' exists, calling it'); $action = $this->controller_object->called_action = $this->action; #error_log('calling action routine ' # . get_class($this->controller_object) # .'::'.$action.'()'); $this->controller_object->{$action}(); } elseif (file_exists($this->views_path . "/" . $this->action . "." . Trax::$views_extension)) { #error_log('views file "'.$this->action.'"'); $action = $this->controller_object->called_action = $this->action; } elseif (method_exists($this->controller_object, "index")) { #error_log('calling action routine ' # . get_class($this->controller_object) # .'::index()'); $action = $this->controller_object->called_action = "index"; $this->controller_object->index(); } else { //error_log('no action'); $methods_size = count($action_methods); if ($methods_size > 1) { $last_method = ($methods_size > 2 ? "," : '') . " and " . array_pop($action_methods); } $this->raise("No action responded to " . $this->action . ". Actions:" . implode(", ", $action_methods) . $last_method, "Unknown action", "404"); } if (isset($this->controller_object->layout)) { if ($controller_layout != $this->controller_object->layout) { # layout was set in the action need to redetermine the layout file to use. $this->controller_object->determine_layout(); } } #$this->controller_object->execute_after_filters(); $this->controller_object->action_called = true; # Find out if there was a redirect to some other page if (isset($this->controller_object->redirect_to) && $this->controller_object->redirect_to != '') { $this->redirect_to($this->controller_object->redirect_to); # execution will end here redirecting to new page } # If render_text was defined as a string render it if (isset($this->controller_object->render_text) && $this->controller_object->render_text != "") { $this->render_text($this->controller_object->render_text); # execution will end here rendering only the text no layout } # If defined string render_action use that instead if (isset($this->controller_object->render_action) && $this->controller_object->render_action != '') { $action = $this->controller_object->render_action; } # Render the action / view if (!$this->controller_object->render_action($action, isset($render_options) ? $render_options : null)) { $this->raise("No view file found {$action} ({$this->view_file}).", "Unknown view", "404"); } $this->controller_object->execute_after_filters(); # Grab all the html from the view to put into the layout $content_for_layout = ob_get_contents(); ob_end_clean(); //error_log("captured ".strlen($content_for_layout)." bytes\n"); if (isset($this->controller_object->render_layout) && $this->controller_object->render_layout !== false && $this->controller_object->layout_file) { $locals['content_for_layout'] = $content_for_layout; # render the layout #error_log("rendering layout: ".$this->controller_object->layout_file); if (!$this->controller_object->render_file($this->controller_object->layout_file, false, $locals)) { # No layout template so just echo out whatever is in $content_for_layout //echo "HERE"; echo $content_for_layout; } } else { # Can't find any layout so throw an exception # $this->raise("No layout file found.", "Unknown layout", "404"); # No layout template so just echo out whatever is in $content_for_layout //error_log("no layout found: ".$this->controller_object->layout_file); echo $content_for_layout; } } } else { $this->raise("Failed to instantiate controller object \"" . $this->controller . "\".", "ActionController Error", "500"); } } else { $this->raise("No controller found.", "Unknown controller", "404"); } // error_log('keep flash='.var_export($this->keep_flash,true)); if (!$this->keep_flash) { # Nuke the flash unset($_SESSION['flash']); Session::unset_var('flash'); } return true; }