[18220] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 4 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 5 | * this work for additional information regarding copyright ownership. |
---|
| 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 7 | * (the "License"); you may not use this file except in compliance with |
---|
| 8 | * the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | * |
---|
| 18 | * |
---|
| 19 | * @package log4php |
---|
| 20 | * @subpackage helpers |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * @ignore |
---|
| 25 | */ |
---|
| 26 | if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); |
---|
| 27 | |
---|
| 28 | define('LOG4PHP_LOGGER_TRANSFORM_CDATA_START', '<![CDATA['); |
---|
| 29 | define('LOG4PHP_LOGGER_TRANSFORM_CDATA_END', ']]>'); |
---|
| 30 | define('LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END', ']]>'); |
---|
| 31 | define('LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END', |
---|
| 32 | LOG4PHP_LOGGER_TRANSFORM_CDATA_END . |
---|
| 33 | LOG4PHP_LOGGER_TRANSFORM_CDATA_PSEUDO_END . |
---|
| 34 | LOG4PHP_LOGGER_TRANSFORM_CDATA_START |
---|
| 35 | ); |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * Utility class for transforming strings. |
---|
| 39 | * |
---|
| 40 | * @author Marco Vassura |
---|
| 41 | * @package log4php |
---|
| 42 | * @subpackage helpers |
---|
| 43 | * @since 0.7 |
---|
| 44 | */ |
---|
| 45 | class LoggerTransform { |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * This method takes a string which may contain HTML tags (ie, |
---|
| 49 | * <b>, <table>, etc) and replaces any '<' and '>' |
---|
| 50 | * characters with respective predefined entity references. |
---|
| 51 | * |
---|
| 52 | * @param string $input The text to be converted. |
---|
| 53 | * @return string The input string with the characters '<' and '>' replaced with |
---|
| 54 | * &lt; and &gt; respectively. |
---|
| 55 | * @static |
---|
| 56 | */ |
---|
| 57 | function escapeTags($input) |
---|
| 58 | { |
---|
| 59 | //Check if the string is null or zero length -- if so, return |
---|
| 60 | //what was sent in. |
---|
| 61 | |
---|
| 62 | if(empty($input)) |
---|
| 63 | return $input; |
---|
| 64 | |
---|
| 65 | //Use a StringBuffer in lieu of String concatenation -- it is |
---|
| 66 | //much more efficient this way. |
---|
| 67 | |
---|
| 68 | return htmlspecialchars($input, ENT_NOQUOTES); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * Ensures that embeded CDEnd strings (]]>) are handled properly |
---|
| 73 | * within message, NDC and throwable tag text. |
---|
| 74 | * |
---|
| 75 | * @param string $buf String holding the XML data to this point. The |
---|
| 76 | * initial CDStart (<![CDATA[) and final CDEnd (]]>) |
---|
| 77 | * of the CDATA section are the responsibility of |
---|
| 78 | * the calling method. |
---|
| 79 | * @param string &str The String that is inserted into an existing |
---|
| 80 | * CDATA Section within buf. |
---|
| 81 | * @static |
---|
| 82 | */ |
---|
| 83 | function appendEscapingCDATA(&$buf, $str) |
---|
| 84 | { |
---|
| 85 | if(empty($str)) |
---|
| 86 | return; |
---|
| 87 | |
---|
| 88 | $rStr = str_replace( |
---|
| 89 | LOG4PHP_LOGGER_TRANSFORM_CDATA_END, |
---|
| 90 | LOG4PHP_LOGGER_TRANSFORM_CDATA_EMBEDDED_END, |
---|
| 91 | $str |
---|
| 92 | ); |
---|
| 93 | $buf .= $rStr; |
---|
| 94 | } |
---|
| 95 | } |
---|