PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/job-manager/frontend-jobs.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 257 lines | 193 code | 58 blank | 6 comment | 61 complexity | 25cc335a7a0265fa34563b0035e2ac7a MD5 | raw file
  1. <?php // encoding: UTF-8
  2. function jobman_display_jobs_list( $cat ) {
  3. global $jobman_shortcode_jobs, $jobman_shortcode_all_jobs, $jobman_shortcode_category, $jobman_shortcodes, $jobman_field_shortcodes, $wp_query;
  4. $options = get_option( 'jobman_options' );
  5. $content = '';
  6. $page = get_post( $options['main_page'] );
  7. if( 'all' != $cat ) {
  8. $page->ID = -1;
  9. $page->post_type = 'jobman_joblist';
  10. $page->post_title = __( 'Cape Resorts careers', 'jobman' );
  11. }
  12. if( 'all' != $cat ) {
  13. $jobman_shortcode_category = $category = get_term( $cat, 'jobman_category' );
  14. if( NULL == $category ) {
  15. $cat = 'all';
  16. }
  17. else {
  18. $page->post_title = $category->name;
  19. $page->post_parent = $options['main_page'];
  20. $page->post_name = $category->slug;
  21. }
  22. }
  23. $args = array(
  24. 'post_type' => 'jobman_job',
  25. 'suppress_filters' => false
  26. );
  27. if( ! empty( $options['sort_by'] ) ) {
  28. switch( $options['sort_by'] ) {
  29. case 'title':
  30. $args['orderby'] = 'title';
  31. break;
  32. case 'dateposted':
  33. $args['orderby'] = 'date';
  34. break;
  35. case 'closingdate':
  36. $args['orderby'] = 'meta_value';
  37. $args['meta_key'] = 'displayenddate';
  38. break;
  39. default:
  40. $args['orderby'] = 'meta_value';
  41. $args['meta_key'] = $options['sort_by'];
  42. break;
  43. }
  44. }
  45. if( $options['jobs_per_page'] > 0 ) {
  46. $args['numberposts'] = $options['jobs_per_page'];
  47. $args['posts_per_page'] = $options['jobs_per_page'];
  48. if( array_key_exists( 'page', $wp_query->query_vars ) && $wp_query->query_vars['page'] > 1 )
  49. $args['offset'] = ( $wp_query->query_vars['page'] - 1 ) * $options['jobs_per_page'];
  50. }
  51. else {
  52. $args['numberposts'] = -1;
  53. }
  54. if( in_array( $options['sort_order'], array( 'asc', 'desc' ) ) )
  55. $args['order'] = $options['sort_order'];
  56. else
  57. $args['order'] = 'asc';
  58. if( 'all' != $cat )
  59. $args['jcat'] = $category->slug;
  60. add_filter( 'posts_where', 'jobman_job_live_where' );
  61. add_filter( 'posts_join', 'jobman_job_live_join' );
  62. add_filter( 'posts_distinct', 'jobman_job_live_distinct' );
  63. $jobs = get_posts( $args );
  64. $args['posts_per_page'] = '';
  65. $args['offset'] = '';
  66. $args['numberposts'] = -1;
  67. $jobman_shortcode_all_jobs = get_posts( $args );
  68. remove_filter( 'posts_where', 'jobman_job_live_where' );
  69. remove_filter( 'posts_join', 'jobman_job_live_join' );
  70. remove_filter( 'posts_distinct', 'jobman_job_live_distinct' );
  71. if( $options['user_registration'] ) {
  72. if( 'all' == $cat && $options['loginform_main'] )
  73. $content .= jobman_display_login();
  74. else if( 'all' != $cat && $options['loginform_category'] )
  75. $content .= jobman_display_login();
  76. }
  77. $related_cats = array();
  78. foreach( $jobs as $id => $job ) {
  79. // Get related categories
  80. if( $options['related_categories'] ) {
  81. $categories = wp_get_object_terms( $job->ID, 'jobman_category' );
  82. if( count( $categories ) > 0 ) {
  83. foreach( $categories as $cat ) {
  84. $related_cats[] = $cat->slug;
  85. }
  86. }
  87. }
  88. }
  89. $related_cats = array_unique( $related_cats );
  90. if( $options['related_categories'] && count( $related_cats ) > 0 ) {
  91. $links = array();
  92. foreach( $related_cats as $rc ) {
  93. $cat = get_term_by( 'slug', $rc, 'jobman_category' );
  94. $links[] = '<a href="'. get_term_link( $cat->slug, 'jobman_category' ) . '" title="' . sprintf( __( 'Jobs for %s', 'jobman' ), $cat->name ) . '">' . $cat->name . '</a>';
  95. }
  96. $content .= '<h3>' . __( 'Related Categories', 'jobman' ) . '</h3>';
  97. $content .= implode(', ', $links) . '<br>';
  98. }
  99. $applyform = false;
  100. $data = get_posts( 'post_type=jobman_app_form&numberposts=-1' );
  101. if( count( $data ) > 0 ) {
  102. $applyform = true;
  103. $applypage = $data[0];
  104. $url = get_page_link( $applypage->ID );
  105. //$content .= "<form action='$url' method='post' class='file_form'>";
  106. }
  107. if( count( $jobs ) > 0 ) {
  108. if( 'sticky' == $options['highlighted_behaviour'] )
  109. // Sort the sticky jobs to the top
  110. uasort( $jobs, 'jobman_sort_highlighted_jobs' );
  111. $template = $options['templates']['job_list'];
  112. jobman_add_shortcodes( $jobman_shortcodes );
  113. jobman_add_field_shortcodes( $jobman_field_shortcodes );
  114. $jobman_shortcode_jobs = $jobs;
  115. $content .= do_shortcode( $template );
  116. jobman_remove_shortcodes( array_merge( $jobman_shortcodes, $jobman_field_shortcodes ) );
  117. }
  118. else {
  119. $data = get_posts( 'post_type=jobman_app_form&numberposts=-1' );
  120. if( count( $data > 0 ) )
  121. $applypage = $data[0];
  122. $content .= '<p>';
  123. if( 'all' == $cat || ! isset( $category->term_id ) ) {
  124. $content .= sprintf( __( "We currently don't have any jobs available. Please check back regularly, as we frequently post new jobs. In the meantime, you can also <a href='%s'>send through your résumé</a>, which we'll keep on file.", 'jobman' ), get_page_link( $applypage->ID ) );
  125. }
  126. else {
  127. $url = get_page_link( $applypage->ID );
  128. $structure = get_option( 'permalink_structure' );
  129. if( '' == $structure ) {
  130. $url .= '&amp;c=' . $category->term_id;
  131. }
  132. else {
  133. if( substr( $url, -1 ) == '/' )
  134. $url .= $category->slug . '/';
  135. else
  136. $url .= '/' . $category->slug;
  137. }
  138. $content .= sprintf( __( "We currently don't have any jobs available in this area. Please check back regularly, as we frequently post new jobs. In the mean time, you can also <a href='%s'>send through your résumé</a>, which we'll keep on file, and you can check out the <a href='%s'>jobs we have available in other areas</a>.", 'jobman' ), $url, get_page_link( $options['main_page'] ) );
  139. }
  140. }
  141. $content .= '</p>';
  142. if( $applyform )
  143. //$content .= '</form>';
  144. $page->post_content = $content;
  145. return array( $page );
  146. }
  147. function jobman_sort_highlighted_jobs( $a, $b ) {
  148. $ahighlighted = get_post_meta( $a->ID, 'highlighted', true );
  149. $bhighlighted = get_post_meta( $b->ID, 'highlighted', true );
  150. if( $ahighlighted == $bhighlighted )
  151. return 0;
  152. if( 1 == $ahighlighted )
  153. return -1;
  154. return 1;
  155. }
  156. function jobman_display_job( $job ) {
  157. global $jobman_shortcode_job, $jobman_shortcodes, $jobman_field_shortcodes;
  158. $options = get_option( 'jobman_options' );
  159. $content = '';
  160. if( is_string( $job ) || is_int( $job ) )
  161. $job = get_post( $job );
  162. if( $options['user_registration'] && $options['loginform_job'] )
  163. $content .= jobman_display_login();
  164. if( NULL != $job ) {
  165. $jobmeta = get_post_custom( $job->ID );
  166. $jobdata = array();
  167. foreach( $jobmeta as $key => $value ) {
  168. if( is_array( $value ) )
  169. $jobdata[$key] = $value[0];
  170. else
  171. $jobdata[$key] = $value;
  172. }
  173. }
  174. // Check that the job hasn't expired
  175. if( array_key_exists( 'displayenddate', $jobdata ) && '' != $jobdata['displayenddate'] && strtotime($jobdata['displayenddate']) <= time() )
  176. $job = NULL;
  177. // Check that the job isn't in the future
  178. if( strtotime( $job->post_date ) > time() )
  179. $job = NULL;
  180. if( NULL == $job ) {
  181. $page = get_post( $options['main_page'] );
  182. $page->post_type = 'jobman_job';
  183. $page->post_title = __( 'This job doesn\'t exist', 'jobman' );
  184. $content .= '<p>' . sprintf( __( 'Perhaps you followed an out-of-date link? Please check out the <a href="%s">jobs we have currently available</a>.', 'jobman' ), get_page_link( $options['main_page'] ) ) . '</p>';
  185. $page->post_content = $content;
  186. return array( $page );
  187. }
  188. $template = $options['templates']['job'];
  189. jobman_add_shortcodes( $jobman_shortcodes );
  190. jobman_add_field_shortcodes( $jobman_field_shortcodes );
  191. $jobman_shortcode_job = $job;
  192. $content .= do_shortcode( $template );
  193. jobman_remove_shortcodes( array_merge( $jobman_shortcodes, $jobman_field_shortcodes ) );
  194. $page = $job;
  195. $page->post_title = $options['text']['job_title_prefix'] . $job->post_title;
  196. $page->post_content = $content;
  197. return array( $page );
  198. }
  199. ?>