/gamecrawler/wp/youxisoso/dataresult.php
PHP | 317 lines | 248 code | 22 blank | 47 comment | 78 complexity | f028ae2285f0ef3fcd8f3f75cb1feaff MD5 | raw file
- <?php
- /**
- Template Name:data_result
- * @package WordPress
- * @subpackage Default_Theme
- * @author: shiwei
- */
-
- /**
- * ?????????1????
- * @param $str
- * @param $lenth
- * @param $start
- * @return unknown_type
- */
- function subString_UTF8($str, $lenth, $start=0){
- $len = strlen($str);
- $r = array();
- $n = 0;
- $m = 0;
- for($i = 0; $i < $len; $i++) {
- $x = substr($str, $i, 1);
- $a = base_convert(ord($x), 10, 2);
- $a = substr('00000000'.$a, -8);
- if ($n < $start){
- if (substr($a, 0, 1) == 0) {
- }elseif (substr($a, 0, 3) == 110) {
- $i += 1;
- }elseif (substr($a, 0, 4) == 1110) {
- $i += 2;
- }
- $n++;
- }else{
- if (substr($a, 0, 1) == 0) {
- $r[ ] = substr($str, $i, 1);
- }elseif (substr($a, 0, 3) == 110) {
- $r[ ] = substr($str, $i, 2);
- $i += 1;
- }elseif (substr($a, 0, 4) == 1110) {
- $r[ ] = substr($str, $i, 3);
- $i += 2;
- }else{
- $r[ ] = '';
- }
- if (++$m >= $lenth){
- break;
- }
- }
- }
- return join('',$r);
- }
-
-
- /**
- * ??????????
- * @param $str
- * @param $words
- * @return unknown_type
- */
- function highlight_word($str, $words){
- if(is_array($words)) {
- foreach($words as $k => $word){
- $pattern[$k] = '/(?!<[^>]*)'.
- '('.$word.')'.
- '(?![^<]*>)/ui';
- $replace[$k] = "<font style='color:red'>\\1</font>";
- }
- } else {
- $pattern = '/(?!<[^>]*)'.
- '('.$word.')'.
- '(?![^<]*>)/ui';
- $replace = "<font color='red'>\\1</font>";
- }
- return preg_replace($pattern,$replace,$str);
- }
-
-
-
- //????()?
- $pageSize = 10 ;
- $pageModel= 10 ; //???????
- $selfPageLink = "/" ; //?????
- $autoLink = "" ;
- $siteurl = get_bloginfo('template_url');
-
-
- //??????????????
- $cat = $_POST['cat'] ;
- if($cat == null || "" == $cat){
- $cat = $_GET['cat'] ;
- }
- //$categories = "" ;
- //$catStr = "" ;
- if($cat != null && "" != $cat){
- $category_id = get_cat_ID($cat);
- //$categories = get_categories ('child_of='.$category_id) ;
- //$categories = $wpdb->get_results("select p.name,p.term_id as pterm_id ,t.name,t.term_id as term_id ".
- // " from wp_terms t ,wp_term_taxonomy m , wp_terms p ".
- // " where t.term_id = m.term_id and p.term_id = m.parent and p.term_id ='".$category_id."'") ;
- //foreach ($categories as $category) {
- // $catStr =$catStr."'".$category->term_id."'," ;
- //}
- }
- $fixdiv = $_POST['fixdiv'] ;
- if($fixdiv == null || "" == $fixdiv){
- $fixdiv = $_GET['fixdiv'] ;
- }
- if($fixdiv == null ){
- $fixdiv = "" ;
- }
- //?????
- $keyword = $_POST['keywords'] ;
- if($keyword == null || "" == $keyword ){
- $keyword = $_GET["keywords"];
- }
- //$keyword = "??" ;
- //????????????
- $keyword = trim($keyword) ;
- $keyword = preg_replace("/\s+/" ," " ,$keyword) ;
- keywordStat($keyword) ;
- //????
- $paged = $_POST["paged"];
- if($paged == null || "" == $paged ){
- $paged = $_GET["paged"];
- if($paged == null || "" == $paged ){
- $paged = 0 ;
- }
- }
- $statNum = $pageSize * ($paged) ;
-
- //??sphinx
- require 'sphinxapi.php';
- //////////??sphinx?????///////////////
- $cl = new SphinxClient ();
- $cl->SetServer ( 'localhost', 9312);
- $cl->SetConnectTimeout ( 3 );
- //$catArray = array() ;
- //$catArray[0] = $cat ;
- if($category_id != null && "" != $category_id){
- $catArray = array() ;
- $catArray[0] = $category_id ;
- $cl->setFilter("post_category_id",$catArray);
- }
- $cl->SetArrayResult ( true );
- $cl->SetMatchMode ( SPH_MATCH_ANY);
- $cl->SetLimits ( $statNum, $pageSize ,1000);
- $cl->SetFieldWeights(array("post_title"=>1000, "post_content"=>1));
- //$cl->SetSelect("*") ;
- //$cl->SetSortMode ( SPH_SORT_ATTR_ASC, "gamepi" );
- $res = $cl->Query ( $keyword, "*" );
- $opts = array(
- 'before_match' => '<span style="color:red">',
- 'after_match' => '</span>',
- 'chunk_separator' => '...'//,
- //'limit'=>300
- );
-
- ////////??sphinx?????///////////////
-
- //????post?id?
- $unionSql = "" ;
- foreach($res['matches'] as $postidsArray){
- //$postids .= $postidsArray['id'].",";
- $unionSql = $unionSql." select ".$postidsArray['id']." as postid ,".$postidsArray['weight']." as weight from dual union all ";
- }
-
- //????
- $postQue = "" ;
- if(""==$unionSql){
- $postQue = "select ID,post_title, post_content,post_game_url,post_game_image,post_category_name from wp_posts where 1!=1 " ;
- }else {
- $unionSql = substr($unionSql,0,strlen($unionSql)-11) ;
- $postQue = "select post.ID,post.post_title, post.post_content,post.post_game_url,post.post_game_image,post.post_category_name from wp_posts post, ".
- "(".$unionSql.") temp where temp.postid = post.ID order by temp.weight desc " ;
- }
-
- $callback = $_GET['callback'];
-
- $myposts = $wpdb->get_results($postQue);
-
- $keyArray = explode(" ",$keyword) ;
-
- $html = "<div id='list_center'> ";
- $html .= "<span id='soso_result' class='list_centtopspan'> ??".$res['total_found']."????? ????:'".$res['time']."' </span>" ;
-
- foreach($myposts as $mypost){
- $gamePic = $mypost->post_game_image;
- $gameLink = $mypost->post_game_url;
- $postLink = get_permalink($mypost->ID);
- $postTitle = $mypost->post_title ;
- $desContent = $mypost->post_content ;
- if($keyword !=null && ""!=$keyword){
- $postTitle = highlight_word($postTitle,$keyArray) ;
- $desContent = highlight_word(subString_UTF8($desContent,150),$keyArray) ;
- }
- $cat_name = $mypost->post_category_name ;
- $cat_title = "" ;
- if($cat_name == 'andriod' ||$cat_name == 'iphone' || $cat_name == 'windows phone' ){
- $cat_title = "????:";
- }else {
- $cat_title = "??:";
- }
- $html .=
- "<div class='list'>".
- " <span class='list_img'><a href='".$postLink."'>".
- " <img src='".$gamePic."' width='104' height='79' alt='".$mypost->post_title."' title='".$mypost->post_title."' />".
- " </a></span>".
- " <h3 class='list_title'><a href='".$postLink."'>".$postTitle."</a>".
- " </h3>".
- " <span class='list_cat'>".$cat_title."<samp>".$cat_name."</samp></span>".
- " <p class='list_neirong'>".$desContent."</p>".
- " <span class='list_add'>??????<samp>".$gameLink."</samp></span>".
- "</div>";
-
- }
- $html .= "<div id='scroll'>";
- $totalPage = ceil($res['total_found']/$pageSize) ;
- if($totalPage >0){
- $i = 0 ;
- if(intval($paged) > 0 ){
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".(intval($paged)+1).","".$fixdiv."")' ><img src='".$siteurl."/images/next-top.gif' alt='???' title='???' class='f_l'/></a>" ;
- }
- if($totalPage<=$pageModel){
- for(;$i<$totalPage;$i++){
- if($i == intval($paged)){
- $html.="<font class='linknone'>".($i +1)."</font>";
- }else{
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- }elseif($totalPage < $pageModel + 3){
- $halfPageModel = intval($pageModel /3) ;
- if(intval($paged) < $halfPageModel*2){
- for($i=0;$i < $halfPageModel*2+1;$i++){
- if($i == intval($paged)){
- $html.="<font class='linknone'>".($i +1)."</font>";
- }else {
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- $html.="<a class='linkstyle03'>...</a>";
- for($i = $totalPage-($pageModel-$halfPageModel*2 -2);$i<$totalPage;$i++){
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }elseif(intval($paged) > $halfPageModel - 1) {
- for($i =0 ;$i< $halfPageModel-1;$i++){
- $html .= "<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- $html.="<a class='linkstyle03'>...</a>";
- for($i=$totalPage-($pageModel-$halfPageModel);$i < $totalPage;$i++){
- if($i == intval($paged)){
- $html.="<font class='linknone'>".($i +1)."</font>";
- }else{
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- }
- }else{
- $halfPageModel = intval($pageModel /2) ;
- if(intval($paged) < $halfPageModel-1){
- for($i =0 ;$i< $halfPageModel;$i++){
- if($i == intval($paged)){
- $html.="<font class='linknone'>".($i +1)."</font>";
- }else{
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- $html.="<a class='linkstyle03'>...</a>";
- for($i =$totalPage - ($pageModel - $halfPageModel - 1) ;$i< $totalPage ;$i++){
- $html .= "<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }elseif(intval($paged) > $totalPage - ($halfPageModel) ) {
- for($i = 0 ;$i< $halfPageModel-1 ;$i++){
- $html .= "<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- $html.="<a class='linkstyle03'>...</a>";
- for($i = $totalPage - ($pageModel - $halfPageModel) ;$i< $totalPage;$i++){
- if($i == intval($paged)){
- $html.="<font class='linknone'>".($i +1)."</font>";
- }else{
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- }else {
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",0,"".$fixdiv."")' class='linkstyle03'>1</a>";
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",1,"".$fixdiv."")' class='linkstyle03'>2</a>";
- $uses = 3 ;
- if($paged > $totalPage/2){
- $uses = 2 ;
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",2,"".$fixdiv."")' class='linkstyle03'>3</a>";
- }
- $html.="<a class='linkstyle03'>...</a>";
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".(intval($paged)-1).","".$fixdiv."")' class='linkstyle03'>".intval($paged)."</a>";
- $html.="<font class='linknone'>".(intval($paged) +1)."</font>";
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".(intval($paged)+1).","".$fixdiv."")' class='linkstyle03'>".(intval($paged) +2)."</a>";
- $html.="<a class='linkstyle03'>...</a>";
- for($i = $totalPage - $uses ;$i< $totalPage;$i++){
- $html .= "<a href='javascript:getResult("".$keyword."","".$cat."",".$i.","".$fixdiv."")' class='linkstyle03'>".($i +1)."</a>";
- }
- }
- }
-
-
- if(intval($paged)<$totalPage-1){
- $html.="<a href='javascript:getResult("".$keyword."","".$cat."",".(intval($paged)+1).","".$fixdiv."")' ><img src='".$siteurl."/images/next-bottom.gif' alt='???' title='???' class='f_l' /></a>";
- }
- }
-
- $html .= "</div>";
- $html .= "</div>";
-
- $jsonarray = array('html'=>$html,'fixdiv'=>$fixdiv) ;
- $ccc = json_encode($jsonarray);
- // $ccc = substr($ccc, 0 , $ccc.length -1) ;
- // $ccc = $ccc."]}" ;
- echo $callback.'('.$ccc.')' ;
- ?>