Skip to content

Commit

Permalink
Merge pull request #290 from wikitongues/main
Browse files Browse the repository at this point in the history
Prod Deploy
  • Loading branch information
FredericoAndrade authored Feb 4, 2025
2 parents 75cb902 + bd3699b commit ceca2cf
Show file tree
Hide file tree
Showing 19 changed files with 583 additions and 265 deletions.
30 changes: 30 additions & 0 deletions wp-content/plugins/wt-gallery/includes/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
// Lexicons: create language object
if (!function_exists('get_language_gallery_html')) {
function get_language_gallery_html($language_post_id) {
if (!$language_post_id) {
return '';
}
if (is_array($language_post_id)) {
$language_post_id = $language_post_id['ID'];
// log_data("is array", "dom");
} else {
$language_post_id = $language_post_id;
// log_data("not array", "dom");
}
$post_title = get_the_title($language_post_id);
$standard_name = get_field('standard_name', $language_post_id);
return "<div class='language'><span class='identifier'>{$post_title}</span><p>{$standard_name}</p></div>";
}
}

// Resources: Get Domain
if (!function_exists('getDomainFromUrl')) {
function getDomainFromUrl($url) {
$host = parse_url($url, PHP_URL_HOST);
if (substr($host, 0, 4) === 'www.') {
$host = substr($host, 4);
}
return $host;
}
}
133 changes: 69 additions & 64 deletions wp-content/plugins/wt-gallery/includes/render_gallery_items.php
Original file line number Diff line number Diff line change
@@ -1,80 +1,85 @@
<?php
function render_gallery_items($query, $atts, $gallery_id, $paged, $data_attributes) {
ob_start();
function render_gallery_items($query, $atts, $gallery_id, $paged, $data_attributes) {
ob_start();

$classes = 'gallery-container';
if (!empty($atts['pagination']) && $atts['pagination'] === 'true' && $query->max_num_pages > 1) {
$classes .= ' paginated';
}
// Check if this is an AJAX call.
$is_ajax = defined('DOING_AJAX') && DOING_AJAX;

echo '<div class="'.$classes.'" id="' . esc_attr($atts['gallery_id']) . '" data-attributes="' . $data_attributes . '">';
echo '<ul class="gallery-list" style="grid-template-columns: repeat('.$atts['columns'].', 1fr);">';
// Only output the outer container if not an AJAX call.
if (!$is_ajax) {
$classes = 'gallery-container';
if (!empty($atts['pagination']) && $atts['pagination'] === 'true' && $query->max_num_pages > 1) {
$classes .= ' paginated';
}
echo '<div class="'.$classes.'" id="' . esc_attr($atts['gallery_id']) . '" data-attributes="' . $data_attributes . '">';
}
echo '<ul class="gallery-list" style="grid-template-columns: repeat('.$atts['columns'].', 1fr);">';

while ($query->have_posts()) {
$query->the_post();
$post_type = $atts['post_type']; // Use post type dynamically
$title = get_custom_title($atts['post_type']);
while ($query->have_posts()) {
$query->the_post();
$post_type = $atts['post_type']; // Use post type dynamically
$title = get_custom_title($atts['post_type']);

// Include the template for the post type
$template_file = plugin_dir_path(__FILE__) . 'templates/gallery-' . $post_type . '.php';
if (file_exists($template_file)) {
include $template_file;
} else {
echo '<li>No template found for ' . esc_html($post_type) . '</li>';
}
}
// Include the template for the post type
$template_file = plugin_dir_path(__FILE__) . 'templates/gallery-' . $post_type . '.php';
if (file_exists($template_file)) {
include $template_file;
} else {
echo '<li>No template found for ' . esc_html($post_type) . '</li>';
}
}

echo '</ul>';
if ($atts['pagination'] === 'true' && $query->max_num_pages > 1) {
echo generate_gallery_pagination($query, $gallery_id, $paged);
}
echo '</div>';
echo '</ul>';
if ($atts['pagination'] === 'true' && $query->max_num_pages > 1) {
echo generate_gallery_pagination($query, $gallery_id, $paged);
}
echo '</div>';

wp_reset_postdata();
wp_reset_postdata();

$output = ob_get_clean();
return $output;
}
$output = ob_get_clean();
return $output;
}

function generate_gallery_pagination($query, $gallery_id, $paged) {
$max_pages = $query->max_num_pages;
$pagination_html = '<ul class="gallery-pagination" data-gallery-id="' . esc_attr($gallery_id) . '">';
function generate_gallery_pagination($query, $gallery_id, $paged) {
$max_pages = $query->max_num_pages;
$pagination_html = '<ul class="gallery-pagination" data-gallery-id="' . esc_attr($gallery_id) . '">';

$pages_to_show = 9;
$half_pages_to_show = floor($pages_to_show / 2);
$pages_to_show = 9;
$half_pages_to_show = floor($pages_to_show / 2);

// Start and end page calculation
$start_page = max(1, $paged - $half_pages_to_show);
$end_page = min($max_pages, $paged + $half_pages_to_show);
// Start and end page calculation
$start_page = max(1, $paged - $half_pages_to_show);
$end_page = min($max_pages, $paged + $half_pages_to_show);

// Adjust if we are near the beginning or end
if ($paged <= $half_pages_to_show) {
$end_page = min($max_pages, $pages_to_show);
} elseif ($paged + $half_pages_to_show >= $max_pages) {
$start_page = max(1, $max_pages - $pages_to_show + 1);
}
// Adjust if we are near the beginning or end
if ($paged <= $half_pages_to_show) {
$end_page = min($max_pages, $pages_to_show);
} elseif ($paged + $half_pages_to_show >= $max_pages) {
$start_page = max(1, $max_pages - $pages_to_show + 1);
}

// Generate pagination links
// Add "Previous" button if not on the first page
$prev = '';
if ($paged > 1) {
$prev = '<a href="#" class="page-numbers" data-page="' . ($paged - 1) . '" data-gallery-id="' . esc_attr($gallery_id) . '">Previous</a>';
}
$pagination_html .= '<li class="page-helper">'.$prev.'</li>';
// Generate pagination links
// Add "Previous" button if not on the first page
$prev = '';
if ($paged > 1) {
$prev = '<a href="#" class="page-numbers" data-page="' . ($paged - 1) . '" data-gallery-id="' . esc_attr($gallery_id) . '">Previous</a>';
}
$pagination_html .= '<li class="page-helper">'.$prev.'</li>';

// Loop through the range of pages to display
for ($i = $start_page; $i <= $end_page; $i++) {
$active_class = ($i == $paged) ? ' active' : ''; // Highlight current page
$pagination_html .= '<li><a href="#" class="page-numbers' . $active_class . '" data-page="' . $i . '" data-gallery-id="' . esc_attr($gallery_id) . '">' . $i . '</a></li>';
}
// Loop through the range of pages to display
for ($i = $start_page; $i <= $end_page; $i++) {
$active_class = ($i == $paged) ? ' active' : ''; // Highlight current page
$pagination_html .= '<li><a href="#" class="page-numbers' . $active_class . '" data-page="' . $i . '" data-gallery-id="' . esc_attr($gallery_id) . '">' . $i . '</a></li>';
}

// Add "Next" button if not on the last page
$next = '';
if ($paged < $max_pages) {
$next .= '<a href="#" class="page-numbers" data-page="' . ($paged + 1) . '" data-gallery-id="' . esc_attr($gallery_id) . '">Next</a>';
}
$pagination_html .= '<li class="page-helper">'.$next.'</li>';
// Add "Next" button if not on the last page
$next = '';
if ($paged < $max_pages) {
$next .= '<a href="#" class="page-numbers" data-page="' . ($paged + 1) . '" data-gallery-id="' . esc_attr($gallery_id) . '">Next</a>';
}
$pagination_html .= '<li class="page-helper">'.$next.'</li>';

$pagination_html .= '</ul>';
return $pagination_html;
}
$pagination_html .= '</ul>';
return $pagination_html;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<li class="gallery-item">
<?php
$source_languages = array(get_field('source_languages'));
$target_languages = get_field('target_languages');
$dropbox_link = get_field('dropbox_link');
$external_link = get_field('external_link');
$url = '';
if ($dropbox_link) {
$url = $dropbox_link;
} elseif ($external_link) {
$url = $external_link;
}
;
echo "<a href={$url}>";

echo '<section><p>Lexicon</p>';

foreach ($source_languages as $language_post_id) {
echo get_language_gallery_html($language_post_id);
}
echo '</section>';

echo '<section><p>to</p><span class="target-languages">';
foreach ($target_languages as $language_post_id) {
echo get_language_gallery_html($language_post_id);
}
echo '</span></section></a>';

?>
</li>
6 changes: 4 additions & 2 deletions wp-content/plugins/wt-gallery/wt-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function custom_gallery_enqueue_scripts() {
}
add_action('wp_enqueue_scripts', 'custom_gallery_enqueue_scripts');

require_once plugin_dir_path(__FILE__) . 'includes/helpers.php';
require_once plugin_dir_path(__FILE__) . 'includes/queries.php';
require_once plugin_dir_path(__FILE__) . 'includes/render_gallery_items.php';


// AJAX callback function to load more gallery items
function load_custom_gallery_ajax_callback() {
check_ajax_referer('custom_gallery_nonce', 'nonce'); // Security check
Expand Down Expand Up @@ -189,7 +191,6 @@ function custom_gallery($atts) {
if (!empty($selected_posts)) {
$args['post__in'] = $selected_posts;
}
// log_data($args,"dom");

$data_attributes = esc_attr(json_encode($args));

Expand All @@ -212,8 +213,9 @@ function custom_gallery($atts) {
if ($atts['title']) {
$output .= '<h2 class="wt_sectionHeader">'.$atts['title'].'</h2>';
}
$output .= '<p>There are no other '.$atts['post_type'].' to display—yet.</p>';
$output .= '<p>There are no other '.$atts['post_type'].'s to display—<a href="'.home_url('/submit-a-lexicon'.rtrim($atts['post_type'], 's'), 'relative').'">yet</a>.</p>';
}

}
$output .= '</div>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
{
"key": "field_64fa4744ab1c9",
"label": "Fellow year",
"label": "Fellow Year",
"name": "fellow_year",
"aria-label": "",
"type": "select",
Expand Down

This file was deleted.

Loading

0 comments on commit ceca2cf

Please sign in to comment.