function CreatePackage($PACKAGE_DIR) { if (strlen($this->LAST_ERROR) > 0) { return false; } //Add last slash if (substr($PACKAGE_DIR, -1, 1) != "/") { $PACKAGE_DIR .= "/"; } $path = $_SERVER["DOCUMENT_ROOT"] . $PACKAGE_DIR; CheckDirPath($path); if (!is_dir($path) || !is_writable($path)) { $this->LAST_ERROR = GetMessage("LEARNING_BAD_PACKAGE"); return false; } RewriteFile($path . "/res1.xml", $this->_CreateCourseToc()); RewriteFile($path . "/imsmanifest.xml", $this->CreateManifest()); //XML Resource Data foreach ($this->arItems as $res_id => $content) { RewriteFile($path . "/res" . $res_id . ".xml", $content); } //Resource $dbres_path = $path . "/dbresources/"; CheckDirPath($dbres_path); foreach ($this->arResources as $res_id => $arFiles) { $res_path = $path . "/resources/res" . $res_id . "/"; CheckDirPath($res_path); foreach ($arFiles as $arFile) { if (array_key_exists("DB", $arFile)) { $arTempFile = CFile::MakeFileArray($arFile["DB"]); if ($arTempFile && isset($arTempFile["tmp_name"])) { @copy($arTempFile["tmp_name"], $dbres_path . $arFile["ID"]); } } else { @copy($_SERVER["DOCUMENT_ROOT"] . $arFile["SRC"], $res_path . $arFile["ID"]); } } } return true; }
function MakeFileArray($path, $mimetype = false) { $io = CBXVirtualIo::GetInstance(); $arFile = array(); if (intval($path) > 0) { $res = CFile::GetByID($path); if ($ar = $res->Fetch()) { $bExternalStorage = false; foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($ar, &$arFile))) { $bExternalStorage = true; break; } } if (!$bExternalStorage) { $arFile["name"] = strlen($ar['ORIGINAL_NAME']) > 0 ? $ar['ORIGINAL_NAME'] : $ar['FILE_NAME']; $arFile["size"] = $ar['FILE_SIZE']; $arFile["type"] = $ar['CONTENT_TYPE']; $arFile["description"] = $ar['DESCRIPTION']; $arFile["tmp_name"] = $io->GetPhysicalName(preg_replace("#[\\\\\\/]+#", "/", $_SERVER['DOCUMENT_ROOT'] . '/' . COption::GetOptionString('main', 'upload_dir', 'upload') . '/' . $ar['SUBDIR'] . '/' . $ar['FILE_NAME'])); } return $arFile; } } $path = preg_replace("#(?<!:)[\\\\\\/]+#", "/", $path); if (strlen($path) == 0 || $path == "/") { return NULL; } if (preg_match("#^(http[s]?)://#", $path)) { $temp_path = ''; $bExternalStorage = false; foreach (GetModuleEvents("main", "OnMakeFileArray", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($path, &$temp_path))) { $bExternalStorage = true; break; } } if (!$bExternalStorage) { $temp_path = CFile::GetTempName('', bx_basename($path)); $ob = new CHTTP(); $ob->follow_redirect = true; if ($ob->Download($path, $temp_path)) { $arFile = CFile::MakeFileArray($temp_path); } } elseif ($temp_path) { $arFile = CFile::MakeFileArray($temp_path); } } elseif (preg_match("#^(ftp[s]?|php)://#", $path)) { if ($fp = fopen($path, "rb")) { $content = ""; while (!feof($fp)) { $content .= fgets($fp, 4096); } if (strlen($content) > 0) { $temp_path = CFile::GetTempName('', bx_basename($path)); if (RewriteFile($temp_path, $content)) { $arFile = CFile::MakeFileArray($temp_path); } } fclose($fp); } } else { if (!file_exists($path)) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . $path)) { $path = $_SERVER["DOCUMENT_ROOT"] . $path; } else { return NULL; } } if (is_dir($path)) { return NULL; } $arFile["name"] = $io->GetLogicalName(bx_basename($path)); $arFile["size"] = filesize($path); $arFile["tmp_name"] = $path; $arFile["type"] = $mimetype; if (strlen($arFile["type"]) <= 0) { $arFile["type"] = CFile::GetContentType($path, true); } } if (strlen($arFile["type"]) <= 0) { $arFile["type"] = "unknown"; } return $arFile; }
// collect all the variables and write to files while (list($fpath, $arM)=each($arTEXT)) { $strContent = ""; foreach ($arM as $M) { if (strlen($M)>0) $strContent .= "\n".$M.";"; } if (!TR_BACKUP($fpath)) { $strError .= GetMessage("TR_CREATE_BACKUP_ERROR", array('%FILE%' => $fpath))."<br>\n"; } else { if (strlen($strContent)>0) { RewriteFile($_SERVER["DOCUMENT_ROOT"].$fpath, "<?".$strContent."\n?".">"); } else { if (file_exists($_SERVER["DOCUMENT_ROOT"].$fpath)) { @chmod($_SERVER["DOCUMENT_ROOT"].$fpath, BX_FILE_PERMISSIONS); @unlink($_SERVER["DOCUMENT_ROOT"].$fpath); } } } } if (strlen($save)>0) LocalRedirect("translate_list.php?lang=".LANGUAGE_ID."&path=".$path_back."&".bitrix_sessid_get()); else LocalRedirect("translate_edit.php?lang=".LANGUAGE_ID."&file=".urlencode($file)."&show_error=".$show_error); } }
function AddAttachment($listName, $listItemID, $fileName, $attachment) { global $USER; if (!$this->__Init()) { return $this->error; } if (!($listName_original = CIntranetUtils::checkGUID($listName))) { return new CSoapFault('Data error', 'Wrong GUID - ' . $listName); } if (strlen($attachment) <= 0) { return new CSoapFault('Wrong attachment', 'Wrong attachment'); } $listName = ToUpper(CIntranetUtils::makeGUID($listName_original)); $listItemID = intval($listItemID); $dbRes = CTasks::GetByID($listItemID); if ($task = $dbRes->Fetch()) { $fileName = str_replace(array('/', '\\', '..'), '', $fileName); // minor security foreach ($task["FILES"] as $fileID) { $FILE = ToLower(basename(CFile::GetPath($fileID))); if ($FILE == ToLower($fileName)) { Header('HTTP/1.1 500 Internal Server Error'); $obDetail = new CXMLCreator('detail'); $obDetail->addChild(CXMLCreator::createTagAttributed('errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/"', 'The specified name is already in use.')); $obDetail->addChild(CXMLCreator::createTagAttributed('errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/"', '0x81020067')); return new CSoapFault('soap::Server', 'Exception of type \'Microsoft.SharePoint.SoapServer.SoapServerException\' was thrown.', $obDetail); } } $tmpFileName = CTempFile::GetFileName('sheet_happens'); RewriteFile($tmpFileName, $attachment); $arFile = CFile::MakeFileArray($tmpFileName); $arFile['name'] = basename($fileName); $arFile['MODULE_ID'] = 'tasks'; $arValue = array($FILE_ID = CFile::SaveFile($arFile, 'outlook/Lists/' . $listItemID)); CTasks::AddFiles($task["ID"], $arValue); return array('AddAttachmentResult' => '/tasks/getfile/' . (int) $listItemID . '/' . (int) $FILE_ID . '/' . urlencode(ToLower(basename(CFile::GetPath($FILE_ID))))); } else { return new CSoapFault('0x81020016', 'List item not found'); } }
/** * Восстанавливает шаблон, удаляя из него вставки Carrot quest. * <b>Параметры:</b> * <var>$componentTemlateName</var> - имя компонента, который необходимо подменить. * <var>$tpl</var> - шаблон модификации из $this->TEMPLATE_LIST * <var>$delete_created</var> - удалять ли созданные Carrot quest-ом файлы и папки * <b>Возвращаемое значение:</b> нет */ public function RestoreTemplate (&$tpl, $delete_created = false) { $tpl = (array)$tpl; // Нейтрализуем изменения foreach ($tpl["MODIFICATIONS"] as $mod) { foreach ($mod -> FILES_MODIFIED as $file) { $path = ($mod -> COMPONENT_TEMPLATE_PATH).$file; $content = file_get_contents ($path); $pattern = "~\n<!-- Carrot Quest Insert Start -->([\s\S]*?)<!-- Carrot Quest Insert End -->\n~is"; $content = preg_replace($pattern, "", $content); RewriteFile($path, $content); } if ($delete_created) { if ($mod -> CREATED_BY_CARROTQUEST) DeleteDirFileEx($mod -> COMPONENT_TEMPLATE_PATH); else foreach($mod -> FILES_CREATED as $file) DeleteDirFileEx(($mod -> COMPONENT_TEMPLATE_PATH).$file); $tpl["MODIFICATIONS"] -> FILES_CREATED = array(); } } }
function AddAttachment($listName, $listItemID, $fileName, $attachment) { global $USER; if (!$this->__Init()) { return $this->error; } if (!($listName_original = CIntranetUtils::checkGUID($listName))) { return new CSoapFault('Data error', 'Wrong GUID - ' . $listName); } if (strlen($attachment) <= 0) { return new CSoapFault('Wrong attachment', 'Wrong attachment'); } $listName = ToUpper(CIntranetUtils::makeGUID($listName_original)); $listItemID = intval($listItemID); $dbRes = CIBlockElement::GetByID($listItemID); if (($obElement = $dbRes->GetNextElement()) && CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_WRITE_DOCUMENT, $USER->GetID(), $listItemID, array())) { $arElement = $obElement->GetFields(); $arProperty = $obElement->GetProperty('TaskFiles'); $fileName = str_replace(array('/', '\\', '..'), '', $fileName); // minor security $arValue = $arProperty['VALUE']; foreach ($arValue as $FILE_ID) { $FILE = ToLower(basename(CFile::GetPath($FILE_ID))); if ($FILE == ToLower($fileName)) { Header('HTTP/1.1 500 Internal Server Error'); $obDetail = new CXMLCreator('detail'); $obDetail->addChild(CXMLCreator::createTagAttributed('errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/"', 'The specified name is already in use.')); $obDetail->addChild(CXMLCreator::createTagAttributed('errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/"', '0x81020067')); return new CSoapFault('soap::Server', 'Exception of type \'Microsoft.SharePoint.SoapServer.SoapServerException\' was thrown.', $obDetail); } } $path = '/upload/outlook/Lists/' . $listItemID; CheckDirPath($_SERVER['DOCUMENT_ROOT'] . $path); RewriteFile($_SERVER['DOCUMENT_ROOT'] . $path . '/' . $fileName, $attachment); $arFile = CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . $path . '/' . $fileName); $arFile['MODULE_ID'] = 'intranet'; $arValue = array($FILE_ID = CFile::SaveFile($arFile, 'outlook/Lists/' . $listItemID)); @unlink($arFile['tmp_name']); CIBlockElement::SetPropertyValues($arElement['ID'], $arElement['IBLOCK_ID'], $arValue, 'TaskFiles'); return array('AddAttachmentResult' => CFile::GetPath($FILE_ID)); } else { return new CSoapFault('0x81020016', 'List item not found'); } }
function TSEARCH($file, &$count) { global $arSearchParam, $APPLICATION, $USER; if (!$USER->CanDoOperation('edit_php')) { return false; } $_mess = __IncludeLang($file, true); if (!is_array($_mess)) { return false; } $_phrase = $phrase = $arSearchParam['search']; if (!$arSearchParam['bCaseSens']) { $_phrase = strtolower($arSearchParam['search']); } $I_PCRE_MODIFIER = $arSearchParam['bCaseSens'] ? '' : 'i'; $_bMessage = true; $_bMnemonic = false; $_arSearchData = array(); if ($arSearchParam['bSearchMessage'] && $arSearchParam['bSearchMnemonic']) { $_bMessage = true; $_bMnemonic = true; } elseif ($arSearchParam['bSearchMnemonic']) { $_bMnemonic = true; } $_bResult = false; $count = 0; foreach ($_mess as $_sMn => $_sMe) { $__sMe = $_sMe; $__sMn = $_sMn; if (!$arSearchParam['bCaseSens']) { $__sMe = strtolower($_sMe); $__sMn = strtolower($_sMn); } $_bSearch = false; if ($_bMessage) { if (strpos($__sMe, $_phrase) !== false) { $_bSearch = true; } } if ($_bMnemonic) { if (strpos($__sMn, $_phrase) !== false) { $_bSearch = true; } } if ($_bSearch) { $_bResult = true; $res = array(); //Replace if ($arSearchParam['is_replace']) { $pattern = '/' . preg_quote($phrase, '/') . '/S' . $I_PCRE_MODIFIER . BX_UTF_PCRE_MODIFIER; TR_BACKUP($file); if ($_bMessage) { preg_match_all($pattern, $_sMe, $res); $count += count($res[0]); $_sMe = preg_replace($pattern, $arSearchParam['replace'], $_sMe); } if ($_bMnemonic) { preg_match_all($pattern, $_sMn, $res); $count += count($res[0]); $_sMn = preg_replace($pattern, $arSearchParam['replace'], $_sMn); } } else { $pattern = '/' . preg_quote($phrase, '/') . '/' . $I_PCRE_MODIFIER . BX_UTF_PCRE_MODIFIER; if ($_bMessage) { preg_match_all($pattern, $_sMe, $res); $count += count($res[0]); } if ($_bMnemonic) { preg_match_all($pattern, $_sMn, $res); $count += count($res[0]); } } } if ($arSearchParam['is_replace']) { $_arSearchData[] = "\$MESS[\"" . EscapePHPString($_sMn) . "\"] = \"" . EscapePHPString(str_replace("\r", "", $_sMe)) . "\""; } } if ($arSearchParam['is_replace'] && $_bResult) { $strContent = ""; foreach ($_arSearchData as $M) { if (strlen($M) > 0) { $strContent .= "\n" . $M . ";"; } } RewriteFile($file, "<?" . $strContent . "\n?" . ">"); } return $_bResult; }