function __struct_get_file_info($abs_path, $file) { static $arTextExt = array("php", "htm", "html"); $io = CBXVirtualIo::GetInstance(); $arFile = array("file"=>$file, "name"=>""); if($io->DirectoryExists($abs_path."/".$file)) { $arFile["type"] = "D"; if($io->FileExists($abs_path."/".$file."/.section.php")) { $sSectionName = ""; $arDirProperties = array(); include($io->GetPhysicalName($abs_path."/".$file."/.section.php")); $arFile["name"] = $sSectionName; $arFile["properties"] = $arDirProperties; } } else { $arFile["type"] = "F"; if(in_array(GetFileExtension($file), $arTextExt)) { $f = $io->GetFile($abs_path."/".$file); $sContent = $f->GetContents(); $arContent = ParseFileContent($sContent); $arFile["name"] = CUtil::ConvertToLangCharset($arContent["TITLE"]); $arFile["properties"] = $arContent["PROPERTIES"]; } } if($GLOBALS['arOptions']['show_file_info'] == true) { if ($io->DirectoryExists($abs_path."/".$file)) { $f = $io->GetDirectory($abs_path."/".$file); $arFile["time"] = $f->GetModificationTime(); } else { $f = $io->GetFile($abs_path."/".$file); $arFile["time"] = $f->GetModificationTime(); $arFile["size"] = $f->GetFileSize(); } } return $arFile; }
public static function OnChangeFile($path, $site) { global $BX_WORKFLOW_PUBLISHED_PATH, $BX_WORKFLOW_PUBLISHED_SITE; if ($BX_WORKFLOW_PUBLISHED_PATH == $path && $BX_WORKFLOW_PUBLISHED_SITE == $site) { return; } $err_mess = CWorkflow::err_mess() . "<br>Function: OnChangeFile<br>Line: "; global $DB, $USER, $APPLICATION; $HISTORY_SIMPLE_EDITING = COption::GetOptionString("workflow", "HISTORY_SIMPLE_EDITING", "N"); if ($HISTORY_SIMPLE_EDITING == "Y") { $HISTORY_COPIES = intval(COption::GetOptionString("workflow", "HISTORY_COPIES", "10")); CWorkflow::CleanUpHistoryCopies_SE($path, $HISTORY_COPIES - 1); if ($HISTORY_COPIES > 0) { $DOC_ROOT = CSite::GetSiteDocRoot($site); $filesrc = $APPLICATION->GetFileContent($DOC_ROOT . $path); $arContent = ParseFileContent($filesrc); $TITLE = $arContent["TITLE"]; $BODY = $arContent["CONTENT"]; $arFields = array("DOCUMENT_ID" => 0, "MODIFIED_BY" => $USER->GetID(), "TITLE" => $TITLE, "FILENAME" => $path, "SITE_ID" => $site, "BODY" => $BODY, "BODY_TYPE" => "html", "STATUS_ID" => 1, "~TIMESTAMP_X" => $DB->CurrentTimeFunction()); $DB->Add("b_workflow_log", $arFields, array("BODY"), "workflow"); } } }
//Properties from fileman settings $arFilemanProperties = array(); if (CModule::IncludeModule("fileman") && is_callable(array("CFileMan", "GetPropstypes"))) { $arFilemanProperties = CFileMan::GetPropstypes($site); } //Properties from page $arDirProperties = array(); if ($strWarning != "" && isset($_POST["PROPERTY"]) && is_array($_POST["PROPERTY"])) { //Restore post values if error occured foreach ($_POST["PROPERTY"] as $arProperty) { if (isset($arProperty["VALUE"]) && strlen($arProperty["VALUE"]) > 0) { $arDirProperties[$arProperty["CODE"]] = $arProperty["VALUE"]; } } } else { $arPageSlice = ParseFileContent($fileContent); $arDirProperties = $arPageSlice["PROPERTIES"]; } //All file properties. Includes properties from root folders $arInheritProperties = $APPLICATION->GetDirPropertyList(array($site, $path)); if ($arInheritProperties === false) { $arInheritProperties = array(); } //Tags if (!$createNewFolder && IsModuleInstalled("search")) { $tagPropertyCode = COption::GetOptionString("search", "page_tag_property", "tags"); unset($arFilemanProperties[$tagPropertyCode]); unset($arDirProperties[$tagPropertyCode]); unset($arInheritProperties[strtoupper($tagPropertyCode)]); } $bSearchExists = isset($tagPropertyCode) && CModule::IncludeModule("search");
$get_content = "Y"; } elseif (strlen($template) > 0) { for ($i = 0; $i < count($arTemplates); $i++) { if ($arTemplates[$i]["file"] == $template) { $filesrc = GetTemplateContent($arTemplates[$i]["file"]); $arContent = ParseFileContent($filesrc); $str_TITLE = $arContent["TITLE"]; $str_BODY = $arContent["CONTENT"]; $get_content = "Y"; break; } } } if ($get_content != "Y") { $filesrc = GetTemplateContent($arTemplates[0]["file"]); $arContent = ParseFileContent($filesrc); $str_TITLE = $arContent["TITLE"]; $str_BODY = $arContent["CONTENT"]; } $str_FILENAME = strlen($fname) ? htmlspecialcharsbx($fname) : "/untitled.php"; $str_SITE_ID = htmlspecialcharsbx($site); $str_BODY_TYPE = "html"; $str_TITLE = htmlspecialcharsbx($str_TITLE); } else { $doc_files = CWorkflow::GetFileList($ID); while ($zr = $doc_files->GetNext()) { $arDocFiles[] = $zr; } $str_BODY = htmlspecialcharsback($str_BODY); } if ($message) {
function ParseFileContent($filesrc, $bCheckProlog = false) { $res = ParseFileContent($filesrc); if ($bCheckProlog) { $prolog = trim(strtolower($res['PROLOG'])); if (strlen($prolog) > 0 && strpos($prolog, "prolog_before") === false && strpos($prolog, 'bitrix/header.php') === false && strpos($prolog, '$application->settitle') === false && strpos($prolog, '$application->setpageproperty') === false) { $res['CONTENT'] = $res['PROLOG'] . "\n" . $res['CONTENT']; $res['PROLOG'] = ''; } $epilog = trim(strtolower($res['EPILOG'])); if (strlen($epilog) > 0 && strpos($epilog, 'bitrix/footer.php') === false && strpos($epilog, 'epilog.php') === false) { $res['CONTENT'] = $res['CONTENT'] . "\n" . $res['EPILOG']; $res['EPILOG'] = ''; } } return $res; }
function ReindexFile($path, $SEARCH_SESS_ID="") { global $APPLICATION; $io = CBXVirtualIo::GetInstance(); $DB = CDatabase::GetModuleConnection('search'); if(!is_array($path)) return 0; $file_doc_root = CSite::GetSiteDocRoot($path[0]); $file_rel_path = $path[1]; $file_abs_path = preg_replace("#[\\\\\\/]+#", "/", $file_doc_root."/".$file_rel_path); $f = $io->GetFile($file_abs_path); if(!$f->IsExists() || !$f->IsReadable()) return 0; if(!CSearch::CheckPath($file_rel_path)) return 0; $max_file_size = COption::GetOptionInt("search", "max_file_size", 0); if( $max_file_size > 0 && $f->GetFileSize() > ($max_file_size*1024) ) return 0; $file_site = ""; $rsSites = CSite::GetList($by = "lendir", $order = "desc"); while($arSite = $rsSites->Fetch()) { $site_path = preg_replace("#[\\\\\\/]+#", "/", $arSite["ABS_DOC_ROOT"]."/".$arSite["DIR"]."/"); if(strpos($file_abs_path, $site_path) === 0) { $file_site = $arSite["ID"]; break; } } if($file_site == "") return 0; $item_id = $file_site."|".$file_rel_path; if (strlen($item_id) > 255) return 0; if(strlen($SEARCH_SESS_ID) > 0) { $DATE_CHANGE = $DB->CharToDateFunction( FormatDate( $DB->DateFormatToPHP(CLang::GetDateFormat("FULL")), $f->GetModificationTime() + CTimeZone::GetOffset() ) ); $strSql = " SELECT ID FROM b_search_content WHERE MODULE_ID = 'main' AND ITEM_ID = '".$DB->ForSQL($item_id)."' AND DATE_CHANGE = ".$DATE_CHANGE." "; $r = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if($arR = $r->Fetch()) { $strSql = "UPDATE b_search_content SET UPD='".$DB->ForSQL($SEARCH_SESS_ID)."' WHERE ID = ".$arR["ID"]; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); return $arR["ID"]; } } $arrFile = false; foreach(GetModuleEvents("search", "OnSearchGetFileContent", true) as $arEvent) { if($arrFile = ExecuteModuleEventEx($arEvent, array($file_abs_path, $SEARCH_SESS_ID))) break; } if(!is_array($arrFile)) { $sFile = $APPLICATION->GetFileContent($file_abs_path); $sHeadEndPos = strpos($sFile, "</head>"); if($sHeadEndPos===false) $sHeadEndPos = strpos($sFile, "</HEAD>"); if($sHeadEndPos!==false) { //html header detected try to get document charset $arMetaMatch = array(); if(preg_match("/<(meta)\\s+([^>]*)(content)\\s*=\\s*(['\"]).*?(charset)\\s*=\\s*(.*?)(\\4)/is", substr($sFile, 0, $sHeadEndPos), $arMetaMatch)) { $doc_charset = $arMetaMatch[6]; if(defined("BX_UTF")) { if(strtoupper($doc_charset) != "UTF-8") $sFile = $APPLICATION->ConvertCharset($sFile, $doc_charset, "UTF-8"); } } } $arrFile = ParseFileContent($sFile); } $title = CSearch::KillTags(trim($arrFile["TITLE"])); if(strlen($title) <= 0) return 0; //strip out all the tags $filesrc = CSearch::KillTags($arrFile["CONTENT"]); $arGroups = CSearch::GetGroupCached(); $arGPerm = Array(); foreach($arGroups as $group_id) { $p = $APPLICATION->GetFileAccessPermission(Array($file_site, $file_rel_path), Array($group_id)); if($p >= "R") { $arGPerm[] = $group_id; if($group_id==2) break; } } $tags = COption::GetOptionString("search", "page_tag_property"); //save to database $ID = CSearch::Index("main", $item_id, Array( "SITE_ID" => $file_site, "DATE_CHANGE" => date("d.m.Y H:i:s", $f->GetModificationTime()+1), "PARAM1" => "", "PARAM2" => "", "URL" => $file_rel_path, "PERMISSIONS" => $arGPerm, "TITLE" => $title, "BODY" => $filesrc, "TAGS" => array_key_exists($tags, $arrFile["PROPERTIES"])? $arrFile["PROPERTIES"][$tags]: "", ), false, $SEARCH_SESS_ID ); return $ID; }
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(); $arContent = ParseFileContent($filesrc); if ($arContent["TITLE"] === false) { continue; } $arFile["LOGIC_NAME"] = $arContent["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)); } }