Horde_View_Helper_Text
extends Horde_View_Helper_Base
in package
View helpers for text
Tags
Table of Contents
- $_cycles : array<string|int, mixed>
- $_inflector : Horde_Support_Inflector
- $_view : Horde_View
- The parent view invoking the helper.
- __call() : mixed
- Call chaining so members of the view can be called (including other helpers).
- __construct() : mixed
- Creates a helper for $view.
- __get() : mixed
- Proxy on undefined property access (get).
- __set() : mixed
- Proxy on undefined property access (set).
- cleanSmartQuotes() : string
- Removes smart quotes.
- cycle() : mixed
- Creates a Cycle object whose __toString() method cycles through elements of an array every time it is called.
- h() : mixed
- Escapes a value for output in a view template.
- highlight() : string
- Highlights a phrase where it is found in the text by surrounding it like <strong class="highlight">I'm highlighted</strong>.
- makeBreakable() : string
- Inserts HTML code to allow linebreaks in a string after slashes or underscores.
- pluralize() : mixed
- Pluralizes the $singular word unless $count is one. If $plural form is not supplied, inflector will be used.
- resetCycle() : mixed
- Resets a cycle so that it starts from the first element the next time it is called.
- truncate() : string
- If $text is longer than $length, $text will be truncated to the length of $length and the last three characters will be replaced with the $truncateString.
- truncateMiddle() : string
- Limits a string to a given maximum length in a smarter way than just using substr().
Properties
$_cycles
protected
array<string|int, mixed>
$_cycles
= array()
$_inflector
protected
Horde_Support_Inflector
$_inflector
$_view
The parent view invoking the helper.
protected
Horde_View
$_view
Methods
__call()
Call chaining so members of the view can be called (including other helpers).
public
__call(string $method, array<string|int, mixed> $args) : mixed
Parameters
- $method : string
-
The method.
- $args : array<string|int, mixed>
-
The parameters for the method.
Return values
mixed —The result of the method.
__construct()
Creates a helper for $view.
public
__construct(Horde_View $view) : mixed
Parameters
- $view : Horde_View
-
The view to help.
Return values
mixed —__get()
Proxy on undefined property access (get).
public
__get(mixed $name) : mixed
Parameters
- $name : mixed
Return values
mixed —__set()
Proxy on undefined property access (set).
public
__set(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : mixed
Return values
mixed —cleanSmartQuotes()
Removes smart quotes.
public
cleanSmartQuotes(string $str) : string
Parameters
- $str : string
-
A string with potential smart quotes.
Tags
Return values
string —The cleaned-up string.
cycle()
Creates a Cycle object whose __toString() method cycles through elements of an array every time it is called.
public
cycle(mixed $firstValue) : mixed
This can be used for example, to alternate classes for table rows:
">
item
You can use named cycles to allow nesting in loops. Passing an array as the last parameter with a name key will create a named cycle. You can manually reset a cycle by calling resetCycle() and passing the name of the cycle:
values as $value): ?>
resetCycle('colors') ?>
Parameters
- $firstValue : mixed
Return values
mixed —h()
Escapes a value for output in a view template.
public
h(mixed $var) : mixed
h($this->templateVar) ?>
Parameters
- $var : mixed
-
The output to escape.
Return values
mixed —The escaped value.
highlight()
Highlights a phrase where it is found in the text by surrounding it like <strong class="highlight">I'm highlighted</strong>.
public
highlight(string $text, string $phrase[, string $highlighter = null ]) : string
The Highlighter can be customized by passing $highlighter as a string containing $1 as a placeholder where the phrase is supposed to be inserted.
Parameters
- $text : string
-
A text containing phrases to highlight.
- $phrase : string
-
A phrase to highlight in $text.
- $highlighter : string = null
-
A highlighting replacement.
Return values
string —The highlighted text.
makeBreakable()
Inserts HTML code to allow linebreaks in a string after slashes or underscores.
public
makeBreakable(string $str) : string
Parameters
- $str : string
-
A string to mark up with linebreak markers.
Return values
string —The marked-up string.
pluralize()
Pluralizes the $singular word unless $count is one. If $plural form is not supplied, inflector will be used.
public
pluralize(int $count, string $singular[, string $plural = null ]) : mixed
Parameters
- $count : int
-
Count determines singular or plural.
- $singular : string
-
Singular form.
- $plural : string = null
-
Plural form (optional).
Return values
mixed —resetCycle()
Resets a cycle so that it starts from the first element the next time it is called.
public
resetCycle([string $name = 'default' ]) : mixed
Pass in $name to reset a named cycle.
Parameters
- $name : string = 'default'
-
Name of cycle to reset.
Return values
mixed —truncate()
If $text is longer than $length, $text will be truncated to the length of $length and the last three characters will be replaced with the $truncateString.
public
truncate(string $text[, int $length = 30 ][, string $truncateString = '...' ]) : string
$this->truncate('Once upon a time in a world far far away', 14);
// => Once upon a...
Parameters
- $text : string
-
A text to truncate.
- $length : int = 30
-
The maximum length of the text
- $truncateString : string = '...'
-
Replacement string for the truncated text.
Return values
string —The truncated text.
truncateMiddle()
Limits a string to a given maximum length in a smarter way than just using substr().
public
truncateMiddle(string $str[, int $maxLength = 80 ][, string $joiner = '...' ]) : string
Namely, cut from the MIDDLE instead of from the end so that if we're doing this on (for instance) a bunch of binder names that start off with the same verbose description, and then are different only at the very end, they'll still be different from one another after truncating.
$str = 'The quick brown fox jumps over the lazy dog tomorrow morning.';
$shortStr = $this->truncateMiddle($str, 40);
// $shortStr == 'The quick brown fox... tomorrow morning.'
Parameters
- $str : string
-
A text to truncate.
- $maxLength : int = 80
-
The maximum length of the text
- $joiner : string = '...'
-
Replacement string for the truncated text.
Return values
string —The truncated text.