Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

OW Simple Operator - PHP functions as template operators

What the owsimpleoperator extension does, how its operators are registered from owsimpleoperator.ini, the five PHP functions it offers on this installation (time, mktime, getdate, str_replace, str_rot13), and how to…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/template-operators/owsimpleoperator.md

On this page

OW Simple Operator: PHP functions as template operators

OW Simple Operator (extension/owsimpleoperator, version 1.2.7 in ezinfo.php, GPL v3 or later) is a small extension for writing template operators with less code. It was made by Open Wide; the copyright is held by Open Wide and Brookins Consulting (see the extension's README.md and doc/COPYRIGHT.md). It does two things:

  1. it turns PHP functions that are listed in a setting into template operators, and
  2. it gives you a base class, OWSimpleOperator, where every public method of your class becomes an operator, without operatorList(), namedParameterList() or modify() of your own.

This page covers the first part and how the extension is wired in. The second part is in Your own operators with OW Simple Operator; the traps of both are in OW Simple Operator: limitations and risks.

Contents

  1. How it is wired in
  2. The operators it offers here
  3. Calling a PHP function operator
  4. Allowing another PHP function
  5. Debug output

How it is wired in

The extension registers its operators like any other extension (see Registering operators):

  • settings/site.ini.append.php adds ExtensionAutoloadPath[]=owsimpleoperator to [TemplateSettings], so the template engine reads extension/owsimpleoperator/autoloads/eztemplateautoload.php.
  • That file does not hard-code operator names. It reads owsimpleoperator.ini:
    • [PHPFunctions] PermittedFunctionList[] becomes the operator names of the class PHPFunctionOperator (an empty subclass of OWSimpleOperator);
    • every line of [ClassOperators] PermittedClassOperatorList[], written file;Class;method, adds the operator method served by Class from file.
  • OWSimpleOperator::modify() then calls the method of the same name on the operator class if there is one, and otherwise the PHP function of that name.

The shipped settings/owsimpleoperator.ini.append.php:

[OWSimpleOperatorSettings]
DebugOutput=disabled

[PHPFunctions]
PermittedFunctionList[]
PermittedFunctionList[]=time
PermittedFunctionList[]=mktime
PermittedFunctionList[]=getdate
PermittedFunctionList[]=str_replace
PermittedFunctionList[]=str_rot13

[ClassOperators]
PermittedClassOperatorList[]
#PermittedClassOperatorList[]=extension/owsimpleoperator/autoloads/exampleoperator.php;ExampleOperator;example_sum

On a development installation the extension is active on the site and admin siteaccesses, and these five names are its operators.

The operators it offers here

time, mktime, getdate, str_replace and str_rot13

OperatorPHP functionArguments, in PHP orderReturns
timetime()nonethe current Unix timestamp (integer)
mktimemktime()hour, minute, second, month, day, year (each optional)a Unix timestamp in the server's time zone
getdategetdate()timestamp (optional, default now)a hash: seconds, minutes, hours, mday, wday, mon, year, yday, weekday, month, 0
str_replacestr_replace()search, replace, subjectthe subject with every search string replaced
str_rot13str_rot13()stringthe string with ROT13 applied

Each takes up to ten arguments ($max_operator_parameter = 10 in OWSimpleOperator); arguments you do not give are left out of the PHP call, so the PHP function's own defaults apply.

str_replace has the same name as an operator of the extension swark. The owsimpleoperator registration is read later, so it wins on a development installation (see Registration order and overrides). The kernel's own date operators (currentdate, maketime, makedate, datetime, l10n) cover most date needs without this extension: see Locale operators.

Calling a PHP function operator

Use the call form and give every argument in the order of the PHP function:

{* call form: every argument in the parentheses *}
{str_replace( 'great', 'very good', 'This is a great example!' )}
{str_rot13( 'Exponential' )}
{'Exponential'|str_rot13}

Output:


This is a very good example!
Rkcbaragvny
Rkcbaragvny

str_rot13 takes a single argument, so the pipe form works for it as well ({'Exponential'|str_rot13}).

The date functions:

{def $now = time()
     $parts = getdate( mktime( 12, 30, 0, 7, 4, 2026 ) )}
{if $now|gt( 1700000000 )}time() returned a Unix timestamp: an integer{/if}

mktime( 0, 0, 0, 1, 1, 2026 ) = {mktime( 0, 0, 0, 1, 1, 2026 )}
{$parts.weekday} {$parts.mday} {$parts.month} {$parts.year}, {$parts.hours}:{$parts.minutes}

Output:

time() returned a Unix timestamp: an integer
mktime( 0, 0, 0, 1, 1, 2026 ) = 1767254400
Saturday 4 July 2026, 12:30

mktime() uses the time zone of the PHP process: on a development installation that is Pacific time, so midnight on 1 January 2026 is 1767254400 and not the UTC value. Format timestamps for people with the kernel's l10n or datetime operators, which follow the siteaccess locale.

With more than one argument, do not pipe the first argument in. OWSimpleOperator::modify() puts the piped value in front of the argument list and removes the last argument you gave, so the PHP function gets one argument too few:

{* pipe form: the piped value becomes the FIRST argument and the LAST given argument is dropped *}
{'This is a great example!'|str_replace( 'great', 'very good' )}

Output:

(no output)

Logged by the template engine:

EXCEPTION ArgumentCountError: str_replace() expects at least 3 arguments, 2 given

The template engine does not catch PHP's ArgumentCountError: rendering stops at that tag. Details in OW Simple Operator: limitations and risks.

A PHP function that is not listed in PermittedFunctionList[] is not an operator. The engine leaves the tag empty and logs a warning:

{* a function that is not in PermittedFunctionList[] is no operator at all *}
{strrev( 'abc' )}

Output:

(no output)

Logged by the template engine:

WARNING : Operator 'strrev' is not registered

Allowing another PHP function

Add it to PermittedFunctionList[] in an owsimpleoperator.ini.append.php of your own extension or siteaccess (not in the extension's file, which an update would replace), then clear the INI and template caches:

[PHPFunctions]
PermittedFunctionList[]=ucwords

The comment in the shipped settings file states the rule: every template can call a listed function with any argument, so list only functions without side effects that read nothing outside their arguments. file_get_contents, for example, would let any template read any file the web server can read. The extension's test tests/owSimpleOperatorDefaultSettingsTest.php refuses a list of such functions (file, process, eval-like and configuration functions) in the shipped settings and checks that every listed function exists in the running PHP.

Before you allow a function, check whether the template library already has it: the operators of eZTemplateStringsOperator wrap sixty PHP string functions with checked parameters (PHP string functions), and settings/template.ini [PHP] PHPOperatorList[] maps single-argument PHP functions to operators (PHP function operators).

Debug output

[OWSimpleOperatorSettings] DebugOutput=enabled writes every call with its arguments and its result to the debug output (eZDebug::writeDebug()), for example PHP Function: str_rot13("Exponential") => "Rkcbaragvny". Keep it disabled outside development.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x