$id - $src
";
		print_r($p_array);
		print "
"; } /** * Stara funkcja array_display - działa prawidłowo w wersji PHP 4 * * @param array, object $p_array Tablica lub obiekt do wyświetlenia * @param int $user_defined I don't know ;) */ public static function ArrayDisplayOld($array_name, $user_defined = 0 ) { $indexBreak = 0; if (!isset($array_name)) { print("

TABLICA JEST PUSTA

\n"); } else { print("\n"); print("\n"); // for (reset($array_name); (strcmp(($key=key($array_name)) ,"")); next($array_name)){ foreach ($array_name as $key => $value) { if (strcmp($key,"GLOBALS") == 0) $user_defined = 0; if ($user_defined == 1) continue; if ((is_array($value) || is_object($value)) && (strcmp($key,"GLOBALS") != 0)) { print("\n"); } else { print("\n"); } if (++$indexBreak>1000) { break; } } print("
".$array_name."
".substr(gettype($key),0,3).">".str_replace(" "," ",$key)."<".(is_object($array_name) ? 'b.d.' : count($array_name[$key])).""); Utils::ArrayDisplayOld($value); print ("
".substr(gettype($key),0,3).">".str_replace(" "," ",$key)."<"); print("".substr(gettype($value),0,3).">".str_replace(" "," ",$value)."<
\n"); @reset($array_name); } } /** * * @param string $search * @param string $replace * @param string $subject * @return string */ public static function ReplaceFirstString($search, $replace, $subject) { $search = '/'.preg_quote($search, '/').'/'; return preg_replace($search, $replace, $subject, 1); } /** * Przeszukiwanie tablicy na podstawie zadanych tekst�w * * @param Array $array * @param string $keySearchStart * @param string $keySearchEnd * @return int */ public static function GetArrayKeyNumberDifference($array, $keySearchStart, $keySearchEnd) { $index = 0; foreach ($array as $key => $value) { if ($key==$keySearchStart) { $indexStart = $index; } if ($key==$keySearchEnd) { $indexEnd = $index; break; // przerywamy bo nie mamy czego szukac } $index++; } $difference = $indexEnd-$indexStart; return $difference; } /** * Zwraca rozszerzenie pliku na podstawie nazwy * * @param string $fileName * @return string */ public static function FileExtFromName($fileName) { $array = explode('.', $fileName); $ext = $array[count($array)-1]; return $ext; } /** * Zwraca nazwe pliku bez rozszerzenia * * @param string $fileName * @return string */ public static function FileNameFromName($fileName) { $array = explode('.', $fileName); unset($array[count($array)-1]); $fileName = implode('.', $array); return $fileName; } /** * Wykonuje redirect * * @param string $url */ public static function Redirect($url,$error =false) { $url = str_replace('&', '&', $url); header( "HTTP/1.1 $error"); header("Location: ".$url); exit(); } /** * Porz�dkuje entery (zwaraca tekst z enterami w zadanej postaci) * * @param string $p_text * @param string $p_enter * @return string */ function GetSaveEnterInText($p_text, $p_enter = null) { $enter = is_null($p_enter) ? chr(13) : $p_enter; $text = $p_text; $text = str_replace("\r\n", "\n", $text); $text = str_replace("\r", "", $text); $text = str_replace("\n", $enter, $text); return $text; } /** * Wy�wietla zapytania (funcja do debugowania) * */ function DisplayQueries() { echo count($_SESSION['queries']).'
'; sort($_SESSION['queries']); Utils::ArrayDisplayOld($_SESSION['queries']); unset($_SESSION['queries']); } public static function RemovePolish($string) { $letters = array('ę'=>'e', 'ó'=>'o', 'ą'=>'a', 'ś'=>'s', 'ł'=>'l', 'ź'=>'z', 'ż'=>'z', 'ć'=>'c', 'ń'=>'n', 'Ę'=>'e', 'Ó'=>'O', 'Ą'=>'A', 'Ś'=>'S', 'Ł'=>'L', 'Ż'=>'Z', 'Ź'=>'Z', 'Ć'=>'C', 'Ń'=>'N'); $string = strtr($string, $letters); foreach($letters as $letters=>$replacement) { $string = str_replace($letters, $replacement, $string); } return strtolower($string); } public static function RemovePolishNoToLower($string) { $letters = array('ę'=>'e', 'ó'=>'o', 'ą'=>'a', 'ś'=>'s', 'ł'=>'l', 'ź'=>'z', 'ż'=>'z', 'ć'=>'c', 'ń'=>'n', 'Ę'=>'e', 'Ó'=>'O', 'Ą'=>'A', 'Ś'=>'S', 'Ł'=>'L', 'Ż'=>'Z', 'Ź'=>'Z', 'Ć'=>'C', 'Ń'=>'N'); $string = strtr($string, $letters); foreach($letters as $letters=>$replacement) { $string = str_replace($letters, $replacement, $string); } return $string; } public static function TextToUrl($string) { $letters = array('-'=> '_',' '=> '_', '/'=> '_', 'ę'=>'e', 'ó'=>'o', 'ą'=>'a', 'ś'=>'s', 'ł'=>'l', 'ź'=>'z', 'ż'=>'z', 'ć'=>'c', 'ń'=>'n', 'Ę'=>'e', 'Ó'=>'O', 'Ą'=>'A', 'Ś'=>'S', 'Ł'=>'L', 'Ż'=>'Z', 'Ź'=>'Z', 'Ć'=>'C', 'Ń'=>'N'); $string = strtr($string, $letters); foreach($letters as $letters=>$replacement) { $string = str_replace($letters, $replacement, $string); } return urlencode(strtolower(strip_tags($string))); } public static function AddSlashes($string) { return $string; } public static function TextToTitle($string) { $string = str_replace('"', '', (strip_tags($string))); return $string; } /** * Zamienia polskie znaki zakodowane utf pobrane z adresu url(param) na polskie znaki :) * */ function url2pl($text) { // $text = str_replace("", '/', $text); $text = str_replace("%2F", '/', $text); $text = str_replace("\xC4\x85", 'ą', $text); $text = str_replace("\xC4\x84", 'Ą', $text); $text = str_replace("\xC4\x87", 'ć', $text); $text = str_replace("\xC4\x86", 'Ć', $text); $text = str_replace("\xC4\x99", 'ę', $text); $text = str_replace("\xC4\x98", 'Ę', $text); $text = str_replace("\xC5\x82", 'ł', $text); $text = str_replace("\xC5\x81", 'Ł', $text); $text = str_replace("\xC3\xB3", 'ó', $text); $text = str_replace("\xC3\x93", 'Ó', $text); $text = str_replace("\xC5\x9B", 'ś', $text); $text = str_replace("\xC5\x9A", 'Ś', $text); $text = str_replace("\xC5\xBC", 'ż', $text); $text = str_replace("\xC5\xBB", 'Ż', $text); $text = str_replace("\xC5\xBA", 'ż', $text); $text = str_replace("\xC5\xB9", 'Ż', $text); $text = str_replace("\xc5\x84", 'ń', $text); $text = str_replace("\xc5\x83", 'Ń', $text); return $text; } function specjalSearchSing($text) { $text = str_replace("%2F", '%252F', $text); $text = str_replace("/", '%252F', $text); return $text; } public static function cleanUrl($text) { $text=strtolower($text); $code_entities_match = array(' ','--','"','!','@','#','$','%','^','&','*','(',')','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','='); $code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','',''); $text = str_replace($code_entities_match, $code_entities_replace, $text); return $text; } public function cleanUrlSpaces($text) { $text=strtolower($text); $code_entities_match = array(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','='); $code_entities_replace = array(' ','-','','','','','','','','','','','','','','','','','','','','','','','',''); $text = str_replace($code_entities_match, $code_entities_replace, $text); return $text; } /** * Pomocnicza f sortuj�ca * */ public static function sortIt($objA, $objB, $key = 'count'){ if ($objA[$key] == $objB[$key]) return 0; return ($objA[$key] > $objB[$key]) ? -1 : 1; } public function MakeImageUrlFromHeader($headerTitle) { $exp = explode(" ", $headerTitle); $imgUrl = ''; foreach ($exp as $e) { $imgUrl .= ucfirst(strtr(strtolower($e), "žążśźęćńółĄŻŚŹĘĆŃÓŁ?!.,:", "zazszecnolAZSZECNOL_____")); } return $imgUrl; } /** * Pomocnicza f sortuj�ca * */ public static function sortByQO($objA, $objB){ self::sortIt($objA, $objB, 'queue_order'); } /** * Rozpoczyna mpomiar czasu * */ public static function TimerStart() { // Rozpoczynamy pomiar czasu wykonywania skryptu $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; // --> } /** * Konczy pomiar czasu * * @return string */ public static function TimerEnd() { // Konczymy pomiar czasu wykonywania skryptu $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); return $totaltime; } /** * Zapisuje sortowanie dla podanej tabeli * * @param array $p_arraySort tablica id'k�w * @param string $sortColumn kolumna sortowania * @param string $table tabla sortowania * @param string $idColumn po jakim id'ku sorujemy */ public static function SaveSort($arraySort, $sortColumn, $table, $idColumn) { $db = Registry::Get('db'); if (count($arraySort)) { foreach ($arraySort as $id => $value) { $sql = 'UPDATE '.$table.' SET '.$sortColumn.'='.$value.' WHERE '.$idColumn.' = '.$id; //Utils::ArrayDisplay($sql); $db->execute($sql); } } } /** * Filtr danych XSS * * @param string $val * @return string */ public static function RemoveXss($val) { // $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val); if(Config::Get('site')!='Admin') { $search = 'aąbcćdeęfghijklłmnoópqrsśtuvwxyzżź'; $search .= 'AĄBCĆDEĘFGHIJKLŁMNOÓPQRSŚTUVWXYZŻŹ'; $search .= '1234567890!@#$%^&*()'; $search .= '~`";:?+/={}[]-_|\'\\'; for ($i = 0; $i < strlen($search); $i++) { $val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); $val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); } $ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound'); $ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); $htmlStart = '/\"\s*>/'; $ra = array_merge($ra1, $ra2); $found = true; while ($found == true) { $val_before = $val; for ($i = 0; $i < sizeof($ra); $i++) { $pattern = '/'; for ($j = 0; $j < strlen($ra[$i]); $j++) { if ($j > 0) { $pattern .= '('; $pattern .= '(&#[xX]0{0,8}([9ab]);)'; $pattern .= '|'; $pattern .= '|(�{0,8}([9|10|13]);)'; $pattern .= ')*'; } $pattern .= $ra[$i][$j]; } $pattern .= '/i'; $replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); $val = preg_replace($pattern, $replacement, $val); $val = preg_replace($htmlStart, "", $val); if ($val_before == $val) { $found = false; } } } } return $val; } /** * Zwraca sliczna date * * @param string $datetime * @return string */ public static function NiceDate($datetime, $noShort = false, $format = null, $time_format = null) { $date = strtotime($datetime); if (!$date) { $date = (int)$datetime; } $now = time(); $out = ''; if($format == null) $format = Registry::Get('DATE_SHORT_FORMAT'); if($time_format == null) $time_format = Registry::Get('TIME_DEFAULT_FORMAT'); if (!$noShort) { if(date(Registry::Get('DATE_SHORT_FORMAT'), $date) == date(Registry::Get('DATE_SHORT_FORMAT'), $now)) { $out = "Dzisiaj, " . strftime($time_format, $date); } else if(date(Registry::Get('DATE_SHORT_FORMAT'), $date) == date(Registry::Get('DATE_SHORT_FORMAT'), $now - 86400)) { $out = "Wczoraj, " . strftime($time_format, $date); } else if(stristr(PHP_OS, "WIN")) { $out = ucfirst(iconv("CP1250", "ISO-8859-2", strftime($format, $date))); } else { $out = ucfirst(strftime($format, $date)); } } else { if(stristr(PHP_OS, "WIN")) { $out = ucfirst(iconv("CP1250", "ISO-8859-2", strftime($format, $date))); } else { $out = ucfirst(strftime($format, $date)); } } return $out; } /** * Pod�wietla s�owa wyst�puj�ce w tytule i tre�ci. * Nale�y przekaza� mu DataObject. * Fields - pola po przecinku, w kt�rych ma by� wyr�nione slowo wyszukania. * $hlBegin - tekst wstawiony przed szukabym s�owem * $hlEnd - tekst wstawiony po szukabym s�owie * * @param DataObject $array * @param string $search * @param string $fields * @param string $hlBegin * @param string $hlEnd */ public static function HighlightText(&$array, $search, $fields = 'Title,Text,Tag', $hlBegin = HL_BEGIN, $hlEnd = HL_END) { $search = strtolower($search); $replace = "$hlBegin$search$hlEnd"; $field = explode(',', $fields); if (is_array($array)){ foreach ($array as $obj) { for ($i = 0 ; $i < count($field) ; $i++) { if($field[$i]=='Tag'){ $methodGet = "Get" . trim($field[$i]); $methodSet = "Set" . trim($field[$i]); $value = $obj->$methodGet(); $arrayValue = explode(',', $value); $done = array(); foreach ($arrayValue as $tagObj) { if(strtolower($tagObj) == strtolower($search)){ $tagObj = $replace; array_unshift($done, $tagObj); } else { $done[] = $tagObj; } } $value = implode(',', $done); $obj->$methodSet($value); } else { $methodGet = "Get" . trim($field[$i]); $methodSet = "Set" . trim($field[$i]); $value = $obj->$methodGet(); $obj->$methodSet(str_ireplace($search, $replace, $value)); } } } } else{ for ($i = 0 ; $i < count($field) ; $i++) { if($field[$i]=='Tag'){ $methodGet = "Get" . trim($field[$i]); $methodSet = "Set" . trim($field[$i]); $value = $obj->$methodGet(); $arrayValue = explode(',', $value); $done = array(); foreach ($arrayValue as $tagObj) { if(strtolower($tagObj) == strtolower($search)){ $tagObj = $replace; array_unshift($done, $tagObj); } else { $done[] = $tagObj; } } $value = implode(',', $done); $obj->$methodSet($value); } else { $methodGet = "Get" . trim($field[$i]); $methodSet = "Set" . trim($field[$i]); $value = $obj->$methodGet(); $obj->$methodSet(str_ireplace($search, $replace, $value)); } } } } /** * Zwraca dat� - miesi�c za kt�ry przyznana zosta�a nagroda. * */ public static function AwardDate() { $month = (int)date('m'); $year = (int)date('Y'); //Od 21 nagrody przyznajemy za obecny miesiac, wcze�niej za miniony if ((int)date('d') < 21) { $month --; if ($month == 0) { $month = 12; $year --; } } return $year.$month."01"; } /** * counts elements of an multidimensional array * * @param array $array Input Array * @param int $limit dimensions that shall be considered (-1 means no limit ) * @return int counted elements */ public static function Multicount ($array, $limit = -1) { $cnt = 0; $limit = $limit > 0 ? (int) $limit : -1; $arrs[] = $array; for ($i=0; isset($arrs[$i]) && is_array($arrs[$i]); ++$i) { foreach ($arrs[$i] as $value) { if (!is_array($value) ) ++$cnt; elseif( $limit==-1 || $limit>1 ) { if( $limit>1 ) --$limit; $arrs[] = $value; } } } return $cnt; } /** * Konwertuje tablicę do formatu jSon'a. * * @param array $array * @return string */ public static function Array2Json($array) { $output = "{"; foreach ($array as $key=>$val) { if (is_array($val)) { $output .= "\"".$key."\" : [" . Array2Json($val) ."],"; } else { $output .= "\"".$key."\" : \"".$val."\","; } } $output .= "}"; return $output; } /** * funkcja wypisujaca js wypisujacego adres email * * @param $email - adres email * @param $cssClass - klasa css dla linka */ public static function jsEmail($email,$cssClass = null) { $s = ''; return $s; } /** * funkcja przypisuje cyfrom z lancucha wartosci literowe (na potrzeby LUCENE) * @param string $var * @return string */ public static function codeIntToChar($var) { $out = null; //var_dump($var); $lenght = strlen($var); $var = (string)$var; for($i = 0; $i < $lenght; $i++) { if(in_array($var[$i], array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) { $out .= chr(107 + $var[$i]); } else { $out .= $var[$i]; } } //var_dump($out); //if($lenght < 3) { // $out = 'zxc'.$out; //} return $out; } public static function codeCharToInt($var) { $out = null; $lenght = strlen($var); $var = (string)$var; for($i = 0; $i < $lenght; $i++) { $ord = ord($var[$i]) - 107; $out .= $ord; } //TODO - obsluga dla mniejszych liczb niz 3 cyfry if($lenght < 3) { $out = 'zxc'.$out; } return $out; } /** * Metoda tworzy katalogi * * @param string $dir sciezka katalog�w * @param int $mode prawa zapisu * @param bool $recursive czy ma tworzy� katalogi rekursywnie * @return bool */ public static function Mkdirs($dir, $mode = 0777, $recursive = true) { if( is_null($dir) || $dir === "" ){ return FALSE; } if( is_dir($dir) || $dir === DIRECTORY_SEPARATOR ){ return TRUE; } if( PhotoDAL::mkdirs(dirname($dir), $mode, $recursive) ){ return mkdir($dir, $mode); } return FALSE; } public static function dateDiff($date1, $date2) { //$date1 today, or any other day //$date2 date to check against $d1 = explode(" ", $date1); $y1 = $d1[0]; $m1 = $d1[1]; $d1 = $d1[2]; $d2 = explode(" ", $date2); $y2 = $d2[0]; $m2 = $d2[1]; $d2 = $d2[2]; $date1_set = mktime(0,0,0, $m1, $d1, $y1); $date2_set = mktime(0,0,0, $m2, $d2, $y2); return(round(($date2_set-$date1_set)/(60*60*24))); } public static function MultiImplode($glue, $pieces, $multiGlue = null) { $first = array_shift($pieces); if (!$multiGlue) { $multiGlue = $glue; } $ret = (is_array($first) ? self::MultiImplode($glue, $first, $multiGlue) : $first); foreach ($pieces as $item) { if (is_array($item)) { $ret .= $multiGlue . '' . self::MultiImplode($glue, $item); } else { $ret .= $glue . $item; } } return $ret; } public static function CleanString($str) { return str_replace(array('\"', "R11;", "R22;", "R21;", "R30;", "R17;"), array('"', '-', '”', '„', '', ''), $str); } public static function DisplayBackTrace($backtrace) { $backtrace = array_map(function ($a) { return array($a["line"], $a["file"], $a["function"]); }, $backtrace); var_dump($backtrace); } /* * Zamienia " na ", < na < , > > */ public static function SaveInput($string, $type = 'input') { $patterns = array('/"/'); $replacements = array('"'); if($type == 'textarea') { $patterns = array('/"/', '/