Don't like ads? PRO users don't see any ads ;-)
Guest

sigh

By: a guest on May 2nd, 2012  |  syntax: PHP  |  size: 16.21 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /**
  3.  * The template for displaying Archive pages.
  4.  *
  5.  * THIS IS THE ONE THAT SHOWS FOR JOBS AND OPPORTUNITIES
  6.  *
  7.  * Used to display archive-type pages if nothing more specific matches a query.
  8.  * For example, puts together date-based pages if no date.php file exists.
  9.  *
  10.  * Learn more: http://codex.wordpress.org/Template_Hierarchy
  11.  *
  12.  * @package WordPress
  13.  * @subpackage Starkers
  14.  * @since Starkers 3.0
  15.  */
  16.  
  17. ?>
  18.  
  19. <?php
  20.  function buildTaxonomyTermOrSQL($checkBoxName, $tM) {
  21.         if (is_array($_POST[$checkBoxName])) {
  22.        
  23.                 foreach ($_POST[$checkBoxName] as $interest) {
  24.                         $terms .= " " . $tM . ".slug = '" . $interest . "' OR ";
  25.                 }
  26.         } else {
  27.                 $terms = "";
  28.         }
  29.        
  30.         return $terms;
  31.  }
  32.  
  33. function taxTerm($checkBoxName,$alias){
  34.         $tM = 'wp_z4azbl_terms';
  35.         $string = " $alias.term_id IN (SELECT term_id FROM wp_z4azbl_terms WHERE ";
  36.         if(is_array($_POST[$checkBoxName])){
  37.                 foreach($_POST[$checkBoxName] as $slug){
  38.                         $string .= "slug = " . "'" . $slug . "' OR ";
  39.                 }
  40.                 $string = substr($string, 0, -3);
  41.         }
  42.         $string .= ") AND ";
  43.         $empty = " $alias.term_id IN (SELECT term_id FROM wp_z4azbl_terms WHERE ) AND ";
  44.         if($string == $empty){
  45.                 $string = "";
  46.         }
  47.         return $string;
  48. }
  49.  
  50. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51.  
  52. if (isset($_POST["searchingJobs"])) {
  53.         //Build job search query
  54.         $termsName = $wpdb->terms;
  55.  
  56.                 ///////////////
  57.                 // All Terms
  58.                 ///////////////
  59.                 $terms = "(" . buildTaxonomyTermOrSQL("interest", $termsName) . buildTaxonomyTermOrSQL("job-type", $termsName) . buildTaxonomyTermOrSQL("experience", $termsName);
  60.                 if (substr($terms, -3) == "OR ") {
  61.                         $terms = substr($terms, 0, -3);
  62.                 }
  63.                 $terms .= ") AND";
  64.  
  65.                 $interests = taxTerm("interest",'wp1');
  66.                 $type = taxTerm("job-type",'wp2');
  67.                 $experience = taxTerm("experience",'wp3');
  68.  
  69.  
  70. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  71.        
  72.         $qry = "SELECT * FROM $wpdb->posts
  73.         LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
  74.         LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  75.         LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  76.         LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
  77.         LEFT JOIN $wpdb->terms wp1 ON(wp1.term_id = $wpdb->term_taxonomy.term_id)
  78.         LEFT JOIN $wpdb->terms wp2 ON(wp2.term_id = $wpdb->term_taxonomy.term_id)
  79.         LEFT JOIN $wpdb->terms wp3 ON(wp3.term_id = $wpdb->term_taxonomy.term_id)";
  80.         if (($_POST["job_latitude"] != "") && ($_POST["radius"] != "X") ) {
  81.                 //add location joins
  82.                 $qry .= "LEFT JOIN $wpdb->postmeta AS latitude ON(
  83.                 $wpdb->posts.ID = latitude.post_id
  84.                 AND latitude.meta_key = 'latitude'
  85.                 )";
  86.                 $qry .= "LEFT JOIN $wpdb->postmeta AS longitude ON(
  87.                 $wpdb->posts.ID = longitude.post_id
  88.                 AND longitude.meta_key = 'longitude'
  89.                 )";
  90.                 $qry .= "LEFT JOIN $wpdb->postmeta AS location ON(
  91.                 $wpdb->posts.ID = location.post_id
  92.                 AND location.meta_key = 'location'
  93.                 )";
  94.         }
  95.         //$qry .= " WHERE " . $terms;
  96.         if ($terms != "() AND") {
  97.                 $qry .= " WHERE $terms $wpdb->term_taxonomy.taxonomy = 'jobtype' AND";
  98.         } else {
  99.                 $qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
  100.         }
  101.  
  102. //              $combined = "";
  103. //              $combined .= $interests . $type . $experience;
  104. //              $combined = substr($combined, 0, -4);
  105. //              $combined .= " AND";
  106. //              if($combined != " AND"){
  107. //                      $qry .= " WHERE $combined $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
  108. //              } else{
  109. //                      $qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
  110. //              }
  111.  
  112. //              if($interests == "" && $type == "" && $experience == ""){
  113. //                      $qry .= " WHERE $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
  114. //              } else {
  115. //                      $qry .= " WHERE $interests $type $experience $wpdb->term_taxonomy.taxonomy = 'jobtype' AND ";
  116. //              }
  117.  
  118.         $qry .= "
  119.         $wpdb->posts.post_status = 'publish'
  120.         AND $wpdb->posts.post_type = 'jobs'
  121.         ";
  122.         //Now check for location fields
  123.         if (($_POST["job_latitude"] != "") && ($_POST["radius"] != "X") ) {
  124.                 $radius = $_POST["radius"];
  125.                 $qry .= " AND ( 3959 * acos( cos( radians(" . $_POST["job_latitude"]  . ") ) * cos( radians( latitude.meta_value ) ) * cos( radians( longitude.meta_value ) - radians(" . $_POST["job_longitude"]  . ") ) + sin( radians(" . $_POST["job_latitude"]  . ") ) * sin( radians( latitude.meta_value ) ) ) ) < " . $_POST["radius"];
  126.                 $qry .= " OR location.meta_value = 'Virtual Office'";
  127.         }
  128.         $qry .= " GROUP BY $wpdb->posts.ID ORDER BY $wpdb->posts.post_date DESC";
  129.         //echo $qry;
  130.         $jobResults = $wpdb->get_results($qry);
  131.        
  132.         ?>
  133.         <?php foreach ($jobResults as $post): ?>
  134.         <?php setup_postdata($post); ?>
  135.        
  136.        
  137.        
  138.         <div class="post_entry">
  139. <?php //echo $interests . $type . $experience; ?>
  140.                         <h4 class="post-title"><a class="title-anchor" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h4>
  141.  
  142.                         <?php  
  143.                                 $location = get_post_meta($post->ID, 'location', TRUE);
  144.                                 $organization = get_post_meta($post->ID, 'organization', TRUE);
  145.                                 $url = get_post_meta($post->ID, 'url', TRUE);
  146.                 $matches = substr($url, 0, 7);
  147.                 if ($matches=='http://')
  148.                 {
  149.                         $url = substr($url, 7);        
  150.                 }
  151.                 else
  152.                 {
  153.                         $matches = substr($url, 0, 8);
  154.                         if ($matches=='https://')
  155.                         $url = substr($url, 8);
  156.                 }
  157.                         ?>
  158.                         <p class="post_meta_date">Posted: <?php echo get_the_date(); ?></p>
  159.                         <div class="post-meta">
  160.                                 <?php if($organization != ''){ ?><p class="post_meta_organization"><?php echo $organization; ?></p><?php } ?>
  161.                                 <?php if($location != ''){ ?><p class="post_meta_location"><?php echo $location; ?></p><?php } ?>
  162.                                 <!-- <?php if($url != ''){ ?><p class="post_meta_url">Website: <a href="http://<?php echo $url; ?>" target="_blank">Click Here</a></p><?php } ?> -->
  163.                                 <p class="post_meta_url"><?php  $sideterms = wp_get_post_terms($post->ID,'jobtype');
  164.                                                 $showterms = array();
  165.                                                 foreach($sideterms as $term){
  166.                                                         if(($term->slug) == 'full-time' || ($term->slug) == 'internship' || ($term->slug) == 'part-time' || ($term->slug) == 'temporarycontract'){
  167.                                                                 $showterms[] = $term->name;
  168.                                                         }
  169.                                                 }
  170.                                                 echo implode(', ', $showterms);
  171.                                 ?></p>
  172.                         </div>
  173.                         <div class="hidden tags<?php $terms = wp_get_post_terms($post->ID,'jobtype'); foreach($terms as $term){echo ' ' . $term->slug;} ?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ' ' . $term->slug;} ?>"></div>
  174.                        
  175.  
  176.         <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
  177.                         <p class="post_excerpt"><?php the_excerpt(); ?><p class="post_categories"><?php
  178.                                 $terms = wp_get_post_terms($post->ID,'jobtype');
  179.                                 $names = array();
  180.                                 foreach($terms as $term){
  181.                                         if(($term->slug) == 'full-time' || ($term->slug) == 'internship' || ($term->slug) == 'part-time' || ($term->slug) == 'temporarycontract'){
  182.                                         }else{ $names[] = $term->name; }
  183.                                 }
  184.                                 echo implode(', ', $names);
  185.                         ?><?php $terms = wp_get_post_terms($post->ID,'opportunitytype'); foreach($terms as $term){echo ', ' . $term->name;} ?>.</p></p>
  186.         <?php else : ?>
  187.                         <div class="category_read_more"><?php the_content( __( 'Read More', 'twentyten' ) ); ?></div>
  188.                         <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
  189.         <?php endif; ?>
  190.                                 <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
  191.  
  192.                 <?php comments_template( '', true ); ?>
  193.                 </div>
  194.                
  195.                
  196.                
  197.          <?php endforeach; ?>
  198.         <?php
  199. } else {
  200.  
  201. get_header(); ?>
  202. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
  203. <script type="text/javascript">
  204. function getUrlVars()
  205. {
  206.     var vars = [], hash;
  207.     var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
  208.     for(var i = 0; i < hashes.length; i++)
  209.     {
  210.         hash = hashes[i].split('=');
  211.         vars.push(hash[0]);
  212.         vars[hash[0]] = hash[1];
  213.     }
  214.     return vars;
  215. }
  216. </script>
  217. <script type="text/javascript">
  218. var geocoder;
  219.  function initialize() {
  220.     geocoder = new google.maps.Geocoder();
  221.   }
  222. initialize();
  223. $(document).ready(function() {
  224. searchJobs();
  225. });
  226.  function initialize() {
  227.     geocoder = new google.maps.Geocoder();
  228.    
  229.   }
  230.  
  231.         function codeAddress() {
  232.                 var address = document.getElementById("zip").value;
  233.                 geocoder.geocode( { 'address': address}, function(results, status) {
  234.                         if (status == google.maps.GeocoderStatus.OK) {
  235.                                 $("#lat")[0].value = results[0].geometry.location.lat();
  236.                                 $("#lng")[0].value = results[0].geometry.location.lng();
  237.                                 loadJobs();
  238.                         } else {
  239.                                 alert("Geocode was not successful for the following reason: " + status);
  240.                         }
  241.                 });
  242.   }
  243.  
  244.         function searchJobs() {
  245.                 //set url query
  246.                 var interests = new Array();
  247.                 $("input[name='interest[]']").each(function(){
  248.                         if($(this).prop('checked')){
  249.                                 interests.push($(this).val());
  250.                         }
  251.                 });
  252.  
  253.                 var types = new Array();
  254.                 $("input[name='job-type[]']").each(function(){
  255.                         if($(this).prop('checked')){
  256.                                 types.push($(this).val());
  257.                         }
  258.                 });
  259.  
  260.                 var experience = new Array();
  261.                 $("input[name='experience[]']").each(function(){
  262.                         if($(this).prop('checked')){
  263.                                 experience.push($(this).val());
  264.                         }
  265.                 });
  266.                 var interestsstring = '', typestring = '', experiencestring = '';
  267.                 if(interests.join("+") != ''){
  268.                         interestsstring = "interests=" + interests.join("+");
  269.                 }
  270.                 if(types.join("+") != ''){
  271.                         if(interestsstring == ''){
  272.                                 typestring = "type=" + types.join("+");
  273.                         }else{
  274.                                 typestring = "&type=" + types.join("+");
  275.                         }
  276.                 }
  277.                 if(experience.join("+") != ''){
  278.                         if(interestsstring == '' && typestring == ''){
  279.                                 experiencestring = "experience=" + experience.join("+");
  280.                         }else{
  281.                                 experiencestring = "&experience=" + experience.join("+");
  282.                         }
  283.                 }
  284.                 var querystring = interestsstring + typestring + experiencestring;
  285.                 window.location.hash = querystring;
  286.  
  287.                 //slide up the div
  288.                 $("#jobListings").slideUp('fast', function() {
  289.                         //geocoding
  290.                         if ($("#zip")[0].value != "" && $("#zip")[0].value != "City, State, Zip, or Address") {
  291.                                 codeAddress();
  292.                         } else {
  293.                                 $(".loader").slideDown('fast');
  294.                                 loadJobs();
  295.                         }
  296.  
  297.                 });
  298.                 return false;
  299.         }
  300.         function loadJobs() {
  301.                 dataString = $("#category_fieldset_jobs").serialize();
  302.                   $.post(window.location, $("#category_fieldset_jobs").serialize(), function(data) {
  303.                         $("#jobListings").html(data);
  304.                         $(".loader").slideUp();
  305.                         $("#jobListings").slideDown();
  306.                         document.getElementById('zip').value == 'City, State, Zip, or Address';
  307.                         $("#lat")[0].value = "";
  308.                         $("#lng")[0].value = "";
  309.                         wrapEntries();
  310.                   });
  311.         }
  312.  
  313.         function wrapEntries() {
  314.                 $('.post_entry').each(function(){
  315.                         var anchor;
  316.                         anchor = $(this).find('.title-anchor').attr('href');
  317.                         $(this).wrap('<a href=\"' + anchor + '\"></a>');
  318.                 });
  319.         }
  320. </script>
  321.                         <div id="page" class="job">
  322.                                         <div id="category_filter">
  323.                                         <form id="category_fieldset_jobs" method="POST" action="" onsubmit="return searchJobs()">
  324.                                                 <div id="filter_left" class="category_filter_content">
  325.                                                         <h2>Interests</h2>
  326.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="academia" />Academia<br />
  327.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="adminassistant" />Admin/Assistant<br />
  328.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="communicationsmarketing" />Communications/Marketing<br />
  329.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="development" />Development<br />
  330.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="filmvideo-production" />Film/Video Production<br />
  331.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="journalism" />Journalism<br />
  332.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="law" />Law<br/>
  333.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="adminmanagement" />Management<br />
  334.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="policy" />Policy<br />
  335.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="web-developmentit" />Web Development/IT<br />
  336.                                                         <input class="filterbox" type="checkbox" name="interest[]" value="other" />Other
  337.                                                 </div>
  338.                                                 <div id="filter_middle" class="category_filter_content">
  339.                                                         <h2>Location</h2>
  340.                                                         Within <select name="radius">
  341.                                                                 <option value="10">10</option>
  342.                                                                 <option value="25">25</option>
  343.                                                                 <option value="50">50</option>
  344.                                                                 <option value="100">100</option>
  345.                                                                 <option value="X">Unlimited</option>
  346.                                                         </select> miles of<br/>
  347.                                                         <input type="text" id="zip" name="zip" onfocus="if(this.value == 'City, State, Zip, or Address') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'City, State, Zip, or Address'; }" value="City, State, Zip, or Address" />
  348.                                                         <h2>Job Type</h2>
  349.                                                         <input class="filterbox" type="checkbox" name="job-type[]" value="full-time" />Full-Time<br />
  350.                                                         <input class="filterbox" type="checkbox" name="job-type[]" value="part-time" />Part-Time<br />
  351.                                                         <input class="filterbox" type="checkbox" name="job-type[]" value="temporarycontract" />Temporary/Contract<br/>
  352.                                                         <input class="filterbox" type="checkbox" name="job-type[]" value="internship" />Internship<br/>
  353.                                                 </div>
  354.                                                 <div id="filter_right" class="category_filter_content">
  355.                                                         <h2>Experience</h2>
  356.                                                         <input class="filterbox" type="checkbox" name="experience[]" value="early-career" />Early-Career<br />
  357.                                                         <input class="filterbox" type="checkbox" name="experience[]" value="mid-career" />Mid-Career<br />
  358.                                                         <input class="filterbox" type="checkbox" name="experience[]     " value="advanced" />Late-Career<br/>
  359.                                                         <input id="filter_submit" type="button" value="FIND" onclick="searchJobs()" />
  360.                                                 </div>
  361.                                                 <div class="clear"></div>
  362.                                                 <input type="hidden" name="searchingJobs" value="Y" />
  363.                                                 <input type="hidden" id="lat" name="job_latitude" value="" />
  364.                                                 <input type="hidden" id="lng" name="job_longitude" value="" />
  365.                                         </form>
  366.                                         </div>
  367.                                 <h1 class="category_head"><img src="<?php bloginfo('template_url') ?>/images/job_icon_small.png" class="header_icon_small" /><p><?php echo post_type_archive_title(); ?></p><a href="<?php bloginfo('url'); ?>/submit-job" class="posting">Post a Job</a></h1>
  368.  
  369. <div class="loader"></div>
  370.  
  371.                                 <?php
  372.                                         $category_description = category_description();
  373.                                         if ( ! empty( $category_description ) )
  374.                                                 echo '' . $category_description . '';
  375.  
  376.                                 /* Run the loop for the category page to output the posts.
  377.                                  * If you want to overload this in a child theme then include a file
  378.                                  * called loop-category.php and that will be used instead.
  379.                                  */
  380.                                  
  381.                                 if (get_post_type() == 'jobs') {
  382.                                         ?>
  383.                                         <div id="jobListings">
  384.                                         </div>
  385.                                         <?php
  386.                                 } else {
  387.                                         get_template_part( 'loop', 'category' );
  388.                                 }
  389.                                 ?>
  390.                         <?php get_sidebar(); ?>
  391.                         </div>
  392.  
  393. <script type="text/javascript">
  394.         var querystring = getUrlVars();
  395.         if(querystring['interests'] != undefined){ var interests = querystring['interests'].split('+'); }
  396.         if(querystring['type'] != undefined){ var type = querystring['type'].split('+'); }
  397.         if(querystring['experience'] != undefined){ var experience = querystring['experience'].split('+'); }
  398.  
  399.         if(interests != undefined){
  400.                 $("input[name='interest[]']").each(function(){
  401.                         for (var i = 0; i < interests.length; i++){
  402.                                 if(interests[i] == $(this).val()){
  403.                                         $(this).prop('checked',true);
  404.                                 }
  405.                         }
  406.                 });
  407.         }
  408.         if(type != undefined){
  409.                 $("input[name='job-type[]']").each(function(){
  410.                         for (var i = 0; i < type.length; i++){
  411.                                 if(type[i] == $(this).val()){
  412.                                         $(this).prop('checked',true);
  413.                                 }
  414.                         }
  415.                 });
  416.         }
  417.         if(experience != undefined){
  418.                 $("input[name='experience[]']").each(function(){
  419.                         for (var i = 0; i < experience.length; i++){
  420.                                 if(experience[i] == $(this).val()){
  421.                                         $(this).prop('checked',true);
  422.                                 }
  423.                         }
  424.                 });
  425.         }
  426. </script>
  427.  
  428. <?php
  429. get_footer();
  430. }
  431. ?>