function __construct($perror = false, $facility = LOG_LOCAL0) { $this->verbose = $perror; $flag = LOG_PID; if ($perror) { $flag |= LOG_PERROR; } $this->logger = openlog(Lepton::getServerHostname(), $flag, $facility); }
/** * Post a comment to a feed. * * @param string $nsuri The namespace and URI to post to * @param array $item The item to post */ function post($nsuri, $item) { $db = DBX::getInstance(DBX); // Extract namespace and URI list($ns, $uri) = StringUtil::getNamespaceURI(config::get('lepton.comments.defaultnamespace', 'comments'), $nsuri); // TODO: Implement spam filtering here if (Lepton::has('spamfilter')) { if (Spamfilter::checkContent($item)) { $status = 'QUARANTINED'; } else { $status = 'PUBLISHED'; } } else { $status = 'PUBLISHED'; } // Check to make sure the required parameters are present if (!$item['message']) { throw new BaseException('Missing required key message for comment item'); } if ((!$item['name'] || !$item['email']) && !$item['userid']) { throw new BaseException('Missing required key for comment item (name,email or userid)'); } if (!$item['ip']) { $item['ip'] = request::getRemoteHost(); } $ambient = array(); foreach ($item as $k => $i) { switch ($k) { case 'ip': case 'subject': case 'message': case 'userid': case 'name': case 'email': case 'website': case 'status': break; default: $ambient[$k] = $i; } } // Save the comment $rs = $db->updateRow("INSERT INTO comments (ns,uri,postdate,userid,name,email,website,ip,message,status,ambient) " . "VALUES ('%s','%s',NOW(),'%d','%s','%s','%s','%s','%s','%s','%s')", $ns, $uri, $item['userid'], $item['name'], $item['email'], $item['website'], $item['ip'], $item['message'], $status, serialize($ambient)); }
} function getLastError() { return $this->lasterror; } static function register($handler) { $sh = new $handler(); ShutdownHandler::$handlers[$handler] = $sh; register_shutdown_function(array(ShutdownHandler::$handlers[$handler], "shutdown")); } } /** * @class ConsoleShutdownHandler * * */ class ConsoleShutdownHandler extends ShutdownHandler { function shutdown() { if ($this->wasError()) { // TODO: Write pretty error info // printf("There was an error!\n"); // print_r($this->getLastError()); } } } ShutdownHandler::register('ConsoleShutdownHandler'); Lepton::setExceptionHandler('ConsoleExceptionHandler');
static function setErrorHandler($handler, $override = false) { if ($override == true || self::$__errorhandler == null) { self::$__errorhandler = $handler; console::debugEx(LOG_BASIC, __CLASS__, "Assigned error handler: %s", $handler); } else { console::debugEx(LOG_BASIC, __CLASS__, "Ignoring error handler: %s", $handler); } }
logger::emerg($dbg); if (config::get('lepton.mvc.exception.log', false) == true) { $logfile = config::get('lepton.mvc.exception.logfile', "/tmp/" . $_SERVER['HTTP_HOST'] . "-debug.log"); $log = "=== Unhandled Exception ===\n\n" . $dbg . "\n"; $lf = @fopen($logfile, "a+"); if ($lf) { fputs($lf, $log); fclose($lf); } } $ico_error = resource::get('warning.png'); header('content-type: text/html; charset=utf-8'); echo '<html><head><title>Unhandled Exception</title>' . self::$css . self::$js . '</head><body>' . '<div id="box"><div id="left"><img src="' . $ico_error . '" width="32" height="32"></div><div id="main">' . '<h1>An Unhandled Exception Occured</h1>' . '<hr noshade>' . '<p>This means that something didn\'t go quite go as planned. This could be ' . 'caused by one of several reasons, so please be patient and try ' . 'again in a little while.</p>'; if (config::get('lepton.mvc.exception.feedback', false) == true) { echo '<p>The administrator of the website has been notified about this error. You ' . 'can help us find and fix the problem by writing a line or two about what you were doing when this ' . 'error occured.</p>'; echo '<p id="feedbacklink"><a href="javascript:doFeedback();">If you would like to assist us with more information, please click here</a>.</p>'; echo '<div id="feedback" style="display:none;"><p>Describe in a few short lines what you were doing right before you encountered this error:</p><form action="/errorevent.feedback/' . $id . '" method="post"><div><textarea name="text" style="width:100%; height:50px;"></textarea></div><div style="padding-top:5px; text-align:right;"><input type="button" value=" Close " onclick="closeFeedback();"> <input type="submit" value=" Submit Feedback "></div></form></div>'; } if (config::get('lepton.mvc.exception.showdebug', false) == true) { echo '<hr noshade>' . '<a href="javascript:toggleAdvanced();">Details »</a>' . '<pre id="advanced" style="display:none; height:300px;">' . $dbg . '</pre>'; } echo '<div>' . '</body></html>'; } } if (config::get('lepton.mvc.exception.feedback', false) == true) { Router::hookRequestUri('^\\/errorevent\\.feedback\\/(.*)$', array('MvcExceptionHandler', 'saveFeedback')); } MvcExceptionHandler::$css = '<style type="text/css">' . 'body { background-color:#202020; }' . 'hr { height:1px; color:#C0C0C0; background-color:#C0C0C0; border:solid 1px transparent; padding:0px; margin:10px 0px 10px 0px; }' . '#box { -moz-border-radius:10px; -webkit-border-radius:10px; -opera-border-radius:10px; background-color:#E0E0E0; padding:15px; width:690px; margin:50px auto 20px auto; overflow:hidden; border:solid 2px #C0C0C0; -moz-box-shadow:5px 5px 25px #000; }' . '#left { float:left; width:20px; padding:2px 25px 0px 10px; }' . '#main { float:left; width:630px; }' . 'h1 { margin:4px 0px 4px 0px; padding:0px; font:bold 14pt sans-serif; color:#404040; }' . 'p { margin:4px 0px 4px 0px; padding:0px; font:8pt sans-serif; color:#404040; }' . 'textarea { overflow-y:scroll; overflow-x:hidden; font-size:8pt; padding:5px; background-color:#F8F8F8; border:inset 1px #F0F0F0; }' . 'pre { overflow-x:scroll; overflow-y:scroll; font-size:8pt; padding:5px; background-color:#F8F8F8; border:inset 1px #F0F0F0; }' . 'a { color:#A06060; text-decoration:underline; font: 8pt sans-serif; text-decoration:none; }' . 'a:hover { text-decoration:underline; }' . 'input[type=button] { font:8pt sans-serif; color:#606060; }' . 'input[type=submit] { font:8pt sans-serif; color:#202020; }' . '</style>'; MvcExceptionHandler::$js = '<script type="text/javascript">' . 'function toggleAdvanced() { ' . 'var el = document.getElementById("advanced"); ' . 'if (el.style.display == "none") { ' . 'el.style.display = "block"; ' . '} else { ' . 'el.style.display = "none"; ' . '}' . '}' . 'function doFeedback() {' . 'document.getElementById("feedbacklink").style.display = "none";' . 'document.getElementById("feedback").style.display = "block";' . '}' . 'function closeFeedback() {' . 'document.getElementById("feedbacklink").style.display = "block";' . 'document.getElementById("feedback").style.display = "none";' . '}' . '</script>'; Lepton::setExceptionHandler('MvcExceptionHandler');
<?php /** * @file index.php * * Lepton/NG: MVC Application Entrypoint * * Part of Lepton/NG - (c) 2010, Noccy Labs * Distributed under the GNU GPL v3 * * NOTE: * You probably don't have to change anything in here. Just make sure your * configuration is correct (located in your app/config directory) * * @license GPL v2 * @author Christopher Vagnetoft <*****@*****.**> */ // Load configuration and the base system. require 'sys/base.php'; // debug::enable(); // Initialize an MVC application to handle the request for us ModuleManager::load('lepton.base.mvc'); Lepton::run('MvcApplication', 'app');