Skip to content

Commit

Permalink
FIX: url filtering issue in block
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinjohn22 committed Dec 26, 2024
2 parents 5ac4394 + 05d23ae commit 53203a5
Show file tree
Hide file tree
Showing 12 changed files with 2,285 additions and 59 deletions.
71 changes: 51 additions & 20 deletions admin/templates/meta/resume-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,67 @@
do_action( 'awsm_resume_preview_mb_init', $post->ID );
?>
<div class="awsm-resume-preview">
<?php
<?php
$awsm_attachment_id = get_post_meta( $post->ID, 'awsm_attachment_id', true );
$attachment_url = wp_get_attachment_url( intval( $awsm_attachment_id ) );
if ( $attachment_url ) :
$file_extension = strtolower( pathinfo( $attachment_url, PATHINFO_EXTENSION ) );

// Supported office formats
$supported_office_formats = array(
'doc', 'docx', // Word documents
'ppt', 'pptx', // PowerPoint presentations
'xls', 'xlsx' // Excel spreadsheets
);

// Formats supported by Google Docs Viewer
$google_docs_formats = array(
'csv', // CSV files
'odt', 'ods', 'odp' // OpenDocument formats
);

// Supported image formats
$supported_image_formats = array(
'jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp' // Common image formats
);

?>
<div class="awsm-document-preview">
<?php if ( $file_extension === 'pdf' ) : ?>
<iframe
src="<?php echo esc_url( $attachment_url ); ?>"
style="width: 100%; height: 400px; border: none;"
frameborder="0">
</iframe>
<?php elseif ( in_array( $file_extension, array( 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx' ) ) ) : ?>
<iframe
src="<?php echo esc_url( 'https://view.officeapps.live.com/op/embed.aspx?src=' . urlencode( $attachment_url ) ); ?>"
style="width: 100%; height: 400px; border: none;"
frameborder="0">
</iframe>
<?php else : ?>
<div class="awsm-preview-unsupported">
<h2><strong><?php esc_html_e( 'This file type cannot be previewed. Please download the file to view it.', 'wp-job-openings' ); ?></strong></h2>
</div>
<?php endif; ?>
<iframe
src="<?php echo esc_url( $attachment_url ); ?>"
style="width: 100%; height: 400px; border: none;"
frameborder="0">
</iframe>
<?php elseif ( in_array( $file_extension, $supported_office_formats ) ) : ?>
<iframe
src="<?php echo esc_url( 'https://view.officeapps.live.com/op/embed.aspx?src=' . urlencode( $attachment_url ) ); ?>"
style="width: 100%; height: 400px; border: none;"
frameborder="0">
</iframe>
<?php elseif ( in_array( $file_extension, $google_docs_formats ) ) : ?>
<iframe
src="https://docs.google.com/viewer?embedded=true&url=<?php echo urlencode( $attachment_url ); ?>"
style="width: 100%; height: 400px; border: none;"
frameborder="0">
</iframe>
<?php elseif ( in_array( $file_extension, $supported_image_formats ) ) : ?>
<img
src="<?php echo esc_url( $attachment_url ); ?>"
style="width: 100%; height: auto; border: none;"
alt="<?php echo esc_attr( basename( $attachment_url ) ); ?>">
<?php else : ?>
<div class="awsm-preview-unsupported">
<h2><strong><?php esc_html_e( 'This file type cannot be previewed. Please download the file to view it.', 'wp-job-openings' ); ?></strong></h2>
</div>
<?php endif; ?>
</div>
<?php else : ?>
<div class="awsm-resume-none">
<h2><strong><?php esc_html_e( 'No resume to preview. File not found!', 'wp-job-openings' ); ?></strong></h2>
</div>
<?php
endif;
?>
<?php
endif;
?>

</div>
887 changes: 886 additions & 1 deletion blocks/build/index-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blocks/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-server-side-render'), 'version' => '578da28cf0a1eeb580d5');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-server-side-render'), 'version' => '433675ab56dc3fb8c616');
774 changes: 773 additions & 1 deletion blocks/build/style-index-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blocks/build/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '6de16102ce61bdc5fdfe');
<?php return array('dependencies' => array(), 'version' => 'a75d07c7a107b68260a6');
443 changes: 442 additions & 1 deletion blocks/build/view.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions blocks/build/view.js.map

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions blocks/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ jQuery(function($) {
var hide_expired_jobs = $wrapper.data('awsm-hide-expired-jobs');
var other_options = $wrapper.data('awsm-other-options');
/* end */

$rootWrapper.find('.awsm-b-filter-item').each(function() {
var currentLoopSpec = $(this).data('filter');
console.log($(this).data('filter'));

var searchParams = new URLSearchParams(document.location.search);
var currentSpecQueryVal = searchParams.get(currentLoopSpec);
var $currentOption = $(this).find('.awsm-b-filter-option');

if ($currentOption.val().length === 0 && currentSpecQueryVal && currentSpecQueryVal.length > 0) {
formData.forEach(function(item) {
if (item.name === $currentOption.attr('name')) {
item.value = '-1';
}
});
}
});

formData.push({
name: 'listings_per_page',
value: listings
Expand Down Expand Up @@ -151,17 +169,6 @@ jQuery(function($) {
awsmJobFilters($rootWrapper);
}

if ($(rootWrapperSelector).length > 0) {
$(rootWrapperSelector).each(function() {
var $currentWrapper = $(this);
var $filterForm = $currentWrapper.find(filterSelector + ' form');
if (awsmJobsPublic.is_search.length > 0 || filterCheck($filterForm)) {
triggerFilter = true;
awsmJobFilters($currentWrapper);
}
});
}

var updateQuery = function(key, value, url) {
url = typeof url !== 'undefined' ? url : currentUrl;
url = url.split('?')[0];
Expand Down Expand Up @@ -200,13 +207,21 @@ jQuery(function($) {
}
};

if ($('.awsm-job-no-more-jobs-get').length > 0) {
$('.awsm-b-job-listings').hide();
$('.awsm-job-no-more-jobs-get').slice(1).hide();
}

$(filterSelector + ' .awsm-b-filter-option').on('change', function(e) {
e.preventDefault();
var $elem = $(this);
var $selected = $elem.find('option:selected');
var $rootWrapper = $elem.parents(rootWrapperSelector);
var currentSpec = $elem.parents('.awsm-b-filter-item').data('filter');
var slug = $selected.data('slug');
if ($('.awsm-b-job-listings').length > 0) {
$rootWrapper.find('.awsm-job-no-more-jobs-get').hide();
}
slug = typeof slug !== 'undefined' ? slug : '';
setPaginationBase($rootWrapper, currentSpec, slug);
if (awsmJobsPublic.deep_linking.spec) {
Expand Down
13 changes: 8 additions & 5 deletions inc/class-awsm-job-openings-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,22 +448,25 @@ public function awsm_block_posts_filters() {
// phpcs:enable
}

public static function awsm_block_job_query_args( $filters = array(), $attributes = array() ) {
public static function awsm_block_job_query_args( $filters = array(), $attributes = array(), $is_term_or_slug = array() ) {
$args = array();
if ( is_tax() ) {
$q_obj = get_queried_object();
$taxonomy = $q_obj->taxonomy;
$term_id = $q_obj->term_id;
$filters = array( $taxonomy => $term_id );
$is_term_or_slug[ $taxonomy ] = 'term_id';
}


if ( ! empty( $filters ) ) {
foreach ( $filters as $taxonomy => $term_id ) {
if ( ! empty( $term_id ) ) {
foreach ( $filters as $taxonomy => $value ) {
if ( ! empty( $value ) ) {
$field_type = isset( $is_term_or_slug[ $taxonomy ] ) ? $is_term_or_slug[ $taxonomy ] : 'term_id';
$spec = array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $term_id,
'field' => $field_type,
'terms' => (array) $value,
);
$args['tax_query'][] = $spec;
}
Expand Down
55 changes: 54 additions & 1 deletion inc/template-functions-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,62 @@ function awsm_block_job_filters_explode( $filter_data ) {
}
}

if ( ! function_exists( 'get_block_filtered_job_terms' ) ) {
function get_block_filtered_job_terms( $attributes ) {
$filter_suffix = '_spec';
$filters = explode(',', $attributes["filter_options"]);
$filtered_terms = array();

error_log( json_encode( 'enters get_block_filtered_job_terms', JSON_PRETTY_PRINT ) );

if ( ! empty( $filters ) ) {
foreach ( $filters as $filter ) {
$current_filter_key = str_replace( '-', '__', $filter ) . $filter_suffix;

if ( isset( $_GET[ $current_filter_key ] ) ) {
$term_slug = sanitize_title( $_GET[ $current_filter_key ] );
$term = get_term_by( 'slug', $term_slug, $filter );

if ( $term && ! is_wp_error( $term ) ) {
$filtered_terms[ $filter ] = $term;
} else {
$filtered_terms[ $filter ] = null;
}
}
}
}

return $filtered_terms;
}
}

if ( ! function_exists( 'awsm_block_jobs_query' ) ) {
function awsm_block_jobs_query( $attributes = array() ) {
$args = AWSM_Job_Openings_Block::awsm_block_job_query_args( array(), $attributes );
$query_args = array();
$is_term_or_slug = array();
$filter_suffix = '_spec';


$filter_options_array = explode(',', $attributes["filter_options"]);

if ( ! empty( $filter_options_array ) ) {
foreach ( $filter_options_array as $filter ) {
$current_filter_key = str_replace( '-', '__', $filter ) . $filter_suffix;
if ( isset( $_GET[ $current_filter_key ] ) ) {
$term_slug = sanitize_title( $_GET[ $current_filter_key ] );
$term = get_term_by( 'slug', $term_slug, $filter );
if ( $term && ! is_wp_error( $term ) ) {
$query_args[ $filter ] = $term->term_id;
$is_term_or_slug[ $filter ] = 'term_id';
} else {
$query_args[ $filter ] = $term_slug;
$is_term_or_slug[ $filter ] = 'slug';
}
}
}
}

$args = AWSM_Job_Openings_Block::awsm_block_job_query_args( $query_args, $attributes, $is_term_or_slug = array() );
$query = new WP_Query( $args );
return $query;
}
Expand Down
13 changes: 1 addition & 12 deletions inc/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function awsm_jobs_query( $shortcode_atts = array() ) {

$filters = get_option( 'awsm_jobs_listing_available_filters' );

// if ( $_GET ) {
if ( ! empty( $filters ) ) {
foreach ( $filters as $filter ) {
$current_filter_key = str_replace( '-', '__', $filter ) . $filter_suffix;
Expand All @@ -61,7 +60,6 @@ function awsm_jobs_query( $shortcode_atts = array() ) {
}
}
}
// }

$args = AWSM_Job_Openings::awsm_job_query_args( $query_args, $shortcode_atts, $is_term_or_slug );
$query = new WP_Query( $args );
Expand Down Expand Up @@ -400,13 +398,4 @@ function awsm_jobs_single_featured_image() {
}
add_action( 'before_awsm_jobs_single_content', 'awsm_jobs_single_featured_image' );

add_filter( 'query_vars', 'register_custom_query_vars' );
function register_custom_query_vars( $vars ) {
$filters = get_option( 'awsm_jobs_listing_available_filters' );
if ( $filters ) {
foreach ( $filters as $filter ) {
$vars[] = str_replace( '-', '__', $filter ) . '_spec';
}
}
return $vars;
}

46 changes: 41 additions & 5 deletions inc/templates/block-files/block-job-openings-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,45 @@
</div>
<?php
else :
?>
<div class="jobs-none-container">
<p><?php awsm_no_jobs_msg(); ?></p>
</div>
<?php
$filter_suffix = '_spec';
$job_spec = array();

if ( ! empty( $_GET ) ) {
foreach ( $_GET as $key => $value ) {
if ( substr( $key, -strlen( $filter_suffix ) ) === $filter_suffix ) {
$job_spec[ $key ] = sanitize_text_field( $value );
}
}
}

if ( ! empty( $job_spec ) ) {
print_r('sefdsd');
?>
<div class="awsm-b-job-wrap<?php awsm_jobs_wrapper_class(); ?>">
<?php
do_action( 'awsm_block_filter_form', $attributes );
do_action( 'awsm_block_form_outside', $attributes );
?>
<?php
get_block_filtered_job_terms( $attributes);
$no_jobs_content = sprintf(
'<div class="awsm-jobs-pagination awsm-load-more-main awsm-no-more-jobs-container awsm-job-no-more-jobs-get"><p>%s</p></div>',
esc_html__( 'Sorry! No jobs to show.', 'wp-job-openings' )
);
echo $no_jobs_content;
?>
<div <?php awsm_block_jobs_view_class( '', $attributes ); ?><?php awsm_block_jobs_data_attrs( array(), $attributes ); ?>>
<?php
include get_awsm_jobs_template_path( 'block-main', 'block-files' );
?>
</div>
</div>
<?php
} else {
?>
<div class="jobs-none-container">
<p><?php awsm_no_jobs_msg(); ?></p>
</div>
<?php
}
endif;

0 comments on commit 53203a5

Please sign in to comment.