Diferencia entre revisiones de «Creando sitios complejos con ActionApps»

De ActionApps Documentacion
Saltar a: navegación, buscar
m (→‎Usando el Modulo de sitio)
(→‎Usando el Modulo de sitio)
Línea 57: Línea 57:
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
Main classification of pages
+
Clasificacion principal de las paginas
−
Econnect's pages are divided into three webs:  
+
Las paginas de Econect estas divididas en tres clases:  
−
z - zpravodajstvi (news)  
+
z - zpravodajstvi (noticias)  
 
e - econnect  
 
e - econnect  
−
n - nno (NGO related news)
+
n - nno (Noticias relacionadas con ONGs)
 
</td>
 
</td>
 
</tr>
 
</tr>
Línea 77: Línea 77:
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
Each web (w) is divided into subwebs, so for example web z - zpravodajstvi contains:
+
Cada web (w) esta dividida en subwebs, por ejemplo la web z (noticias) contiene:
−
z - news
+
z - noticias
−
k - comments
+
k - comentarios
−
t - press releases
+
t - boletines de prensa
 
...
 
...
 
</td>
 
</td>
Línea 89: Línea 89:
 
</td>
 
</td>
 
<td width="79" valign="top">
 
<td width="79" valign="top">
−
f (filter)
+
f (filtro)
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
−
Any letter
+
Cualquier letra
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
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, ...)
+
El uso primario de esta variable es para seleccionar la categoria de los items visibles (ambiente, derechos humanos, cultura, ...), pero cada pagina pidria usar esta variable para su propio proposito (tipo de apoyo, empleo, etc...)
 
</td>
 
</td>
 
</tr>
 
</tr>
Línea 106: Línea 106:
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
−
Any letter
+
Cualquier letra
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
The same as f - primary used for the selection of a region
+
Igual que f - se usa para filtrar por region  
 
</td>
 
</td>
 
</tr>
 
</tr>
Línea 117: Línea 117:
 
</td>
 
</td>
 
<td width="79" valign="top">
 
<td width="79" valign="top">
−
p (page)
+
p (pagina)
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
−
Any number
+
Cualquier numero
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
Stores the page number, where user is (switched by page-scroller). Could be more than one character long in our case.
+
Almacena el numero de pagina, donde este el usuario (acorde con el page-scroller). Puede ser mas de un caracter en nuestro caso.
 +
 
 
</td>
 
</td>
 
</tr>
 
</tr>
Línea 131: Línea 132:
 
</td>
 
</td>
 
<td width="79" valign="top">
 
<td width="79" valign="top">
−
t (type)
+
t (tipo)
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
−
Any letter
+
Cualquier letra
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
Special type of output ? like 'text only', 'printer friendly', ...
+
Tipo especial de salida, como 'solo texto', 'para impresion', ...
 
</td>
 
</td>
 
</tr>
 
</tr>
Línea 148: Línea 149:
 
</td>
 
</td>
 
<td width="181" valign="top">
 
<td width="181" valign="top">
−
Any number
+
Cualquier numero
 
</td>
 
</td>
 
<td width="292" valign="top">
 
<td width="292" valign="top">
−
Id of item to show (like 24365) - as you see it could beagain more than one character long
+
Identificacion del item a desplegar (como 12345) - como se puede ver, puede tener una logitud variable.
 
</td>
 
</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
 +
Ud. puede usar cualquier numero de variables de estado en su sitio y combinarlas en la cadena de estado llamada 'apc'. Lo unico que hay que tener en cuenta es que la cadena de estado 'apc' debe ser  dividible en variables de estado. En el ejemplo de Econnect usamos la siguiente expresion rehular para obtener las variables de estado a partir de la "cadena de estado apc".
 +
  
−
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}
 
  {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 ))
 
  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 ))
  
−
<strong>Main control file</strong>
+
<strong>Script principal de control</strong>
−
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.
+
El script principal de control es el unico archivo que Ud. necesitara editar en el proceso de creacon del sitio. El archivo contiene un script (probablemente en PHP) y su proposito es convertir la "cadena de estado APC" en variables de estado, y posiblemente cambiar el estado de las variables en base a los parametros que se obtienen en la 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.
+
El script se invoca antes que culquier pagina del sitio se despliegue. Aqui esta un ejemplo sensillo pero funcional del script. Los comentarios estan adentro.
  
−
If $apc is not defined, we probably access the main page (like http://ecn.cz).
+
Si la variable $apc no esta definida, probablemente estamos accediendo la pagina principal (ej. http://ecn.cz).
  
−
  if( !$apc )  $apc = 'zzvx--';      # initialize 'state string', if not set, yet
+
  if( !$apc )  $apc = 'zzvx--';      # inicializamos la 'cadena de estado' si aun no existe
 +
                                    # en su valor inicial
  
−
Split $apc state string into state variables (for now prefixed by 'o');
 
  
 +
Separamos la cadena de estado $apc en variables de estado (por ahora con prefijo '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 ))
 
  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;
 
   list($ostate,$ow,$os,$of,$or,$op,$ot,$ox) = $vars;
−
   else                        # if the $apc is in wrong format, initialize it
+
   else                        # si la cadena $apc tiene un formato erroneo,  
 +
                              # inicializamos las variables de estado
 
   list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');
 
   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
+
Ahora tenemos que programar las reacciones a solicitudes especiales en url.
 +
Por ejemplo, si estamos en el sitio y hacemos clic en una liga que contiene
 +
<code>w=z</code> (como por ejemplo <code>http://ecn.cz/index.stm?apc=zzvx1--&w=z</code>), cambiamos el estado a la seccion 'noticias'  
  
−
  if( isset($w) ) {  # w stands for WEB
+
  if( isset($w) ) {  # w corresponde a WEB
 
   switch($w) {
 
   switch($w) {
 
     case 'z':
 
     case 'z':
Línea 191: Línea 197:
 
  }
 
  }
  
−
The same with state variable s, but we are switching within the same WEB (variable {w} remains unchanged)
+
Lo mismo con la variable de estado s, pero el cambio es dentro de la misma WEB (la variable {w} permanece sin cambios)
  
−
  if( isset($s) ) {  # s stands for SUBWEB
+
  if( isset($s) ) {  # s corresponde a SUBWEB
 
   $os=$s;
 
   $os=$s;
−
   $ox='';            # $ow stays the same – we change subweb, not web
+
   $ox='';            # $ow queda igual – cambiamos subweb, no web
 
   $op='1';
 
   $op='1';
−
   if( $old_w != 'z' ) # the format in zpravodajstvi stays the same
+
   if( $old_w != 'z' ) # el formato de noticias queda igual
 
     $old_f='';
 
     $old_f='';
 
  }
 
  }
  
−
Write rule for each possible url request.
+
Regla de reescritura para cada solicitud posible en url.
 +
 
  
−
  if( isset($f) ) {$of=$f; $ox=''; $op='1';}    # f stands for FILTER
+
  if( isset($f) ) {$of=$f; $ox=''; $op='1';}    # f corresponde a FILTRO
−
  if( isset($r) ) {$or=$r; $ox=''; $op='1';}    # r stands for REGION
+
  if( isset($r) ) {$or=$r; $ox=''; $op='1';}    # r corresponde a REGION
−
  if( isset($p) ) {$op=$p; $ox='';}            # page
+
  if( isset($p) ) {$op=$p; $ox='';}            # pagina
 
  if( isset($t) ) {$ot=$t; $ox='';}            # switch to special mode
 
  if( isset($t) ) {$ot=$t; $ox='';}            # switch to special mode
 
  if( isset($x) ) {$ox=$x;}                    # item id to display
 
  if( isset($x) ) {$ox=$x;}                    # item id to display

Revisión del 04:26 15 dic 2005

Usando el Modulo de sitio

Origin: FAQ: id=1680 How to use Site Module

Modulo de sitio

Hasta este momento, el mejor enfoque para contruir o administrar un sitio web de complejidad mediana a grande con ActionApps es usando el Modulo de Sitio. Este modulo es de gran ayuda al combinar varias vistas y canales en una misma pagina.

Vamos a usar el sitio de Econnect como ejemplo, para demostrar los principios basicos.

El modulo de sitio es parte de la interface de administracion de AA, igual que otros modulos. Puede accederlo desde la caja de seleccion 'cambiar a', si ud. tiene permiso. El modulo de sitio le permite describir la estructur del sitio como una arborecencia. Los sitios basados en el modulo no necesitan archivos especiales (como shtml). El sitio completo puede ser manejado usando la interfase de administracion de AA, con excepcion del 'script principal de control', descrito despues. La manera de describir la estructura del sitio sera expuesta en este texto, mas adelante.

Idea - Estado y sesiones

La consideracion principal durante la planificacion del Modulo de sitio fue despempenho. Los sitios complejos solieron tener muchos visitantes al dia. Para un mejor desempenho es mejor tener las paginas en cache. Sin embargo, con el enfoque previo al modulo de sitio, cada usuario obtiene su propia identificacion de sesion, que es unica para cada usuario y nos ayuda a almacenar el status, donde el usuario esta dentro del sitio (por ejemplo en que lugar del page scroller esta). Esta bien pero es muy dificil cachear esa informacion. Debido a eso se desarrollo el modulo de sitio sin variables de sesion para cada usuario. Usamos en cambio una "cadena de estado". Alli almacenamos el status, en que lugar del sitio esta el usuario. A esta variable de estado la llamamos apc (por 'Cache de apuntador de la aplicacion' o 'Application Pointer Cache' :-). Tiene un comportamiento especial en AA y es agregada automaticamente a todas las ligas generadas por AA y de esa manera podemos saber donde estuvo el usuario en la transicion anterior.

Por ejemplo: si Ud. obtiene la liga http://ecn.cz/index.stm?apc=zzvx1--&..., este usuario estuvo en la pagina "news-alerts-all_categories-all_regions-page1" del sitio. Como esta eso codificado en la cadena alfanumerica "apc" es otro tema, y mas bien depende de Ud. y sera descrito mas adelante.

La cadena de estado apc

Como se puede ver (???), la cadena de estado de Econnect consiste en 7 variables de estado - cada caracter el la cadena es una variable en nuestro caso, pero no es una regla (de hecho la quinta variable de estado p, pagina, podria tener una logitud mayor a uno). Todas variables de estado estan definidas en el script principal de control del sitio - /module/site/sites/site_xxx.php3 (o alternativamente es invocado, por razones de seguridad, mediante http://). En este script se define no solo en numero de variables de estado y la expresion regular que permite extraer los valores de la cadena de estado apc, sino tambien la manera en que cambiamos esa cadena de estado. Por ejemplo, si el codigo de <site>site_xxx.php3</site> obtiene el siguiente parametro en el url:

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

la variable de estado se cambia a apc=zzvx3--, lo que significa que esta en la misma pagina web, pero en la pagina numero 3.

Describamos a ontinuacion las variables usadas en el sitio de Econnect, pero tengamos en mente que las variables usadas en su sitio pueden ser diferentes, si desea.

Position in apc state string

Name of state variable

Possible states of the variable

Description

1

w (web)

z,e,n

Clasificacion principal de las paginas Las paginas de Econect estas divididas en tres clases: z - zpravodajstvi (noticias) e - econnect n - nno (Noticias relacionadas con ONGs)

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)

Cada web (w) esta dividida en subwebs, por ejemplo la web z (noticias) contiene: z - noticias k - comentarios t - boletines de prensa ...

3

f (filtro)

Cualquier letra

El uso primario de esta variable es para seleccionar la categoria de los items visibles (ambiente, derechos humanos, cultura, ...), pero cada pagina pidria usar esta variable para su propio proposito (tipo de apoyo, empleo, etc...)

4

r (region)

Cualquier letra

Igual que f - se usa para filtrar por region

5

p (pagina)

Cualquier numero

Almacena el numero de pagina, donde este el usuario (acorde con el page-scroller). Puede ser mas de un caracter en nuestro caso.

6

t (tipo)

Cualquier letra

Tipo especial de salida, como 'solo texto', 'para impresion', ...

7

x (item)

Cualquier numero

Identificacion del item a desplegar (como 12345) - como se puede ver, puede tener una logitud variable.

Ud. puede usar cualquier numero de variables de estado en su sitio y combinarlas en la cadena de estado llamada 'apc'. Lo unico que hay que tener en cuenta es que la cadena de estado 'apc' debe ser dividible en variables de estado. En el ejemplo de Econnect usamos la siguiente expresion rehular para obtener las variables de estado a partir de la "cadena de estado apc".


{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 ))

Script principal de control El script principal de control es el unico archivo que Ud. necesitara editar en el proceso de creacon del sitio. El archivo contiene un script (probablemente en PHP) y su proposito es convertir la "cadena de estado APC" en variables de estado, y posiblemente cambiar el estado de las variables en base a los parametros que se obtienen en la URL.

El script se invoca antes que culquier pagina del sitio se despliegue. Aqui esta un ejemplo sensillo pero funcional del script. Los comentarios estan adentro.

Si la variable $apc no esta definida, probablemente estamos accediendo la pagina principal (ej. http://ecn.cz).

if( !$apc )  $apc = 'zzvx--';      # inicializamos la 'cadena de estado' si aun no existe
                                   # en su valor inicial


Separamos la cadena de estado $apc en variables de estado (por ahora con prefijo '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                        #  si la cadena $apc tiene un formato erroneo, 
                             # inicializamos las variables de estado
  list($ow,$os,$of,$or,$op,$ot) = array( 'z', 'z', 'v', 'x', '-', '-');

Ahora tenemos que programar las reacciones a solicitudes especiales en url. Por ejemplo, si estamos en el sitio y hacemos clic en una liga que contiene w=z (como por ejemplo http://ecn.cz/index.stm?apc=zzvx1--&w=z), cambiamos el estado a la seccion 'noticias'

if( isset($w) ) {   # w corresponde a 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;
  }
}

Lo mismo con la variable de estado s, pero el cambio es dentro de la misma WEB (la variable {w} permanece sin cambios)

if( isset($s) ) {   # s corresponde a SUBWEB
  $os=$s;
  $ox=;             # $ow queda igual – cambiamos subweb, no web
  $op='1';
  if( $old_w != 'z' ) # el formato de noticias queda igual
    $old_f=;
}

Regla de reescritura para cada solicitud posible en url.


if( isset($f) ) {$of=$f; $ox=; $op='1';}    # f corresponde a FILTRO
if( isset($r) ) {$or=$r; $ox=; $op='1';}    # r corresponde a REGION
if( isset($p) ) {$op=$p; $ox=;}             # pagina
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.