By Ho Yiu YEUNG (楊皓堯), aka Sheepy
This plugin adds a number of field operations to TinyButStrong, making it easier to use magnet, do calculation, manipulate string, or author web page.
Important! This plugin does not make TBS easier to learn. It can simplify your template, or it can ruin them.
Usage of this extension will slow down merging; if complicated processing is needed, custom function / method or JavaScript may serve you better.
For bug report or feature request, either email me or join the forum.
Upgrade
Upgrading from 1.0
New syntax
The operation syntax let TinyButStrong parse fields faster, and reduces the chance of conflict with future versions.
Operations
Changing to new syntax is as simple as adding 'ope' before parameters, e.g.
From: [field; inv; abs]
To: [field; ope=inv,abs]
Simplified Magnets
Magnets have been simplified since version 1.03, e.g.
From: [field; zeromagnet; reversemanget; magnet=tag]
To: [field; ope=!zeromagnet=tag]
Multiple operations
Since comma is operation separator, operation parameter separator has been changed to colon for pair of numbers and pipe for string:
[field; ope=substring=1:2]
[field; ope=zebra=odd|even]
Most mathematical operations, however, can be repeated using comma:
[field; ope=+=1,2,3]
Backward compatibility
However, this also means individual operation parameter cannot be protected by quote.
If this functionality is required, defining 'TBS_PLUS_NON_OPE' to true will enable operations to be used without ope.
This does not complete restore the old syntax, for example zebra will use pipe as separator not comma, but ope is not necessary.
PHP Side
Requirements
Installation
Commands
Operations
It is possible to execute field operations from php side by calling the Operation static method, if an instant of the plugin is acquired, either by creation:
$Plus = new clsTbsPlugInPlus();
Or get from TinyButStrong:
$Plus = $TBS->_PlugIns['clsTbsPlugInPlus'];
Syntax:
mixed $Plus->Operation(mixed Value, string Operation [, string Parameter] );
Example:
// Returns random story background
$Plus->Operation('background/story_*.jpg', 'randomfile');
It is possible to execute multiple operations by passing in an array of Operation and Parameter.
Example:
// Equals to [123; ope= abs, +=456, -=789]
$Plus->Operation(123, array('abs','+','-'), array(null,456,789));
Template Side
Syntax
Operation syntax
The same with TinyButStrong operation, except that parameter is assigned by equal sign:
[nav.page; ope= -=1, *=[config.pagesize], negativemagnet=td ]
[onshow; ope= val=images/[product.image].jpg, filemagnet=tr ]
This is the default plugin syntax since 1.1. Operations are case sensitive.
Operation syntax can be disabled by defining TBS_PLUS_NO_OPE to true before plugin installation.
Extended field eter syntax
This is syntax of version 1.0, and now must be enabled by defining TBS_PLUS_NON_OPE to true before plugin installation
This syntax is easier to read and use, but make everything merge slower even when not used.
Usage: just use the operations as new field parameter, e.g.
[nav.page; -=1; *=[config.pagesize]; negativemagnet=td ]
[onshow; val=images/[product.image].jpg; filemagnet=tr ]
In 1.0, comma is the only parameter separator instead of pipe and colon.
For backward compatibility, field parameter is not case sensitive, and deprecated alias can be used. The alias are:
add, dec, multi, div, mod, power, neg, prepostfix, sizeof, reversemagnet, nonzeromagnet, nonemptymagnet, unequalmagnet, not, and 2space.
These operations work with numbers, and have undefined result when used on or with non-numbers. Some operations (+,-,*,/,etc.) can be chained in form of ope=+=1,2,3
These operations works with strings, and have undefined result when used on or with non-string.
Most of these operations can be used to replace TinyButStrong magnets.
These operations turns value to merge into something else, sometimes with conditions.
Data would not be changed if condition is not meet.
See PHP's Boolean casting for more details.
Changelog
Todo / Idea