PageRenderTime 28ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/gamecrawler/wp/youxisoso/functions.php

http://collectgame.googlecode.com/
PHP | 429 lines | 297 code | 56 blank | 76 comment | 45 complexity | 7ccb32c735f1fa881ec0c892991d9217 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. */
  5. function getCommendGames($category, $postnum){
  6. $cid = get_cat_ID($category);
  7. //???????PI??????
  8. $commends = get_posts(array('category'=>$cid, 'numberposts'=>$postnum, 'meta_key'=>'GamePI', 'orderby' => 'meta_value_num'));
  9. //$commends = get_posts(array('category'=>$cid, 'numberposts'=>$postnum, 'meta_key'=>'recommend', 'meta_value'=>'?'));
  10. $result = array();
  11. foreach ($commends as $key => $commend){
  12. $temp = array();
  13. $temp['post_id'] = $commend->ID;
  14. $temp['post_title'] = $commend->post_title;
  15. $temp['post_link'] = get_post_permalink($commend->ID);
  16. $cat = get_the_category($commend->ID);
  17. $temp['post_category'] = $cat[0]->name;
  18. $pic = get_post_meta($commend->ID, "GamePic");
  19. $temp['game_img'] = $pic[0];
  20. $result[] = $temp;
  21. }
  22. return $result;
  23. }
  24. function getNewestGames($category, $postnum){
  25. $commends = get_posts(array('category'=>get_cat_ID($category), 'numberposts'=>$postnum));
  26. $result = array();
  27. foreach ($commends as $key => $commend){
  28. $temp = array();
  29. $temp['post_id'] = $commend->ID;
  30. $temp['post_title'] = $commend->post_title;
  31. $temp['post_link'] = get_post_permalink($commend->ID);
  32. $cat = get_the_category($commend->ID);
  33. $temp['post_category'] = $cat[0]->name;
  34. $pic = get_post_meta($commend->ID, "GamePic");
  35. $temp['game_img'] = $pic[0];
  36. $result[] = $temp;
  37. }
  38. return $result;
  39. }
  40. //???????
  41. function getPostTotalViews($postID){
  42. $count_key = 'post_views_count';
  43. $count = get_post_meta($postID, $count_key, true);
  44. if($count==''){
  45. delete_post_meta($postID, $count_key);
  46. add_post_meta($postID, $count_key, '1');
  47. return "0";
  48. }
  49. return $count;
  50. }
  51. //?????????
  52. function getPostWeeklyViews($postID){
  53. $weekly_views_key = 'post_weekly_views_count';
  54. $weekly_count = get_post_meta($postID, $weekly_views_key, true);
  55. if($weekly_count == ''){
  56. $today_weekno = date('W');
  57. delete_post_meta($postID, $weekly_views_key);
  58. delete_post_meta($postID, $weekly_views_weekno);
  59. add_post_meta($postID, $weekly_views_key, '1');
  60. add_post_meta($postID, $weekly_views_weekno, $today_weekno);
  61. return '0';
  62. }
  63. return $weekly_count;
  64. }
  65. //????????????single???????????
  66. function setPostViews($postID) {
  67. $total_count_key = 'post_views_count';
  68. $weekly_views_key = 'post_weekly_views_count';
  69. //????????????????????????????????????????????????
  70. $weekly_views_weekno = 'post_weekly_view_weekno';
  71. $total_count = get_post_meta($postID, $total_count_key, true);
  72. //??????
  73. if($total_count==''){
  74. $total_count = 1;
  75. delete_post_meta($postID, $total_count_key);
  76. add_post_meta($postID, $total_count_key, $total_count);
  77. }else{
  78. $total_count++;
  79. update_post_meta($postID, $total_count_key, $total_count);
  80. }
  81. //??????
  82. $today_weekno = date('W'); //?????????????
  83. $weekly_count = get_post_meta($postID, $weekly_views_key, true);
  84. $weekly_weekno = get_post_meta($postID, $weekly_views_weekno, true);
  85. if($weekly_count =='' || $weekly_weekno == ''){
  86. delete_post_meta($postID, $weekly_views_key);
  87. delete_post_meta($postID, $weekly_views_weekno);
  88. add_post_meta($postID, $weekly_views_key, '1');
  89. add_post_meta($postID, $weekly_views_weekno, $today_weekno);
  90. }else{
  91. if ($today_weekno == $today_weekno){ //????????????????????+1
  92. $weekly_count++;
  93. update_post_meta($postID, $weekly_views_key, $weekly_count);
  94. }else{ //?????????????
  95. update_post_meta($postID, $weekly_views_key, '1');
  96. update_post_meta($postID, $weekly_views_key, $today_weekno);
  97. }
  98. }
  99. }
  100. //???????????????????????????????????????weekly/total
  101. function getPostByViews($viewsType = 'weekly', $postNum = 5){
  102. $meta_key = 'post_weekly_views_count';
  103. if ($viewsType == 'weekly'){
  104. $meta_key = 'post_weekly_views_count';
  105. }else if($viewsType == 'total'){
  106. $meta_key = 'post_views_count';
  107. }
  108. $args = array('numberposts' => $postNum,'meta_key' =>$meta_key, 'orderby' => 'meta_value_num');
  109. return get_posts($args);
  110. }
  111. //?????????
  112. function setGameOpendCount($gameId){
  113. $game_open_count_key = "post_games_open_count";
  114. $open_count = get_post_meta($gameId, $game_open_count_key, true);
  115. if($open_count){
  116. update_post_meta($gameId, $game_open_count_key, $open_count++);
  117. }else{
  118. delete_post_meta($gameId, $game_open_count_key);
  119. add_post_meta($gameId, $game_open_count_key, 1);
  120. }
  121. }
  122. /**
  123. * ???????????10??
  124. * @author shiwei
  125. * @param $postNum
  126. * @return unknown_type
  127. */
  128. function getHotPost( $postNum = 10){
  129. global $wpdb ;
  130. // $hotPostQue = "select count(post.post_title) ,post.ID as ID ,post.post_title as post_title ,tax.term_id as term_id ".
  131. // " from wp_term_taxonomy tax ,wp_term_relationships ships, (select p.* ,m.meta_value meta_value ".
  132. // " 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' ".
  133. // " AND p.post_type = 'post' ) post where ".
  134. // " post.ID = ships.object_id and ships.term_taxonomy_id = tax.term_taxonomy_id ".
  135. // " and tax.taxonomy ='category' ".
  136. // " group by post.post_title order by post.meta_value DESC limit 0,".$postNum;
  137. $hotPostQue = "select post.ID as ID ,post.post_title as post_title ,post.post_category_name as cat_name ,".
  138. " post.post_game_image as GamePic ".
  139. " from wp_posts post ".
  140. " where post.post_status = 'publish' and post.post_type = 'post' ".
  141. " order by post.post_pi desc limit 0 ,".$postNum;
  142. $hotposts = $wpdb->get_results($hotPostQue);
  143. return $hotposts ;
  144. }
  145. //????
  146. function collectGame($user_id, $game_id){
  147. global $wpdb;
  148. $result = $wpdb->get_results('select ID from wp_usergame where userid='.$user_id.' and gameid='.$game_id.' and type=1');
  149. if(count($result) == 0)
  150. $wpdb->insert('wp_usergame', array('userid'=>$user_id, 'gameid'=>$game_id, 'type'=>1, 'created'=>gmdate('Y-m-d H:i:s')));
  151. }
  152. //??????????
  153. function hasCollected($user_id, $game_id){
  154. global $wpdb;
  155. $result = $wpdb->get_results('select ID from wp_usergame where userid='.$user_id.' and gameid='.$game_id.' and type=1');
  156. return count($result);
  157. }
  158. //??????????
  159. function noteOpenedGame($user_id, $game_id){
  160. global $wpdb;
  161. $result = $wpdb->get_results('select ID from wp_usergame where userid='.$user_id.' and gameid='.$game_id.' and type=0');
  162. if(count($result) == 0)
  163. $wpdb->insert('wp_usergame', array('userid'=>$user_id, 'gameid'=>$game_id, 'type'=>0, 'created'=>gmdate('Y-m-d H:i:s')));
  164. }
  165. //?????????
  166. function getUserGames($userid, $type, $page){
  167. global $wpdb;
  168. return $wpdb->get_results('select * from wp_usergame where userid='.$userid.' and type='.$type.' order by created desc limit '.(($page - 1)*15).', '.($page * 15));
  169. }
  170. //??????????
  171. function getUserGamesCount($userid, $type){
  172. global $wpdb;
  173. $result = $wpdb->get_results('select count(*) as count from wp_usergame where userid='.$userid.' and type='.$type);
  174. return $result[0]->count;
  175. }
  176. function deleteUserGames($id){
  177. global $wpdb;
  178. $wpdb->query('delete from wp_usergame where ID='.$id);
  179. }
  180. /**
  181. * ??postID???????id??
  182. * @param $game_id
  183. * @return unknown_type
  184. */
  185. function findTagByPostId($game_id){
  186. global $wpdb;
  187. $tagQuery = "select tax.term_id as term_id , tax.taxonomy as taxonomy from wp_posts post ,wp_term_relationships ships ,wp_term_taxonomy tax ".
  188. " where post.ID = ships.object_id and ships.term_taxonomy_id = tax.term_taxonomy_id and tax.taxonomy in ('category','post_tag') ".
  189. " and post.ID='".$game_id."' " ;
  190. $tags = $wpdb->get_results($tagQuery);
  191. return $tags ;
  192. }
  193. /**
  194. * ???????10??????????tag??
  195. * @author : shiwei
  196. * @param $game_id post id
  197. * @param $size ?????
  198. * @return unknown_type
  199. */
  200. function getRelevancePosts($game_id,$size=10){
  201. global $wpdb;
  202. //???????tag+categroy??
  203. $tags = findTagByPostId($game_id) ;
  204. //??tag????
  205. $postQuery = " select distinct post.* from wp_posts post ,wp_term_relationships ships ,wp_term_taxonomy tax ".
  206. " where post.ID = ships.object_id and ships.term_taxonomy_id = tax.term_taxonomy_id and post.post_status = 'publish' AND post.post_type = 'post' ".
  207. " and post.ID !='".$game_id."' ";
  208. $condition = "(" ;
  209. $typeId = "" ;
  210. foreach ($tags as $tag){
  211. if("category"==$tag->taxonomy){
  212. $typeId = $tag->term_id ;
  213. } else {
  214. $condition = $condition."'".$tag->term_id."',";
  215. }
  216. }
  217. if($condition!="("){
  218. $condition = substr($condition,0,strlen($condition)-1);
  219. $condition = $condition.")" ;
  220. $postQuery = $postQuery." and ( (tax.term_id in ".$condition." and tax.taxonomy ='post_tag' ) or " ;
  221. }else {
  222. $postQuery = $postQuery." and ( (tax.term_id = '' and tax.taxonomy ='post_tag' ) or " ;
  223. }
  224. $postQuery = $postQuery." ( tax.term_id in ('".$typeId."') and tax.taxonomy ='category')) " ;
  225. $postQuery = $postQuery." order by tax.taxonomy desc limit 0,".$size ;
  226. $posts = $wpdb->get_results($postQuery);
  227. return $posts ;
  228. }
  229. //?????????????
  230. function setCustomLog($data){
  231. global $wpdb;
  232. $custom_id = $data['custom_id'];
  233. $results = $wpdb->get_results('select ID,data, op_date from wp_customlog where custom_id="'.$data['custom_id'].'" and data_type='.$data['data_type'].' order by op_date asc');
  234. if (count($results) >= 5){
  235. $id = $results[0]->ID;
  236. if($results[4]->data != $data['data'])
  237. $wpdb->update('wp_customlog', $data, array('ID'=>$id));
  238. }else {
  239. $wpdb->insert('wp_customlog', $data);
  240. }
  241. }
  242. //???????IP
  243. function GetIP(){
  244. if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
  245. $ip = getenv("HTTP_CLIENT_IP");
  246. else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
  247. $ip = getenv("HTTP_X_FORWARDED_FOR");
  248. else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
  249. $ip = getenv("REMOTE_ADDR");
  250. else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
  251. $ip = $_SERVER['REMOTE_ADDR'];
  252. else
  253. $ip = "unknown";
  254. return($ip);
  255. }
  256. //????????????????????????????????????????????????????????????????
  257. function deleteCustomLog($custome_id, $user_id){
  258. global $wpdb;
  259. $results = $wpdb->get_results('select count(*) as count from wp_customlog where custom_id="'.$user_id.'"');
  260. if ($results[0]->count){
  261. $wpdb->query('delete from wp_customlog where custom_id="'.$custome_id.'"');
  262. }else{
  263. $wpdb->update('wp_customlog', array('custom_id' => $user_id), array('custom_id'=>$custome_id));
  264. }
  265. }
  266. /**
  267. *
  268. * ????????
  269. * @param $user_id ??????ID
  270. * @param $value ???????
  271. */
  272. function addUserEmpiricalValue($user_id, $value){
  273. $key = "user_empiricalValue";
  274. $oldvalue = get_user_meta($user_id, $key, true);
  275. if($oldvalue && $oldvalue != ''){
  276. $value = $value + (int)$oldvalue;
  277. update_user_meta($user_id, $key, $value);
  278. }else{
  279. delete_user_meta($user_id, $key);
  280. add_user_meta($user_id, $key, $value);
  281. }
  282. }
  283. /**
  284. * ????????
  285. * @param unknown_type $userid
  286. */
  287. function getUserEmpiricalValue($userid){
  288. $key = "user_empiricalValue";
  289. $oldvalue = get_user_meta($userid, $key, true);
  290. return $oldvalue;
  291. }
  292. /**
  293. *
  294. * ????????????
  295. * @param unknown_type $useridm
  296. * @param unknown_type $gameid
  297. */
  298. function hasOpendGame($useridm, $gameid){
  299. global $wpdb;
  300. $result = $wpdb->get_results('select ID from wp_usergame where userid='.$user_id.' and gameid='.$game_id.' and type=0');
  301. return count($result) > 0 ? true : false;
  302. }
  303. /**
  304. * ?????????
  305. * @param $keyword ???
  306. * @author shiwei
  307. * @return unknown_type
  308. */
  309. function keywordStat($keyword){
  310. if($keyword!=null && ""!=$keyword){
  311. global $wpdb;
  312. $result = $wpdb->query( $wpdb->prepare( "update wp_keyword_stat set find_count = find_count+1 ,post_date = sysdate() where keyword=%s",$keyword ) );
  313. if($result<1){
  314. $result = $wpdb->query( $wpdb->prepare( "INSERT INTO wp_keyword_stat( keyword,post_date) VALUES ( %s,sysdate() )",$keyword ) );
  315. }
  316. }
  317. }
  318. /**
  319. * ?????????
  320. * @param $cookid ??ID????
  321. * @author yuyue
  322. * @return ??id,??
  323. */
  324. function getWanGuoByCookie($cookid){
  325. global $wpdb;
  326. $return_str = "";
  327. $result = $wpdb->get_results('select data from wp_customlog where custom_id = \''.$cookid.'\' and data_type = 1 order by op_date desc limit 4 ');
  328. if(count($result) > 0){
  329. $youxiID = "";
  330. foreach($result as $mypost) {
  331. $youxiID .= $mypost->data.',';
  332. }
  333. $youxiID = substr($youxiID,0,strlen($youxiID)-1);
  334. $sql = "select p.id,p.post_title from wp_posts p,wp_customlog c where p.id = c.data and custom_id = '".$cookid."' and data_type = 1 order by op_date desc limit 4";
  335. $result = $wpdb->get_results($sql);
  336. $return_str .= '<h4 style="font-weight:normal;width:650px;">????</h4><script language="javascript" type="text/javascript">';
  337. foreach($result as $loadimg) {
  338. $imgurl = get_post_meta ( $loadimg->id, "GamePic", $single = true );
  339. $return_str .='delayImagPrint.put("'.$loadimg->id.'","'.$imgurl.'");';
  340. }
  341. $return_str .='</script><ul>';
  342. foreach($result as $mypost) {
  343. $posttitle = $mypost->post_title;
  344. $imgurl = get_post_meta ( $mypost->id, "GamePic", $single = true );
  345. $return_str .='<li><a href=?p='.$mypost->id.'><img src="'.$imgurl.'" alt="'.$posttitle.'" width="130" height="101" title="'.$posttitle.'" /></a><img src="http://www.youxisoso.com/wp-content/themes/youxisoso/images/zjwgimgbg.jpg" width="130" height="7" style=" float:left; margin:-5px 0 0 7px" /><a href=?p='.$mypost->id.'>'.$posttitle.'</a></li>';
  346. }
  347. $return_str .= "</ul>";
  348. }
  349. return $return_str;
  350. }
  351. function mytheme_comment($comment, $args, $depth) {
  352. if($GLOBALS['comment']== null){
  353. $GLOBALS['comments_indexs'] = ($args['page']-1)* $args['per_page'] +1;
  354. }else{
  355. $GLOBALS['comments_indexs'] = $GLOBALS['comments_indexs']+1;
  356. }
  357. $GLOBALS['comment'] = $comment;
  358. ?>
  359. <div class="pinglun">
  360. <ul class="pl_left">
  361. <li><img src="<?php bloginfo('template_url');?>/images/pingltx.jpg" width="57" height="57" alt="?????" title="?????" /></li>
  362. <li class="pl_name"><?php echo get_comment_author_link();?></li>
  363. </ul>
  364. <span class="hengxian"></span>
  365. <ul class="pl_cont">
  366. <li class="pl_time">???:<?php echo get_comment_date() ;echo get_comment_time(); ?></li>
  367. <li class="pl_main"><?php comment_text();?></li>
  368. </ul>
  369. <span class="louceng"><?php echo $GLOBALS['comments_indexs'];?>F</span>
  370. </div>
  371. <?php
  372. }
  373. ?>