function ParseFileContent($filesrc, $params = array()) { ///////////////////////////////////// // Parse prolog, epilog, title ///////////////////////////////////// $filesrc = trim($filesrc); $prolog = $epilog = ''; $php_doubleq = false; $php_singleq = false; $php_comment = false; $php_star_comment = false; $php_line_comment = false; $php_st = "<" . "?"; $php_ed = "?" . ">"; if ($params["use_php_parser"] && substr($filesrc, 0, 2) == $php_st) { $phpChunks = PHPParser::getPhpChunks($filesrc); if (!empty($phpChunks)) { $prolog = $phpChunks[0]; $filesrc = substr($filesrc, strlen($prolog)); } } elseif (substr($filesrc, 0, 2) == $php_st) { $fl = strlen($filesrc); $p = 2; while ($p < $fl) { $ch2 = substr($filesrc, $p, 2); $ch1 = substr($ch2, 0, 1); if ($ch2 == $php_ed && !$php_doubleq && !$php_singleq && !$php_star_comment) { $p += 2; break; } elseif (!$php_comment && $ch2 == "//" && !$php_doubleq && !$php_singleq) { $php_comment = $php_line_comment = true; $p++; } elseif ($php_line_comment && ($ch1 == "\n" || $ch1 == "\r" || $ch2 == "?>")) { $php_comment = $php_line_comment = false; } elseif (!$php_comment && $ch2 == "/*" && !$php_doubleq && !$php_singleq) { $php_comment = $php_star_comment = true; $p++; } elseif ($php_star_comment && $ch2 == "*/") { $php_comment = $php_star_comment = false; $p++; } elseif (!$php_comment) { if (($php_doubleq || $php_singleq) && $ch2 == "\\\\") { $p++; } elseif (!$php_doubleq && $ch1 == '"') { $php_doubleq = true; } elseif ($php_doubleq && $ch1 == '"' && substr($filesrc, $p - 1, 1) != '\\') { $php_doubleq = false; } elseif (!$php_doubleq) { if (!$php_singleq && $ch1 == "'") { $php_singleq = true; } elseif ($php_singleq && $ch1 == "'" && substr($filesrc, $p - 1, 1) != '\\') { $php_singleq = false; } } } $p++; } $prolog = substr($filesrc, 0, $p); $filesrc = substr($filesrc, $p); } elseif (preg_match("'(.*?<title>.*?</title>)(.*)\$'is", $filesrc, $reg)) { $prolog = $reg[1]; $filesrc = $reg[2]; } $title = PHPParser::getPageTitle($filesrc, $prolog); $arPageProps = array(); if (strlen($prolog)) { if (preg_match_all("'\\\$APPLICATION->SetPageProperty\\(([\"\\'])(.*?)(?<!\\\\)[\"\\'] *, *([\"\\'])(.*?)(?<!\\\\)[\"\\']\\);'i", $prolog, $out)) { foreach ($out[2] as $i => $m1) { $arPageProps[UnEscapePHPString($m1, $out[1][$i])] = UnEscapePHPString($out[4][$i], $out[3][$i]); } } } if (substr($filesrc, -2) == "?" . ">") { if (isset($phpChunks) && count($phpChunks) > 1) { $epilog = $phpChunks[count($phpChunks) - 1]; $filesrc = substr($filesrc, 0, -strlen($epilog)); } else { $p = strlen($filesrc) - 2; $php_start = "<" . "?"; while ($p > 0 && substr($filesrc, $p, 2) != $php_start) { $p--; } $epilog = substr($filesrc, $p); $filesrc = substr($filesrc, 0, $p); } } return array("PROLOG" => $prolog, "TITLE" => $title, "PROPERTIES" => $arPageProps, "CONTENT" => $filesrc, "EPILOG" => $epilog); }
function GetDirList($path, &$arDirs, &$arFiles, $arFilter = array(), $sort = array(), $type = "DF", $bLogical = false, $task_mode = false) { global $USER, $APPLICATION; CMain::InitPathVars($site, $path); $DOC_ROOT = CSite::GetSiteDocRoot($site); $arDirs = array(); $arFiles = array(); $exts = strtolower($arFilter["EXTENSIONS"]); $arexts = explode(",", $exts); if (isset($arFilter["TYPE"])) { $type = strtoupper($arFilter["TYPE"]); } $io = CBXVirtualIo::GetInstance(); $path = $io->CombinePath("/", $path); $abs_path = $io->CombinePath($DOC_ROOT, $path); if (!$io->DirectoryExists($abs_path)) { return false; } $date_format = CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL")); $tzOffset = CTimeZone::GetOffset(); $dir = $io->GetDirectory($abs_path); $arChildren = $dir->GetChildren(); foreach ($arChildren as $child) { $arFile = array(); if (($type == "F" || $type == "") && $child->IsDirectory()) { continue; } if (($type == "D" || $type == "") && !$child->IsDirectory()) { continue; } $file = $child->GetName(); if ($bLogical) { if ($child->IsDirectory()) { $sSectionName = ""; $fsn = $io->CombinePath($abs_path, $file, ".section.php"); if (!$io->FileExists($fsn)) { continue; } include $io->GetPhysicalName($fsn); $arFile["LOGIC_NAME"] = $sSectionName; } else { if (CFileMan::GetFileTypeEx($file) != "php") { continue; } if ($file == '.section.php') { continue; } if (!preg_match('/^\\.(.*)?\\.menu\\.(php|html|php3|php4|php5|php6|phtml)$/', $file, $regs)) { $f = $io->GetFile($abs_path . "/" . $file); $filesrc = $f->GetContents(); $title = PHPParser::getPageTitle($filesrc); if ($title === false) { continue; } $arFile["LOGIC_NAME"] = $title; } } } $arFile["PATH"] = $abs_path . "/" . $file; $arFile["ABS_PATH"] = $path . "/" . $file; $arFile["NAME"] = $file; $arPerm = $APPLICATION->GetFileAccessPermission(array($site, $path . "/" . $file), $USER->GetUserGroupArray(), $task_mode); if ($task_mode) { $arFile["PERMISSION"] = $arPerm[0]; if (count($arPerm[1]) > 0) { $arFile["PERMISSION_EX"] = $arPerm[1]; } } else { $arFile["PERMISSION"] = $arPerm; } $arFile["TIMESTAMP"] = $child->GetModificationTime() + $tzOffset; $arFile["DATE"] = date($date_format, $arFile["TIMESTAMP"]); if (isset($arFilter["TIMESTAMP_1"]) && strtotime($arFile["DATE"]) < strtotime($arFilter["TIMESTAMP_1"])) { continue; } if (isset($arFilter["TIMESTAMP_2"]) && strtotime($arFile["DATE"]) > strtotime($arFilter["TIMESTAMP_2"])) { continue; } if (is_set($arFilter, "MIN_PERMISSION") && $arFile["PERMISSION"] < $arFilter["MIN_PERMISSION"] && !$task_mode) { continue; } if (!$child->IsDirectory() && $arFile["PERMISSION"] <= "R" && !$task_mode) { continue; } if ($bLogical) { if (strlen($arFilter["NAME"]) > 0 && strpos($arFile["LOGIC_NAME"], $arFilter["NAME"]) === false) { continue; } } else { if (strlen($arFilter["NAME"]) > 0 && strpos($arFile["NAME"], $arFilter["NAME"]) === false) { continue; } } //if(strlen($arFilter["NAME"])>0 && strpos($arFile["NAME"], $arFilter["NAME"])===false) // continue; if (substr($arFile["ABS_PATH"], 0, strlen(BX_ROOT . "/modules")) == BX_ROOT . "/modules" && !$USER->CanDoOperation('edit_php') && !$task_mode) { continue; } if ($arFile["PERMISSION"] == "U" && !$task_mode) { $ftype = GetFileType($arFile["NAME"]); if ($ftype != "SOURCE" && $ftype != "IMAGE" && $ftype != "UNKNOWN") { continue; } if (substr($arFile["NAME"], 0, 1) == ".") { continue; } } if ($child->IsDirectory()) { $arFile["SIZE"] = 0; $arFile["TYPE"] = "D"; $arDirs[] = $arFile; } else { if ($exts != "") { if (!in_array(strtolower(substr($file, bxstrrpos($file, ".") + 1)), $arexts)) { continue; } } $arFile["TYPE"] = "F"; $arFile["SIZE"] = $child->GetFileSize(); $arFiles[] = $arFile; } } if (is_array($sort) && count($sort) > 0) { $by = key($sort); $order = strtolower($sort[$by]); $by = strtolower($by); if ($order != "desc") { $order = "asc"; } if ($by != "size" && $by != "timestamp") { $by = "name"; } usort($arDirs, array("_FilesCmp", "cmp_" . $by . "_" . $order)); usort($arFiles, array("_FilesCmp", "cmp_" . $by . "_" . $order)); } return null; }