예제 #1
0
 /**
  * This function takes multiple arguments and dumps them to the source code.
  */
 public static function Dump()
 {
     if (class_exists('Staple_Config')) {
         if (Staple_Config::getValue('errors', 'devmode') == 1) {
             $args = func_get_args();
             echo "<pre>";
             foreach ($args as $dumper) {
                 var_dump($dumper);
                 echo "\n";
             }
             echo "</pre>";
         }
     } else {
         $args = func_get_args();
         echo "<pre>";
         foreach ($args as $dumper) {
             var_dump($dumper);
             echo "\n";
         }
         echo "</pre>";
     }
 }
예제 #2
0
 public function Log($errmsg, $errsql = NULL, $applicationID = NULL)
 {
     $db = Staple_DB::get();
     $dbenc = Staple_Config::getValue('encrypt', 'key');
     $columns = 'occurred,error';
     $values = "NOW(), '" . $db->escape_string($errmsg) . "'";
     if (isset($errsql)) {
         $ssnregex = '/^\\d{3}\\-\\d{2}\\-\\d{4}$/';
         $errsql = preg_replace($ssnregex, 'SSN', $errsql);
         $columns .= ',`sql`';
         $values .= ",AES_ENCRYPT('" . $db->escape_string($errsql) . "','" . $db->real_escape_string($dbenc) . "')";
     }
     if (isset($applicationID)) {
         $columns .= ',applicationID';
         $values .= ",'" . (int) $applicationID . "'";
     }
     $sql = "INSERT INTO log_database_err ({$columns}) VALUES ({$values})";
     if (($result = $db->query($sql)) === true) {
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Redirect to the route location.
  */
 public function Redirect()
 {
     $base = Staple_Config::getValue('application', 'public_location');
     header('Location: ' . $base . $this);
     exit(0);
 }
예제 #4
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);
     }
 }
예제 #5
0
 /**
  * Converts the object into a string by calling the build() method.
  * @return string
  */
 public function __toString()
 {
     try {
         ob_start();
         $this->build();
         $buffer = ob_get_contents();
         ob_end_clean();
         return $buffer;
     } catch (Exception $e) {
         $msg = '<p class=\\"viewerror\\">The View threw an Uncaught Exception when converting to a string....</p>';
         if (Staple_Config::getValue('errors', 'devmode')) {
             $msg .= '<p>' . $e->getMessage() . '</p>';
         }
         return $msg;
     }
 }
예제 #6
0
 /**
  * Creates the shortest link possible to the specified controller/action. 
  * The array must include a controller, followed by an action, followed by any parameters
  * sent to the action as unique items in the array. Parameters may only be of type string
  * or int.
  * 
  * @param mixed $route
  * @param array $get
  * @return string
  */
 public static function get($route, array $get = array())
 {
     //Convert Get array to get string.
     $getString = self::getArraytoString($get);
     //Set the link base
     $base = Staple_Config::getValue('application', 'public_location');
     //Is the link an array or a string?
     if (!is_array($route)) {
         //Return a string link.
         $link = $base . $route;
     } else {
         //Process and Controller/Action/Parameter route
         //Setup the default link and the case-insensitive replacements.
         $link = '#';
         //Count the route elements
         $routesize = count($route);
         if ($routesize == 0) {
             $link = $base;
             //An empty array returns a base link.
         } elseif ($routesize == 1) {
             if (ctype_alnum((string) $route[0])) {
                 $controller = (string) $route[0];
                 if ($controller == 'index') {
                     $link = $base;
                 } else {
                     $controller = self::urlCase($controller);
                     $link = $base . $controller;
                 }
             } else {
                 throw new Exception('Bad Link', Staple_Error::LINK_ERROR);
             }
         } else {
             //Extract the Controller, Action and Parameters.
             $controller = (string) array_shift($route);
             $action = (string) array_shift($route);
             //URL Encode parameter values.
             $params = array();
             foreach ($route as $value) {
                 $params[] = urlencode($value);
             }
             //Check that the route follows valid syntax are valid.
             if (ctype_alnum($controller) && ctype_alnum($action)) {
                 if ($controller == 'index' && $action == 'index' && $params == array()) {
                     $link = $base;
                 } elseif ($controller != 'index' && $action == 'index' && $params == array()) {
                     $link = $base . $controller;
                 } else {
                     if (count($params) > 0) {
                         $paramstring = '/' . implode('/', $params);
                     } else {
                         $paramstring = '';
                     }
                     //Convert action to case-insensitive value
                     $controller = self::urlCase($controller);
                     $action = self::urlCase($action);
                     $link = $base . $controller . '/' . $action . $paramstring;
                 }
             } else {
                 throw new Exception('Bad Link', Staple_Error::LINK_ERROR);
             }
         }
     }
     //Finally append the get string
     if (strlen($getString) > 2) {
         $link .= '?' . $getString;
     }
     //Return the link.
     return $link;
 }
예제 #7
0
 /**
  * The toString magic method calls the forms build function to output the form to the website.
  */
 public function __toString()
 {
     try {
         return $this->build();
     } catch (Exception $e) {
         $msg = '<p class=\\"formerror\\">Form Error....</p>';
         if (Staple_Config::getValue('errors', 'devmode')) {
             $msg .= '<p>' . $e->getMessage() . '</p>';
         }
         return $msg;
     }
 }