diff --git a/.gitignore b/.gitignore index d2a9e6c..a7d2a98 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ vendor/ logs/ build/ *.zip +.cursor/ diff --git a/Dockerfile b/Dockerfile index 0cf51a4..d521fd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM wordpress:6.6.2-php8.3-apache +FROM wordpress:6.8.0-php8.3-apache RUN apt-get update && \ apt-get install -y --no-install-recommends ssl-cert && \ diff --git a/docker-compose.yml b/docker-compose.yml index 8208f57..f6453d8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.1' - services: wordpress: depends_on: diff --git a/fetch-jft-plugin.php b/fetch-jft-plugin.php index 8c6f872..7056200 100644 --- a/fetch-jft-plugin.php +++ b/fetch-jft-plugin.php @@ -7,7 +7,7 @@ * Install: Drop this directory into the "wp-content/plugins/" directory and activate it. * Contributors: pjaudiomv, bmltenabled * Authors: bmltenabled - * Version: 1.8.5 + * Version: 1.9.0 * Requires PHP: 7.3 * License: GPL v2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html diff --git a/js/jft.js b/js/jft.js new file mode 100644 index 0000000..82a426c --- /dev/null +++ b/js/jft.js @@ -0,0 +1,23 @@ +jQuery(document).ready(function($) { + const jftLanguageSelect = $('#jft_language'); + const timezoneContainer = $('#timezone-container'); + const layoutContainer = $('#layout-container'); + + function updateEnglishOnlyOptions() { + let isEnglish = jftLanguageSelect.val() === 'english'; + + if (isEnglish) { + timezoneContainer.show(); + layoutContainer.show(); + } else { + timezoneContainer.hide(); + layoutContainer.hide(); + } + } + + // Initial update + updateEnglishOnlyOptions(); + + // Listen for changes + jftLanguageSelect.on('change', updateEnglishOnlyOptions); +}); diff --git a/readme.txt b/readme.txt index 9aa792b..0c70540 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: pjaudiomv, klgrimley, bmltenabled Tags: jft, just for today, narcotics anonymous, na -Tested up to: 6.6 -Stable tag: 1.8.5 +Tested up to: 6.8 +Stable tag: 1.9.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -50,6 +50,10 @@ This section describes how to install the plugin and get it working. == Changelog == += 1.9.0 = + +* Added Time Zone support for English. + = 1.8.5 = * Compliance fixes. diff --git a/src/Dashboard.php b/src/Dashboard.php index 6467870..c6b8b63 100644 --- a/src/Dashboard.php +++ b/src/Dashboard.php @@ -8,14 +8,43 @@ class Dashboard public function __construct() { - add_action('admin_init', [$this, 'registerSettings']); - add_action('admin_menu', [$this, 'createMenu']); + if (is_admin()) { + add_action('admin_init', [$this, 'registerSettings']); + add_action('admin_menu', [$this, 'createMenu']); + add_action('admin_enqueue_scripts', [ $this, 'enqueueBackendFiles' ], 500); + } + } + + public function enqueueBackendFiles(string $hook): void + { + if ('settings_page_jft-plugin' !== $hook) { + return; + } + $base_url = plugin_dir_url(dirname(__FILE__)); + wp_enqueue_script('fetch-jft-admin', $base_url . 'js/jft.js', [ 'jquery' ], filemtime(plugin_dir_path(dirname(__FILE__)) . 'js/jft.js'), false); } public function registerSettings(): void { register_setting(self::SETTING_GROUP, 'jft_layout'); - register_setting(self::SETTING_GROUP, 'jft_language'); + register_setting( + self::SETTING_GROUP, + 'jft_language', + [ + 'type' => 'string', + 'default' => 'english', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + register_setting( + self::SETTING_GROUP, + 'jft_timezone', + [ + 'type' => 'string', + 'default' => '', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); } public function createMenu(string $baseFile): void @@ -37,6 +66,19 @@ public function settingsLink($links) return $links; } + private static function renderSelectOption(string $name, string $selected_value, array $options): string + { + // Render a dropdown select input for settings + $select_html = "'; + + return $select_html; + } + public function drawSettings(): void { ?> @@ -48,37 +90,51 @@ public function drawSettings(): void do_settings_sections(self::SETTING_GROUP); ?> - - - + + +

Choose the language for the JFT Display.
insert [jft] shortcode on your page or post. Languages other then English only works with raw HTML layout.

- + + + + + +
Language - -

Choose the language for the JFT Display.
insert [jft] shortcode on your page or post. Languages other then English only works with raw HTML layout.

+
Language + 'Danish', + 'english' => 'English', + 'farsi' => 'Farsi', + 'french' => 'French', + 'german' => 'German', + 'italian' => 'Italian', + 'japanese' => 'Japanese', + 'portuguese' => 'Portuguese', + 'russian' => 'Russian', + 'spanish' => 'Spanish', + 'swedish' => 'Swedish', + ] + ), + $allowed_html + ); + ?>
Layout
Timezone (English Only) + 'Server Default', + // North America + 'America/New_York' => 'America/New_York', + 'America/Chicago' => 'America/Chicago', + 'America/Denver' => 'America/Denver', + 'America/Los_Angeles' => 'America/Los_Angeles', + 'America/Anchorage' => 'America/Anchorage', + 'America/Honolulu' => 'America/Honolulu', + 'America/Phoenix' => 'America/Phoenix', + + // South America + 'America/Sao_Paulo' => 'America/Sao_Paulo', + 'America/Argentina/Buenos_Aires' => 'America/Argentina/Buenos_Aires', + 'America/Santiago' => 'America/Santiago', + + // Europe + 'Europe/London' => 'Europe/London', + 'Europe/Paris' => 'Europe/Paris', + 'Europe/Berlin' => 'Europe/Berlin', + 'Europe/Moscow' => 'Europe/Moscow', + + // Africa + 'Africa/Cairo' => 'Africa/Cairo', + 'Africa/Johannesburg' => 'Africa/Johannesburg', + 'Africa/Lagos' => 'Africa/Lagos', + + // Asia + 'Asia/Dubai' => 'Asia/Dubai', + 'Asia/Kolkata' => 'Asia/Kolkata', + 'Asia/Bangkok' => 'Asia/Bangkok', + 'Asia/Singapore' => 'Asia/Singapore', + 'Asia/Tokyo' => 'Asia/Tokyo', + 'Asia/Shanghai' => 'Asia/Shanghai', + 'Asia/Seoul' => 'Asia/Seoul', + + // Australia/Pacific + 'Australia/Sydney' => 'Australia/Sydney', + 'Australia/Perth' => 'Australia/Perth', + 'Pacific/Auckland' => 'Pacific/Auckland', + 'Pacific/Fiji' => 'Pacific/Fiji' + ]; + echo wp_kses( + static::renderSelectOption( + 'jft_timezone', + $timezone, + $timezone_options + ), + $allowed_html + ); + ?> +

Only applies when English language is selected. Leave blank to use server default.

+
diff --git a/src/Reading.php b/src/Reading.php index 84821c4..4b735cb 100644 --- a/src/Reading.php +++ b/src/Reading.php @@ -11,7 +11,7 @@ class Reading const CSS_CLASS = 'jft-rendered-element'; const DEFAULT_CONFIG = [ - 'url' => 'https://jftna.org/jft/', + 'url' => 'https://jft.na.org/', 'dom_element' => 'table', 'footer' => '
Subscribe
', 'language' => 'english' @@ -19,10 +19,11 @@ class Reading public function renderReading($atts = []): string { - $args = shortcode_atts(['layout' => '', 'language' => ''], $atts); + $args = shortcode_atts(['layout' => '', 'language' => '', 'timezone' => ''], $atts); $layout = $this->sanitizeLayout($args); $language = $this->sanitizeLanguage($args); - $languageConfig = $this->getLanguageConfig($language); + $timezone = $this->sanitizeTimezone($args); + $languageConfig = $this->getLanguageConfig($language, $timezone); $response = $this->getJft($languageConfig); if ($layout == "block" && $language != "english") { return 'Fetch JFT Error - Block layout can only be used with english. Language set: ' . $language; @@ -30,11 +31,27 @@ public function renderReading($atts = []): string return $this->getContent($layout, $response, $languageConfig); } - protected function getLanguageConfig($language): array + protected function getLanguageConfig($language, $timezone = ''): array { $pdate = new \jDateTimePlus(true, true, 'Asia/Tehran'); + + // Check for timezone setting for English + $timezoneParam = ''; + if ($language === 'english') { + // Prioritize shortcode timezone parameter over global setting + $timezone_setting = !empty($timezone) ? $timezone : get_option('jft_timezone'); + if (!empty($timezone_setting)) { + $timezoneParam = '?timeZone=' . urlencode($timezone_setting); + } + } + $languageConfig = [ - 'english' => self::DEFAULT_CONFIG, + 'english' => [ + 'url' => self::DEFAULT_CONFIG['url'] . $timezoneParam, + 'dom_element' => self::DEFAULT_CONFIG['dom_element'], + 'footer' => self::DEFAULT_CONFIG['footer'], + 'language' => self::DEFAULT_CONFIG['language'] + ], 'spanish' => [ 'url' => 'https://fzla.org/wp-content/uploads/meditaciones/' . $this->getTimezoneDate('spanish', 'm/d') . ".html", 'footer' => '', @@ -111,6 +128,11 @@ protected function sanitizeLanguage(array $args): string return !empty($args['language']) ? sanitize_text_field(strtolower($args['language'])) : sanitize_text_field(get_option('jft_language')); } + protected function sanitizeTimezone(array $args): string + { + return !empty($args['timezone']) ? sanitize_text_field($args['timezone']) : ''; + } + protected function getJft(array $languageConfig): string { $charset = self::DEFAULT_CHAR_ENCODING;