Beispiel #1
0
 /**
  * 获得模板渲染后的内容
  * @return string
  * @throws TXException
  */
 public function getContent()
 {
     //防XSS注入
     foreach ($this->objects as &$object) {
         if (is_string($object)) {
             $object = $this->encode($object);
         } elseif (is_array($object)) {
             $object = new TXArray($object);
         }
     }
     unset($object);
     $this->objects['PRM'] = new TXArray($this->params);
     extract($this->objects);
     ob_start();
     //include template
     $lang = TXLanguage::getLanguage();
     $file = sprintf('%s/template/%s%s.tpl.php', TXApp::$app_root, $this->view, $lang ? '.' . $lang : "");
     if (!is_readable($file)) {
         $file = sprintf('%s/template/%s.tpl.php', TXApp::$app_root, $this->view);
     }
     if (!is_readable($file)) {
         throw new TXException(2005, $this->view);
     }
     include $file;
     TXLogger::showLogs();
     $content = ob_get_clean();
     return $content;
 }
Beispiel #2
0
 /**
  * 构造函数
  * @param $data
  * @param bool $encode
  */
 public function __construct($data, $encode = true)
 {
     $data = TXString::recursionEncode($data, $encode);
     if (SYS_CONSOLE && TXLogger::$ConsoleOut) {
         TXLogger::format();
         $data['__logs'] = TXLogger::$ConsoleOut;
         TXLogger::$ConsoleOut = array();
     }
     $this->data = $data;
 }
Beispiel #3
0
 /**
  * 返回所有日志
  */
 public static function showLogs()
 {
     if (self::$ConsoleOut) {
         self::format();
         if (RUN_SHELL) {
             foreach (self::$ConsoleOut as $Out) {
                 $value = $Out['value'];
                 $key = $Out['key'];
                 $type = $Out['type'];
                 if (is_array($value)) {
                     $value = var_export($value, true);
                 }
                 echo "[{$type}] {$key} => {$value}\n";
             }
         } elseif (SYS_CONSOLE) {
             echo "\n<script type=\"text/javascript\">\n";
             foreach (self::$ConsoleOut as $Out) {
                 $value = $Out['value'];
                 $key = $Out['key'];
                 $type = $Out['type'];
                 if (is_array($value)) {
                     $value = json_encode($value);
                     $message = sprintf('console.%s("%s => ", %s);', $type, $key, $value ?: "false");
                 } else {
                     $message = sprintf('console.%s("%s => ", "%s");', $type, $key, addslashes(str_replace(array("\r\n", "\r", "\n"), "", $value)));
                 }
                 echo $message . "\n";
             }
             echo "</script>";
         }
         self::$ConsoleOut = array();
     }
 }
Beispiel #4
0
 public function action_view($id)
 {
     TXLogger::display($id);
     exit;
 }
Beispiel #5
0
 /**
  * 拼装orderby
  * @param $orderBy
  * @return string
  */
 protected function buildOrderBy($orderBy)
 {
     $orders = array();
     foreach ($orderBy as $key => $val) {
         $key = $this->real_escape_string($key);
         if (is_array($val)) {
             $asc = isset($val[0]) ? $val[0] : 'ASC';
             $code = isset($val[1]) ? $val[1] : 'gbk';
             if (!in_array(strtoupper($asc), array('ASC', 'DESC'))) {
                 TXLogger::error("order must be ASC/DESC, {$asc} given", 'sql Error');
                 continue;
             }
             $orders[] = "CONVERT(`{$key}` USING {$code}) {$asc}";
         } else {
             if (!in_array(strtoupper($val), array('ASC', 'DESC'))) {
                 TXLogger::error("order must be ASC/DESC, {$val} given", 'sql Error');
                 continue;
             }
             $orders[] = '`' . $key . "` " . $val;
         }
     }
     if ($orders) {
         return ' ORDER BY ' . join(',', $orders);
     } else {
         return '';
     }
 }
Beispiel #6
0
 /**
  * sql execute
  * @param $sql
  * @param bool $id
  * @return bool|int|mysqli_result|string
  */
 public function execute($sql, $id = false)
 {
     if (mysqli_query($this->handler, $sql)) {
         if ($id) {
             return mysqli_insert_id($this->handler);
             //            return mysql_insert_id();
         }
         return true;
     } else {
         TXLogger::addError(sprintf("sql Error: %s [%s]", mysqli_error($this->handler), $sql));
         TXLogger::error($sql, 'sql Error:');
         return false;
     }
 }
Beispiel #7
0
 /**
  * 拼装Doubleorderby
  * @param $orderBys
  * @return string
  */
 protected function buildOrderBy($orderBys)
 {
     $orders = array();
     foreach ($orderBys as $k => $orderBy) {
         if (is_string($k) && in_array($k, $this->doubles)) {
             $table = $k;
         } else {
             if (isset($this->doubles[$k])) {
                 $table = $this->doubles[$k];
             } else {
                 if (is_string($k)) {
                     $k = $this->real_escape_string($k);
                     //外层循环
                     if (is_array($orderBy)) {
                         $asc = isset($orderBy[0]) ? $orderBy[0] : 'ASC';
                         $code = isset($orderBy[1]) ? $orderBy[1] : 'gbk';
                         if (!in_array(strtoupper($asc), array('ASC', 'DESC'))) {
                             TXLogger::error("order must be ASC/DESC, {$asc} given", 'sql Error');
                             continue;
                         }
                         $orders[] = "CONVERT(`{$k}` USING {$code}) {$asc}";
                     } else {
                         if (!in_array(strtoupper($orderBy), array('ASC', 'DESC'))) {
                             TXLogger::error("order must be ASC/DESC, {$orderBy} given", 'sql Error');
                             continue;
                         }
                         $orders[] = '`' . $k . "` " . $orderBy;
                     }
                     continue;
                 } else {
                     continue;
                 }
             }
         }
         foreach ($orderBy as $key => $val) {
             $key = $this->real_escape_string($key);
             if (is_array($val)) {
                 $field = $table . ".`" . $key . '`';
                 $asc = isset($val[0]) ? $val[0] : 'ASC';
                 $code = isset($val[1]) ? $val[1] : 'gbk';
                 if (!in_array(strtoupper($asc), array('ASC', 'DESC'))) {
                     TXLogger::error("order must be ASC/DESC, {$asc} given", 'sql Error');
                     continue;
                 }
                 $orders[] = "CONVERT({$field} USING {$code}) {$asc}";
             } else {
                 if (!in_array(strtoupper($val), array('ASC', 'DESC'))) {
                     TXLogger::error("order must be ASC/DESC, {$val} given", 'sql Error');
                     continue;
                 }
                 $orders[] = $table . ".`" . $key . "` " . $val;
             }
         }
     }
     if ($orders) {
         return ' ORDER BY ' . join(',', $orders);
     } else {
         return '';
     }
 }
Beispiel #8
0
 /**
  * @param $event
  * @param array $param
  */
 public function testEvent2($event, $param = array())
 {
     TXLogger::info("tigger in afterAction" . $event);
 }
Beispiel #9
0
 /**
  * 异常捕获类
  * @param $code
  * @param $message
  * @param $file
  * @param $line
  * @throws TXException
  */
 public static function handleError($code, $message, $file, $line)
 {
     if ($code === E_WARNING || $code === E_NOTICE) {
         $message = sprintf("%s\n#1 %s(%s)", $message, $file, $line);
         TXLogger::addError($message, $code);
     } elseif (error_reporting() & $code) {
         throw new TXException(1000, $message);
     }
     return;
 }
Beispiel #10
0
 public function another($event, $params = array())
 {
     TXLogger::info("tigger in anther" . $event);
     TXLogger::info($params);
 }
Beispiel #11
0
 /**
  * 请求入口
  * @param $event
  * @param $request TXRequest
  */
 public static function onRequest($event, $request)
 {
     TXLogger::addLog('request: ' . $request->getHostInfo() . $request->getUrl());
 }
Beispiel #12
0
 public function init()
 {
     TXLogger::addLog('init');
     return 0;
 }