public static function sendException($file, $message, $trace) { $body = "<html><body>\n"; $body .= "<h3>{$file}</h3><p>{$message}</p><p><pre>{$trace}</pre></p>"; $body .= "</body></html>\n"; $alt = strip_tags($body); $creds = ["from" => self::getWebmasterEmail(), "name" => self::getWebmasterEmail(), "reply" => self::getWebmasterEmail(), "subject" => ENV . '-' . CShell::id() . " Webinar Error", "category" => CShell::id()]; SystemTool::sendEmail($creds, SystemTool::getWebmasterEmail(), $body, $alt); }
/** * Dissect the URL and route the request. */ function callHook() { $controller = CShell::id(); $action = 'home'; $queryString = array(); try { //Remove all get parameters $URI = preg_replace('/\\?(.*)/', '', $_SERVER['REQUEST_URI']); $urlArray = explode("/", str_replace('-', '_', $URI)); //The first segment will always be empty if (count($urlArray) > 0) { array_shift($urlArray); } if (count($urlArray) > 0 && $urlArray[0] != '') { //Ignore the sub-folder if it exists. if (PageTool::getSubFolder() != '') { array_shift($urlArray); } /** * If an exception is triggered or the dc is set to false set the controller. */ if (count($urlArray) > 0 && (in_array($urlArray[0], CShell::exceptions()) || in_array($urlArray[0], CShell::system()) || !CShell::default_controller())) { $controller = $urlArray[0]; array_shift($urlArray); } //Set the action. if (count($urlArray) > 0) { //If GoLink skip assignment of action. if ($controller != CShell::GO) { $action = $urlArray[0]; array_shift($urlArray); } //Set the arguments if (count($urlArray) > 0) { $queryString = $urlArray; } } } $controllerName = $controller; $controller = ucwords($controller); $controller .= 'Controller'; if (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php')) { require_once ROOT . DS . 'app' . DS . 'controllers' . DS . $controller . '.php'; } elseif (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php')) { require_once ROOT . DS . 'app' . DS . 'controllers' . DS . 'system' . DS . $controller . '.php'; } if (class_exists($controller) && method_exists($controller, $action)) { $dispatch = new $controller($controllerName, $action); } else { header('HTTP/1.0 404 Not Found'); exit; } call_user_func_array(array($dispatch, $action), $queryString); } catch (Exception $e) { SystemTool::sendException($e->getFile(), $e->getMessage(), $e->getTraceAsString()); } }
/** * Exception handler * @param Exception $exception The exception raised */ function exceptionHandler($exception) { try { $exceptionMessage = NULL; // If a transaction is in progress, rollback it if (DatabaseFactory::isTransactionInProgress()) { DatabaseFactory::rollback(); } // logs exception before doing anything else, for logs to be filled even if an exception will occur during the exception treatment $logInstance = LogTool::getInstance(); // debug exception in web context if ($exception instanceof GenericWarningException) { // logs warning $logInstance->logException($exception, LogTool::WARNING_LEVEL); } else { // logs error $logInstance->logException($exception); } $exceptionClass = get_class($exception); if ($exception instanceof GenericException) { // Displays message if (TranslationTool::isTranslationAllowed()) { $exceptionMessage = $exception->getUserLocalizedMessage(); } else { $exceptionMessage = $exception->getMessage(); } } else { // If error is not managed, displays generic message $exceptionMessage = 'GENERIC_EXCEPTION'; } if (SystemTool::isAjaxContext()) { echo json_encode(array('error' => $exceptionMessage), true); } else { echo $exceptionMessage; } } catch (Exception $e) { echo $e->getMessage(); try { LogTool::getInstance()->logException($e); echo $exceptionClass . ' raised : ' . $exceptionMessage; echo '+ ' . get_class($e) . ' while handling exception : ' . $e->getMessage(); exit(LogTool::KO_RETURN_CODE); } catch (Exception $e2) { try { LogTool::getInstance()->logException($e2); echo $exceptionClass . ' raised (unable to display exception details)'; exit(LogTool::KO_RETURN_CODE); } catch (Exception $e3) { echo 'unable to display exception details'; exit; } } } }
public static function getSeconds() { date_default_timezone_set('America/New_York'); $targetDate = self::getTargetDate(); $seconds = $targetDate - time(); if (isset($_GET['seconds'])) { $seconds = SystemTool::sanitize($_GET['seconds'], 3); } if ($seconds < 1) { $seconds = 2; } return $seconds; }
<?php // Starts session before header is sent session_start(); require_once 'globals/globals.php'; require_once 'core/functions.php'; // init Smarty require_once 'smarty.inc.php'; // Gets class_loader require_once 'class_loader.inc.php'; // Gets error handler require_once 'error_handler.inc.php'; SystemTool::$context = SystemTool::CONTEXT_AJAX; // starts transaction DatabaseFactory::startTransaction(); $authenticationInstance = AuthenticationTool::getInstance(); $isPlayerConnected = $authenticationInstance->isPlayerConnected(); // TODO: Checks that player has access to the admin part
/** * Checks if context allowed translation */ public static function isTranslationAllowed() { // No gettext in other context than web return SystemTool::isWebProcess(); }
/** * @return null|str */ public static function checkEID() { $e = null; if (isset($_GET["eid"])) { //Sanitize for base 64 $e = base64_decode(SystemTool::sanitize($_GET["eid"], 1)); //Sanitize for email $e = SystemTool::sanitize($e, 2); //Is it a valid email? if (SystemTool::validate($e)) { setcookie(SystemTool::getCookieName(), base64_encode($e), PageTool::getCookieLength(), CShell::cookiePath(), CShell::cookieDomain()); } else { $e = null; } } return $e; }
<?php require_once 'globals/globals.php'; require_once 'core/functions.php'; // Gets class_loader require_once 'class_loader.inc.php'; // Gets error handler require_once 'error_handler.inc.php'; SystemTool::$context = SystemTool::CONTEXT_ENGINE;
<?php /** * 首页 * 分类,幻灯片,其它链接 */ ini_set('display_errors', 1); require_once './config.inc.php'; //用户openid if (empty($_SESSION['openid'])) { $redirecturl = SITE_DOMAIN . 'index.php'; $redirecturl .= '#' . time(); SystemTool::checkOpenid($db, 'snsapi_userinfo', $redirecturl); } //分类数据 $allcategory = SystemTool::getAllCategory($db); $pageidx = 'index'; //meta信息 $title = '微官网--同城新媒'; //template include 'template/index.html';
break; case 0: $db->query("insert into clicklog(`contentid`,`openid`,`shareopenid`,`ip`,`msg`,`isvalid`) values(" . $contentinfo['id'] . ",'" . $clickOpenid . "','" . $shareOpenid . "','" . $_SERVER['REMOTE_ADDR'] . "','位置不在分钱范围内','0')"); $msg = array('result' => false, 'msg' => '位置不在分钱范围内'); echo json_encode($msg); exit; break; case -2: $db->query("insert into clicklog(`contentid`,`openid`,`shareopenid`,`ip`,`msg`,`isvalid`) values(" . $contentinfo['id'] . ",'" . $clickOpenid . "','" . $shareOpenid . "','" . $_SERVER['REMOTE_ADDR'] . "','数据插入错误','0')"); $msg = array('result' => false, 'msg' => '数据插入错误'); echo json_encode($msg); exit; break; case 1: $db->query("insert into clicklog(`contentid`,`openid`,`shareopenid`,`ip`,`msg`,`isvalid`) values(" . $contentinfo['id'] . ",'" . $clickOpenid . "','" . $shareOpenid . "','" . $_SERVER['REMOTE_ADDR'] . "','点击有效','1')"); $msg = array('result' => true, 'msg' => '本次阅读为你的好友增加¥' . $clickprice); echo json_encode($msg); exit; break; default: $msg = array('result' => false, 'msg' => '服务器异常错误'); echo json_encode($msg); exit; } } else { SystemTool::systemLog($db, '点击统计错误', '参数错误或缺少参数', $_SERVER['REMOTE_ADDR'] . print_r($_POST, true)); $db->query("insert into clicklog(`contentid`,`openid`,`shareopenid`,`ip`,`msg`,`isvalid`) values(" . $contentinfo['id'] . ",'" . $clickOpenid . "','" . $shareOpenid . "','" . $_SERVER['REMOTE_ADDR'] . "','数据异常','0')"); } echo '0'; exit; }
<?php /** * User: Matthew Pollotta * Date: 7/12/13 */ require_once ROOT . DS . 'vendor' . DS . 'autoload.php'; SystemTool::setEnvironment(); require_once ROOT . DS . 'lib' . DS . 'jetstream' . DS . 'bootstrap' . DS . 'shared.php';
/** * Gets current log file path * @return string Current log file path */ public function getLogFilePath() { $this->currentLogDate = DateTool::getTimeString(DateTool::FORMAT_MYSQL_DATE); // Checks which context is used if (SystemTool::isScriptProcess()) { // process is an engine, get its name from file used $logFileName = basename($_SERVER['PHP_SELF'], '.php'); } else { $logFileName = 'web'; } $logFilePath = LOG_DIR . '/' . $this->currentLogDate . '-' . $logFileName . '.log'; return $logFilePath; }
protected static function setCredentials() { static::$_DBHOST = SystemTool::getDBHost(); static::$_DBUSER = SystemTool::getDBUser(); static::$_DBPASS = SystemTool::getDBPass(); }
public function refer() { $this->setCache(false); $this->_return = self::PROCESS; $backto = ''; if (isset($_POST["backto"])) { $backto = $_POST["backto"]; } $from = ''; if (isset($_POST["from"])) { $from = $_POST["from"]; } //Sanitize for base 64 $sender = base64_decode(SystemTool::sanitize($_COOKIE[SystemTool::getCookieName()], 1)); //Sanitize for email $sender = SystemTool::sanitize($sender, 2); //Is it a valid email? If not back to refer page. if (!SystemTool::validate($sender)) { header("Location: " . PageTool::getSiteRoot() . $backto); exit; } $success = 0; $emails = explode(",", $_POST["email"]); foreach ($emails as $email) { $email = SystemTool::sanitize($email, 2); if (SystemTool::validate($email)) { $WRM = new Webinar_referModel(); $WRM->addRecord(CShell::webinar_id(), $email, SystemTool::getTimestamp()); //Set up and render the email HTML. $eTemplate = new Template('email_share'); if ($from == "cr") { $eTemplate->set('cr', true); } $body = $eTemplate->render(false); $body = str_replace("!!EMAIL!!", $sender, $body); $alt = strip_tags($body); //Send the email. $PHPEmails = CShell::emails(); $PHPEmails["refer"]["subject"] = 'An invitation from ' . $sender . ' - The Street Gold Event'; SystemTool::sendEmail($PHPEmails["refer"], $email, $body, $alt); $success = 1; } } if ($success) { setcookie(CShell::REFER, '1', PageTool::getCookieLength(), CShell::cookiePath(), CShell::cookieDomain()); // 1yr cookie header('Location: /' . $backto); exit; } else { header('Location: /' . $backto . '?e=no'); exit; } }
private function send_exception($file, $message, $trace) { $body = "<html><body>\n"; $body .= "<h2>{$file}</h2><br/><p>{$message}</p><br/><p><pre>{$trace}</pre></p>"; $body .= "</body></html>\n"; $alt = strip_tags($body); $creds = ["from" => "*****@*****.**", "name" => "Casey Research", "reply" => "*****@*****.**", "subject" => "Casey Research Link Server Error", "category" => "Link Server Error"]; SystemTool::sendEmail($creds, SystemTool::getWebmasterEmail(), $body, $alt); }
/** * Checks if current page is an ajax page * @param boolean $checkIsWebProcess Specifies if methods has to use isWebProcess method * @return boolean Current page is an ajax page */ public static function isAjaxContext() { return SystemTool::isWebProcess() && SystemTool::$context == SystemTool::CONTEXT_AJAX; }
ini_set('display_errors', 1); require_once './config.inc.php'; $contentid = intval($_GET['id']); //share openid if (isset($_GET['shareopenid']) && !empty($_GET['shareopenid'])) { $shareopenid = $_GET['shareopenid']; } //用户openid if (empty($_SESSION['openid'])) { SystemTool::systemLog($db, 'content.php', 'empty session openid', 'check openid'); $redirecturl = SITE_DOMAIN . 'content.php?id=' . $contentid; if (!empty($shareopenid)) { $redirecturl .= '&shareopenid=' . $shareopenid; } $redirecturl .= '#' . time(); SystemTool::checkOpenid($db, 'snsapi_userinfo', $redirecturl); exit; } $content = ContentClass::getArticle($db, $contentid); if (empty($content)) { echo '内容不存在或者已删除'; exit; } if (!empty($shareopenid)) { $isclicked = ClickCount::checkisClicked($db, $contentid, $_SESSION['openid'], $shareopenid); } $tempareadata = json_decode($content['city'], true); $data['province'] = $tempareadata['province']; $data['tempcity'] = $tempareadata['city']; $data['district'] = is_array($tempareadata['district']) ? implode(',', $tempareadata['district']) : ''; if (!empty($data['district'])) {