mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-18375 calendar: huge refactor of the initial patch
1) Moved the calendar types location to a sub-folder in the calendar directory. 2) Removed/moved language strings. 3) Removed calendar types that should be downloaded as plugins. 4) Removed a Non-English language pack for the Gregorian calendar type that should be downloaded separately. 5) Removed custom files responsible for checking for updates and uninstalling calendar types, which should be done by core. 6) Removed JS from the calendar_month block as there is no non-JS alternative provided and the JS written does not make use of the YUI library to ensure multiple browser support. 7) Removed code from the base class responsible for creating timestamps that are saved in the DB. 8) Added PHPDocs. Note: In the original patch we are editing core functions responsible for saving time in the database in the calendar base class. This is very dangerous, we do not want to touch these functions as it could cause a complete fubar of the database. There are places we are forcing the use of the gregorian calendar as we are passing dates generated by the PHP date function, where as sometimes we pass dates from usergetdate (which was being overwritten to return the date specific to the calendar). We can not expect third party modules to change the calendar type depending on the format they pass to these functions.
This commit is contained in:
parent
6dd59aabfa
commit
2f00e1b245
45 changed files with 606 additions and 1931 deletions
|
@ -203,9 +203,7 @@ function rfc2445_is_valid_value($value, $type) {
|
|||
$m = intval(substr($value, 4, 2));
|
||||
$d = intval(substr($value, 6, 2));
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian');
|
||||
return $calendarsystem_gregorian->checkdate($m, $d, $y);
|
||||
return checkdate($m, $d, $y);
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_DATE_TIME:
|
||||
|
|
|
@ -341,6 +341,7 @@ $cache = '.var_export($cache, true).';
|
|||
'qtype' => $CFG->dirroot.'/question/type',
|
||||
'mod' => $CFG->dirroot.'/mod',
|
||||
'auth' => $CFG->dirroot.'/auth',
|
||||
'calendartype' => $CFG->dirroot.'/calendar/type',
|
||||
'enrol' => $CFG->dirroot.'/enrol',
|
||||
'message' => $CFG->dirroot.'/message/output',
|
||||
'block' => $CFG->dirroot.'/blocks',
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
<FIELD NAME="groupmodeforce" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="defaultgroupingid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="default grouping used in course modules, does not have key intentionally"/>
|
||||
<FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendarsystem" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendartype" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
|
@ -772,7 +772,7 @@
|
|||
<FIELD NAME="city" TYPE="char" LENGTH="120" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="country" TYPE="char" LENGTH="2" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="lang" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="en" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendarsystem" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="calendartype" TYPE="char" LENGTH="20" NOTNULL="false" DEFAULT="" SEQUENCE="false"/>
|
||||
<FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timezone" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="99" SEQUENCE="false"/>
|
||||
<FIELD NAME="firstaccess" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
|
|
|
@ -39,12 +39,10 @@ require_once($CFG->libdir . '/formslib.php');
|
|||
* @copyright 2007 Jamie Pratt <me@jamiep.org>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
||||
{
|
||||
class MoodleQuickForm_date_selector extends MoodleQuickForm_group {
|
||||
|
||||
/**
|
||||
* Control the fieldnames for form elements
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
* Control the fieldnames for form elements.
|
||||
*
|
||||
* startyear => int start of range of years that can be selected
|
||||
* stopyear => int last year that can be selected
|
||||
|
@ -78,13 +76,11 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
* @param array $options Options to control the element's display
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
*/
|
||||
function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
||||
{
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
$this->_options = array('startyear'=> $CALENDARSYSTEM->get_min_year(), 'stopyear'=>$CALENDARSYSTEM->get_max_year(),
|
||||
'timezone'=>99, 'optional'=>false);
|
||||
function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
$this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(),
|
||||
'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false);
|
||||
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
|
@ -111,18 +107,18 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
function _createElements()
|
||||
{
|
||||
global $OUTPUT, $CALENDARSYSTEM;
|
||||
function _createElements() {
|
||||
global $OUTPUT;
|
||||
|
||||
$this->_elements = array();
|
||||
for ($i=1; $i<=31; $i++) {
|
||||
$days[$i] = $i;
|
||||
}
|
||||
$months = $CALENDARSYSTEM->get_month_names();
|
||||
for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) {
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
$days = $calendartype->get_days();
|
||||
$months = $calendartype->get_months();
|
||||
for ($i = $this->_options['startyear']; $i <= $this->_options['stopyear']; $i++) {
|
||||
$years[$i] = $i;
|
||||
}
|
||||
|
||||
$this->_elements = array();
|
||||
// E_STRICT creating elements without forms is nasty because it internally uses $this
|
||||
$this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
|
||||
$this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
|
||||
|
@ -149,8 +145,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
* @param object $caller calling object
|
||||
* @return bool
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
function onQuickFormEvent($event, $arg, &$caller) {
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
|
@ -176,7 +171,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
// If optional, default to off, unless a date was provided
|
||||
if($this->_options['optional']) {
|
||||
if($this->_options['optional']) {
|
||||
$value['enabled'] = $requestvalue != 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -216,8 +211,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
function toHtml() {
|
||||
include_once('HTML/QuickForm/Renderer/Default.php');
|
||||
$renderer = new HTML_QuickForm_Renderer_Default();
|
||||
$renderer->setElementTemplate('{element}');
|
||||
|
@ -241,8 +235,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
* @param bool $required Whether a group is required
|
||||
* @param string $error An error message associated with a group
|
||||
*/
|
||||
function accept(&$renderer, $required = false, $error = null)
|
||||
{
|
||||
function accept(&$renderer, $required = false, $error = null) {
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
}
|
||||
|
||||
|
@ -253,8 +246,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
* @param bool $assoc specifies if returned array is associative
|
||||
* @return array
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
function exportValue(&$submitValues, $assoc = false) {
|
||||
$value = null;
|
||||
$valuearray = array();
|
||||
foreach ($this->_elements as $element){
|
||||
|
@ -271,13 +263,15 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
|||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
$value[$this->getName()] = make_timestamp($valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
0, 0, 0,
|
||||
$this->_options['timezone'],
|
||||
true);
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = core_calendar\type_factory::factory();
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']);
|
||||
$value[$this->getName()] = make_timestamp($gregoriandate['year'],
|
||||
$gregoriandate['month'],
|
||||
$gregoriandate['day'],
|
||||
0, 0, 0,
|
||||
$this->_options['timezone'],
|
||||
true);
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
|
|
|
@ -39,11 +39,10 @@ require_once($CFG->libdir . '/formslib.php');
|
|||
* @copyright 2006 Jamie Pratt <me@jamiep.org>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
||||
class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
|
||||
|
||||
/**
|
||||
* Options for the element
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
* Options for the element.
|
||||
*
|
||||
* startyear => int start of range of years that can be selected
|
||||
* stopyear => int last year that can be selected
|
||||
|
@ -79,13 +78,11 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
* @param array $options Options to control the element's display
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
*/
|
||||
function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
||||
{
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
$this->_options = array('startyear'=> $CALENDARSYSTEM->get_min_year(), 'stopyear'=>$CALENDARSYSTEM->get_max_year(),
|
||||
'defaulttime' => 0, 'timezone'=>99, 'step'=>5, 'optional'=>false);
|
||||
function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
$this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(),
|
||||
'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false);
|
||||
|
||||
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
||||
$this->_persistantFreeze = true;
|
||||
|
@ -112,16 +109,14 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
*
|
||||
* @access private
|
||||
*/
|
||||
function _createElements()
|
||||
{
|
||||
global $OUTPUT, $CALENDARSYSTEM;
|
||||
function _createElements() {
|
||||
global $OUTPUT;
|
||||
|
||||
$this->_elements = array();
|
||||
for ($i=1; $i<=31; $i++) {
|
||||
$days[$i] = $i;
|
||||
}
|
||||
$months = $CALENDARSYSTEM->get_month_names();
|
||||
for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) {
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
$days = $calendartype->get_days();
|
||||
$months = $calendartype->get_months();
|
||||
for ($i = $this->_options['startyear']; $i <= $this->_options['stopyear']; $i++) {
|
||||
$years[$i] = $i;
|
||||
}
|
||||
for ($i=0; $i<=23; $i++) {
|
||||
|
@ -130,6 +125,8 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
for ($i=0; $i<60; $i+=$this->_options['step']) {
|
||||
$minutes[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
|
||||
$this->_elements = array();
|
||||
// E_STRICT creating elements without forms is nasty because it internally uses $this
|
||||
$this->_elements[] = @MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
|
||||
$this->_elements[] = @MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
|
||||
|
@ -163,8 +160,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
* @param object $caller calling object
|
||||
* @return bool
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
function onQuickFormEvent($event, $arg, &$caller) {
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
|
@ -237,8 +233,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
function toHtml() {
|
||||
include_once('HTML/QuickForm/Renderer/Default.php');
|
||||
$renderer = new HTML_QuickForm_Renderer_Default();
|
||||
$renderer->setElementTemplate('{element}');
|
||||
|
@ -262,8 +257,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
* @param bool $required Whether a group is required
|
||||
* @param string $error An error message associated with a group
|
||||
*/
|
||||
function accept(&$renderer, $required = false, $error = null)
|
||||
{
|
||||
function accept(&$renderer, $required = false, $error = null) {
|
||||
$renderer->renderElement($this, $required, $error);
|
||||
}
|
||||
|
||||
|
@ -274,8 +268,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
* @param bool $assoc specifies if returned array is associative
|
||||
* @return array
|
||||
*/
|
||||
function exportValue(&$submitValues, $assoc = false)
|
||||
{
|
||||
function exportValue(&$submitValues, $assoc = false) {
|
||||
$value = null;
|
||||
$valuearray = array();
|
||||
foreach ($this->_elements as $element){
|
||||
|
@ -292,20 +285,24 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
|||
return $value;
|
||||
}
|
||||
}
|
||||
$valuearray=$valuearray + array('year' => 1970, 'month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0);
|
||||
$value[$this->getName()] = make_timestamp(
|
||||
$valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
$valuearray['hour'],
|
||||
$valuearray['minute'],
|
||||
0,
|
||||
$this->_options['timezone'],
|
||||
true);
|
||||
// Get the calendar type used - see MDL-18375.
|
||||
$calendartype = core_calendar\type_factory::factory();
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
$valuearray['hour'],
|
||||
$valuearray['minute']);
|
||||
$value[$this->getName()] = make_timestamp($gregoriandate['year'],
|
||||
$gregoriandate['month'],
|
||||
$gregoriandate['day'],
|
||||
$gregoriandate['hour'],
|
||||
$gregoriandate['minute'],
|
||||
0,
|
||||
$this->_options['timezone'],
|
||||
true);
|
||||
|
||||
return $value;
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2003,8 +2003,6 @@ function get_user_preferences($name = null, $default = null, $user = null) {
|
|||
/**
|
||||
* Given date parts in user time produce a GMT timestamp.
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* @package core
|
||||
* @category time
|
||||
* @param int $year The year part to create timestamp of
|
||||
|
@ -2020,16 +2018,6 @@ function get_user_preferences($name = null, $default = null, $user = null) {
|
|||
* @return int GMT timestamp
|
||||
*/
|
||||
function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) {
|
||||
global $CALENDARSYSTEM;
|
||||
if ($CALENDARSYSTEM->get_min_year() == 1350 && $year > 2000) {
|
||||
debugging('Warning. Wrong call to make_timestamp().', DEBUG_DEVELOPER);
|
||||
error('Your code must be fixed by a developer.');
|
||||
}
|
||||
return $CALENDARSYSTEM->make_timestamp($year, $month, $day, $hour, $minute, $second, $timezone, $applydst);
|
||||
}
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
function make_timestamp_old($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) {
|
||||
|
||||
// Save input timezone, required for dst offset check.
|
||||
$passedtimezone = $timezone;
|
||||
|
@ -2156,8 +2144,6 @@ function format_time($totalsecs, $str = null) {
|
|||
* If parameter fixday = true (default), then take off leading
|
||||
* zero from %d, else maintain it.
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* @package core
|
||||
* @category time
|
||||
* @param int $date the timestamp in UTC, as obtained from the database.
|
||||
|
@ -2172,77 +2158,8 @@ function format_time($totalsecs, $str = null) {
|
|||
* @return string the formatted date/time.
|
||||
*/
|
||||
function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour = true) {
|
||||
global $CALENDARSYSTEM;
|
||||
return $CALENDARSYSTEM->userdate($date, $format, $timezone, $fixday, $fixhour);
|
||||
}
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
function userdate_old($date, $format = '', $timezone = 99, $fixday = true, $fixhour = true) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
if (empty($format)) {
|
||||
$format = get_string('strftimedaydatetime', 'langconfig');
|
||||
}
|
||||
|
||||
if (!empty($CFG->nofixday)) {
|
||||
// Config.php can force %d not to be fixed.
|
||||
$fixday = false;
|
||||
} else if ($fixday) {
|
||||
$formatnoday = str_replace('%d', 'DD', $format);
|
||||
$fixday = ($formatnoday != $format);
|
||||
$format = $formatnoday;
|
||||
}
|
||||
|
||||
// Note: This logic about fixing 12-hour time to remove unnecessary leading
|
||||
// zero is required because on Windows, PHP strftime function does not
|
||||
// support the correct 'hour without leading zero' parameter (%l).
|
||||
if (!empty($CFG->nofixhour)) {
|
||||
// Config.php can force %I not to be fixed.
|
||||
$fixhour = false;
|
||||
} else if ($fixhour) {
|
||||
$formatnohour = str_replace('%I', 'HH', $format);
|
||||
$fixhour = ($formatnohour != $format);
|
||||
$format = $formatnohour;
|
||||
}
|
||||
|
||||
// Add daylight saving offset for string timezones only, as we can't get dst for
|
||||
// float values. if timezone is 99 (user default timezone), then try update dst.
|
||||
if ((99 == $timezone) || !is_numeric($timezone)) {
|
||||
$date += dst_offset_on($date, $timezone);
|
||||
}
|
||||
|
||||
$timezone = get_user_timezone_offset($timezone);
|
||||
|
||||
// If we are running under Windows convert to windows encoding and then back to UTF-8
|
||||
// (because it's impossible to specify UTF-8 to fetch locale info in Win32).
|
||||
|
||||
if (abs($timezone) > 13) {
|
||||
// Server time.
|
||||
$datestring = date_format_string($date, $format, $timezone);
|
||||
if ($fixday) {
|
||||
$daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date)));
|
||||
$datestring = str_replace('DD', $daystring, $datestring);
|
||||
}
|
||||
if ($fixhour) {
|
||||
$hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date)));
|
||||
$datestring = str_replace('HH', $hourstring, $datestring);
|
||||
}
|
||||
|
||||
} else {
|
||||
$date += (int)($timezone * 3600);
|
||||
$datestring = date_format_string($date, $format, $timezone);
|
||||
if ($fixday) {
|
||||
$daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date)));
|
||||
$datestring = str_replace('DD', $daystring, $datestring);
|
||||
}
|
||||
if ($fixhour) {
|
||||
$hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $date)));
|
||||
$datestring = str_replace('HH', $hourstring, $datestring);
|
||||
}
|
||||
}
|
||||
|
||||
return $datestring;
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
return $calendartype->userdate($date, $format, $timezone, $fixday, $fixhour);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2287,8 +2204,6 @@ function date_format_string($date, $format, $tz = 99) {
|
|||
* Given a $time timestamp in GMT (seconds since epoch),
|
||||
* returns an array that represents the date in user time
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* @package core
|
||||
* @category time
|
||||
* @uses HOURSECS
|
||||
|
@ -2297,58 +2212,9 @@ function date_format_string($date, $format, $tz = 99) {
|
|||
* dst offset is applied {@link http://docs.moodle.org/dev/Time_API#Timezone}
|
||||
* @return array An array that represents the date in user time
|
||||
*/
|
||||
function usergetdate($time, $timezone=99) {
|
||||
global $CALENDARSYSTEM;
|
||||
return $CALENDARSYSTEM->usergetdate($time, $timezone);
|
||||
}
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
function usergetdate_old($time, $timezone=99) {
|
||||
|
||||
// Save input timezone, required for dst offset check.
|
||||
$passedtimezone = $timezone;
|
||||
|
||||
$timezone = get_user_timezone_offset($timezone);
|
||||
|
||||
if (abs($timezone) > 13) {
|
||||
// Server time.
|
||||
return getdate($time);
|
||||
}
|
||||
|
||||
// Add daylight saving offset for string timezones only, as we can't get dst for
|
||||
// float values. if timezone is 99 (user default timezone), then try update dst.
|
||||
if ($passedtimezone == 99 || !is_numeric($passedtimezone)) {
|
||||
$time += dst_offset_on($time, $passedtimezone);
|
||||
}
|
||||
|
||||
$time += intval((float)$timezone * HOURSECS);
|
||||
|
||||
$datestring = gmstrftime('%B_%A_%j_%Y_%m_%w_%d_%H_%M_%S', $time);
|
||||
|
||||
// Be careful to ensure the returned array matches that produced by getdate() above.
|
||||
list(
|
||||
$getdate['month'],
|
||||
$getdate['weekday'],
|
||||
$getdate['yday'],
|
||||
$getdate['year'],
|
||||
$getdate['mon'],
|
||||
$getdate['wday'],
|
||||
$getdate['mday'],
|
||||
$getdate['hours'],
|
||||
$getdate['minutes'],
|
||||
$getdate['seconds']
|
||||
) = explode('_', $datestring);
|
||||
|
||||
// Set correct datatype to match with getdate().
|
||||
$getdate['seconds'] = (int)$getdate['seconds'];
|
||||
$getdate['yday'] = (int)$getdate['yday'] - 1; // The function gmstrftime returns 0 through 365.
|
||||
$getdate['year'] = (int)$getdate['year'];
|
||||
$getdate['mon'] = (int)$getdate['mon'];
|
||||
$getdate['wday'] = (int)$getdate['wday'];
|
||||
$getdate['mday'] = (int)$getdate['mday'];
|
||||
$getdate['hours'] = (int)$getdate['hours'];
|
||||
$getdate['minutes'] = (int)$getdate['minutes'];
|
||||
return $getdate;
|
||||
function usergetdate($time, $timezone = 99) {
|
||||
$calendartype = calendar_type_plugin_factory::factory();
|
||||
return $calendartype->usergetdate($time, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2672,8 +2538,6 @@ function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone
|
|||
/**
|
||||
* Calculates the required DST change and returns a Timestamp Array
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* @package core
|
||||
* @category time
|
||||
* @uses HOURSECS
|
||||
|
@ -2695,10 +2559,8 @@ function dst_changes_for_year($year, $timezone) {
|
|||
list($dsthour, $dstmin) = explode(':', $timezone->dst_time);
|
||||
list($stdhour, $stdmin) = explode(':', $timezone->std_time);
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian');
|
||||
$timedst = $calendarsystem_gregorian->make_timestamp($year, $timezone->dst_month, $monthdaydst, 0, 0, 0, 99, false);
|
||||
$timestd = $calendarsystem_gregorian->make_timestamp($year, $timezone->std_month, $monthdaystd, 0, 0, 0, 99, false);
|
||||
$timedst = make_timestamp($year, $timezone->dst_month, $monthdaydst, 0, 0, 0, 99, false);
|
||||
$timestd = make_timestamp($year, $timezone->std_month, $monthdaystd, 0, 0, 0, 99, false);
|
||||
|
||||
// Instead of putting hour and minute in make_timestamp(), we add them afterwards.
|
||||
// This has the advantage of being able to have negative values for hour, i.e. for timezones
|
||||
|
@ -2774,9 +2636,6 @@ function dst_offset_on($time, $strtimezone = null) {
|
|||
*/
|
||||
function find_day_in_month($startday, $weekday, $month, $year) {
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
$calendarsystem_gregorian = calendarsystem_plugin_factory::factory('gregorian');
|
||||
|
||||
$daysinmonth = days_in_month($month, $year);
|
||||
|
||||
if ($weekday == -1) {
|
||||
|
@ -2798,7 +2657,7 @@ function find_day_in_month($startday, $weekday, $month, $year) {
|
|||
if ($startday < 1) {
|
||||
|
||||
$startday = abs($startday);
|
||||
$lastmonthweekday = strftime('%w', $calendarsystem_gregorian->mktime(12, 0, 0, $month, $daysinmonth, $year));
|
||||
$lastmonthweekday = strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year));
|
||||
|
||||
// This is the last such weekday of the month.
|
||||
$lastinmonth = $daysinmonth + $weekday - $lastmonthweekday;
|
||||
|
@ -2815,7 +2674,7 @@ function find_day_in_month($startday, $weekday, $month, $year) {
|
|||
|
||||
} else {
|
||||
|
||||
$indexweekday = strftime('%w', $calendarsystem_gregorian->mktime(12, 0, 0, $month, $startday, $year));
|
||||
$indexweekday = strftime('%w', mktime(12, 0, 0, $month, $startday, $year));
|
||||
|
||||
$diff = $weekday - $indexweekday;
|
||||
if ($diff < 0) {
|
||||
|
@ -2846,8 +2705,6 @@ function days_in_month($month, $year) {
|
|||
/**
|
||||
* Calculate the position in the week of a specific calendar day
|
||||
*
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* @package core
|
||||
* @category time
|
||||
* @param int $day The day of the date whose position in the week is sought
|
||||
|
@ -2856,9 +2713,8 @@ function days_in_month($month, $year) {
|
|||
* @return int
|
||||
*/
|
||||
function dayofweek($day, $month, $year) {
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
global $CALENDARSYSTEM;
|
||||
return $CALENDARSYSTEM->dayofweek($day, $month, $year);
|
||||
// I wonder if this is any different from strftime('%w', mktime(12, 0, 0, $month, $daysinmonth, $year, 0));.
|
||||
return intval(date('w', mktime(12, 0, 0, $month, $day, $year)));
|
||||
}
|
||||
|
||||
// USER AUTHENTICATION AND LOGIN.
|
||||
|
|
|
@ -482,13 +482,6 @@ global $FULLSCRIPT;
|
|||
*/
|
||||
global $SCRIPT;
|
||||
|
||||
/**
|
||||
* MDL-18375, Multi-Calendar Support
|
||||
*
|
||||
* $CALENDARSYSTEM is a global that defines the calendar system
|
||||
*/
|
||||
global $CALENDARSYSTEM;
|
||||
|
||||
// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
||||
// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
|
@ -568,7 +561,7 @@ require_once($CFG->libdir .'/editorlib.php'); // All text editor related f
|
|||
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
|
||||
require_once($CFG->libdir .'/modinfolib.php'); // Cached information on course-module instances
|
||||
require_once($CFG->dirroot.'/cache/lib.php'); // Cache API
|
||||
require_once($CFG->dirroot . '/calendarsystem/calendarsystem.class.php'); // MDL-18375, Multi-Calendar Support
|
||||
require_once($CFG->dirroot.'/calendar/type/calendartype.class.php'); // Calendar type.
|
||||
|
||||
// make sure PHP is not severly misconfigured
|
||||
setup_validate_php_configuration();
|
||||
|
@ -979,26 +972,6 @@ if (isset($CFG->maintenance_later) and $CFG->maintenance_later <= time()) {
|
|||
}
|
||||
}
|
||||
|
||||
// MDL-18375, Multi-Calendar Support
|
||||
// note: do not accept calendarsystem parameter from POST
|
||||
if (isset($_GET['calendarsystem']) and ($calendarsystem = optional_param('calendarsystem', '', PARAM_SAFEDIR))) {
|
||||
if (file_exists($CFG->dirroot .'/calendarsystem/'. $calendarsystem)) {
|
||||
$SESSION->calendarsystem = $calendarsystem;
|
||||
}
|
||||
}
|
||||
|
||||
unset($calendarsystem);
|
||||
|
||||
if (empty($CFG->calendarsystem)) {
|
||||
if (empty($SESSION->calendarsystem)) {
|
||||
$CFG->calendarsystem = 'gregorian';
|
||||
} else {
|
||||
$CFG->calendarsystem = $SESSION->calendarsystem;
|
||||
}
|
||||
}
|
||||
|
||||
$CALENDARSYSTEM = calendarsystem_plugin_factory::factory();
|
||||
|
||||
// note: we can not block non utf-8 installations here, because empty mysql database
|
||||
// might be converted to utf-8 in admin/index.php during installation
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue