function actionDefault() { // Define the date format used for testing $fmt = '%A, %d %B %Y'; // Default locale is always en YDDebugUtil::dump(YDLocale::get(), 'Current locale:'); YDDebugUtil::dump(strftime($fmt), 'strftime test'); // Set the locale to English YDLocale::set('eng'); YDDebugUtil::dump(YDLocale::get(), 'Current locale:'); YDDebugUtil::dump(strftime($fmt), 'strftime test'); // Set the locale to Dutch YDLocale::set('nl'); YDDebugUtil::dump(YDLocale::get(), 'Current locale:'); YDDebugUtil::dump(strftime($fmt), 'strftime test'); YDDebugUtil::dump(date("l dS of F Y h:i:s A"), 'date function'); // Set the locale to Portugese YDLocale::set('ptg'); YDDebugUtil::dump(YDLocale::get(), 'Current locale:'); YDDebugUtil::dump(strftime($fmt), 'strftime test'); // Set the locale to Italian YDLocale::set('ita'); YDDebugUtil::dump(YDLocale::get(), 'Current locale:'); YDDebugUtil::dump(strftime($fmt), 'strftime test'); }
function t($t) { // Return empty string when param is missing if (empty($t)) { return ''; } // Load the language file @(include_once dirname(__FILE__) . '/languages/language_' . strtolower(YDLocale::get()) . '.php'); // Initialize the language array if (!isset($GLOBALS['t'])) { $GLOBALS['t'] = array(); } // Return the right translation $t = strtolower($t); return array_key_exists($t, $GLOBALS['t']) ? $GLOBALS['t'][$t] : "%{$t}%"; }
/** * This function will format a timestamp using the strftime function. * * @param $timestamp The timestamp to format. It can also be a date/time form object. * @param $format The strftime format to use. You can also use the predefined options date, time and * datetime. * @param $locale (optional) The locale to use to format the date. * * @returns A formatted timestamp * * @static */ function formatDate($timestamp, $format, $locale = null) { // Check if the timestamp is an object and has the getTimeStamp function if (is_object($timestamp) && method_exists($timestamp, 'getTimeStamp')) { $timestamp = $timestamp->getTimeStamp(); } // Convert to an integer if (is_numeric($timestamp)) { $timestamp = intval($timestamp); } // If text, convert to number if (is_string($timestamp)) { $timestamp = strtotime($timestamp); } // If array, is a date YDForm element value if (is_array($timestamp)) { // check if timestamp exists. otherwise create it $hours = isset($timestamp['hours']) ? $timestamp['hours'] : 0; $minutes = isset($timestamp['minutes']) ? $timestamp['minutes'] : 0; $seconds = isset($timestamp['seconds']) ? $timestamp['seconds'] : 0; $month = isset($timestamp['month']) ? $timestamp['month'] : 1; $day = isset($timestamp['day']) ? $timestamp['day'] : 1; $year = isset($timestamp['year']) ? $timestamp['year'] : 1970; $timestamp = mktime($hours, $minutes, $seconds, $month, $day, $year); } // Check the standard formats if (strtolower($format) == 'date') { $format = '%d %B %Y'; } if (strtolower($format) == 'datetime') { $format = '%d %B %Y %H:%M'; } if (strtolower($format) == 'datetimesql') { $format = '%Y-%m-%d %H:%M:%S'; } if (strtolower($format) == 'time') { $format = '%H:%M'; } if (strtolower($format) == 'file') { $format = '%d-%m-%Y %H:%M'; } // Set the new locale if (!is_null($locale)) { $currentLocale = YDLocale::get(); YDLocale::set($locale); } // Return the formatted date $timestamp = strftime($format, $timestamp); // Reset the old locale if (!is_null($locale)) { YDLocale::set($currentLocale); } // Return the timestamp return $timestamp; }
/** * This function will format a timestamp using the strftime function. * * @param $timestamp The timestamp to format. It can also be a date/time form object. * @param $format The strftime format to use. You can also use the predefined options date, time and * datetime. * @param $locale (optional) The locale to use to format the date. * * @returns A formatted timestamp * * @static */ function formatDate($timestamp, $format, $locale = null) { // Check if the timestamp is an object and has the getTimeStamp function if (is_object($timestamp) && method_exists($timestamp, 'getTimeStamp')) { $timestamp = $timestamp->getTimeStamp(); } // Convert to an integer if (is_numeric($timestamp)) { $timestamp = intval($timestamp); } // If text, convert to number if (is_string($timestamp)) { $timestamp = strtotime($timestamp); } // Check the standard formats if (strtolower($format) == 'date') { $format = '%d %B %Y'; } if (strtolower($format) == 'datetime') { $format = '%d %B %Y %H:%M'; } if (strtolower($format) == 'time') { $format = '%H:%M'; } // Set the new locale if (!is_null($locale)) { $currentLocale = YDLocale::get(); YDLocale::set($locale); } // Return the formatted date $timestamp = strftime($format, $timestamp); // Reset the old locale if (!is_null($locale)) { YDLocale::set($currentLocale); } // Return the timestamp return $timestamp; }
require_once 'includes/config.php'; // Include the Yellow Duck Framework require_once YD_INIT_FILE; // Include the classes needed on all pages YDInclude('YDForm.php'); YDInclude('YDRequest.php'); YDInclude('YDTemplate.php'); require_once 'includes/page.class.php'; require_once 'includes/users.class.php'; // Define the constants we want to override for the Framework //YDConfig::set( 'YD_DEBUG', 1 ); YDLocale::set(LOCALE); // Show all errors including notification of unset variables error_reporting(E_ALL); // Include the language file include_once dirname(__FILE__) . '/languages/language_' . strtolower(YDLocale::get()) . '.php'; // /** // * The t function used for translations // * @param t Code of the word to translate // * @return t corresponding string for the current locale // * // * For the moment the code must be in form module.word.or.more // * Every thing is currently in one file, could evolve if required // */ // function t( $t ) { // // // Return empty string when param is missing // if ( empty( $t ) ) { // return ''; // } //
/** * This function adds a new directory * * @param $dir Directory to add */ function addDirectory($dir) { if (!isset($GLOBALS['YD_LANGUAGES_DIRECTORIES'])) { $GLOBALS['YD_LANGUAGES_DIRECTORIES'] = array(); } $GLOBALS['YD_LANGUAGES_DIRECTORIES'][] = $dir; if (!isset($GLOBALS['t'])) { $GLOBALS['t'] = array(); } // just try to include language file @(include_once $dir . '/' . YDLocale::get() . '.php'); }
/** * This function return node attributes * * @returns An array with all attributes */ function getNode() { // delete previous stored values $this->resetAll(); // define our id to find $this->content_id = $this->_id; $this->language_id = YDLocale::get(); $this->limit(1); // find node $this->findAll(); // parse html if (isset($this->html)) { $this->html = htmlentities($this->html); } if (isset($this->xhtml)) { $this->xhtml = htmlentities($this->xhtml); } // return node attributes without relation prefixs return $this->getValues(false, false, false, false); }