Buna.. Navigând pe site-urile de pe sistemul uCoz Ro, am observat că mulţi nu pot să se folosească de operatori. Care sunt aceşti operatori? Aceşti operatori sunt nişte teguri care pun condiţii pentru a permite vizualizarea unui conţinut a site-ului sau de a nu permite. De obicei aceşti operatori se folosesc pentru a pune condiţii grupurilor de utilizatori. Spre exemplu:
Quote
Daca copilul are nota 10 atunci va merge la concert sau (in caz contrar) va asta acasa sa faca temele.
Codul pentru aceasta propozitie ar trebui sa fie cam asa:
Code
<?if($NOTA$)?=10> va merge la concert<?else?> va asta acasa sa faca temele. <?endif?>
Acum să vedem cum implimentăm la noi pe site.. cea mai mare greşeală întâlnită a fost cea că oaspeţii văd linkuri cu profilul meu şi Ieşire şi invers utilizatorii logţi văd link de logare şi înregistrare...
Cum procedăm...intrăm în Top part of the website şi vedem ce teguri sunt:
Deci dacă utilizatoru este pe site si daca este logat atunii ii afisam linkul de profil si iesire in caz contrar afisam link logIn si link inregistrare. In cazul dat punem 2-uă condiţi (aşa se cere) prima condiţie daca utilizatoru este pe site şi a 2-ua dacă este logat. Întrun cât sunt 2-uă condiţi trebuie să avem 2 operatori ?endif?
Puteţi folosi operatorii ca un grup de utilizatori sa vada ceva alţii nu... Fiecare Content pot să-şi aibă proprii operator aşa că vedeţi ce şi unde folosiţi
Mai jos aveţi un tutorial chiar de pe CP:
System templates have their own simple markup language that is similar to the PHP programming language with some its elements. This language helps output (process) or do not output (do not process) template parts depending on truth or falsity of various conditions, applied to values of special variables (such as $GROUP_ID$), as well as make calculations over these variables. Template variables look like $VARNAME$, where VARNAME can contain only capital Latin letters, digits and an underscore. Each template has its own set of variables that can be used within this template.
The language of the templates allows 3 main actions:
To output a variable value by means of entering it into any place of the template (even within HTML tags).
Example:
The address of the home page of my website It will output (for $HOME_PAGE_LINK$ being equal to 'http://mysite.com'): The address of of the home page of my website
An undefined variable is considered empty.
To output the computed result of an expression , enclosed into special brackets and ?>. The expression can contain mathematical operations, comparison operations, callings of functions.
Examples:
3 plus 2 equals 3+2 ?> It will output: 3 plus 2 equals 5
In 10 years it will be the year $YEAR$+10 ?> It will output (for $YEAR$ being equal to 2010): In 10 years it will be the year 2020
Your username begins with the letter " substr($USERNAME$,0,1) ?>" It will output (for $USERNAME$ being equal to 'Admin'): Your username begins with the letter "A"
See the full list of all possible operations and functions, as well as computation rules, below.
To realize conditional processing with the help of the conditional operators and .
The syntax of conditional blocks is as follows:
expression)?>true_codefalse_code
expression)?>true_codefalse_code
expression - a mathematical or logical (Boolean) expression that is computed in order to determine its truth (for the block ) or falsity (for the block ). See the computation rules below.
true_code – the template code that will be processed in case of fulfillment of the condition, set by the conditional operator.
false_code – the template code that will be processed in case of non-fulfillment of the condition, set by the conditional operator (can be fully absent together with the operator '', if only truth check is needed).
Conditional blocks can be nested. Up to 10 nesting levels are allowed.
Examples:
You $USER_LOGGED_IN$)?>logged in as "$USERNAME$"did not log in It will output (for $USERNAME$ being equal to 'Admin'): You logged in as "Admin" if $USER_LOGGED_IN$ is true, otherwise You did not log in .
$USERNAME$='Hacker' or $USERNAME$='bad_boy' or substr($USERNAME$,0,4)='anti')?>Got you, $USERNAME$!!! It will output (having substituted $USERNAME$ by its value): Got you, $USERNAME$!!!, if $USERNAME$ equals 'Hacker' or 'bad_boy', or begins with 'anti'.
$POSTS$>50)?>***$POSTS$>10.0)?>*** It will output ' *** ', if $POSTS$ is greater than 50, ' ** ', if it is greater than 10 and less than or equal to 50, and ' * ' if it is less than or equal to 10.
$NUMBER$ % 2 = 1)?>oddeven It will output whether the number in $NUMBER$ is even or odd.
Computing of expressions:
There are 3 types of operands: string (specify text), integer (specify an integer number from -9223372036854775808 to 9223372036854775807), fractional (specify a fractional number).
String operands are specified as template variables ($USERNAME$) or constants within single ('Constant1') or double quotes ("Constant2"). In case it is necessary to use the quote symbol within the constant itself, it can be screened off by means of a backslash ('It\'s all right' will be read as "It's all right"). The backslash itself can be screened as well ("big\\small" will be read as "big\small"). The backslash has no screening effect before all other characters and is displayed together with the subsequent character. Within string constants a closing bracket is not allowed ?>, as it will be interpreted as an indicator of expression end.
Integer operands can be specified in decimal, binary, octal or hexadecimal numeral systems. Decimal constants are specified as a sequence of digits from 0 to 9 (123, 999999, 3). Binary constants begin with the prefix "0b" (or "0B"), followed by a sequence of digits 0 and 1 (0b1000 sets number 8, 0B11111111 sets number 255). Octal constants begin with the prefix "0o" (or "0O"), followed by digits from 0 to 7 (0o200 sets number 128, 0o456 sets number 302). Hexadecimal constants begin with the prefix "0x" (or "0X"), followed by digits from 0 to 9 and Latin letters from A to F, case-insensitive (0x10A sets number 266, 0Xffff sets number 65535).
Fractional operands are specified as a sequence of digits from 0 to 9 which contains necessarily a decimal point (123.56) or the Latin letter E that separates the decimal exponent (1.234e6 sets number 1234000, 1e3 sets number 1000, 2e-4 sets number 0.0002), or the number value is outside the permissible range for integer operands.
All operators described below, except for the described separately, transform automatically their operands into the necessary type (the expression "5" + 3?> will return 8). When transforming a string value into a numerical value, the rules from item 4 are used (i.e. the result will be always interpreted as fractional, and alternative numerical systems are not recognized) and additionally the minus character (-) before the number is recognized. Transformation of a string into a number stops on the first inadmissible character, leading spaces are ignored. Integer operands are transformed into a string without the loss of accuracy and without the use of decimal fractions (1234567890123445678 ?> will output '1234567890123445678'). Fractional operands are transformed into a string in the format with a floating point accurate to 15 decades (1234567890123445678.0 ?> will output '1.23456789012346e+17').
Expressions are computed with account of operation priorities. A priority can be controlled by means of brackets (the expression 2 * (5 + 3)?> will return 16). If brackets are absent, priority of operators is determined by the following table (in the order of priority decreasing):
unary +, unary -, ~, not, !, all functions
**
*, /, %
+, -
=, ==, !=, <=, <, >=, >
&
|, ^
&&, and
||, or
An expression is considered false if its computed result is an empty string, the string '0' (i.e. a string with the only digit 0, and strings '4', 'Hello', '00' or '0.0' are considered true), an integer value 0 or a fractional value 0.0. All other values are considered true.
Arithmetic operators:
+, -, *
Binary arithmetic addition, subtraction, multiplication correspondingly. If both operands are integer, the result will be integer as well (it must not be outside the range of integer values).
unary +, unary -
It is equivalent to adding to zero or subtracting from zero correspondingly, but it has a high priority.
/
Arithmetic division. The result is always fractional.
%
Residue of division. Operands are reduced to integer numbers. The result is always integer.
**
Binary exponential operation. The first operand (must be positive) is raised to the power of the second one. The result is always fractional.
Comparison operators:
=, ==
Equality check. If two operands are string then strings are compared with the account of case (lowercase and uppercase letters are differentiated). If both operands are integer then integer numbers are compared. Otherwise operands are compared as fractional numbers. The result of the operator is the integer number 1 if operands are equal and 0 if operands are not equal. Examples:"1.000"="1.0")?> is false (are compared as strings), "1.000"="1.0"+0)?> is true (numbers are compared).
!=
Inequality check. It is similar to equality check but the result is the opposite.
<=, <, >=, >
Comparison of two numbers. If both operands are integer the integer numbers are compared. Otherwise operands are compared as fractional numbers. The result of the operator is the integer number 1 if the operator condition holds, and 0 if the condition does not hold.
Logical operators:
!, not
Unary operator of logical negation. If the operand is false the result is the integer number 1, otherwise it is 0.
&&, and
Binary operator of logical "And" (multiplication). If both operands are true, the result is the integer number 1, otherwise it is 0.
||, or
Binary operator of logical "Or" (addition). If any of the operands is true, the result is the integer number 1, otherwise it is 0.
Bitwise operators always reduce operands to an integer number and return an integer result:
&, |, ^
Binary operators of bitwise "And" (multiplication), "Or" (addition) and "Exclusive Or" correspondingly.
~
Unary operator of bitwise negation (inversion).
Functions:
int N int(N)
It returns the integer part of the numeric parameter N, obtained by means of rounding toward zero. The result is always integer.
abs N abs(N)
It returns the absolute value (module) of the numeric parameter N. If the operand is integer, the result will be integer as well. Otherwise it will be fractional.
rnd( ) rnd N rnd(N)
It returns a random number. If the parameter is absent or equal to 0, then a fractional number from 0 inclusively to 1 non-inclusively is returned. If the parameter is integer (not equal to 0), then an integer number from 0 to N-1 inclusive when N>0 and a number from N+1 to 0 inclusive when N<0 is returned. Otherwise the parameter is reduced to a fractional number and is multiplied by a random fractional number from 0 inclusive to 1 non-inclusive. Examples: rnd 10 ?> will return an integer number from 0 to 9 inclusive, rnd 10.0 ?> will return a fractional number from 0 to 10 non-inclusive.
min(A1,A2,...,An) max(A1,A2,...,An)
It returns correspondingly the minimum or the maximum value among the returned numerical parameters. The result is always fractional.
len S len(S)
It returns the length of the string parameter. The result is always integer.
strpos(S1,S2)
It finds the first occurrence of string S2 in string S1, going from the beginning of S1 to the end. The comparison is case-sensitive. Both parameters must be specified as strings (or as a result of calling a function that returns a string). The search is limited by the first 1000 characters of string S1. The comparison is limited by the first 100 characters of string S2. It returns an integer number – the position of string S2 from the beginning of S1, counting from 0. If the occurrence was not found, it returns -1. (strpos('Mikyky','ky')?> will return 2).
strrpos(S1,S2)
It is similar to strops but finds the last occurrence of S2. The search is limited by the last 1000 characters of string S1. (strpos('Mikyky','ky')?> will return 4).
substr(S,N1,N2) substr(S,N1)
It returns a substring from string S, starting from position N1 (the first character has position 0), of the length equal to N2 characters. Parameter S must be specified as a string (or as a result of calling a function that returns a string). N1 and N2 are reduced to integer values. If N2 is not specified then a substring from position N1 to the end of string S is returned. If N1 is negative then the initial position is counted from the end of string S. If N2 is negative then it sets the final position from the end of string S. (substr('Hello',2)?> will return 'llo', substr('Hello',2,2)?> will return 'l', substr('Hello',-2)?> will return 'lo',substr('Hello',0,-2)?> will return 'Hel').