CMS MADE SIMPLE FORGE

CGCalendar

 

[#12232] CGCalendar admin page does not display a calendar for some non-english locales

avatar
Created By: Niels Ohrt (Niels_O)
Date Submitted: Wed Jan 01 06:42:45 -0500 2020

Assigned To: Robert Campbell (calguy1000)
Version: 2.6.2
CMSMS Version: 2.2.13
Severity: Major
Resolution: None
State: Open
Summary:
CGCalendar admin page does not display a calendar for some non-english locales
Detailed Description:
When CGCalendar 2.6.2 is started from the CMSMS 2.2.13 admin panel (PHP 7.2)
with a non-english locale the calendar itself is not displayed.
(The error has existed at least since CGCalendar 2.1.4.2)
Instead an error message is displayed in the Console: 

moduleinterface.php?mact=CGCalendar,m1_,defaultadmin,0&__c=438775917c066d4a89d:159
Uncaught SyntaxError: Unexpected token ';'
var datestrings = ;      line 159

Which is found here:

CGCalendar/templates/admin_events_tab.tpl line 117:
var datestrings = {$datestrings};

And assigned here:

CGCalendar/function.admindisplaymanageevents.php  line 59 
$smarty→assign('datestrings',json_encode($locale_info));

Based on $locale_info output from get_locale_dates():

CGCalendar/function.admindisplaymanageevents.php line 47 
$locale_info = cgcalendar_utils::get_locale_dates();

CGCalendar/lib/class.calendar_utils.php get_locale_dates()

static public function get_locale_dates()
    {
        $out = array();
        $out['monthNames'] = array();
        $out['monthNamesShort'] = array();
        for( $i = 0; $i < 12; $i++ ) {
            $out['monthNames'][] = strftime('%B',mktime(1,0,0,$i+1,1,2000));
$out['monthNamesShort'][] =
strftime('%b',mktime(1,0,0,$i+1,1,2000));
        }

        $mod = cms_utils::get_module(MOD_CGCALENDAR);
        $fmt = 'last sunday + %d days';
        $out['dayNames'] = array();
        $out['dayNamesShort'] = array();
        $curday = (int)date('w');
        for( $i = 0; $i < 7; $i++ ) {
            $out['dayNames'][] = strftime('%A',strtotime(sprintf($fmt,$i)));
$out['dayNamesShort'][] =
strftime('%a',strtotime(sprintf($fmt,$i)));
        }
        return $out;
          } 

json_encode($locale_info)requires that  $locale_info is UTF8 encoded.
get_locale_dates()does not deliver this but as long as ordinal values from ASCII
is used is ASCII=UTF8, thats why get_locale_dates() works for English locales
and crashes for other locales.
The error can be fixed by utf8_encode:
 
 $out['monthNames'][] = utf8_encode(strftime('%B',mktime(1,0,0,$i+1,1,2000)));
$out['monthNamesShort'][] =
utf8_encode(strftime('%b',mktime(1,0,0,$i+1,1,2000)));

 $out['dayNames'][] = utf8_encode(strftime('%A',strtotime(sprintf($fmt,$i))));
$out['dayNamesShort'][] =
utf8_encode(strftime('%a',strtotime(sprintf($fmt,$i))));


History