PageRenderTime 58ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/snprofile.php

https://github.com/minea94/DboorZ
PHP | 171 lines | 156 code | 8 blank | 7 comment | 57 complexity | 4b769f8e69b06b93a804d7e914dcf9be 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."snprofile.php" );
  11. class GPage extends securegamepage
  12. {
  13. public $topics = array( );
  14. public $pageSize = 20;
  15. public $pageIndex = NULL;
  16. public $pageCount = NULL;
  17. public $uid = 0;
  18. public $userData = array( );
  19. public $myData = array( );
  20. public $isFriend = FALSE;
  21. public $friendList = array( );
  22. public function GPage( )
  23. {
  24. parent::securegamepage( );
  25. $this->viewFile = "snprofile.phtml";
  26. $this->contentCssClass = "player";
  27. }
  28. public function load( )
  29. {
  30. parent::load( );
  31. $this->myData['name'] = $this->data['name'];
  32. $this->myData['avatar'] = $this->data['avatar'];
  33. $this->myData['id'] = $this->player->playerId;
  34. $this->pageIndex = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  35. $this->uid = isset( $_GET['uid'] ) && 0 < intval( $_GET['uid'] ) ? intval( $_GET['uid'] ) : $this->player->playerId;
  36. $m = new SNprofileModel( );
  37. $rowsCount = $m->getNewsCount( $this->uid );
  38. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  39. $this->userData = $m->getuserData( $this->uid );
  40. $friendId = array( );
  41. $listRows = $m->getFriendsList( $this->player->playerId );
  42. while ( $listRows->next( ) )
  43. {
  44. $id = $listRows->row['playerid1'] == $this->player->playerId ? $listRows->row['playerid2'] : $listRows->row['playerid1'];
  45. $name = $listRows->row['playerid1'] == $this->player->playerId ? $listRows->row['playername2'] : $listRows->row['playername1'];
  46. $frienddata = $m->getFriendData( $id );
  47. $this->friendList[] = array(
  48. $id,
  49. $name,
  50. $frienddata['avatar'],
  51. $frienddata['last_login_sec']
  52. );
  53. $friendId[] = $id;
  54. }
  55. $this->isFriend = in_array( $this->uid, $friendId ) || $this->uid == $this->player->playerId ? TRUE : FALSE;
  56. if ( isset( $_GET['DNid'] ) && !empty( $_GET['DNid'] ) )
  57. {
  58. $NewsID = mysql_real_escape_string( trim( $_GET['DNid'] ) );
  59. if ( $NewsID != "" )
  60. {
  61. if ( $this->myData['id'] == $this->uid )
  62. {
  63. $m->DeleteNews( $NewsID, $this->player->playerId );
  64. }
  65. $m->dispose( );
  66. $this->redirect( "snprofile.php?uid=".$this->uid );
  67. }
  68. }
  69. else if ( isset( $_GET['DCid'] ) && !empty( $_GET['DCid'] ) )
  70. {
  71. $CommentID = mysql_real_escape_string( trim( $_GET['DCid'] ) );
  72. if ( $CommentID != "" )
  73. {
  74. $m->DeleteComment( $CommentID, $this->player->playerId );
  75. $m->dispose( );
  76. $this->redirect( "snprofile.php?uid=".$this->uid );
  77. }
  78. }
  79. else if ( $this->isPost( ) )
  80. {
  81. $post = array( );
  82. if ( isset( $_GET['do'] ) && $_GET['do'] == "News" )
  83. {
  84. $post['userid'] = $this->uid;
  85. $post['message'] = isset( $_POST['news'] ) && $_POST['news'] != "" ? trim( $_POST['news'] ) : "";
  86. $post['image'] = isset( $_POST['image'] ) && $_POST['image'] != "" ? trim( $_POST['image'] ) : "";
  87. $post['url'] = isset( $_POST['url'] ) && $_POST['url'] != "" ? trim( $_POST['url'] ) : "";
  88. $post['youtube'] = isset( $_POST['youtube'] ) && $_POST['youtube'] != "" ? trim( $_POST['youtube'] ) : "";
  89. if ( $this->uid == $this->player->playerId && $post['message'] != "" )
  90. {
  91. $m->SendNews( $post );
  92. }
  93. }
  94. else
  95. {
  96. $post['to_userid'] = $this->uid;
  97. $post['userid'] = intval( $this->player->playerId );
  98. $post['username'] = $this->data['name'];
  99. $post['comment'] = isset( $_POST['comment'] ) && $_POST['comment'] != "" ? trim( $_POST['comment'] ) : "";
  100. $post['topicid'] = isset( $_POST['topicid'] ) && $_POST['topicid'] != "" ? trim( $_POST['topicid'] ) : "";
  101. if ( $post['to_userid'] != 0 && $post['comment'] != "" && $post['userid'] != 0 && $this->isFriend )
  102. {
  103. $m->SendComment( $post );
  104. }
  105. }
  106. $m->dispose( );
  107. $this->redirect( "snprofile.php?uid=".$this->uid );
  108. }
  109. else
  110. {
  111. $News = $m->GetNews( $this->uid, $this->pageIndex, $this->pageSize );
  112. $k = 0;
  113. while ( $News->next( ) )
  114. {
  115. $Comments = $m->GetComments( $News->row['ID'] );
  116. $this->topics[$k]['news'] = $News->row;
  117. while ( $Comments->next( ) )
  118. {
  119. $this->topics[$k]['news']['comment'][] = $Comments->row;
  120. }
  121. ++$k;
  122. }
  123. $m->dispose( );
  124. }
  125. }
  126. public function getNextLink( )
  127. {
  128. $text = text_nextpage_lang." »";
  129. if ( $this->pageIndex + 1 == $this->pageCount )
  130. {
  131. return $text;
  132. }
  133. $link = "p=".( $this->pageIndex + 1 );
  134. $link = "snprofile.php?uid=".$this->uid."&".$link;
  135. return "<a href=\"".$link."\">".$text."</a>";
  136. }
  137. public function getPreviousLink( )
  138. {
  139. $text = "« ".text_prevpage_lang;
  140. if ( $this->pageIndex == 0 )
  141. {
  142. return $text;
  143. }
  144. $link = "";
  145. if ( 0 < $this->pageIndex )
  146. {
  147. if ( $link != "" )
  148. {
  149. $link .= "&";
  150. }
  151. $link .= "p=".( $this->pageIndex - 1 );
  152. }
  153. if ( $link != "" )
  154. {
  155. $link = "?".$link;
  156. }
  157. $link = "snprofile.php".$link."&uid=".$this->uid;
  158. return "<a href=\"".$link."\">".$text."</a>";
  159. }
  160. }
  161. $p = new GPage( );
  162. $p->run( );
  163. ?>