\Horde_View_Helper_Text

View helpers for text

All helpers hold a link back to the instance of the view. The undefined property handlers (get()/call() methods) are used to mix helpers together, effectively placing them on the same pane of glass (the view) and allowing any helper to call any other.

Summary

Methods
Properties
Constants
__construct()
__get()
__set()
__call()
h()
pluralize()
cycle()
resetCycle()
highlight()
truncate()
truncateMiddle()
makeBreakable()
cleanSmartQuotes()
No public properties found
No constants found
No protected methods found
$_view
$_cycles
$_inflector
N/A
No private methods found
No private properties found
N/A

Properties

$_view

$_view : \Horde_View

The parent view invoking the helper.

Type

\Horde_View

$_cycles

$_cycles : array

Type

array

$_inflector

$_inflector : \Horde_Support_Inflector

Type

\Horde_Support_Inflector

Methods

__construct()

__construct(\Horde_View  $view) 

Creates a helper for $view.

Parameters

\Horde_View $view

The view to help.

__get()

__get(  $name) 

Proxy on undefined property access (get).

Parameters

$name

__set()

__set(  $name,   $value) 

Proxy on undefined property access (set).

Parameters

$name
$value

__call()

__call(string  $method, array  $args) : mixed

Call chaining so members of the view can be called (including other helpers).

Parameters

string $method

The method.

array $args

The parameters for the method.

Returns

mixed —

The result of the method.

h()

h(mixed  $var) : mixed

Escapes a value for output in a view template.

h($this->templateVar) ?>

Parameters

mixed $var

The output to escape.

Returns

mixed —

The escaped value.

pluralize()

pluralize(integer  $count, string  $singular, string  $plural = null) 

Pluralizes the $singular word unless $count is one. If $plural form is not supplied, inflector will be used.

Parameters

integer $count

Count determines singular or plural.

string $singular

Singular form.

string $plural

Plural form (optional).

cycle()

cycle(  $firstValue) 

Creates a Cycle object whose __toString() method cycles through elements of an array every time it is called.

This can be used for example, to alternate classes for table rows:

<?php foreach($items as $item): ?> <tr class="<?php echo $this->cycle("even", "odd") ?>">

item

<?php endforeach ?>

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:

<?php foreach($items as $item): ?>

values as $value): ?> resetCycle('colors') ?>

<?php endforeach ?>

Parameters

$firstValue

resetCycle()

resetCycle(string  $name = 'default') 

Resets a cycle so that it starts from the first element the next time it is called.

Pass in $name to reset a named cycle.

Parameters

string $name

Name of cycle to reset.

highlight()

highlight(string  $text, string  $phrase, string  $highlighter = null) : string

Highlights a phrase where it is found in the text by surrounding it like <strong class="highlight">I'm highlighted</strong>.

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

string $text

A text containing phrases to highlight.

string $phrase

A phrase to highlight in $text.

string $highlighter

A highlighting replacement.

Returns

string —

The highlighted text.

truncate()

truncate(string  $text, integer  $length = 30, string  $truncateString = '...') : 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.

$this->truncate('Once upon a time in a world far far away', 14); // => Once upon a...

Parameters

string $text

A text to truncate.

integer $length

The maximum length of the text

string $truncateString

Replacement string for the truncated text.

Returns

string —

The truncated text.

truncateMiddle()

truncateMiddle(string  $str, integer  $maxLength = 80, string  $joiner = '...') : string

Limits a string to a given maximum length in a smarter way than just using substr().

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

string $str

A text to truncate.

integer $maxLength

The maximum length of the text

string $joiner

Replacement string for the truncated text.

Returns

string —

The truncated text.

makeBreakable()

makeBreakable(string  $str) : string

Inserts HTML code to allow linebreaks in a string after slashes or underscores.

Parameters

string $str

A string to mark up with linebreak markers.

Returns

string —

The marked-up string.

cleanSmartQuotes()

cleanSmartQuotes(string  $str) : string

Removes smart quotes.

Parameters

string $str

A string with potential smart quotes.

Returns

string —

The cleaned-up string.