Ejemplo n.º 1
0
 /**
  * 获得默认的Debuger
  *
  * @return Watt_Debug
  */
 public static function getDefaultDebug()
 {
     if (!self::$_defaultDebug) {
         self::$_defaultDebug = new Watt_Debug();
         if (defined('APP_START_TIME')) {
             self::$_defaultDebug->setStartTime((int) (APP_START_TIME * 1000));
         }
     }
     return self::$_defaultDebug;
 }
Ejemplo n.º 2
0
 public function connect()
 {
     if (false === socket_connect($this->sock, $this->host, $this->port)) {
         throw new Exception("socket_connect(" . $this->host . ":" . $this->port . ") failed: " . socket_strerror(socket_last_error($this->sock)));
     }
     //stream_set_timeout ($this->sock,10);
     Watt_Debug::getDefaultDebug()->addInfo("socket_connect(" . $this->host . ":" . $this->port . ") success");
     $this->isConnected = true;
     return $this->isConnected;
 }
Ejemplo n.º 3
0
 /**
  * 以XML的方式渲染数据并输出
  *
  * @param boolean $show
  * @return string
  */
 public function render($show = true)
 {
     ob_start();
     echo json_encode($this->_data);
     $out = ob_get_clean();
     if ($show) {
         echo $out;
     }
     //如果输出debug信息, XML会报错
     Watt_Debug::getDefaultDebug()->clearDebugInfo();
     return $out;
 }
Ejemplo n.º 4
0
 /**
  * 以XML的方式渲染数据并输出
  *
  * @param boolean $show
  * @return string
  */
 public function render($show = true)
 {
     ob_start();
     //这里显示菜单
     //这里显示主体部分
     //parent::render( true );
     reset($this->_data);
     echo '<?xml version="1.0" encoding="' . $this->_charSet . '"?>' . "\n";
     echo Watt_Util_Array::varToXml($this->_data);
     //这里显示底部
     $out = ob_get_clean();
     if ($show) {
         header("Content-type: text/xml; charset=" . $this->_charSet);
         echo $out;
     }
     //如果输出debug信息, XML会报错
     Watt_Debug::getDefaultDebug()->clearDebugInfo();
     return $out;
 }
Ejemplo n.º 5
0
 /**
  * @todo 解决和dialog重复的问题
  *
  * @param boolean $show
  * @return string
  */
 public function render($show = true)
 {
     ob_start();
     /**
      * ajax 也要显示显示 Tq消息
      * Tq消息要在 tip 之前
      * ajax不显示消息, 此时消息存在 session 里,下次统一发送
      */
     //echo Tpm_Message_Sender_Tq::getMsgHtml();
     /**
      * 这里显示主体部分
      */
     parent::render(true);
     $out = ob_get_clean();
     if ($show) {
         echo $out;
     }
     //如果输出debug信息, Ajax会不爽
     Watt_Debug::getDefaultDebug()->clearDebugInfo();
     return $out;
 }
Ejemplo n.º 6
0
 /**
  * 记录:
  * 使用默认的 loger 记录日志
  * 
  * 时间 - 服务器自动记录时间
  *
  * 起因 - msg
  * 经过
  * 结果
  * 
  * 地点 - sourceName
  * 人物 - userId
  *      - actorName (userName)
  *
  * @param string $msg 记录的信息
  * @param int $level
  * @param string $sourceName
  * @param string $actorName
  * @param string $actorId
  * @param mix $exts
  * @return boolean
  */
 public static final function addLog($msg, $level = 0, $sourceName = "", $actorName = "", $actorId = "", $exts = null, $extsInt = null)
 {
     //如果禁用日志则不记录 by terry at Wed Aug 18 10:02:05 CST 2010
     if (self::$_disabledAddLog) {
         return true;
     }
     if (is_array($msg)) {
         $msg = var_export($msg, true);
     }
     //默认所有日志就记录入 debuger 日志
     self::getDefaultLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts, $extsInt);
     if ($level > self::LEVEL_DEBUG) {
         //self::getDefaultLogger()->log( 'Before DB Log' );
         self::getSystemLogger()->log($msg, $level, $sourceName, $actorName, $actorId, $exts, $extsInt);
         //self::getDefaultLogger()->log( 'After DB Log' );
     }
     /**
      * 如果是Debug模式,同时输出到屏幕 / 判断debug模式在 addInfoToDefault 中实现
      * @author terry
      * @version 0.1.0
      * Mon Sep 24 21:06:25 CST 2007
      */
     Watt_Debug::addInfoToDefault('Watt_Log::addLog', $msg);
     return true;
 }
Ejemplo n.º 7
0
 public static function test()
 {
     set_time_limit(10);
     $url = Watt_Util_Net::isLANIp($_SERVER['SERVER_ADDR']);
     $epollServer = Watt_Config::getEpollServer();
     /*
     		$epoll_url = Watt_Config::getEpollServer();
     		
     		if($url)//判断是否内网IP
     		{
     			if(preg_match("/\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/",$epoll_url))//判断是否IP
     			{
     				$epollUpdateUrl = $epoll_url;
     			}
     			else //是否域名
     			{
     				$epollUpdateUrl = "in".$epoll_url;
     			}
     		}
     		else 
     		{
     			$epollUpdateUrl = $epoll_url;
     		}
     		$epollServer = $epollUpdateUrl;
     */
     $port = Watt_Config::getEpollServerPort();
     $epollClient = new Watt_Net_EpollClient($epollServer, $port);
     $fromId = 4040;
     $epollClient->login($fromId);
     $epollClient->sendTpmMsg($fromId, 151017933, 1, 'Title', 'Link', 'test消息', 'msn', 'qq18076495', 'extmsg', 1);
     //		$list = $epollClient->getOnlineList( $fromId );
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 19:46:17 CST 2008] :\n ";
     //		var_dump( $list );
     //		echo "</pre>";
     //exit();
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Thu Jun 26 20:28:09 CST 2008] :\n ";
     //		var_dump( strToHex( iconv('ISO-8859-1','UTF-8','消息' ) ) );
     //		var_dump( ( urlencode('消息') ) );
     //		var_dump( pack( "H*","886D6F60" ) );
     //		echo "</pre>";
     //exit();
     Watt_Debug::getDefaultDebug()->addInfo('After login');
     //		$docHeader = pack( 'H*', 'D0CF11E0A1B11AE1' );
     //		$docHeader = pack( 'H*', 'FFFE' );
     //		$total = pack('H*','00910001000003EA');
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 17:13:46 CST 2008] :\n ";
     //		var_dump( strToHex($total) );
     //		echo "</pre>";
     //
     //		$total = pack('nnN',0x0091,0x0001,0x000003EA);
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 17:13:46 CST 2008] :\n ";
     //		var_dump( strToHex($total) );
     //		echo "</pre>";
     //
     //		$rev = unpack('nlen/ncmd/Nepollid/', $total);
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 14:24:03 CST 2008] :\n ";
     //		var_dump( $rev );
     //		echo "</pre>";
     //		//exit();
     //
     //		$total = pack( 'H*', '00910001000003EA50F1120058DBEEBFAAC1040880DBEEBF50DBEEBF68DBEEBFD8C1040884DBEEBFC8DCEE00000012F12800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' );
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 17:13:46 CST 2008] :\n ";
     //		var_dump( strToHex($total) );
     //		echo "</pre>";
     //
     //		$rev = unpack( "nlen/ncmd/Nepollid/a".self::MAX_USER_NAME_EX."user/a".self::MAX_PASSWD_LEN_EX."pwd/Nip/Naction/a*memo/",$total );
     //		echo "<pre>Terry at [".__FILE__."(line:".__LINE__.")]\nWhen [Fri Jun 13 14:24:03 CST 2008] :\n ";
     //		var_dump( $rev );
     //		echo "</pre>";
     //		exit();
     /*
     0091
     0001
     000003EA
     50F1120058DBEEBFAAC1040880DBEEBF50DBEEBF68DBEEBFD8C1040884DBEEBF
     C8DCEE00000012F1280000000000000000000000000000000000000000000000
     00000000
     00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
     */
 }
Ejemplo n.º 8
0
 /**
  * 功能://添加新功能,用第二个参数来传所有的值
  * Tony---Fri Mar 16 20:34:11 CST 2007----20:34:11
  */
 public function NewDb($sql, $he, $page = false, $type = '', $format1 = false)
 {
     Watt_Debug::addInfoToDefault('', 'startUseReadonlyDb');
     Watt_Db::startUseReadonlyDb();
     try {
         if ($format1) {
             $this->format = $format1;
         } else {
             $this->format = false;
         }
         $error_self = error_reporting(E_ALL ^ E_NOTICE);
         foreach ($he as $key => $v) {
             $title[$key] = $v[0];
             if ($v[1]) {
                 $field[$key] = $v[1];
             }
             if ($v[2]) {
                 $data[$key] = $v[2];
             }
             if ($v[3]) {
                 $field_t[$key] = $v[3];
             }
             if ($v[4]) {
                 $ti[$key] = $v[4];
             }
         }
         if ($ti) {
             $this->addTot($ti, $this->heji_type);
         }
         $result = $this->simple($sql, $page, $title, $field, $data, $field_t, $type, "#*#", '', $format1);
         Watt_Debug::addInfoToDefault('', 'endUseReadonlyDb');
         Watt_Db::endUseReadonlyDb();
         return $result;
     } catch (Exception $e) {
         Watt_Db::endUseReadonlyDb();
         throw $e;
     }
 }
Ejemplo n.º 9
0
 /**
  * 渲染一个指定的 view 文件
  * view文件是相对于 view Path 的相对路径+文件名,开始不带 / 或 \
  * 
  *
  * @param Watt_Data_Schema $data
  * @param String $viewFile 不带扩展名的viewFile
  * @param Boolean $show
  * @return String
  */
 public function renderView($data, $viewFile, $show = True)
 {
     //$this->_data = $data;
     $this->addData($data);
     $this->_viewFile = $this->_getAbsViewPathFilename($viewFile . $this->_viewExt);
     Watt_Debug::addInfoToDefault(__FILE__ . " " . __LINE__, "use view: " . $this->_viewFile);
     return $this->render($show);
 }
Ejemplo n.º 10
0
 private function _loadStrings()
 {
     $this->_connectMemcache();
     if ($this->_memcache) {
         if ($this->_memcache->get($this->_memcacheKeyPrefix . $this->_lang . '_LOADED')) {
             $this->isStringsLoaded = true;
             Watt_Debug::addInfoToDefault('After load language string from memcache.(cached)');
             return true;
         }
         Watt_Debug::addInfoToDefault('Before load language string from memcache.');
         $langPath = Watt_Config::getLangPath() . $this->_lang . DIRECTORY_SEPARATOR;
         if (!file_exists($langPath)) {
             $langPath = Watt_Config::getLangPath() . "default" . DIRECTORY_SEPARATOR;
         }
         $this->_loadLangFilesInDir($langPath);
         //载入备用目录的语言文件 //
         //$langPath = Watt_Config::getLangPath(1).$this->_lang.DIRECTORY_SEPARATOR;
         //$this->_loadLangFilesInDir( $langPath );
         $this->_memcache->set($this->_memcacheKeyPrefix . $this->_lang . '_LOADED', true);
         Watt_Debug::addInfoToDefault('After load language string from memcache.');
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 11
0
 /**
  * 结束使用只读数据库
  *
  * @author bobit
  * Mon Sep 24 16:37:49 CST 200716:37:49
  */
 public static function endUseReadonlyDb()
 {
     self::$_need_use_readonly_db = 0;
     Watt_Debug::addInfoToDefault('', 'Unset use READONLY DB server');
 }
Ejemplo n.º 12
0
 /**
  * 处理 do
  * 有可能会返回 goToDo
  * 
  * 只有一个单词的do,对应的action是 index
  * 
  *
  * @param string $do
  * @return string $goToDo
  */
 protected function processDo($do, $defaultView = "Html")
 {
     if ($do == "") {
         $e = new Watt_Exception(Watt_I18n::trans("ERR_DISPATCH_NODO"));
         throw $e;
     }
     $goToDo = "";
     $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do);
     $controller = $arrCtrlAndAction[0];
     $action = $arrCtrlAndAction[1];
     $doFile = $arrCtrlAndAction[2];
     $doAction = $arrCtrlAndAction[3];
     //exit( $doFile . "|" . $doAction );
     //使用 ob_start 是为了Controller里的 redirect 可以正常使用
     if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) {
         /**
          * 为了不让服务器过长等待时间,改为不启用Ctrl Buffer
          * @author terry
          * @version 0.1.0
          * Mon Jan 14 14:41:39 CST 2008
          */
         ob_start();
     }
     /**
      * 增加了对页面缓存的支持
      */
     $cache = null;
     Watt_Debug::addInfoToDefault('Begin create action [' . $controller . '] [' . $action . ']');
     $theCtrl = Watt_Controller_Action::factory($controller, $action);
     Watt_Debug::addInfoToDefault('After create action');
     $viewMenu = isset($_REQUEST["view_menu"]) ? trim($_REQUEST["view_menu"]) == '0' ? false : true : true;
     $theCtrl->setNeedMenu($viewMenu);
     $actionCacheTime = $theCtrl->getActionCacheTime($action);
     if ($actionCacheTime > 0) {
         $cache = new Watt_Cache($actionCacheTime);
         if ($cache->cacheCheck()) {
             //如果符合缓存条件,则会读取缓存文件,并 exit.
             /**
              * 改为退出处理,为了记录页面执行时间。
              * 这里一定不能 return true.
              * @author terry
              * @version 0.1.0
              * Mon Jan 14 14:30:43 CST 2008
              */
             return '';
         }
     }
     /**
      * 检查 会话的权限。 
      * 如果没有权限,抛出一个异常
      * 此处别扭
      */
     $rbac = new Watt_Rbac();
     //$rbac->checkSession(Watt_Session::getSession(), $do);
     $privilege = $rbac->checkActionPrivilege(Watt_Session::getSession(), $theCtrl, $action);
     if (is_object($privilege) && $privilege instanceof TpmYonghuzhaoquanxian) {
         if (!$theCtrl->getTitle()) {
             $theCtrl->setTitle(Watt_I18n::trans($privilege->getQxMingcheng()));
         }
     }
     Watt_Debug::addInfoToDefault('', 'Pre do action..');
     if (method_exists($theCtrl, $doAction)) {
         //执行controller中的action
         $theCtrl->{$doAction}();
     } else {
         throw new Exception(Watt_I18n::trans("ERR_APP_LOST_ACTION"));
     }
     Watt_Debug::addInfoToDefault('', 'After do action..');
     $goToDo = $theCtrl->getGoToDo();
     $data = $theCtrl->getData();
     /**
      * 改为对 Ctrl 不进行 Buffer 的处理
      * @author terry
      * @version 0.1.0
      * Mon Jan 14 15:05:28 CST 2008
      */
     if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) {
         if (defined("DEBUG") && DEBUG) {
             //调试阶段才显示Controller里输出的信息
             echo ob_get_clean();
         } else {
             //用户使用阶段不允许 action 里输出显示数据
             ob_clean();
         }
     }
     if ($theCtrl->isNeedView()) {
         Watt_Debug::addInfoToDefault('', 'Pre load view..');
         if ($theCtrl->getViewType()) {
             $defaultView = $theCtrl->getViewType();
         }
         /**
          * 创建一个View。将来可以用不同的View代替此View
          */
         //$view = Watt_View::factory( "Html", Watt_Config::getViewPath() );
         $view = Watt_View::factory($defaultView, Watt_Config::getViewPath());
         $view->setHeader($theCtrl->getHeader());
         Watt_Debug::addInfoToDefault('', 'After view factory..');
         /**
          * 读取菜单应该由View来判断
          * @author terry
          * Thu Jul 22 10:46:07 CST 2010
          */
         if ($theCtrl->isNeedMenu() && strtolower($defaultView) == 'html') {
             //$theCtrl->isNeedCaidan();
             /**
              * 如果用户已登录,读取菜单信息
              * @todo 未登录可能也可以有菜单
              */
             if ($user_id = Watt_Session::getSession()->getUserId()) {
                 $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Watt_Session::getSession()->getRoleId());
                 if (count($tpmCaidans)) {
                     $view->setHeader($tpmCaidans, "menu");
                 }
             }
             //读取菜单完
         }
         //$view->renderModel($theCtrl);
         $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true);
     }
     /**
      * 与开始的Cache对应
      */
     if ($actionCacheTime > 0 && $cache instanceof Watt_Cache) {
         $cache->caching();
     }
     return $goToDo;
 }