aks_var


Current version: 0.2.2
Support forum: English | Russian

Download: aks_var

aks_var – Easy variables and calculations TxP

Summary

aks_var operate with Txp variables and Custom Fields.

Tags

<txp:aks_var /> or <txp:aks_var>some…</txp:aks_var>
<txp:aks_evar /> same as <txp:aks_var />, but it display result. (evar – E cho VAR)

Attributes

AttributeSampleDescription
// —— input $value
name'my_var'TXP variable
customfield'my_cust_field'Custom field
value'12345 qwerty'Init value, text or digits
avar'SERVER_NAME'apache variables, same as $_SERVER[$avar]
tvar'url_title'thisarticle variables, same as $GLOBALS[‘thisarticle’][$tvar]
var'$GLOBALS["prefs"]["spam_blacklists"]'ANY variables
// —— some calc
calc'*5-(32-2)/4'Any arithmetic operations + – * / …
substr'2:7'Same as PHP substr. WARNING – NO UTF-8 support
regexp'/^(some text)/i'preg_replace($regexp, $to, $value)
to"It's $1"
// —— output $value
setname'my_var2'result to this TXP variable

.

Examples dump: :)

.
Variables

ExampleResultComments
<txp:aks_var name="my_var" value="123" />display noneset TXP variable my_var =123. It’s equal <txp:variable name=“my_var” value=“123” /> tag.
<txp:aks_evar name="my_var" />123only display my_var. It’s equal as <txp:variable name=“my_var” /> tag
<txp:aks_evar name="my_var" setname="other_var" />123other_var =my_var

.
Custom Fields

ExampleComments
<txp:aks_evar customfield="my_cust_field" />It’s equal as <txp:custom_field name=“my_cust_field” />
<txp:aks_evar customfield="my_cust_field" setname="my_var" />my_var = my_cust_field //get custom field to TxP variable
<txp:aks_evar customfield="my_cust_field" substr="0:5" setname="my_var" />my_var = substr(my_cust_field,0,5)

.
CALC

ExampleResultComments
<txp:aks_evar name="my_var" value="14" calc="/2" />7my_var =14/2
<txp:aks_evar name="my_var" calc="+1" />8my_var =my_var+1
<txp:aks_evar name="my_var" calc="*2+(24-4)/2" setname="other_var" />26other_var =my_var*2+(24-4)/2 // my_var – no change

.
SUBSTR

ExampleResultComments
<txp:aks_evar name="my_var" value="123456789" substr="3" />456789my_var =substr(‘123456789’,3) // WARNING – NO UTF-8 support
<txp:aks_evar name="my_var" substr="2:3" setname="other_var" />678other_var =substr(my_var,2,3)

.

REGEXP

Change \r\n to <br />

<txp:aks_evar regexp="/[\r\n]+/s" to="<br />">

Some text
next line
next
etc
</txp:aks_evar>

Get subdomain name. Sample: abc.domain.com => abc and www.abc.domain.com => abc

<txp:aks_evar avar='SERVER_NAME' regexp="/^(www\.)?(.*?)\..*$/i" to="$2" />

2DO

  • preg_replace done
  • apache variables done
  • some other TxP variables done
  • split

Changelog

0.2

  • add preg_replace
  • add read apache, PHP, TxP variables
  • allow include txp tags: <txp:aks_var value=”<txp:title />” /> or <txp:aks_var><txp:title /></txp:aks_var>