Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > definir_session

definir_session

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:

  1. $s = pipeline('definir_session',
  2. $GLOBALS['visiteur_session']
  3. ? serialize($GLOBALS['visiteur_session'])
  4. . '_' . @$_COOKIE['spip_session']
  5. : ''
  6. );

Download

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:

  1. <options>prefixPlugin_options.php</options>
  2. <pipeline>
  3. <nom>definir_session</nom>
  4. </pipeline>

Download

Example

The "FaceBook Login" plugin defines a cache name which is also dependent on the Facebook authentication if that has been validated:

  1. function fblogin_definir_session($flux){
  2. $flux .= (isset($_SESSION['fb_session']) ? serialize(isset($_SESSION['fb_session'])) : '');
  3. return $flux;
  4. }

Download

The "Forms & Tables" plugin also defines a specific cache when cookies linked to its forms are discovered:

  1. function forms_definir_session($session){
  2. foreach($_COOKIE as $cookie=>$value){
  3. if (strpos($cookie,'cookie_form_')!==FALSE)
  4. $session .= "-$cookie:$value";
  5. }
  6. return $session;
  7. }

Download

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:

  1. function balise_FORMS ($p) {
  2. $p->descr['session'] = true;
  3.  
  4. return calculer_balise_dynamique($p, 'FORMS', array('id_form', 'id_article', 'id_donnee','id_donnee_liee', 'class'));
  5. }

Download

  • Author :
  • Published :
  • Updated : 29/05/10
  • Translations : English, français