PageRenderTime 69ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/msg.php

https://github.com/minea94/DboorZ
PHP | 357 lines | 338 code | 12 blank | 7 comment | 92 complexity | c54779b610ace497bda3af7d9c4f6600 MD5 | raw file
  1. <?php
  2. /*********************/
  3. /* */
  4. /* Version : 5.1.0 */
  5. /* Author : RM */
  6. /* Comment : 071223 */
  7. /* */
  8. /*********************/
  9. require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
  10. require_once( MODEL_PATH."msg.php" );
  11. class GPage extends securegamepage
  12. {
  13. public $showList = NULL;
  14. public $selectedTabIndex = NULL;
  15. public $errorText = NULL;
  16. public $receiver = NULL;
  17. public $subject = NULL;
  18. public $body = NULL;
  19. public $messageDate = NULL;
  20. public $messageTime = NULL;
  21. public $showFriendPane = NULL;
  22. public $friendsList = NULL;
  23. public $viewOnly = NULL;
  24. public $isInbox = NULL;
  25. public $sendMail = NULL;
  26. public $dataList = NULL;
  27. public $pageSize = 10;
  28. public $pageCount = NULL;
  29. public $pageIndex = NULL;
  30. public function GPage( )
  31. {
  32. parent::securegamepage( );
  33. $this->viewFile = "msg.phtml";
  34. $this->contentCssClass = "messages";
  35. }
  36. public function load( )
  37. {
  38. parent::load( );
  39. $this->sendMail = TRUE;
  40. $this->isInbox = TRUE;
  41. $this->viewOnly = FALSE;
  42. $this->showFriendPane = FALSE;
  43. $this->errorText = "";
  44. $this->showList = !( isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && intval( $_GET['t'] ) == 1 );
  45. $this->selectedTabIndex = isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && 1 <= intval( $_GET['t'] ) && intval( $_GET['t'] ) <= 2 ? intval( $_GET['t'] ) : 0;
  46. $this->friendList = array( );
  47. $friends_player_ids = trim( $this->data['friend_players'] );
  48. if ( $friends_player_ids != "" )
  49. {
  50. $friends_player_ids = explode( "\n", $friends_player_ids );
  51. foreach ( $friends_player_ids as $friend )
  52. {
  53. list( $playerId, $playerName ) = explode( " ", $friend );
  54. $this->friendList[$playerId] = $playerName;
  55. }
  56. }
  57. $m = new MessageModel( );
  58. if ( !$this->isPost( ) )
  59. {
  60. if ( isset( $_GET['uid'] ) && is_numeric( $_GET['uid'] ) && 0 < intval( $_GET['uid'] ) )
  61. {
  62. $this->receiver = $m->getPlayerNameById( intval( $_GET['uid'] ) );
  63. $this->showList = FALSE;
  64. $this->selectedTabIndex = 1;
  65. }
  66. else if ( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) && 0 < intval( $_GET['id'] ) )
  67. {
  68. $result = $m->getMessage( $this->player->playerId, intval( $_GET['id'] ) );
  69. if ( $result->next( ) )
  70. {
  71. $this->viewOnly = TRUE;
  72. $this->showList = FALSE;
  73. $this->isInbox = $result->row['to_player_id'] == $this->player->playerId;
  74. $this->sendMail = !$this->isInbox;
  75. $this->receiver = $this->isInbox ? $result->row['from_player_name'] : $result->row['to_player_name'];
  76. $this->subject = $result->row['msg_title'];
  77. $this->body = $this->getFilteredText( $result->row['msg_body'] );
  78. $this->messageDate = $result->row['mdate'];
  79. $this->messageTime = $result->row['mtime'];
  80. $this->selectedTabIndex = $this->isInbox ? 0 : 2;
  81. if ( $this->isInbox && !$result->row['is_readed'] && !$this->player->isSpy )
  82. {
  83. $m->markMessageAsReaded( $this->player->playerId, intval( $_GET['id'] ) );
  84. --$this->data['new_mail_count'];
  85. }
  86. }
  87. else
  88. {
  89. $this->showList = TRUE;
  90. $this->selectedTabIndex = 0;
  91. }
  92. $result->free( );
  93. }
  94. }
  95. else if ( isset( $_POST['sm'] ) )
  96. {
  97. $this->receiver = trim( $_POST['an'] );
  98. $this->subject = trim( $_POST['be'] );
  99. $this->body = $_POST['message'];
  100. if ( trim( $this->receiver ) == "" )
  101. {
  102. $this->showList = FALSE;
  103. $this->selectedTabIndex = 1;
  104. $this->errorText = messages_p_noreceiver."<p></p>";
  105. $m->dispose( );
  106. }
  107. else
  108. {
  109. if ( trim( $this->body ) == "" )
  110. {
  111. $this->showList = FALSE;
  112. $this->selectedTabIndex = 1;
  113. $this->errorText = messages_p_nobody."<p></p>";
  114. $m->dispose( );
  115. }
  116. else
  117. {
  118. if ( strtolower( trim( $this->receiver ) ) == "[ally]" && 0 < intval( $this->data['alliance_id'] ) && $this->hasAllianceSendMessageRole( ) )
  119. {
  120. $pids = trim( $m->getAlliancePlayersId( intval( $this->data['alliance_id'] ) ) );
  121. if ( $pids != "" )
  122. {
  123. if ( $this->subject == "" )
  124. {
  125. $this->subject = messages_p_emptysub;
  126. }
  127. $arr = explode( ",", $pids );
  128. foreach ( $arr as $apid )
  129. {
  130. if ( $apid == $this->player->playerId )
  131. {
  132. continue;
  133. }
  134. $m->sendMessage( $this->player->playerId, $this->data['name'], $apid, $m->getPlayerNameById( $apid ), $this->subject, $this->body );
  135. }
  136. $this->showList = TRUE;
  137. $this->selectedTabIndex = 2;
  138. }
  139. }
  140. else
  141. {
  142. $receiverPlayerId = $m->getPlayerIdByName( $this->receiver );
  143. if ( 0 < intval( $receiverPlayerId ) )
  144. {
  145. if ( $receiverPlayerId == $this->player->playerId )
  146. {
  147. $this->showList = FALSE;
  148. $this->selectedTabIndex = 1;
  149. $this->errorText = "<b>".messages_p_noloopback."</b><p></p>";
  150. }
  151. else
  152. {
  153. if ( $this->subject == "" )
  154. {
  155. $this->subject = messages_p_emptysub;
  156. }
  157. $m->sendMessage( $this->player->playerId, $this->data['name'], $receiverPlayerId, $this->receiver, $this->subject, $this->body );
  158. $this->showList = TRUE;
  159. $this->selectedTabIndex = 2;
  160. }
  161. }
  162. else
  163. {
  164. $this->showList = FALSE;
  165. $this->selectedTabIndex = 1;
  166. $this->errorText = messages_p_notexists." <b>".$this->receiver."</b><p></p>";
  167. }
  168. }
  169. }
  170. }
  171. }
  172. else if ( isset( $_POST['fm'] ) )
  173. {
  174. $this->receiver = trim( $_POST['an'] );
  175. $this->subject = trim( $_POST['be'] );
  176. $this->body = $_POST['message'];
  177. $this->showList = FALSE;
  178. $this->selectedTabIndex = 1;
  179. $this->showFriendPane = TRUE;
  180. if ( $_POST['fm'] != "" && is_numeric( $_POST['fm'] ) )
  181. {
  182. $playerId = intval( $_POST['fm'] );
  183. if ( 0 < $playerId && isset( $this->friendList[$playerId] ) )
  184. {
  185. unset( $this->friendList[$playerId] );
  186. }
  187. }
  188. else if ( isset( $_POST['mfriends'] ) )
  189. {
  190. foreach ( $_POST['mfriends'] as $friendName )
  191. {
  192. $friendName = trim( $friendName );
  193. if ( $friendName == "" )
  194. {
  195. continue;
  196. }
  197. $playerId = intval( $m->getPlayerIdByName( $friendName ) );
  198. if ( 0 < $playerId && !isset( $this->friendList[$playerId] ) && $playerId != $this->player->playerId )
  199. {
  200. $this->friendList[$playerId] = $friendName;
  201. }
  202. }
  203. }
  204. $friends = "";
  205. foreach ( $this->friendList as $k => $v )
  206. {
  207. if ( $friends != "" )
  208. {
  209. $friends .= "\n";
  210. }
  211. $friends .= $k." ".$v;
  212. }
  213. $m->saveFriendList( $this->player->playerId, $friends );
  214. }
  215. else if ( isset( $_POST['rm'] ) )
  216. {
  217. $this->receiver = trim( $_POST['an'] );
  218. $this->subject = trim( $_POST['be'] );
  219. $this->body = PHP_EOL.PHP_EOL."_________________________________".PHP_EOL.text_from_lang." ".$this->receiver.":".PHP_EOL.PHP_EOL.$_POST['message'];
  220. preg_match( "/^(RE)\\^?([0-9]*):([\\w\\W]*)\$/", $this->subject, $matches );
  221. if ( sizeof( $matches ) == 4 )
  222. {
  223. $this->subject = ( "RE^".( $matches[2] + 1 ) ).":".$matches[3];
  224. }
  225. else
  226. {
  227. $this->subject = "RE: ".$this->subject;
  228. }
  229. $this->showList = FALSE;
  230. $this->selectedTabIndex = 1;
  231. }
  232. else if ( isset( $_POST['dm'] ) && isset( $_POST['dm'] ) )
  233. {
  234. foreach ( $_POST['dm'] as $messageId )
  235. {
  236. if ( $m->deleteMessage( $this->player->playerId, $messageId ) )
  237. {
  238. --$this->data['new_mail_count'];
  239. }
  240. }
  241. }
  242. if ( $this->showList )
  243. {
  244. $rowsCount = $m->getMessageListCount( $this->player->playerId, $this->selectedTabIndex == 0 );
  245. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  246. $this->pageIndex = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) && intval( $_GET['p'] ) < $this->pageCount ? intval( $_GET['p'] ) : 0;
  247. $this->dataList = $m->getMessageList( $this->player->playerId, $this->selectedTabIndex == 0, $this->pageIndex, $this->pageSize );
  248. if ( 0 < $this->data['new_mail_count'] )
  249. {
  250. $this->data['new_mail_count'] = $m->syncMessages( $this->player->playerId );
  251. }
  252. }
  253. $m->dispose( );
  254. }
  255. public function getFilteredText( $text )
  256. {
  257. require_once( MODEL_PATH."wordsfilter.php" );
  258. $filter = new FilterWordsModel( );
  259. return $filter->FilterWords( $text );
  260. }
  261. public function _hasAllianceRole( $role )
  262. {
  263. $alliance_roles = trim( $this->data['alliance_roles'] );
  264. if ( $alliance_roles == "" )
  265. {
  266. return FALSE;
  267. }
  268. list( $roleNumber, $roleName ) = $alliance_roles;
  269. return $roleNumber & $role;
  270. }
  271. public function hasAllianceSendMessageRole( )
  272. {
  273. return $this->_hasAllianceRole( ALLIANCE_ROLE_SENDMESSAGE );
  274. }
  275. public function preRender( )
  276. {
  277. parent::prerender( );
  278. if ( isset( $_GET['uid'] ) )
  279. {
  280. $this->villagesLinkPostfix .= "&uid=".intval( $_GET['uid'] );
  281. }
  282. if ( isset( $_GET['id'] ) )
  283. {
  284. $this->villagesLinkPostfix .= "&id=".intval( $_GET['id'] );
  285. }
  286. if ( isset( $_GET['p'] ) )
  287. {
  288. $this->villagesLinkPostfix .= "&p=".intval( $_GET['p'] );
  289. }
  290. if ( 0 < $this->selectedTabIndex )
  291. {
  292. $this->villagesLinkPostfix .= "&t=".$this->selectedTabIndex;
  293. }
  294. }
  295. public function getNextLink( )
  296. {
  297. $text = "»";
  298. if ( $this->pageIndex + 1 == $this->pageCount )
  299. {
  300. return $text;
  301. }
  302. $link = "";
  303. if ( 0 < $this->selectedTabIndex )
  304. {
  305. $link .= "t=".$this->selectedTabIndex;
  306. }
  307. if ( $link != "" )
  308. {
  309. $link .= "&";
  310. }
  311. $link .= "p=".( $this->pageIndex + 1 );
  312. $link = "msg.php?".$link;
  313. return "<a href=\"".$link."\">".$text."</a>";
  314. }
  315. public function getPreviousLink( )
  316. {
  317. $text = "«";
  318. if ( $this->pageIndex == 0 )
  319. {
  320. return $text;
  321. }
  322. $link = "";
  323. if ( 0 < $this->selectedTabIndex )
  324. {
  325. $link .= "t=".$this->selectedTabIndex;
  326. }
  327. if ( 1 < $this->pageIndex )
  328. {
  329. if ( $link != "" )
  330. {
  331. $link .= "&";
  332. }
  333. $link .= "p=".( $this->pageIndex - 1 );
  334. }
  335. if ( $link != "" )
  336. {
  337. $link = "?".$link;
  338. }
  339. $link = "msg.php".$link;
  340. return "<a href=\"".$link."\">".$text."</a>";
  341. }
  342. }
  343. $p = new GPage( );
  344. $p->run( );
  345. ?>