SigServer:SignatureMath: Difference between revisions

no edit summary
No edit summary
 
(42 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{TOCright}}
Back to: [[SigServer:Documentation]]
== Language Reference ==
== Language Reference ==


=== Basic Syntax ===
=== Basic Syntax ===
Before the XML is parsed the Signature engine looks for opening and closing tags ({{ and }}). Everything between those are interpreted as Signature Math (from now on abbreviated SigMath) and parsed before the XML parser takes action. Every opening tag must be followed by a closing tag.
Before the XML is parsed the Signature engine looks for opening and closing tags (<nowiki>{{ and }}</nowiki>). Everything between those are interpreted as Signature Math (from now on abbreviated SigMath) and parsed before the XML parser takes action. Every opening tag must be followed by a closing tag.


'''Example'''
'''Example'''
  <text>
  <text>
   <line>{{ 2 + 3 }}</line>
   <line><nowiki>{{ 2 + 3 }}</nowiki></line>
  </text>
  </text>


Line 18: Line 22:


Number may be either float or integer.
Number may be either float or integer.
'''Example: Numbers'''
1
The above example is classified as a number.
1.1
This example is also classified as a number.
"1"
This is too a number, because a check is performed on every string to see whether it is a number or not.
-1
This is a negative number. As of version 1.1.0, they are now supported without hacks.
'''Example: Strings'''
"string"
'string'
" 1"
All three examples are strings. Both " and ' may be used with strings. You cannot escape anything inside a string. This means <code><nowiki>{{ "}}" }}</nowiki></code> or <code><nowiki>{{ "\"" }}</nowiki></code> gives you an error message.
'''Example: Boolean'''
true
false
Boolean values may only be lower case.
=== Operators ===
SigMath supports some basic operators. Arithmetic operators have the highest priority. Comparison operators have the second highest priority. Logic operators have the least priority. Brackets may be used to group expressions, such as (1 + 2) * 3 = 9.
==== Arithmetic Operators ====
;+
:Adds two numbers. If one of the arguments are a string the second argument will be appnended to the first.
;-
:Subracts two numbers.
;<nowiki>*</nowiki>
:Takes the first argument times the second.
;/
:Divides the first argument with the second.
==== Comparison Operators ====
;<
:Checks if the first argument is smaller than the second. If so ''true'' is returned.
;>
:Checks if the first argument is bigger than the second. If so ''true'' is returned.
;<=
:Checks if the first argument is smaller than or equal to the second. If so ''true'' is returned.
;>=
:Checks if the first argument is bigger than or equal to the second. If so ''true'' is returned.
;==
:Checks if the first argument is equal to the second. If so ''true'' is returned.
;!=
:Checks if the first argument is not equal to the second. If so ''true'' is returned.
==== Logic Operators ====
;||
:Checks if the first argument or the second argument are true. If so ''true'' is returned.
;&&
:Checks if the first argument and the second argument are true. If so ''true'' is returned.
;!
:Returns the opposite of the immediately following boolean value.


=== Variables ===
=== Variables ===
SigMath have support for variables. It supports both [[SigServer:Variables|AniDB variables]] and [[SigServer:Variables|user defined variables]]. AniDB variables are prefixed with $ and user defined variables with @
SigMath has support for variables. It supports both [[SigServer:Variables|AniDB variables]] and user defined. AniDB variables are prefixed with $ and user defined variables with @.
 
'''Example'''
<nowiki>{{ $example }}</nowiki>
<nowiki>{{ @example }}</nowiki>
The first block outputs the AniDB variable named ''example''. The second block outputs the user defined variable named ''example''. A user defined variable may have the same name as an AniDB variable. The variables are only alphanumeric and may contain _ as well.
 
Setting a variable is quite straight-forward.
 
'''Example'''
<nowiki>{{ @example = "Where's the money Lebowski?" }}</nowiki>
 
This will set the variable ''@example'' to ''Where's the money Lebowski?''. It's possible to redefine variables throughout the code.


'''Example'''
'''Example'''
  {{ $example }}
  <nowiki>{{ @example = "Where's the money Lebowski?" }}</nowiki>
  {{ @example }}
  <nowiki>{{ @example = @example + " said Boris" }}</nowiki>
The first block outputs the AniDB variable named ''example''. The second block outputs the user defined variable named ''example''
 
This will set the variable ''@example'' to ''Where's the money Lebowski? said Boris''.
 
This method can override AniDB variables.
 
=== Functions ===
SigMath supports a range of functions. Arguments are separated by comma, and each argument is evaluated before it is passed on to the function. For a complete list of all functions see the [[#Function Reference|function reference]].


== Function Reference ==
== Function Reference ==
Line 32: Line 110:


==== abs ====
==== abs ====
  ''number'' '''abs'''(''number'' value);
  ''number'' '''abs'''(''number'' value)
Returns the absolute value of a number
Returns the absolute value of a number


'''Example'''
Example:
  abs(1); // Returns 1
  <nowiki>{{ abs(1) }} <!-- Returns 1 --></nowiki>
  abs(-1); // Returns 1
  <nowiki>{{ abs(-1) }} <!-- Returns 1 --></nowiki>


==== ceil ====
==== ceil ====
  ''number'' '''ceil'''(''number'' value);
  ''number'' '''ceil'''(''number'' value)
Returns the ceiling of a number.
Returns the ceiling of a number.


'''Example'''
Example:
  ceil(1.4); // Returns 2
  <nowiki>{{ ceil(1.4) }} <!-- Returns 2 --></nowiki>
  ceil(1.9); // Returns 2
  <nowiki>{{ ceil(1.9) }} <!-- Returns 2 --></nowiki>
 
==== div ====
''number'' '''div'''(''number'' dividend, ''number'' divisor)
Returns the integer quotient when dividing dividend with divider.
 
Example:
<nowiki>{{ div(10, 3) }} <!-- Returns 3 --></nowiki>


==== floor ====
==== floor ====
  ''number'' '''floor'''(''number'' value);
  ''number'' '''floor'''(''number'' value)
Returns the floor of a number.
Returns the floor of a number.


'''Example'''
Example:
  floor(1.1); // Returns 1
  <nowiki>{{ floor(1.1) }} <!-- Returns 1 --></nowiki>
  floor(1.9); // Returns 1
  <nowiki>{{ floor(1.9) }} <!-- Returns 1 --></nowiki>


==== max ====
==== max ====
  ''number'' '''max'''(''number'' value1, ''number'' value2[, ''number'' ...]);
  ''number'' '''max'''(''number'' value1, ''number'' value2[, ''number'' ...])
Returns the numerically highest value of the given arguments. At least two arguments are required.
Returns the numerically highest value of the given arguments. At least two arguments are required.


'''Example'''
Example:
  max(3, 5);           // Returns 5
  <nowiki>{{ max(3, 5) }}           <!-- Returns 5 --></nowiki>
  max(3, 1.2, 5, 5.1); // Returns 5.1
  <nowiki>{{ max(3, 1.2, 5, 5.1) }} <!-- Returns 5.1 --></nowiki>
 


==== min ====
==== min ====
  ''number'' '''min'''(''number'' value1, ''number'' value2[, ''number'' ...]);
  ''number'' '''min'''(''number'' value1, ''number'' value2[, ''number'' ...])
Returns the numerically lowest value of the given arguments. At least two arguments are required.
Returns the numerically lowest value of the given arguments. At least two arguments are required.


'''Example'''
Example:
  min(3, 5);           // Returns 3
  <nowiki>{{ min(3, 5) }}           <!-- Returns 3 --></nowiki>
  min(3, 1.2, 5, 5.1); // Returns 1.2
  <nowiki>{{ min(3, 1.2, 5, 5.1) }} <!-- Returns 1.2 --></nowiki>


==== mod ====
==== mod ====
  ''number'' '''mod'''(''number'' dividend, ''number'' divisor);
  ''number'' '''mod'''(''number'' dividend, ''number'' divisor)
Returns the reminder when dividing dividend with divider.
Returns the reminder when dividing dividend with divider.


'''Example'''
Example:
  mod(10, 3); // Returns 1
  <nowiki>{{ mod(10, 3) }} <!-- Returns 1 --></nowiki>


==== pow ====
==== pow ====
  ''number'' '''pow'''(''number'' base, ''number'' exp);
  ''number'' '''pow'''(''number'' base, ''number'' exp)
Returns base to the power of exp.
Returns base to the power of exp.


'''Example'''
Example:
  pow(3, 2); // Returns 9
  <nowiki>{{ pow(3, 2) }} <!-- Returns 9 --></nowiki>
  pow(2, 3); // Returns 8
  <nowiki>{{ pow(2, 3) }} <!-- Returns 8 --></nowiki>
 
==== random ====
''number'' '''random'''(''number'' start, ''number'' end)
Returns a random integer from the set of integers starting at start and ending at end.
 
Example:
<nowiki>{{ random(1, 10) }}  <!-- Returns a random integer from 1 to 10 --></nowiki>
<nowiki>{{ random(0, 100) }} <!-- Returns a random integer from 0 to 100 --></nowiki>


==== round ====
==== round ====
  ''number'' '''round'''(''number'' value[, ''number'' precision]);
  ''number'' '''round'''(''number'' value[, ''number'' precision])
Returns base to the power of exp.
Returns a rounded number with the given precision. If precision isn't specified it will return an integer.


'''Example'''
Example:
  round(2.4);     // Returns 2
  <nowiki>{{ round(2.4) }}     <!-- Returns 2 --></nowiki>
  round(2.5);     // Returns 3
  <nowiki>{{ round(2.5) }}     <!-- Returns 3 --></nowiki>
  round(2.55, 1); // Returns 2.6
  <nowiki>{{ round(2.55, 1) }} <!-- Returns 2.6 --></nowiki>


==== sqrt ====
==== sqrt ====
  ''number'' '''sqrt'''(''number'' value);
  ''number'' '''sqrt'''(''number'' value)
Returns the square root of value.
Returns the square root of value.


'''Example'''
Example:
  sqrt(9); // Returns 3
  <nowiki>{{ sqrt(9) }} <!-- Returns 3 --></nowiki>


=== Miscellaneous ===
=== Miscellaneous ===
==== date ====
''string'' '''date'''(''string'' format[, ''string'' time[, ''number'' offset]])
''string'' '''date'''(''string'' format[, ''number'' timestamp[, ''number'' offset]])
''string'' '''date'''(''string'' format, "now"[, ''number'' offset])
Returns the date and time in the format specified by the first argument. The format syntax is the same as [https://secure.php.net/manual/en/function.date.php PHP's date()]. The first optional argument may be either:
* a string with date
* a Unix timestamp
* the string "now", in the case you want to use the third argument with the current timestamp
The second optional argument specifies the number of seconds to add or subtract from the specified time. This is useful if you want to shift all dates in your signature to a different timezone than the server is running on.
Example:
<nowiki>{{ date("Y-m-d") }}                        <!-- Returns current date e.g. "2007-11-20" --></nowiki>
<nowiki>{{ date("H:i:s") }}                        <!-- Returns current time, e.g. "19:50:37" --></nowiki>
<nowiki>{{ date("Y-m-d", "1995-10-03T20:30:37") }} <!-- Returns date "1995-10-03" --></nowiki>
<nowiki>{{ date("Y-m-d H:i:s", "1995-10-03T20:30:37", -7200) }} <!-- Returns "1995-10-03 18:30:37" --></nowiki>
==== fetchvar ====
''string'' '''fetchvar'''(''string'' variable)
Returns the variable given as an argument.
Example:
<nowiki>{{ @test1 = "Hi!" }}</nowiki>
<nowiki>{{ fetchvar("@test1") }}    <!-- Returns "Hi!" --></nowiki>
<nowiki>{{ fetchvar("@test" + 1) }} <!-- Returns "Hi!" --></nowiki>
<nowiki>{{ @test2 = 1 }}</nowiki>
<nowiki>{{ fetchvar("$latestwatched_id" + @test2 + "_aname") }} <!-- Returns the name of the latest watched anime --></nowiki>
==== fsformat ====
''string'' '''fsformat'''(''number'' sizeInMiB[, ''number'' decimals[, ''boolean'' tenBasedExponents ]])
Formats the given file size according to the given parameters, using the most fitting unit for its size. File sizes should be expressed in MiB, as given by the system provided variables. The decimals argument specifies how many decimal numbers should be printed after the decimal point; the default value is 2. By default, 2<sup>n</sup> based units are used (1 GiB = 2<sup>10</sup> MiB = 1024 MiB), but this can be toggled to use 10<sup>n</sup> based units instead (1 GB = 10<sup>3</sup> MB = 1000 MB) by setting the third argument to true.
Example:
<nowiki>{{ fsformat(1024) }} <!-- Returns "1.00 GiB" --></nowiki>
<nowiki>{{ fsformat(1024, 2, true) }} <!-- Returns "1.02 GB" --></nowiki>
<nowiki>{{ fsformat(1048576, 0) }} <!-- Returns "1 TiB" --></nowiki>
<nowiki>{{ fsformat(1234, 6) }} <!-- Returns "1.205078 GiB" --></nowiki>


==== if ====
==== if ====
''Alias of [[#notempty|notempty();]]
''Alias of [[#notempty|notempty()]]''
 
==== lc ====
''Alias of [[#lowercase|lowercase()]]''
 
==== length ====
''number'' '''length'''(''string'' value)
Returns the number of characters of the string.
 
Example:
<nowiki>{{ length("Foobar") }}  <!-- Returns 6 --></nowiki>
<nowiki>{{ length("") }}        <!-- Returns 0 --></nowiki>
<nowiki>{{ length("Foo bar.") }} <!-- Returns 8 --></nowiki>
 
==== lengthw ====
''number'' '''lengthw'''(''mixed'' string[, ''string'' font[, ''number'' size]])
Returns width of given string in pixels. Default font is ''verdana''. Default size is ''12'' pixels.
 
Example:
<nowiki>{{ lengthw("Foobar") }}              <!-- Returns 54 --></nowiki>
<nowiki>{{ lengthw("") }}                    <!-- Returns 2, due to the way the bounding box works. --></nowiki>
<nowiki>{{ lengthw("Foobar", "comic", 10) }}  <!-- Returns 55 --></nowiki>
 
==== lowercase ====
''string'' '''lowercase'''(''mixed'' value[, ''string'' options])
If only first argument is specified it converts all the characters to lower case. The second argument may be "first" or "words". If it is "first" only the string's first character will be converted. If it is set to "words", every word's first character will be converted.
 
Example:
<nowiki>{{ lowercase("Foo Bar") }}          <!-- Returns "foo bar" --></nowiki>
<nowiki>{{ lowercase("Foo Bar", "first") }} <!-- Returns "foo Bar" --></nowiki>
<nowiki>{{ lowercase("Foo BAR", "words") }} <!-- Returns "foo bAR" --></nowiki>


==== notempty ====
==== notempty ====
  ''mixed'' '''notempty'''(''mixed'' value[, ''string'' true[, ''string'' false]]);
  ''mixed'' '''notempty'''(''mixed'' value[, ''mixed'' true[, ''mixed'' false]])
Check's if the first argument is not empty. Returns TRUE or FALSE if the optional arguments aren't specified. If they are specified it returns the second argument if TRUE and the third argument if FALSE.
Checks if the first argument is not empty. Returns TRUE or FALSE if the optional arguments aren't specified. If they are specified it returns the second argument if TRUE and the third argument if FALSE.


'''Example'''
Example:
  notempty("");                      // Returns false
  <nowiki>{{ notempty("") }}                      <!-- Returns false --></nowiki>
  notempty("Foobar");                // Returns true
  <nowiki>{{ notempty("Foobar") }}                <!-- Returns true --></nowiki>
  notempty(6 > 2);                  // Returns true
  <nowiki>{{ notempty(6 > 2) }}                    <!-- Returns true --></nowiki>
  notempty("", "Not empty", "Empty") // Returns "Empty"
  <nowiki>{{ notempty("", "Not empty", "Empty") }} <!-- Returns "Empty" --></nowiki>


==== padding ====
==== padding ====
  ''string'' '''padding'''(''mixed'' value, ''number'' padding[, ''string'' align]);
  ''string'' '''padding'''(''mixed'' value, ''number'' padding[, ''string'' align])
Takes value and adds padding on left side if third argument isn't specified. Third argument is optional and may be "left" or "right" and specifies the padding alignment. Second argument specifies the padding width.
Takes value and adds padding on left side if third argument isn't specified. Third argument is optional and may be "left" or "right" and specifies the padding alignment. Second argument specifies the padding width.


'''Example'''
Example:
  padding("2.40", 6);         // Returns "  2.40"
  <nowiki>{{ padding("2.40", 6) }}         <!-- Returns "  2.40" --></nowiki>
  padding("12.40", 6);       // Returns " 12.40"
  <nowiki>{{ padding("12.40", 6) }}       <!-- Returns " 12.40" --></nowiki>
  padding("2.40", 6, "left"); // Returns "2.40  "
  <nowiki>{{ padding("2.40", 6, "left") }} <!-- Returns "2.40  " --></nowiki>
  padding("1220.40", 6);     // Returns "1220.40"
  <nowiki>{{ padding("1220.40", 6) }}     <!-- Returns "1220.40" --></nowiki>
 
==== date ====
''string'' '''date'''(''string'' format[, ''string'' time]);
Returns date and time according to the first argument. The format syntax is the same as PHP's date(). The optional argument may be a timestamp or string with date.
 
'''Example'''
date("Y-m-d");                        // Returns current date e.g. "2007-11-20"
date("H:i:s");                        // Returns current time, e.g. "19:50:37"
date("Y-m-d", "1995-10-03T20:30:37"); // Returns date "1995-10-03"


==== precision ====
==== precision ====
  ''string'' '''precision'''(''number'' value, ''number'' precision);
  ''string'' '''precision'''(''number'' value, ''number'' precision)
Returns string containing value with a fixed number of decimals.
Returns string containing value with a fixed number of decimals.


'''Example'''
Example:
  precision(5, 2);   // Returns "5.00"
  <nowiki>{{ precision(5, 2) }}   <!-- Returns "5.00" --></nowiki>
  precision(5.25, 1); // Returns "5.2"
  <nowiki>{{ precision(5.25, 1) }} <!-- Returns "5.2" --></nowiki>
  precision(5.26, 1); // Returns "5.3"
  <nowiki>{{ precision(5.26, 1) }} <!-- Returns "5.3" --></nowiki>
  precision(5.24, 1); // Returns "5.2"
  <nowiki>{{ precision(5.24, 1) }} <!-- Returns "5.2" --></nowiki>


==== precision ====
==== truncate ====
  ''string'' '''truncate'''(''string'' value, ''number'' length[, ''string'' appendage]);
  ''string'' '''truncate'''(''string'' value, ''number'' length[, ''string'' appendage])
Returns the string truncated to specified length. If third argument is specified it will be appended to the returned string if it's truncated.
Returns the string truncated to specified length. If third argument is specified it will be appended to the returned string if it's truncated.


'''Example'''
Example:
  truncate("Foobar", 3);       // Returns "Foo"
  <nowiki>{{ truncate("Foobar", 3) }}       <!-- Returns "Foo" --></nowiki>
  truncate("Foobar", 4, ".."); // Returns "Fo.."
  <nowiki>{{ truncate("Foobar", 4, "..") }} <!-- Returns "Fo.." --></nowiki>
  truncate("Foob", 4, "..");   // Returns "Foob"
  <nowiki>{{ truncate("Foob", 4, "..") }}   <!-- Returns "Foob" --></nowiki>
 
==== truncatew ====
''string'' '''truncatew'''(''mixed'' string, ''number'' width[, ''string'' font[, ''number'' size[, ''string'' appendage]]])
Returns the string truncated to specified width in pixels. Default font is ''verdana''. Default size is ''12'' pixels. If ''appendage'' is set it will be appended when truncated.
 
Example:
<nowiki>{{ truncatew("Foobar", 60) }}                      <!-- Returns "Foobar" --></nowiki>
<nowiki>{{ truncatew("Foobar", 30) }}                      <!-- Returns "Foo" --></nowiki>
<nowiki>{{ truncatew("Foobar", 30, "comic", 10) }}        <!-- Returns "Foo" --></nowiki>
<nowiki>{{ truncatew("Foobar", 30, "comic", 10, "...") }}  <!-- Returns "Fo..." --></nowiki>
 
==== uc ====
''Alias of [[#uppercase|uppercase()]]''
 
==== uppercase ====
''string'' '''uppercase'''(''mixed'' value[, ''string'' options])
If only first argument is specified it converts all the characters to upper case. The second argument may be "first" or "words". If it is "first" only the string's first character will be converted. If it is set to "words", every word's first character will be converted.
 
Example:
<nowiki>{{ uppercase("Foo Bar") }}          <!-- Returns "FOO BAR" --></nowiki>
<nowiki>{{ uppercase("foo bar", "first") }} <!-- Returns "Foo bar" --></nowiki>
<nowiki>{{ uppercase("foo baR", "words") }} <!-- Returns "Foo BaR" --></nowiki>
 
[[Category:SigServer]]
92

edits

MediaWiki spam blocked by CleanTalk.
MediaWiki spam blocked by CleanTalk.