Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

1.4. Section 2 - FrontEnd

About this section

Functions for frontend development.

All of those functions are only available in a frontend context. They also all need the API class to be instantiated, as they will use the internal variable $pObj.

Do not try to use them out of a frontend context, and without the API class instantiated.

fe_mergeTSconfFlex

Merge plugin TS configuration with flexform configuration.

This function merge the plugin TS configuration array with the flexform configuration (priority is given to flexform). Everything is done automatically with a mapping array containing the path of the TS elements to replace, and the path of the flexform fields in the XML.

Parameters

Parameter:

Default value:

Description:

$mapArray

The mapping array with informations about values to replace

$tsArray

The initial TS configuration array

$flexRes

The flexform object (usually $this->pObj->cObj->data['pi_flexform'])

Return

The merged configuration array.

Examples

When you use flexforms for the configuration of a plugin, the values you set are most often defined by default in the ext_typoscript_setup.txt files, as default values. Those TypoScript values are passed to your plugin class as an array ($conf). So with flexforms, you need to check for an existing value in the XML, and to replace the value in the $conf array if necessary.

This function will handle that process automatically. It will check for flexform values, and replace the corresponding values in the $conf array. All you have to do is to provide a mapping array, with informations about where the values are located. Look at the example below:

1:

2:

3:

4:

5:

6:

7:

8:

9:

10:

11:

12:

13:

14:

15:

16:

17:

18:

19:

20:

// Mapping array for PI flexform

$flex2conf = array(

'pidList' => 'sDEF:pages',

'recursive' => 'sDEF:recursive',

'allowHTML' => 'sDEF:allow_html',

'templateFile' => 'sTEMPLATE:template_file',

'dateFormat' => 'sDEF:date_format',

'list.' => array(

'defaultMode' => 'sLIST:default_mode',

'maxRecords' => 'sLIST:max_records',

'maxPages' => 'sLIST:max_pages',

'displayFields' => 'sLIST:display_fields',

'pictures.' => array(

'file.' => array(

'maxW' => 'sLIST:image_maxw',

'maxH' => 'sLIST:image_maxh',

),

'params' => 'sLIST:image_params',

),

);

The keys of the array are the TypoScript objects names in the $conf array. You can add as many levels as you want, just by adding sub-arrays. The values of the array must be path to the corresponding value in the flexform. For example:

sDEF:pages

It will tell the function to look for the pages field of the sDEF sheet.

When you have your mapping array, you need to get the flexform values, and to launch the function. This is done like this:

1:

2:

3:

4:

5:

6:

7:

8:

// Init flexform configuration of the plugin

$this->pi_initPIflexForm();

// Get flexform informations

$piFlexForm = $this->cObj->data['pi_flexform'];

// Ovverride TS setup with flexform

$conf = $this->api->fe_mergeTSconfFlex($flex2conf,$conf,$piFlexForm);

Then every TypoScript object of your $conf array will be replaced by the corresponding flexform value, if there is one. Otherwise, the TypoScript value will remain untouched.

fe_initTemplate

Loads a template file.

This function reads a template file and store it as a C-Object in the API class.

Parameters

Parameter:

Default value:

Description:

$templateFile

The template file to load

Return

Void.

Examples

1:

2:

// Store template file in the API class for further processing

$this->api->fe_initTemplate('EXT:myextension/pi1/template.html');

fe_renderTemplate

Template rendering.

This function analyzes the template C-Object, previously set by $this->fe_initTemplate and substitute the specified section with the specified subsections.

Parameters

Parameter:

Default value:

Description:

$templateMarkers

The markers array

$templateSection

The section to substitute

Return

The processed template section.

Examples

Here's an example HTML template:

1:

2:

3:

4:

5:

6:

7:

8:

9:

10:

11:

12:

13:

14:

15:

16:

17:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Template File</title>
</head>
<body>
<!-- ###HELLO### -->
<p>###WORLD###</p>
<p>###UNIVERSE###</p>
<!-- ###HELLO### -->
</body>
</html>

And here's the PHP code to render it:

1:

2:

3:

4:

5:

6:

7:

8:

// Template markers

$templateMarkers = array(

'###WORLD###' => 'Hello World!',

'###UNIVERSE###' => 'Hello Universe!',

);

// Render template

$content = $this->api->fe_renderTemplate($templateMarkers,'###HELLO###');

fe_makeStyledContent

Returns the content with CSS.

This function is used to output the requested content wrapped in an HTML element, containing a CSS class.

Parameters

Parameter:

Default value:

Description:

$element

The HTML element to produce.

$className

The CSS class name to link.

$content

false

The content to wrap.

$piClass

1

Prepends class name with plugin name (using pi_classParam).

$htmlSpecialChars

false

Pass the content through htmlspecialchars().

$startTagOnly

false

Generate only the starting tag (without content!).

$params
array()

The parameters of the HTML element as key/value pairs.

Return

The CSS styled content.

See also
  1. div_cleanArray

  2. div_writeTagParams

fe_setInternalVars

Sets internals variables.

This function is used to set the internal variables array ($this->pObj->internal) needed to execute a MySQL query.

Parameters

Parameter:

Default value:

Description:

$results_at_a_time
false

The maximum number of records to display in a list view.

$maxPages
false

The maximum number of pages to display in the browsebox.

$searchFieldList
false

The fields available for searching.

$orderByList
false

The fields available to use as ORDER BY parameter.

Return

Void.

fe_buildSwapClassesJSCode

Adds swapClasses JavaScript Code.

This function adds the javascript code used to switch between CSS classes.

Parameters

Parameter:

Default value:

Description:

$class1

The first class.

$class2

The second class.

Return

Void.

fe_makeSwapClassesJSLink

Returns a swapClasses link.

This function is used to output the requested content wrapped in an HTML link element calling the swapClasses JS function.

Parameters

Parameter:

Default value:

Description:

$elementId

The ID of the HTML element to change.

$content
false

The content to wrap.

$htmlSpecialChars
false

Pass the content through htmlspecialchars().

$startTagOnly
false

Generate only the starting tag (without content!).

$params
array()

The attributes of the HTML element as key/value pairs.

Return

The swap classes link.

See also
  1. div_cleanArray

  2. div_writeTagParams

fe_createImageObjects

Create IMAGE cObjects.

This function creates an IMAGE cObject for each given filename.

This function is particularly useful with image references stored in a database field.

Parameters

Parameter:

Default value:

Description:

$imgRefs

A comma list of picture names.

$conf

The TS setup for the images.

$imgPath
false

The path of the images (will be prepended to each picture name).

Return

An IMAGE cObject for each picture.

fe_linkTP

Link a string to some page.

This function links a string to a page (the active one by default).

It's the same function as tslib_pibase::pi_linkTP(), except that a configuration array for the typolink can be passed directly as argument.

Parameters

Parameter:

Default value:

Description:

$str

The content string to wrap in <a> tags.

$uréParameters
array()

Array with URL parameters as key/value pairs. They will be "imploded" and added to the list of parameters defined in the plugins TypoScript property "parent.addParams" plus $this->pi_moreParams.

$cache
0

If $cache is set (0/1), the page is asked to be cached by a &cHash value (unless the current plugin using this class is a USER_INT). Otherwise the no_cache-parameter will be a part of the link.

$altPageId
0

Alternative page ID for the link (by default this function links to the SAME page!).

$conf
array()

An optionnal array for the typolink configuration.

Return

The input string wrapped in <a> tags.

fe_linkTP_unsetPIvars

Link a string to some page.

This function links a string to a page (the active one by default), while keeping current piVars.

Additionnal piVars can be added or overlaid in the overrulePIvars array. All piVars found in the unsetPIvars array won't be preserved.

Please see the pi_linkTP_keepPIvars function of tslib_pibase for more details.

Parameters

Parameter:

Default value:

Description:

$str

The content string to wrap in <a> tags.

$overrulePIvars
array()

Array of values to override or add in the current piVars.

$unsetPIvars
array()

Array of values not to include in the current piVars.

$cache
0

Ask the page to be cached by a &cHash value.

$clearAnyway
0

Do not preserve current piVars.

$altPageId
0

Alternative page ID for the link.

Return

The input string wrapped in <a> tags.

fe_linkTP_unsetPIvars_url

Returns an URL to some page.

This function returns the URL to a page (the active one by default), while keeping current piVars.

Additionnal piVars can be added or overlaid in the overrulePIvars array. All piVars found in the unsetPIvars array won't be preserved.

Same as fe_linkTP_unsetPIvars, but it returns only the URL.

Please see the pi_linkTP_keepPIvars_url function of tslib_pibase for more details.

Parameters

Parameter:

Default value:

Description:

$overrulePIvars
array()

Array of values to override or add in the current piVars.

$unsetPIvars
array()

Array of values not to include in the current piVars.

$cache
0

Ask the page to be cached by a &cHash value.

$clearAnyway
0

Do not preserve current piVars.

$altPageId
0

Alternative page ID for the link.

Return

The complete URL.

fe_initFeAdmin

Init the FE-Admin script for frontend input.

This function adds all the configuration necessary to use fe_adminLib to the plugin configuration array.

Parameters

Parameter:

Default value:

Description:

$conf

The plugin configuration array.

$table

The table to use.

$pid

The pid for the records.

$feAdminConf

The configuration array for fe_adminLib subparts.

$create
1

Create capabilities (Boolean).

$edit
0

Edit capabilities (Boolean).

$delete
0

Delete capabilities (Boolean).

$infomail
0

Infomail capabilities (Boolean).

$fe_userOwnSelf
0

FE-Users own themselves (Boolean).

$fe_userEditSelf
0

FE-Users can edit themselves (Boolean).

$debug
0

Output debug informations (Boolean).

$defaultCmd
'create'

The default command to use if none is found.

$confKey
'fe_adminLib'

The key to use for fe_adminLib in the plugin configuration array.

Return

The complete plugin configuration array with a valid fe_adminLib configuration.

fe_createInput

Creates an input.

This function creates an HTML input tag, ready for a usage with fe_adminLib.

Parameters

Parameter:

Default value:

Description:

$type

The type of the input.

$name

The name of the input (field).

$feAdminConf

The fe_adminLib configuration array.

$feAdminSection

The fe_adminLib section (usually create or edit) - Used to check for required fields.

$number
1

The number of imput to create.

$params
array()

The input tag parameters (depending of context) as an array with key/value pairs.

$defaultValue
0

The default value for the input.

Can be an array for multiple inputs, or 'unix' for checkboxes/radios with unix-perms like values (eg. 1 -2 - 4 - 8, etc.), or 'increment' for incrementing values (eg. 0 - 1 -2 - 3, etc.).

$defaultChecked
0

For checkboxes or radios, if the input must be checked by default. Can be a comma list for multiple checkboxes.

$keepSentValues
1

Keep element value if the form is redrawn (will override default value or default checked).

$langPrefix
'pi_feadmin_'

The prefix for the plugin locallangfile. Used to fetch the title of the input and the warning message, if applicable.

$headerSeparation
'<br />'

The separation between the title and the input.

Return

A complete form element, with title, warning, and the input itself.

See also
  1. div_checkVarType

  2. div_cleanArray

  3. fe_buildFormElementHeader

  4. div_writeTagParams

fe_createTextArea

Creates a text area.

This function creates an HTML <textarea> tag for use with the fe_adminLib script.

Parameters

Parameter:

Default value:

Description:

$name

The name of the textarea (field).

$feAdminConf

The fe_adminLib configuration array.

$feAdminSection

The fe_adminLib section (usually create or edit) - Used to check for required fields.

$params
array()

The textarea tag parametersas  an array with key/value pairs.

$defaultValue
0

The default value for the textarea.

$keepSentValues
1

Keep element value if the form is redrawn (will override default value).

$langPrefix
'pi_feadmin_'

The prefix for the plugin locallangfile. Used to fetch the title of the textarea and the warning message, if applicable.

$headerSeparation
'<br />'

The separation between the title and the textarea.

Return

A complete textarea zone, with title and warning.

See also
  1. div_cleanArray

  2. buildFormElementHeader

  3. div_writeTagParams

fe_createSelect

Creates a select.

This function creates an HTML select tag for use with the fe_adminLib script.

The $option parameter can be an array or a number. If it's an array, the options will get the keys as values, and the values as label. If it's a number, it will create x options (x representing that number). The values will be incremented from zero, and the labels taken from the locallang file, according to the standard Typo3 syntax (eg.: lang_prefix_fieldname.I.value).

Parameters

Parameter:

Default value:

Description:

$name

The name of the select (field).

$feAdminConf

The fe_adminLib configuration array.

$feAdminSection

The fe_adminLib section (usually create or edit) - Used to check for required fields.

$options

The options to create.

$htmlspecialchars
1

Pass the option labels through htmlspecialchars().

$params
array()

The select tag parameters as an array with key/value pairs.

$keepSentValues
1

Keep element value if the form is redrawn.

$langPrefix
'pi_feadmin_'

The prefix for the plugin locallangfile. Used to fetch the title of the select and the warning message, if applicable.

$headerSeparation
'<br />'

The separation between the title and the select.

Return

A complete select, with title and warning.

See also
  1. div_cleanArray

  2. buildFormElementHeader

  3. div_writeTagParams

fe_createSelectFromTable

Creates a select from a table.

This function creates an HTML select tag for use with the fe_adminLib script. Values and labels are taken from an external table.

Parameters

Parameter:

Default value:

Description:

$name

The name of the select (field).

$feAdminConf

The fe_adminLib configuration array.

$feAdminSection

The fe_adminLib section (usually create or edit) - Used to check for required fields.

$table

The table containing the records (must be a valid Typo3 table).

$pidList

The pages from where to select the records (as a comma list).

$labelField

The field in the database to use as option label.

$valueField
'uid'

The field in the database to use as option value (usually UID).

$htmlspecialchars
1

Pass the option labels through htmlspecialchars().

$addWhere
''

Optional additional WHERE clauses put in the end of the query.

DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!

$groupBy
''

Optional GROUP BY field(s), if none, supply blank string.

$orderBy
''

Optional ORDER BY field(s), if none, supply blank string.

$limit
''

Optional LIMIT value ([begin,]max), if none, supply blank string.

$params
array()

The select tag parameters as an array with key/value pairs.

$keepSentValues
1

Keep element value if the form is redrawn.

$langPrefix
'pi_feadmin'

The prefix for the plugin locallangfile. Used to fetch the title of the select and the warning message, if applicable.

$headerSeparation
'<br />'

The separation between the title and the select.

Return

A complete select, with title and warning.

See also
  1. div_cleanArray

  2. buildFormElementHeader

  3. div_writeTagParams

fe_buildFormElementHeader

Returns a form element header.

This function creates the header of a form element for use with the fe_adminLib script. It also checks if the field is required in the plugin configuration array, and adds warning markers.

Parameters

Parameter:

Default value:

Description:

$name

The name of the field.

$langPrefix

The prefix to use to get the field title in the locallang file.

$headerSeparation

The separation to use between the header and the form element.

$requiredFieldList
false

A comma list of the required fields of the feAdmin section.

$evalValues
array()

The evalValues array from the feAdmin configuration array.

Return

The header zone.

fe_buildLoginBox

Build a login box.

This function constructs a standard Typo3 login box. All the setup is done by the function. You only have to specify the PID of the sysfolder where you store your website users records, and it will handle everything. If the user is already logged, it display a logout form.

Parameters

Parameter:

Default value:

Description:

$pid

The PID of the sysfolder containing the frontend users allowed to login.

$inputSize
30

The size of the inputs to generate.

$method
'POST'

The method of the form object used for sending variables.

$target
'_self'

The target of the form object.

$wrap
false

Wrap the whole object.

$layout
false

The layout of the form object.

$langPrefix
'pi_loginbox_'

The prefix to use to get the field title in the locallang file.

$permaLogin
false

Show permalogin option (needs extension 'core_permalogin')

Return

A login box.

See also
  1. fe_makeStyledContent

fe_buildSearchBox

Build a search box.

This function constructs a standard Typo3 search box for use in plugins. The result is basically the same as tslib_piBase::pi_list_searchBox, but the output is valid XHTML, without tables.

Parameters

Parameter:

Default value:

Description:

$method
post

The method for the search form (get or post).

$nocache
true

Add a no cache flag.

$sword
'sword'

The sword variable in piVars.

$pointer
'pointer'

The pointer variable in piVars.

Return

A search box.

See also
  1. fe_makeStyledContent

fe_buildBrowseBox

Build a browse box.

This function constructs a standard Typo3 browse box for use in plugins. The result is basically the same as tslib_piBase::pi_list_browseresults, but the output is valid XHTML, without tables.

Parameters

Parameter:

Default value:

Description:

$pointer
post

The pointer variable in piVars.

$count
true

The SQL count ressource in PI internal variables.

$maxResults
'sword'

The max results number in PI internal variables.

$maxPages
'pointer'

The max pages number in PI internal variables.

Return

A browse box.

See also
  1. fe_makeStyledContent