Quellcode durchsuchen

Feature 272 - A workaround: Creation of a new function for formatting long dates, it should work on PHP 5.2.x and PHP 5.3+.

Ivan Tcholakov vor 15 Jahren
Ursprung
Commit
3aa3213d6b
2 geänderte Dateien mit 32 neuen und 6 gelöschten Zeilen
  1. 27 1
      main/inc/lib/internationalization.lib.php
  2. 5 5
      main/inc/lib/main_api.lib.php

+ 27 - 1
main/inc/lib/internationalization.lib.php

@@ -385,7 +385,7 @@ function api_detect_language(&$string, $encoding = null) {
  */
 
 /**
- * Returns formated date/time format correspondent to a given language.
+ * Returns formated date/time, correspondent to a given language.
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  * @author Christophe Gesche<gesche@ipm.ucl.ac.be>
  *         originally inspired from from PhpMyAdmin
@@ -431,6 +431,32 @@ function api_format_date($date_format, $time_stamp = -1, $language = null) {
 	return strftime($date_format, $time_stamp);
 }
 
+/**
+ * Returns date and time with long format correspondent to a given language.
+ * This function is a workaround, it is designed to work for PHP 5.2.x and PHP 5.3+.
+ * @author Ivan Tcholakov, 2010
+ * @param int $time_stamp (optional)	Time as an integer value. The default value -1 means now, the function time() is called internally.
+ * @param string $language (optional)	Language indentificator. If it is omited, the current interface language is assumed.
+ * @return string						Returns the formatted date.
+ */
+function api_format_date_time_long($time_stamp = -1, $language = null) {
+	static $date_formatter; // Holds the IntlDateFormatter object that should be created only once, for performance.
+	if ($time_stamp == -1) {
+		$time_stamp = time();
+	}
+	if (IS_PHP_53 && INTL_INSTALLED && !isset($date_formatter)) {
+		$locale = _api_get_locale_from_language($language);
+		$date_formatter = datefmt_create($locale, IntlDateFormatter::FULL, IntlDateFormatter::SHORT);
+		if (!is_object($date_formatter)) {
+			$date_formatter = false;
+		}
+	}
+	if ($date_formatter) {
+		return api_to_system_encoding(datefmt_format($date_formatter, $time_stamp), 'UTF-8');
+	}
+	return api_format_date(DATE_FORMAT_LONG, $time_stamp).'&nbsp;&nbsp;&nbsp;&nbsp;'.api_format_date(TIME_NO_SEC_FORMAT, $time_stamp);
+}
+
 /**
  * Returns an array of translated week days in short names.
  * @param string $language (optional)	Language indentificator. If it is omited, the current interface language is assumed.

+ 5 - 5
main/inc/lib/main_api.lib.php

@@ -2661,7 +2661,7 @@ function api_get_themes() {
  */
 function api_disp_html_area($name, $content = '', $height = '', $width = '100%', $attributes = null, $editor_config = null) {
 	global $_configuration, $_course, $fck_attribute;
-	require_once dirname(__FILE__).'/formvalidator/Element/html_editor.php';
+	require_once api_get_path(LIBRARY_PATH).'formvalidator/Element/html_editor.php';
 	$editor = new HTML_QuickForm_html_editor($name, null, $attributes, $editor_config);
 	$editor->setValue($content);
 	// The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
@@ -2676,7 +2676,7 @@ function api_disp_html_area($name, $content = '', $height = '', $width = '100%',
 
 function api_return_html_area($name, $content = '', $height = '', $width = '100%', $attributes = null, $editor_config = null) {
 	global $_configuration, $_course, $fck_attribute;
-	require_once(dirname(__FILE__).'/formvalidator/Element/html_editor.php');
+	require_once api_get_path(LIBRARY_PATH).'formvalidator/Element/html_editor.php';
 	$editor = new HTML_QuickForm_html_editor($name, null, $attributes, $editor_config);
 	$editor->setValue($content);
 	// The global variable $fck_attribute has been deprecated. It stays here for supporting old external code.
@@ -4347,21 +4347,21 @@ function api_get_local_time($time, $format=null, $to_timezone=null, $from_timezo
 	}
 	// If time is a timestamp, convert it to a string
 	if (is_int($time)) {
-		$time = date("Y-m-d H:i:s", $time);
+		$time = date('Y-m-d H:i:s', $time);
 	}
 	try {
 		$date = new DateTime($time, new DateTimezone($from_timezone));
 		$date->setTimezone(new DateTimeZone($to_timezone));
 		// In the following case, the format is an internal Chamilo format, so we are using api_format_date
 		if (is_int($format) || strpos($format, '%') !== false) {
-			return api_format_date($format, strtotime($date->format("Y-m-d H:i:s")));
+			return api_format_date($format, strtotime($date->format('Y-m-d H:i:s')));
 		} else {
 			if ($format_null && IS_PHP_53) {
 				// use IntlDateFormatter to localize the date in the language of the user
 				$locale = api_get_language_isocode();
 				// TODO: This instance of IntlDateFormatter is better to be cached for each locale. It is for speed, api_get_local_time() is called repetitively in tables.
 				$date_formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::SHORT);
-				return api_to_system_encoding($date_formatter->format(strtotime($date->format("Y-m-d H:i:s"))), 'UTF-8');
+				return api_to_system_encoding($date_formatter->format(strtotime($date->format('Y-m-d H:i:s'))), 'UTF-8');
 			} else {
 				return $date->format($format);
 			}