Hjälp: Programmer MacrosThese macros are designed to provide programming-like functionality. They are powerful when used appropriately, and dangerous when used carelessly. Take care when using these macros.
NOTE: These macros are included in WebGUI in order to provide very powerful display mechanisms. Though they could be used to write simple web applications, this is not their intended use, nor is it supported or condoned by Plain Black. If you find yourself trying to do something like that, just write a macro. =) By default these macros are disabled to protect the security of your site and server, and only your administrator can enable them.
^D; or ^D(); - Date
The current date and time.
You can configure the date by using date formatting symbols. For instance, if you created a macro like this ^D("%c %D, %y"); it would output September 26, 2001. The following are the available date formatting symbols:
%% | % | %y | 4 digit year | %Y | 2 digit year | %m | 2 digit month | %M | variable digit month | %c | month name | %d | 2 digit day of month | %D | variable digit day of month | %w | day of week name | %h | 2 digit base 12 hour | %H | variable digit base 12 hour | %j | 2 digit base 24 hour | %J | variable digit base 24 hour | %p | lower case am/pm | %P | upper case AM/PM | %z | user preference date format | %Z | user preference time format |
^Env()
Can be used to display a web server environment variable on a page. The environment variables available on each server are different, but you can find out which ones your web server has by going to: http://www.yourwebguisite.com/env.pl
The macro should be specified like this ^Env("REMOTE_ADDR");
^Execute();
Allows a content manager or administrator to execute an external program. Takes the format of ^Execute("/this/file.sh");.
^FormParam();
This macro is mainly used in generating dynamic queries in SQL Reports. Using this macro you can pull the value of any form field simply by specifing the name of the form field, like this: ^FormParam("phoneNumber");
^If();
A simple conditional statement (IF/THEN/ELSE) to control layout and messages.
Examples:
Display Happy New Year on 1st January:
^If('^D("%m%d");' eq '0101' , Happy New Year);
Display a message to people on your subnet (192.168.1.*):
^If('^Env("REMOTE_ADDR");' =~ /^192.168.1/,"Hi co-worker","Hi Stranger");
Display a message to Windows users:
^If('^Env("HTTP_USER_AGENT");' =~ /windows/i,"Hey... Linux is free !");
Display a message if a user is behind a proxy:
^If('^Env("HTTP_VIA");' ne "", You're behind a proxy !, Proxy-free is the best...);
Display Good Morning/Afternoon/Evening:
^If(^D("%J");<=12,Good Morning,^If(^D("%J");<=18,Good Afternoon,Good evening););
^Include();
Allows a content manager or administrator to include a file from the local filesystem.
Example: ^Include("/this/file.html");
^International();
Pull a translated message from the internationalization system.
Example: ^International(45,"Article");
^Quote();
Use this to escape a string before using it in a database query.
^Page();
This can be used to retrieve information about the current page. For instance it could be used to get the page URL like this ^Page("urlizedTitle"); or to get the menu title like this ^Page("menuTitle");.
^SQL();
A one line SQL report. Sometimes you just need to pull something back from the database quickly. This macro is also useful in extending the SQL Report wobject. It uses the numeric macros (^0; ^1; ^2; etc) to position data and can also use the ^rownum; macro just like the SQL Report wobject. Examples:
^SQL("select count(*) from users","There are ^0; users on this system.");
^SQL("select userId,username from users order by username","<a href='^/;?op=viewProfile&uid=^0;'>^1;</a><br>");
^URLEncode();
This macro is mainly useful in SQL reports, but it could be useful elsewhere as well. It takes the input of a string and URL Encodes it so that the string can be passed through a URL. It's syntax looks like this: ^URLEncode("Is this my string?");
^User();
This macro will allow you to display any information from a user's account or profile. For instance, if you wanted to display a user's email address you'd create this macro: ^User("email");
^*; or ^*(); - Random Number
A randomly generated number. This is often used on images (such as banner ads) that you want to ensure do not cache. In addition, you may configure this macro like this ^*(100); to create a random number between 0 and 100.
^-;,^0;,^1;,^2;,^3;, etc.
These macros are reserved for system/wobject-specific functions as in the SQL Report wobject and the Body in the Style Manager.
Se vidare: |