OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / scripts / kcfinder-2.51 / lib / helper_text.php
1 <?php
2
3 /** This file is part of KCFinder project
4   *
5   *      @desc Text processing helper class
6   *   @package KCFinder
7   *   @version 2.51
8   *    @author Pavel Tzonkov <pavelc@users.sourceforge.net>
9   * @copyright 2010, 2011 KCFinder Project
10   *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11   *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12   *      @link http://kcfinder.sunhater.com
13   */
14
15 class text {
16
17   /** Replace repeated white spaces to single space
18     * @param string $string
19     * @return string */
20
21     static function clearWhitespaces($string) {
22         return trim(preg_replace('/\s+/s', " ", $string));
23     }
24
25   /** Normalize the string for HTML attribute value
26     * @param string $string
27     * @return string */
28
29     static function htmlValue($string) {
30         return
31             str_replace('"', "&quot;",
32             str_replace("'", '&#39;',
33             str_replace('<', '&lt;',
34             str_replace('&', "&amp;",
35         $string))));
36     }
37
38   /** Normalize the string for JavaScript string value
39     * @param string $string
40     * @return string */
41
42     static function jsValue($string) {
43         return
44             preg_replace('/\r?\n/', "\\n",
45             str_replace('"', "\\\"",
46             str_replace("'", "\\'",
47             str_replace("\\", "\\\\",
48         $string))));
49     }
50
51   /** Normalize the string for XML tag content data
52     * @param string $string
53     * @param bool $cdata */
54
55     static function xmlData($string, $cdata=false) {
56         $string = str_replace("]]>", "]]]]><![CDATA[>", $string);
57         if (!$cdata)
58             $string = "<![CDATA[$string]]>";
59         return $string;
60     }
61
62   /** Returns compressed content of given CSS code
63     * @param string $code
64     * @return string */
65
66     static function compressCSS($code) {
67         $code = self::clearWhitespaces($code);
68         $code = preg_replace('/ ?\{ ?/', "{", $code);
69         $code = preg_replace('/ ?\} ?/', "}", $code);
70         $code = preg_replace('/ ?\; ?/', ";", $code);
71         $code = preg_replace('/ ?\> ?/', ">", $code);
72         $code = preg_replace('/ ?\, ?/', ",", $code);
73         $code = preg_replace('/ ?\: ?/', ":", $code);
74         $code = str_replace(";}", "}", $code);
75         return $code;
76     }
77 }
78
79 ?>