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