// Copyright: Copyright (C) 2002-2007 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/gettext.inc.php"; require_once "monica/lninfo.inc.php"; require_once "monica/login.inc.php"; require_once "monica/markabbr.inc.php"; // err2msg: Compose the error message from the $error array function err2msg($error) { $msgs = _errmsg_array_errors_to_msg($error); switch (count($msgs)) { case 0: return ""; case 1: return $msgs[0]; default: for ($i = 0; $i < count($msgs); $i++) { $msgs[$i] = "
  • $msgs[$i]
  • \n"; } return "\n"; } } // _errmsg_array_errors_to_msg: Compose error messages from the $errors array function _errmsg_array_errors_to_msg($errors) { $msgs = array(); // A single error if (!array_key_exists("errors", $errors)) { $msg = _errmsg_single_error_to_msg($errors); if (!is_null($msg)) { $msgs[] = $msg; } // An array of errors } else { foreach ($errors["errors"] as $error) { $msgs = array_merge($msgs, _errmsg_array_errors_to_msg($error)); } } return $msgs; } // _errmsg_single_error_to_msg: Compose a single error message from the $error array function _errmsg_single_error_to_msg($error) { // Nothing if (!array_key_exists("msg", $error)) { return null; } // Normal gettext $msg = $error["msg"]; if (!is_array($msg)) { $msg = _($msg); // Complex format } else { switch (count($msg)) { // 2 arguments: dgettext(domain, text) case 2: $msg = dgettext($msg[0], $msg[1]); break; // 3 arguments: ngettext(singular, plural, number) case 3: $msg = ngettext($msg[0], $msg[1], $msg[2]); break; // 4 arguments: dngettext(domain, singular, plural, number) case 4: $msg = dngettext($msg[0], $msg[1], $msg[2], $msg[3]); break; } } // Substitute the arguments if (array_key_exists("margs", $error)) { $margs = $error["margs"]; // Replace variables for ($i = 0; $i < count($margs); $i++) { switch ($margs[$i]) { case "_USERNAME": $margs[$i] = get_login_name(); break; case "_DEFAULT_LANG": $margs[$i] = ln(DEFAULT_LANG, LN_DESC_CURLC); break; default: $margs[$i] = $margs[$i]; break; } } $msg = vsprintf($msg, $margs); } return markabbr($msg); } ?>