[ Index ]
 

Code source de SPIP 1.8.3

Accédez au Source d'autres logiciels libres | Soutenez Angelica Josefina !

title

Body

[fermer]

/ecrire/ -> inc_extra.php3 (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2005                                                *
   7   *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
   8   *                                                                         *
   9   *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
  10   *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
  11  \***************************************************************************/
  12  
  13  
  14  
  15  ////////////////////////////////////////////////////////////////////////////////////
  16  // Pour utiliser les champs "extra", il faut installer dans le fichier
  17  // ecrire/mes_options.php3 un tableau definissant les champs pour chaque
  18  // type d'objet que l'on veut Žtendre (article, rubrique, breve, auteur,
  19  // site ou mot). Pour acceder aux valeurs des champs extra dans les
  20  // squelettes du site public, utiliser la notation :
  21  //                     [(#EXTRA|extra{nom_du_champ})]
  22  // Exemples :
  23  
  24  /*
  25  
  26  //
  27  // Definition de tous les extras possibles
  28  //
  29  
  30  $GLOBALS['champs_extra'] = Array (
  31      'auteurs' => Array (
  32              "alim" => "radio|brut|Pr&eacute;f&eacute;rences alimentaires|Veggie,Viande",
  33              "habitation" => "liste|brut|Lieu|Kuala Lumpur,Cape Town,Uppsala",
  34              "ml" => "case|propre|Je souhaite m'abonner &agrave; la mailinglist",
  35              "age" => "ligne|propre|&Acirc;ge du capitaine",
  36              "biblio" => "bloc|propre|Bibliographie"
  37          ),
  38  
  39      'articles' => Array (
  40              "isbn" => "ligne|typo|ISBN",
  41               "options" => "multiple|brut|Options de cet article|1,2,3,plus"
  42  
  43               
  44          )
  45      );
  46  
  47  // Note : pour les listes et les radios on peut preciser les valeurs des labels 
  48  //  Exemples
  49  //  "habitation" => "liste|brut|Lieu|San Diego,Suresnes|diego,suresnes",
  50  
  51  
  52  */
  53  
  54  
  55  /*
  56  
  57  // On peut optionnellement vouloir restreindre la portee des extras :
  58  // - pour les articles/rubriques/breves en fonction du secteur ;
  59  // - pour les auteurs en fonction du statut
  60  // - pour les mots-cles en fonction du groupe de mots
  61  // Exemples :
  62  
  63  $GLOBALS['champs_extra_proposes'] = Array (
  64      'auteurs' => Array (
  65          // tous : par defaut
  66          'tous' =>  'age|alim|ml',
  67          // les admins (statut='0minirezo') ont plus de champs que les auteurs 
  68          '0minirezo' => 'age|alim|ml|biblio|habitation'
  69          ),
  70  
  71      'articles' => Array (
  72          // tous : par defaut aucun champs extra sur les articles
  73          'tous' => '',
  74          // seul le champs extra "isbn" est proposé dans le secteur 1)
  75          '1' => 'isbn',
  76          // Dans le secteur 2 le champs "options" est proposé)
  77          '2' => 'options'
  78          )
  79      );
  80  
  81  
  82  */
  83  
  84  ////////////////////////////////////////////////////////////////////////////////////
  85  
  86  //
  87  // Ce fichier ne sera execute qu'une fois
  88  if (defined("_ECRIRE_INC_EXTRA")) return;
  89  define("_ECRIRE_INC_EXTRA", "1");
  90  
  91  // a partir de la liste des champs, generer la liste des input
  92  function extra_saisie($extra, $type, $ensemble='') {
  93      $extra = unserialize($extra);
  94  
  95      // quels sont les extras de ce type d'objet
  96      if (!$champs = $GLOBALS['champs_extra'][$type])
  97          $champs = Array();
  98  
  99      // prendre en compte, eventuellement, les champs presents dans la base
 100      // mais oublies dans mes_options.
 101      if (is_array($extra))
 102          while (list($key,) = each($extra))
 103              if (!$champs[$key])
 104                  $champs[$key] = "masque||($key?)";
 105  
 106      // quels sont les extras proposes...
 107      // ... si l'ensemble est connu
 108      if ($ensemble && isset($GLOBALS['champs_extra_proposes'][$type][$ensemble]))
 109          $champs_proposes = explode('|', $GLOBALS['champs_extra_proposes'][$type][$ensemble]);
 110      // ... sinon, les champs proposes par defaut
 111      else if (isset($GLOBALS['champs_extra_proposes'][$type]['tous'])) {
 112          $champs_proposes = explode('|', $GLOBALS['champs_extra_proposes'][$type]['tous']);
 113      }
 114  
 115      // sinon tous les champs extra du type
 116      else {
 117          $champs_proposes =  Array();
 118          reset($champs);
 119          while (list($ch, ) = each($champs)) $champs_proposes[] = $ch;
 120      }
 121  
 122      // bug explode
 123      if($champs_proposes == explode('|', '')) $champs_proposes = Array();
 124  
 125      // maintenant, on affiche les formulaires pour les champs renseignes dans $extra
 126      // et pour les champs proposes
 127      reset($champs_proposes);
 128      while (list(, $champ) = each($champs_proposes)) {
 129          $desc = $champs[$champ];
 130          list($form, $filtre, $prettyname, $choix, $valeurs) = explode("|", $desc);
 131  
 132          if (!$prettyname) $prettyname = ucfirst($champ);
 133          $affiche .= "<b>$prettyname&nbsp;:</b><br />";
 134  
 135          switch($form) {
 136  
 137              case "case":
 138              case "checkbox":
 139                  $affiche = ereg_replace("<br />$", "&nbsp;", $affiche);
 140                  $affiche .= "<INPUT TYPE='checkbox' NAME='suppl_$champ'";
 141                  if ($extra[$champ] == 'true')
 142                      $affiche .= " CHECKED ";
 143                  break;
 144  
 145              case "list":
 146              case "liste":
 147              case "select":
 148                  $choix = explode(",",$choix);
 149                  if (!is_array($choix)) {
 150                      $affiche .= "Pas de choix d&eacute;finis.\n";
 151                      break;
 152                  }
 153  
 154                  // prendre en compte les valeurs des champs
 155                  // si elles sont renseignees
 156                  $valeurs = explode(",",$valeurs);
 157                  if($valeurs == explode(",",""))
 158                      $valeurs = $choix ;
 159  
 160                  $affiche .= "<SELECT NAME='suppl_$champ' ";
 161                  $affiche .= "CLASS='forml'>\n";
 162                  $i = 0 ;
 163                  while (list(, $choix_) = each($choix)) {
 164                      $val = $valeurs[$i] ;
 165                      $affiche .= "<OPTION VALUE=\"$val\"";
 166                      if ($val == entites_html($extra[$champ]))
 167                          $affiche .= " SELECTED";
 168                      $affiche .= ">$choix_</OPTION>\n";
 169                      $i++;
 170                  }
 171                  $affiche .= "</SELECT>";
 172                  break;
 173  
 174              case "radio":
 175                  $choix = explode(",",$choix);
 176                  if (!is_array($choix)) {
 177                      $affiche .= "Pas de choix d&eacute;finis.\n";
 178                      break;
 179                  }
 180                  $valeurs = explode(",",$valeurs);
 181                  if($valeurs == explode(",",""))
 182                      $valeurs = $choix ;
 183  
 184                  $i=0;
 185                  while (list(, $choix_) = each($choix)) {
 186                      $affiche .= "<INPUT TYPE='radio' NAME='suppl_$champ' ";
 187                      $val = $valeurs[$i] ;
 188                      if (entites_html($extra["$champ"])== $val)
 189                          $affiche .= " CHECKED";
 190  
 191                      // premiere valeur par defaut
 192                      if (!$extra["$champ"] AND $i == 0)
 193                          $affiche .= " CHECKED";
 194  
 195                      $affiche .= " VALUE='$val'>$choix_</INPUT>\n";
 196                      $i++;
 197                  }
 198                  break;
 199  
 200              // A refaire car on a pas besoin de renvoyer comme pour checkbox
 201              // les cases non cochees
 202              case "multiple":
 203                  $choix = explode(",",$choix);
 204                  if (!is_array($choix)) {
 205                      $affiche .= "Pas de choix d&eacute;finis.\n";
 206                      break; }
 207                  for ($i=0; $i < count($choix); $i++) {
 208                      $affiche .= "<INPUT TYPE='checkbox' NAME='suppl_$champ$i'";
 209                      if (entites_html($extra["$champ"][$i])=="on")
 210                          $affiche .= " CHECKED";
 211                      $affiche .= ">\n";
 212                      $affiche .= $choix[$i];
 213                      $affiche .= "</INPUT>\n";
 214                  }
 215                  break;
 216  
 217              case "bloc":
 218              case "block":
 219                  $affiche .= "<TEXTAREA NAME='suppl_$champ' CLASS='forml' ROWS='5' COLS='40'>".entites_html($extra[$champ])."</TEXTAREA>\n";
 220                  break;
 221  
 222              case "masque":
 223                  $affiche .= "<font color='#555555'>".interdire_scripts($extra[$champ])."</font>\n";
 224                  break;
 225  
 226              case "ligne":
 227              case "line":
 228              default:
 229                  $affiche .= "<INPUT TYPE='text' NAME='suppl_$champ' CLASS='forml'\n";
 230                  $affiche .= " VALUE=\"".entites_html($extra[$champ])."\" SIZE='40'>\n";
 231                  break;
 232          }
 233  
 234          $affiche .= "<p>\n";
 235      }
 236  
 237      if ($affiche) {
 238          debut_cadre_enfonce();
 239          echo $affiche;
 240          fin_cadre_enfonce();
 241      }
 242  }
 243  
 244  // recupere les valeurs postees pour reconstituer l'extra
 245  function extra_recup_saisie($type) {
 246      $champs = $GLOBALS['champs_extra'][$type];
 247      if (is_array($champs)) {
 248          $extra = Array();
 249          while(list($champ,)=each($champs)) {
 250              list($style, $filtre, , $choix,) = explode("|", $GLOBALS['champs_extra'][$type][$champ]);
 251              list(, $filtre) = explode(",", $filtre);
 252              switch ($style) {
 253              case "multiple":
 254                  $choix =  explode(",", $choix);
 255                  $extra["$champ"] = array();
 256                  for ($i=0; $i < count($choix); $i++) {
 257                      if ($filtre && function_exists($filtre))
 258                           $extra["$champ"][$i] =
 259                               $filtre($GLOBALS["suppl_$champ$i"]);
 260                      else
 261                          $extra["$champ"][$i] = $GLOBALS["suppl_$champ$i"];
 262                  }
 263                  break;
 264  
 265              case 'case':
 266              case 'checkbox':
 267                  if ($GLOBALS["suppl_$champ"] == 'on')
 268                      $GLOBALS["suppl_$champ"] = 'true';
 269                  else
 270                      $GLOBALS["suppl_$champ"] = 'false';
 271  
 272              default:
 273                  if ($filtre && function_exists($filtre))
 274                  $extra["$champ"]=$filtre($GLOBALS["suppl_$champ"]);
 275                  else $extra["$champ"]=$GLOBALS["suppl_$champ"];
 276                  break;
 277              }
 278          }
 279          return serialize($extra);
 280      } else
 281          return '';
 282  }
 283  
 284  // Retourne la liste des filtres a appliquer pour un champ extra particulier
 285  function extra_filtres($type, $nom_champ) {
 286      $champ = $GLOBALS['champs_extra'][$type][$nom_champ];
 287      if (!$champ) return array();
 288      list(, $filtre, ) = explode("|", $champ);
 289      list($filtre, ) = explode(",", $filtre);
 290      if ($filtre && $filtre != 'brut' && function_exists($filtre))
 291          return array($filtre);
 292      return array();
 293  }
 294  
 295  // Retourne la liste des filtres a appliquer a la recuperation
 296  // d'un champ extra particulier
 297  function extra_filtres_recup($type, $nom_champ) {
 298      $champ = $GLOBALS['champs_extra'][$type][$nom_champ];
 299      if (!$champ) return array();
 300      list(, $filtre, ) = explode("|", $champ);
 301      list(,$filtre) = explode(",", $filtre);
 302      if ($filtre && $filtre != 'brut' && function_exists($filtre))
 303          return array($filtre);
 304      return array();
 305  }
 306  
 307  function extra_champ_valide($type, $nom_champ) {
 308      return isset($GLOBALS['champs_extra'][$type][$nom_champ]);
 309  }
 310  
 311  // a partir de la liste des champs, generer l'affichage
 312  function extra_affichage($extra, $type) {
 313      $extra = unserialize ($extra);
 314      if (!is_array($extra)) return;
 315      $champs = $GLOBALS['champs_extra'][$type];
 316  
 317      while (list($nom,$contenu) = each($extra)) {
 318          list ($style, $filtre, $prettyname, $choix, $valeurs) =
 319              explode("|", $champs[$nom]);
 320          list($filtre, ) = explode(",", $filtre);
 321          switch ($style) {
 322              case "checkbox":
 323              case "case":
 324                  if ($contenu=="true") $contenu = _T('item_oui');
 325                  elseif ($contenu=="false") $contenu = _T('item_non');
 326                  break;
 327  
 328              case "multiple":
 329                  $contenu_ = "";
 330                  $choix = explode (",", $choix);
 331                  if (is_array($contenu) AND is_array($choix)
 332                  AND count($choix)==count($contenu))
 333                      for ($i=0; $i < count($contenu); $i++)
 334                          if ($contenu[$i] == "on")
 335                              $contenu_ .= "$choix[$i], ";
 336                          else if ($contenu[$i] <> '')
 337                              $contenu_ = "Choix incoh&eacute;rents, "
 338                              ."v&eacute;rifiez la configuration... ";
 339                  $contenu = ereg_replace(", $", "", $contenu_);
 340                  break;
 341          }
 342          if ($filtre != 'brut' AND function_exists($filtre))
 343              $contenu = $filtre($contenu);
 344          if (!$prettyname)
 345              $prettyname = ucfirst($nom);
 346          if ($contenu)
 347              $affiche .= "<div><b>$prettyname&nbsp;:</b> "
 348              .interdire_scripts($contenu)."<br /></div>\n";
 349      }
 350  
 351      if ($affiche) {
 352          debut_cadre_enfonce();
 353          echo $affiche;
 354          fin_cadre_enfonce();
 355      }
 356  }
 357  
 358  ?>


Généré le : Thu Feb 22 22:27:47 2007 par Balluche grâce à PHPXref 0.7