core/model/modx/modlexicon.class.php

Show: inherited
Table of Contents

MODX Revolution

Copyright 2006-2012 by MODX, LLC. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Package
modx  

\modLexicon

Package: modx

The lexicon handling class. Handles all lexicon topics by loading and storing their entries into a cached array.

Also considers database-based overrides for specific lexicon entries that preserve the originals and allow reversion.

Properties

Propertyprotectedarray  $_lexicon= 'array()'

The actual language array.

Default valuearray()Details
Type
array
Access
protected  
Todo
Separate into separate arrays for each namespace (and maybe topic) so that no namespacing in lexicon entries is needed. Maybe keep a master array of entries, but then have subarrays for topic-specific referencing.  
Propertyprotectedarray  $_loadedTopics= 'array()'

An array of loaded topic strings

Default valuearray()Details
Type
array
Propertyprotectedarray  $_paths= 'array()'

Directories to search for language strings in.

Default valuearray()Details
Type
array
Access
protected  
Deprecated
 
Propertypublic\modX  $modx= 'null'

Reference to the MODX instance.

Default valuenullDetails
Type
\modX
Access
protected  

Methods

methodpublic__construct( \xPDO $modx, array $config = array() ) : void

Creates the modLexicon instance.

Parameters
Name Type Description
$modx \xPDO

A reference to the modX instance.

$config array

An array of configuration properties

Details
Constructor
 
methodprivate_parse( string $str, array $params ) : string

Parses a lexicon string, replacing placeholders with specified strings.

Parameters
Name Type Description
$str string

The string to parse

$params array

An associative array of keys to replace

Returns
Type Description
string The processed string
Details
Access
private  
methodpublicclear( string $language = '' ) : void

Completely clears the lexicon

Parameters
Name Type Description
$language string
methodpublicclearCache( string $path = '' ) : string

Clears the lexicon cache for the specified path.

Parameters
Name Type Description
$path string

The path to clear.

Returns
Type Description
string The results of the cache clearing.
Details
Access
public  
methodpublicexists( string $index,  $language = '' ) : boolean

Returns if the key exists in the lexicon.

Parameters
Name Type Description
$index string
$language
Returns
Type Description
boolean True if exists.
Details
Access
public  
methodpublicfetch( string $prefix = '', boolean $removePrefix = false, string $language = '' ) : array

Accessor method for the lexicon array.

Parameters
Name Type Description
$prefix string

If set, will only return the lexicon entries with this prefix.

$removePrefix boolean

If true, will strip the prefix from the returned indexes

$language string
Returns
Type Description
array The internal lexicon.
Details
Access
public  
methodpublicgetCacheKey( string $namespace = 'core', string $topic = 'default', string $language = '' ) : string

Return the cache key representing the specified lexicon topic.

Parameters
Name Type Description
$namespace string

The namespace for the topic

$topic string

The topic to grab

$language string

The language for the topic

Returns
Type Description
string The cache key for the specified topic
Details
Access
public  
methodpublicgetFileTopic( string $language = 'en', string $namespace = 'core', string $topic = 'default' ) : array

Get entries from file-based lexicon topic

Parameters
Name Type Description
$language string

The language to filter by.

$namespace string

The namespace to filter by.

$topic string

The topic to filter by.

Returns
Type Description
array An array of lexicon entries in key - value pairs for the specified filter.
methodpublicgetLanguageList( string $namespace = 'core' ) : array

Get a list of available languages for a Namespace.

Parameters
Name Type Description
$namespace string

The Namespace to filter by.

Returns
Type Description
array An array of available languages
methodpublicgetNamespacePath( string $namespace = 'core' ) : string

Get the path of the specified Namespace

Parameters
Name Type Description
$namespace string

The key of the Namespace

Returns
Type Description
string The path for the Namespace
methodpublicgetTopicList( string $language = 'en', string $namespace = 'core' ) : array

Get a list of available Topics when given a Language and Namespace.

Parameters
Name Type Description
$language string

The language to filter by.

$namespace string

The language to filter by.

Returns
Type Description
array An array of Topic names.
methodpublicload( ) : void

Loads a variable number of topic areas. They must reside as topicname.

inc.php files in their proper culture directory. Can load an infinite number of topic areas via a dynamic number of arguments.

They are loaded by language:namespace:topic, namespace:topic, or just topic. Examples: $modx->lexicon->load('en:core:snippet'); $modx->lexicon-

load ('demo:test'); $modx->lexicon->load('chunk');

Details
Access
public  
methodpublicloadCache( string $namespace = 'core', string $topic = 'default', string $language = '' ) : array

Loads a lexicon topic from the cache. If not found, tries to generate a cache file from the database.

Parameters
Name Type Description
$namespace string

The namespace to load from. Defaults to 'core'.

$topic string

The topic to load. Defaults to 'default'.

$language string

The language to load. Defaults to 'en'.

Returns
Type Description
array The loaded lexicon array.
Details
Access
public  
methodpublicprocess( string $key, array $params = array(), string $language = '' ) : string

Get a lexicon string by its index.

Parameters
Name Type Description
$key string

The key of the lexicon string.

$params array

An assocative array of placeholder keys and values to parse

$language string
Returns
Type Description
string The text of the lexicon key, blank if not found.
Details
Access
public  
methodpublicset( string | array $keys, string $text = '', string $language = '' ) : void

Sets a lexicon key to a value. Not recommended, since doesn't query the database.

Parameters
Name Type Description
$keys string | array

Either an array of array pairs of key/values or a key string.

$text string

The text to set, if the first parameter is a string.

$language string

The language to set the key in. Defaults to current.

Details
Access
public  
methodpublictotal( string $language = '' ) : int

Returns the total # of entries in the active lexicon

Parameters
Name Type Description
$language string
Returns
Type Description
int
Documentation was generated by DocBlox 0.18.1.