public function Search($file) { global $APPLICATION, $USER; if ($this->maxResultCount && count($this->Result) >= $this->maxResultCount) { return "stop"; } if ($this->bSkip) { if ($file == $this->Params['lastPath']) { $this->bSkip = false; } else { return; } // Files was handled earlier } $io = CBXVirtualIo::GetInstance(); $bIsDir = $io->DirectoryExists($file); $replFileCount = 0; if ($bIsDir && !$this->Params['bDirsToo']) { return; } $entity = $bIsDir ? $io->GetDirectory($file) : $io->GetFile($file); $path = CFilemanUtils::TrimPath($file, $this->docRoot); $arPath = array($this->Params['site'], $path); // Check access if (!$USER->CanDoFileOperation('fm_view_file', $arPath)) { return; } $name = CFileman::GetFileName($file); // Name of file or dir // Check filename if ($this->Params['fileName'] != "") { if (!$this->Params['bCaseSens']) { $name = strtolower($name); $this->Params['fileName'] = strtolower($this->Params['fileName']); } // Simple find in file name if (strpos($this->Params['fileName'], "*") === false) { if (strpos($name, $this->Params['fileName']) === false) { return; } } else { $pattern = str_replace('.', '\\.', $this->Params['fileName']); $pattern = str_replace('/', '', $pattern); $pattern = str_replace('*', '.*', $pattern); if (!preg_match('/^' . $pattern . '$/i', $io->ExtractNameFromPath($file))) { return; } } } if (!$bIsDir) { // Check filesize $size = $entity->GetFileSize(); // Filesize limits in Kb if ($this->Params['sizeFrom'] > 0 && $size < $this->Params['sizeFrom'] * 1024 || $this->Params['sizeTo'] > 0 && $size > $this->Params['sizeTo'] * 1024) { return; } } else { $size = 0; } // Check filetime $time = $entity->GetModificationTime() + CTimeZone::GetOffset(); if ($this->Params['dateFrom'] && $time < MakeTimeStamp($this->Params['dateFrom'], CLang::GetDateFormat("FULL")) || $this->Params['dateTo'] && $time > MakeTimeStamp($this->Params['dateTo'], CLang::GetDateFormat("FULL"))) { return; } if ($this->Params['phrase'] != "") { // File size limits or it's dir or access denied if ($size > $this->maxFileOpenSize || $bIsDir || $this->bReplace && !$USER->CanDoFileOperation('fm_edit_existent_file', $arPath)) { return; } $fTmp = $io->GetFile($file); $phrase = $this->Params['phrase']; $fileContent = str_replace("\r\n", "\n", $fTmp->GetContents()); $origFileContent = $fileContent; $isPHP = CFileman::IsPHP($fileContent) || HasScriptExtension($path) || substr($name, 0, 1) == "."; if (!$this->Params['bCaseSens']) { $phrase = strtolower($phrase); $fileContent = strtolower($fileContent); } $I_PCRE_MODIFIER = $this->Params['bCaseSens'] ? '' : 'i'; // TODO: Add check Entire word //$this->Params['entire'] if (strpos($fileContent, $phrase) === false) { return; } if ($this->bReplace) { if ($isPHP && !$USER->CanDoOperation('edit_php')) { return; } // User can't write PHP files $pattern = '/' . preg_quote($this->Params['phrase'], '/') . '/' . $I_PCRE_MODIFIER . BX_UTF_PCRE_MODIFIER; $res = array(); preg_match_all($pattern, $origFileContent, $res); $origFileContent = preg_replace($pattern, $this->Params['replacePhrase'], $origFileContent); $replFileCount = count($res[0]); $APPLICATION->SaveFileContent($file, $origFileContent); } else { if ($isPHP && !($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', $arPath))) { return; } // User can't read PHP files $pattern = '/' . preg_quote($this->Params['phrase'], '/') . '/' . $I_PCRE_MODIFIER . BX_UTF_PCRE_MODIFIER; // Only for LPA. All php fragments will be cutted off if ($USER->CanDoFileOperation('fm_lpa', $arPath) && !$USER->CanDoOperation('edit_php')) { $origFileContent = CMain::ProcessLPA($origFileContent, ''); } $res = array(); preg_match_all($pattern, $origFileContent, $res); $replFileCount = count($res[0]); } } $this->Result[] = array('path' => $path, 'size' => $size, 'b_dir' => $bIsDir, 'time' => $time, 'str_date' => date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL")), $time), 'str_size' => $bIsDir ? "" : CFile::FormatSize($size), 'type_src' => "/bitrix/images/fileman/types/" . ($bIsDir ? "folder" : CFileMan::GetFileTypeEx($file)) . ".gif", 'repl_count' => $replFileCount); }
$new_filesrc .= $arPHP[$n][2]; } else { $new_filesrc .= '#PHP' . str_pad(++$php_count, 4, "0", STR_PAD_LEFT) . '#'; } } $new_filesrc .= substr($filesrc, $end); $filesrc = $new_filesrc; } } $bEditProps = strlen($res["PROLOG"]) > 0; $title = $res["TITLE"]; $page_properties = $res["PROPERTIES"]; } else { $filesrc = $filesrc_tmp; } if ((CFileman::IsPHP($filesrc) || $isScriptExt) && !($USER->CanDoOperation('edit_php') || $limit_php_access)) { $strWarning = GetMessage("FILEMAN_FILEEDIT_CHANGE_ACCESS"); } } elseif ($prop_edit == "Y") { $bEditProps = true; } if ($bEdit) { $APPLICATION->SetTitle(GetMessage("FILEMAN_FILEEDIT_PAGE_TITLE") . " \"" . htmlspecialcharsbx($arParsedPath["LAST"]) . "\""); } else { $APPLICATION->SetTitle(GetMessage("FILEMAN_NEWFILEEDIT_TITLE")); } $aTabs = array(); $aTabs[] = array("DIV" => "edit1", "TAB" => GetMessage("FILEMAN_H_EDIT_TAB1"), "ICON" => "main_user_edit", "TITLE" => GetMessage("FILEMAN_H_EDIT_TAB2")); if ($bEditProps) { $aTabs[] = array("DIV" => "edit2", "TAB" => GetMessage("FILEMAN_H_EDIT_RTAB2"), "ICON" => "main_user_edit", "TITLE" => GetMessage("FILEMAN_H_EDIT_TAB2_TITLE")); }
if (isset($_GET['target']) && check_freetrix_sessid()) { switch ($_GET['target']) { case "load": CSnippets::LoadList(array( 'template' => $APPLICATION->UnJSEscape($_GET["templateID"]), 'bClearCache' => isset($_GET['clear_snippets_cache']) && $_GET['clear_snippets_cache'] == 'Y', )); break; case "add": case "edit": CUtil::JSPostUnEscape(); $code = isset($_REQUEST['code']) ? $_REQUEST['code'] : ''; if (CFileman::IsPHP($code) && !$USER->CanDoOperation('edit_php')) return $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); CSnippets::Edit(array( 'bNew' => $_REQUEST['target'] == 'add', 'name' => $_REQUEST['name'], 'path' => $_REQUEST['target'] == 'add' && isset($_REQUEST['path']) ? $_REQUEST['path'] : false, 'template' => $_REQUEST['templateID'], 'site' => $_REQUEST['site'], 'title' => isset($_REQUEST['title']) ? $_REQUEST['title'] : '', 'description' => isset($_REQUEST['description']) ? $_REQUEST['description'] : '', 'code' => $code, 'thumb' => isset($_REQUEST['thumb']) ? $_REQUEST['thumb'] : false, 'location' => isset($_REQUEST["location"]) ? $_REQUEST["location"] : false, 'newGroup' => isset($_REQUEST["new_group"]) ? $_REQUEST["new_group"] : false ));