2023-06-13 11:40:28 +03:00

149 lines
4.2 KiB
PHP

<?
function get_related($iblock_id, $id)
{
$res = CIBlockElement::GetList(Array("NAME" => "ASC"), Array("IBLOCK_ID" => $iblock_id, "ID" => $id, ), false, Array("nPageSize" => 1000));
$ar_res = Array();
while ($obElement = $res->GetNextElement())
{
$ar_res = $obElement->GetFields();
$ar_res['PROPERTIES'] = $obElement->GetProperties();
}
return $ar_res;
}
function get_related_array($iblock_id, $ids)
{
$ar_res = Array();
foreach($ids AS $id)
{
$res = CIBlockElement::GetList(Array("NAME" => "ASC"), Array("IBLOCK_ID" => $iblock_id, "ID" => $id, ), false, Array("nPageSize" => 1000));
while ($obElement = $res->GetNextElement())
{
$ar_res_element = $obElement->GetFields();
$ar_res_element['PROPERTIES'] = $obElement->GetProperties();
$ar_res[] = $ar_res_element;
}
}
return $ar_res;
}
function get_ext_from_mime($mime)
{
$mime_map = [
'application/x-compressed' => '7zip',
'image/bmp' => 'bmp',
'image/x-bmp' => 'bmp',
'image/x-bitmap' => 'bmp',
'image/x-xbitmap' => 'bmp',
'image/x-win-bitmap' => 'bmp',
'image/x-windows-bmp' => 'bmp',
'image/ms-bmp' => 'bmp',
'image/x-ms-bmp' => 'bmp',
'application/bmp' => 'bmp',
'application/x-bmp' => 'bmp',
'application/x-win-bitmap' => 'bmp',
'text/x-comma-separated-values' => 'csv',
'text/comma-separated-values' => 'csv',
'application/vnd.msexcel' => 'csv',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
'application/x-msdownload' => 'exe',
'image/gif' => 'gif',
'application/x-gzip' => 'gzip',
'text/html' => 'html',
'image/jpeg' => 'jpeg',
'image/pjpeg' => 'jpeg',
'application/pdf' => 'pdf',
'application/octet-stream' => 'pdf',
'image/png' => 'png',
'image/x-png' => 'png',
'application/powerpoint' => 'ppt',
'application/vnd.ms-powerpoint' => 'ppt',
'application/vnd.ms-office' => 'ppt',
'application/msword' => 'doc',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
'application/x-rar' => 'rar',
'application/rar' => 'rar',
'application/x-rar-compressed' => 'rar',
'text/rtf' => 'rtf',
'text/richtext' => 'rtx',
'application/x-tar' => 'tar',
'application/x-gzip-compressed' => 'tgz',
'image/tiff' => 'tiff',
'text/plain' => 'txt',
'application/excel' => 'xl',
'application/msexcel' => 'xls',
'application/x-msexcel' => 'xls',
'application/x-ms-excel' => 'xls',
'application/x-excel' => 'xls',
'application/x-dos_ms_excel' => 'xls',
'application/xls' => 'xls',
'application/x-xls' => 'xls',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
'application/vnd.ms-excel' => 'xlsx',
'application/xml' => 'xml',
'text/xml' => 'xml',
'text/xsl' => 'xsl',
'application/xspf+xml' => 'xspf',
'application/x-zip' => 'zip',
'application/zip' => 'zip',
'application/x-zip-compressed' => 'zip',
'application/s-compressed' => 'zip',
'multipart/x-zip' => 'zip',
];
return isset($mime_map[ $mime ]) ? $mime_map[ $mime ] : false;
}
function mb_ucfirst($string)
{
$string = mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
return $string;
}
use Bitrix\Main\Diag\ExceptionHandlerFormatter;
class HttpExceptionHandlerOutput extends \Bitrix\Main\Diag\HttpExceptionHandlerOutput
{
public function renderExceptionMessage($exception, $debug = false)
{
if ($debug)
{
echo ExceptionHandlerFormatter::format($exception, true);
}
else
{
global $APPLICATION;
$APPLICATION->RestartBuffer();
$APPLICATION->__view = [];
include($_SERVER["DOCUMENT_ROOT"] . "/local/templates/500/header.php");
include $_SERVER['DOCUMENT_ROOT'] . '/500.php';
include($_SERVER["DOCUMENT_ROOT"] . "/local/templates/500/footer.php");
CHTTP::SetStatus("500 Internal Server Error");
}
}
}
AddEventHandler("main", "OnEpilog", "OnEpilogHandler", 1);
function OnEpilogHandler()
{
if (defined('ERROR_404') && ERROR_404 == 'Y')
{
global $APPLICATION;
$APPLICATION->RestartBuffer();
include $_SERVER['DOCUMENT_ROOT'].'/local/templates/404/header.php';
include $_SERVER['DOCUMENT_ROOT'].'/404.php';
include $_SERVER['DOCUMENT_ROOT'].'/local/templates/404/footer.php';
}
}
\Bitrix\Main\Application::getInstance()->getExceptionHandler()->setHandlerOutput(new HttpExceptionHandlerOutput());
?>