*
{bold}, {endbold}: All text between these tags is printed bold. *
{color=#123456}, {endcolor}: All text between these tags is printed in the given color. *
{link=http://nodomain.org}, {endlink}: A link with the given target is created. The link text is the text between the tags. * * @param string $MessageTyp The type of the message to be printed. It must be one of * the following types: 'INFO', 'WARN' or 'ERROR'. *
Every other type will lead to an error message indicating an invalid message type. * @param string $MessageHeadline The headline of the status message. *
It may be formatted with special color/link/bold tags. * @param string $MessageText The text of the status message. *
It may be formatted with special color/link/bold tags. This parameter is optional. * @param array $MessageVariables The variables that are used to replace the spacers (%s) in the * submitted text. This parameter is optional. * @param boolean $returnOutput if set to true this function will return the generated HTML code instead of printing it directly (default: false) * @return String HTML code if $returnOutput is set to true, otherwise null */ function StatusMessage($MessageTyp,$MessageHeadline,$MessageText='',$MessageVariables = array(), $returnOutput = false) { /* Setting CSS-StyleSheet class depending on the $MessageTyp and rewriting $MessageTyp with a readable string. */ if($MessageTyp == "INFO") { $class = "class=\"statusInfo ui-corner-all\""; } elseif($MessageTyp == "WARN") { $class = "class=\"statusWarn ui-corner-all\""; } elseif($MessageTyp == "ERROR") { $class = "class=\"statusError ui-corner-all\""; } /* Set output-message, when none or false $MessageTyp is submitted. */ else { $class = "class=\"statusError ui-corner-all\""; $MessageTyp = "ERROR"; $MessageHeadline = "Invalid/Missing Message type"; $MessageText = "Please report this error to the Bug-Tracker at {link=http://www.ldap-account-manager.org/}LDAP Account Manager Development Team{endlink}. Thank you."; } $MessageHeadline = parseMessageString($MessageHeadline); $MessageText = parseMessageString($MessageText); $MessageHeadline = "
" . $MessageHeadline . "
"; // Format $MessageHeadline if ($MessageText != '') { $MessageText = "

" . $MessageText . "

"; // Format $MessageText } $format = "
\n\n\n\n\n
" . $MessageHeadline . $MessageText . "
\n
\n"; $output = ''; if (is_array($MessageVariables)) { if (sizeof($MessageVariables) > 0) { array_unshift($MessageVariables, $format); $output = call_user_func_array('sprintf',$MessageVariables); } else { $output = $format; } } else { $output = sprintf($format, $MessageVariables); } if ($returnOutput) { return $output; } else { echo $output; } return null; } /** * Use the three replace functions on the submitted Text. * * @access private * * @param string $MessageString The text that is used to search for replaceable strings. * * @return string The processed text. */ function parseMessageString($MessageString) { return linkText(colorText(boldText($MessageString))); } /** * Replace {bold} and {endbold} with and HTML-Tags. * * @access private * * @param string $text The text that is used to search for {bold} and {endbold} tags. * * @return string The submitted text with {bold} and {endbold} replaced with * the appropriate HTML tages and */ function boldText($text) { $pattern = "/\\{bold\\}([^{]*)\\{endbold\\}/"; // Regular expression matching {bold}[Text]{endbold} $replace = "\\1"; // Replace pattern return preg_replace($pattern,$replace,$text); } /** * Replace {color=#[HEX-Value]} or {color=[HEX-Value]} and {endcolor} with and HTML-Tags. * * @access private * * @param string $text The text that is used to search for {color} and {endcolor} tags. * * @return string Input string with HTML-formatted color tags */ function colorText($text) { $pattern = "/\\{color=#?([0-9,a-f,A-F]{6})\\}([^{]*)\\{endcolor\\}/"; // Regular expression matching {color=#[HEX-Value]}[Text]{endcolor} or {color=[HEX-Value]}[Text]{endcolor} $replace = "\\2"; // Replace pattern return preg_replace($pattern,$replace,$text); } /** * Replace {link=[Link-Target]} and {endlink} with and HTML-Tags. * * @access private * * @param string $text The text that is used to search for {link} and {endlink} tags. * * @return string Input string with HTML-formatted link tags */ function linkText($text) { $pattern = "/\\{link=([^}]*)\\}([^{]*)\\{endlink\\}/"; // Regular expression matching {link=[Link-Target]}[Text]{endlink} $replace = "\\2"; //Replace pattern return preg_replace($pattern,$replace,$text); } ?>