/** Shows a message to the standard output. * This function shows a predefined message to the standard output. Unlike the printText function (which is a low-level function), * this one translates the message in the current locale, date it and adds a tag to it. It also writes it on the program log. * For proper translations, the message needs to be separated from his variable parts. For this, you can use \$X for a varaiable, * where X corresponds to the key for the value in the $args array * * \param $message The message to show. It will be translated according to the translation tables available. * \param $args The variables to bind with the identifiers in $message. * \param $type The type of the message. Available types are based on PHP error types constants (user errors constants, i.e. starting with "E_USER" * are also available) : * \li E_NOTICE : A notice message (useful for debug and info messages). The default. * \li E_WARNING : A non-fatal error. * \li E_ERROR : A fatal error. The program is expected to end after an error of this type. * \param $force Forces the message to be displayed, even if verbose mode is not enabled * \param $translate Indicates if the message has to be translated. * \return TRUE if the message has been correctly displayed, FALSE if an error occured. */ public static function message($message, $args = array(), $type = E_NOTICE, $force = FALSE, $translate = TRUE) { $verbosity = 1; $prefix = ""; //Getting type string switch ($type) { case E_NOTICE: case E_USER_NOTICE: $prefix = 'Notice'; break; case E_WARNING: case E_USER_WARNING: $prefix = 'Warning'; if (PHP_OS == 'Linux') { //If we are on Linux, we use colors echo "[0;33m"; } break; case E_ERROR: case E_USER_ERROR: $prefix = 'Error'; $force = TRUE; $verbosity = 0; if (PHP_OS == 'Linux') { //If we are on Linux, we use colors (yes, I comment twice) echo "[0;31m"; } break; case E_DEBUG: $prefix = 'Debug'; $verbosity = 2; break; default: $prefix = 'Unknown'; } //Translating prefix if ($translate) { $prefix = Leelabot::$instance->intl->translate($prefix); } //Translating message if ($translate) { $message = Leelabot::$instance->intl->translate($message); } //Parsing message vars if (!is_array($args)) { $args = array($args); } foreach ($args as $id => $value) { $message = str_replace('$' . $id, $value, $message); } if (in_array($type, array(E_USER_ERROR, E_ERROR, E_WARNING, E_USER_WARNING))) { Leelabot::$_lastError = $message; } //Put it in log, if is opened if (Leelabot::$_logFile) { fputs(Leelabot::$_logFile, date($translate ? Leelabot::$instance->intl->getDateTimeFormat() : "m/d/Y h:i:s A") . ' -- ' . $prefix . ' -- ' . $message . PHP_EOL); } if (Leelabot::$verbose >= $verbosity || $force) { echo date($translate ? Leelabot::$instance->intl->getDateTimeFormat() : "m/d/Y h:i:s A") . ' -- ' . $prefix . ' -- ' . $message . PHP_EOL; if (PHP_OS == 'Linux') { echo "[0m"; } } }