Source for file func.php
Documentation is available at func.php
* Fichier utilitaire proposant des fonctions souvent utilisées dans Lodel
* LODEL - Logiciel d'Edition ELectronique.
* Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
* Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @author Sophie Malafosse
* @author Pierre-Alain Mignot
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
# echo "name de fichier : $filename";
if (! (unlink($filename)) ) die ("Ne peut pas supprimer $filename. probleme de right contacter Luc ou Ghislain");
@chmod ($filename,0666 & octdec($GLOBALS['filemask']));
foreach($context as $key=> $val) {
$context[$key]= str_replace(array("\n","Â\240"),array(" "," "),$val);
* Extrait toutes les variables passées par la méthode post puis les stocke dans
foreach ($arr as $key=> $val) {
if (!isset ($GLOBALS['context'][$key])) // protege
$GLOBALS['context'][$key] = $val;
array_walk($GLOBALS['context'],"clean_request_variable");
require_once 'class.inputfilter.php';
//ici on regle un bug : lors qu'on insere un espace insécable, l'appel à la fonction PHP 'chr' plante sur le   dans la fonction $filter->decode
$var = $filter->process(trim($var));
// le process nettoie un peu trop : remplace les br fermés par des br ouverts : document plus valide..
$var = str_replace(array("\n", " "), array("", "Â\240"), $var);
/*if (!get_magic_quotes_gpc()) {
if ($where) $where= "WHERE ". $where;
#require_once ($GLOBALS[home]."connect.php");
$rank= $db->getone("SELECT MAX(rank) FROM #_TP_$table $where");
function chrank($table,$id,$critere,$dir,$inverse= "",$jointables= "")
$dir= $dir== "up" ? - 1 : 1; if ($inverse) $dir=- $dir;
$desc= $dir> 0 ? "" : "DESC";
$result= $db->execute(lq("SELECT $table.id,$table.rank FROM $table $jointables WHERE $critere ORDER BY $table.rank $desc")) or dberror();
$rank= $dir> 0 ? 1 : mysql_num_rows($result);
while ($row= $result->fetchrow($result)) {
# intervertit avec le suivant s il existe
if (!($row2= $result->fetchrow($result))) break;
$db->execute(lq("UPDATE $table SET rank='$rank' WHERE id='$row2[id]'")) or dberror();
if ($row['rank']!= $rank) {
$db->execute(lq("UPDATE $table SET rank='$rank' WHERE id='$row[id]'")) or dberror();
* function returning the closing tag corresponding to the opening tag in the sequence
* this function could be smarter.
for($i= $n- 1; $i>= 0; $i-- ) $ret.= "</". $results[1][$i]. ">";
* Fonction permettant de vérifier l'existence d'un fichier correctement !
* @param string $file fichier à tester
// plus important : on supprime le cache généré par les fonctions de stat de fichier !
return file_exists($file); // on retourne le test du fichier
* Retourne la dernière date de modif de $filename
* @param string $filename fichier à tester
require_once 'cachefunc.php';
foreach ($arr as $k=> $v) {
if (!isset ($metaarr)) { // cree le hash des meta
return $metaarr ? serialize($metaarr) : $meta;
return strtr($data,array("&"=> "&","<" => "<", ">" => ">"));
### use the transaction now.
// Déverrouille toutes les tables verrouillées
$db->execute(lq("UNLOCK TABLES")) or dberror();
// Verrouille toutes les tables MySQL en écriture
$db->execute(lq("LOCK TABLES #_MTP_". join (" WRITE ,". "#_MTP_", $list). " WRITE")) or dberror();
foreach ($arr as $k=> $v) {
foreach ($arr2 as $k=> $v) {
if (!isset ($options_cache)) {
$optionsfile= SITEROOT. "CACHE/options_cache.php";
require_once('optionfunc.php');
if ($options_cache[$n]) $ret[$n]= stripslashes($options_cache[$n]);
if ($options_cache[$name]) // cached ?
function getlodeltext($name,$group,&$id,&$contents,&$status,$lang=- 1)
if ($name[0]!= '[' && $name[1]!= '@') return array(0,$name);
$group= substr($name,1,$dotpos);
$name= substr($name,$dotpos+ 1,- 1);
die("ERROR: unknow group for getlodeltext");
if ($lang==- 1) $lang= $GLOBALS['lang'] ? $GLOBALS['lang'] : $GLOBALS['lodeluser']['lang'];
if (!$lang) $lang = $GLOBALS['installlang']; // if no lang is specified choose the default installation language
require_once("connect.php");
$critere= $GLOBALS['lodeluser']['visitor'] ? "" : "AND status>0";
$arr= $db->getRow("SELECT id,contents,status FROM ". lq($prefix). "texts WHERE name='". $name. "' AND textgroup='". $group. "' AND (lang='$lang' OR lang='') $critere ORDER BY lang DESC");
if (!$GLOBALS['lodeluser']['admin'] || $logic) break;
require_once("logic.php");
$logic->createTexts($name,$group);
$contents= $arr['contents'];
if (!$contents && $GLOBALS['lodeluser']['visitor']) $contents= "@". $name;
if ($lang==- 1) $lang= $GLOBALS['lang'] ? $GLOBALS['lang'] : $GLOBALS['lodeluser']['lang'];
if ($GLOBALS['langcache'][$lang][$group. ".". $name]) {
return $GLOBALS['langcache'][$lang][$group. ".". $name];
#echo "name=$name,group=$group,id=$id,contents=$contents,status=$status,lang=$lang<br />";
if ($GLOBALS['idagauche']) {
/*$class = $GLOBALS['db']->getOne(lq("SELECT class FROM #_TP_objects WHERE id='$id'"));
if ($GLOBALS['db']->errorno()) {
return $base. $id. '.'. $GLOBALS['extensionscripts'];
//fabrique des urls type index.php?/rubrique/mon-titre
$path = getPath($id,'querystring');
return $base. '.'. $GLOBALS['extensionscripts']. '?id='. $id;
$url .= (false === strpos($url, '?')) ? '?file=1' : '&file=1';
$fp= fopen($file,"r") or die("Impossible to read the file $file");
* retourne le chemin complet vers une entitée *
* @param integer $id identifiant numérique de l'entitée *
* @param string $urltype le type d'url utilisée(path,querystring)
* @return string le chemin
* @since fonction ajoutée en 0.8
function getPath($id, $urltype,$base= 'index')
$urltype = 'querystring'; //la version actuelle de lodel ne gère que le type path
if($urltype!= 'path' && $urltype!= 'querystring') {
$result = $GLOBALS['db']->execute(lq("SELECT identifier FROM #_TP_entities INNER JOIN #_TP_relations ON id1=id WHERE id2='$id' ORDER BY degree DESC")) or dberror();
$path.= '/'. $result->fields['identifier'];
$row = $GLOBALS['db']->getRow(lq("SELECT identifier FROM #_TP_entities WHERE id='$id'"));
if ($GLOBALS['db']->errorno()) {
$path.= "/$id-". $row['identifier'];
return $base. '.'. $GLOBALS['extensionscripts']. $path;
return "$base.". $GLOBALS['extensionscripts']. "?$path";
* sent the header and the file for downloading
* @param string name of the real file.
* @param string name to send to the browser.
function download($filename,$originalname= "",$contents= "")
'doc'=> 'application/msword',
'pdf'=> 'application/pdf',
'xls'=> 'application/vnd.ms-excel'
if (!$originalname) $originalname= $filename;
|