eZPublish  4.4
eZURLAliasML Class Reference

Handles URL aliases in eZ Publish. More...

+ Inheritance diagram for eZURLAliasML:
+ Collaboration diagram for eZURLAliasML:

Public Member Functions

 actionURL ()
 
 eZURLAliasML ($row)
 
 getChildren ()
 
 getPath ($locale=null, $incomingLanguageList=null)
 
 setAttribute ($name, $value)
 
 store ($fieldFilters=null)
 
- Public Member Functions inherited from eZPersistentObject
 attribute ($attr, $noFunction=false)
 
 attributes ()
 
 eZPersistentObject ($row)
 
 fill ($row)
 
 hasAttribute ($attr)
 
 hasDirtyData ()
 
 remove ($conditions=null, $extraConditions=null)
 
 setAttribute ($attr, $val)
 
 setHasDirtyData ($hasDirtyData)
 
 store ($fieldFilters=null)
 
 sync ($fieldFilters=null)
 

Static Public Member Functions

static actionToUrl ($action)
 
static choosePrioritizedRow ($rows)
 Chooses the most prioritized row (based on language) of $rows and returns it. More...
 
static cleanURL ($url)
 
static convertPathToAlias ($pathURL)
 
static convertToAlias ($urlElement, $defaultValue=false)
 
static convertToAliasCompat ($urlElement, $defaultValue=false)
 
static create ($element, $action, $parentID, $language)
 
static definition ()
 
static fetchByAction ($actionName, $actionValue, $maskLanguages=false, $onlyPrioritized=false, $includeRedirections=false)
 
static fetchByParentID ($id, $maskLanguages=false, $onlyPrioritized=false, $includeRedirections=true)
 
static fetchByPath ($uriString, $glob=false)
 
static fetchNodeIDByPath ($uriString, $glob=false)
 
static fetchPathByActionList ($actionName, $actionValues, $locale=null)
 
static findUniqueText ($parentElementID, $text, $action, $linkCheck=false, $languageID=false)
 
static getNewID ()
 
static nodeIDFromAction ($action)
 
static removeByAction ($actionName, $actionValue)
 
static removeSingleEntry ($parentID, $textMD5, $language)
 
static reverseTranslate (&$uri, $uriString, $internalURIString)
 
static sanitizeURL ($url)
 
static setLangMaskAlwaysAvailable ($langID, $actionName, $actionValue)
 
static storePath ($path, $action, $languageName=false, $linkID=false, $alwaysAvailable=false, $rootID=false, $cleanupElements=true, $autoAdjustName=false, $reportErrors=true, $aliasRedirects=true)
 
static strtolower ($text)
 
static translate (&$uri, $reverse=false)
 
static urlToAction ($url)
 
static urlTranslationEnabledByUri (eZURI $uri)
 
- Static Public Member Functions inherited from eZPersistentObject
static conditionText ($conditions)
 
static conditionTextByRow ($conditions, $row)
 
static count ($def, $conds=null, $field=null)
 
static definition ()
 
static escapeArray ($array)
 
static fetchObject ($def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
 
static fetchObjectList ($def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
 
static getShortAttributeName ($db, $def, $attrName)
 
static handleRows ($rows, $class_name, $asObject)
 
static newObjectOrder ($def, $orderField, $conditions)
 
static removeObject ($def, $conditions=null, $extraConditions=null)
 
static reorderObject ($def, $orderField, $conditions, $down=true)
 
static swapRow ($table, $keys, $order_id, $rows, $id1, $id2)
 
static updateObjectList ($parameters)
 

Public Attributes

 $Path
 
const ACTION_INVALID = 51
 
const DB_ERROR = 101
 
const LINK_ALREADY_TAKEN = 3
 
const LINK_ID_NOT_FOUND = 1
 
const LINK_ID_WRONG_ACTION = 2
 
- Public Attributes inherited from eZPersistentObject
 $PersistentDataDirty
 Whether the data is dirty, ie needs to be stored, or not. More...
 

Static Private Member Functions

static dbError ($db)
 
static filterRows ($rows, $onlyPrioritized)
 
static generateCond ($table, $prevTable, $i, $langMask, $element)
 
static generateFullSelect ($table)
 
static generateGlobCond ($table, $prevTable, $i, $langMask, $glob)
 
static generateSelect ($table, $i, $len)
 
static languageScore ($mask)
 
static md5 ($db, $text, $escape=true)
 

Static Private Attributes

static $charset = null
 

Detailed Description

Handles URL aliases in eZ Publish.

URL aliases are different names for existing URLs in eZ Publish. Using URL aliases allows for having better looking urls on the webpage as well as having fixed URLs pointing to various locations.

This class handles storing, fetching, moving and subtree updates on eZ Publish URL aliases, this performed using methods from eZPersistentObject.

The table used to store path information is designed to keep each element in the path (separated by /) in one row, ie. not the entire path. Each row uses the parent field to say which element is the parent of the current one, a value of 0 means a top-level path element. The system also supports path elemens in multiple languages, each language is stored in separate rows but with the same path element ID, the exception is when the text of multiple languages are the same then they will simply share the same row.

Instead of manipulating path elements directly it is recommended to use one the higher level methods for fetching or storing a path.

For objects the methods getChildren() and getPath() can be used to fetch the child elements and path string.

Typically you will not have a path element object and should use on of these static functions:

  • storePath() - Stores a given path with specified action, all parent are created if they don't exist.
  • fetchByPath() - Fetch path elements by path string, some wildcard support is also available.
  • translate() - Translate requested path string into the internal path.

For more detailed path element handling these static methods are available:

Most of these methods have some common arguments, they can be:

  • $maskLanguages - If true then only elements which matches the currently prioritized languaes is processed.
  • $onlyPrioritized - If true then only the top prioritized language of the elements is considered. Requires $maskLanguages to be set to true.
  • $includeRedirections - If true then elements which redirects to this is also processed.

Member Function Documentation

static eZURLAliasML::actionToUrl (   $action)
static

Decodes the action string $action into an internal path string and returns it.

The following actions are supported:

  • eznode - argument is node ID, path is 'content/view/full/<nodeID>'
  • module - argument is module/view/args, path is the arguments
  • nop - a no-op, path is '/'

Referenced by eZPathElement\actionURL(), actionURL(), and translate().

eZURLAliasML::actionURL ( )

Converts the action property into a real url which responds to the module/view on the site.

static eZURLAliasML::choosePrioritizedRow (   $rows)
static

Chooses the most prioritized row (based on language) of $rows and returns it.

Parameters
array$rows
Returns
array|false The most prioritized row, or false if no match was found

Referenced by fetchByPath(), filterRows(), eZPathElement\getPath(), getPath(), eZPathElement\getPathArray(), reverseTranslate(), and translate().

static eZURLAliasML::cleanURL (   $url)
static
static eZURLAliasML::convertPathToAlias (   $pathURL)
static

Converts the path $pathURL into a new alias path with limited characters. For more information on the conversion see convertToAlias().

Note
each element in the path (separated by / (slash) ) is converted separately.
Returns
the converted path

Referenced by eZWebDAVContentServer\fetchNodeByTranslation(), eZWebDAVContentBackend\fetchNodeByTranslation(), eZWebDAVContentServer\fetchParentNodeByTranslation(), and eZWebDAVContentBackend\fetchParentNodeByTranslation().

static eZURLAliasML::convertToAlias (   $urlElement,
  $defaultValue = false 
)
static
static eZURLAliasML::convertToAliasCompat (   $urlElement,
  $defaultValue = false 
)
static
static eZURLAliasML::create (   $element,
  $action,
  $parentID,
  $language 
)
static

Creates a new path element with given arguments, MD5 sum is automatically created.

Parameters
$elementThe text string for the path element.
$actionAction string.
$parentIDID of parent path element.
$languageID or mask of languages
$languageNameName of language(s), comma separated

Referenced by storePath().

static eZURLAliasML::dbError (   $db)
staticprivate

Returns a structure with the current database error.

Note
This is used by storePath().

Referenced by storePath().

static eZURLAliasML::definition ( )
static
eZURLAliasML::eZURLAliasML (   $row)

Initializes a new URL alias from database row.

Note
If 'path' is set it will be cached in $Path.

Referenced by create(), removeSingleEntry(), and storePath().

static eZURLAliasML::fetchByAction (   $actionName,
  $actionValue,
  $maskLanguages = false,
  $onlyPrioritized = false,
  $includeRedirections = false 
)
static

Fetches real path element(s) which matches the action name $actionName and value $actionValue.

Lets say we have the following elements:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
2 6 0 'spam' 'eznode:55'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
5 5 3 'repairman' 'eznode:42'
6 6 3 'repoman' 'eznode:55'
=== ==== ====== =========== ==========

then we try to fetch a specific action:

it would return:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
3 3 0 'bicycle' 'eznode:5'
=== ==== ====== =========== ==========

Now let's try with an element which is redirecting:

it would return:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
2 6 0 'spam' 'eznode:55'
=== ==== ====== =========== ==========

Referenced by eZContentObjectTreeNode\adjustPathElement(), ezpLanguageSwitcher\destinationUrl(), ezpLanguageSwitcherFunctionCollection\fetchUrlAlias(), eZStaticCache\generateNodeListCache(), and eZContentObjectTreeNode\updateSubTreePath().

static eZURLAliasML::fetchByParentID (   $id,
  $maskLanguages = false,
  $onlyPrioritized = false,
  $includeRedirections = true 
)
static

Fetches path element(s) which matches the parent ID $id.

Lets say we have the following elements:

=== ==== ====== =========== ========== id link parent text action === ==== ====== =========== ========== 1 1 0 'ham' 'eznode:4' 2 6 0 'spam' 'eznode:55' 3 3 0 'bicycle' 'eznode:5' 4 4 0 'superman' 'nop:' 5 5 3 'repairman' 'eznode:42' 6 6 3 'repoman' 'eznode:55' === ==== ====== =========== ==========

then we try to fetch a specific ID:

it would return (ie. no redirections):

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
=== ==== ====== =========== ==========

Now let's try with an element which is redirecting:

$includeRedirections = true;
eZURLAliasML::fetchByParentID( 0, false, false, $includeRedirections );

it would return:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
2 6 0 'spam' 'eznode:55'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
=== ==== ====== =========== ==========

Referenced by eZStaticCache\generateCache(), and getChildren().

static eZURLAliasML::fetchByPath (   $uriString,
  $glob = false 
)
static

Fetches the path element(s) which has the path $uriString. If $glob is set it will use $uriString as the folder to search in and $glob as the starting text to match against.

Lets say we have the following elements:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
2 6 0 'spam' 'eznode:55'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
5 5 3 'repairman' 'eznode:42'
6 6 3 'repoman' 'eznode:55'
=== ==== ====== =========== ==========

Then we try to fetch a specific path:

$elements = eZURLAliasML::fetchByPath( "bicycle/repairman" );

we would get:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
5 5 3 'repairman' 'eznode:42'
=== ==== ====== =========== ==========
$elements = eZURLAliasML::fetchByPath( "bicycle", "rep" ); // bicycle/rep*

we would get:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
5 5 3 'repairman' 'eznode:42'
6 6 3 'repoman' 'eznode:55'
=== ==== ====== =========== ==========

Referenced by fetchNodeIDByPath(), eZStaticCache\generateCache(), and eZSSLZone\getSSLZones().

static eZURLAliasML::fetchNodeIDByPath (   $uriString,
  $glob = false 
)
static

The same as 'fetchByPath' but extracting nodeID from action. Only first entry will be processed if 'fetchByPath' returns multiple result(e.g. $glob is wildcard).

Returns
nodeID on success or false otherwise.

Referenced by eZTemplateCacheBlock\decodeNodeID(), ezpLanguageSwitcher\destinationUrl(), eZContentFunctionCollection\fetchContentNode(), eZWebDAVContentServer\fetchNodeByTranslation(), eZWebDAVContentBackend\fetchNodeByTranslation(), and ezpLanguageSwitcherFunctionCollection\fetchUrlAlias().

static eZURLAliasML::fetchPathByActionList (   $actionName,
  $actionValues,
  $locale = null 
)
static

Fetches the path string based on the action $actionName and the values $actionValues. The first entry in $actionValues would be the top-most path element in the path the second entry the child of the first path element and so on.

Lets say we have the following elements:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
2 6 0 'spam' 'eznode:55'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
5 5 3 'repairman' 'eznode:42'
6 6 3 'repoman' 'eznode:55'
=== ==== ====== =========== ==========

then we try to fetch a specific ID:

$path = eZURLAliasML::fetchPathByActionList( 'eznode', array( 3, 5 ) );

it would return:

'bicycle/repairman'
Note
This function is faster than getPath() since it can fetch all elements in one SQL.
If the fetched elements does not point to each other (parent/id) then null is returned.

Referenced by eZContentObjectTreeNode\pathWithNames().

static eZURLAliasML::filterRows (   $rows,
  $onlyPrioritized 
)
staticprivate

Filters the DB rows $rows by selecting the most prioritized row per path element and returns the new row list.

Parameters
$onlyPrioritizedIf false all rows are returned, if true filtering is performed.

Referenced by fetchByAction(), and fetchByParentID().

static eZURLAliasML::findUniqueText (   $parentElementID,
  $text,
  $action,
  $linkCheck = false,
  $languageID = false 
)
static

Checks if the text entry $text is unique on the current level in the URL path. If not the name is adjusted with a number at the end until it becomes unique. The unique text string is returned.

Parameters
$textThe text element which is to be checked
$actionThe action string which is to be excluded from the check. Set to empty string to disable the exclusion.
$linkCheckIf true then it will see all existing entries as taken.

Referenced by eZContentObjectTreeNode\adjustPathElement().

static eZURLAliasML::generateCond (   $table,
  $prevTable,
  $i,
  $langMask,
  $element 
)
staticprivate

Generates WHERE part of SQL based on table $table, previous table $prevTable, counter $i, language mask $langMask and text $element.

Referenced by fetchByPath().

static eZURLAliasML::generateFullSelect (   $table)
staticprivate

Generates full SELECT part of SQL based on table $table.

Referenced by fetchByPath().

static eZURLAliasML::generateGlobCond (   $table,
  $prevTable,
  $i,
  $langMask,
  $glob 
)
staticprivate

Generates WHERE part of SQL for a wildcard match based on table $table, previous table $prevTable, counter $i, language mask $langMask and wildcard text $glob.

Note
$glob does not contain the wildcard character * but only the beginning of the matching text.

Referenced by fetchByPath().

static eZURLAliasML::generateSelect (   $table,
  $i,
  $len 
)
staticprivate

Generates partial SELECT part of SQL based on table $table, counter $i and total length $len.

Referenced by fetchByPath().

eZURLAliasML::getChildren ( )

Finds all the children of the current element.

For more control over the list use fetchByParentID().

static eZURLAliasML::getNewID ( )
static
eZURLAliasML::getPath (   $locale = null,
  $incomingLanguageList = null 
)

Calculates the full path for the current item and returns it.

Parameters
$localeThe locale for which a path should be calculated.
$incomingLanguageListArray of locale codes representing the prioritized site language list.
Note
If you know the action values of the path use fetchPathByActionList() instead, it is more optimized.
The calculated path is cached in $Path.
static eZURLAliasML::languageScore (   $mask)
staticprivate

Calculates the score of the language mask $mask based upon the currently prioritized languages and returns it.

Note
The higher the value the more the language is prioritized.

Referenced by choosePrioritizedRow().

static eZURLAliasML::md5 (   $db,
  $text,
  $escape = true 
)
staticprivate

Wraps a database md5 call around the string $text and returns the new SQL for it.

Parameters
$escapeIf true it will lowercase the text and escape it.
Note
If the database is Oracle and the text is empty the MD5 is computed by PHP and returned.

Referenced by create(), setAttribute(), and store().

static eZURLAliasML::nodeIDFromAction (   $action)
static

Grabs nodeID from action string.

Returns
nodeID on success, false otherwise.

Referenced by fetchNodeIDByPath().

static eZURLAliasML::removeByAction (   $actionName,
  $actionValue 
)
static

Removes all path elements which matches the action name $actionName and value $actionValue.

Referenced by eZContentObjectTreeNode\removeThis().

static eZURLAliasML::removeSingleEntry (   $parentID,
  $textMD5,
  $language 
)
static

Removes a URL-Alias which has parent $parentID, MD5 text $textMD5 and language $language. If the entry has only the specified language and there are existing children the entry will be disabled instead of removed. If the entry has other languages other than the one which was specified the language bit is removed.

Parameters
$parentIDID of the parent element
$textMD5MD5 of the lowercase version of the text, see eZURLAliasML::strtolower().
$languageThe language entry to remove, can be a string with the locale or a language object (eZContentLanguage).

Referenced by eZContentObject\removeTranslation().

static eZURLAliasML::reverseTranslate ( $uri,
  $uriString,
  $internalURIString 
)
static

Perform reverse translation of uri, that is from system-url to url alias.

Referenced by translate().

static eZURLAliasML::sanitizeURL (   $url)
static

Transform a semi-valid url into one that can be stored in the url-alias system. Removes leading/trailing slashes and repeated slashes.

echo eZURLAliasML::sanitizeURL( "" ); // Result ""
echo eZURLAliasML::sanitizeURL( "users//the_dude" ); // Result "users/the_dude"
echo eZURLAliasML::sanitizeURL( "archive/products/" ); // Result "archive/products"
Returns
the sanitized URL
eZURLAliasML::setAttribute (   $name,
  $value 
)

Overrides the default behaviour to automatically update TextMD5.

static eZURLAliasML::setLangMaskAlwaysAvailable (   $langID,
  $actionName,
  $actionValue 
)
static

Updates the lang_mask field for path elements which matches action $actionName and value $actionValue. If $langID is false then bit 0 (the always available bit) will be removed, otherwise it will set bit 0 for the chosen language and remove it for other languages.

Referenced by eZContentObject\setAlwaysAvailableLanguageID().

eZURLAliasML::store (   $fieldFilters = null)

Generates the md5 for the alias and stores the values.

Note
Transaction unsafe. If you call several transaction unsafe methods you must enclose the calls within a db transaction; thus within db->begin and db->commit.
static eZURLAliasML::storePath (   $path,
  $action,
  $languageName = false,
  $linkID = false,
  $alwaysAvailable = false,
  $rootID = false,
  $cleanupElements = true,
  $autoAdjustName = false,
  $reportErrors = true,
  $aliasRedirects = true 
)
static

Stores the full path $path to point to action $action, any missing parents are created as placeholders (ie. nop:).

Returns an array containing the entry 'status' which is the status code, is true if all went well, a number otherwise (see class constants). Will contain 'path' for succesful creation or if the path already exists.

Parameters
$pathString containing full path, leading and trailing slashes are stripped.
$actionAction string for entry.
$languageNameThe language to use for entry, can be a string (locale code, e.g. 'nor-NO') an eZContentLanguage object or false for the top prioritized language.
$linkIDNumeric ID for link field, if it is set to false the entry will point to itself. Use this for redirections. Use true if you want to create an link/alias which points to a module (ie. no entry in urlalias table).
$alwaysAvailableIf true the entry will be available in any language.
$rootIDID of the parent element to start at, use 0/false for the very top.
$cleanupElementsIf true each element in the path will be cleaned up according to the current URL transformation rules.
$autoAdjustNameIf true it will adjust the name until it is unique in the path. Used together with $linkID.
$reportErrorsIf true it will report found errors using eZDebug, if false errors are only return in 'status'.
$aliasRedirectsIf true and an alias is being stored it will redirect (using HTTP 301) to it's destination.

Referenced by eZContentObjectTreeNode\updateSubTreePath().

static eZURLAliasML::strtolower (   $text)
static

Unicode-aware strtolower, performs the conversion by using eZCharTransform

Referenced by md5().

static eZURLAliasML::translate ( $uri,
  $reverse = false 
)
static

Transforms the URI if there exists an alias for it, the new URI is replaced in $uri.

Returns
true is if successful, false otherwise
The string with new url is returned if the translation was found, but the resource has moved.

Lets say we have the following elements:

=== ==== ====== =========== ==========
id link parent text action
=== ==== ====== =========== ==========
1 1 0 'ham' 'eznode:4'
2 6 0 'spam' 'eznode:55'
3 3 0 'bicycle' 'eznode:5'
4 4 0 'superman' 'nop:'
5 5 3 'repairman' 'eznode:42'
6 6 3 'repoman' 'eznode:55'
=== ==== ====== =========== ==========

then we try to translate a path:

$uri = "bicycle/repairman";
if ( $result )
{
echo $result, "\n";
echo $uri, "\n";
}

we would get:

'1'
'content/view/full/42'

If we then were to try:

$uri = "spam";
if ( $result )
{
echo $result, "\n";
echo $uri, "\n";
}

we would get:

'bicycle/repoman'
'error/301'

Trying a non-existing path:

$uri = "spam/a-lot";
if ( $result )
{
echo $result, "\n";
echo $uri, "\n";
}

then $result would be empty:

Alterntively we can also do a reverse lookup:

$uri = "content/view/full/55";
if ( $result )
{
echo $result, "\n";
echo $uri, "\n";
}

we would get:

'1'
'bicycle/repoman'

Referenced by eZWebDAVContentServer\fetchParentNodeByTranslation(), eZWebDAVContentBackend\fetchParentNodeByTranslation(), eZHTTPHeader\headerOverrideArray(), and eZURLWildcard\translate().

static eZURLAliasML::urlToAction (   $url)
static

Takes the url string $url and returns the action string for it.

The following path are supported:

  • content/view/full/<nodeID> => eznode:<nodeID>

If the url points to an existing module it will return module:<url>

Returns
false if the action could not be figured out.

Referenced by reverseTranslate().

static eZURLAliasML::urlTranslationEnabledByUri ( eZURI  $uri)
static

Checks if url translation should be used on the current url.

Parameters
$uriThe current eZUri object

Member Data Documentation

eZURLAliasML::$charset = null
staticprivate
eZURLAliasML::$Path

Optionally computed path string for this element, used for caching purposes.

Referenced by getPath().

const eZURLAliasML::ACTION_INVALID = 51
const eZURLAliasML::DB_ERROR = 101
const eZURLAliasML::LINK_ALREADY_TAKEN = 3
const eZURLAliasML::LINK_ID_NOT_FOUND = 1

Referenced by storePath().

const eZURLAliasML::LINK_ID_WRONG_ACTION = 2

Referenced by storePath().


The documentation for this class was generated from the following file: