PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/gamecrawler/wp/youxisoso/search_back.php

http://collectgame.googlecode.com/
PHP | 435 lines | 353 code | 37 blank | 45 comment | 78 complexity | 61056cf613b963ac1abb97e7e7a7853e MD5 | raw file
  1. <?php
  2. //????()?
  3. $pageSize = 10 ;
  4. $pageModel= 10 ; //???????
  5. $selfPageLink = "/" ; //?????
  6. $autoLink = "" ;
  7. $siteurl = get_bloginfo('template_url');
  8. //???id
  9. $cat = $_POST['cat'] ;
  10. if($cat == null || "" == $cat){
  11. $cat = $_GET['cat'] ;
  12. }
  13. $categories = "" ;
  14. $catStr = "" ;
  15. if($cat != null && "" != $cat){
  16. $category_id = get_cat_ID($cat);
  17. $categories = get_categories ('child_of='.$category_id) ;
  18. // $categories = $wpdb->get_results("select p.name,p.term_id as pterm_id ,t.name,t.term_id as term_id ".
  19. // " from wp_terms t ,wp_term_taxonomy m , wp_terms p ".
  20. // " where t.term_id = m.term_id and p.term_id = m.parent and p.term_id ='".$category_id."'") ;
  21. foreach ($categories as $category) {
  22. $catStr =$catStr."'".$category->term_id."'," ;
  23. }
  24. }
  25. //?????
  26. $startSapnChar = "_%%" ;
  27. $endSpanChar = "_%" ;
  28. //$keyword = $_POST('keyword') ;
  29. $oldKeyword = "" ;
  30. $keyword = $_POST['s'] ;
  31. if($keyword == null || "" == $keyword ){
  32. $keyword = $_GET["s"];
  33. }
  34. if($keyword!= null){
  35. $keyword =str_replace('\\\'',"&#39;",$keyword) ;
  36. $keyword =str_replace('\\\"',"&#34;",$keyword) ;
  37. $oldKeyword = $keyword ;
  38. $oldKeyword = str_replace("&#34;",'"',$keyword );
  39. $oldKeyword = str_replace("&#39;","'",$oldKeyword );
  40. $keyword = str_replace($endSpanChar,"",$keyword) ;
  41. $keyword= trim($keyword) ;
  42. }
  43. $oldKeywordArray = explode(" ",$keyword);
  44. $keywordArray = array() ;
  45. //??
  46. $paged = $_POST["paged"];
  47. if($paged == null || "" == $paged ){
  48. $paged = $_GET["paged"];
  49. if($paged == null || "" == $paged ){
  50. $paged = 0 ;
  51. }
  52. }
  53. //???????????
  54. $queryStr = "select distinct terp.term_id as term_id, terp.name as name from wp_term_taxonomy tax ,wp_terms terp where tax.parent = terp.term_id" ;
  55. $cats = $wpdb->get_results($queryStr );
  56. $statNum = $pageSize * $paged ;
  57. function csubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) {
  58. if(function_exists("mb_substr")){
  59. if(mb_strlen($str, $charset) <= $length) return $str;
  60. $slice = mb_substr($str, $start, $length, $charset);
  61. }else{
  62. $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
  63. $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
  64. $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
  65. $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
  66. preg_match_all($re[$charset], $str, $match);
  67. if(count($match[0]) <= $length) return $str;
  68. $slice = join("",array_slice($match[0], $start, $length));
  69. }
  70. if($suffix) return $slice."…";
  71. return $slice;
  72. }
  73. get_header();
  74. ?>
  75. <div id="list_left">
  76. <ul>
  77. <li id="xuanzhong">>????</li>
  78. <?php
  79. if($category_id != null && "" != $category_id){
  80. ?>
  81. <li class="fenleileftfloat NOxuanzhong" ><a href="<?php echo $selfPageLink."?s=".$oldKeyword ;?>">????</a></li>
  82. <?php
  83. }else{
  84. ?>
  85. <li id="xuanzhong" class="fenleileftfloat"><a href="<?php echo $selfPageLink ;?>">????</a></li>
  86. <?php
  87. }
  88. ?>
  89. <?php
  90. foreach($cats as $v){
  91. if($v->term_id == $category_id){
  92. ?>
  93. <li id="xuanzhong" class="fenleileftfloat"><a href="<?php echo $selfPageLink."?s=".$oldKeyword."&cat=".$v->name;?>" ><?php echo $v->name; ?></a></li>
  94. <?php
  95. }else{
  96. ?>
  97. <li class="fenleileftfloat NOxuanzhong"><a href="<?php echo $selfPageLink."?s=".$oldKeyword."&cat=".$v->name;?>"><?php echo $v->name; ?></a></li>
  98. <?php
  99. }
  100. }
  101. ?>
  102. <!--
  103. <li class="NOxuanzhong"><a href="#">????</a></li>
  104. <li class="NOxuanzhong"><a href="#">flash??</a></li>
  105. <li class="NOxuanzhong"><a href="#">????</a></li> -->
  106. </ul>
  107. </div>
  108. <div id="list_center">
  109. <!-- ???????? -->
  110. <?php
  111. $postTable = "(select p.* ,m.meta_value meta_value from wp_posts p left join wp_postmeta m on m.post_id = p.ID and m.meta_key='GamePI' and p.post_status = 'publish' AND p.post_type = 'post' )" ;
  112. $condition = " where post.ID = ships.object_id and ships.term_taxonomy_id = tax.term_taxonomy_id and tax.taxonomy ='category' " ;
  113. foreach ($oldKeywordArray as $value){
  114. if($value!= null && $value!=""){
  115. $keywordArray[$value] = $value ;
  116. $condition=$condition." and post.post_title like '%".$value."%' ";
  117. }
  118. }
  119. // foreach ($oldKeywordArray as $value){
  120. // if($value!= null && $value!=""){
  121. // $keywordArray[$value] = $value ;
  122. // $condition=$condition." or post_content like '%".$value."%' ";
  123. // }
  124. // }
  125. // if($keyword != null && "" != $keyword){
  126. // $condition=$condition." and post_title like '%".$keyword."%' ";
  127. // }
  128. if($category_id != null && "" != $category_id){
  129. if($catStr !=null && "" != $catStr){
  130. $catStr = substr($catStr,0,strlen($catStr)-1) ;
  131. $condition=$condition." and tax.term_id in (".$catStr.") " ;
  132. }else{
  133. $condition=$condition." and tax.term_id = '' " ;
  134. }
  135. }
  136. $postCountQue = "select count(distinct post.post_title) as counts from wp_term_taxonomy tax ,wp_term_relationships ships, ".$postTable." post ".$condition ;
  137. $mycounts = $wpdb->get_results($postCountQue) ;
  138. $mycount= 0 ;
  139. if($mycounts != null){
  140. $mycount = $mycounts[0]->counts ;
  141. }
  142. ?>
  143. <span id="mianbaoxie" class="list_centtopspan">?????<a href="?">??</a>=><a href="<?php echo $selfPageLink ;?>">????</a></span>
  144. <span id="soso_result" class="list_centtopspan">??<?php echo $mycount; ?></>?????</span>
  145. <?php
  146. //$args = array ('paged'=>$paged,"orderby"=>"date");
  147. //query_posts($args);
  148. //while (have_posts()) : the_post();
  149. $postQue = "select count(distinct post.post_title) ,post.ID as ID ,post.post_title as post_title ,tax.term_id as term_id ,post.post_content as post_content ".
  150. "from wp_term_taxonomy tax ,wp_term_relationships ships, ".$postTable." post ".$condition." group by post.post_title ORDER BY post.meta_value DESC LIMIT ".$statNum.",".$pageSize ;
  151. $myposts = $wpdb->get_results($postQue);
  152. $startSapn = "<span style='color:red;'>";
  153. $endSpan = "</span>" ;
  154. foreach($myposts as $mypost) {
  155. // get game image by user defined
  156. //$gameSize = get_post_meta($mypost->ID, 'GameSize', true);
  157. $gamePic = get_post_meta($mypost->ID, 'GamePic', true);
  158. $gameLink = get_post_meta($mypost->ID, 'GameLink', true);
  159. $postLink = get_permalink($mypost->ID);
  160. $postTitle = $mypost->post_title ;
  161. $postTitle = str_replace("%","",$postTitle) ;
  162. $postTitle = str_replace("&quot;","&#39;",$postTitle) ;
  163. $titleHtml = $postTitle ;
  164. foreach($keywordArray as $value) {
  165. if($value !=null && $value != ""){
  166. $startFindPos = 0 ;
  167. $titleHtml = "" ;
  168. $indexPos = stripos($postTitle,$value,$startFindPos) ;
  169. if($indexPos >-1){
  170. do{
  171. $titleHtml = $titleHtml.substr($postTitle,$startFindPos,$indexPos-$startFindPos).$startSapnChar.
  172. substr($postTitle,$indexPos,strlen($value)).$endSpanChar.substr($postTitle,$indexPos+strlen($value)) ;
  173. $startFindPos = $indexPos + strlen($value);
  174. } while(($indexPos = stripos($postTitle,$value,$startFindPos)) >-1) ;
  175. }else{
  176. $titleHtml = $postTitle ;
  177. }
  178. // $titleArray = explode($value,$postTitle) ;
  179. // $titleHtml = "" ;
  180. // if(count($titleArray)>0){
  181. // $arrayCount = count($titleArray) ;
  182. // for($i= 0 ;$i<$arrayCount -1;$i++){
  183. // $titleHtml = $titleHtml.$titleArray[$i].$startSapnChar.$value.$endSpanChar ;
  184. // }
  185. // $titleHtml = $titleHtml.$titleArray[$arrayCount -1] ;
  186. // } else {
  187. // $titleHtml = $postTitle ;
  188. // }
  189. $postTitle = $titleHtml ;
  190. }
  191. }
  192. $titleHtml = str_replace($startSapnChar,$startSapn,$titleHtml) ;
  193. $titleHtml = str_replace($endSpanChar,$endSpan,$titleHtml) ;
  194. //mb_strimwidth(strip_tags(apply_filters('the_content', $mypost->post_content)), 0, 300,"…");
  195. $desHtml = csubstr($mypost->post_content, 0, 300, "utf-8", true) ;
  196. ?>
  197. <div class="list">
  198. <span class="list_img"><a href="<?php echo $postLink; ?>"><img src="<?php echo $gamePic ?>" width="104" height="79" alt="<?php echo $titleHtml; ?>" title="<?php echo $titleHtml; ?>" /></a></span>
  199. <h3 class="list_title"><a href="<?php echo $postLink; ?>"><?php echo $titleHtml;//$mypost->post_title; ?></a></h3>
  200. <span class="list_cat">
  201. <?php
  202. $cat_name = get_cat_name($mypost->term_id);
  203. if($cat_name == 'andriod' ||$cat_name == 'iphone' || $cat_name == 'windows phone' ){
  204. echo "????:";
  205. }else {
  206. echo "??:";
  207. }
  208. ?>
  209. <samp><?php echo $cat_name?></samp></span>
  210. <p class="list_neirong"><?php echo $desHtml; ?></p>
  211. <span class="list_add">??????<!-- <a href="<?php //echo $gameLink; ?>"> --><samp><?php echo $gameLink; ?></samp><!-- </a> --></span>
  212. </div>
  213. <?php
  214. }
  215. //endwhile;
  216. ?>
  217. <!-- ???????? -->
  218. <!-- ???? -->
  219. <div id="scroll">
  220. <?php
  221. $totalPage = ceil($mycount/$pageSize) ;
  222. if($totalPage >0){
  223. $i = 0 ;
  224. $pagedLink = $selfPageLink."?s=".$oldKeyword."&cat=".$cat;
  225. if(intval($paged) > 0 ){
  226. ?>
  227. <a href="<?php echo $pagedLink."&paged=".(intval($paged)-1); ?>" ><img src="<?php echo $siteurl ?>/images/next-top.gif" alt="???" title="???" class="f_l"/></a>
  228. <?php
  229. }
  230. ?>
  231. <?php
  232. if($totalPage<=$pageModel){
  233. for(;$i<$totalPage;$i++){
  234. if($i == intval($paged)){
  235. ?>
  236. <font class="linknone"><?php echo ($i +1);?></font>
  237. <?php
  238. }else{
  239. ?>
  240. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  241. <?php
  242. }
  243. }
  244. }elseif($totalPage < $pageModel + 3){
  245. $halfPageModel = intval($pageModel /3) ;
  246. if(intval($paged) < $halfPageModel*2){
  247. for($i=0;$i < $halfPageModel*2+1;$i++){
  248. if($i == intval($paged)){
  249. ?>
  250. <font class="linknone"><?php echo ($i +1);?></font>
  251. <?php
  252. }else{
  253. ?>
  254. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  255. <?php
  256. }
  257. }
  258. ?>
  259. <a class="linkstyle03"><?php echo "...";?></a>
  260. <?php
  261. for($i = $totalPage-($pageModel-$halfPageModel*2 -2);$i<$totalPage;$i++){
  262. ?>
  263. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  264. <?php
  265. }
  266. ?>
  267. <?php
  268. }elseif(intval($paged) > $halfPageModel - 1) {
  269. for($i =0 ;$i< $halfPageModel-1;$i++){
  270. ?>
  271. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  272. <?php
  273. }
  274. ?>
  275. <a class="linkstyle03"><?php echo "...";?></a>
  276. <?php
  277. for($i=$totalPage-($pageModel-$halfPageModel);$i < $totalPage;$i++){
  278. if($i == intval($paged)){
  279. ?>
  280. <font class="linknone"><?php echo ($i +1);?></font>
  281. <?php
  282. }else{
  283. ?>
  284. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  285. <?php
  286. }
  287. }
  288. }
  289. }else{
  290. $halfPageModel = intval($pageModel /2) ;
  291. if(intval($paged) < $halfPageModel-1){
  292. for($i =0 ;$i< $halfPageModel;$i++){
  293. if($i == intval($paged)){
  294. ?>
  295. <font class="linknone"><?php echo ($i +1);?></font>
  296. <?php
  297. }else{
  298. ?>
  299. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  300. <?php
  301. }
  302. }
  303. ?>
  304. <a class="linkstyle03"><?php echo "...";?></a>
  305. <?php
  306. for($i =$totalPage - ($pageModel - $halfPageModel - 1) ;$i< $totalPage ;$i++){
  307. ?>
  308. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  309. <?php
  310. }
  311. }elseif(intval($paged) > $totalPage - ($halfPageModel) ) {
  312. for($i = 0 ;$i< $halfPageModel-1 ;$i++){
  313. ?>
  314. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  315. <?php
  316. }
  317. ?>
  318. <a class="linkstyle03"><?php echo "...";?></a>
  319. <?php
  320. for($i = $totalPage - ($pageModel - $halfPageModel) ;$i< $totalPage;$i++){
  321. if($i == intval($paged)){
  322. ?>
  323. <font class="linknone"><?php echo ($i +1);?></font>
  324. <?php
  325. }else{
  326. ?>
  327. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  328. <?php
  329. }
  330. }
  331. }else {
  332. ?>
  333. <a href="<?php echo $pagedLink."&paged=0"; ?>" class="linkstyle03"><?php echo 1;?></a>
  334. <a href="<?php echo $pagedLink."&paged=1"; ?>" class="linkstyle03"><?php echo 2;?></a>
  335. <?php
  336. $uses = 3 ;
  337. if($paged > $totalPage/2){
  338. $uses = 2 ;
  339. ?>
  340. <a href="<?php echo $pagedLink."&paged=1"; ?>" class="linkstyle03"><?php echo 3;?></a>
  341. <?php
  342. }
  343. ?>
  344. <a class="linkstyle03"><?php echo "...";?></a>
  345. <a href="<?php echo $pagedLink."&paged=".(intval($paged)-1); ?>" class="linkstyle03"><?php echo intval($paged);?></a>
  346. <font class="linknone"><?php echo (intval($paged) +1);?></font>
  347. <a href="<?php echo $pagedLink."&paged=".(intval($paged)+1); ?>" class="linkstyle03"><?php echo (intval($paged) +2);?></a>
  348. <a class="linkstyle03"><?php echo "...";?></a>
  349. <?php
  350. for($i = $totalPage - $uses ;$i< $totalPage;$i++){
  351. ?>
  352. <a href="<?php echo $pagedLink."&paged=".(intval($i)); ?>" class="linkstyle03"><?php echo ($i +1);?></a>
  353. <?php
  354. }
  355. }
  356. }
  357. if(intval($paged)<$totalPage-1){
  358. ?>
  359. <a href="<?php echo $pagedLink."&paged=".(intval($paged)+1); ?>" ><img src="<?php echo $siteurl ?>/images/next-bottom.gif" alt="???" title="???" class="f_l" /></a>
  360. <?php
  361. }
  362. }
  363. ?>
  364. </div>
  365. <!-- ???? -->
  366. </div>
  367. <!-- ?????? -->
  368. <div id="list_right">
  369. <h2>??????</h2>
  370. <?php
  371. // $hotPostQue = "select count(post.post_title) ,post.ID as ID ,post.post_title as post_title ,tax.term_id as term_id ".
  372. // " from wp_term_taxonomy tax ,wp_term_relationships ships, wp_posts post where ".
  373. // " post.ID = ships.object_id and ships.term_taxonomy_id = tax.term_taxonomy_id and post_status = 'publish' AND post_type = 'post' and tax.taxonomy ='category' ".
  374. // " group by post.post_title order by post.comment_count desc limit 0,10 ";
  375. //query_posts('orderby=comment_count&showposts=4');//????ID?7?2???
  376. //while (have_posts()) : the_post();
  377. $i =1 ;
  378. $hotposts = getHotPost(10); // $wpdb->get_results($hotPostQue);
  379. foreach($hotposts as $hotpost) {
  380. //$gameSize = get_post_meta($hotpost->ID, 'GameSize', true);
  381. $gamePic = get_post_meta($hotpost->ID, 'GamePic', true);
  382. //$gameLink = get_post_meta($hotpost->ID, 'GameLink', true);
  383. $postLink = get_permalink($hotpost->ID);
  384. ?>
  385. <div class="list_tuijian">
  386. <span class="list_img"><a href="<?php echo $postLink; ?>"><img src="<?php echo $gamePic; ?>" width="104" height="79" alt="<?php echo $hotpost->post_title; ?>" title="<?php echo $hotpost->post_title;?>" /></a></span>
  387. <!-- <span class="listriht listriht_tuijian"><img src="<?php echo $siteurl ?>/images/tuijian/<?php echo $i++ ;?>.jpg" /></span> -->
  388. <h5 class="listriht listriht_tit"><a href="<?php echo $postLink; ?>"><?php echo $hotpost->post_title; ?></a></h5>
  389. <span class="listriht listriht_cat "><?php echo get_cat_name($hotpost->term_id);?></span>
  390. </div>
  391. <?php
  392. }
  393. //endwhile;
  394. ?>
  395. </div>
  396. <!-- ?????? -->
  397. </div>
  398. <?php get_footer();?>