Oops.
[platal.git] / include / platal.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
d3f26be9 22$TIME_BEGIN = microtime(true);
0337d704 23
8b00e0e0 24define('PERMS_EXT', 'ext');
25define('PERMS_USER', 'user');
26define('PERMS_ADMIN', 'admin');
0337d704 27
28define('SKINNED', 0);
62a66dfc 29define('SIMPLE', 1);
30define('NO_SKIN', 2);
0337d704 31
94c63478 32define('NO_AUTH', 0);
33define('DO_AUTH', 1);
8fc4efa3 34define('NO_HTTPS', 2);
94c63478 35
08d7cc45 36function pl_autoload($cls)
42a50827 37{
e654517d 38 $cls = strtolower($cls);
39 $path = dirname(dirname(__FILE__));
1148fc03 40 if (!@include "$path/classes/$cls.php") {
bd5e1f3d 41 if (substr($cls, -3, 3) == 'req') {
e654517d 42 @include 'validations.inc.php';
43 return;
b1a86dbc
FB
44 } else if (substr($cls, 0, 6) == 'banana') {
45 require_once 'banana/banana.inc.php';
46 Banana::load(substr($cls, 6));
47 return;
e654517d 48 }
49 @include "$cls.inc.php";
50 }
42a50827 51}
08d7cc45 52pl_autoload('Env');
6995a9b9 53
54function pl_error_handler($errno, $errstr, $errfile, $errline)
55{
a18afbdc 56 static $errortype;
6995a9b9 57 if (!error_reporting())
58 return;
59
a18afbdc 60 if (!isset($errortype)) {
61 $errortype = array (
62 E_ERROR => "Error",
63 E_WARNING => "Warning",
64 E_PARSE => "Parsing Error",
65 E_NOTICE => "Notice",
66 E_CORE_ERROR => "Core Error",
67 E_CORE_WARNING => "Core Warning",
68 E_COMPILE_ERROR => "Compile Error",
69 E_COMPILE_WARNING => "Compile Warning",
70 E_USER_ERROR => "User Error",
71 E_USER_WARNING => "User Warning",
72 E_USER_NOTICE => "User Notice",
d70b6639
FB
73 E_STRICT => "Runtime Notice",
74 E_RECOVERABLE_ERROR => "Recoverable Error"
a18afbdc 75 );
76 }
6995a9b9 77
28023828 78 global $globals;
a7de4ef7 79 if (isset($globals) && !$globals->debug) {
a18afbdc 80 if ($errno == E_NOTICE || $errno == E_USER_NOTICE || $errno == E_STRICT) {
28023828 81 return;
82 }
83 }
84
d70b6639 85 $type = isset($errortype[$errno]) ? $errortype[$errno] : $errno;
493b6abe 86 $errstr = utf8_encode(htmlentities($errstr));
6995a9b9 87 $GLOBALS['pl_errors'][] =
88 "<div class='phperror'>".
d70b6639 89 "<strong>{$type}</strong> <em>$errstr</em><br />".
6995a9b9 90 "<tt>$errfile : $errline</tt>".
91 "</div>";
92}
93
0f384dd3 94function pl_clear_errors()
95{
96 unset($GLOBALS['pl_errors']);
97}
98
aa5f19ae 99function pl_dump_env()
100{
101 echo "<div class='phperror'><pre>";
732e5855 102 echo "\nSESSION: " . session_id(); var_dump($_SESSION);
c0799142
FB
103 echo "\nPOST: "; var_dump($_POST);
104 echo "\nGET: "; var_dump($_GET);
105 echo "\nCOOKIE: "; var_dump($_COOKIE);
aa5f19ae 106 echo "</pre></div>";
107}
108
6995a9b9 109function pl_print_errors()
110{
a18afbdc 111 if (!empty($GLOBALS['pl_errors'])) {
112 print join("\n", $GLOBALS['pl_errors']);
113 }
6995a9b9 114}
115
116set_error_handler('pl_error_handler', E_ALL | E_STRICT);
47fa97fe
FB
117register_shutdown_function('pl_print_errors');
118//register_shutdown_function('pl_dump_env');
0337d704 119
eaf30d86 120/** Check if the string is utf8
92432704 121 */
122function is_utf8($s)
123{
124 return @iconv('utf-8', 'utf-8', $s) == $s;
125}
126
eaf30d86
PH
127/** vérifie si une adresse email est bien formatée * ATTENTION, cette fonction ne doit pas être appelée sur une chaîne ayant subit un addslashes (car elle accepte le "'" qui it alors un "\'"
128 * @param $email l'adresse email a verifier
76a8d80b 129 * @return BOOL */
eaf30d86 130function isvalid_email($email)
76a8d80b 131{
eaf30d86
PH
132 // la rfc2822 authorise les caractères "a-z", "0-9", "!", "#", "$", "%", "&", "'", "*", "+", "-", "/", "=", "?", "^", `", "{", "|", "}", "~" aussi bien dans la partie locale que dans le domaine.
133 // Pour la partie locale, on réduit cet ensemble car il n'est pas utilisé.
134 // Pour le domaine, le système DNS limite à [a-z0-9.-], on y ajoute le "_" car il est parfois utilisé.
32111f70 135 return preg_match("/^[a-z0-9_.'+-]+@[a-z0-9._-]+\.[a-z]{2,6}$/i", $email);
76a8d80b 136}
137
8b00e0e0 138function pl_url($path, $query = null, $fragment = null)
139{
140 global $platal;
141
142 $base = $platal->ns . $path . ($query ? '?'.$query : '');
143 return $fragment ? $base.'#'.$fragment : $base;
144}
d90fe33c 145
d1ebc57a 146function pl_self($n = null) {
147 global $platal;
148 return $platal->pl_self($n);
149}
150
8b00e0e0 151function http_redirect($fullurl)
d90fe33c 152{
732e5855
FB
153 Platal::session()->close();
154 header('Location: '. $fullurl);
d90fe33c 155 exit;
156}
157
8b00e0e0 158function pl_redirect($path, $query = null, $fragment = null)
159{
160 global $globals;
161 http_redirect($globals->baseurl . '/' . pl_url($path, $query, $fragment));
162}
0337d704 163
493b6abe 164function pl_entities($text, $mode = ENT_COMPAT)
165{
166 return htmlentities($text, $mode, 'UTF-8');
167}
168
169function pl_entity_decode($text, $mode = ENT_COMPAT)
170{
171 return html_entity_decode($text, $mode, 'UTF-8');
172}
173
a7de4ef7 174// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 175?>