PageRenderTime 29ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/gamecrawler/wp/youxisoso/sphinxtest.php

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