/** * Save text to a caller-defined log * * If the log doesn't currently exist, it will be created. * * The log filename is /site/assets/logs/[name].txt * * @param string $name Name of log to save to (word consisting of [-._a-z0-9] and no extension) * @param string $text Text to save to the log * @return bool Whether it was written (usually assumed to be true) * @throws WireException * */ public function ___save($name, $text) { $log = new FileLog($this->getFilename($name)); $log->setDelimeter("\t"); $user = $this->wire('user'); $page = $this->wire('page'); $text = str_replace(array("\r", "\n", "\t"), ' ', strip_tags($text)); $line = ($user ? $user->name : "?") . "\t" . ($page ? $page->httpUrl : "?") . "\t" . $text; return $log->save($line); }
protected function validation() { // process the submitted form $this->form->processInput($this->input->post); // check if honeypot is checked $spam_field = $this->form->get("sendemail"); $spam_action = $this->sanitizer->text($this->input->post->sendemail); // if it is checked, add an error to the error array if ($spam_action == 1) { $spam_field->error("If you are human, you'd best email us directly; your submission is being detected as spam! If you are a robot, please ignore this."); // write this attempt to a log $spam_log = new FileLog($this->config->paths->logs . 'detectedspam.txt'); $spam_log->save('Spam caught: ' . $this->sanitizer->textarea($this->input->post->body)); } }
/** * Save text to a caller-defined log * * If the log doesn't currently exist, it will be created. * * The log filename is /site/assets/logs/[name].txt * * @param string $name Name of log to save to (word consisting of [-._a-z0-9] and no extension) * @param string $text Text to save to the log * @param array $options Options to modify behavior (defaults: showUser=true, showPage=true, delimiter=\t) * @return bool Whether it was written (usually assumed to be true) * @throws WireException * */ public function ___save($name, $text, $options = array()) { $defaults = array('showUser' => true, 'showPage' => true, 'delimiter' => "\t"); $options = array_merge($defaults, $options); $log = new FileLog($this->getFilename($name)); $log->setDelimeter($options['delimiter']); $text = str_replace(array("\r", "\n", "\t"), ' ', $text); if ($options['showPage']) { $page = $this->wire('page'); $text = ($page && $page->id ? $page->httpUrl : "page?") . "{$options['delimiter']}{$text}"; } if ($options['showUser']) { $user = $this->wire('user'); $text = ($user && $user->id ? $user->name : "user?") . "{$options['delimiter']}{$text}"; } return $log->save($text); }
function ProcessWireShutdown() { $types = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict Warning', E_RECOVERABLE_ERROR => 'Recoverable Fatal Error'); $fatalTypes = array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_PARSE, E_RECOVERABLE_ERROR); $error = error_get_last(); if (!$error) { return true; } $type = $error['type']; if (!in_array($type, $fatalTypes)) { return true; } $http = isset($_SERVER['HTTP_HOST']); $config = wire('config'); $user = wire('user'); $userName = $user ? $user->name : '?'; $page = wire('page'); $path = ($config ? $config->httpHost : '') . ($page ? $page->url : '/?/'); if ($config && $http) { $path = ($config->https ? 'https://' : 'http://') . $path; } $line = $error['line']; $file = $error['file']; $message = isset($types[$type]) ? $types[$type] : 'Error'; if (strpos($error['message'], "\t") !== false) { $error['message'] = str_replace("\t", ' ', $error['message']); } $message .= ": \t{$error['message']}"; if ($type != E_USER_ERROR) { $message .= " (line {$line} of {$file}) "; } $debug = false; $log = null; $why = ''; $who = ''; $sendOutput = true; if ($config) { $debug = $config->debug; $sendOutput = $config->allowExceptions !== true; if ($config->ajax) { $http = false; } if ($config->adminEmail && $sendOutput) { $logMessage = "Page: {$path}\nUser: {$userName}\n\n" . str_replace("\t", "\n", $message); wireMail($config->adminEmail, $config->adminEmail, 'ProcessWire Error Notification', $logMessage); } if ($config->paths->logs) { $logMessage = "{$userName}\t{$path}\t" . str_replace("\n", " ", $message); $log = new FileLog($config->paths->logs . 'errors.txt'); $log->setDelimeter("\t"); $log->save($logMessage); } } if (!$sendOutput) { return true; } // we populate $who to give an ambiguous indication where the full error message has been sent if ($log) { $who .= "Error has been logged. "; } if ($config && $config->adminEmail) { $who .= "Administrator has been notified. "; } // we populate $why if we're going to show error details for any of the following reasons: // otherwise $why will NOT be populated with anything if ($debug) { $why = "site is in debug mode (\$config->debug = true; in /site/config.php)."; } else { if (!$http) { $why = "you are using the command line API."; } else { if ($user && $user->isSuperuser()) { $why = "you are logged in as a Superuser."; } else { if ($config && is_file($config->paths->root . "install.php")) { $why = "/install.php still exists."; } else { if ($config && !is_file($config->paths->assets . "active.php")) { // no login has ever occurred or user hasn't logged in since upgrade before this check was in place // check the date the site was installed to ensure we're not dealing with an upgrade $installed = $config->paths->assets . "installed.php"; if (!is_file($installed) || filemtime($installed) > time() - 21600) { // site was installed within the last 6 hours, safe to assume it's a new install $why = "Superuser has never logged in."; } } } } } } if ($why) { // when in debug mode, we can assume the message was already shown, so we just say why. // when not in debug mode, we display the full error message since error_reporting and display_errors are off. $why = "This error message was shown because {$why} {$who}"; $html = "<p><b>{message}</b><br /><small>{why}</small></p>"; if ($http) { if ($config && $config->fatalErrorHTML) { $html = $config->fatalErrorHTML; } $html = str_replace(array('{message}', '{why}'), array(nl2br(htmlspecialchars($message, ENT_QUOTES, "UTF-8", false)), htmlspecialchars($why, ENT_QUOTES, "UTF-8", false)), $html); // make a prettier looking debug backtrace, when applicable $html = preg_replace('!(<br[^>]*>\\s*)(#\\d+\\s+[^<]+)!is', '$1<code>$2</code>', $html); echo "\n\n{$html}\n\n"; } else { echo "\n\n{$message}\n\n{$why}\n\n"; } } else { // public fatal error that doesn't reveal anything specific if ($http) { header("HTTP/1.1 500 Internal Server Error"); } // file that error message will be output in, when available $file = $config && $http ? $config->paths->templates . 'errors/500.html' : ''; if ($file && is_file($file)) { // use defined /site/templates/errors/500.html file echo str_replace('{message}', $who, file_get_contents($file)); } else { // use generic error message, since no 500.html available echo "\n\nUnable to complete this request due to an error. {$who}\n\n"; } } return true; }
<?php $vowel = array('a' => 'ᅡ', 'eo' => 'ᅥ', 'o' => 'ᅩ', 'u' => 'ᅮ', 'eu' => 'ᅳ', 'i' => 'ᅵ', 'ae' => 'ᅢ', 'e' => 'ᅦ', 'oe' => 'ᅬ', 'wi' => 'ᅱ', 'ya' => 'ㅑ', 'yeo' => 'ㅕ', 'yo' => 'ㅛ', 'yu' => 'ㅠ', 'yae' => 'ㅒ', 'ye' => 'ᅨ', 'wa' => 'ᅪ', 'wae' => 'ᅫ', 'wo' => 'ᅯ', 'we' => 'ᅰ', 'ui' => 'ᅴ', 'y' => 'ㅣ'); $consonant = array('g' => 'ㄱ', 'k' => 'ㄱ', 'kk' => 'ㄲ', 'k' => 'ㅋ', 'd' => 'ㄷ', 't' => 'ㄷ', 'tt' => 'ㄸ', 't' => 'ㅌ', 'b' => 'ㅂ', 'pp' => 'ㅃ', 'p' => 'ㅍ', 'j' => 'ㅈ', 'jj' => 'ㅉ', 'ch' => 'ㅊ', 's' => 'ㅅ', 'ss' => 'ㅆ', 'h' => 'ㅎ', 'n' => 'ㄴ', 'm' => 'ㅁ', 'ng' => 'ㅇ', 'r' => 'ㄹ', 'l' => 'ㄹ', 'f' => 'ㅍ', 'q' => 'ㅋ', 'x' => 'ㅋ', 'z' => 'ㅈ'); require_once 'lib/FileLog.class.php'; $f = new FileLog('data/names.tsv', array('time', 'name', 'korean')); if ($_POST['name']) { $f->save(array(time(), $_POST['name'], strlen($_POST['korean']) > 0 ? $_POST['korean'] : $_POST['mozilla'])); header('Location: ./'); exit; } $d = $f->load(); $d = array_reverse($d); ?> <!DOCTYPE html> <html lang="en-US"> <head> <meta name="viewport" content="width=device-width" /> <meta charset="UTF-8"> <title>Let's type my name in Korean.</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>My Name to Korean</h1> <p>Let's try to type my name in Korean with Firefox OS Korean keyboard.</p> <h2>Conversion table</h2> <h3>vowel</h3> <ul class="table"> <?php ksort($vowel);
/** * Look for errors at shutdown and log them, plus echo the error if the page is editable * */ function ProcessWireShutdown() { $types = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'ProcessWire Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict Warning', E_RECOVERABLE_ERROR => 'Recoverable Fatal Error'); $fatalTypes = array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR); $error = error_get_last(); $type = $error['type']; if (in_array($type, $fatalTypes)) { $config = wire('config'); $user = wire('user'); $userName = $user ? $user->name : 'Unknown User'; $page = wire('page'); $path = $page ? $page->url : '/?/'; $line = $error['line']; $file = $error['file']; $message = "{$error['message']}"; $debug = false; if ($type != E_USER_ERROR) { $message .= " (line {$line} of {$file})"; } if ($config) { $debug = $config->debug; $logMessage = "{$userName}:{$path}:{$types[$type]}:{$message}"; if ($config->adminEmail) { @mail($config->adminEmail, 'ProcessWire Error Notification', $logMessage); } $logMessage = str_replace("\n", " ", $logMessage); if ($config->paths->logs) { $log = new FileLog($config->paths->logs . "errors.txt"); $log->save($logMessage); } } if ($debug || !isset($_SERVER['HTTP_HOST']) || $user && $user->isSuperuser()) { // when in debug mode, we can assume the message was already shown, so we just say why. // when not in debug mode, we display the full error message since error_reporting and display_errors are off. if ($debug) { $message = "This error message was shown because the site is in DEBUG mode."; } else { $message .= "\n\nThis error message was shown because you are logged in as a Superuser."; } if (isset($_SERVER['HTTP_HOST'])) { $message = "<p class='WireFatalError'>" . nl2br($message) . "</p>"; } echo "\n\n{$message}\n\n"; } else { header("HTTP/1.1 500 Internal Server Error"); echo "Unable to complete this request due to an error"; } } }
/** * Look for errors at shutdown and log them, plus echo the error if the page is editable * */ function ProcessWireShutdown() { $types = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Strict Warning', E_RECOVERABLE_ERROR => 'Recoverable Fatal Error'); $fatalTypes = array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_PARSE, E_RECOVERABLE_ERROR); $error = error_get_last(); if (!$error) { return; } $type = $error['type']; if (!in_array($type, $fatalTypes)) { return; } $http = isset($_SERVER['HTTP_HOST']); $config = wire('config'); $user = wire('user'); $userName = $user ? $user->name : '?'; $page = wire('page'); $path = ($config ? $config->httpHost : '') . ($page ? $page->url : '/?/'); if ($config && $http) { $path = ($config->https ? 'https://' : 'http://') . $path; } $line = $error['line']; $file = $error['file']; $message = isset($types[$type]) ? $types[$type] : 'Error'; if (strpos($error['message'], "\t") !== false) { $error['message'] = str_replace("\t", ' ', $error['message']); } $message .= "\t{$error['message']}"; if ($type != E_USER_ERROR) { $message .= " (line {$line} of {$file}) "; } $debug = false; $log = null; $why = ''; $who = ''; if ($config) { $debug = $config->debug; if ($config->ajax) { $http = false; } if ($config->adminEmail) { $logMessage = "Page: {$path}\nUser: {$userName}\n\n" . str_replace("\t", "\n", $message); @mail($config->adminEmail, 'ProcessWire Error Notification', $logMessage); } if ($config->paths->logs) { $logMessage = "{$userName}\t{$path}\t" . str_replace("\n", " ", $message); $log = new FileLog($config->paths->logs . 'errors.txt'); $log->setDelimeter("\t"); $log->save($logMessage); } } // we populate $who to give an ambiguous indication where the full error message has been sent if ($log) { $who .= "Error has been logged. "; } if ($config && $config->adminEmail) { $who .= "Administrator has been notified. "; } // we populate $why if we're going to show error details for any of the following reasons: if ($debug) { $why = "site is in debug mode (\$config->debug = true; in /site/config.php)."; } else { if (!$http) { $why = "you are using the command line API."; } else { if ($user && $user->isSuperuser()) { $why = "you are logged in as a Superuser."; } else { if ($config && is_file($config->paths->root . "install.php")) { $why = "/install.php still exists."; } else { if ($config && !is_file($config->paths->assets . "active.php")) { // no login has ever occurred or user hasn't logged in since upgrade before this check was in place // check the date the site was installed to ensure we're not dealing with an upgrade $installed = $config->paths->assets . "installed.php"; if (!is_file($installed) || filemtime($installed) > time() - 21600) { // site was installed within the last 6 hours, safe to assume it's a new install $why = "Superuser has never logged in."; } } } } } } if ($why) { // when in debug mode, we can assume the message was already shown, so we just say why. // when not in debug mode, we display the full error message since error_reporting and display_errors are off. $why = "This error message was shown because {$why} {$who}"; if ($http) { $why = "<em>{$why}</em>"; } if ($debug) { $message = $why; } else { $message .= "\n\n{$why}"; } if ($http) { $message = "<p class='error WireFatalError'>" . nl2br($message) . "</p>"; } echo "\n\n{$message}\n\n"; } else { header("HTTP/1.1 500 Internal Server Error"); echo "Unable to complete this request due to an error. {$who}"; } return true; }