PATH:
root
/
polmet2templates
<?php class Utils { public static function imageResize($file, $saveDir = false, $options = []) { // If $saveDir === true, then use the same file // If $saveDir === false or "", then return as image; // Otherwise save to given path $fileDir = trim(dirname($file), "\\/"); $file = trim(str_replace($fileDir, "", $file), "\\/"); if ($saveDir === true) { $saveDir = $fileDir; } else if ($saveDir !== false && $saveDir !== "") { $saveDir = trim($saveDir, "\\/"); if (!is_dir($saveDir)) @mkdir($saveDir, 0777, true); } if (!isset($options)) $options = []; $options = array_merge([ "fileName" => $file, "skipSmaller" => true, "width" => 320, "height" => 0, "ratio" => 0, "compression" => 70, "overwrite" => false ], $options); if (isset($options["fileRename"])) { if (isset($options["fileRename"][2])) { if (is_callable($options["fileRename"][1])) $options["fileName"] = preg_replace_callback($options["fileRename"][0], $options["fileRename"][1], $file); else $options["fileName"] = preg_replace($options["fileRename"][0], $options["fileRename"][1], $file); } else { $options["fileName"] = str_replace($options["fileRename"][0], $options["fileRename"][1]); } } $openedFile = "{$fileDir}/{$file}"; $saveFileName = "{$saveDir}/{$options['fileName']}"; if (!isset($options["overwrite"]) || $options["overwrite"] === false) { if (file_exists($saveFileName) && @filesize($saveFileName) > 0) { return false; } } if ($size = @getimagesize("{$fileDir}/{$file}")) { if (isset($options["width"]) && (!isset($options["height"]) || $options["height"] < 1)) { if ($options["width"] == $size[0] || (isset($options["skipSmaller"]) && $options["skipSmaller"] !== false && $options["width"] >= $size[0]) || (isset($options["skipBigger"]) && $options["skipBigger"] !== false && $options["width"] <= $size[0])) return false; } if (isset($options["height"]) && (!isset($options["width"]) || $options["width"] < 1)) { if ($options["height"] == $size[1] || (isset($options["skipSmaller"]) && $options["skipSmaller"] !== false && $options["height"] >= $size[1]) || (isset($options["skipBigger"]) && $options["skipBigger"] !== false && $options["height"] <= $size[1])) return false; } if (isset($options["width"]) && isset($options["height"]) && $options["width"] == $size[0] && $options["height"] == $size[1]) return false; } if ($saveFileName != $openedFile) $saveFile = fopen("{$saveDir}/{$options['fileName']}", "w+"); if (isset($options["width"]) && !isset($options["height"])) { if (!isset($options["ratio"]) || $options["ratio"] == 0) $options["height"] = 0; else $options["height"] = $options["width"] / $options["ratio"]; } if (isset($options["height"]) && !isset($options["width"])) { if (!isset($options["ratio"]) || $options["ratio"] == 0) $options["width"] = 0; else $options["width"] = $options["height"] * $options["ratio"]; } if (extension_loaded('imagick')) { $image = new Imagick("{$fileDir}/{$file}"); $image->clone; $image->setImageCompressionQuality($options["compression"]); $image->stripImage(); $image->thumbnailImage($options["width"], $options["height"]); if (!isset($saveFile)) $saveFile = fopen("{$fileDir}/{$file}", "w+"); $image->writeImageFile($saveFile); $image->destroy(); // if (filesize($saveFile) == 0) unlink($saveFile); } else { } } public static function imageResizeDir($inputDir = "userfiles", $outputDir = "images/thumbs/userfiles", $options = [], $recursive = true) { if (!isset($options)) $options = []; if (!is_array($options)) $options = [$options]; $options = array_merge([ "mode" => "rsearch", "pattern" => "/.*\.(?:jpe?g|gif|png|bmp|webp)/i" ], $options); if ($options["mode"] != "rglob") { $files = self::rsearch($inputDir, $options["pattern"]); } else { $files = self::rglob("{$inputDir}/{$options['pattern']}"); } foreach ($files as $file) { $fileOutputDir = str_replace(["\\", "/"], "/", dirname($file)); $fileOutputDir = trim(substr($fileOutputDir, strpos($fileOutputDir, "/")), "/"); $fileOutputDir = "{$outputDir}/{$fileOutputDir}"; self::imageResize($file, $fileOutputDir, $options); } } public static function rglob($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { $files = array_merge($files, self::rglob($dir.'/'.basename($pattern), $flags)); } return $files; } public static function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $ite = new RecursiveIteratorIterator($dir); $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH); $fileList = array(); foreach($files as $file) { $file[0] = trim($folder, "\/") . DIRECTORY_SEPARATOR . "{$file[0]}"; $fileList = array_merge($fileList, $file); } return $fileList; } public static function deleteDir($dirPath) { if (!is_dir($dirPath)) { throw new InvalidArgumentException("$dirPath must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { self::deleteDir($file); } else { unlink($file); } } rmdir($dirPath); } public static function firstXChars($string, $chars = 100) { return strstr($string, ".", true) . "."; } public static function translit($string) { return iconv("UTF-8", "ASCII//TRANSLIT", $string); } public static function HTMLSplit($html = "", $options = ["xpath" => "//*"]) { if (!isset($options) || $options == "") $options = ["xpath" => $options]; if (gettype($options) != "array") $options = ["xpath" => $options]; if (!isset($options['xpath']) || $options['xpath'] == "") $options['xpath'] = "//*"; $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $dom = new DOMDocument(); $dom->loadHTML($html); $find = new DOMXPath($dom); $elements = $find->query($options['xpath']); $elArr = []; foreach ($elements as $element) { array_push($elArr, $dom->saveHTML($element)); $element->parentNode->removeChild($element); } $html = []; preg_match_all("/(?<=<body>).*(?=<\/body>)/is", $dom->saveHTML(), $html); if (!isset($html[0][0])) $html[0] = [""]; return [$html[0][0], $elArr]; } public static function HTMLgetBlockWithClass($html, $options = ["class" => ""]) { if (!isset($options) || $options == "") $options = ["class" => ""]; if (gettype($options) != "array") $options = ["class" => ""]; if (!isset($options['class'])) $options['class'] = ""; $xpath = "//*[contains(@class, '{$options['class']}')]"; return self::HTMLSplit($html, $xpath); } /* public static function HTMLProcess($html, $options = ["xpath" => "//*"], $callback, $data) { if (!isset($options) || $options == "") $options = ["xpath" => $options]; if (gettype($options) != "array") $options = ["xpath" => $options]; if (!isset($options['xpath']) || $options['xpath'] == "") $options['xpath'] = "//*"; $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $dom = new DOMDocument(); $dom->loadHTML($html); $find = new DOMXPath($dom); $elements = $find->query($options['xpath']); $elArr = []; foreach ($elements as $element) { array_push($elArr, $dom->saveHTML($element)); $element->parentNode->removeChild($element); } } */ public static function makeLink($link = "", $customChars = [[], []], $urlEntities = false, $override = false, $noPolishChars = true) { if ($customChars && gettype($customChars) != "array" && $customChars != "") { $customChars = [$customChars, ""]; } if (gettype($customChars[0]) != "array") $customChars[0] = str_split($customChars[0]); if (gettype($customChars[1]) != "array") $customChars[1] = str_split($customChars[1]); $toFindLen = count($customChars[0]); $toReplaceLen = count($customChars[1]); if ($toReplaceLen > $toFindLen) $customChars[1] = array_slice($customChars[1], 0, $toFindLen); if ($toReplaceLen < $toFindLen) { $timesToRepeat = ceil($toFindLen / $toReplaceLen); $arr = $customChars[1]; for ($i = 1; $i < $timesToRepeat; $i++) { $customChars[1] = array_merge($customChars[1], $arr); } $customChars[1] = array_slice($customChars[1], 0, $toFindLen); } $link = preg_replace_callback("/( |-|_|\/|\\|){2,}/", function($ch) { return substr($ch[0], 0, 1); }, $link); if ($override !== true) { $customChars[0] = array_merge([" ", "-", ".", "\\", "/", "#", "?", "&"], $customChars[0]); $customChars[1] = array_merge(["-", "-", "_", "_", "_", "_", "_", "_"], $customChars[1]); } if ($noPolishChars !== false) { $customChars[0] = array_merge(["Ą", "Ć", "Ę", "Ł", "Ń", "Ó", "Ś", "Ź", "Ż", "ą", "ć", "ę", "ł", "ń", "ó", "ś", "ź", "ż"], $customChars[0]); $customChars[1] = array_merge(["A", "C", "E", "L", "N", "O", "S", "Z", "Z", "a", "c", "e", "l", "n", "o", "s", "z", "z"], $customChars[1]); } $link = htmlspecialchars(str_replace($customChars[0], $customChars[1], $link)); if ($urlEntities) $link = rawurlencode($link); return $link; } /* function shortenText($text, $sentences = 3, $len = 150, $stripTags = true) { if ($stripTags === true) $text = preg_replace("/<br[^>]*>/", " ", strip_tags($text, "<br>")); $startText = $text; $matches = array(); preg_match_all("/([^.]+). {1," . $sentences . "}/", $text . " ", $matches); $matches = $matches[0]; if (count($matches) > 0) $matches[count($matches) - 1] = substr($matches[count($matches) - 1], 0, -1); if ($sentences > 0) $matches = array_slice($matches, 0, $sentences); $text = implode("", $matches); if (strlen($text) > $len) $text = substr($text, 0, strpos($text, ". ", ($len - 10) > 0 ? $len - 10 : 0)) . "..."; return $startText . ".." == $text ? $startText : $text; } echo shortenText("Sfdasd sad sad adsa, sadasdssad sa, dsa. Dasdasfsdadsad, dsadsad dsa... Fdsfsfdsfds, fdsfsdf s, fdsfsdfds. FDsfdsfds... ", 2); */ public static function shortenText($text, $sentences = 3, $len = 150, $stripTags = true, $tags = "<br>") { if ($stripTags === true) { $text = preg_replace("/(?:alt|title)=['\"]([^'\"]+)['\"]/i", ">$1<a ", $text); $text = preg_replace("/<br[^>]*>|\s+|(?: )+/i", " ", strip_tags($text . " ", $tags)); } $text = preg_replace("/\s+/", " ", $text); $startText = $text; $matches = array(); //preg_match_all("/(?<=[.?!:][\sA-ZĄĆĘŁŃÓŚŹŻ]|^)[A-ZĄĆĘŁŃÓŚŹŻ].+?(?:[.?!:]\s|$)/i", $text . " ", $matches); preg_match_all("/(?<=^|\.\s|:\s|;\s)[^.]+(?:\.|:|;)(?:\s|$)/", $text . " ", $matches); $matches = $matches[0]; if (count($matches) <= 0) return $text; if ($sentences > 0) $matches = array_slice($matches, 0, $sentences); $text = substr(implode("", $matches), 0, -1); if (strlen($text) <= strlen($startText) && strlen($startText) <= $len) return $startText; if (strlen($text) <= $len) return preg_replace("/\.{4,}/i", "...", $text); if (strlen($text) + 3 <= $len) return preg_replace("/\.{4,}/i", "...", $text . "..."); $text = substr($text, 0, $len - 3) . "..."; return preg_replace("/\.{4,}/i", "...", $text); } public static function leadingZeros($num = 0, $max = 10) { //return str_pad($num, ceil(log10(abs($max) + 1)), '0', STR_PAD_LEFT); return sprintf("%0" . (ceil(log10(abs($max) + 1))) . "d", $num); } public static function getTexts($db, $tytulyCol = "tytul", &$tytuly, $tekstyCol = "tresc", &$teksty, &$inne, $table = "teksty", $lang = "", $stripTagsByTitlesID = [], $stripTagsByTextsID = [], $correctUnicodePLChars = true, $correctRelativePaths = false, $changeSizes = true, $defaultSize = 16) { if ($table == "" || $table == NULL || !$table) $table = "teksty"; if ($tytulyCol == "" || $tytulyCol == NULL || !$tytulyCol) $tytulyCol = "tytul"; if ($tekstyCol == "" || $tekstyCol == NULL || !$tekstyCol) $tekstyCol = "tresc"; $tekstyCols = $db->getColumnNames("{$table}{$lang}"); foreach ($tekstyCols as $tKey => $tVal) { if ($tVal == $tytulyCol || $tVal == $tekstyCol) unset($tekstyCols[$tKey]); } $tekstyDB = $db->select("{$table}{$lang}"); foreach ($tekstyDB as $key => $value) { $value[$tytulyCol] = preg_replace_callback("/{%(.+?)(?=%})%}/", function($f) { return defined($f[1]) ? constant($f[1]) : $f[0]; }, $value[$tytulyCol]); $value[$tekstyCol] = preg_replace_callback("/{%(.+?)(?=%})%}/", function($f) { return defined($f[1]) ? constant($f[1]) : $f[0]; }, $value[$tekstyCol]); if (array_search($value['id'], $stripTagsByTitlesID) !== false) $value[$tytulyCol] = strip_tags($value[$tytulyCol]); if (array_search($value['id'], $stripTagsByTextsID) !== false) $value[$tekstyCol] = strip_tags($value[$tekstyCol]); if ($correctUnicodePLChars === true) { $value[$tytulyCol] = preg_replace_callback("/[acenos][\x{301}\x{307}\x{328}]/ui", function($f) { $str = "AĄCĆEĘNŃOÓSŚaącćeęnńoósś"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tytulyCol]); $value[$tytulyCol] = preg_replace_callback("/[z][\x{301}]/ui", function($f) { $str = "ZŹzź"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tytulyCol]); $value[$tytulyCol] = preg_replace_callback("/[z][\x{307}]/ui", function($f) { $str = "ZŻzż"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tytulyCol]); $value[$tekstyCol] = preg_replace_callback("/[acenos][\x{301}\x{307}\x{328}]/ui", function($f) { $str = "AĄCĆEĘNŃOÓSŚaącćeęnńoósś"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tekstyCol]); $value[$tekstyCol] = preg_replace_callback("/[z][\x{301}]/ui", function($f) { $str = "ZŹzź"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tekstyCol]); $value[$tekstyCol] = preg_replace_callback("/[z][\x{307}]/ui", function($f) { $str = "ZŻzż"; return substr($str, strpos($str, $f[0][0]) + 1, 2); }, $value[$tekstyCol]); } if ($correctRelativePaths === true) { $value[$tytulyCol] = preg_replace("/((?:src|href)[^=\"]*?=[^\"]*?\")userfiles/i", "$1" . HOME_ROOT . "/userfiles", $value[$tytulyCol]); $value[$tekstyCol] = preg_replace("/((?:src|href)[^=\"]*?=[^\"]*?\")userfiles/i", "$1" . HOME_ROOT . "/userfiles", $value[$tekstyCol]); } if ($changeSizes === true) { $value[$tytulyCol] = preg_replace_callback("/(?<=: |:)(\d+)(px)(?=[; ',\"])/", function($f) { if (isset($f[1])) $f = (floatval($f[1]) / 16) . "rem"; return $f; }, $value[$tytulyCol]); $value[$tekstyCol] = preg_replace_callback("/(?<=: |:)(\d+|\d+\.\d+)(px)(?=[; ',\"])/", function($f) { if (isset($f[1])) $f = (floatval($f[1]) / 16) . "rem"; return $f; }, $value[$tekstyCol]); } $tytuly[$value['id']] = $value[$tytulyCol]; $teksty[$value['id']] = $value[$tekstyCol]; $inne[$value['id']] = []; foreach ($tekstyCols as $tVal) $inne[$value['id']][$tVal] = $value[$tVal]; } } public static function getMenus($db, $table = "menu", $lang = "", $options = []) { if (!isset($options['id'])) $options['id'] = "id"; if (!isset($options['order'])) $options['order'] = "kolejnosc"; if (!isset($options['show'])) $options['show'] = "pokaz"; if (!isset($options['parent'])) $options['parent'] = "rodzic"; if (!isset($options['flink'])) $options['flink'] = "flink"; if (!isset($options['redirect'])) $options['redirect'] = "przekierowanie"; if (!isset($options['text'])) $options['text'] = "tekst"; // if (!isset($options['sqlwhere'])) $options['sqlwhere'] = "`{$options['show']}` = 1"; // SELECT ONLY CHECKED AS VISIBLE if (!isset($options['sqlorderby'])) $options['sqlorderby'] = "`{$options['parent']}` ASC, `{$options['order']}` ASC, `{$options['id']}` ASC"; if (!isset($options['sqlwhere'])) $options['sqlwhere'] = ""; if ($options['sqlorderby']) $options['sqlorderby'] = "ORDER BY {$options['sqlorderby']} "; else $options['sqlorderby'] = ""; $menuDB = $db->select("{$table}{$lang}", "*, CASE WHEN {$options['parent']} > 0 THEN 1 ELSE 0 END AS `level`", NULL, "WHERE {$options['id']} != {$options['parent']}" . ($options['sqlwhere'] != "" ? " AND ({$options['sqlwhere']})" : "") . " {$options['sqlorderby']}"); $menu = []; foreach ($menuDB as $mKey => $mVal) { $menu[$mVal['id']] = $mVal; } unset($menuDB); array_walk_recursive($menu, function(&$item) { $item = preg_replace_callback("/{%(.+?)(?=%})%}/", function($f) { return defined($f[1]) ? constant($f[1]) : $f[0]; }, $item); }); foreach ($menu as $mKey => $mVal) { $menu[$mKey]['level'] = count(Utils::generateBreadcrumbs($menu, $mKey)) - 1; $menu[$mKey]['link'] = isset($menu[$mKey][$options['redirect']]) ? $menu[$mKey][$options['redirect']] : ""; if ($menu[$mKey]['link'] == "") { if ($menu[$mKey][$options['flink']] != "") { $menu[$mKey]['link'] = ($menu[$mKey][$options['text']] != "" && $menu[$mKey][$options['text']] != 0) ? $menu[$mKey][$options['text']] . "," : ""; $menu[$mKey]['link'] .= $menu[$mKey]['id'] . ","; $menu[$mKey]['link'] .= $menu[$mKey][$options['flink']]; } else { $menu[$mKey]['link'] = "index.php"; $miArr = []; array_push($miArr, "m={$menu[$mKey]['id']}"); if ($menu[$mKey][$options['text']] != 0 && $menu[$mKey][$options['text']] != "") array_push($miArr, "s={$menu[$mKey][$options['text']]}"); if (count($miArr) > 0) $menu[$mKey]['link'] .= "?" . implode("&", $miArr); } } } $tmp = []; foreach ($menu as $mKey => $mVal) array_push($tmp, $mVal); return $tmp; } public static function menuLink($miVal = []) { $miVal['link'] = isset($miVal['przekierowanie']) ? $miVal['przekierowanie'] : ""; if ($miVal['link'] == "") { if (isset($miVal['flink']) && $miVal['flink'] != "") { $miVal['link'] = ($miVal['tekst'] != "" && $miVal['tekst'] != 0) ? $miVal['tekst'] . "," : ""; $miVal['link'] .= $miVal['id'] . ","; $miVal['link'] .= $miVal['flink']; } else { $miVal['link'] = "index.php"; $miArr = []; array_push($miArr, "m={$miVal['id']}"); if ($miVal['tekst'] != 0 && $miVal['tekst'] != "") array_push($miArr, "s={$miVal['tekst']}"); if (count($miArr) > 0) $miVal['link'] .= "?" . implode("&", $miArr); } } return $miVal; } public static function hasChildNew($menu, $options = ["rodzic" => 0]) { $found = false; $checkKey = array_keys($options)[0]; $checkVal = $options[$checkKey]; foreach ($menu as $mK => $mV) { if ($mV[$checkKey] == $checkVal) { $found = true; break; } } return $found; } public static function renderMenu($menu, $options = ["id" => "id", "parent" => "rodzic"], $html = ["open" => "<ul>", "line" => "<li>", "dropClass" => "dropdown", "activeClass" => "active"]) { $arr = []; foreach ($menu as $mK => $mV) { if (!isset($arr[$mV[$options['parent']]])) $arr[$mV[$options['parent']]] = []; array_push($arr[$mV[$options['parent']]], $mV); } var_dump($arr); } public static function dirFiles($path = "", $options = [ "relative" => true, "noDots" => true, "type" => "files", // allowed types: files|dirs|all, default is "files" "exclude" => "", // exclude is superior to include (in RegEx format or array) "include" => "/.+/i", // include is inferior to exclude (in RegEx format or array) "asFirst" => false, "sort" => true, // false|true=name|dirs|files "subfolders" => false, "fileNameOnly" => false ]) { // $path = "./luchspolska/../files/"; if (!$path || $path == "") $path = $_SERVER['PHP_SELF']; if (!isset($options["currentPath"]) || !$options["currentPath"] || $options["currentPath"] == "" || !file_exists($options["currentPath"])) $currentPath = $_SERVER['PHP_SELF']; else $currentPath = $options["currentPath"]; $currentPath = str_replace("\\", "/", $currentPath); if (is_dir($currentPath)) { $currentDir = $currentPath . "/"; $currentFile = ""; } else { $currentDir = substr($currentPath, 0, strrpos($currentPath, "/") + 1); $currentFile = substr($currentPath, strrpos($currentPath, "/") + 1); } $base = str_replace($currentDir, "", self::getServerAddress()) . "/"; $currentPath = str_replace("\\", "/", $currentPath); if (!isset($options["relative"])) $options["relative"] = true; if (!isset($options["noDots"])) $options["noDots"] = true; if (!isset($options["type"])) $options["type"] = "files"; if ($options["type"] != "dirs" && $options["type"] != "all" && $options["type"] != "files") $options["type"] = "files"; if (!isset($options["sort"])) $options["sort"] = true; if (!isset($options["exclude"])) $options["exclude"] = ""; if (!isset($options["include"])) $options["include"] = "/.+/i"; if (!isset($options["asFirst"])) $options["asFirst"] = false; if (!isset($options["subfolders"])) $options["subfolders"] = false; if (!isset($options["fileNameOnly"])) $options["fileNameOnly"] = false; // if (gettype($options["exclude"]) == "array") $options["exclude"] = implode("|", $options["exclude"]); // if (gettype($options["include"]) == "array") $options["include"] = implode("|", $options["include"]); if (isset($options["cutToDirectory"]) && $options["cutToDirectory"] == "") unset($options["cutToDirectory"]); $path = rawurldecode($path) . "/"; $path = "/" . str_replace("\\", "/", $path); $path = preg_replace("/\\{2,}|\/{2,}/", "/", $path); if ($options["relative"]) { $path = preg_replace("/\\{2,}/", "/", $path); $path = substr($path, stripos($path, "/./")); $path = str_replace("/./", $base, $path); } $list = @scandir("./$path"); if ($list === false) $list = []; foreach ($list as $key => $dir) { if ($options["noDots"] === true) { if ($dir == "." || $dir == "..") { unset($list[$key]); continue; } } if (isset($options["exclude"]) && $options["exclude"] != "") { if (gettype($options["exclude"]) == "array") { if (array_search($dir, $options["exclude"]) !== false) { unset($list[$key]); continue; } } else if (preg_match($options["exclude"], $dir)) { unset($list[$key]); continue; } } if (isset($options["include"]) && substr($options["include"], 0, 4) != "/.*/" && substr($options["include"], 0, 4) != "/.+/") { if (!preg_match($options["include"], $dir)) { unset($list[$key]); continue; } } if (isset($options["type"])) { if ($options["type"] == "files") { if (is_dir(getcwd() . "{$path}{$dir}")) { unset($list[$key]); continue; } } else if ($options["type"] == "dirs") { if (!is_dir(getcwd() . "{$path}{$dir}")) { unset($list[$key]); continue; } } } } foreach ($list as $k => $l) { $list[$k] = substr($path, 1) . $list[$k]; if ($options["fileNameOnly"]) $list[$k] = substr($list[$k], strrpos($list[$k], "/") + 1); } return array_values($list); } /* public static function dirFiles($path, $cutToDirectory = "userfiles", $noDots = true, $sort = true, $first = true) { $acceptOnly = ["png", "jpg", "jpeg", "gif", "svg", "tiff", "bmp", "ico"]; $path = rawurldecode($path); if ($cutToDirectory) { $path = substr($path, stripos($path, $cutToDirectory)); } $givenFile = ""; if (!is_dir($path)) { if ($first == true) $givenFile = $path; $path = dirname($path); } $hnd = @opendir($path); $files = []; while($hnd !== false && ($file = readdir($hnd)) !== false) { if ($noDots && ($file !== '.' && $file !== '..')) { $filePath = $path . "/" . $file; $filePath = preg_replace("/(\/|\\\){2,}/", "$1", $filePath); if (!is_dir($filePath)) { $ext = mb_strtolower(substr($filePath, strrpos($filePath, ".") + 1)); if (array_search($ext, $acceptOnly) !== false && (@exif_imagetype($filePath) || @getimagesize($filePath))) { if (!($first == true && $givenFile == $filePath)) array_push($files, $filePath); } } } } sort($files, SORT_LOCALE_STRING); if ($givenFile != "") { $ext = mb_strtolower(substr($givenFile, strrpos($givenFile, ".") + 1)); if (!is_dir($givenFile) && array_search($ext, $acceptOnly) !== false && (@exif_imagetype($givenFile) || @getimagesize($givenFile))) $files = array_merge([$givenFile], $files); } return $files; } */ public static function human_filesize($bytes, $decimals = 2) { $sz = 'BKMGTPEZY'; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f ", $bytes / pow(1024, $factor)) . @$sz[$factor] . factor > 1 ? "iB" : ""; } public static function parseAttributes($attrData) { $attrMatch = []; $attrs = []; // {%(.+?)(?=%)%}{#(.+?)(?=#)#}.+?{\/#\2#}{\/%\1%} preg_match_all("/{%(.+?)(?=%)%}(.*){%\/\g1%}/", $attrData, $attrMatch); if (isset($attrMatch[0])) { foreach ($attrMatch[0] as $aKey => $aValue) { $attrs[$attrMatch[1][$aKey]] = []; $attrValues = []; preg_match_all("/{#(.+?)(?=#)#}(.*){#\/\g1#}/", $aValue, $attrValues); if (isset($attrValues[0])) { foreach ($attrValues[2] as $vKey => $vValue) { $attrs[$attrMatch[1][$aKey]][$attrValues[1][$vKey]] = $vValue; } } } } return $attrs; } public static function generateBreadcrumbs($data = [], $id = 0, $options = [ "id" => "id", "parent" => "rodzic", ]) { if (gettype($options) != "array") $options = [ "id" => "id", "parent" => "rodzic", ]; else { if (!isset($options['id'])) $options['id'] = "id"; if (!isset($options['parent'])) $options['parent'] = "rodzic"; } $arr = []; $parentID = $id; $found = false; foreach ($data as $dKey => $dValue) { if (isset($dValue[$options['id']]) && $dValue[$options['id']] == $id) { $found = true; break; } } if ($found === false) return []; while ($parentID != 0) { foreach ($data as $dKey => $dValue) { if (isset($dValue[$options['id']]) && $dValue[$options['id']] == $parentID) { array_unshift($arr, $dValue); $parentID = $dValue[$options['parent']]; break; } } } return $arr; } public static function hasChild($data = [], $parent = 0, $childToFind = 0, $options = [ "id" => "id", "parent" => "rodzic", ]) { $arr = Utils::generateBreadcrumbs($data, $childToFind, $options); foreach ($arr as $aKey => $aVal) { if (isset($aVal[$options['id']]) && $aVal[$options['id']] == $parent) { return true; } } return false; } public static function getServerAddress() { $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $domainName = $_SERVER['HTTP_HOST']; $addr = $protocol . $domainName . $_SERVER['REQUEST_URI']; $addr = substr($addr, 0, strrpos($addr, "/")); return $addr . "/"; } public static function includeDependencies($dependencies = []) { /* Array $dependencies: "your_name" = [ "css" => "css/your.css.link.css" / [], // optional, css path or array of css paths "js" => "js/your.js.link.js" / [], // optional, js path or array of js paths "id" => 2 / [1, 2] / function(), // values to test // function should return value or array of values "test" => 2 / [1, 2] / function(), // tested values on "id" // function should return value or array of values or boolean (when doing testing in place) "additional" => [ "type" => "css" / "js", // optional, if not specified, it will try to recognize from run() result "data" => $variable, // your custom data set, any type to later use inside run() "run" => function($data, &$css, &$js, &$cssLine, &$jsLine) // your custom function, have one argument, which is your previously given "data". Should return url path to css/js. You can alter $css for css links and $js for js links ] ] $css, $cssLine, $js, $jsLine - arrays of paths */ $css = []; $js = []; $jsScript = []; foreach ($dependencies as $dKey => $dValue) { $cssLine = []; $jsLine = []; $jsScriptLine = []; if (!isset($dValue['when']) || $dValue['when'] == "" || $dValue['when'] == NULL) $dValue['when'] = true; if (isset($dValue['id'])) { if (gettype($dValue['id']) == "integer" || gettype($dValue['id']) == "float") $dValue['id'] = [$dValue['id']]; if (gettype($dValue['id']) == "string") $dValue['id'] = explode(",", $dValue['id']); if (!isset($dValue['test'])) $dValue['test'] = true; if (is_callable($dValue['test'])) $dValue['test'] = $dValue['test']($dValue, $css, $js); if (gettype($dValue['test']) == 'integer' || gettype($dValue['test']) == 'float') $dValue['test'] = [$dValue['test']]; if (gettype($dValue['test']) == 'string') $dValue['test'] = explode(",", $dValue['test']); if (gettype($dValue['test']) == 'array') { $result = false; foreach ($dValue['test'] as $tKey => $tValue) { if (array_search($tValue, $dValue['id']) !== false) { $result = true; break; } } $dValue['test'] = $result; } $dValue['when'] = $dValue['test']; } if ($dValue['when'] === true) { if (isset($dValue['css'])) { if (is_callable($dValue['css'])) $dValue['css'] .= $dValue['css']($dValue, $css, $js); else { if (gettype($dValue['css']) == "string") $dValue['css'] = [$dValue['css']]; foreach ($dValue['css'] as $cValue) if ($cValue != "") array_push($cssLine, "<link rel=\"stylesheet\" href=\"{$cValue}\">"); } } if (isset($dValue['js'])) { if (is_callable($dValue['js'])) $dValue['js'] .= $dValue['js']($dValue, $css, $js); else { if (gettype($dValue['js']) == "string") $dValue['js'] = [$dValue['js']]; foreach ($dValue['js'] as $jValue) if ($jValue != "") array_push($jsLine, "<script type=\"text/javascript\" src=\"{$jValue}\"></script>"); } } if (isset($dValue['jsScript'])) { if (is_callable($dValue['jsScript'])) $dValue['jsScript'] .= $dValue['jsScript']($dValue, $css, $js); else { if (gettype($dValue['jsScript']) == "string") $dValue['jsScript'] = [$dValue['jsScript']]; foreach ($dValue['jsScript'] as $jValue) if ($jValue != "") array_push($jsScriptLine, $jValue); } } if (isset($dValue['additional'])) { if (!isset($dValue['additional']['data'])) $dValue['additional']['data'] = NULL; $result = $dValue['additional']['run']($dValue['additional']['data'], $css, $js, $cssLine, $jsLine); if (!isset($dValue['additional']['type']) || ($dValue['additional']['type'] != "css" && $dValue['additional']['type'] != "js")) $dValue['additional']['type'] = mb_strtolower(substr($result, strrpos($result, ".") + 1)); switch ($dValue['additional']['type']) { case 'css': array_push($cssLine, "<link rel=\"stylesheet\" href=\"{$result}\">"); break; case 'js': array_push($jsLine, "<script type=\"text/javascript\" src=\"{$result}\"></script>"); break; case 'jsScript': array_push($jsScriptLine, $result); break; default: break; } } } $css = array_merge($css, $cssLine); $js = array_merge($js, $jsLine); $jsScript = array_merge($jsScript, $jsScriptLine); } $css = implode("\n", $css); $js = implode("\n", $js); $jsScriptTxt = ""; if (count($jsScript) > 0) { $jsScriptTxt = "<script type=\"text/javascript\">(function(d){var wf=d.createElement('script'),s=d.scripts[0];wf.async=true;"; foreach ($jsScript as $line) { $jsScriptTxt .= "wf.src='" . addcslashes($line, "'") . "';s.parentNode.insertBefore(wf,s);"; } $jsScriptTxt .= "})(document);</script>"; } echo "$css $js $jsScriptTxt"; } } function getmonth($month) { if($month[0] == '0'){ $month = ltrim ( $month, '0' ); } $list = array(); $list['1'] = "Styczeń"; $list['2'] = "Luty"; $list['3'] = "Marzec"; $list['4'] = "Kwiecień"; $list['5'] = "Maj"; $list['6'] = "Czerwiec"; $list['7'] = "Lipiec"; $list['8'] = "Sierpień"; $list['9'] = "Wrzesień"; $list['10'] = "Październik"; $list['11'] = "Listopad"; $list['12'] = "Grudzień"; return $list[$month]; } class view { function makecatlink($id,$nazwa,$group) { if($group != "") { $nazwa = $this->nopolishchars($nazwa); $link = $id.",".$group.",museum,".$nazwa.".html"; } else { $nazwa = $this->nopolishchars($nazwa); $link = $id.",museum,".$nazwa.".html"; } return $link; } function makeprolink($id,$nazwa,$group,$pro) { if($group != "") $link = $id.",".$group.",".$pro.",museum,".$nazwa.".html"; else $link = $id.",0,".$pro.",museum,".$nazwa.".html"; return $link; } function makelink($tekst, $id, $flink, $prze, $group, $month, $year) { $link = ''; if($prze != '') $link = $prze; else if( $flink=='katalog') $link = "oferta.html"; else if( ($tekst == 0 || $tekst =="" ) && $group == '' && $flink=='aktualnosci') $link = "aktualnosci.html"; else if( ($tekst == 0 || $tekst =="" ) && $group == '' && $flink=='galerie') $link = "galerie.html"; else if( ($tekst == 0 || $tekst =="" ) && $group!= '') $link = "index.php?m=".$id."&g=".$group; else if($tekst == 0 || $tekst =="") $link = "index.php?m=".$id; else if($flink == '' && $group != '') $link = "index.php?s=".$tekst."&m=".$id."&g=".$group; else if($flink == '') $link = "index.php?s=".$tekst."&m=".$id; else if($flink != '' && $group != '') $link = $group.",".$tekst.",".$id.",".$flink.".html"; else $link = $tekst.",".$id.",".$flink.".html"; return $link; } function checkactive($nazwa, $active, $lang, $style) { $nazwa = strtolower($nazwa); $active = strtolower($active); //echo strtolower($this->getname2($_GET['g'],$lang)); //echo $nazwa."< >".$active."< >".strtolower($this->getname2($_GET['g'],$lang))."<br/>"; // echo strtolower($this->getname2($_GET['g'],$lang)); // if($active == $nazwa && !isset ($_GET['g'])) if($active == $nazwa) return $style; else if(isset ($_GET['g']) && $active!='oferta' && $nazwa==strtolower($this->getname2($_GET['g'],$lang))) return $style; } function checkmenu($id, $okruszki) { for($i = 0; $i < count($okruszki); ++$i) { if($id == $okruszki[$i]) return true; } return false; } public function activeMenu($id,$tab){ if(count($tab) >0) for($i =0; $i<count($tab); ++$i) { if($id == $tab[$i]){ return true; break; } } } function nopolishchars($in) { $ogonki = array("ę", "ó", "ą", "ś", "ł", "ż", "ź", "ć", "ń", "Ę", "Ó", "Ą", "Ś", "Ł", "Ż", "Ź", "Ć", "Ń", " ", ".","-",","); $bez_ogonkow = array("e", "o", "a", "s", "l", "z", "z", "c", "n", "E", "O", "A", "S", "L", "Z", "Z", "C", "N", "_","","_","_"); $out = str_replace($ogonki, $bez_ogonkow, $in); return $out; } function getname2($id, $lang){ $nazwa=''; $id_menu = $id; $zapytanie ="SELECT `nazwa` FROM menu$lang WHERE id='$id_menu'"; $result = mysql_query($zapytanie)or die(mysql_error()); while($result_oferta = mysql_fetch_array($result)) { $nazwa = $result_oferta[0]; } return $nazwa; } } ?>
[-] paginator.php
[edit]
[+]
..
[-] form.php
[edit]
[-] page-multi.php
[edit]
[-] header.php
[edit]
[-] top.php
[edit]
[-] form-send.php
[edit]
[+]
css
[-] category.php
[edit]
[-] home.php
[edit]
[-] footer.php
[edit]
[-] page.php
[edit]
[-] news.php
[edit]
[-] funkcje.php
[edit]
[-] includes.php
[edit]
[+]
scss
[-] ajax_more.php
[edit]
[-] begin.php
[edit]
[-] product.php
[edit]