PATH:
root
/
paleypartnerlib
<?php /** * Class Buffer * * Creates PHP output buffer with string processing. * By passing options to the constructor we can decide * about replacing variables by custom data, like: * - when TITLE = 5, then '{{TITLE}}' can be replaced for 5 * * When we want to use buffer, we need to initialize it like that: * $buf = new Buffer($dataArray, $callbacksArray); * * Before outputting we can switch buffer processing by setting * variable Buffer::$processBuffer ($buf->processBuffer = true | false). * True means buffer will be processed before output (and only before output/getting content) * * We can output by echo and similar to this buffer, and in * the end, we can get content to variable by Buffer::getContent * ($buf->getContent()) or flush by Buffer::outputContent * ($buf->outputContent()). Using getContent(true) or * outputContent(true) forces to close buffer. */ class Buffer { protected $data; protected $modCallbacks; public $processBuffer = true; public function __construct($data = NULL, $modCallbacks = []) { if (!$data) ob_start(); else { if (!is_array($data)) $data = [$data]; $this->data = $data; $this->modCallbacks = $modCallbacks; ob_start("self::process"); } return $this; } protected function process($buffer, $phase) { if ($this->processBuffer !== true) return $buffer; $buffer = preg_replace_callback("/{{([^}]+?)}}/", function($f) { return isset($this->data[$f[1]]) ? $this->data[$f[1]] : $f[1]; }, $buffer); if (gettype($this->modCallbacks) != "array") $this->modCallbacks = [$this->modCallbacks]; foreach ($this->modCallbacks as $callback) { if (is_callable($callback)) { $buffer = $callback($buffer, $this->data); } } return $buffer; } public function getContent($close = false) { $content = self::process(ob_get_contents(), NULL); if ($close !== false) ob_end_clean(); return $content; } public function outputContent($close = false) { ob_flush(); if ($close !== false) ob_end_clean(); } public function __destruct() { $this->outputContent(true); } } 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) { setlocale(LC_CTYPE, "pl_PL"); return iconv("UTF-8", "ASCII//TRANSLIT", $string); } public static function removePLAccents($string) { return strtr($string, ["Ą" => "A", "Ć" => "C", "Ę" => "E", "Ł" => "L", "Ń" => "N", "Ó" => "O", "Ś" => "S", "Ź" => "Z", "Ż" => "Z", "ą" => "a", "ć" => "c", "ę" => "e", "ł" => "l", "ń" => "n", "ó" => "o", "ś" => "s", "ź" => "z", "ż" => "z"]); } 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)); $link = preg_replace_callback("/( |-|_|\/|\\|){2,}/", function($ch) { return substr($ch[0], 0, 1); }, $link); if ($urlEntities) $link = rawurlencode($link); return $link; } /* OLD public static function shortenText($text, $sentences = 3, $len = 150, $stripTags = true, $tags = "<br>") { if ($stripTags === true) { $text = preg_replace("/(?:alt|title)=['\"]([^'\"]+)['\"]/ui", ">$1<a ", $text); $text = preg_replace("/<br[^>]*>|\s+|(?: )+/ui", " ", 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 shortenText($text, $sentences = 3, $words = 90, $len = 90, $strCont = "...", $stripTags = true, $tags = "<br>") { $cont = ""; if ($stripTags === true) { $text = preg_replace("/(?:alt|title)=['\"]([^'\"]+)['\"]/ui", ">$1<a ", $text); $text = preg_replace("/<br[^>]*>|\s+|(?: )+/ui", " ", strip_tags($text . " ", $tags)); } // GET SENTENCES $match = []; $match2 = []; if (!isset($sentences) || intval($sentences) < 1) $sentences = 1; else $sentences = intval($sentences); preg_match("/([^\.\?!:;$]+?[\.\?!]{1,3}|[:;$]){0," . ($sentences + 1) . "}/ui", $text, $match2); preg_match("/([^\.\?!:;$]+?[\.\?!]{1,3}|[:;$]){0,{$sentences}}/ui", $text, $match); if (isset($match2[0]) && isset($match[0]) && mb_strlen($match2[0]) > mb_strlen($match[0])) { $cont = $strCont; $text = mb_substr($match[0], 0, -1); } $text = rtrim($text); if (!isset($words) || intval($words) < 1) $words = 1; else $words = intval($words); preg_match_all("/([a-z0-9_ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+)/ui", $text, $match, PREG_OFFSET_CAPTURE); if (isset($match[1]) && count($match[1]) > $words) { if (!isset($match[1][$words - 1])) $words = count($match[1]) - 1; $strlen = $match[1][$words - 1][1] + mb_strlen($match[1][$words - 1][0]); $text = mb_substr($text, 0, $strlen + 1); $cont = $strCont; } $text = rtrim($text); if (mb_strlen($text) > $len) { $text = rtrim(mb_substr($text, 0, $len - mb_strlen($strCont))); $cont = $strCont; } $text .= $cont; return $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) { $htmlAttrSizes = [1 => 10, 2 => 13, 3 => 16, 4 => 18, 5 => 24, 6 => 32, 7 => 48]; /* $value[$tytulyCol] = preg_replace_callback("/( ?)size=['\"]?([1-7])['\"]?([ >])/i", function($f) use ($htmlAttrSizes) { return $f[1] . "style=\"font-size: " . $htmlAttrSizes[intval($f[2])] / 16 . "rem\"" . $f[3]; }, $value[$tytulyCol]); */ $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("/( ?)size=['\"]?([1-7])['\"]?([ >])/i", function($f) use ($htmlAttrSizes) { return $f[1] . "style=\"font-size: " . $htmlAttrSizes[intval($f[2])] / 16 . "rem\"" . $f[3]; }, $value[$tekstyCol]); */ $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) { if ($mVal[$options['id']] == $mVal[$options['parent']]) continue; $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) { if ($mVal[$options['parent']] > 0 && !isset($menu[$mVal[$options['parent']]])) { unset($menu[$mKey]); continue; } $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); } } if (defined("LANG_IN_LINK")) { if (LANG_IN_LINK !== true && $lang == "") { $lang_set = explode(",", LANGS); $lang = $lang_set[0]; } if ($lang != "") $menu[$mKey]['link'] = "{$lang}/{$menu[$mKey]['link']}"; } } return $menu; $tmp = []; foreach ($menu as $mKey => $mVal) array_push($tmp, $mVal); return $tmp; } // public static function buildMenuIDsTree($menuItem, $allMenu, $options = [], $currentLevel = 1) { // $options = array_merge([ // "id" => "id", // "parent" => "rodzic", // "level" => "level", // "enabled" => "pokaz", // "maxLevel" => INF // ], $options); // if (isset($menuItem[$options["level"]])) $currentLevel = $menuItem[$options["level"]]; // $startLevel = $currentLevel; // if ($currentLevel > $options["maxLevel"]) return NULL; // $arr = NULL; // foreach ($allMenu as $aK => $aV) { // if ($aV[$options["level"]] < $startLevel) continue; // if ($aV[$options["enabled"]] != 1) continue; // if ($aV[$options["parent"]] == $menuItem[$options["id"]]) { // if ($arr != NULL && gettype($arr) != "array") $arr = [$arr]; // if (gettype($arr) == "array") array_push($arr, $aV[$options["id"]]); // if ($arr == NULL) $arr = $aV[$options["id"]]; // $arr2 = self::buildMenuIDsTree($aV, $allMenu, $options, $aV[$options["level"]]); // if ($arr2 != NULL) { // if (gettype($arr) != "array") $arr = [$arr]; // array_push($arr, $arr2); // } // } // } // return $arr; // } public static function buildMenuIDsTree($list, $r = ["rodzic" => 0], $maxLevel = INF, $currentLevel = 1) { if ($currentLevel > $maxLevel) return []; if (gettype($r) != "array") $r = [$r => 0]; $col = array_keys($r)[0]; $r = array_merge(["pokaz" => 1], $r); $arr = []; foreach ($list as $lK => $lV) { $skip = false; // if (isset($lV['pokaz']) && $lV['pokaz'] != 1 && $lV[$col] > 0) continue; foreach ($r as $rK => $rV) { if (isset($lV[$rK]) && $lV[$rK] != $rV) { $skip = true; break; } } if ($skip === true) continue; $arr[$lV['id']] = self::buildMenuIDsTree($list, array_merge($r, [$col => $lV['id']]), $maxLevel, $currentLevel + 1); } return $arr; } public static function renderMenuTree($allMenu, $menuIDsTree, $options = [], $htmlTemplate = [], $currentLevel = 1) { $options = array_merge([ "id" => "id", "parent" => "rodzic", "maxLevel" => INF, "emptyTags" => true ], $options); if ($currentLevel > $options["maxLevel"]) return ""; if (!isset($menuIDsTree) || gettype($menuIDsTree) != "array") return ""; $htmlOriginalTemplate = [ "listHTML" => "<ul{#listActive#}>{{itemHTML}}</ul>", "itemHTML" => "<li{#itemActive#}><a href=\"{%link%}\">{%nazwa%}</a>{{listHTML}}</li>" ]; $htmlOriginalTemplate = $htmlTemplate = array_merge($htmlOriginalTemplate, $htmlTemplate); if (isset($htmlTemplate["level"]) && isset($htmlTemplate["level"][$currentLevel])) $htmlTemplate = array_merge($htmlTemplate, $htmlTemplate["level"][$currentLevel]); $html = ""; foreach ($menuIDsTree as $mK => $mV) { $compiledTemplate = $htmlTemplate; foreach ($compiledTemplate as $cK => &$cV) { if (is_callable($cV)) $compiledTemplate[$cK] = $cV($allMenu, isset($options["parentID"]) ? $options["parentID"] : -1, $mK, $mV, $currentLevel, $compiledTemplate); } if (isset($compiledTemplate["level"])) { foreach ($compiledTemplate["level"] as $l) { foreach ($l as $cK => &$cV) { if (is_callable($cV)) $l[$cK] = $cV($allMenu, isset($options["parentID"]) ? $options["parentID"] : -1, $mK, $mV, $currentLevel, $compiledTemplate); } } } foreach ($compiledTemplate as $cK => &$cV) { if (strtolower($cK) == "level") continue; $compiledTemplate[$cK] = str_replace(["{!CURRENT_ID!}", "{!CURRENT_LEVEL!}"], [$mK, $currentLevel], $compiledTemplate[$cK]); $compiledTemplate[$cK] = preg_replace_callback("/{#([^%]+)#(|[^}]+)?}/", function($f) use ($allMenu, $mK, $options, $compiledTemplate) { if (!isset($compiledTemplate[$f[1]])) { if (isset($options["emptyTags"]) && $options["emptyTags"] == true) return ""; else return $f[1]; } else { if (isset($f[2]) && $f[2] != "") { $f[2] = substr($f[2], 1); switch ($f[2]) { case "mb_strtolower": case "strtolower": case "lower": return mb_strtolower($compiledTemplate[$f[1]]); case "mb_strtoupper": case "strtoupper": case "upper": return mb_strtoupper($compiledTemplate[$f[1]]); default: return $compiledTemplate[$f[1]]; } return $compiledTemplate[$f[1]]; } else return $compiledTemplate[$f[1]]; } }, $compiledTemplate[$cK]); $compiledTemplate[$cK] = preg_replace_callback("/{%([^%]+)%(|[^}]+)?}/", function($f) use ($allMenu, $mK, $options, $compiledTemplate) { if (!isset($allMenu[$mK][$f[1]])) { if (isset($options["emptyTags"]) && $options["emptyTags"] == true) return ""; else return $f[1]; } else { if (isset($f[2]) && $f[2] != "") { $f[2] = substr($f[2], 1); switch ($f[2]) { case "mb_strtolower": case "strtolower": case "lower": return mb_strtolower($allMenu[$mK][$f[1]]); case "mb_strtoupper": case "strtoupper": case "upper": return mb_strtoupper($allMenu[$mK][$f[1]]); default: return $allMenu[$mK][$f[1]]; } return $allMenu[$mK][$f[1]]; } else return $allMenu[$mK][$f[1]]; } }, $compiledTemplate[$cK]); } $compile = $compiledTemplate["itemHTML"]; if (count($mV) > 0) { $t = self::renderMenuTree($allMenu, $mV, array_merge($options, ["parentID" => $mK]), $htmlOriginalTemplate, $currentLevel + 1); // $t = str_replace("{{itemHTML}}", $t, $compiledTemplate["listHTML"]); } else { $t = ""; } $compile = str_replace("{{listHTML}}", $t, $compile); // echo "<pre>{$currentLevel} | "; // ob_start(); // var_dump($htmlTemplate["level"]); // $x = ob_get_clean(); // echo htmlentities($x); // echo "</pre><br>"; // echo "{$mK} | " . htmlentities($compile) . " | " . count($mV) . " | " . htmlentities($t) . "<br>"; $html .= $compile; } $mK = array_keys($menuIDsTree)[0]; $compiledTemplate = $htmlTemplate; foreach ($compiledTemplate as $cK => &$cV) { if (is_callable($cV)) $compiledTemplate[$cK] = $cV($allMenu, isset($options["parentID"]) ? $options["parentID"] : -1, $mK, $mV, $currentLevel, $compiledTemplate); } if (isset($compiledTemplate["level"])) { foreach ($compiledTemplate["level"] as $l) { foreach ($l as $cK => &$cV) { if (is_callable($cV)) $l[$cK] = $cV($allMenu, isset($options["parentID"]) ? $options["parentID"] : -1, $mK, $mV, $currentLevel, $compiledTemplate); } } } foreach ($compiledTemplate as $cK => &$cV) { if (strtolower($cK) == "level") continue; $compiledTemplate[$cK] = str_replace(["{!CURRENT_ID!}", "{!CURRENT_LEVEL!}"], [$mK, $currentLevel], $compiledTemplate[$cK]); $compiledTemplate[$cK] = preg_replace_callback("/{#([^%]+)#(|[^}]+)?}/", function($f) use ($allMenu, $mK, $options, $compiledTemplate) { if (!isset($compiledTemplate[$f[1]])) { if (isset($options["emptyTags"]) && $options["emptyTags"] == true) return ""; else return $f[1]; } else { if (isset($f[2]) && $f[2] != "") { $f[2] = substr($f[2], 1); switch ($f[2]) { case "mb_strtolower": case "strtolower": case "lower": return mb_strtolower($compiledTemplate[$f[1]]); case "mb_strtoupper": case "strtoupper": case "upper": return mb_strtoupper($compiledTemplate[$f[1]]); default: return $compiledTemplate[$f[1]]; } return $compiledTemplate[$f[1]]; } else return $compiledTemplate[$f[1]]; } }, $compiledTemplate[$cK]); $compiledTemplate[$cK] = preg_replace_callback("/{%([^%]+)%(|[^}]+)?}/", function($f) use ($allMenu, $mK, $options, $compiledTemplate) { if (!isset($allMenu[$mK][$f[1]])) { if (isset($options["emptyTags"]) && $options["emptyTags"] == true) return ""; else return $f[1]; } else { if (isset($f[2]) && $f[2] != "") { $f[2] = substr($f[2], 1); switch ($f[2]) { case "mb_strtolower": case "strtolower": case "lower": return mb_strtolower($allMenu[$mK][$f[1]]); case "mb_strtoupper": case "strtoupper": case "upper": return mb_strtoupper($allMenu[$mK][$f[1]]); default: return $allMenu[$mK][$f[1]]; } return $allMenu[$mK][$f[1]]; } else return $allMenu[$mK][$f[1]]; } }, $compiledTemplate[$cK]); } // echo "{$mK} | " . htmlentities($compiledTemplate["listHTML"]) . "<br>"; return str_replace("{{itemHTML}}", $html, $compiledTemplate["listHTML"]); // $html = $htmlCurrentTemplate["dropOpen"]; // foreach ($menuIDsTree as $mK => $mV) { // $htmlCompiledTemplate = $htmlCurrentTemplate; // foreach ($htmlCompiledTemplate as &$h) { // $h = preg_replace_callback("/{%([^%]+)%(|[^}]+)?}/", function($f) use ($allMenu, $mK) { // if (isset($allMenu[$mK][$f[1]])) { // if (isset($f[2]) && $f[2] != "") { // $f[2] = substr($f[2], 1); // switch ($f[2]) { // case "mb_strtolower": // case "strtolower": // case "lower": // return mb_strtolower($allMenu[$mK][$f[1]]); // case "mb_strtoupper": // case "strtoupper": // case "upper": // return mb_strtoupper($allMenu[$mK][$f[1]]); // default: // return $allMenu[$mK][$f[1]]; // } // return $allMenu[$mK][$f[1]]; // } else return $allMenu[$mK][$f[1]]; // } else return $f[1]; // }, $h); // } // var_dump($htmlCompiledTemplate); // if (gettype($mV) == "array" && count($mV) == 0) { // $html = substr($html, 0, strrpos( // $html, $htmlCompiledTemplate["itemClose"])); // $html .= self::renderMenuTree($allMenu, $mV, $options, $htmlTemplate, $currentLevel + 1); // $html .= $htmlCompiledTemplate["itemClose"]; // } else { // $html .= $htmlCompiledTemplate["itemOpen"]; // $html .= $htmlCompiledTemplate["itemHTML"]; // $html .= $htmlCompiledTemplate["itemClose"]; // } // } // $html .= $htmlCurrentTemplate["dropClose"]; } public static function renderMenu($menuIDsTree, $allMenu, $options = []) { $options = array_merge([ "nodeOpen" => "ul", "nodeClose" => true, "nodeInsideItem" => true, "nodeAttributes" => [], // Node Attributes can be: // a="b" c="d" // // ["a" => "b", "c" => "d"] // // function returning one of these "itemOpen" => "li", "itemClose" => true, "itemAttributes" => [] ], $options); $dom = new DOMDocument("1.0", "UTF-8"); foreach ($menuIDsTree as $mKey => $mItem) { if (gettype($mItem) != "array") { $item = $dom->createElement($options["itemOpen"]); if (is_callable($options["itemAttributes"])) $iAttr = $options["itemAttributes"]; else $iAttr = $options["itemAttributes"]; } if (gettype($iAttr) != "array") { $arr = []; preg_match_all("~(?=\S)[^'\"\s]*(?:'[^']*'[^'\"\s]*|\"[^\"]*\"[^'\"\s]*)*~", $iAttr, $arr); $arr = $arr[0]; $iAttr = []; foreach ($arr as $a) { $attr = explode("=", trim($a)); if (count($attr) == 1) $attr[1] = "{%NULL%}"; if (isset($iAttr[$attr[0]])) { $chOld = $iAttr[$attr[0]][0]; $chNew = $attr[1][0]; $attr[1] = trim($attr[1], $chNew); if ($chOld != $chNew) $attr[1] = str_replace($chOld, "\\{$chOld}", $attr[1]); $iAttr[$attr[0]] = trim($iAttr[$attr[0]], $chOld); $iAttr[$attr[0]] = str_replace($chOld, "\\{$chOld}", $iAttr[$attr[0]]); $iAttr[$attr[0]] = "{$iAttr[$attr[0]]}" . (strtolower($attr[0]) == "style" ? ";" : "") . " {$attr[1]}"; if (strtolower($attr[0]) == "style") $iAttr[$attr[0]] = preg_replace("/([;\\s])(?=\\1)|[;\\s]$/", "", $iAttr[$attr[0]]); $iAttr[$attr[0]] = "{$chOld}{$iAttr[$attr[0]]}{$chOld}"; } else $iAttr[$attr[0]] = $attr[1]; } } $strAttr = implode(" ", array_map(function($k, $i) { return "{$k}" . ($i != "{%NULL%}" ? "={$i}" : ""); }, array_keys($iAttr), array_values($iAttr))); // $strAttr = preg_replace("/(['\"])(.+?)\\1\s+(['\"])(.+?)\\3/", "$1$2 $4$1", $strAttr); echo "<pre>"; print_r($strAttr); echo "</pre>"; } } public static function menuLink($miVal = [], $lang = "") { $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); } } if (defined("LANG_IN_LINK")) { if (LANG_IN_LINK !== true && $lang == "") { $lang_set = explode(",", LANGS); $lang = $lang_set[0]; } if ($lang != "") $miVal[$mKey]['link'] = "{$lang}/{$miVal[$mKey]['link']}"; } 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 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 ]) { if (!$path || $path == "") $path = $_SERVER['PHP_SELF']; else $path = rawurldecode($path); 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); } if (!is_dir(trim($path, "/"))) { $path = substr($path, 0, strrpos(rtrim($path, "/"), "/")) . "/"; $list = @scandir("./$path"); } else $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 humanFilesize($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 pagingArray($options = []) { if (gettype($options) != "array") $options = []; $options = array_merge([ "page" => 1, "perPage" => 12, "items" => 1, "first" => true, "last" => true, // "allPages" => true, // RETURNING ALL PAGES WHEN ENABLED "pagesFromStart" => 1, "pagesFromEnd" => 1, "pagesLeftFromCenter" => 1, "pagesRightFromCenter" => 1, "separatorLeft" => true, "separatorRight" => true ], $options); if ($options['page'] < 1) $options['page'] = 1; if ($options['perPage'] < 1) $options['perPage'] = 1; if ($options['items'] < 1) $options['items'] = 1; $options['maxPages'] = ceil($options['items'] / $options['perPage']); if ($options['page'] > $options['maxPages']) $options['page'] = $options['maxPages']; if (!isset($options['allPages']) || $options['allPages'] === false) { $left = $options['page'] - $options['pagesLeftFromCenter']; if ($left < 1) $left = 1; if ($left > $options['maxPages']) $left = $options['maxPages']; $right = $options['page'] + $options['pagesRightFromCenter']; if ($right < 1) $right = 1; if ($right > $options['maxPages']) $right = $options['maxPages']; $middle = range($left, $right); $start = []; $startItems = $options['pagesFromStart'] + 1; if ($startItems > $options['maxPages']) $startItems = $options['maxPages']; $end = []; $endItems = $options['maxPages'] - $options['pagesFromEnd']; if ($endItems < 1) $endItems = 1; if (isset($options['first']) && $options['first'] !== false) $start = range(1, $startItems); if (isset($options['last']) && $options['last'] !== false) $end = range($endItems, $options['maxPages']); $pager = array_merge(array_unique(array_merge($start, $middle, $end))); if (isset($options['first']) && $options['first'] !== false && isset($options['separatorLeft']) && $options['separatorLeft'] !== false) foreach($pager as $pK => $pV) { if ($pV >= $options['page']) break; if ($pager[$pK + 1] - $pV > 1) { array_splice($pager, $pK + 1, 0, false); break; } } if (isset($options['last']) && $options['last'] !== false && isset($options['separatorRight']) && $options['separatorRight'] !== false) { $pager = array_reverse($pager); foreach($pager as $pK => $pV) { if ($pV <= $options['page']) break; if ($pV - $pager[$pK + 1] > 1) { array_splice($pager, $pK + 1, 0, false); break; } } $pager = array_reverse($pager); } } else $pager = range(1, $options['maxPages']); if (isset($options['data'])) { $arr = []; if (!isset($options['id']) || $options['id'] === false) { foreach($pager as $pK => $pV) { if ($pV !== false && isset($options['data'][$pV - 1])) array_push($arr, $options['data'][$pV - 1]); if ($pV === false) array_push($arr, false); } } else { foreach($pager as $pK => $pV) { if ($pV === false) array_push($arr, false); else foreach($options['data'] as $dK => $dV) { if (!isset($dV[$options['id']])) continue; else if ($dV[$options['id']] == $pV) { array_push($arr, $dV); break; } } } } if (count($arr) == count($pager)) $pager = $arr; } return $pager; } 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"; } public static function arraySearchKeyRecursive($array, $key) { $found = false; if (gettype($array) != "array") return $found; $found = array_key_exists($key, $array); if ($found == true) return $found; foreach ($array as $aKey => $aItem) { $found = self::arraySearchKeyRecursive($aItem, $key); if ($found == true) break; } return $found; } public static function arrayKeyChangeValueRecursive(&$array, $key, $val = NULL) { if (gettype($array) != "array") return false; if (array_key_exists($key, $array)) { $array[$key] = $val; return true; } foreach ($array as $aKey => &$aItem) { if (gettype($aItem) == "array") { if (array_key_exists($key, $aItem)) { $aItem[$key] = $val; return true; } else { self::arrayKeyChangeValueRecursive($aItem, $key, $val); } } } return false; } public static function isLeapYear($year) { return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0))); } public static function strposAll($string, $search, $caseInsensitive = false) { $arr = []; $offset = 0; if ($caseInsensitive !== false) { while (($pos = stripos($string, $search, $offset)) !== false) { array_push($arr, $pos); $offset = $pos + 1; } } else { while (($pos = strpos($string, $search, $offset)) !== false) { array_push($arr, $pos); $offset = $pos + 1; } } if (count($arr) == 0) return false; return $arr; } } 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; } } ?>
[-] _includes.php
[edit]
[+]
..
[-] connection.php
[edit]
[+]
DBService_
[-] Dokumentacja
[edit]
[-] funkcje.php
[edit]
[-] includes.php
[edit]
[-] classes.php
[edit]