aks_var

Current version: 0.3a

Support forum: English
Download: aks_var

aks_var – Easy variables and calculations

Version 0.3a download link / homepage

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

Attribute Sample Description
// —— 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 + – * / …
round @‘2’@ Round value (number of digits after the decimal point)
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”@ preg_replace($regexp, $to, $value)
split @“2”@ Return part of spliting string
delim @”##”@ delim for split
// —— 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)

SPLIT

ExampleResultComments
<txp:aks_evar name="my_var" value="123:qqq" split="2" delim=":" />qqqReturn part of spliting string

.

REGEXP

Change \r\n to

<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 done

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>

0.2.1

  • Change operate order. Was: calc,substr,regexp. Now: substr,regexp,calc.

0.2.2a

  • Support TxP tags in calc attribute
  • Added attribute round

0.3

  • PHP 5.3 fix
  • Added attribute split