|
|
LinkStat
Extension list »
See also LinkProxy.
Collects statistics about links used in rendered documents.
Each call to LinkStat adds one rule; rules are applied in order they were defined to each /Link in the document. Multiple rules can apply to a link if they match.
without arguments will enable this action for current doc with default set of rules (set in the settings). {{LinkStat clear}} will clear current rules.
Examples
For example, to add «File X was downloaded N times» to each RAR or ZIP link use this rule:
{{LinkStat ([^\\/]+\.(rar|zip))$, match=1,
read=downloads -1, tooltip=download,
proxy="dl.php?{URL}"}}
Or you can count the number of all external links in your document(s) when they’re rendered, anonymize them and add a tooltip:
{{LinkStat ^http://, proxy=http://anonymize/,
read=external -1, inc=external -1
tooltip=This is external link number $.}}
Parameters
Full form:
{{LinkStat pattern, exclude=pattern,
match=indexlist, read=indexlist,
tooltip=str, proxy=str,
inc=indexlist, storage=str, breaks}}
- pattern
- A regular expression snippet; brackets will be auto-added unless it starts with "/" (in this case you can supply custom modifiers, e.g.: /regexp/i).
- exclude
- A regular expression that is matched after matching pattern; same rules for regexp brackets apply as per pattern.
- match
- Index-list of match indexes to pass to tooltip; defaults to «false». Constants (non-numbers) are passed to the tooltip as is. Indexes outside of matches are 0.
- read
- Set of index-list (see below) to pass to tooltip as format args; defaults to «false».
- tooltip
- If a language string with this name (in strings.conf) exists, it’s used; otherwise a string named "{{linkstat:" + space + this value is searched; ultimately the value itself is used if nothing else found. Gets passed matches and reads (see above). If this starts with «+» tooltip is appended, otherwise – set to. Format strings are:
- @ – fetches next value off the match parameter (exception if none left).
- $ – same as @ but for read parameter.
- the value of tooltip can be a callback function if it starts with «LinkStatCallback» (and it can have nothing else following). Its format:
PHPfunction ($matches, $reads) .
- proxy
- Changes link to this pattern – useful which tracking number of downloads. The value of «0» disables URL modification; other turns it on. Format strings are:
- {URL} – URL-encoded original link; it’s automaticaly appended if proxy URL contained none of the format strings;
- {RAW} – raw address;
- {Index} (e.g. {-1}) – is replaced by the value of given match pocket.
- inc
- Set of index-list; specifies if and where to store number of occurrences of this rule (each time summed up with previous value – on each document render). If passed as flag (just «inc») defaults to -1; if omitted – to false.
- storage
- This switches storage interface by its name in LinkStatStorages setting. If it’s invalid tooltip and inc parameters will be ignored. Defaults to default.
- breaks
- If this rule has matched all following rules will be skipped for the current link.
Index-lists
An «index-list» is either false (or no) or a string. If it’s a string, it’s a space-separated sequence of numbers and strings. Numbers refer to match pocket (0 refers to the full match and a special value of -1 (which is the default) refers to the entire URL), string is a constant (if it starts with «_» AND has at least one «_» later the first «_» is removed and all others are replaced with spaces; if it starts with "__" the first «_» is removed but all others are left intact).
«Sets of index-list» are just arrays of index-lists separated by «|». Example: «read=-1 | downloads 2». For read individual «false» index-lists result in string 0, for inc they’re ignored.
|