PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/plugins/game/game_total.php

http://ownerpress.googlecode.com/
PHP | 248 lines | 204 code | 5 blank | 39 comment | 22 complexity | 22045f3dbe31f8a831cf5d2fda1a6739 MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. class game_total{
  3. private $cat;//??,big_type
  4. private $page;//??
  5. private $number;//??
  6. private $pic_address;//????
  7. private $url_address="/wp-content/themes/zenko/scripts/timthumb.php?src=";
  8. private $width=120;
  9. private $height=160;
  10. private $cat_cn_en_map = array('??'=>'star', '??'=>'trend', '??'=>'sport', '??'=>'event', '??'=>'culture', '??'=>'life', '??'=>'pet');
  11. private $cat_en_cn_map = array('star'=>'??', 'trend'=>'??', 'sport'=>'??', 'event'=>'??', 'culture'=>'??', 'life'=>'??', 'pet'=>'??');
  12. public function __construct($cat,$page){
  13. if(!empty($cat)){
  14. $cat = $this->cat_en_cn_map[$cat];
  15. }
  16. $this->cat=$cat;
  17. $this->page=$page;
  18. require_once 'pic_address.php';
  19. $this->pic_address=new pic_address();
  20. }
  21. //??
  22. public function game_run(){
  23. ?>
  24. <div id="middle">
  25. <div class="h_game_l">
  26. <?php
  27. $this->game_head();
  28. $this->main_game();
  29. ?>
  30. </div>
  31. </div>
  32. <?php
  33. }
  34. public function game_head(){
  35. ?>
  36. <div class="h_g_t">
  37. <h3>????</h3>
  38. <div class="h_g_nav">
  39. <a href="/games/" <?php if(empty($this->cat)){?>class="h_g_sel"<?php }?>>??</a>
  40. <?php
  41. foreach($this->cat_cn_en_map as $cat_cn => $cat_en){
  42. ?>
  43. <span>-</span>
  44. <a href="/games/<?php echo $cat_en;?>/" <?php if(strcmp($this->cat, $cat_cn)==0){?>class="h_g_sel"<?php }?>><?php echo $cat_cn;?></a>
  45. <?php } ?>
  46. </div>
  47. </div>
  48. <?php
  49. }
  50. public function main_game(){
  51. //???????
  52. global $wpdb;//????
  53. if(empty($this->cat)){
  54. //??
  55. $this->number=$wpdb->get_var("select count(*) from tb_game_type where is_right=1");
  56. }else{
  57. $this->number=$wpdb->get_var("select count(*) from tb_game_type where is_right=1 and big_type='".$wpdb->escape($this->cat)."'");
  58. }
  59. //echo $this->number;
  60. if(intval($this->number)==0){
  61. echo "?????????";
  62. return ;
  63. }
  64. //$this->number=133;
  65. $page=$this->page-1;
  66. $page_number=ceil($this->number/15);
  67. //echo $page_number;
  68. if($page>=$page_number){
  69. //?????????????
  70. $page=0;
  71. $this->page=1;
  72. //echo "????";
  73. }
  74. $search_begin=$page*15;//???????
  75. if(empty($this->cat)){
  76. $opts = $wpdb->get_results("select mid,type from tb_game_type where is_right=1 order by tid desc limit ".$search_begin.",15");
  77. //echo "select mid from tb_game_type where is_right=1 order by tid desc limit ".$search_begin.",15";
  78. }else{
  79. $opts = $wpdb->get_results("select mid,type from tb_game_type where is_right=1 and big_type='".$wpdb->escape($this->cat)."' order by tid desc limit ".$search_begin.",15");
  80. }
  81. foreach ($opts as $my_game){
  82. $mid=$my_game->mid;//??mid
  83. $type=$my_game->type;//??type
  84. $game_opts = $wpdb->get_row("SELECT pid_1,pid_2 FROM tb_game_pic WHERE type = '".$wpdb->escape($type)."' limit 0,1",ARRAY_A);
  85. $pid_1=$game_opts['pid_1'];
  86. $pid_2=$game_opts['pid_2'];
  87. $each_game=array('mid'=>$mid,'pid_1'=>$pid_1,'pid_2'=>$pid_2);
  88. $this->draw_game($each_game);
  89. }
  90. $this->draw_foot();
  91. }
  92. public function draw_foot(){
  93. if(intval($this->number)<=15){
  94. //?????
  95. return ;
  96. }
  97. $url="/games/";
  98. if(!empty($this->cat)){
  99. $url .= $this->cat_cn_en_map[$this->cat].'/';
  100. }
  101. //???
  102. ?>
  103. <div class="page">
  104. <?php
  105. //$this->number=1000;
  106. //$this->page=7;//??????
  107. if(intval($this->page)==1){
  108. //???????????????????????
  109. ?>
  110. <span class="dis_page">[???]</span>
  111. <span class="dis_page">&lt;&lt;??? </span>
  112. <?php
  113. }else{
  114. //??????????
  115. $my_page=$this->page-1;
  116. ?>
  117. <a href="<?php echo "{$url}?page=1";?>">[???]</a>
  118. <a href="<?php echo "{$url}?page={$my_page}";?>">&lt;&lt;??? </a>
  119. <?php
  120. }
  121. $foot_now_page=$this->page;//??????
  122. $foot_page=ceil($this->number/15); //??????
  123. if($foot_now_page<5||($foot_page-$foot_now_page)<4){
  124. //?????4?????????4???$foot_noe_page=5
  125. if($foot_now_page<=9 && ($foot_page<=9 || $foot_page-$foot_now_page>=4)){
  126. //???????9?????????9??????????9??? 8?12)
  127. for($foot_i=1;$foot_i<=$foot_page&&$foot_i<=9;$foot_i++){
  128. //?????????????9???????
  129. if($foot_i==$foot_now_page){
  130. //????
  131. ?>
  132. <b><?php echo $foot_now_page;?></b>
  133. <?php
  134. }else{
  135. //????
  136. ?>
  137. <a href="<?php echo "{$url}?page={$foot_i}";?>"><?php echo $foot_i;?></a>
  138. <?php
  139. }
  140. }
  141. }else{
  142. //???????9????9????????4?
  143. for($foot_i=9;$foot_i>=1;$foot_i--){
  144. //?????9?
  145. $foot_in_i=$foot_i-1;
  146. if($foot_page-$foot_in_i==$foot_now_page){
  147. //???
  148. ?>
  149. <b><?php echo $foot_now_page;?></b>
  150. <?php
  151. }else{
  152. $foot_in_page=$foot_page-$foot_in_i;
  153. //????
  154. ?>
  155. <a href="<?php echo "{$url}?page={$foot_in_page}";?>"><?php echo $foot_in_page;?></a>
  156. <?php
  157. }
  158. }
  159. }
  160. }else{
  161. //????4????4?
  162. for($foot_i=4;$foot_i>=1;$foot_i--){
  163. //???4?
  164. $here_page=$foot_now_page-$foot_i;
  165. ?>
  166. <a href="<?php echo "{$url}?page={$here_page}";?>"><?php echo $here_page;?></a>
  167. <?php
  168. }
  169. //?????
  170. ?>
  171. <b><?php echo $foot_now_page;?></b>
  172. <?php
  173. //???4?
  174. for($foot_i=1;$foot_i<=4;$foot_i++){
  175. //???4?
  176. $here_page=$foot_now_page+$foot_i;
  177. ?>
  178. <a href="<?php echo "{$url}?page={$here_page}";?>"><?php echo $here_page;?></a>
  179. <?php
  180. }
  181. }
  182. //???????
  183. if($foot_now_page==$foot_page){
  184. //?????
  185. ?>
  186. <span class="dis_page">???&gt;&gt;</span>
  187. <span class="dis_page">[???]</span>
  188. <?php
  189. }else{
  190. //??????
  191. $my_page=$this->page+1;
  192. ?>
  193. <a href="<?php echo "{$url}?page={$my_page}";?>">??? &gt;&gt;</a>
  194. <a href="<?php echo "{$url}?page={$foot_page}";?>">[???]</a>
  195. <?php
  196. }
  197. ?>
  198. </div>
  199. <?php
  200. }
  201. function draw_game($game){
  202. global $wpdb;//????
  203. $mid=$game['mid'];//??id
  204. $pid_1=$game['pid_1'];//????1
  205. $pid_2=$game['pid_2'];//????2
  206. //$a=get_post($mid);
  207. $address1=$this->pic_address->get_address($pid_1);//???????
  208. $address2=$this->pic_address->get_address($pid_2);//???????
  209. $p1_address="{$this->url_address}{$address1}&w={$this->width}&h={$this->height}&zc=1";
  210. $p2_address="{$this->url_address}{$address2}&w={$this->width}&h={$this->height}&zc=1";
  211. //$link=get_permalink($mid);//????
  212. $link= '/games/'.$mid.'.html';
  213. //$title=get_the_title($mid);//??
  214. //echo $title;
  215. //$nr=get_posts($mid);
  216. $opts = $wpdb->get_row("SELECT post_content,post_title,post_excerpt FROM wp_posts WHERE id = '".$wpdb->escape($mid)."' and post_type='game' and post_status='publish'",ARRAY_A);
  217. $number=$wpdb->num_rows;
  218. //echo $number."xxxsss";
  219. if(intval($number)!=1){
  220. $title="??????";
  221. $page="????????";
  222. }else{
  223. $title=$opts['post_title'];
  224. $my_page=$opts['post_content'];
  225. $page=$opts['post_excerpt'];
  226. }
  227. //echo $title.$page;
  228. ?>
  229. <div class="h_game_item">
  230. <a href="<?php echo $link;?>" class="h_game_itemA">
  231. <img src="<?php echo $p1_address;?>"/>
  232. </a>
  233. <a href="<?php echo $link;?>" class="h_game_itemA">
  234. <img src="<?php echo $p2_address;?>"/>
  235. </a>
  236. <div class="h_g_itemR">
  237. <a href="<?php echo $link;?>"><?php echo $title;?></a>
  238. <p><?php echo $page;?></p>
  239. </div>
  240. </div>
  241. <?php
  242. }
  243. }