pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

DateTime support for date strings in Arabic and other languages #4896

Open digicodexx opened 6 years ago

digicodexx commented 6 years ago

I’ve been having issues adding Date Post Types lately.

Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (۱۳۹۷-۰۲-۱۴) at position 0 (�): Unexpected character in G:\xampp\htdocs\..\wp-content\plugins\pods\classes\fields\datetime.php:668 Stack trace: #0 G:\xampp\htdocs\..\wp-content\plugins\pods\classes\fields\datetime.php(668): DateTime->__construct(‘\xDB\xB1\xDB\xB3\xDB\xB9\xDB\xB7-\xDB\xB0\xDB\xB2-\xDB…’) #1 G:\xampp\htdocs\..\wp-content\plugins\pods\classes\PodsForm.php(1506): PodsField_DateTime->createFromFormat(‘m/d/Y’, ”) #2 G:\xampp\htdocs\..\wp-content\plugins\pods\ui\fields\date.php(38): PodsForm::field_method(‘date’, ‘createFromForma…’, ‘m/d/Y’, ”) #3 G:\xampp\htdocs\..\wp-content\plugins\pods\classes\PodsView.php(515): require(‘G:\\xampp\\htdocs…’) #4 G:\xampp\htdocs\..\wp-content\plugins\pods\classes\PodsView.php(116): PodsView::get_template_part(‘G:/xampp/htdocs…’, Array) #5 G:\xampp\htdocs\..\wp-content\plugins\pods\includes\classes.php(231): PodsView::view(‘G:\\xamp in G:\xampp\htdocs\..\wp-content\plugins\pods\classes\fields\datetime.php on line 668

Steps to Reproduce (for bugs)

Just by simply adding a new CPT field.

Pods Package Export (helpful!)

{"meta":{"version":"2.7.2","build":1525454173},"pods":{"60":{"id":60,"name":"series","label":"Series","description":"","type":"post_type","storage":"meta","object":"","alias":"","fields":{"series-title":{"id":61,"name":"series-title","label":"series-title","description":"","help":"","class":"","type":"text","weight":0,"pick_object":"","pick_val":"","sister_id":"","required":"1","text_allow_shortcode":"0","text_allow_html":"0","text_allowed_html_tags":"strong em a ul ol li b i","text_max_length":"255","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","text_repeatable":"0","text_placeholder":""},"series-info":{"id":62,"name":"series-info","label":"series-info","description":"","help":"","class":"","type":"wysiwyg","weight":1,"pick_object":"","pick_val":"","sister_id":"","required":"1","wysiwyg_editor":"tinymce","wysiwyg_media_buttons":"1","wysiwyg_oembed":"0","wysiwyg_wptexturize":"1","wysiwyg_convert_chars":"1","wysiwyg_wpautop":"1","wysiwyg_allow_shortcode":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","wysiwyg_repeatable":"0","wysiwyg_allowed_html_tags":""},"series-post-date":{"id":63,"name":"series-post-date","label":"series-post-date","description":"","help":"","class":"","type":"date","weight":2,"pick_object":"","pick_val":"","sister_id":"","required":"1","date_type":"format","date_format":"mdy","date_allow_empty":"1","date_html5":"0","pick_post_status":["publish"],"admin_only":"0","restrict_role":"0","restrict_capability":"0","hidden":"0","read_only":"0","roles_allowed":["administrator"],"rest_read":"0","rest_write":"0","rest_pick_response":"array","rest_pick_depth":"2","unique":"0","date_repeatable":"0","date_format_custom":"","date_format_custom_js":""}},"show_in_menu":"1","label_singular":"Series","public":"1","show_ui":"1","supports_title":"1","supports_editor":"1","publicly_queryable":"1","exclude_from_search":"0","capability_type":"post","capability_type_custom":"series","capability_type_extra":"1","has_archive":"0","hierarchical":"0","rewrite":"1","rewrite_with_front":"1","rewrite_feeds":"0","rewrite_pages":"1","query_var":"1","can_export":"1","default_status":"draft","supports_author":"0","supports_thumbnail":"0","supports_excerpt":"0","supports_trackbacks":"0","supports_custom_fields":"0","supports_comments":"0","supports_revisions":"0","supports_page_attributes":"0","supports_post_formats":"0","built_in_taxonomies_category":"0","built_in_taxonomies_elementor_font_type":"0","built_in_taxonomies_elementor_library_type":"0","built_in_taxonomies_link_category":"0","built_in_taxonomies_post_tag":"0","show_in_nav_menus":"1","show_in_admin_bar":"1","pfat_enable":"0","pfat_run_outside_loop":"0","pfat_append_single":"append","pfat_filter_single":"the_content","pfat_append_archive":"append","pfat_filter_archive":"the_content","rest_enable":"0","read_all":"0","write_all":"0"}}}

WordPress Environment

``` WordPress Version: 4.9.5 PHP Version: 7.2.4 MySQL Version: 5.5.5 Server Software: Apache/2.4.33 (Win32) OpenSSL/1.1.0g PHP/7.2.4 Your User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 Session Save Path: G:\xampp\tmp Session Save Path Exists: Yes Session Save Path Writeable: Yes Session Max Lifetime: 1440 Opcode Cache: Apc: No Memcached: No OPcache: No Redis: No Object Cache: APC: No APCu: No Memcache: No Memcached: No Redis: No WPDB Prefix: plz_ WP Multisite Mode: No WP Memory Limit: 40M Pods Network-Wide Activated: No Pods Install Location: G:\xampp\htdocs\ooo\wp-content\plugins\pods/ Pods Tableless Mode Activated: No Pods Light Mode Activated: No Currently Active Theme: Astra Currently Active Plugins: Elementor: 2.0.9 Elementor Pro: 2.0.4 Header Footer Elementor: 1.0.12 Pods - Custom Content Types and Fields: 2.7.2 wp-jalali: 5.0.1 ```
jimtrue commented 6 years ago

From WordPress.org Forums: https://wordpress.org/support/topic/failed-to-parse-time-string/ Thanks for creating the report @digicodexx !

sc0ttkclark commented 6 years ago

What kind of content are you storing in the series date field?

۱۳۹۷-۰۲-۱۴ looks kind of weird as a date string, is that localized?

sc0ttkclark commented 6 years ago

It looks like we've got two issues here:

  1. We weren't handling the exception correctly in this case, I've added a fix for this
  2. PHP doesn't support converting arabic date strings in it's functions. I'm not sure what the workaround for this is, but feel free to let us know if you have any ideas/links that could assist for adding future support.
digicodexx commented 6 years ago

It's a Persian string, and yes it is localized, (http://wp-persian.com) http://fa.wordpress.org/wordpress-4.9.1-fa_IR.zip, (upgradable to 4.9.5 via control panel).

The plugin responsible for Persian calendar is: https://wordpress.org/plugins/wp-jalali/. I've had no issues with other plugins so far.

sc0ttkclark commented 6 years ago

For this, we might need to look into IntlDateFormatter http://php.net/manual/en/intldateformatter.format.php

Not sure exactly which configs have it, but it requires an additional PECL package installed/enabled for PHP.

GaryJones commented 6 years ago

I don't think even the IntlDateFormatter accepts non-Latin input, which is what's required here.

I did find http://www.ar-php.org/, and one of the pages is to parse Arabic strings into DateTime objects.

The latest version is from 2016, and that parsing is made up of a couple of classes, and a couple of XML files - one of which translates, another which adds Hijri calendar corrections and so on.

I don't think though that this Arabic input is necessarily core functionality - what about support for adding Korean, or Japanese, or Chinese or Hebrew or Greek other non-Latin scripts as input? Each of the respective locales (and even some from locales with Latin scripts) may have their own calendar / datetime variations that differ from Gregorian calendar used in Western countries.

Pods core could certainly ensure that RTL scripts display correctly, but accepting localized values that are passed into to PHP core classes and functions is going to need a whole new section of code, or for it to be handled in a separate plugin.

I don't know if the JS datepicker has the ability to pick and display in Arabic but submit in English.

aahani commented 5 years ago

As a workaround, I save and retrieve Georgian dates. Then to display Jalali dates, I use the following code in the template: {@event_start_date, jalali_date_full} where jalali_date_full is a function saved in the child theme / code snippet plugin as follows: function jalali_date_full($input_date) { return jdate("l، j F Y", strtotime($input_date)); }

But it would be nice to save Jalali dates, using a Jalali JavaScript datepicker.

sc0ttkclark commented 1 year ago

Needs retesting on the latest React date field inputs that we have.