PageRenderTime 23ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Project/faci-qsoft/wp-content/themes/noo-jobmonster/framework/job/job-template.php

https://gitlab.com/hop23typhu/list-theme
PHP | 436 lines | 372 code | 51 blank | 13 comment | 70 complexity | 23f39b23e651cea5e91fc30e7942a201 MD5 | raw file
  1. <?php
  2. if( !function_exists( 'jm_job_template_loader' ) ) :
  3. function jm_job_template_loader( $template ) {
  4. if ( is_post_type_archive( 'noo_job' )
  5. || is_tax( 'job_category' )
  6. || is_tax( 'job_type' )
  7. || is_tax( 'job_tag' )
  8. || is_tax( 'job_location' ) ) {
  9. $template = locate_template( 'archive-noo_job.php' );
  10. }
  11. return $template;
  12. }
  13. add_filter( 'template_include', 'jm_job_template_loader' );
  14. endif;
  15. if( !function_exists( 'jm_job_post_class' ) ) :
  16. function jm_job_post_class($output) {
  17. $post_id = get_the_ID();
  18. if( 'noo_job' == get_post_type($post_id) ) {
  19. if( 'yes' == noo_get_post_meta( $post_id, '_featured', '' ) ) {
  20. $output[] = 'featured-job';
  21. }
  22. }
  23. return $output;
  24. }
  25. add_filter('post_class', 'jm_job_post_class');
  26. endif;
  27. if( !function_exists( 'jm_job_social_media' ) ) :
  28. function jm_job_social_media() {
  29. if( !is_singular( 'noo_job' ) ) return;
  30. // Facebook media
  31. if( noo_get_option('noo_job_social_facebook', true ) ) {
  32. $job_id = get_the_ID();
  33. $thumbnail_id = '';
  34. if( jm_get_job_setting( 'cover_image','yes') == 'yes' ) {
  35. $thumbnail_id = noo_get_post_meta($job_id, '_cover_image', '');
  36. }
  37. if( empty( $thumbnail_id ) ) {
  38. $employer_id = get_post_field( 'post_author', $job_id );
  39. $company_id = jm_get_job_company( $job_id );
  40. noo_get_post_meta($company_id, '_logo', '');
  41. }
  42. $social_share_img = wp_get_attachment_url( $thumbnail_id, 'full');
  43. if( !empty( $social_share_img ) ) :
  44. ?>
  45. <meta property="og:image" content="<?php echo $social_share_img; ?>"/>
  46. <meta property="og:image:secure_url" content="<?php echo $social_share_img; ?>" />
  47. <?php
  48. endif;
  49. }
  50. }
  51. add_filter('wp_head', 'jm_job_social_media');
  52. endif;
  53. if( !function_exists( 'jm_job_loop' ) ) :
  54. function jm_job_loop( $args = '' ) {
  55. $defaults = array(
  56. 'paginate' =>'normal',
  57. 'class' => '',
  58. 'item_class' =>'loadmore-item',
  59. 'query' => '',
  60. 'title_type' =>'text',
  61. 'title' => '',
  62. 'pagination' => 1,
  63. 'excerpt_length' =>30,
  64. 'posts_per_page' =>'',
  65. 'ajax_item' =>false,
  66. 'featured' =>'recent',
  67. 'no_content' =>'text',
  68. 'display_style' => 'list',
  69. 'list_job_meta' => array(),
  70. 'paginate_data' => array(),
  71. 'show_view_more' => 'yes',
  72. 'show_autoplay' => 'on'
  73. );
  74. $loop_args = wp_parse_args($args,$defaults);
  75. extract($loop_args);
  76. global $wp_query;
  77. if(!empty($loop_args['query'])) {
  78. $wp_query = $loop_args['query'];
  79. }
  80. $content_meta = array();
  81. $content_meta['show_company'] = noo_get_option('noo_jobs_show_company_name', true);
  82. $content_meta['show_type'] = noo_get_option('noo_jobs_show_job_type', true);
  83. $content_meta['show_location'] = noo_get_option('noo_jobs_show_job_location', true);
  84. $content_meta['show_date'] = noo_get_option('noo_jobs_show_job_date', true);
  85. $content_meta['show_closing_date'] = noo_get_option('noo_jobs_show_job_closing', true);
  86. $content_meta['show_category'] = noo_get_option('noo_jobs_show_job_category', false);
  87. $list_job_meta = array_merge($content_meta, $list_job_meta);
  88. $paginate_data = apply_filters( 'noo-job-loop-paginate-data', $paginate_data, $loop_args );
  89. if( $display_style == 'slider' ) {
  90. $class .= ' slider';
  91. $paginate = '';
  92. }
  93. $item_class = array($item_class);
  94. $item_class[] ='noo_job';
  95. ob_start();
  96. if( $display_style !== 'slider' ) {
  97. include(locate_template("layouts/noo_job-loop.php"));
  98. } else {
  99. include(locate_template("layouts/noo_job-slider.php"));
  100. }
  101. echo ob_get_clean();
  102. wp_reset_postdata();
  103. wp_reset_query();
  104. }
  105. endif;
  106. if( !function_exists( 'jm_job_detail' ) ) :
  107. function jm_job_detail( $query=null, $in_preview=false ) {
  108. if(empty($query)){
  109. global $wp_query;
  110. $query = $wp_query;
  111. }
  112. while ($query->have_posts()): $query->the_post(); global $post;
  113. // Job's social info
  114. $job_id = $post->ID;
  115. $facebook = noo_get_post_meta( $job_id, "_company_facebook", '' );
  116. $twitter = noo_get_post_meta( $job_id, "_company_twitter", '' );
  117. $google_plus = noo_get_post_meta( $job_id, "_company_google_plus", '' );
  118. $linkedin = noo_get_post_meta( $job_id, "_company_linkedin", '' );
  119. $pinterest = noo_get_post_meta( $job_id, "_company_pinterest", '' );
  120. $company_id = jm_get_job_company($post);
  121. ob_start();
  122. if( !$in_preview ) {
  123. include(locate_template("layouts/noo_job-detail.php"));
  124. } else {
  125. include(locate_template("layouts/noo_job-preview.php"));
  126. }
  127. echo ob_get_clean();
  128. endwhile;
  129. wp_reset_query();
  130. }
  131. endif;
  132. if( !function_exists( 'jm_the_job_meta' ) ) :
  133. function jm_the_job_meta($args = '', $job = null) {
  134. $defaults=array(
  135. 'show_company'=>true,
  136. 'show_type'=>true,
  137. 'show_location'=>true,
  138. 'show_date'=>true,
  139. 'show_closing_date'=>false,
  140. 'show_category'=>false,
  141. 'job_id'=>'',
  142. 'schema'=>false
  143. );
  144. $args = wp_parse_args($args,$defaults);
  145. if( empty( $job ) || !is_object( $job ) ) {
  146. $job = get_post(get_the_ID());
  147. }
  148. $job_id = $job->ID;
  149. $html = array();
  150. $html[] = '<p class="content-meta">';
  151. // Company Name
  152. if( $args['show_company'] ) {
  153. $company_id = jm_get_job_company($job);
  154. if( !empty( $company_id ) ) {
  155. $html[] = '<span class="job-company"> <a href="'.get_permalink($company_id).'">' . get_the_title( $company_id ) . '</a></span>';
  156. }
  157. }
  158. // Job Type
  159. if( $args['show_type'] ) {
  160. $type = jm_get_job_type( $job_id );
  161. if( !empty( $type ) ) {
  162. $schema = $args['schema'] ? ' employmentType="' . $type->name . '"' : '';
  163. $html[] = '<span class="job-type"' . $schema . '><a href="'.get_term_link($type,'job_type').'" style="color: '.$type->color.'"><i class="fa fa-bookmark"></i>' .$type->name. '</a></span>';
  164. }
  165. }
  166. // Job Location
  167. $locations_html = '';
  168. $separator = ', ';
  169. if( $args['show_location'] ) {
  170. $locations = get_the_terms( $job_id, 'job_location' );
  171. if( !empty( $locations ) && !is_wp_error( $locations ) ) {
  172. foreach ($locations as $location) {
  173. $schema = $args['schema'] ? ' name="' . $location->name . '"' : '';
  174. $locations_html .= '<a href="' . get_term_link($location->term_id,'job_location') . '"' . $schema . '><em>' . $location->name . '</em></a>' . $separator;
  175. }
  176. $schema = $args['schema'] ? ' itemscope itemtype="http://schema.org/LocalBusiness"' : '';
  177. $html[] = '<span class="job-location"' . $schema . '>';
  178. $html[] = '<i class="fa fa-map-marker"></i>';
  179. $html[] = trim($locations_html, $separator);
  180. $html[] = '</span>';
  181. }
  182. }
  183. // Date
  184. if( $args['show_date'] || $args['show_closing_date'] ) {
  185. $html[] = '<span class="job-date">';
  186. $html[] = '<time class="entry-date" datetime="' . esc_attr(get_the_date('c', $job_id)) . '">';
  187. $html[] = '<i class="fa fa-calendar"></i>';
  188. if( $args['show_date'] ) {
  189. $schema = $args['schema'] ? ' itemprop="datePosted"' : '';
  190. $html[] = '<span' . $schema . '>';
  191. $html[] = esc_html(get_the_date(get_option('date_format'), $job_id));
  192. $html[] = '</span>';
  193. }
  194. $separator = ' - ';
  195. if( $args['show_closing_date'] ) {
  196. $closing_date = noo_get_post_meta($job_id, '_closing', '');
  197. $closing_date = is_numeric( $closing_date ) ? $closing_date : strtotime( $closing_date );
  198. if( !empty( $closing_date ) ) {
  199. $html[] = '<span>';
  200. $html[] = ( $args['show_date'] ? $separator : '' ) . esc_html( date_i18n( get_option('date_format'), $closing_date ) );
  201. $html[] = '</span>';
  202. }
  203. }
  204. $html[] = '</time>';
  205. $html[] = '</span>';
  206. }
  207. // Category
  208. $categories_html = '';
  209. $separator = ' - ';
  210. if( $args['show_category'] ) {
  211. $categories = get_the_terms( $job_id, 'job_category' );
  212. if( !empty( $categories ) && !is_wp_error( $categories ) ) {
  213. foreach ($categories as $category) {
  214. $categories_html .= '<a href="' . get_term_link($category->term_id, 'job_category') . '" title="' . esc_attr(sprintf(__("View all jobs in: &ldquo;%s&rdquo;", 'noo') , $category->name)) . '">' . ' ' . $category->name . '</a>' . $separator;
  215. }
  216. $schema = $args['schema'] ? ' itemprop="occupationalCategory"' : '';
  217. $html[] = '<span class="job-category"' . $schema . '>';
  218. $html[] = '<i class="fa fa-folder"></i>';
  219. $html[] = trim($categories_html, $separator);
  220. $html[] = '</span>';
  221. }
  222. }
  223. if ( is_singular( 'noo_job' ) ) :
  224. // -- Add button print
  225. $html[] = '<span>';
  226. $html[] = '<a href="javascript:void(0)" onclick="return window.print();"><i class="fa fa-print"></i> ' . __('Print', 'noo'). '</a>';
  227. $html[] = '</span>';
  228. endif;
  229. echo implode($html, "\n");
  230. }
  231. endif;
  232. if( !function_exists( 'jm_the_job_tag' ) ) :
  233. function jm_the_job_tag( $job = null ) {
  234. if( empty( $job ) || !is_object( $job ) ) {
  235. $job = get_post(get_the_ID());
  236. }
  237. $job_id = $job->ID;
  238. $html = array();
  239. $tags = get_the_terms( $job_id, 'job_tag' );
  240. if( !empty( $tags ) ) {
  241. $html[] = '<div class="entry-tags">';
  242. $html[] = '<span><i class="fa fa-tag"></i></span>';
  243. foreach ($tags as $tag) {
  244. $html[] = '<a href="' . get_term_link($tag->term_id, 'job_tag') . '" title="' . esc_attr(sprintf(__("View all jobs in: &ldquo;%s&rdquo;", 'noo') , $tag->name)) . '">' . ' ' . $tag->name . '</a>';
  245. }
  246. $html[] = '</div>';
  247. }
  248. echo implode($html, "\n");
  249. }
  250. endif;
  251. if( !function_exists( 'jm_the_job_social' ) ) :
  252. function jm_the_job_social( $job_id = null, $title = '' ) {
  253. if( !noo_get_option('noo_job_social', true) ) {
  254. return;
  255. }
  256. $job_id = (null === $job_id) ? get_the_ID() : $job_id;
  257. if( get_post_type($job_id) != 'noo_job' ) return;
  258. $facebook = noo_get_option('noo_job_social_facebook', true );
  259. $twitter = noo_get_option('noo_job_social_twitter', true );
  260. $google = noo_get_option('noo_job_social_google', true );
  261. $pinterest = noo_get_option('noo_job_social_pinterest', true );
  262. $linkedin = noo_get_option('noo_job_social_linkedin', true );
  263. $share_url = urlencode( get_permalink() );
  264. $share_title = urlencode( get_the_title() );
  265. $share_source = urlencode( get_bloginfo( 'name' ) );
  266. $share_content = urlencode( get_the_content() );
  267. $share_media = wp_get_attachment_thumb_url( get_post_thumbnail_id() );
  268. $popup_attr = 'resizable=0, toolbar=0, menubar=0, status=0, location=0, scrollbars=0';
  269. $html = array();
  270. if ( $facebook || $twitter || $google || $pinterest || $linkedin ) {
  271. $html[] = '<div class="job-social clearfix">';
  272. $html[] = '<span class="noo-social-title">';
  273. $html[] = empty( $title ) ? __("Share this job",'noo') : $title;
  274. $html[] = '</span>';
  275. if($facebook) {
  276. $html[] = '<a href="#share" class="noo-icon fa fa-facebook"'
  277. . ' title="' . __( 'Share on Facebook', 'noo' ) . '"'
  278. . ' onclick="window.open('
  279. . "'http://www.facebook.com/sharer.php?u={$share_url}&amp;t={$share_title}','popupFacebook','width=650,height=270,{$popup_attr}');"
  280. . ' return false;">';
  281. $html[] = '</a>';
  282. }
  283. if($twitter) {
  284. $html[] = '<a href="#share" class="noo-icon fa fa-twitter"'
  285. . ' title="' . __( 'Share on Twitter', 'noo' ) . '"'
  286. . ' onclick="window.open('
  287. . "'https://twitter.com/intent/tweet?text={$share_title}&amp;url={$share_url}','popupTwitter','width=500,height=370,{$popup_attr}');"
  288. . ' return false;">';
  289. $html[] = '</a>';
  290. }
  291. if($google) {
  292. $html[] = '<a href="#share" class="noo-icon fa fa-google-plus"'
  293. . ' title="' . __( 'Share on Google+', 'noo' ) . '"'
  294. . ' onclick="window.open('
  295. . "'https://plus.google.com/share?url={$share_url}','popupGooglePlus','width=650,height=226,{$popup_attr}');"
  296. . ' return false;">';
  297. $html[] = '</a>';
  298. }
  299. if($pinterest) {
  300. $html[] = '<a href="#share" class="noo-icon fa fa-pinterest"'
  301. . ' title="' . __( 'Share on Pinterest', 'noo' ) . '"'
  302. . ' onclick="window.open('
  303. . "'http://pinterest.com/pin/create/button/?url={$share_url}&amp;media={$share_media}&amp;description={$share_title}','popupPinterest','width=750,height=265,{$popup_attr}');"
  304. . ' return false;">';
  305. $html[] = '</a>';
  306. }
  307. if($linkedin) {
  308. $html[] = '<a href="#share" class="noo-icon fa fa-linkedin"'
  309. . ' title="' . __( 'Share on LinkedIn', 'noo' ) . '"'
  310. . ' onclick="window.open('
  311. . "'http://www.linkedin.com/shareArticle?mini=true&amp;url={$share_url}&amp;title={$share_title}&amp;source={$share_source}','popupLinkedIn','width=610,height=480,{$popup_attr}');"
  312. . ' return false;">';
  313. $html[] = '</a>';
  314. }
  315. $html[] = '</div>'; // .noo-social.social-share
  316. }
  317. echo implode("\n", $html);
  318. }
  319. endif;
  320. if( !function_exists( 'jm_related_jobs' ) ) :
  321. function jm_related_jobs( $job_id, $title = '' ) {
  322. global $wp_query;
  323. // -- args query
  324. // $terms = get_the_terms( $post->ID , 'noo_job');
  325. $args = array(
  326. 'post_type' => 'noo_job',
  327. 'post_status' => 'publish',
  328. // 'tag__in' => array($first_tag),
  329. 'posts_per_page' => (int) noo_get_option( 'noo_job_related_num', 3 ),
  330. 'post__not_in' => array($job_id)
  331. );
  332. // -- tax_query
  333. $job_categorys = get_the_terms( $job_id, 'job_category' );
  334. $job_types = get_the_terms( $job_id, 'job_type' );
  335. $job_locations = get_the_terms( $job_id, 'job_location' );
  336. $args['tax_query'] = array( 'relation' => 'AND' );
  337. if ( $job_categorys ) {
  338. $term_job_category = array();
  339. foreach ($job_categorys as $job_category) {
  340. $term_job_category = array_merge( $term_job_category, (array) $job_category->slug );
  341. }
  342. $args['tax_query'][] = array(
  343. 'taxonomy' => 'job_category',
  344. 'field' => 'slug',
  345. 'terms' => $term_job_category
  346. );
  347. }
  348. if ( $job_types ) {
  349. $term_job_type = array();
  350. foreach ($job_types as $job_type) {
  351. $term_job_type = array_merge( $term_job_type, (array) $job_type->slug );
  352. }
  353. $args['tax_query'][] = array(
  354. 'taxonomy' => 'job_type',
  355. 'field' => 'slug',
  356. 'terms' => $term_job_type
  357. );
  358. }
  359. if( $job_locations ) {
  360. $term_job_location = array();
  361. foreach ($job_locations as $job_location) {
  362. $term_job_location = array_merge( $term_job_location, (array) $job_location->slug );
  363. }
  364. $args['tax_query'][] = array(
  365. 'taxonomy' => 'job_location',
  366. 'field' => 'slug',
  367. 'terms' => $term_job_location
  368. );
  369. }
  370. // --- new query
  371. $wp_query = new WP_Query( $args );
  372. $loop_args = array(
  373. 'title' => $title,
  374. 'paginate' =>null,
  375. 'class' =>'related-jobs hidden-print',
  376. 'item_class' =>'',
  377. 'query' => $wp_query,
  378. 'pagination' => false,
  379. 'ajax_item' => null,
  380. 'no_content' =>'none',
  381. 'display_style' => '',
  382. );
  383. jm_job_loop( $loop_args );
  384. }
  385. endif;