-
Notifications
You must be signed in to change notification settings - Fork 4
/
string.php
110 lines (92 loc) · 2.62 KB
/
string.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* @package com_zoo
* @author YOOtheme http://www.yootheme.com
* @copyright Copyright (C) YOOtheme GmbH
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
*/
/**
* The general String Helper.
*
* @package Component.Helpers
* @since 2.0
*/
class StringHelper extends AppHelper {
/**
* wrapped class
* @var string
*/
protected $_class = 'JString';
/**
* Map all functions to JRequest class
*
* @param string $method Method name
* @param array $args Method arguments
*
* @return mixed
*/
public function __call($method, $args) {
return $this->_call(array($this->_class, $method), $args);
}
/**
* Truncates the input string.
*
* @param string $text input string
* @param int $length the length of the output string
* @param string $truncate_string the truncate string
*
* @return string The truncated string
* @since 2.0
*/
public function truncate($text, $length = 30, $truncate_string = '...') {
if ($text == '') {
return '';
}
if ($this->strlen($text) > $length) {
$length -= min($length, strlen($truncate_string));
$text = preg_replace('/\s+?(\S+)?$/', '', substr($text, 0, $length + 1));
return $this->substr($text, 0, $length).$truncate_string;
} else {
return $text;
}
}
/**
* Sluggifies the input string.
*
* @param string $string input string
* @param bool $force_safe Do we have to enforce ASCII instead of UTF8 (default: false)
*
* @return string sluggified string
* @since 2.0
*/
public function sluggify($string, $force_safe = false) {
// zoo_hack_start
static $cache = array();
if (!isset($cache[$string])) { // performance bug
$string = $this->strtolower((string)$string);
$string = $this->str_ireplace(array('$', ','), '', $string);
if ($force_safe) {
$string = JFilterOutput::stringURLSafe($string);
} else {
$string = JApplication::stringURLSafe($string);
}
$cache[$string] = trim($string);
}
return $cache[$string];
// zoo_hack_end
}
/**
* Apply Joomla text filters based on the user's groups
*
* @param string $string The string to clean
*
* @return string The cleaned string
*/
public function applyTextFilters($string) {
// Apply the textfilters (let's reuse Joomla's ContentHelper class)
if (!class_exists('ContentHelper')) {
require_once JPATH_SITE . '/administrator/components/com_content/helpers/content.php';
}
return ContentHelper::filterText((string) $string);
}
}