Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2012
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.37 KB | None | 0 0
  1. <?php
  2. add_action('wp_ajax_query_geo_ads', 'query_geo_ads');
  3. add_action('wp_ajax_nopriv_query_geo_ads', 'query_geo_ads');
  4. add_action('wp_ajax_get_image_url', 'get_image_url');
  5. add_action('wp_ajax_nopriv_get_image_url', 'get_image_url');
  6.  
  7. add_action('wp_ajax_query_total', 'query_total');
  8. add_action('wp_ajax_nopriv_query_total', 'query_total');
  9.  
  10.  
  11. if (defined('MULTISITE') && (MULTISITE))
  12. {
  13.  
  14. if (!defined('TT'))
  15. define('TT', plugins_url('/geo-ads/timthumb_wpmu.php'));
  16. }
  17. else
  18. {
  19. if (!defined('TT'))
  20. define('TT', plugins_url('/geo-ads/timthumb.php'));
  21. }
  22.  
  23. function query_total()
  24. {
  25. global $wpdb;
  26. $table = $wpdb->prefix.'cp_ad_geocodes';
  27.  
  28. $q = "SELECT COUNT(*) FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id) WHERE p.post_status = 'publish'";
  29. $c = $wpdb->get_var($q);
  30. echo $c;
  31.  
  32. die();
  33.  
  34. }
  35.  
  36. function query_geo_ads()
  37. {
  38. if ($_GET['range'] == 'true') {
  39. query_geo_ads_refresh();
  40. }
  41. else {
  42. global $wpdb;
  43. $table = $wpdb->prefix.'cp_ad_geocodes';
  44. $querystr = "SELECT t.post_id, t.category, t.lat, t.lng, p.post_title, p.post_content, m.meta_value as price, CONCAT(wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE(wpo.option_value,'%year%',date_format(p.post_date,'%Y')) ,'%monthnum%',date_format(p.post_date,'%m')) ,'%day%',date_format(p.post_date,'%d')) ,'%postname%',p.post_name ) ) as permalink
  45. FROM $table t LEFT JOIN $wpdb->posts p ON (p.ID = t.post_id)
  46. INNER JOIN $wpdb->options wpo ON wpo.option_name='permalink_structure'
  47. INNER JOIN $wpdb->options wpo_su ON wpo_su.option_name='siteurl'
  48. LEFT JOIN $wpdb->postmeta m ON (m.meta_key = 'cp_price') AND (m.post_id = p.ID)
  49. WHERE p.post_status = 'publish'
  50. AND p.post_type = 'ad_listing' ";
  51.  
  52. $ads = $wpdb->get_results($querystr);
  53.  
  54. $expires = 50000;
  55. $cache_time = mktime();
  56.  
  57. header("Cache-Control: max-age:" . $expires . ", must-revalidate");
  58. header("Expires: " . gmdate("D, d M Y H:i:s",$cache_time+$expires) . " GMT");
  59.  
  60. echo json_encode($ads);
  61. die();
  62. }
  63. }
  64.  
  65. function get_image_url()
  66. { $post_id = intval($_POST['id']);
  67. $attachment = get_posts(array('post_type' => 'attachment','post_status' => null,'order' => 'ASC','orderby' => 'post_date','post_mime_type' => 'image','post_parent' => $post_id));
  68. $height = 100;
  69. $width = 100;
  70. $url = TT.'?src='.wp_get_attachment_url($attachment[0]->ID, false).'&h='.$height.'&w='.$width;
  71. if ($attachment)
  72. echo $url;
  73. die();
  74. }
  75.  
  76. function query_geo_ads_refresh() {
  77. ?>
  78. <?php
  79. global $wpdb;
  80.  
  81. $exclude_categories = $_REQUEST['exclude_categories'];
  82. $term_id = $_REQUEST['term_id'];
  83. $term_slug = $_REQUEST['term_slug'];
  84. $taxonomy_name = $_REQUEST['taxonomy_name'];
  85. $northeast_lng = $_REQUEST['northeast_lng'];
  86. $northeast_lat = $_REQUEST['northeast_lat'];
  87. $southwest_lng = $_REQUEST['southwest_lng'];
  88. $southwest_lat = $_REQUEST['southwest_lat'];
  89. $lng = $_REQUEST['lng'];
  90. $lat = $_REQUEST['lat'];
  91.  
  92. if(!empty($exclude_categories)) {
  93. $exclude_categories = explode(';', $exclude_categories);
  94. }
  95. if(!$term_id) // this means root
  96. //$term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0' );
  97. $term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0&parent=0' );
  98. else {
  99. $current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
  100. $term_categories = get_terms( $taxonomy_name, 'orderby=count&hide_empty=0&parent=' . $term_id );
  101.  
  102. if(empty($term_categories))
  103. $term_categories[] = $current_term;
  104. }
  105.  
  106. foreach ($term_categories as $catinfo_obj)
  107. {
  108. $term_id = $catinfo_obj->term_id;
  109. $arrsrch = array("'");
  110. $arrrep = array('');
  111. $name = htmlspecialchars_decode($catinfo_obj->name);
  112. $name = strtolower(str_replace($arrsrch,$arrrep,$name));
  113. if(!empty($exclude_categories)) {
  114. if(in_array(strtolower($name), $exclude_categories))
  115. continue;
  116. }
  117. $subterm_ids = get_term_children( $term_id, 'ad_cat' );
  118. $subterm_ids[] = $term_id;
  119. $term_ids = implode(',', $subterm_ids);
  120.  
  121. if($term_id)
  122. {
  123. $my_post_type = "'ad_listing'";
  124. $sql = "select * from $wpdb->posts p where p.post_type in ($my_post_type) and p.post_status in ('publish') and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($term_ids) )";
  125.  
  126. $postinfo = $wpdb->get_results($sql);
  127.  
  128.  
  129.  
  130.  
  131. if($postinfo)
  132. {
  133. $srcharr = array("'");
  134. $replarr = array("\'");
  135. foreach($postinfo as $postinfo_obj)
  136. {
  137. $ID = $postinfo_obj->ID;
  138.  
  139.  
  140. $geocode = cp_get_geocode($ID);
  141. $lat = $geocode['lat'];
  142. $lng = $geocode['lng'];
  143. // check current post geo place is within map coord area
  144. if($lat > $northeast_lat || $lat < $southwest_lat)
  145. continue;
  146. if($northeast_lng > $southwest_lng) {
  147. if($lng > $northeast_lng || $lng < $southwest_lng)
  148. continue;
  149. } else {
  150. if($lng > 0 && $lng < $southwest_lng)
  151. continue;
  152. if($lng < 0 && $lng > $northeast_lng)
  153. continue;
  154. }
  155. $address = get_post_meta($ID,'cp_address_line',true);
  156. if(!empty($address))
  157. $address = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_address_line',true)));
  158. else {
  159. $street = get_post_meta($ID,'cp_street',true);
  160. $city = get_post_meta($ID,'cp_city',true);
  161. $state = get_post_meta($ID,'cp_state',true);
  162. $country = get_post_meta($ID,'cp_country',true);
  163. if(!empty($street))
  164. $address .= $street . ', ';
  165. if(!empty($city))
  166. $address .= $city . ', ';
  167. if(!empty($state))
  168. $address .= $state . ', ';
  169. if(!empty($country))
  170. $address .= $country . ', ';
  171. $address = trim($address);
  172. $address = substr($address, 0, strlen($address)-1);
  173. $address = str_replace($srcharr,$replarr,$address);
  174. }
  175.  
  176.  
  177.  
  178.  
  179. if($postinfo_obj->post_type == 'ad_listing') {
  180. $timing = date('M d, Y',strtotime(get_post_meta($ID,'cp_start_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'cp_end_date',true)));
  181. } else {
  182. $timing = date('M d, Y',strtotime(get_post_meta($ID,'st_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'end_date',true))).'<br />'.get_post_meta($ID,'st_time',true).' to '.get_post_meta($ID,'end_time',true);
  183. }
  184. ?>
  185. <div class="undertab"><span class="big">Classified Ads / <strong><span class="colour">Just Listed</span></strong></span></div>
  186. <?php
  187. global $wpdb,$wp_query, $post;
  188.  
  189. $exclude_categories = $_REQUEST['exclude_categories'];
  190. $term_id = $_REQUEST['term_id'];
  191. $term_slug = $_REQUEST['term_slug'];
  192. $taxonomy_name = $_REQUEST['taxonomy_name'];
  193. $northeast_lng = $_REQUEST['northeast_lng'];
  194. $northeast_lat = $_REQUEST['northeast_lat'];
  195. $southwest_lng = $_REQUEST['southwest_lng'];
  196. $southwest_lat = $_REQUEST['southwest_lat'];
  197.  
  198. if(!empty($exclude_categories)) {
  199. $exclude_categories = explode(';', $exclude_categories);
  200. }
  201. if(!$term_id) // this means root
  202. //$term_categories = get_terms( 'ad_cat', 'orderby=count&hide_empty=0' );
  203. $term_categories = get_terms( 'ad_cat', 'order=DESC','orderby=post_date' );
  204. else {
  205. $current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
  206. $term_categories = get_terms( $taxonomy_name, 'order=DESC','orderby=post_date' );
  207.  
  208. if(empty($term_categories))
  209. $term_categories[] = $current_term;
  210. }
  211.  
  212. foreach ($term_categories as $catinfo_obj)
  213. {
  214. $term_id = $catinfo_obj->term_id;
  215. $arrsrch = array("'");
  216. $arrrep = array('');
  217. $name = htmlspecialchars_decode($catinfo_obj->name);
  218. $name = strtolower(str_replace($arrsrch,$arrrep,$name));
  219. if(!empty($exclude_categories)) {
  220. if(in_array(strtolower($name), $exclude_categories))
  221. continue;
  222. }
  223. $subterm_ids = get_term_children( $term_id, 'ad_cat' );
  224. $subterm_ids[] = $term_id;
  225. $term_ids = implode(',', $subterm_ids);
  226.  
  227. if($term_id)
  228. {
  229. $my_post_type = "'ad_listing'";
  230. $sql = "select * from $wpdb->posts p where p.post_type in ($my_post_type) and p.post_status in ('publish') and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($term_ids) )";
  231.  
  232. $postinfo = $wpdb->get_results($sql);
  233.  
  234. $data_arr = array();
  235. $geo_codes = array();
  236.  
  237. if($postinfo)
  238. {
  239. $srcharr = array("'");
  240. $replarr = array("\'");
  241. foreach($postinfo as $postinfo_obj)
  242. {
  243. $ID = $postinfo_obj->ID;
  244. $title = str_replace($srcharr,$replarr,($postinfo_obj->post_title));
  245. $plink = get_permalink($postinfo_obj->ID);
  246.  
  247. $geocode = cp_get_geocode($ID);
  248. $lat = $geocode['lat'];
  249. $lng = $geocode['lng'];
  250. // check current post geo place is within map coord area
  251. if($lat > $northeast_lat || $lat < $southwest_lat)
  252. continue;
  253. if($northeast_lng > $southwest_lng) {
  254. if($lng > $northeast_lng || $lng < $southwest_lng)
  255. continue;
  256. } else {
  257. if($lng > 0 && $lng < $southwest_lng)
  258. continue;
  259. if($lng < 0 && $lng > $northeast_lng)
  260. continue;
  261. }
  262. $address = get_post_meta($ID,'cp_address_line',true);
  263. if(!empty($address))
  264. $address = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_address_line',true)));
  265. else {
  266. $street = get_post_meta($ID,'cp_street',true);
  267. $city = get_post_meta($ID,'cp_city',true);
  268. $state = get_post_meta($ID,'cp_state',true);
  269. $country = get_post_meta($ID,'cp_country',true);
  270. if(!empty($street))
  271. $address .= $street . ', ';
  272. if(!empty($city))
  273. $address .= $city . ', ';
  274. if(!empty($state))
  275. $address .= $state . ', ';
  276. if(!empty($country))
  277. $address .= $country . ', ';
  278. $address = trim($address);
  279. $address = substr($address, 0, strlen($address)-1);
  280. $address = str_replace($srcharr,$replarr,$address);
  281. }
  282.  
  283. $phone = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_phone',true)));
  284. $email = str_replace($srcharr,$replarr,(get_post_meta($ID,'cp_email',true)));
  285. $author = get_userdata($postinfo_obj->post_author);
  286. $category = get_the_category($postinfo_obj->ID);
  287. if($postinfo_obj->post_type == 'ad_listing') {
  288. $timing = date('M d, Y',strtotime(get_post_meta($ID,'cp_start_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'cp_end_date',true)));
  289. } else {
  290. $timing = date('M d, Y',strtotime(get_post_meta($ID,'st_date',true))).' to '.date('M d, Y',strtotime(get_post_meta($ID,'end_date',true))).'<br />'.get_post_meta($ID,'st_time',true).' to '.get_post_meta($ID,'end_time',true);
  291. }
  292. ?>
  293. <?php appthemes_before_post(); ?>
  294.  
  295. <div class="post-block-out">
  296.  
  297. <div class="post-block">
  298.  
  299. <div class="post-left">
  300.  
  301. <?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail($ID); ?>
  302.  
  303. </div>
  304. <div class="<?php if ( get_option('cp_ad_images') == 'yes' ) echo 'post-right'; else echo 'post-right-no-img'; ?> <?php echo get_option('cp_ad_right_class'); ?>">
  305.  
  306. <!-- <h3><a href="<?php echo $plink; ?>"><?php if ( mb_strlen( $title ) >= 75 ) echo mb_substr( $title, 0, 75 ).'...'; else echo $title; ?></a></h3>
  307.  
  308. <div class="clr"></div>
  309.  
  310. <p class="post-meta">
  311. <span class="folder">
  312. <a href="/ad-category/<?php echo $catinfo_obj->slug; ?>/">
  313. <?php echo $name; ?>
  314. </a>
  315. </span> |
  316. <span class="owner">
  317. <a href="/author/<?php echo $author->user_nicename; ?>">
  318. <?php echo $author->display_name; ?>
  319. </a>
  320. </span> |
  321. <span class="clock"><span><?php echo $timing; ?></span></span>
  322. </p>-->
  323.  
  324.  
  325. </div>
  326.  
  327. <div class="clr"></div>
  328.  
  329. </div><!-- /post-block -->
  330.  
  331. </div><!-- /post-block-out -->
  332.  
  333.  
  334.  
  335. <?php
  336. }
  337. }
  338. }
  339. }
  340.  
  341. die();
  342. }
  343. }
  344. }}}
  345. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement