예제 #1
0
<?php

defined('FOLDER_ROOT') || define('FOLDER_ROOT', realpath(dirname(__FILE__) . '/../'));
defined('LIBRARY_ROOT') || define('LIBRARY_ROOT', FOLDER_ROOT . '/library/');
defined('SITE_ROOT') || define('SITE_ROOT', FOLDER_ROOT . '/public/');
defined('PROGRAM_ROOT') || define('PROGRAM_ROOT', FOLDER_ROOT . '/application/');
defined('ELEMENTS_ROOT') || define('ELEMENTS_ROOT', FOLDER_ROOT . '/elements/');
include LIBRARY_ROOT . 'Staple/Main.class.php';
$main = Staple_Main::get();
$main->run();
예제 #2
0
 /**
  * 
  * handleException catches Exceptions and displays an error page with the details.
  * @todo create and implement and error controller that can display custom errors
  * per application.
  * @param Exception $ex
  */
 public function handleException(Exception $ex)
 {
     //handle the error
     $this->setLastException($ex);
     //Notify observers
     $this->notify();
     //Clear the output buffer
     ob_clean();
     //Get the Front Controller
     $main = Staple_Main::get();
     //Process the Header
     $main->processHeader(true);
     //Echo the error message
     echo "<div class=\"section\"><div class=\"row\"><div class=\"small-12 columns\"><h1><i class=\"fi-alert\"></i> " . $ex->getMessage() . " Code: " . $ex->getCode() . "</h1></div></div></div>";
     //Echo details if in dev mode
     if ($main->inDevMode()) {
         if (($p = $ex->getPrevious()) instanceof Exception) {
             echo "<p><b>Previous Error:</b> " . $p->getMessage . " Code: " . $p->getCode() . "</p>";
         }
         echo "<pre>" . $ex->getTraceAsString() . "</pre>";
         foreach ($ex->getTrace() as $traceln) {
             echo "<pre>";
             var_dump($traceln);
             echo "</pre>";
         }
     }
     //If the site uses layout, build the default layout and put the error message inside.
     if (Staple_Layout::layoutExists(Staple_Config::getValue('layout', 'default'))) {
         //Grab the current buffer contents to add to the layout
         $buffer = ob_get_contents();
         ob_clean();
         //Create the layout object and build the layout
         $layout = new Staple_Layout(Staple_Config::getValue('layout', 'default'));
         $layout->build($buffer);
     }
 }
예제 #3
0
 public static function GetRouteInfo()
 {
     $blah = Staple_Main::getRoute();
 }
예제 #4
0
 /**
  *
  * If an array is supplied, a link is created to a controller/action. If a string is
  * supplied, a file link is specified.
  * @param string | array $link
  * @param array $get
  * @return string
  */
 public function link($link, array $get = array())
 {
     return Staple_Main::get()->link($link, $get);
 }
예제 #5
0
 /**
  * 
  * This function renders the view. If accepts a string representing the controller and
  * a string representing the requested action. With this information the correct view
  * is selected and rendered.
  * @param string $class
  * @param string $view
  */
 public function build()
 {
     if ($this->_render === true) {
         //Load the view from the default loader
         $view = Staple_Main::get()->getLoader()->loadView($this->controller, $this->view);
         if (strlen($view) >= 1) {
             include $view;
         }
     } else {
         //skip rendering of an additional views
         $this->_render = false;
     }
 }
예제 #6
0
 /**
  * 
  * This function accepts a routing string to redirect the application internally. A
  * redirect of this sort clears the output buffer and redraws the header, proceeding
  * as if the redirected controller/action was called directly. 
  * @param mixed $to
  */
 protected function _redirect($to)
 {
     Staple_Main::get()->redirect($to);
     $this->view->noRender();
 }
예제 #7
0
 /**
  * This function is a temporary fix until the changes are completed to Staple_Route.
  * @param string $action
  * @deprecated
  */
 public function displayPaging($action = NULL)
 {
     //Setup Link Variables
     $linkVars = array_merge($_GET, $this->pageVariables);
     //These two variables would be overridden anyway.
     if (array_key_exists('items', $linkVars)) {
         unset($linkVars['items']);
     }
     if (array_key_exists('page', $linkVars)) {
         unset($linkVars['page']);
     }
     //Set a default link action location if none is submitted.
     if ($action == NULL) {
         $action = Staple_Main::getRoute();
     }
     $buffer = "<div class=\"staple_pager row\">\n<div class=\"staple_pager_pages small-12 medium-11 columns\">\n";
     $pages = $this->getPages();
     if (count($pages) > 1) {
         if ($this->getCurrentPage() == 1) {
             $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a> ';
         } elseif ($this->getCurrentPage() > 1) {
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => 1))) . '"><i class="fa fa-angle-double-left"></i></a> ';
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getCurrentPage() - 1))) . '"><i class="fa fa-angle-left"></i></a> ';
         }
         if ($pages[0] != 1) {
             $buffer .= '... ';
         }
         foreach ($pages as $page) {
             if ($this->getCurrentPage() == $page) {
                 $buffer .= '<span class="currentpage button tiny disabled">' . (int) $page . '</span> ';
             } else {
                 $buffer .= '<a class="button tiny secondary" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => (int) $page))) . '">' . (int) $page . '</a> ';
             }
         }
         if ($pages[count($pages) - 1] != $this->getNumberOfPages()) {
             $buffer .= '... ';
         }
         if ($this->getCurrentPage() == $this->getNumberOfPages()) {
             $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
         } else {
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getCurrentPage() + 1))) . '"><i class="fa fa-angle-right"></i></a> ';
             $buffer .= '<a class="button tiny" href="' . Staple_Link::get($action, array_merge($linkVars, array('page' => $this->getNumberOfPages()))) . '"><i class="fa fa-angle-double-right"></i></a>';
         }
     } else {
         $buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a>  <a class="button tiny disabled">1</a> <a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
     }
     $buffer .= "</div>\n";
     if ($this->getDisplayItemAmountSelector() === true) {
         $buffer .= "<div class=\"staple_pager_items small-12 medium-1 columns\">\n";
         $buffer .= '<select onChange="window.location=\'' . Staple_Link::get($action, array_merge($linkVars, array('page' => 1))) . "&items='+this.value\">\n";
         foreach ($this->getItemAmountSelections() as $value) {
             $selected = '';
             if ($this->getItemsPerPage() == $value) {
                 $selected = ' selected';
             }
             $buffer .= '<option value="' . $value . '"' . $selected . '>' . $value . "</option>\n";
         }
         $buffer .= "</select>\n";
         $buffer .= "</div>\n";
     }
     $buffer .= "</div>\n";
     return $buffer;
 }
예제 #8
0
 /**
  * 
  * Dispatches to the AuthController -> index action. Throws an Exception if the controller does
  * not extend Staple_AuthController.
  * @throws Exception
  */
 private function dispatchAuthController()
 {
     $conString = $this->_settings['controller'];
     $class = substr($conString, 0, strlen($conString) - 10);
     $authCon = Staple_Main::getController($class);
     if (!$authCon instanceof Staple_AuthController) {
         $authCon = new $conString();
     }
     if ($authCon instanceof Staple_AuthController) {
         //Start the Controller
         $authCon->_start();
         //Register Auth Controller with the Front Controller
         Staple_Main::get()->registerController($authCon);
         //Set the view's controller to match the route
         $authCon->view->setController($class);
         //Set the view's action to match the route
         $authCon->view->setView('index');
         //Call the controller action, Send the route requested to the action
         //@todo Add option to customize the controller action
         call_user_func_array(array($authCon, 'index'), array(Staple_Main::getRoute()));
         //Grab the buffer contents from the controller and post it after the header.
         $buffer = ob_get_contents();
         ob_clean();
         //Process the header
         Staple_Main::get()->processHeader();
         if ($authCon->layout instanceof Staple_Layout) {
             $authCon->layout->build($buffer);
         } else {
             echo $buffer;
             $authCon->view->build();
         }
     } else {
         throw new Exception('Fatal Error connecting to Auth Controller', Staple_Error::AUTH_ERROR);
     }
 }
예제 #9
0
 public function build($buffer = NULL)
 {
     if (isset($this->name)) {
         if (isset($buffer)) {
             $this->buffer = $buffer;
         }
         $layout = Staple_Main::get()->getLoader()->loadLayout($this->name);
         include $layout;
     } else {
         throw new Exception("Attempted to build unknown layout.", Staple_Error::APPLICATION_ERROR);
     }
 }