1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | // cookie_path returns the path to use for the PhpWebGallery cookie. |
---|
25 | // If PhpWebGallery is installed on : |
---|
26 | // http://domain.org/meeting/gallery/category.php |
---|
27 | // cookie_path will return : "/meeting/gallery" |
---|
28 | function cookie_path() |
---|
29 | { |
---|
30 | if ( isset($_SERVER['REDIRECT_SCRIPT_NAME']) and |
---|
31 | !empty($_SERVER['REDIRECT_SCRIPT_NAME']) ) |
---|
32 | { |
---|
33 | $scr = $_SERVER['REDIRECT_SCRIPT_NAME']; |
---|
34 | } |
---|
35 | else if ( isset($_SERVER['REDIRECT_URL']) ) |
---|
36 | { |
---|
37 | // mod_rewrite is activated for upper level directories. we must set the |
---|
38 | // cookie to the path shown in the browser otherwise it will be discarded. |
---|
39 | if |
---|
40 | ( |
---|
41 | isset($_SERVER['PATH_INFO']) and !empty($_SERVER['PATH_INFO']) and |
---|
42 | ($_SERVER['REDIRECT_URL'] !== $_SERVER['PATH_INFO']) and |
---|
43 | (substr($_SERVER['REDIRECT_URL'],-strlen($_SERVER['PATH_INFO'])) |
---|
44 | == $_SERVER['PATH_INFO']) |
---|
45 | ) |
---|
46 | { |
---|
47 | $scr = substr($_SERVER['REDIRECT_URL'], 0, |
---|
48 | strlen($_SERVER['REDIRECT_URL'])-strlen($_SERVER['PATH_INFO'])); |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | $scr = $_SERVER['REDIRECT_URL']; |
---|
53 | } |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $scr = $_SERVER['SCRIPT_NAME']; |
---|
58 | } |
---|
59 | |
---|
60 | $scr = substr($scr,0,strrpos( $scr,'/')); |
---|
61 | |
---|
62 | // add a trailing '/' if needed |
---|
63 | if ((strlen($scr) == 0) or ($scr{strlen($scr)-1} !== '/')) |
---|
64 | { |
---|
65 | $scr .= '/'; |
---|
66 | } |
---|
67 | |
---|
68 | if ( substr(PHPWG_ROOT_PATH,0,3)=='../') |
---|
69 | { // this is maybe a plugin inside pwg directory |
---|
70 | // TODO - what if it is an external script outside PWG ? |
---|
71 | $scr = $scr.PHPWG_ROOT_PATH; |
---|
72 | while (1) |
---|
73 | { |
---|
74 | $new = preg_replace('#[^/]+/\.\.(/|$)#', '', $scr); |
---|
75 | if ($new==$scr) |
---|
76 | { |
---|
77 | break; |
---|
78 | } |
---|
79 | $scr=$new; |
---|
80 | } |
---|
81 | } |
---|
82 | return $scr; |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * persistently stores a variable in pwg cookie |
---|
87 | * @return boolean true on success |
---|
88 | * @see pwg_get_cookie_var |
---|
89 | */ |
---|
90 | function pwg_set_cookie_var($var, $value) |
---|
91 | { |
---|
92 | $_COOKIE['pwg_'.$var] = $value; |
---|
93 | return |
---|
94 | setcookie('pwg_'.$var, $value, |
---|
95 | strtotime('+10 years'), cookie_path()); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * retrieves the value of a persistent variable in pwg cookie |
---|
100 | * @return mixed |
---|
101 | * @see pwg_set_cookie_var |
---|
102 | */ |
---|
103 | function pwg_get_cookie_var($var, $default = null) |
---|
104 | { |
---|
105 | if (isset($_COOKIE['pwg_'.$var])) |
---|
106 | { |
---|
107 | return $_COOKIE['pwg_'.$var]; |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | return $default; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | ?> |
---|