2 /********************************************************************
6 Copyright 2008 Radosław Pietruszewski
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ********************************************************************/
25 *******************************/
27 function setH1($value)
29 define('WTRMLN_H1',$value);
31 return '<h1>' . $value . '</h1>';
34 /* Zamiana tablicy na obiekt
35 ********************************/
37 function arrayToObject(array $array)
39 foreach($array as $key => $var)
43 $object->$key = arrayToObject($var);
54 /* Zamiana obiektu na tablicę
55 ********************************/
57 function objectToArray($object)
59 foreach($object as $key => $var)
63 $array[$key] = objectToArray($var);
74 /* Zamiana tablicy lub obiektu na HTML-owskie/XML-owskie argumenty
75 ********************************/
77 function arrayToHTMLArguments($array)
81 foreach($array as $key => $var)
83 $arguments .= ' ' . $key . '="' . $var . '"';
86 $arguments = substr($arguments, 1);
91 /* Alias funkcji arrayToHTMLArguments
92 ********************************/
94 function objectToHTMLArguments($object)
96 return arrayToHTMLArguments($object);
99 /* zwraca element tablicy $_POST
100 ********************************/
107 /* tworzy polską odmianę rzeczownika dla liczebnika
108 *******************************/
110 function generatePlFormOf($int, $odm1, $odm2, $odm3)
112 if($int == 0) return $odm3;
113 if($int == 1) return $odm1;
114 if($int > 1 && $int < 5) return $odm2;
115 if($int > 4 && $int < 22) return $odm3;
116 $int = substr($int, -1, 1);
118 if($int == 0 ||
$int == 1) return $odm3;
119 if($int > 1 && $int < 5) return $odm2;
120 if($int > 4 && $int < 10) return $odm3;
123 /* tworzy link do podstrony
124 **************************************/
126 function site_url($url)
128 return WTRMLN_SITEURL
. $url;
131 /* określenie IP kolesia
133 /* funkcja pochodzi oryginalnie z: http://php.org.pl/artykuly/3/22
134 **************************************/
140 if(!empty($_SERVER['HTTP_CLIENT_IP']))
142 $ip = $_SERVER['HTTP_CLIENT_IP'];
145 if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
147 $ipList = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']);
151 array_unshift($ipList, $ip);
155 foreach($ipList as $v)
157 if(!ereg('^(192\.168|172\.16|10|224|240|127|0)\.', $v))
163 return $ip ?
$ip : $_SERVER['REMOTE_ADDR'];
166 /* zwraca hash określony w configu
167 ***********************************/
169 function strHash($string, $algo = NULL)
173 $algo = Config
::$hashAlgo;
176 elseif(is_int($algo))
179 $algo = Config
::$hashAlgo;
180 $algo = $algo[$algo_id];
183 $algoType = $algo[0];
185 $algo = substr($algo, 1);
187 // jeśli pierwszy znak to "x", używamy do haszowania funkcji hash. Jeśli
188 // inny - używamy standardowej funkcji (obecnie są chyba tylko trzy,
189 // może w PHP6 będzie więcej)
193 return hash($algo, $string);
197 return $algo($string);