Whenever a template requests to use
#AUTORISER
,
#SESSION
or any other tag which requires the creation of a different cache for each session, a special identifier is calculated with the session information known about the visitor by the
spip_session
function. This identifier is used to name the cache files. When no information is known about the visitor, the identifier returned is null.
The
definir_session
pipeline is used to complete the information used to create this identifier. It is also possible to compose unique caches relying on other parameters rather than data relating to the visitor.
The pipeline receives and returns a character string. It is called as in the file
ecrire/inc/utils.php:
$s = pipeline('definir_session',
$GLOBALS['visiteur_session']
? serialize($GLOBALS['visiteur_session'])
. '_' . @$_COOKIE['spip_session']
: ''
);
{{Remarks:}} the session data can be required very early on in SPIP’s operations, so it is best to declare the the pipeline function for a plugin directly in the options file. The declaration in the
plugin.xml
file does not need to define the XML tag
<inclure>
in such circumstances:
<options>prefixPlugin_options.php</options>
<pipeline>
<nom>definir_session</nom>
</pipeline>
Example
The "FaceBook Login" plugin defines a cache name which is also dependent on the Facebook authentication if that has been validated:
function fblogin_definir_session($flux){
$flux .= (isset($_SESSION['fb_session']) ? serialize(isset($_SESSION['fb_session'])) : '');
return $flux;
}
The "Forms & Tables" plugin also defines a specific cache when cookies linked to its forms are discovered:
function forms_definir_session($session){
foreach($_COOKIE as $cookie=>$value){
if (strpos($cookie,'cookie_form_')!==FALSE)
$session .= "-$cookie:$value";
}
return $session;
}
We should note that the
#FORMS
dynamic tag for this plugin requests the creation of a cache per session by assigning
true
to the
session
option of the tag:
function balise_FORMS ($p) {
$p->descr['session'] = true;
return calculer_balise_dynamique($p, 'FORMS', array('id_form', 'id_article', 'id_donnee','id_donnee_liee', 'class'));
}