Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo <<<insert
- <?php if ( in_category( 'dallas-slug') ) : ?>
- <p>
- custom text to insert
- </p>
- <?php endif; ?>
- insert;
- <?php
- // Displays class locations from a city location.
- // == Notes ==
- // 1) Suggested index queries to set up the search:
- // * "CREATE UNIQUE INDEX idx ON locations5 (city, state)"
- // * "CREATE INDEX idx ON markers (lat, lng)" <-- note: there should be no UNIQUE here!
- //
- // <customization settings>
- // Limit search to the initial (input) state?
- $limit_to_initial_state = true;
- // Set the DB search table being used.
- $dbtable_search = "markers";
- // Set the geocoding table to be used.
- $dbtable_geocoding = "locations5";
- // Set the maximum search radius. If nothing is found for the first value, search again with the next value.
- $search_radius_array = array(50, 100, 200, 400);
- // Set the result amount maximum.
- $result_amount = 10;
- // Use google geocoding?
- $use_google_geocoding = false;
- // Set the google api key.
- $google_api_key = "hidden";
- // </customization settings>
- require "phpsqlsearch_dbinfo.php";
- // Get the processed Wordpress $_POST variable.
- global $post;
- // Connect to the DB.
- connect_to_db ();
- // Get the page location.
- $location = sanitize(get_post_meta($post->ID, 'job_location', true));
- $space_loc = strrpos ($location, " ");
- $initial_city = sanitize(strtoupper(trim(substr($location, 0, $space_loc))));
- $initial_state = sanitize(strtoupper(trim(substr($location, $space_loc+1))));
- // Try to get the latitude and longitude from the DB. Otherwise, use Google's geocoding API.
- $success_test = mysql_query("SELECT lat, lng FROM $dbtable_geocoding WHERE city='$initial_city' AND state='$initial_state'", $link);
- if (($success_test !== FALSE) && (mysql_num_rows($success_test) != 0)) {
- $current_row = mysql_fetch_row ($success_test);
- $latitude = $current_row[0];
- $longitude = $current_row[1];
- } else {
- if ($use_google_geocoding == FALSE) {
- properexit ("This city isn't in the geocoding database!");
- } else {
- $latlong = call_google_geocoding_api ($location);
- $latitude = $latlong["latitude"];
- $longitude = $latlong["longitude"];
- }
- }
- // Get entries from the DB that match our radius conditions.
- $curlen = count($search_radius_array);
- for ($i = 0; $i < $curlen; $i++) {
- if ($limit_to_initial_state === TRUE) $wherestatetring = "WHERE state='$initial_state'";
- $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,
- mysql_real_escape_string($latitude) ,
- mysql_real_escape_string($longitude) ,
- mysql_real_escape_string($latitude) ,
- mysql_real_escape_string($search_radius_array[$i]));
- $address_list_resource = mysql_query($query_text);
- if (mysql_num_rows($address_list_resource) != 0) break;
- if (!$address_list_resource) properexit("Invalid query: " . mysql_error());
- }
- // Generate html.
- $html = generate_html ($address_list_resource, $google_api_key);
- // Output the page.
- output_page ($html);
- function output_page ($html) {
- get_header();
- echo '<div id="primary" class="content-area">';
- echo '<main id="main" class="site-main" role="main">';
- // Add posts and some other random stuff.
- if (have_posts()) {
- while (have_posts()) {the_post();};
- }
- //get_template_part( 'content', 'single' );
- echo '<div id="main">';
- echo '<div class="site-main">';
- echo '<div class="hentry">';
- echo '<div class="entry-header">';
- the_title( '<h1 class="entry-page-title">', '</h1>' );
- echo '</div>';
- echo '<div class="entry-content">';
- the_content();
- echo <<<insert
- <?php if ( in_category( 'coweta-county-ga') ) : ?>
- <p>
- <center>
- <div class="content">
- <div class="map">
- <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>
- <div class="text">
- <strong>24/7 Best</strong><BR/>
- <img src="url" alt="Best in Coweta County, GA" height="31" width="150" style="vertical-align:middle; padding:5px"><BR/>
- Adddress<BR/>
- Phone: <strong><a href="tel:xxxxx">xxxxx</a></strong><BR>
- <img style="vertical-align:middle;padding-right:7px" src="url" alt="County Georgia">Closest<BR>
- </div>
- </div>
- </div>
- </center>
- </p>
- <p><hr></p>
- <?php endif; ?>
- insert;
- // Add the locations.
- echo '<div align="center">';
- echo <<<PREMIUM_AD
- <?php if (function_exists ('adinserter')) echo adinserter (11); ?>
- <?php if (function_exists ('adinserter')) echo adinserter (2); ?>
- <?php if (function_exists ('adinserter')) echo adinserter (4); ?>
- <?php if (function_exists ('adinserter')) echo adinserter (15); ?>
- PREMIUM_AD;
- echo implode ("n", $html);
- }
- function generate_html ($address_list_resource, $google_api_key) {
- $html = array ();
- $html []= '<section id="results">';
- $i = 0;
- while ($row = &mysql_fetch_assoc($address_list_resource)) {
- $street = $row['street'];
- $city = $row['city'];
- $state = $row['state'];
- $address = $street . ", " . $city.", ". $state;
- $html []= '<p>';
- $html []= '<section id="location entry '.$i.'" data-name="'.$row['name'].'" data-lng="'.$row['lng'].'" data-lat="'.$row['lat'].'">';
- $html []= '<div class="content">';
- $html []= '<div class="map">';
- $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>';
- $html []= '<div class="text">';
- $html []= '<strong>';
- $html []= $row['name'].' <br/>';
- $html []= '</strong>';
- $html []= $street. ', '.$city. ', '.$state.' <br/>';
- $html []= '<i>';
- $html []= number_format($row['distance'],2).' miles away'; '<br/>';
- $html []= '</i>';
- $html []= '<br/>';
- $html []= "Phone: <a href='tel:{$row['phone']}'>{$row['phone']}</a><br/>";
- if(isset($row["url"]) && $row["url"]!="") $html []= '<a href="'.$row['url'].'">More info</a>';
- $html []= '<br/>';
- $html []= '</div>';
- $html []= '</div>';
- $html []= '<hr>';
- $html []= '</p>';
- $html []= '</section>';
- $i += 1;
- }
- $html []= '</section>';
- $html []= '</div><div style="clear:both;"></div>';
- $html []= '<strong>';
- $html []= "";
- $html []= '</strong>';
- return $html;
- }
- echo <<<ADD_LISTING
- <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>
- </div></div></div><BR>
- ADD_LISTING;
- echo do_shortcode("[pt_view id=db60639qko]");
- echo '<BR>';
- echo (' </div></div>');
- echo '</div>';
- echo '</div>';
- // Helper functions.
- function call_google_geocoding_api ($location) {
- // Google geocoding URL.
- $geocoding_url = "https://maps.googleapis.com/maps/api/geocode/json" . "?address=" . urlencode($location) . "&sensor=false";
- // Initiate the curl request.
- $xa = curl_init($geocoding_url);
- $opts = array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPHEADER => array('Content-type: application/json; charset=utf-8')
- );
- curl_setopt_array($xa, $opts);
- $res = curl_exec($xa);
- // JSON-decode the result.
- $res = json_decode($res);
- // Get the coordinates.
- return array("latitude" => (float)$res->results[0]->geometry->location->lat, "longitude" => (float)$res->results[0]->geometry->location->lng);
- }
- function properexit ($textstring) {
- global $link;
- if ($link != null) {
- mysql_query("ROLLBACK", $link);
- mysql_query("UNLOCK TABLES", $link);
- }
- echo $textstring;
- exit();
- }
- function remove_numbers ($string) {
- $numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
- $string = str_ireplace($numbers, "", $string);
- return $string;
- }
- function sanitize ($n) {
- if (is_null($n)) return null;
- if(get_magic_quotes_gpc()) {$n = mysql_real_escape_string(stripslashes($n));} else {$n = mysql_real_escape_string($n);}
- return htmlentities($n);
- }
- function sanitize_array (&$n) {
- foreach ($n as $key => $value) {
- $n[$key] = sanitize($value);
- }
- }
- function cuint ($n) {$n = (int)$n; if (is_null($n)) {return 0;} else {return abs($n);}}
- function alpha($n) {if (is_null($n)) return null; return trim(preg_replace("/[^a-zA-Z]/", "", $n));}
- function alpha_withextras($n, $extras) {if (is_null($n)) return null; return trim(preg_replace("/[^a-zA-Z".$extras."]/", "", $n));}
- function mysql_begin () {
- global $link, $mysql_begin_counter;
- if (!isset($mysql_begin_counter)) $mysql_begin_counter = 0;
- $mysql_begin_counter += 1;
- if ($mysql_begin_counter == 1) return mysql_query ("BEGIN");
- }
- function mysql_commit () {
- global $link, $mysql_begin_counter;
- if (!isset($mysql_begin_counter)) $mysql_begin_counter = 0;
- $mysql_begin_counter -= 1;
- if ($mysql_begin_counter == 0) return mysql_query("COMMIT");
- }
- ?>
- <?php
- // If comments are open or we have at least one comment, load up the comment template
- if ( comments_open() || get_comments_number() ) :
- comments_template();
- endif;
- ?>
- </main><!-- #main -->
- </div><!-- #primary -->
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
- <?php if ( in_category( 'dallas-slug') ) : ?>
- <p>
- custom text to insert
- </p>
- <?php endif; ?>
Add Comment
Please, Sign In to add comment