/** * 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>"; } }
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; } }
/** * * Controller constructor creates an instance of Staple_View and saves it in the $view * property. It then calls the overridable method _start() for additional boot time * procedures. */ public function __construct() { //Set default access levels $methods = get_class_methods(get_class($this)); foreach ($methods as $acMeth) { if (substr($acMeth, 0, 1) != '_') { $this->accessLevels[$acMeth] = 1; } } //Create a view object $this->view = new Staple_View(); //Assign the default layout to the controller, if specified in config. $settings = Staple_Config::get('layout'); if (array_key_exists('default', $settings)) { if ($settings['default'] != '') { $this->_setLayout($settings['default']); $pageSettings = Staple_Config::get('page'); if (array_key_exists('title', $pageSettings)) { $this->layout->setTitle($pageSettings['title']); } } } }
/** * Redirect to the route location. */ public function Redirect() { $base = Staple_Config::getValue('application', 'public_location'); header('Location: ' . $base . $this); exit(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); } }
/** * Read and store the application.ini config file. */ private static function read() { if (defined('CONFIG_ROOT')) { $settings = array(); if (file_exists(CONFIG_ROOT . 'application.ini')) { self::$store = parse_ini_file(CONFIG_ROOT . 'application.ini', true); } } self::$read = true; }
/** * * Default constructor. Accepts optional values for To, From, CC, and BCC. * @param string | array $to * @param string $from * @param array $cc * @param array $bcc */ public function __construct($to = NULL, $from = NULL, array $cc = array(), array $bcc = array()) { //Load the ini settings $settings = Staple_Config::get('email'); if ($settings['from'] != '') { $this->setFrom($settings['from']); } if ($settings['bcc'] != '') { $this->addBcc($settings['bcc']); } if ($settings['html'] == '0') { $this->sendAsHtml(false); } if ($settings['server'] != '') { $this->setServer($settings['server']); } if (array_key_exists('template', $settings)) { if ($settings['template'] != '') { $this->setTemplate($settings['template']); } } //Load any Tos if (isset($to)) { if (is_array($to)) { foreach ($to as $email) { $this->addTo($email); } } else { $this->addTo($to); } } //Load the From if (isset($from)) { $this->setFrom($from); } //Load any CCs if (isset($cc)) { if (is_array($cc)) { $this->setCc($cc); } else { $this->setCc(array($cc)); } } //Load any BCCs if (isset($bcc)) { if (is_array($bcc)) { $this->setBcc($bcc); } else { $this->setBcc(array($bcc)); } } }
/** * Creates and/or returns a named database connection. * @return Staple_DB * @static */ public static function getNamedConnection($name) { if (!isset(self::$namedConnections[$name])) { $c = __CLASS__; self::$namedConnections[$name] = new $c(Staple_Config::get($name)); } return self::$namedConnections[$name]; }
/** * 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; } }
/** * * Loads the AD configuration information and esablishes connection to Active Directory Server * * @throws Exception */ protected function __construct() { $settings = Staple_Config::get('ActiveDirectory'); $this->host = $settings['host']; $this->username = $settings['username']; $this->password = $settings['password']; $this->domain = $settings['domain']; $this->baseDN = $settings['baseDN']; $this->LDAPSenabled = $settings['LDAPSenabled']; if ($this->LDAPSenabled == 1) { $LDAPServer = "ldaps://" . $this->host; $this->LDAPConn = ldap_connect($LDAPServer, 636); } else { $LDAPServer = "ldap://" . $this->host; $this->LDAPConn = ldap_connect($LDAPServer, 389); } ldap_set_option($this->LDAPConn, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($this->LDAPConn, LDAP_OPT_REFERRALS, 0); $this->mgmtbind(); }
/** * 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; }
/** * 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; } }
public function __construct($name = NULL, $doctype = "html5") { if (isset($name)) { $this->setName($name); } switch ($doctype) { case 'html4_trans': case 'html4': $this->doctype = self::DOC_HTML4_TRANS; break; case 'html4_strict': $this->doctype = self::DOC_HTML4_STRICT; break; case 'xhtml_trans': case 'xhtml': $this->doctype = self::DOC_XHTML_TRANS; break; case 'xhtml_strict': $this->doctype = self::DOC_XHTML_STRICT; break; default: $this->doctype = self::DOC_HTML5; } $settings = Staple_Config::get('layout'); if (is_array($settings)) { //Add the default title to the layout if (array_key_exists('title', $settings)) { $this->setTitle($settings['title']); } //Add the default scripts to the layout if (array_key_exists('scripts', $settings)) { if (is_array($settings['scripts'])) { foreach ($settings['scripts'] as $src) { $this->addScript($src); } } else { $this->addScript($settings['scripts']); } } //Add the default styles to the layout if (array_key_exists('styles', $settings)) { if (is_array($settings['styles'])) { foreach ($settings['styles'] as $href) { $this->addStylesheet($href); } } else { $this->layout->addStylesheet($settings['styles']); } } //Add the default metas to the layout if (array_key_exists('meta_description', $settings)) { $this->setMetas('description', $settings['meta_description']); } if (array_key_exists('meta_keywords', $settings)) { $this->setMetas('keywords', $settings['meta_keywords']); } } }