本文整理汇总了PHP中TBGContext::isCLI方法的典型用法代码示例。如果您正苦于以下问题:PHP TBGContext::isCLI方法的具体用法?PHP TBGContext::isCLI怎么用?PHP TBGContext::isCLI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBGContext
的用法示例。
在下文中一共展示了TBGContext::isCLI方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: log
/**
* Log a message to the logger
*
* @param string $message The message to log
* @param string $category[optional] The message category (default "main")
* @param integer $level[optional] The loglevel
*/
public static function log($message, $category = 'main', $level = 1)
{
if (!self::$_logging_enabled) {
return false;
}
if (self::$_loglevel > $level) {
return false;
}
if (self::$_cli_log_to_screen_in_debug_mode && TBGContext::isCLI() && TBGContext::isDebugMode() && class_exists('TBGCliCommand')) {
TBGCliCommand::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold');
TBGCliCommand::cli_echo(" [{$category}] ", 'green', 'bold');
TBGCliCommand::cli_echo("{$message}\n");
}
if (self::$_logonajaxcalls || TBGContext::getRequest()->isAjaxCall()) {
if (self::$_logfile !== null) {
file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND);
}
$time_msg = TBGContext::isDebugMode() ? ($load_time = TBGContext::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms' : '';
self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level);
self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level);
}
}
示例2: formatTime
//.........这里部分代码省略.........
case 11:
$tstring = strftime($this->getDateTimeFormat(9), $tstamp);
break;
case 12:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ', ';
} else {
$tstring .= strftime($this->getDateTimeFormat(12) . ', ', $tstamp);
}
$tstring .= strftime($this->getDateTimeFormat(14), $tstamp);
break;
case 13:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
//$tstring .= __('Today') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ', ';
} else {
$tstring .= strftime($this->getDateTimeFormat(12) . ', ', $tstamp);
}
$tstring .= strftime($this->getDateTimeFormat(14), $tstamp);
break;
case 14:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow');
} else {
$tstring .= strftime($this->getDateTimeFormat(12), $tstamp);
}
break;
case 15:
$tstring = strftime($this->getDateTimeFormat(11), $tstamp);
break;
case 16:
$tstring = strftime($this->getDateTimeFormat(12), $tstamp);
break;
case 17:
$tstring = strftime($this->getDateTimeFormat(13), $tstamp);
break;
case 18:
$tstring = strftime($this->getDateTimeFormat(16), $tstamp);
break;
case 19:
$tstring = strftime($this->getDateTimeFormat(14), $tstamp);
break;
case 20:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today') . ' (' . strftime('%H:%M', $tstamp) . ')';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ' (' . strftime('%H:%M', $tstamp) . ')';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ' (' . strftime('%H:%M', $tstamp) . ')';
} else {
$tstring .= strftime($this->getDateTimeFormat(15), $tstamp);
}
break;
case 21:
$tstring = TBGContext::isCLI() ? strftime('%a, %d %b %Y %H:%M:%S GMT', $tstamp) : strftime($this->getDateTimeFormat(17), $tstamp);
if (\caspar\core\Caspar::getUser()->getTimezone() > 0) {
$tstring .= '+';
}
if (\caspar\core\Caspar::getUser()->getTimezone() < 0) {
$tstring .= '-';
}
if (\caspar\core\Caspar::getUser()->getTimezone() != 0) {
$tstring .= \caspar\core\Caspar::getUser()->getTimezone();
}
break;
case 22:
$tstring = strftime($this->getDateTimeFormat(15), $tstamp);
break;
case 23:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow');
} else {
$tstring .= strftime($this->getDateTimeFormat(15), $tstamp);
}
break;
default:
return $tstamp;
}
return htmlentities($tstring, ENT_COMPAT, $this->getCharset());
}
示例3: tbg_formatTime
//.........这里部分代码省略.........
case 12:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ', ';
} else {
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12) . ', ', $tstamp);
}
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp);
break;
case 13:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
//$tstring .= __('Today') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ', ';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ', ';
} else {
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12) . ', ', $tstamp);
}
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp);
break;
case 14:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow');
} else {
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(12), $tstamp);
}
break;
case 15:
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(11), $tstamp);
break;
case 16:
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(12), $tstamp);
break;
case 17:
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(13), $tstamp);
break;
case 18:
$old = date_default_timezone_get();
date_default_timezone_set('UTC');
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(16), $tstamp);
date_default_timezone_set($old);
break;
case 19:
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(14), $tstamp);
break;
case 20:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today') . ' (' . strftime('%H:%M', $tstamp) . ')';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday') . ' (' . strftime('%H:%M', $tstamp) . ')';
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow') . ' (' . strftime('%H:%M', $tstamp) . ')';
} else {
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp);
}
break;
case 21:
$tstring = TBGContext::isCLI() ? strftime('%a, %d %b %Y %H:%M:%S GMT', $tstamp) : strftime(TBGContext::getI18n()->getDateTimeFormat(17), $tstamp);
if (TBGContext::getUser()->getTimezone() > 0) {
$tstring .= '+';
}
if (TBGContext::getUser()->getTimezone() < 0) {
$tstring .= '-';
}
if (TBGContext::getUser()->getTimezone() != 0) {
$tstring .= TBGContext::getUser()->getTimezone();
}
break;
case 22:
$tstring = strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp);
break;
case 23:
$tstring = '';
if (date('dmY', $tstamp) == date('dmY')) {
$tstring .= __('Today');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') - 1))) {
$tstring .= __('Yesterday');
} elseif (date('dmY', $tstamp) == date('dmY', mktime(0, 0, 0, date('m'), date('d') + 1))) {
$tstring .= __('Tomorrow');
} else {
$tstring .= strftime(TBGContext::getI18n()->getDateTimeFormat(15), $tstamp);
}
break;
default:
return $tstamp;
}
return htmlentities($tstring);
}
示例4: getArticleLinkTag
public function getArticleLinkTag($matches)
{
$article_name = $matches[0];
if (TBGTextParser::getCurrentParser() instanceof TBGTextParser) {
TBGTextParser::getCurrentParser()->addInternalLinkOccurrence($article_name);
}
$article_name = $this->getSpacedName($matches[0]);
if (!TBGContext::isCLI()) {
TBGContext::loadLibrary('ui');
return link_tag(make_url('publish_article', array('article_name' => $matches[0])), $article_name);
} else {
return $matches[0];
}
}
示例5: _mail2
protected function _mail2(TBGMimemail $email)
{
if (TBGContext::isCLI()) {
$server = php_uname('n');
} else {
$server = $_SERVER['SERVER_NAME'];
}
/* Open a socket connection to the mail server SMTP port (25) and read the welcome message. */
$fp = fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
if (!$fp) {
if ($this->debug) {
echo "No server? {$errno} {$errstr}<br>";
}
throw new Exception(TBGContext::getI18n()->__('Could not open connection to server %server on port %port', array('%server' => $this->server, '%port' => $this->port)));
}
$this->_read_buffer($fp, 'open');
/* Standard "ehlo" message. */
if ($this->ehlo) {
fputs($fp, "ehlo {$server}\r\n");
$this->_read_buffer($fp, 'ehlo');
} else {
fputs($fp, "helo {$server}\r\n");
$this->_read_buffer($fp, 'helo');
}
/* Auth login: (Note that Username and password must be Base64 encoded string.) */
if ($this->username != '') {
fputs($fp, "AUTH LOGIN\r\n");
$rv = fgets($fp, 4096);
if ($this->debug) {
echo base64_decode(mb_substr($rv, 4)) . $this->username . ' ' . $rv . '<br>';
}
fputs($fp, base64_encode($this->username) . "\r\n");
$rv = fgets($fp, 4096);
if ($this->debug) {
echo base64_decode(mb_substr($rv, 4)) . $this->password . ' ' . $rv . '<br>';
}
fputs($fp, base64_encode($this->password) . "\r\n");
$rv = $this->_read_buffer($fp, 'user/pass');
if (preg_match("/^500/i", $rv)) {
if ($this->debug) {
echo 'Not ready to authenticate. (' . $rv . ') Try changing server type';
}
throw new Exception(TBGContext::getI18n()->__('Not ready to authenticate. (%rv) Try changing server type', array('%rv' => $rv)));
}
if (!preg_match("/^235/i", $rv)) {
/* OK Authenticated */
if ($this->debug) {
echo 'Username / password not accepted on server<br>';
}
fclose($fp);
throw new Exception(TBGContext::getI18n()->__('Username / password not accepted on server: %rv', array('%rv' => $rv)));
}
}
// "mail from" message and read the return. Assume everything is OK.
fputs($fp, "mail from: <{$email->getFromaddress()}>\r\n");
$rv = $this->_read_buffer($fp, 'mail_from');
// "rcpt to" message and read the return. Each name in the $to, $cc, and $bcc array requires one "rcpt to"
foreach ($email->getRecipients() as $recipient) {
fputs($fp, "rcpt to: <{$recipient['address']}>\r\n");
$rv = $this->_read_buffer($fp, 'to');
}
if (preg_match("/^550/i", $rv)) {
if ($this->debug) {
echo "You are not allowed to send emails through this server.";
}
throw new Exception(TBGContext::getI18n()->__("You are not allowed to send emails through this server. \nThe error was: %rv", array('%rv' => $rv)));
}
foreach ($email->getCC() as $cc) {
fputs($fp, "rcpt to: <{$cc['address']}>\r\n");
$this->_read_buffer($fp, 'cc');
}
foreach ($email->getBCC() as $bcc) {
fputs($fp, "rcpt to: <{$bcc['address']}>\r\n");
$this->_read_buffer($fp, 'bcc');
}
/* "data" message and the message body follows. */
fputs($fp, "data\r\n");
$this->_read_buffer($fp, 'data');
/* Standard message parts. */
fputs($fp, $email->getHeadersAsString());
foreach ($email->getBody(true) as $body_line) {
fputs($fp, $body_line);
}
/* "quit" message and done. */
fputs($fp, ".\r\n");
fputs($fp, "quit\r\n");
$rv = $this->_read_buffer($fp, 'quit');
fclose($fp);
/* status 250 if Message accepted for delivery */
if (preg_match("/^250/i", $rv)) {
return true;
} else {
if ($this->debug) {
echo "Did not receive a confirmation message from the mail server.";
}
throw new Exception(TBGContext::getI18n()->__("Did not receive a confirmation message from the mail server.. \nHowever, we received: %rv", array('%rv' => $rv)));
}
}
示例6: _construct
public function _construct(B2DBRow $row, $foreign_key = null)
{
if (TBGContext::isCLI()) {
return;
}
$hostprefix = !array_key_exists('HTTPS', $_SERVER) || $_SERVER['HTTPS'] == '' || $_SERVER['HTTPS'] == 'off' ? 'http' : 'https';
$this->_hostname = "{$hostprefix}://{$_SERVER['SERVER_NAME']}";
$port = $_SERVER['SERVER_PORT'];
if ($port != 80) {
$this->_hostname .= ":{$port}";
}
}
示例7: _parse_add_toc
protected function _parse_add_toc($matches)
{
if (TBGContext::isCLI()) {
return '';
}
return TBGAction::returnTemplateHTML('publish/toc', array('toc' => $this->toc));
}
示例8: setupI18n
protected static function setupI18n()
{
if (TBGContext::isCLI()) {
return null;
}
$language = self::$_user instanceof TBGUser ? self::$_user->getLanguage() : 'en_US';
if (self::$_user instanceof TBGUser && self::$_user->getLanguage() == 'sys') {
$language = 'en_US';
}
TBGLogging::log('Loading i18n strings');
if (!(self::$_i18n = TBGCache::get("i18n_{$language}"))) {
TBGLogging::log("Loading strings from file ({$language})");
self::$_i18n = new TBGI18n($language);
self::$_i18n->initialize();
TBGCache::add("i18n_{$language}", self::$_i18n);
} else {
TBGLogging::log('Using cached i18n strings');
}
TBGLogging::log('...done');
}
示例9: tbg_exception
/**
* Displays a nicely formatted exception message
*
* @param string $title
* @param Exception $exception
*/
function tbg_exception($title, $exception)
{
if (TBGContext::getRequest() instanceof TBGRequest && TBGContext::getRequest()->isAjaxCall()) {
TBGContext::getResponse()->ajaxResponseText(404, $title);
}
$ob_status = ob_get_status();
if (!empty($ob_status) && $ob_status['status'] != PHP_OUTPUT_HANDLER_END) {
ob_end_clean();
}
if (TBGContext::isCLI()) {
$trace_elements = null;
if ($exception instanceof Exception) {
if ($exception instanceof TBGActionNotFoundException) {
TBGCliCommand::cli_echo("Could not find the specified action\n", 'white', 'bold');
} elseif ($exception instanceof TBGTemplateNotFoundException) {
TBGCliCommand::cli_echo("Could not find the template file for the specified action\n", 'white', 'bold');
} elseif ($exception instanceof B2DBException) {
TBGCliCommand::cli_echo("An exception was thrown in the B2DB framework\n", 'white', 'bold');
} else {
TBGCliCommand::cli_echo("An unhandled exception occurred:\n", 'white', 'bold');
}
echo TBGCliCommand::cli_echo($exception->getMessage(), 'red', 'bold') . "\n";
echo "\n";
TBGCliCommand::cli_echo('Stack trace') . ":\n";
$trace_elements = $exception->getTrace();
} else {
if ($exception['code'] == 8) {
TBGCliCommand::cli_echo('The following notice has stopped further execution:', 'white', 'bold');
} else {
TBGCliCommand::cli_echo('The following error occured:', 'white', 'bold');
}
echo "\n";
echo "\n";
TBGCliCommand::cli_echo($title, 'red', 'bold');
echo "\n";
TBGCliCommand::cli_echo("occured in\n");
TBGCliCommand::cli_echo($exception['file'] . ', line ' . $exception['line'], 'blue', 'bold');
echo "\n";
echo "\n";
TBGCliCommand::cli_echo("Backtrace:\n", 'white', 'bold');
$trace_elements = debug_backtrace();
}
foreach ($trace_elements as $trace_element) {
if (array_key_exists('class', $trace_element)) {
TBGCliCommand::cli_echo($trace_element['class'] . $trace_element['type'] . $trace_element['function'] . '()');
} elseif (array_key_exists('function', $trace_element)) {
if (in_array($trace_element['function'], array('tbg_error_handler', 'tbg_exception'))) {
continue;
}
TBGCliCommand::cli_echo($trace_element['function'] . '()');
} else {
TBGCliCommand::cli_echo('unknown function');
}
echo "\n";
if (array_key_exists('file', $trace_element)) {
TBGCliCommand::cli_echo($trace_element['file'] . ', line ' . $trace_element['line'], 'blue', 'bold');
} else {
TBGCliCommand::cli_echo('unknown file', 'red', 'bold');
}
echo "\n";
}
if (class_exists('B2DB')) {
echo "\n";
TBGCliCommand::cli_echo("SQL queries:\n", 'white', 'bold');
try {
$cc = 1;
foreach (B2DB::getSQLHits() as $details) {
TBGCliCommand::cli_echo("(" . $cc++ . ") [");
$str = $details['time'] >= 1 ? round($details['time'], 2) . ' seconds' : round($details['time'] * 1000, 1) . 'ms';
TBGCliCommand::cli_echo($str);
TBGCliCommand::cli_echo("] from ");
TBGCliCommand::cli_echo($details['filename'], 'blue');
TBGCliCommand::cli_echo(", line ");
TBGCliCommand::cli_echo($details['line'], 'white', 'bold');
TBGCliCommand::cli_echo(":\n");
TBGCliCommand::cli_echo("{$details['sql']}\n");
}
echo "\n";
} catch (Exception $e) {
TBGCliCommand::cli_echo("Could not generate query list (there may be no database connection)", "red", "bold");
}
}
echo "\n";
die;
}
echo "\n\t\t<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\t\t<html>\n\t\t<head>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: \"Droid Sans\", \"Trebuchet MS\", \"Liberation Sans\", \"Nimbus Sans L\", \"Luxi Sans\", Verdana, sans-serif; font-size: 13px; }\n\t\th1 { margin: 5px 0 0 0; font-size: 19px; }\n\t\th2 { margin: 0 0 15px 0; font-size: 16px; }\n\t\th3 { margin: 15px 0 0 0; font-size: 14px; }\n\t\tinput[type=\"text\"], input[type=\"password\"] { float: left; margin-right: 15px; }\n\t\tlabel { float: left; font-weight: bold; margin-right: 5px; display: block; width: 150px; }\n\t\tlabel span { font-weight: normal; color: #888; }\n\t\t.rounded_box {background: transparent; margin:0px;}\n\t\t.rounded_box h4 { margin-bottom: 0px; margin-top: 7px; font-size: 14px; }\n\t\t.xtop, .xbottom {display:block; background:transparent; font-size:1px;}\n\t\t.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;}\n\t\t.xb1, .xb2, .xb3 {height:1px;}\n\t\t.xb2, .xb3, .xb4 {background:#F9F9F9; border-left:1px solid #CCC; border-right:1px solid #CCC;}\n\t\t.xb1 {margin:0 5px; background:#CCC;}\n\t\t.xb2 {margin:0 3px; border-width:0 2px;}\n\t\t.xb3 {margin:0 2px;}\n\t\t.xb4 {height:2px; margin:0 1px;}\n\t\t.xboxcontent {display:block; background:#F9F9F9; border:0 solid #CCC; border-width:0 1px; padding: 0 5px 0 5px;}\n\t\t.xboxcontent table td.description { padding: 3px 3px 3px 0;}\n\t\t.white .xb2, .white .xb3, .white .xb4 { background: #FFF; border-color: #CCC; }\n\t\t.white .xb1 { background: #CCC; }\n\t\t.white .xboxcontent { background: #FFF; border-color: #CCC; }\n\t\tpre { overflow: scroll; padding: 5px; }\n\t\t</style>\n\t\t<!--[if IE]>\n\t\t<style>\n\t\tbody { background-color: #DFDFDF; font-family: sans-serif; font-size: 13px; }\n\t\t</style>\n\t\t<![endif]-->\n\t\t</head>\n\t\t<body>\n\t\t<div class=\"rounded_box white\" style=\"margin: 30px auto 0 auto; width: 700px;\">\n\t\t\t<b class=\"xtop\"><b class=\"xb1\"></b><b class=\"xb2\"></b><b class=\"xb3\"></b><b class=\"xb4\"></b></b>\n\t\t\t<div class=\"xboxcontent\" style=\"vertical-align: middle; padding: 10px 10px 10px 15px;\">\n\t\t\t<img style=\"float: left; margin-right: 10px;\" src=\"" . TBGContext::getTBGPath() . "header.png\"><h1>An error occured in The Bug Genie</h1>";
echo "<h2>{$title}</h2>";
$report_description = null;
if ($exception instanceof Exception) {
if ($exception instanceof TBGActionNotFoundException) {
echo "<h3>Could not find the specified action</h3>";
$report_description = "Could not find the specified action";
} elseif ($exception instanceof TBGTemplateNotFoundException) {
echo "<h3>Could not find the template file for the specified action</h3>";
//.........这里部分代码省略.........
示例10: loginCheck
/**
* Returns the logged in user, or default user if not logged in
*
* @param string $uname
* @param string $upwd
*
* @return TBGUser
*/
public static function loginCheck($username = null, $password = null)
{
try {
$row = null;
// If no username and password specified, check if we have a session that exists already
if ($username === null && $password === null) {
if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
$username = TBGContext::getRequest()->getCookie('tbg3_username');
$password = TBGContext::getRequest()->getCookie('tbg3_password');
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
if (!$row) {
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
}
}
}
// If we have authentication details, validate them
if (TBGSettings::getAuthenticationBackend() !== null && TBGSettings::getAuthenticationBackend() !== 'tbg' && $username !== null && $password !== null) {
TBGLogging::log('Authenticating with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO);
try {
$mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend());
if ($mod->getType() !== TBGModule::MODULE_AUTH) {
TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL);
throw new Exception('Invalid module type');
}
if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
$row = $mod->verifyLogin($username, $password);
} else {
$row = $mod->doLogin($username, $password);
}
if (!$row) {
// Invalid
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
}
} catch (Exception $e) {
throw $e;
}
} elseif ($username !== null && $password !== null) {
TBGLogging::log('Using internal authentication', 'auth', TBGLogging::LEVEL_INFO);
// First test a pre-encrypted password
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
if (!$row) {
// Then test an unencrypted password
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, self::hashPassword($password));
if (!$row) {
// This is a legacy account from a 2.1 upgrade - try md5
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, md5($password));
if (!$row) {
// Invalid
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
} else {
// convert md5 to new password type
$user = new TBGUser($row->get(TBGUsersTable::ID), $row);
$user->changePassword($password);
$user->save();
unset($user);
}
}
}
} elseif (TBGContext::isCLI()) {
$row = TBGUsersTable::getTable()->getByUsername(TBGContext::getCurrentCLIusername());
} elseif (!TBGSettings::isLoginRequired()) {
$row = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID());
}
if ($row) {
if (!$row->get(TBGScopesTable::ENABLED)) {
throw new Exception('This account belongs to a scope that is not active');
} elseif (!$row->get(TBGUsersTable::ACTIVATED)) {
throw new Exception('This account has not been activated yet');
} elseif (!$row->get(TBGUsersTable::ENABLED)) {
throw new Exception('This account has been suspended');
}
$user = TBGContext::factory()->TBGUser($row->get(TBGUsersTable::ID), $row);
} elseif (TBGSettings::isLoginRequired()) {
throw new Exception('Login required');
} else {
throw new Exception('No such login');
}
} catch (Exception $e) {
throw $e;
}
return $user;
}
示例11: setupI18n
protected static function setupI18n()
{
TBGLogging::log('Initializing i18n');
if (!TBGContext::isCLI()) {
$language = self::$_user instanceof TBGUser ? self::$_user->getLanguage() : TBGSettings::getLanguage();
if (self::$_user instanceof TBGUser && self::$_user->getLanguage() == 'sys') {
$language = TBGSettings::getLanguage();
}
TBGLogging::log('Loading i18n strings');
if (!(self::$_i18n = TBGCache::get(TBGCache::KEY_I18N . $language, false))) {
TBGLogging::log("Loading strings from file ({$language})");
self::$_i18n = new TBGI18n($language);
if (!self::isInstallmode()) {
TBGCache::add(TBGCache::KEY_I18N . $language, self::$_i18n, false);
}
} else {
TBGLogging::log('Using cached i18n strings');
}
self::$_i18n->initialize();
}
TBGLogging::log('done (initializing i18n)');
}
示例12: _construct
public function _construct(\b2db\Row $row, $foreign_key = null)
{
if (TBGContext::isCLI()) {
$this->_hostname = php_uname('n');
} else {
$hostprefix = !array_key_exists('HTTPS', $_SERVER) || $_SERVER['HTTPS'] == '' || $_SERVER['HTTPS'] == 'off' ? 'http' : 'https';
$this->_is_secure = (bool) ($hostprefix == 'https');
if (isset($_SERVER["HTTP_X_FORWARDED_HOST"]) && $_SERVER["HTTP_X_FORWARDED_HOST"] != "") {
$this->_hostname = "{$hostprefix}://{$_SERVER["HTTP_X_FORWARDED_HOST"]}";
} else {
$this->_hostname = "{$hostprefix}://{$_SERVER['SERVER_NAME']}";
}
$port = $_SERVER['SERVER_PORT'];
if ($port != 80) {
$this->_hostname .= ":{$port}";
}
}
}
示例13: getArticleLinkTag
public function getArticleLinkTag($matches, $parser)
{
$article_link = $matches[0];
$parser->addInternalLinkOccurrence($article_link);
$article_name = $this->getSpacedName($matches[0]);
if (!TBGContext::isCLI()) {
TBGContext::loadLibrary('ui');
return link_tag(make_url('publish_article', array('article_name' => $matches[0])), $article_name);
} else {
return $matches[0];
}
}
示例14: returnTemplateHTML
/**
* Returns the HTML output from a template, but doesn't render it
*
* @param string $template the template name
* @param array $params template parameters
*
* @return boolean
*/
public static function returnTemplateHTML($template, $params = array())
{
$current_content = ob_get_clean();
TBGContext::isCLI() ? ob_start() : ob_start('mb_output_handler');
echo TBGActionComponent::includeTemplate($template, $params);
$template_content = ob_get_clean();
TBGContext::isCLI() ? ob_start() : ob_start('mb_output_handler');
echo $current_content;
return $template_content;
}