Difference between revisions of "Creating Complex Sites With ActionApps"

From ActionApps Documentation
Jump to: navigation, search
Line 2: Line 2:
 
<div class="aafaq" id="faq1680"><aafaq id=1680> ~ToDo: id=1680 How to use Site Module </aafaq>
 
<div class="aafaq" id="faq1680"><aafaq id=1680> ~ToDo: id=1680 How to use Site Module </aafaq>
 
==== FAQ: How to use Site Module ====
 
==== FAQ: How to use Site Module ====
 
  
 
<strong>Site Module</strong>
 
<strong>Site Module</strong>
<p style="margin-bottom: 0cm;">Current APC ActionApps are very good
+
So far the best approach to biuild/manage a website of a medium to great complexity with ActionApps is to use the [[Term#Site_module|Site Module]]. It helps combining several views /slices into one page.  
for creation of small or not so complex database driven sites.  It
 
was not so easy to create complex websites with many cooperating
 
slices and views, so far. The �site module� is the answer
 
for those, who wants to build complex websites using APC AA.
 
  
<p style="margin-bottom: 0cm;">At the time I wrote the text, the only
+
We are going to use Econnect's site as an example, to demonstarte basic principles.
sites driven by �site module� is the Econnect site
 
<a href="http://ecn.cz/">http://ecn.cz</a>. ChangeNet site
 
<a href="http://changenet.sk/">http://changenet.sk</a> and example
 
site on Sourceforge <a href="http://actionapps.org/slices/">
 
http://action.org/slices/</a>.  I describe the
 
site module on Econnect's site. You will see, that the principles are
 
similar to all �site module� based websites.
 
  
<p style="margin-bottom: 0cm;">The site module is part of AA admin
+
The site module is part of AA admin interface, just like other modules are. You can access it from
interface, just like other modules are. You can access it from
+
'Switch to' selectbox, if you have permission to. Site module allows you to describe structure of the site ? you modify there so called sitetree. Sites based on the module do not need any special
'Switch to' selectbox, if you have permission to. Site module allows
+
files (like shtml, ...) - whole site could be managed using AA admin interface (there is no need for FTP access (with one exception 'main control script' file described later)).  How to describe the structure we will see latter in this text.
you to describe structure of the site you modify there so
 
called sitetree. Sites based on the module do not need any special
 
files (like shtml, ...) - whole site could be managed using AA admin
 
interface (there is no need for FTP access (with one exception
 
'main control script' file described later)).  How to describe the
 
structure we will see latter in this text.
 
  
 
<strong>Idea - State and sessions</strong>
 
<strong>Idea - State and sessions</strong>
<p style="margin-bottom: 0cm;">The first estimation in creation of
+
The primary consideration during the [[Term#Site_module|Site Module]] planning was performance. The complex sites used to be sites with many visitors a day. For better performance is good to be able cache the generated pages. However, in "pre-site module" approach each user gets its own session
site module was the need to write it as fast as possible. The complex
+
id, which is unique for the user and help us to store the state, where the user user is within the site (which page on page-scroller she is on, ...). It is good, but it is extremely hard to cache such informations. That's why we develop the site module without sessions variables given to each user. We use '''state string''' instead. There we store the state, where the user is within the
sites used to be sites with many visitors a day. For better
+
website.
performance is good to be able cache the generated pages. However, in
+
State string is variable which we call <code>'''apc'''</code> (stands for 'Application Pointer Cache' :-) the name of this variable is given ? it have special behavior inside APC AA (it is automatically added to all links generated by APC AA, for example).
�pre-site module� approach each user gets its own session
 
id, which is unique for the user and help us to store the state,
 
where the user user is within the site (which page on page-scroller
 
she is on, ...). It is good, but it is extremely hard to cache such
 
informations. That's why we develop the site module without sessions
 
variables given to each user. We use �state string�
 
instead. There we store the state, where the user is within the
 
website.<br />State string is variable which we call �apc�
 
(stands for �Application Pointer Cache� :-) the name of
 
this variable is given it have special behavior inside APC AA
 
(it is automatically added to all links generated by APC AA, for
 
example).<br />The �apc� variable is added to all links in
 
AA so you every time know, where the user was in step before. <br />For
 
example: if you get the link http://ecn.cz/index.stm?apc=zzvx1--&...,
 
you know, that user was in
 
�news-alerts-all_categories-all_regions-page1� page on
 
the site. How it is coded into �apc� state string is
 
another thing (and it is in most cases up to you) � will be
 
described in next caption.
 
  
<strong>�apc� state string</strong>
+
The <code>apc</code> variable is added to all links in AA so you every time know, where the user was in step before.  
<p style="margin-bottom: 0cm;">As you can see, the Econnect's apc
+
For example: if you get the link http://ecn.cz/index.stm?apc=zzvx1--&..., you know, that user was in "news-alerts-all_categories-all_regions-page1" page on the site. How it is coded into "apc? state string is another matter (and it is in most cases up to you) ? will be described in next caption.
state string consist of seven state variables � each character
 
in the string is one variable in our case, but it is not a rule (in
 
fact the fifth state variable - �p� - page could be more
 
than one character long). All the state variables are defined in main
 
control file for the site - /module/site/sites/site_xxx.php3 (or its
 
alternative called (for security reasons) through http:// call). In
 
this file you define not only the number of state variables, the
 
regular expression for extraction the variables from apc state
 
string, but you specify there also the ways, how we have to change
 
the state. For example, if the site_xxx.php3 file gets the following
 
url parameter:<br /><br />  <a href="http://ecn.cz/index.stm?apc=zzvx1--&p=3">http://ecn.cz/index.stm?apc=zzvx1--&p=3</a>
 
<p style="margin-bottom: 0cm;">the state variable is changed to
 
apc=zzvx3--, which means that you are on the same webpage, but on the
 
page 3.
 
  
<p style="margin-bottom: 0cm;">Now we describe the variables used on
+
<strong><code>apc</code> state string</strong>
Econnect's site, but keep in mind, that the variables used in your
+
As you can see, the Econnect's apc
site could be different (if you will).
+
state string consist of seven state variables - each character in the string is one variable in our case, but it is not a rule (in fact the fifth state variable - <code>p</code> - page could be more
<p style="margin-bottom: 0cm;">
+
than one character long). All the state variables are defined in main control file for the site - /module/site/sites/site_xxx.php3 (or its alternative called (for security reasons) through http:// call). In this file you define not only the number of state variables, the regular expression for extraction the variables from apc state string, but you specify there also the ways, how we have to change the state. For example, if the site_xxx.php3 file gets the following
 +
url parameter:
 +
 
 +
&lt;a href="http://ecn.cz/index.stm?apc=zzvx1--&p=3"&gt;http://ecn.cz/index.stm?apc=zzvx1--&p=3&lt;/a&gt;
 +
 
 +
the state variable is changed to apc=zzvx3--, which means that you are on the same webpage, but on the page 3.
 +
 
 +
Now we describe the variables used on Econnect's site, but keep in mind, that the variables used in your site could be different (if you wish).
  
 
<table width="642" cellspacing="0" cellpadding="4" bordercolor="#000000" border="1" style="page-break-inside: avoid;">
 
<table width="642" cellspacing="0" cellpadding="4" bordercolor="#000000" border="1" style="page-break-inside: avoid;">
Line 110: Line 66:
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
<br />Main classification of pages Econnect's pages are
+
<br />Main classification of pages ? Econnect's pages are
divided into three webs:<br />z zpravodajstvi (news)<br />e
+
divided into three webs:<br />z ? zpravodajstvi (news)<br />e ?
econnect<br />n nno (NGO related news)
+
econnect<br />n ? nno (NGO related news)
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 127: Line 83:
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
<br />Each web (w) is divided into subwebs, so for example web z
+
<br />Each web (w) is divided into subwebs, so for example web z ?
zpravodajstvi contains:<br />|z news<br />k
+
zpravodajstvi contains:<br />|z ? news<br />k ?
comments<br />t press releases<br />...
+
comments<br />t ? press releases<br />...
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 160: Line 116:
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
<br />The same as f primary use for region selection
+
<br />The same as f ? primary use for region selection
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 185: Line 141:
 
</td>
 
</td>
 
<td width="79" valign="top">
 
<td width="79" valign="top">
<br />t (type)
+
t (type)
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
<br />Any letter
+
Any letter
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
<br />Special type of output like 'text only', 'printer
+
<br />Special type of output ? like 'text only', 'printer
 
friendly', ...
 
friendly', ...
 
</td>
 
</td>
Line 200: Line 156:
 
</td>
 
</td>
 
<td width="79" valign="top">
 
<td width="79" valign="top">
<br />x (item)
+
x (item)
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
<br />Any number
+
Any number
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
<br />Id of item to show (like 24365) as you see it could be
+
Id of item to show (like 24365) ? as you see it could be
 
again more than one character long
 
again more than one character long
 
</td>
 
</td>
Line 212: Line 168:
 
</tbody>
 
</tbody>
 
</table>
 
</table>
<p style="margin-bottom: 0cm;">You can use any number of any state
+
<p style="margin-bottom: 0cm;">You can use any number of any state variables in your site and combine it together into apc state string. The only thing you have to keep in mind is that apc state string must be splittable into state variables. In Econnect's example we are using following regular expression to get state variables from 'apc state string'.
variables in your site and combine it together into apc state string.
+
 
The only thing you have to keep in mind is that apc state string must
+
{w}          {s}            {f}          {r}        {p}        {t}      {x}
be splittable into state variables. In Econnect's example we are
+
ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))
using following regular expression to get state variables from 'apc
 
state string'.
 
<pre> <br />
 
{w}          {s}            {f}          {r}        {p}        {t}      {x}
 
ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))</pre>
 
  
 
<strong>Main control file</strong>
 
<strong>Main control file</strong>
<p style="margin-bottom: 0cm;">Main control file is the only file you
+
Main control file is the only file you will need to edit in the process of site creation. The file contains script (probably in PHP) and its purpose is just parse 'apc state string' into state variables and possibly change the state of the variables based on the parameters it gets through url.
will need to edit in the process of site creation. The file contains
+
 
script (probably in PHP) and its purpose is just parse 'apc state
+
The script is called before any page of the site is displayed. There is easy, but functional example of such script. All comments are inside.
string' into state variables and possibly change the state of the
+
 
variables based on the parameters it gets through url.
+
If $apc is not defined, we probably access the main page (like http://ecn.cz).
 +
 
 +
if( !$apc )  $apc = 'zzvx--';      # initialize 'state string', if not set, yet
 +
 
 +
Split $apc state string into state variables (for now prefixed by 'o');
 +
 
 +
if( ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))
 +
  list($ostate,$ow,$os,$of,$or,$op,$ot,$ox) = $vars;
 +
  else                        # if the $apc is in wrong format, initialize it
 +
  list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');
 +
 
 +
Now we have to program the reactions on special url requests. Wherever we are in the site and we click on the link containing <code>w=z</code> (like <code>http://ecn.cz/index.stm?apc=zzvx1--&w=z</code>), we change the state to 'news' section
 +
 
 +
if( isset($w) ) {  # w stands for WEB
 +
  switch($w) {
 +
    case 'z':
 +
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('z','z','v','x','-','-',''); break;
 +
    case 'n':
 +
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('n','N','1','-','-','-',''); break;
 +
    case 'e':
 +
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('e','1','1','-','-','-','73161');
 +
    break;
 +
  }
 +
}
 +
 
 +
The same with state variable s, but we are switching within the same WEB (variable {w} remains unchanged)
 +
 
 +
if( isset($s) ) {  # s stands for SUBWEB
 +
  $os=$s;
 +
  $ox='';            # $ow stays the same – we change subweb, not web
 +
  $op='1';
 +
  if( $old_w != 'z' ) # the format in zpravodajstvi stays the same
 +
    $old_f='';
 +
}
 +
 
 +
Write rule for each possible url request.
 +
 
 +
if( isset($f) ) {$of=$f; $ox=''; $op='1';}    # f stands for FILTER
 +
if( isset($r) ) {$or=$r; $ox=''; $op='1';}    # r stands for REGION
 +
if( isset($p) ) {$op=$p; $ox='';}            # page
 +
if( isset($t) ) {$ot=$t; $ox='';}            # switch to special mode
 +
if( isset($x) ) {$ox=$x;}                    # item id to display
 +
if( isset($scrl) ) {                          # page scroller
 +
  $pagevar = "scr_".$scrl."_Go";
 +
  $op = $$pagevar;
 +
  $ox='';
 +
}
 +
 
 +
Finaly, save the final state of variables into $apc_state array. The key 'state' is used for storing new 'apc state string', other keys of the array are variables, which we can use in site module administration (in next chapter). There should be not only state variables, but any other variables which you want to use in site module, as well.
  
<p style="margin-bottom: 0cm;">The script is called before any page of
+
$apc_state = array ('state' => "$ow$os$of$or$op$ot$ox",
the site is displayed. There is easy, but functional example of such
+
                    'w' => $ow,
script. All comments are inside.
+
                    's' => $os,
 +
                    'f' => $of,
 +
                    'r' => $or,
 +
                    't' => $ot,
 +
                    'p' => $op,
 +
                    'x' => $ox,
 +
  # helper variables used in site module – you can define as many such
 +
  # variables as you want
 +
                    'archive' =>      (($op>10)? 'archive' : ''),
 +
                    );
  
<p style="margin-bottom: 0cm;">If $apc is not defined, we probably
 
access the main page (like <a href="http://ecn.cz/">http://ecn.cz</a>).
 
  
<pre>if( !$apc )  $apc = 'zzvx--';      # initialize 'state string', if not set, yet<br /><br />Split $apc state string into state variables (for now prefixed by 'o');<br /><br />if( ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))<br />  list($ostate,$ow,$os,$of,$or,$op,$ot,$ox) = $vars;<br /> else                        # if the $apc is in wrong format, initialize it<br />  list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');<br /><br />Now we have to program the reactions on special url requests. Wherever we are in the site and we click on the link containing w=z (like <a href="http://ecn.cz/index.stm?apc=zzvx1--&w=z">http://ecn.cz/index.stm?apc=zzvx1--&w=z</a>), we change the state to 'news' section<br /><br />if( isset($w) ) {  # w stands for WEB<br />  switch($w) {<br />  case 'z':<br />    list($ow,$os,$of,$or,$op,$ot,$ox)=array('z','z','v','x','-','-',''); break;<br />  case 'n':<br />    list($ow,$os,$of,$or,$op,$ot,$ox)=array('n','N','1','-','-','-',''); break;<br />  case 'e':<br />    list($ow,$os,$of,$or,$op,$ot,$ox)=array('e','1','1','-','-','-','73161');<br />    break;<br />  }<br />}<br /><br />The same with state variable s, but we are switching within the same WEB (variable {w} remains unchanged)<br /><br />if( isset($s) ) {  # s stands for SUBWEB<br />  $os=$s;<br />  $ox='';            # $ow stays the same � we change subweb, not web<br />  $op='1';<br />  if( $old_w != 'z' ) # the format in zpravodajstvi stays the same<br />    $old_f='';<br />}<br /><br />Write rule for each possible url request.<br /><br />if( isset($f) ) {$of=$f; $ox=''; $op='1';}    # f stands for FILTER<br />if( isset($r) ) {$or=$r; $ox=''; $op='1';}    # r stands for REGION<br />if( isset($p) ) {$op=$p; $ox='';}            # page<br />if( isset($t) ) {$ot=$t; $ox='';}            # switch to special mode<br />if( isset($x) ) {$ox=$x;}                    # item id to display<br />if( isset($scrl) ) {                          # page scroller<br />  $pagevar = "scr_".$scrl."_Go";<br />  $op = $$pagevar;<br />  $ox='';<br />}<br /><br />Finaly, save the final state of variables into $apc_state array. The key 'state' is used for storing new 'apc state string', other keys of the array are variables, which we can use in site module administration (in next chapter). There should be not only state variables, but any other variables which you want to use in site module, as well.<br /><br />$apc_state = array ('state' => "$ow$os$of$or$op$ot$ox",<br />                    'w' => $ow,<br />                    's' => $os,<br />                    'f' => $of,<br />                    'r' => $or,<br />                    't' => $ot,<br />                    'p' => $op,<br />                    'x' => $ox,<br />  # helper variables used in site module � you can define as many such<br />  # variables as you want<br />                    'archive' =>      (($op>10)? 'archive' : ''),<br />                    );<br /></pre>
+
You can find example of such file in /modules/site/sites/ directory of ActionApps installation
<p style="margin-bottom: 0cm;"><br />You can find example of such file
 
in /modules/site/sites/ directory of ActionApps installation
 
  
 
<strong>Site administration</strong>
 
<strong>Site administration</strong>
<p style="margin-bottom: 0cm;">The HTML code for the pages is managed
+
The HTML code for the pages is managed
 
from site administration page. The code is divided into pieces, which
 
from site administration page. The code is divided into pieces, which
is structured into tree structure called sitetree. The
+
is structured into tree structure ? called sitetree. The
 
sitetree you can see on the left side of the administration
 
sitetree you can see on the left side of the administration
 
interface. During the displaying of the page, AA starts with the
 
interface. During the displaying of the page, AA starts with the
Line 251: Line 255:
 
incorporated results of some slice view, as we see later.
 
incorporated results of some slice view, as we see later.
  
<p style="margin-bottom: 0cm;">We recognize two kind of HTML pieces
+
<p style="margin-bottom: 0cm;">We recognize two kind of HTML pieces ?
 
'spots' and 'choices'.
 
'spots' and 'choices'.
  
Line 349: Line 353:
 
</td>
 
</td>
 
<td width="312">
 
<td width="312">
<br />Comments no output is printed
+
<br />Comments ? no output is printed
  
 
</td>
 
</td>
Line 356: Line 360:
 
</table>
 
</table>
  
<p style="margin-bottom: 0cm;">The construct could be nested
+
<p style="margin-bottom: 0cm;">The construct could be nested ?
 
the level of nesting is unlimited.
 
the level of nesting is unlimited.
  

Revision as of 13:19, 26 August 2005

Using Site Module

How to use Site Module

Site Module

Current APC ActionApps are very good for creation of small or not so complex database driven sites. It was not so easy to create complex websites with many cooperating slices and views, so far. The site module is the answer for those, who wants to build complex websites using APC AA.

At the time I wrote the text, the only sites driven by site module is the Econnect site http://ecn.cz. ChangeNet site http://changenet.sk and example site on Sourceforge http://action.org/slices/. I describe the site module on Econnect's site. You will see, that the principles are similar to all site module based websites.

The site module is part of AA admin interface, just like other modules are. You can access it from 'Switch to' selectbox, if you have permission to. Site module allows you to describe structure of the site you modify there so called sitetree. Sites based on the module do not need any special files (like shtml, ...) - whole site could be managed using AA admin interface (there is no need for FTP access (with one exception 'main control script' file described later)). How to describe the structure we will see latter in this text.

Idea - State and sessions

The first estimation in creation of site module was the need to write it as fast as possible. The complex sites used to be sites with many visitors a day. For better performance is good to be able cache the generated pages. However, in pre-site module approach each user gets its own session id, which is unique for the user and help us to store the state, where the user user is within the site (which page on page-scroller she is on, ...). It is good, but it is extremely hard to cache such informations. That's why we develop the site module without sessions variables given to each user. We use state string instead. There we store the state, where the user is within the website.
State string is variable which we call apc (stands for Application Pointer Cache :-) the name of this variable is given it have special behavior inside APC AA (it is automatically added to all links generated by APC AA, for example).
The apc variable is added to all links in AA so you every time know, where the user was in step before.
For example: if you get the link http://ecn.cz/index.stm?apc=zzvx1--&..., you know, that user was in news-alerts-all_categories-all_regions-page1 page on the site. How it is coded into apc state string is another thing (and it is in most cases up to you) will be described in next caption.

apc state string

As you can see, the Econnect's apc state string consist of seven state variables each character in the string is one variable in our case, but it is not a rule (in fact the fifth state variable - p - page could be more than one character long). All the state variables are defined in main control file for the site - /module/site/sites/site_xxx.php3 (or its alternative called (for security reasons) through http:// call). In this file you define not only the number of state variables, the regular expression for extraction the variables from apc state string, but you specify there also the ways, how we have to change the state. For example, if the site_xxx.php3 file gets the following url parameter:

http://ecn.cz/index.stm?apc=zzvx1--&p=3

the state variable is changed to apc=zzvx3--, which means that you are on the same webpage, but on the page 3.

Now we describe the variables used on Econnect's site, but keep in mind, that the variables used in your site could be different (if you will).

Position in apc state string

Name of state variable

Possible states of the variable

description

1

w (web)

z,e,n

Main classification of pages Econnect's pages are divided into three webs:
z zpravodajstvi (news)
e econnect
n nno (NGO related news)

2

s (subweb)

z,m,k,t,a,s (for w=z)
1,2,3,4,5,6,7,8,9 (for w=e)
N,F,P,I,J,V (for w=n)

Each web (w) is divided into subwebs, so for example web z zpravodajstvi contains:
|z news
k comments
t press releases
...

3

f (filter)

Any letter

Primary use of this variable is to select category of shown items (environment, human rights, culture,...), but each page could utilize this variable for its own purpose (category of grant, job, ...)

4

r (region)

Any letter

The same as f primary use for region selection

5

p (page)

Any number

Stores the page number, where user is (switched by page-scroller). Could be more than one character long in our case.

6

t (type)

Any letter

Special type of output like 'text only', 'printer friendly', ...

7

x (item)

Any number

Id of item to show (like 24365) as you see it could be again more than one character long

You can use any number of any state variables in your site and combine it together into apc state string. The only thing you have to keep in mind is that apc state string must be splittable into state variables. In Econnect's example we are using following regular expression to get state variables from 'apc state string'.

 
{w} {s} {f} {r} {p} {t} {x} ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))

Main control file

Main control file is the only file you will need to edit in the process of site creation. The file contains script (probably in PHP) and its purpose is just parse 'apc state string' into state variables and possibly change the state of the variables based on the parameters it gets through url.

The script is called before any page of the site is displayed. There is easy, but functional example of such script. All comments are inside.

If $apc is not defined, we probably access the main page (like http://ecn.cz).

if( !$apc ) $apc = 'zzvx--'; # initialize 'state string', if not set, yet

Split $apc state string into state variables (for now prefixed by 'o');

if( ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))
list($ostate,$ow,$os,$of,$or,$op,$ot,$ox) = $vars;
else # if the $apc is in wrong format, initialize it
list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');

Now we have to program the reactions on special url requests. Wherever we are in the site and we click on the link containing w=z (like http://ecn.cz/index.stm?apc=zzvx1--&w=z), we change the state to 'news' section

if( isset($w) ) { # w stands for WEB
switch($w) {
case 'z':
list($ow,$os,$of,$or,$op,$ot,$ox)=array('z','z','v','x','-','-',''); break;
case 'n':
list($ow,$os,$of,$or,$op,$ot,$ox)=array('n','N','1','-','-','-',''); break;
case 'e':
list($ow,$os,$of,$or,$op,$ot,$ox)=array('e','1','1','-','-','-','73161');
break;
}
}

The same with state variable s, but we are switching within the same WEB (variable {w} remains unchanged)

if( isset($s) ) { # s stands for SUBWEB
$os=$s;
$ox=''; # $ow stays the same we change subweb, not web
$op='1';
if( $old_w != 'z' ) # the format in zpravodajstvi stays the same
$old_f='';
}

Write rule for each possible url request.

if( isset($f) ) {$of=$f; $ox=''; $op='1';} # f stands for FILTER
if( isset($r) ) {$or=$r; $ox=''; $op='1';} # r stands for REGION
if( isset($p) ) {$op=$p; $ox='';} # page
if( isset($t) ) {$ot=$t; $ox='';} # switch to special mode
if( isset($x) ) {$ox=$x;} # item id to display
if( isset($scrl) ) { # page scroller
$pagevar = "scr_".$scrl."_Go";
$op = $$pagevar;
$ox='';
}

Finaly, save the final state of variables into $apc_state array. The key 'state' is used for storing new 'apc state string', other keys of the array are variables, which we can use in site module administration (in next chapter). There should be not only state variables, but any other variables which you want to use in site module, as well.

$apc_state = array ('state' => "$ow$os$of$or$op$ot$ox",
'w' => $ow,
's' => $os,
'f' => $of,
'r' => $or,
't' => $ot,
'p' => $op,
'x' => $ox,
# helper variables used in site module you can define as many such
# variables as you want
'archive' => (($op>10)? 'archive' : ''),
);


You can find example of such file in /modules/site/sites/ directory of ActionApps installation

Site administration

The HTML code for the pages is managed from site administration page. The code is divided into pieces, which is structured into tree structure called sitetree. The sitetree you can see on the left side of the administration interface. During the displaying of the page, AA starts with the first HTML piece and then goes down and prints the right branch of the tree, based on the state of state variables. The piece of HTML code could contain not only HTML code, but there could be incorporated results of some slice view, as we see later.

We recognize two kind of HTML pieces 'spots' and 'choices'.

a) spot

spot is HTML code which is simply displayed. AA prints the contents of the spot and then the evaluation continue with the spot just below. On the other hand 'spot' (as well as choice) could be also the root of some branches of code. You can make spot as root of branch by assigning any (decision) variable to the spot. For example, if you assign variable 'w' to the 'start' spot, you create the root of branches (choices). The evaluation will continue in the branch (choice), where w satisfy the conditions.

b) choice

As you see, each choice belongs to a spot, where a 'decision variable' is defined. Each choice has defined a condition for the decision variable. AA prints only FIRST choice, which satisfy the conditions. After evaluation of the chioce (printing the output), AA continues with the spot on higher level of the sitetree.

You can use regular expressions in the conditions. You can also combine the condition for more than one 'decision' variable. The conditions are joined by the logical AND operator.

Incorporating database views into output.

You can use not only HTML cote in the spots, but you can incorporate here the outputs from any slice. The slice output is always controlled by view in site module (we do not use Fulltext or Index in site module). To include slice output use the following construct:

{view.php3?vid=353}

This includes in the output the result of view number 353. Although the {view.php3...} is just language construct (it have only a little to do with view.php3 file), we can use all the well known parameters we know from view.php3. So, the following example is the one, we surely use in our site for displaying the fulltext of the item x:

{view.php3?vid=217&cmd[217]=x-217-{x}}

As you see from the example, we can use another language construct {x}, which is substituted by the content of variable x (x is the state variable defined in 'main control file' in $apc_state array).

Language construct to be used with site module

Syntax

description

{<variable>}

Returns content of variable (like {w})

{view.php3?vid=<vid>&<view parameters>}

Returns content of view <vid>. View uses the <view parameters> just like the view.php3 script. (like {view.php3?vid=122&cmd[122]=c-1-{f}} )

{switch(var1,var2,..)val1,val2,..:<printed text1>:val1,val2,..:<printed text2>}

Returns <printed text1> or <printed text2> or ... based on conditions val1,val2 for variables var1, var2, ... The only first matching text is printed. You can use regular expressions in conditions. (like {switch(w)z:News:e:Econnect:.*:NGO} )

{# any text}

Comments no output is printed

The construct could be nested the level of nesting is unlimited.


FAQ: How to use Site Module

Site Module So far the best approach to biuild/manage a website of a medium to great complexity with ActionApps is to use the Site Module. It helps combining several views /slices into one page.

We are going to use Econnect's site as an example, to demonstarte basic principles.

The site module is part of AA admin interface, just like other modules are. You can access it from 'Switch to' selectbox, if you have permission to. Site module allows you to describe structure of the site ? you modify there so called sitetree. Sites based on the module do not need any special files (like shtml, ...) - whole site could be managed using AA admin interface (there is no need for FTP access (with one exception 'main control script' file described later)). How to describe the structure we will see latter in this text.

Idea - State and sessions The primary consideration during the Site Module planning was performance. The complex sites used to be sites with many visitors a day. For better performance is good to be able cache the generated pages. However, in "pre-site module" approach each user gets its own session id, which is unique for the user and help us to store the state, where the user user is within the site (which page on page-scroller she is on, ...). It is good, but it is extremely hard to cache such informations. That's why we develop the site module without sessions variables given to each user. We use state string instead. There we store the state, where the user is within the website. State string is variable which we call apc (stands for 'Application Pointer Cache' :-) the name of this variable is given ? it have special behavior inside APC AA (it is automatically added to all links generated by APC AA, for example).

The apc variable is added to all links in AA so you every time know, where the user was in step before. For example: if you get the link http://ecn.cz/index.stm?apc=zzvx1--&..., you know, that user was in "news-alerts-all_categories-all_regions-page1" page on the site. How it is coded into "apc? state string is another matter (and it is in most cases up to you) ? will be described in next caption.

apc state string As you can see, the Econnect's apc state string consist of seven state variables - each character in the string is one variable in our case, but it is not a rule (in fact the fifth state variable - p - page could be more than one character long). All the state variables are defined in main control file for the site - /module/site/sites/site_xxx.php3 (or its alternative called (for security reasons) through http:// call). In this file you define not only the number of state variables, the regular expression for extraction the variables from apc state string, but you specify there also the ways, how we have to change the state. For example, if the site_xxx.php3 file gets the following url parameter:

<a href="http://ecn.cz/index.stm?apc=zzvx1--&p=3">http://ecn.cz/index.stm?apc=zzvx1--&p=3</a>

the state variable is changed to apc=zzvx3--, which means that you are on the same webpage, but on the page 3.

Now we describe the variables used on Econnect's site, but keep in mind, that the variables used in your site could be different (if you wish).

<col width="56" /> <col width="79" /> <col width="181" /> <col width="292" /> <thead> </thead> <tbody>


Position in apc state string


Name of state variable


Possible states of the variable


description

1 </td>


w (web) </td>


z,e,n </td>


Main classification of pages ? Econnect's pages are divided into three webs:
z ? zpravodajstvi (news)
e ? econnect
n ? nno (NGO related news) </td> </tr>

<p align="right">2 </td>


s (subweb) </td>


z,m,k,t,a,s (for w=z)
1,2,3,4,5,6,7,8,9 (for w=e)
N,F,P,I,J,V (for w=n) </td>


Each web (w) is divided into subwebs, so for example web z ? zpravodajstvi contains:
|z ? news
k ? comments
t ? press releases
... </td> </tr>

<p align="right">3 </td>


f (filter) </td>


Any letter </td>


Primary use of this variable is to select category of shown items (environment, human rights, culture,...), but each page could utilize this variable for its own purpose (category of grant, job, ...) </td> </tr>

<p align="right">4 </td>


r (region) </td>


Any letter </td>


The same as f ? primary use for region selection </td> </tr>

<p align="right">5 </td>


p (page) </td>


Any number </td>


Stores the page number, where user is (switched by page-scroller). Could be more than one character long in our case.

</td> </tr>

<p align="right">6 </td>

t (type) </td>

Any letter </td>


Special type of output ? like 'text only', 'printer friendly', ... </td> </tr>

<p align="right">7 </td>

x (item) </td>

Any number </td>

Id of item to show (like 24365) ? as you see it could be again more than one character long </td> </tr> </tbody> </table> <p style="margin-bottom: 0cm;">You can use any number of any state variables in your site and combine it together into apc state string. The only thing you have to keep in mind is that apc state string must be splittable into state variables. In Econnect's example we are using following regular expression to get state variables from 'apc state string'.

{w}          {s}            {f}           {r}         {p}        {t}       {x}
ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))

Main control file Main control file is the only file you will need to edit in the process of site creation. The file contains script (probably in PHP) and its purpose is just parse 'apc state string' into state variables and possibly change the state of the variables based on the parameters it gets through url.

The script is called before any page of the site is displayed. There is easy, but functional example of such script. All comments are inside.

If $apc is not defined, we probably access the main page (like http://ecn.cz).

if( !$apc )  $apc = 'zzvx--';      # initialize 'state string', if not set, yet

Split $apc state string into state variables (for now prefixed by 'o');

if( ereg( "^([a-zA-Z0-9_])([a-zA-Z0-9_])([a-zA-Z0-9_-])([a-zA-Z_]+)([-]|[0-9]+)([a-zA-Z_-])([0-9]*)", $apc, $vars ))
  list($ostate,$ow,$os,$of,$or,$op,$ot,$ox) = $vars;
 else                        # if the $apc is in wrong format, initialize it
  list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');

Now we have to program the reactions on special url requests. Wherever we are in the site and we click on the link containing w=z (like http://ecn.cz/index.stm?apc=zzvx1--&w=z), we change the state to 'news' section

if( isset($w) ) {   # w stands for WEB
  switch($w) {
   case 'z':
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('z','z','v','x','-','-',); break;
   case 'n':
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('n','N','1','-','-','-',); break;
   case 'e':
    list($ow,$os,$of,$or,$op,$ot,$ox)=array('e','1','1','-','-','-','73161');
    break;
  }
}

The same with state variable s, but we are switching within the same WEB (variable {w} remains unchanged)

if( isset($s) ) {   # s stands for SUBWEB
  $os=$s;
  $ox=;             # $ow stays the same – we change subweb, not web
  $op='1';
  if( $old_w != 'z' ) # the format in zpravodajstvi stays the same
    $old_f=;
}

Write rule for each possible url request.

if( isset($f) ) {$of=$f; $ox=; $op='1';}    # f stands for FILTER
if( isset($r) ) {$or=$r; $ox=; $op='1';}    # r stands for REGION
if( isset($p) ) {$op=$p; $ox=;}             # page
if( isset($t) ) {$ot=$t; $ox=;}             # switch to special mode
if( isset($x) ) {$ox=$x;}                     # item id to display
if( isset($scrl) ) {                          # page scroller
  $pagevar = "scr_".$scrl."_Go";
  $op = $$pagevar;
  $ox=;
}

Finaly, save the final state of variables into $apc_state array. The key 'state' is used for storing new 'apc state string', other keys of the array are variables, which we can use in site module administration (in next chapter). There should be not only state variables, but any other variables which you want to use in site module, as well.

$apc_state = array ('state' => "$ow$os$of$or$op$ot$ox",
                    'w' => $ow,
                    's' => $os,
                    'f' => $of,
                    'r' => $or,
                    't' => $ot,
                    'p' => $op,
                    'x' => $ox,
 # helper variables used in site module – you can define as many such
 # variables as you want
                   'archive' =>      (($op>10)? 'archive' : ),
                   );


You can find example of such file in /modules/site/sites/ directory of ActionApps installation

Site administration The HTML code for the pages is managed from site administration page. The code is divided into pieces, which is structured into tree structure ? called sitetree. The sitetree you can see on the left side of the administration interface. During the displaying of the page, AA starts with the first HTML piece and then goes down and prints the right branch of the tree, based on the state of state variables. The piece of HTML code could contain not only HTML code, but there could be incorporated results of some slice view, as we see later.

<p style="margin-bottom: 0cm;">We recognize two kind of HTML pieces ? 'spots' and 'choices'.

a) spot <p style="margin-bottom: 0cm;">spot is HTML code which is simply displayed. AA prints the contents of the spot and then the evaluation continue with the spot just below. On the other hand 'spot' (as well as choice) could be also the root of some branches of code. You can make spot as root of branch by assigning any (decision) variable to the spot. For example, if you assign variable 'w' to the 'start' spot, you create the root of branches (choices). The evaluation will continue in the branch (choice), where w satisfy the conditions.

b) choice <p style="margin-bottom: 0cm;">As you see, each choice belongs to a spot, where a 'decision variable' is defined. Each choice has defined a condition for the decision variable. AA prints only FIRST choice, which satisfy the conditions. After evaluation of the chioce (printing the output), AA continues with the spot on higher level of the sitetree.

<p style="margin-bottom: 0cm;">You can use regular expressions in the conditions. You can also combine the condition for more than one 'decision' variable. The conditions are joined by the logical AND operator.

Incorporating database views into output. <p style="margin-bottom: 0cm;">You can use not only HTML cote in the spots, but you can incorporate here the outputs from any slice. The slice output is always controlled by view in site module (we do not use Fulltext or Index in site module). To include slice output use the following construct: <p style="margin-bottom: 0cm;">{view.php3?vid=353} <p style="margin-bottom: 0cm;">This includes in the output the result of view number 353. Although the {view.php3...} is just language construct (it have only a little to do with view.php3 file), we can use all the well known parameters we know from view.php3. So, the following example is the one, we surely use in our site for displaying the fulltext of the item x: <p style="margin-bottom: 0cm;"> {view.php3?vid=217&cmd[217]=x-217-{x}}

<p style="margin-bottom: 0cm;">As you see from the example, we can use another language construct {x}, which is substituted by the content of variable x (x is the state variable defined in 'main control file' in $apc_state array).

Language construct to be used with site module

<col width="312" /> <col width="312" /> <thead> </thead> <tbody> </tbody>


Syntax


description


{<variable>}


Returns content of variable (like {w})


{view.php3?vid=<vid>&<view parameters>}


Returns content of view <vid>. View uses the <view parameters> just like the view.php3 script. (like {view.php3?vid=122&cmd[122]=c-1-{f}} )


{switch(var1,var2,..)val1,val2,..:<printed text1>:val1,val2,..:<printed text2>}


Returns <printed text1> or <printed text2> or ... based on conditions val1,val2 for variables var1, var2, ... The only first matching text is printed. You can use regular expressions in conditions. (like {switch(w)z:News:e:Econnect:.*:NGO} )


{# any text}


Comments ? no output is printed

<p style="margin-bottom: 0cm;">The construct could be nested ? the level of nesting is unlimited.


</div>

Making your site searchable by Google like search engines

~ToDo: Write about howto help google index the site properly 

Search friendly URLs

=== Generating correct title and metadata ===