예제 #1
0
 /**
  * Delega a manipulação das requisições feitas à
  * aplicação ao controlador responsável.
  */
 public function handle()
 {
     try {
         Registry::getInstance()->set('modelFactory', new MySQLFactory());
         session_start();
         $this->controllerManager->handle();
     } catch (Exception $e) {
         $view = new ErrorView();
         $view->setMessage($e->getMessage());
         $view->show();
     }
 }
 public function render($params, $s_code, $s_message = "")
 {
     $status = new StatusModel();
     $output = !empty($params["output"]) ? $params["output"] : "";
     $status->code = $s_code;
     $status->message = $s_message;
     $result = array("status" => $status, "params" => $params, "result" => array());
     $view = new ErrorView();
     $view->appendHeader($status->code);
     $view->appendHeader($output);
     $view->render($result, $output);
 }
예제 #3
0
 /**
  * This function creates a HTML-block for a menu item.
  *
  * @access public
  * @author k
  * @param MenuElement $parameters['menuElement']
  *        	the menu element
  * @param string $parameters['type']
  *        	the type
  * @see MenuElement::$type
  * @uses Error for error handling
  * @uses ErrorView for error handling
  * @uses MENU_COMMON for the common menu
  * @uses MENU_SIDE for the menu in sidebar
  */
 public static function buildMenuElement($parameters)
 {
     require_once 'HTML/Template/IT.php';
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'html');
     $tpl->loadTemplatefile('particle-template.html');
     switch ($parameters['type']) {
         case MENU_COMMON:
             $tpl->setCurrentBlock('item-in-common-menu');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-COMMON-MENU' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-COMMON-MENU' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-common-menu');
             // echo ' 38: ', $tpl->get('menu-item');
             return $tpl->get('item-in-common-menu');
             break;
         case MENU_SIDE:
             $tpl->setCurrentBlock('item-in-menu-in-sidebar');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-MENU-IN-SIDEBAR' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-MENU-IN-SIDEBAR' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-menu-in-sidebar');
             return $tpl->get('item-in-menu-in-sidebar');
             break;
         default:
             require_once dirname(__FILE__) . '/Error.php';
             $error = new Error();
             $error->setMessage(\pstk\String::translate('errorWhichMenu'));
             require_once dirname(__FILE__) . '/ErrorView.php';
             ErrorView::raiseError($error);
     }
 }
 /**
  * Constructor
  */
 function AddCommentAction($blogInfo, $request)
 {
     $this->BlogAction($blogInfo, $request);
     // change the validation mode of the form
     $this->registerFieldValidator("articleId", new IntegerValidator());
     $this->_form->setFieldErrorMessage("articleId", $this->_locale->tr("error_incorrect_article_id"));
     $this->registerFieldValidator("blogId", new IntegerValidator());
     $this->_form->setFieldErrorMessage("blogId", $this->_locale->tr("error_incorrect_blog_id"));
     $this->registerFieldValidator("parentId", new IntegerValidator(), true);
     $this->_form->setFieldErrorMessage("parentId", $this->_locale->tr("error_incorrect_article_id"));
     $this->registerFieldValidator("userEmail", new EmailValidator(), true);
     $this->_form->setFieldErrorMessage("userEmail", $this->_locale->tr("error_incorrect_email_address"));
     $this->registerFieldValidator("userName", new StringValidator());
     $this->_form->setFieldErrorMessage("userName", $this->_locale->tr("error_comment_without_name"));
     $this->registerFieldValidator("commentText", new StringValidator());
     $this->_form->setFieldErrorMessage("commentText", $this->_locale->tr("error_comment_without_text"));
     $this->registerFieldValidator("userUrl", new HttpUrlValidator(), true);
     $this->_form->setFieldErrorMessage("userUrl", $this->_locale->tr("Invalid URL"));
     $view = new ErrorView($this->_blogInfo);
     $view->setErrorMessage("There has been an error validating the data!");
     $this->setValidationErrorView($view);
     $this->_fetchFields();
 }
예제 #5
0
 /**
  * Follows a route and produces a web page from it.
  */
 public function route()
 {
     $view = null;
     $exception = null;
     /* construct template engine */
     $smarty = new Smarty();
     $smarty->caching = true;
     $smarty->cache_lifetime = 120;
     $smarty->setTemplateDir(__DIR__ . '/layouts');
     $smarty->setCompileDir(__DIR__ . '/../../smarty/compiled_templates');
     $smarty->setCacheDir(__DIR__ . '/../../smarty/cache');
     switch ($this->path) {
         case 'index':
             $view = new IndexView($smarty);
             break;
         case 'statuses':
             if (!$this->isLoggedIn()) {
                 $exception = new Exception('You must be <a href="?action=login">logged in<a> to view the circuit board status list.');
                 break;
             }
             $view = new StatusesView($smarty);
             $model = new StatusesModel($view);
             $controller = new StatusesController($model);
             try {
                 $controller->fetchStatuses();
             } catch (Exception $e) {
                 $exception = $e;
             }
             break;
         case 'updates':
             if (!$this->isLoggedIn() || $_SESSION['rank'] != 'ADMIN') {
                 $exception = new Exception('You must be <a href="?action=login">logged in<a> to an administrator\'s account to poll the service for updates.');
                 break;
             }
             $view = new UpdatesView($smarty);
             $model = new UpdatesModel($view);
             $controller = new UpdatesController($model);
             try {
                 $controller->fetchUpdates();
             } catch (Exception $e) {
                 $exception = $e;
             }
             break;
         case 'register':
             $view = new RegisterView($smarty);
             $model = new RegisterModel($view);
             $controller = new RegisterController($model);
             try {
                 $controller->checkValidRegistration();
                 $username = $model->getUsername();
                 if ($model->isRegistered()) {
                     $view = new RegisteredView($smarty);
                     $model = new RegisteredModel($view);
                     $model->setUsername($username);
                 }
             } catch (Exception $e) {
                 $exception = $e;
             }
             break;
         case 'login':
             $view = new LoginView($smarty);
             $model = new LoginModel($view);
             $controller = new LoginController($model);
             try {
                 $controller->checkValidLogin();
                 if ($model->isLoggedIn()) {
                     // successful login
                     $view = new LoggedInView($smarty);
                     $model = new LoggedInModel($view);
                     $model->setUsername($_SESSION['username']);
                 }
             } catch (Exception $e) {
                 $exception = $e;
             }
             break;
         case 'logout':
             $view = new LogoutView($smarty);
             $model = new LogoutModel($view, $this->isLoggedIn());
             $controller = new LogoutController($model);
             try {
                 $controller->logout();
             } catch (Exception $e) {
                 $exception = $e;
             }
             break;
         case 'debug':
             if (!$this->isLoggedIn() || $_SESSION['rank'] != 'ADMIN') {
                 $exception = new Exception('You must be <a href="?action=login">logged in<a> to an administrator\'s account view the debug page.');
                 break;
             }
             $view = new DebugView($smarty);
             break;
             /* any unhandled action return them to the welcome screen */
         /* any unhandled action return them to the welcome screen */
         default:
             $this->path = 'index';
             $view = new IndexView($smarty);
             break;
     }
     if ($exception !== null) {
         $view = new ErrorView($smarty);
         $model = new ErrorModel($view);
         $model->setMessage($exception->getMessage());
     }
     if (!DEBUG_MODE) {
         /* optimize the output by removing whitespace */
         $smarty->loadFilter("output", "trimwhitespace");
     }
     /* apply view specific information to the template engine */
     $view->applyTemplate($this->isLoggedIn());
     /* display generated template */
     $smarty->display($view->getId() . '.tpl');
 }
예제 #6
0
function alert($msg)
{
    ErrorView::render($msg);
    //echo json_encode(array('error'=>$msg));
    exit;
}