1: <?php
2:
3: /**
4: * This file contains CONTENIDO String API functions.
5: *
6: * If you are planning to add a function, please make sure that:
7: * 1.) The function is in the correct place
8: * 2.) The function is documented
9: * 3.) The function makes sense and is generally usable
10: *
11: * @package Core
12: * @subpackage Backend
13: * @author Timo Hummel
14: * @copyright four for business AG <www.4fb.de>
15: * @license http://www.contenido.org/license/LIZENZ.txt
16: * @link http://www.4fb.de
17: * @link http://www.contenido.org
18: */
19:
20: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
21:
22: /**
23: * Trims a string to a given length and makes sure that all words up to $maxlen
24: * are preserved, without exceeding $maxlen.
25: *
26: * Warning: Currently, this function uses a regular ASCII-Whitespace to do the
27: * separation test. If you are using ' ' to create spaces, this function
28: * will fail.
29: *
30: * Example:
31: * $string = "This is a simple test";
32: * echo cApiStrTrimAfterWord($string, 15);
33: *
34: * This would output "This is a", since this function respects word boundaries
35: * and doesn't operate beyond the limit given by $maxlen.
36: *
37: * @deprecated [2015-05-21]
38: * use cString::trimAfterWord
39: * @param string $string
40: * The string to operate on
41: * @param int $maxlen
42: * The maximum number of characters
43: * @return string
44: * The resulting string
45: */
46: function cApiStrTrimAfterWord($string, $maxlen) {
47: cDeprecated('This method is deprecated and is not needed any longer');
48: return cString::trimAfterWord($string, $maxlen);
49: }
50:
51: /**
52: * Trims a string to a specific length.
53: * If the string is longer than $maxlen,
54: * dots are inserted ("...") right before $maxlen.
55: *
56: * Example:
57: * $string = "This is a simple test";
58: * echo cApiStrTrimHard ($string, 15);
59: *
60: * This would output "This is a si...", since the string is longer than $maxlen
61: * and the resulting string matches 15 characters including the dots.
62: *
63: * @deprecated [2015-05-21]
64: * use cString::trimHard() instead
65: * @param string $string
66: * The string to operate on
67: * @param int $maxlen
68: * The maximum number of characters
69: * @param string $fillup [optional]
70: * @return string
71: * The resulting string
72: */
73: function cApiStrTrimHard($string, $maxlen, $fillup = '...') {
74: cDeprecated('This method is deprecated and is not needed any longer');
75: return cString::trimHard($string, $maxlen, $fillup);
76: }
77:
78: /**
79: * Trims a string to a approximate length.
80: * Sentence boundaries are preserved.
81: *
82: * The algorithm inside calculates the sentence length to the previous and next
83: * sentences. The distance to the next sentence which is smaller will be taken
84: * to
85: * trim the string to match the approximate length parameter.
86: *
87: * Example:
88: *
89: * $string = "This contains two sentences. ";
90: * $string .= "Lets play around with them. ";
91: *
92: * echo cApiStrTrimSentence($string, 40);
93: * echo cApiStrTrimSentence($string, 50);
94: *
95: * The first example would only output the first sentence, the second example
96: * both
97: * sentences.
98: *
99: * Explanation:
100: *
101: * To match the given max length closely, the function calculates the distance
102: * to
103: * the next and previous sentences. Using the maxlength of 40 characters, the
104: * distance to the previous sentence would be 8 characters, and to the next
105: * sentence
106: * it would be 19 characters. Therefore, only the previous sentence is
107: * displayed.
108: *
109: * The second example displays the second sentence also, since the distance to
110: * the
111: * next sentence is only 9 characters, but to the previous it is 18 characters.
112: *
113: * If you specify the boolean flag "$hard", the limit parameter creates a hard
114: * limit
115: * instead of calculating the distance.
116: *
117: * This function ensures that at least one sentence is returned.
118: *
119: * @deprecated [2015-05-21]
120: * use cString::trimSentence
121: * @param string $string
122: * The string to operate on
123: * @param int $approxlen
124: * The approximate number of characters
125: * @param bool $hard [optional]
126: * If true, use a hard limit for the number of characters
127: * @return string
128: * The resulting string
129: */
130: function cApiStrTrimSentence($string, $approxlen, $hard = false) {
131: cDeprecated('This method is deprecated and is not needed any longer');
132: return cString::trimSentence($string, $approxlen, $hard);
133: }
134:
135: /**
136: * Converts diactritics to english characters whenever possible.
137: *
138: * For german umlauts, this function converts the umlauts to their ASCII
139: * equivalents (e.g. รค => ae).
140: *
141: * For more information about diacritics, refer to
142: * http://en.wikipedia.org/wiki/Diacritic
143: *
144: * For other languages, the diacritic marks are removed, if possible.
145: *
146: * @deprecated [2015-05-21]
147: * use cString::replaceDiacritics
148: * @param string $sString
149: * The string to operate on
150: * @param string $sourceEncoding [optional; default: UTF-8]
151: * The source encoding
152: * @param string $targetEncoding [optional; default: UTF-8]
153: * The target encoding
154: * @return string
155: * The resulting string
156: */
157: function cApiStrReplaceDiacritics($sString, $sourceEncoding = 'UTF-8', $targetEncoding = 'UTF-8') {
158: cDeprecated('This method is deprecated and is not needed any longer');
159: return cString::replaceDiacritics($sString, $sourceEncoding, $targetEncoding);
160: }
161:
162: /**
163: * Converts a string to another encoding.
164: * This function tries to detect which function
165: * to use (either recode or iconv).
166: *
167: * If $sourceEncoding and $targetEncoding are the same, this function returns
168: * immediately.
169: *
170: * For more information about encodings, refer to
171: * http://en.wikipedia.org/wiki/Character_encoding
172: *
173: * For more information about the supported encodings in recode, refer to
174: * http://www.delorie.com/gnu/docs/recode/recode_toc.html
175: *
176: * Note: depending on whether recode or iconv is used, the supported charsets
177: * differ. The following ones are commonly used and are most likely supported by
178: * both converters:
179: *
180: * - ISO-8859-1 to ISO-8859-15
181: * - ASCII
182: * - UTF-8
183: *
184: * @deprecated [2015-05-21]
185: * use cString::recodeString
186: * @todo Check if the charset names are the same for both converters
187: * @todo Implement a converter and charset checker to ensure compilance.
188: * @param string $sString
189: * The string to operate on
190: * @param string $sourceEncoding
191: * The source encoding (default: ISO-8859-1)
192: * @param string $targetEncoding
193: * The target encoding (if false, use source encoding)
194: * @return string
195: * The resulting string
196: */
197: function cApiStrRecodeString($sString, $sourceEncoding, $targetEncoding) {
198: cDeprecated('This method is deprecated and is not needed any longer');
199: return cString::recodeString($sString, $sourceEncoding, $targetEncoding);
200: }
201:
202: /**
203: * Removes or converts all "evil" URL characters.
204: * This function removes or converts
205: * all characters which can make an URL invalid.
206: *
207: * Clean characters include:
208: * - All characters between 32 and 126 which are not alphanumeric and
209: * aren't one of the following: _-.
210: *
211: * @deprecated [2015-05-21]
212: * use cString::cleanURLCharacters
213: * @param string $sString
214: * The string to operate on
215: * @param bool $bReplace [optional]
216: * If true, all "unclean" characters are replaced
217: * @return string
218: * The resulting string
219: */
220: function cApiStrCleanURLCharacters($sString, $bReplace = false) {
221: cDeprecated('This method is deprecated and is not needed any longer');
222: return cString::cleanURLCharacters($sString, $bReplace);
223: }
224:
225: /**
226: * Normalizes line endings in passed string.
227: *
228: * @deprecated [2015-05-21]
229: * use cString::normalizeLineEndings
230: * @param string $sString
231: * @param string $sLineEnding
232: * Feasible values are "\n", "\r" or "\r\n"
233: * @return string
234: */
235: function cApiStrNormalizeLineEndings($sString, $sLineEnding = "\n") {
236: cDeprecated('This method is deprecated and is not needed any longer');
237: return cString::normalizeLineEndings($sString, $sLineEnding);
238: }
239: