daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. echo <<<insert
  2. <?php if ( in_category( 'dallas-slug') ) : ?>
  3. <p>
  4. custom text to insert
  5. </p>
  6. <?php endif; ?>
  7. insert;
  8.    
  9. <?php
  10.  
  11. // Displays class locations from a city location.
  12.  
  13. // == Notes ==
  14. // 1) Suggested index queries to set up the search:
  15. // * "CREATE UNIQUE INDEX idx ON locations5 (city, state)"
  16. // * "CREATE INDEX idx ON markers (lat, lng)" <-- note: there should be no UNIQUE here!
  17. //
  18.  
  19. // <customization settings>
  20.  
  21. // Limit search to the initial (input) state?
  22. $limit_to_initial_state = true;
  23.  
  24. // Set the DB search table being used.
  25. $dbtable_search = "markers";
  26.  
  27. // Set the geocoding table to be used.
  28. $dbtable_geocoding = "locations5";
  29.  
  30. // Set the maximum search radius. If nothing is found for the first value, search again with the next value.
  31. $search_radius_array = array(50, 100, 200, 400);
  32.  
  33. // Set the result amount maximum.
  34. $result_amount = 10;
  35.  
  36. // Use google geocoding?
  37. $use_google_geocoding = false;
  38.  
  39. // Set the google api key.
  40. $google_api_key = "hidden";
  41.  
  42. // </customization settings>
  43.  
  44. require "phpsqlsearch_dbinfo.php";
  45.  
  46. // Get the processed Wordpress $_POST variable.
  47. global $post;
  48.  
  49. // Connect to the DB.
  50. connect_to_db ();
  51.  
  52. // Get the page location.
  53. $location = sanitize(get_post_meta($post->ID, 'job_location', true));
  54.  
  55. $space_loc = strrpos ($location, " ");
  56. $initial_city  = sanitize(strtoupper(trim(substr($location, 0, $space_loc))));
  57. $initial_state = sanitize(strtoupper(trim(substr($location, $space_loc+1))));
  58.  
  59. // Try to get the latitude and longitude from the DB. Otherwise, use Google's geocoding API.
  60. $success_test = mysql_query("SELECT lat, lng FROM $dbtable_geocoding WHERE city='$initial_city' AND state='$initial_state'", $link);
  61. if (($success_test !== FALSE) && (mysql_num_rows($success_test) != 0)) {
  62.  $current_row = mysql_fetch_row ($success_test);
  63.  $latitude    = $current_row[0];
  64.  $longitude   = $current_row[1];
  65. } else {
  66.  if ($use_google_geocoding == FALSE) {
  67.   properexit ("This city isn't in the geocoding database!");
  68.  } else {
  69.   $latlong   = call_google_geocoding_api ($location);
  70.   $latitude  = $latlong["latitude"];
  71.   $longitude = $latlong["longitude"];
  72.  }
  73. }
  74.  
  75. // Get entries from the DB that match our radius conditions.
  76. $curlen = count($search_radius_array);
  77. for ($i = 0; $i < $curlen; $i++) {
  78.  if ($limit_to_initial_state === TRUE) $wherestatetring = "WHERE state='$initial_state'";
  79.  $query_text = sprintf("SELECT street, address, city, state, phone, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM $dbtable_search HAVING distance < '%s' $wherestatestring ORDER BY distance LIMIT 0 , " . $result_amount,
  80.   mysql_real_escape_string($latitude)      ,
  81.   mysql_real_escape_string($longitude)     ,
  82.   mysql_real_escape_string($latitude)      ,
  83.   mysql_real_escape_string($search_radius_array[$i]));
  84.  
  85.  $address_list_resource = mysql_query($query_text);
  86.  if (mysql_num_rows($address_list_resource) != 0) break;
  87.  if (!$address_list_resource) properexit("Invalid query: " . mysql_error());
  88. }
  89.  
  90. // Generate html.
  91. $html = generate_html ($address_list_resource, $google_api_key);
  92.  
  93. // Output the page.
  94. output_page ($html);
  95.  
  96. function output_page ($html) {
  97.  get_header();
  98.  
  99. echo '<div id="primary" class="content-area">';
  100. echo '<main id="main" class="site-main" role="main">';
  101.  
  102.  // Add posts and some other random stuff.
  103.  
  104.  if (have_posts()) {
  105.   while (have_posts()) {the_post();};
  106.  }
  107.  
  108. //get_template_part( 'content', 'single' );
  109.  
  110.  echo '<div id="main">';
  111.  echo '<div class="site-main">';
  112.  echo '<div class="hentry">';
  113.  echo '<div class="entry-header">';
  114. the_title( '<h1 class="entry-page-title">', '</h1>' );
  115.  echo '</div>';
  116.  echo '<div class="entry-content">';
  117.  
  118.   the_content();
  119.  
  120.  echo <<<insert
  121.  
  122. <?php if ( in_category( 'coweta-county-ga') ) : ?>
  123. <p>
  124. <center>
  125. <div class="content">
  126. <div class="map">
  127. <div style="padding-right:20px; padding-bottom:20px; float: left;"><img src="https://maps.googleapis.com/maps/" alt="Coweta County" width="350" height="150" /></div>
  128. <div class="text">
  129. <strong>24/7 Best</strong><BR/>
  130. <img src="url" alt="Best in Coweta County, GA" height="31" width="150" style="vertical-align:middle; padding:5px"><BR/>
  131. Adddress<BR/>
  132. Phone: <strong><a href="tel:xxxxx">xxxxx</a></strong><BR>
  133. <img style="vertical-align:middle;padding-right:7px" src="url" alt="County Georgia">Closest<BR>
  134. </div>
  135. </div>
  136. </div>
  137. </center>
  138. </p>
  139. <p><hr></p>
  140. <?php endif; ?>
  141.  
  142. insert;
  143.  
  144.  // Add the locations.
  145.  
  146.  echo '<div align="center">';
  147. echo <<<PREMIUM_AD
  148. <?php if (function_exists ('adinserter')) echo adinserter (11); ?>
  149. <?php if (function_exists ('adinserter')) echo adinserter (2); ?>
  150. <?php if (function_exists ('adinserter')) echo adinserter (4); ?>
  151. <?php if (function_exists ('adinserter')) echo adinserter (15); ?>
  152. PREMIUM_AD;
  153.  echo implode ("n", $html);
  154.  
  155. }
  156.  
  157. function generate_html ($address_list_resource, $google_api_key) {
  158.  $html = array ();
  159.  $html []= '<section id="results">';
  160.  $i = 0;
  161.  while ($row = &mysql_fetch_assoc($address_list_resource)) {
  162.   $street = $row['street'];
  163.   $city   = $row['city'];
  164.   $state  = $row['state'];
  165.   $address = $street . ", " . $city.", ". $state;
  166.  $html []= '<p>';
  167.   $html []= '<section id="location entry '.$i.'" data-name="'.$row['name'].'" data-lng="'.$row['lng'].'" data-lat="'.$row['lat'].'">';
  168.   $html []= '<div class="content">';
  169.   $html []= '<div class="map">';
  170.   $html []= '<div style="padding-right:20px; float: left;"><img src="https://maps.googleapis.com/maps/api/staticmap?size=350x150&key='.$google_api_key.'&markers=size:large%7C'.preg_replace("/#/", "%23", $address).'&sensor=false" width="350" height="150" /></div>';
  171.   $html []= '<div class="text">';
  172.   $html []= '<strong>';
  173.   $html []= $row['name'].' <br/>';
  174.   $html []= '</strong>';
  175.   $html []= $street. ', '.$city. ', '.$state.' <br/>';
  176.   $html []= '<i>';
  177.   $html []= number_format($row['distance'],2).' miles away'; '<br/>';
  178.   $html []= '</i>';    
  179.   $html []= '<br/>';
  180.   $html []= "Phone: <a href='tel:{$row['phone']}'>{$row['phone']}</a><br/>";  
  181.   if(isset($row["url"]) && $row["url"]!="") $html []= '<a href="'.$row['url'].'">More info</a>';
  182.   $html []= '<br/>';
  183.   $html []= '</div>';
  184.   $html []= '</div>';
  185.   $html []= '<hr>';
  186.   $html []= '</p>';
  187.   $html []= '</section>';
  188.   $i += 1;
  189.  }
  190.  $html []= '</section>';
  191.  $html []= '</div><div style="clear:both;"></div>';
  192.  $html []= '<strong>';
  193. $html []= "";
  194.  
  195.  $html []= '</strong>';
  196.  return $html;
  197. }
  198. echo <<<ADD_LISTING
  199. <div align="right"><div style="padding-right:25px"><a href="url" alt="Add Your Business to our Directory"><div style="background-color:#e12727;width:255px;border:0px solid black;padding:3px;"><center><STRONG><font color="white">Add your company</STRONG></font></center></a>
  200. </div></div></div><BR>
  201. ADD_LISTING;
  202. echo do_shortcode("[pt_view id=db60639qko]");
  203. echo '<BR>';
  204. echo (' </div></div>');
  205. echo '</div>';
  206.  echo '</div>';
  207. // Helper functions.
  208.  
  209. function call_google_geocoding_api ($location) {
  210.  // Google geocoding URL.
  211.  $geocoding_url = "https://maps.googleapis.com/maps/api/geocode/json" . "?address=" . urlencode($location) . "&sensor=false";
  212.  
  213.  // Initiate the curl request.
  214.  $xa = curl_init($geocoding_url);
  215.  $opts = array(
  216.   CURLOPT_RETURNTRANSFER => true,
  217.   CURLOPT_HTTPHEADER     => array('Content-type: application/json; charset=utf-8')
  218.  );
  219.  curl_setopt_array($xa, $opts);
  220.  $res = curl_exec($xa);
  221.  
  222.  // JSON-decode the result.
  223.  $res = json_decode($res);
  224.  
  225.  // Get the coordinates.
  226.  return array("latitude" => (float)$res->results[0]->geometry->location->lat, "longitude" => (float)$res->results[0]->geometry->location->lng);
  227. }
  228.  
  229. function properexit ($textstring) {
  230.  global $link;
  231.   if ($link != null) {
  232.   mysql_query("ROLLBACK", $link);
  233.   mysql_query("UNLOCK TABLES", $link);
  234.  }
  235.  echo $textstring;
  236.  exit();
  237. }
  238.  
  239. function remove_numbers ($string) {
  240.  $numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
  241.  $string = str_ireplace($numbers, "", $string);
  242.  return $string;
  243. }
  244.  
  245. function sanitize ($n) {
  246.  if (is_null($n)) return null;
  247.  if(get_magic_quotes_gpc()) {$n = mysql_real_escape_string(stripslashes($n));} else {$n = mysql_real_escape_string($n);}
  248.  return htmlentities($n);
  249. }  
  250.  
  251. function sanitize_array (&$n) {
  252.  foreach ($n as $key => $value) {
  253.   $n[$key] = sanitize($value);
  254.  }
  255. }
  256.  
  257. function cuint ($n) {$n = (int)$n; if (is_null($n)) {return 0;} else {return abs($n);}}
  258. function alpha($n) {if (is_null($n)) return null; return trim(preg_replace("/[^a-zA-Z]/", "", $n));}
  259. function alpha_withextras($n, $extras) {if (is_null($n)) return null; return trim(preg_replace("/[^a-zA-Z".$extras."]/", "", $n));}
  260.  
  261. function mysql_begin () {
  262.  global $link, $mysql_begin_counter;
  263.  if (!isset($mysql_begin_counter)) $mysql_begin_counter = 0;
  264.   $mysql_begin_counter += 1;
  265.  if ($mysql_begin_counter == 1) return mysql_query ("BEGIN");
  266. }
  267.  
  268. function mysql_commit () {
  269.  global $link, $mysql_begin_counter;
  270.  if (!isset($mysql_begin_counter)) $mysql_begin_counter = 0;
  271.  $mysql_begin_counter -= 1;
  272.  if ($mysql_begin_counter == 0) return mysql_query("COMMIT");
  273. }
  274.  
  275. ?>
  276.  
  277.             <?php
  278.                 // If comments are open or we have at least one comment, load up the comment template
  279.                 if ( comments_open() || get_comments_number() ) :
  280.                     comments_template();
  281.                 endif;
  282.             ?>
  283.  
  284.         </main><!-- #main -->
  285.     </div><!-- #primary -->
  286.  
  287.  
  288. <?php get_sidebar(); ?>
  289. <?php get_footer(); ?>
  290.    
  291. <?php if ( in_category( 'dallas-slug') ) : ?>
  292. <p>
  293. custom text to insert
  294. </p>
  295. <?php endif; ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top